uuid(); $count = ['待付款','待发货','待收货','退款/售后']; $where=[]; foreach ($count as &$v){ switch ($v){ case '待付款': $array = '2'; break; case '待发货': $array = '4'; break; case '待收货': $array = '5'; break; case '退款/售后': $array = '7'; break; } $v=ShopOrder::mk()->where('admin_id',$admin_id->id)->whereIn('status',$array)->where($where)->count(); } $this->success('商城订单上标数量',$count); } /** * @Title ("商城订单上标数量") * @Method ("get") * @return void * @throws \think\db\exception\DbException */ public function order_count(){ $admin_id=$this->uuid(); $count = ['全部','待付款','待发货','待收货','已完成']; foreach ($count as &$v){ switch ($v){ case '全部': $array = '0,1,2,3,4,5,6'; break; case '待付款': $array = '2'; break; case '待发货': $array = '4'; break; case '待收货': $array = '5'; break; case '已完成': $array = '6'; break; } $v=ShopOrder::mk()->where('admin_id',$admin_id->id)->whereIn('status',$array)->count(); } $this->success('商城订单上标数量',$count); } /** * @Title("我的订单") * @Method("post") * @Param ("page",desc="页码") * @Param("order_name",desc="搜索名称") * @Param ("status",desc="1全部 2 待支付 3代发货 4 待收货 5已完成") */ public function order_list(){ $admin_id=$this->uuid(); $status = input('status',1); if(!empty($status)){ switch ($status){ case 1: $array = [0,1,2,3,4,5,6]; break; case 2: $array = [2]; break; case 3: $array = [4]; break; case 4: $array = [5]; break; case 5: $array = [6]; break; } } $query = ShopOrder::mQuery()->like('order_name'); $list = $query ->where('admin_id',$admin_id['id']) ->whereIn('status',$array)->order('id desc')->page(true, false, false, 10); foreach ($list['list'] as $k=>$v){ $list['list'][$k]['goods_item']=ShopOrderItem::mk()->where('order_no',$list['list'][$k]['order_no'])->select(); $list['list'][$k]['user_address']=ShopOrderSend::mk()->where('order_no',$list['list'][$k]['order_no'])->find(); $list['list'][$k]['huanxinID'] = DataUser::mk()->where('id',$v['uuid'])->value('huanxinID'); } $this->success('店铺订单列表',$list); } /** * @Title ("订单详情") * @Method ("post") * @Param ("order_id",desc="订单id") * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function order_info(){ $admin_id=$this->uuid(); $order_id = strval(input('order_id')); $str_admin_id = strval($admin_id['id']); $arr = [ 'admin_id' => $str_admin_id, 'id' => $order_id ]; $list = ShopOrder::mk()->where($arr)->find(); $list['time']=0; if($list['status']==2){ $list['time'] = strtotime($list['create_at'])+30*60-time(); /* if($list['list']['time']<=3){ ShopOrder::mk()->where('id',$list['list']['id'])->save(['status'=>0]); }*/ } $list['user']=DataUser::mk()->where('id',$list['uuid'])->field('nickname,phone')->find(); $list['goods_item']=ShopOrderItem::mk()->where('order_no',$list['order_no'])->select(); $list['user_address']=ShopOrderSend::mk()->where('order_no',$list['order_no'])->find(); $list['user_info']=DataUser::mk()->where('id',$list['uuid'])->field('headimg,nickname')->find(); $list['huanxinID'] = DataUser::mk()->where('id',$list['uuid'])->value('huanxinID'); $this->success('店铺订单列表',$list); } /** * @Title ("退款订单列表") * @Method ("get") * @Param ("page",desc="页码") * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function refund_list(){ $admin_id=$this->uuid(); $status =[7,8]; $query = ShopOrder::mQuery()->like('order_name'); $list = $query ->where('admin_id',$admin_id['id']) ->whereIn('status',$status)->where('refund_del',1)->whereOr('refund_status',3)->order('id desc')->page(true, false, false, 10); foreach ($list['list'] as $k=>$v){ $list['list'][$k]['goods_item']=ShopOrderItem::mk()->where('order_no',$list['list'][$k]['order_no'])->select(); $list['list'][$k]['user_address']=ShopOrderSend::mk()->where('order_no',$list['list'][$k]['order_no'])->find(); } $this->success('退款订单',$list); } /** * @Title ("退款操作接口") * @Method ("post") * @Param ("order_id",desc="订单id") * @Param ("type",desc="退款操作 type=1同意退款 type=2 不同意驳回") * @Param ("reason",desc="拒绝退款原因") * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function examine_refund(){ $admnd_id=$this->uuid(); $data = $this->_vali([ 'order_id.require'=>'退款订单不能为空', 'type.require'=>'操作类型能为空', 'reason.default'=>'', ]); $info = ShopOrder::mk()->where(['id'=>$data['order_id'],'admin_id'=>$admnd_id['id'],'status'=>7])->find(); $pay_money = ShopOrderPay::mk()->where(['status' => 2, 'pay_no'=>$info['payment_trade']])->value('money'); if(empty($info)){ $this->error('订单信息有误'); } else{ // 退款操作 if($data['type']==1){ //同意退款 if($info['payment_type']=='支付宝支付') { $result = json_decode($this->refund_order($info['payment_trade'], $info['refund_money']), true); } if($info['payment_type']=='微信支付') { $result = json_decode($this->wxrefund_order($info['payment_trade'], $info['refund_money'],$pay_money), true); } if($result) { ShopOrder::mk()->where(['id' => $data['order_id'], 'admin_id' => $admnd_id['id']])->save(['status' => 8, 'refund_status' => 2, 'dk_time' => date('Y-m-d H:i:s')]); $this->success('已同意退款,支付金额原路退回'); } else{ $this->error('金额未退回查看支付账户'); } } //统一退货 else { ShopOrder::mk()->where(['id'=>$data['order_id'],'admin_id'=>$admnd_id['id']])->save(['status' => 4,'refund_status'=>3,'refuse_reason'=>$data['reason'],'dk_time'=>date('Y-m-d H:i:s')]); //不同意退款 $this->success('不同意退款'); } } } public static function refund_order($pay_no,$money){ $config = [ 'app_id' => '2021003161685907', 'notify_url' => '', 'return_url' => '', 'ali_public_key' =>'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0+yqR2nQ7uZBHoHeeLspwvZcB/jgMyjAxkJk7Dm9IR5VhTTSXNQYmOOjs+g628G52xxHQ/Z1pPK3dFshqIBTQC0VrrTyWFhypb8veKeo5RFzgWKvl1awvOdf5r6qXM6b3OjaBYqiqvpLdpZdVkEY9rLOwh6LM8XKYE3CfM466KypxYBrUeXRmDhweWVScSuOJGuhmd1O2RI2TIHjosxG10v4/s3nfNZ+aGQ+UnASRZbJ0GyyFlqyJ+mZGyAJBahWI4YYG6ZJMp2YNNUAWeb++gVG1Zw+HYMG57C0W6PCZ0LvS454ZRyx72WP+nKi7LMj8fkintEPbOkRd3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mm4CFUPDhIZMCsCgYBx2UzaGkuqpCCim+lY73Kgh4SNOZJ7Ifck32L7TnmrCj3VCS/xUEfHLpU2LFFKBzYUPkrGofd0jtCAGQKdh8IqWVkRunliXNn4CQO2ANI+ddjEFI2EVJ64AYoXDKcKfRfjDOh62NgCCeZalcl9BoS/938T8ZZVpaMYQwDKSXrgKQKBgBCXegcCshZ1Lf6sFqBzGcLCHxLlvm0cz8JSMwDFckaDoqx07RLyI8Almj9lnRxYutfyVzww5rgxADMn8Gargrvr8/LGL5BZg31oPo5Ij4sTEaDw5dRshBaQoTJviBiXpoeInSHwwMR5/RV4GWr1nrBILewvTCvMJHBUy/QS0MRpAoGAe8GMTvLMjgJPnBJK6+p6vNDrpsZTNDlMhSrGFyxskwCeLZpSBFejN12HVoDXuypeA2KO7j6DXR4VxDyS8P0hUlc+iE9IHklT+PMxIuR88x6rqAL/a3DO+QkfYSb0IODLM0UlAFCp6/k7Lt73lkF9sJ4JRP4Fw3R3ddskYu33CzI=', 'log' => [ // optional 'file' => './logs/alipay.log', 'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug 'type' => 'single', // optional, 可选 daily. 'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天 ], 'http' => [ // optional 'timeout' => 5.0, 'connect_timeout' => 5.0, // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html) ], // 'mode' => 'dev', // optional,设置此参数,将进入沙箱模式 ]; try{ $order = [ 'out_trade_no' => $pay_no, 'refund_amount' => $money, ]; Pay::alipay($config)->refund($order); return true; } catch(GatewayException $e){ return false; } } public static function wxrefund_order($pay_no,$money,$pay_money){ $config = [ 'appid' => 'wxa5033cf91977e574', // APP APPID 'app_id' => 'wxa5033cf91977e574', // 公众号 APPID 'miniapp_id' => 'wxa5033cf91977e574', // 小程序 APPID 'mch_id' => '1634830915', 'key' => '7aa3fg0htful8nttb135rnusbvmeggbi', 'notify_url' => '', 'cert_client' => '/www/wwwroot/ship-expert.zhousi.hdlkeji.com/ship-expert/public/cert/apiclient_cert.pem', // optional, 退款,红包等情况时需要用到 'cert_key' => '/www/wwwroot/ship-expert.zhousi.hdlkeji.com/ship-expert/public/cert/apiclient_key.pem',// optional, 退款,红包等情况时需要用到 'log' => [ // optional 'file' => './logs/wechat.log', 'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug 'type' => 'single', // optional, 可选 daily. 'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天 ], 'http' => [ // optional 'timeout' => 5.0, 'connect_timeout' => 5.0, // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html) ], // 'mode' => 'dev', ]; try{ $order = [ 'out_trade_no' => $pay_no, 'out_refund_no' => time(), 'total_fee' => $pay_money*100, 'refund_fee' => $money*100, 'refund_desc' => '退款', ]; Pay::wechat($config)->refund($order); // 返回 `Yansongda\Supports\Collection` 实例,可以通过 `$result->xxx` 访问服务器返回的数据。 return true; } catch(GatewayException $e){ return false; } } //测试退款 ///data/api.business.Order/test_refund //PAY20230909143935695142 //2023090914392620142 public function test_refund(){ $config = [ 'appid' => 'wxa5033cf91977e574', // APP APPID 'app_id' => 'wxa5033cf91977e574', // 公众号 APPID 'miniapp_id' => 'wxa5033cf91977e574', // 小程序 APPID 'mch_id' => '1634830915', 'key' => '7aa3fg0htful8nttb135rnusbvmeggbi', 'notify_url' => '', 'cert_client' => '/www/wwwroot/ship-expert.zhousi.hdlkeji.com/ship-expert/public/cert/apiclient_cert.pem', // optional, 退款,红包等情况时需要用到 'cert_key' => '/www/wwwroot/ship-expert.zhousi.hdlkeji.com/ship-expert/public/cert/apiclient_key.pem',// optional, 退款,红包等情况时需要用到 'log' => [ // optional 'file' => './logs/wechat.log', 'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug 'type' => 'single', // optional, 可选 daily. 'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天 ], 'http' => [ // optional 'timeout' => 5.0, 'connect_timeout' => 5.0, // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html) ], // 'mode' => 'dev', ]; // return json($config); // 退款 $order = [ 'out_trade_no' => 'PAY20231123092418203179', 'out_refund_no' => time(), 'total_fee' => '1', 'refund_fee' => '1', 'refund_desc' => '退款', ]; $payResult = Pay::wechat($config)->refund($order); // 返回 `Yansongda\Supports\Collection` 实例,可以通过 `$result->xxx` 访问服务器返回的数据。 dump($payResult);die; } /** * @Title ("立即发货") * @Method ("post") * @Param ("order_no",desc="订单编号") * @Param ("send_number",desc="快递编号") * @Param ("company_name",desc="快递公司") * @Param ("name",desc="发货姓名") * @Param ("phone",desc="发货联系号码") * @Param ("province",desc="省") * @Param ("city",desc="城市") * @Param ("area",desc="地区") * @Param ("address",desc="详细地址") * @return void */ public function order_send(){ $admin_id = $this->uuid(); $data = $this->_vali( [ 'order_no.require'=>'订单信息不能为空', 'send_number.require'=>'快递单号不能为空', 'company_name.require'=>'快递公司名称不能为空', 'name.require'=>'发货商家联系人', 'phone.require'=>'商家联系号码', 'province.require'=>'发货商家省', 'city.require'=>'商家市', 'area.require'=>'发货商家区县', 'address.require'=>'详细地址' ] ); $send_data = [ 'send_number'=>$data['send_number'], 'company_name'=>$data['company_name'], 'send_datetime'=>date('Y-m-d H:i:s'), 'fa_name'=>$data['name'], 'fa_phone'=>$data['phone'], 'fa_address'=>$data['province'].$data['city'].$data['area'].$data['address'], 'shou_name'=>$data['name'], 'shou_phone'=>$data['phone'], 'shou_address'=>$data['province'].$data['city'].$data['area'].$data['address'], ]; ShopOrderSend::mk()->where('order_no',$data['order_no'])->save($send_data); ShopOrder::mk()->where('order_no',$data['order_no'])->save(['status'=>5]); $this->success('发货成功'); } /** * @Title ("删除退款记录") * @Method ("post") * @Param ("order_id",desc="订单id") * @return void */ public function del_refund(){ $this->uuid(); $data = $this->_vali( [ 'order_id.require'=>'订单id不能为空', ] ); ShopOrder::mk()->where('id',$data['order_id'])->save(['refund_del'=>2]); $this->success('退款记录已清除'); } public function uuid(){ $purchase_model = new Common($this->app); $uuid = $purchase_model->uuid(); return $uuid; } }