getUser(); // $user = ['id'=>40]; $item_id =input('item_id'); $address_id=input('address_id'); $number = input('num'); $pay_no =$this->pay_no($user['id']); $item_total = ShopGoodsItem::mk()->where('id',$item_id)->value('stock_total'); if($number>$item_total){ $this->error('商品没有库存了'); } $data=[ 'uuid'=>$user['id'], 'address_id'=>$address_id, 'item_id'=>$item_id, 'num'=>$number, 'pay_no'=>$pay_no ]; $shop_order_model = new ShopOrder(); $order_id = $shop_order_model->order_create($data); $order_money = ShopOrder::mk()->where(array('uuid'=>$user['id'],'payment_trade'=>$pay_no))->sum('payment_amount'); $pay_data=[ 'pay_no'=>$pay_no, 'money'=>$order_money, 'status'=>1, 'create_at'=>date('Y-m-d H:i:s') ]; ShopOrderPay::mk()->insert($pay_data); $info = ['order_id'=>$order_id,'pay_no'=>$pay_no]; $this->success('快去支付吧',$info); } /** * @Title("购物车下单") * @Method("post") * @Param("cart_ids",desc="购物车id(数组)") * @Param ("address_id",desc="地址id") */ public function crat_create(){ $user =$this->getUser(); $cart_ids = input('cart_ids'); $item_ids = ShopGoodsCart::mk()->whereIn('id',$cart_ids)->select(); foreach ($item_ids as &$v){ $item_total = ShopGoodsItem::mk()->where('id',$v['item_id'])->field('stock_total,goods_spec')->find(); if($v['num']>$item_total['stock_total']){ $this->error($item_total['goods_spec'].'规格没有库存了'); } } $address_id = input('address_id'); $pay_no =$this->pay_no($user['id']); $data=[ 'uuid'=>$user['id'], 'cart_ids'=>$cart_ids, 'address_id'=>$address_id, 'pay_no'=>$pay_no ]; $shop_order_model = new ShopOrder(); $shop_order_model->cart_create($data); $order_money = ShopOrder::mk()->where(array('uuid'=>$user['id'],'payment_trade'=>$pay_no))->sum('payment_amount'); $pay_data=[ 'pay_no'=>$pay_no, 'money'=>$order_money, 'status'=>1, 'create_at'=>date('Y-m-d H:i:s') ]; ShopOrderPay::mk()->insert($pay_data); ShopGoodsCart::mk()->whereIn('id',$cart_ids)->delete(); $this->success('快去支付吧',$pay_no); } /** * @Title("商城下单支付") * @Method("post") * @Header("api-name",type="string",require=1,default="",desc="访问类型") * @Header("api-token",type="string",require=1,default="",desc="token") * @Param("pay_code",type="string",require=1,default="",desc="支付方式code") * @Param("pay_no",type="string",require=1,default="",desc="下单支付单号") * @Param("type",type="string",require=1,default="",desc="支付类型 alipay/wechat") */ public function order_pay(){ $user = $this->getUser(); $data = $this->_vali([ 'pay_code.require'=>'支付code有误', 'pay_no.require'=>'支付订单好不能为空', 'type.require'=>'支付类型不能为空' ]); $code = $data['pay_code']; $pay_type = $data['type']; $pay_no = $data['pay_no']; $pay_money= ShopOrderPay::mk()->where(['status' => 1, 'pay_no'=>$pay_no])->value('money'); if(empty($pay_money)){ $this->error('找不到订单'); } ShopOrderPay::mk()->where(['status' => 1, 'pay_no'=>$pay_no])->save(['pay_type'=>$pay_type]); $all_price = $pay_money; $order_no = $pay_no; $error = 1; Db::startTrans(); $retrun_data = []; try { if (stripos($pay_type, 'alipay') === 0) { $notify_name = 'orderzfb'; $payment_type = '支付宝支付'; } elseif (stripos($pay_type, 'wechat') === 0) { $notify_name = 'orderwx'; $payment_type = '微信支付'; } ShopOrder::mk()->where('payment_trade',$order_no)->save(['payment_type'=>$payment_type]); $notify_url = sysuri("@data/api.notify/{$notify_name}/scene/order/param/{$code}", [], false, true); $parm = ['uuid'=>$this->uuid]; $pay =PaymentService::instance($code)->create($user['openid1'],$order_no,$all_price,'商品下单支付','商品下单支付','','',$notify_url,$parm); $retrun_data['order_no'] = $order_no; $pay['packages'] = isset($pay['package']) ? $pay['package'] : ''; $retrun_data['pay'] = $pay; $retrun_data['success'] = isset($pay['result']) && $pay['result']=='success' ? 1 : 0; Db::commit(); } catch (\Exception $e) { dump($e); // 回滚事务 Db::rollback(); $error = 0; $errorinfo = '未知错误'; } if ($error){ $this->success('成功',$retrun_data); } $this->error($errorinfo); } /** * @Title("我的订单") * @Method("post") * @Header("api-name",type="string",require=1,default="",desc="访问类型") * @Header("api-token",type="string",require=1,default="",desc="token") * @Param("order_name",desc="搜索名称") * @Param ("status",desc="1全部 2 待支付 3代发货 4 待收货 5退款/已退款") */ public function order_list(){ $user = $this->getUser(); $status = input('status',1); if(!empty($status)){ switch ($status){ case 1: $array = [0,1,2,3,4,5,6,7]; break; case 2: $array = [2]; break; case 3: $array = [4]; break; case 4: $array = [5]; break; case 5: $array = [6,7]; break; } } $query = ShopOrder::mQuery()->like('order_name'); $list = $query ->where('uuid',$user['id']) ->whereIn('status',$array)->order('id desc')->page(true, false, false, 10); foreach ($list['list'] as $k=>$v){ $list['list'][$k]['time']=0; if($list['list'][$k]['status']==2){ $list['list'][$k]['time'] = strtotime($list['list'][$k]['create_at'])+30*60-time(); } $list['list'][$k]['admin_name']= SystemUser::mk()->where('id',$list['list'][$k]['admin_id'])->value('nickname'); $list['list'][$k]['goods_item']=ShopOrderItem::mk()->where('order_no',$list['list'][$k]['order_no'])->select(); foreach ($list['list'][$k]['goods_item'] as &$vv){ $vv['item_id'] = ShopGoodsItem::mk()->where('goods_sku',$vv['goods_sku'])->value('id'); } $list['list'][$k]['goods_id'] = ShopGoods::mk()->where('code',$list['list'][$k]['goods_item'][0]['goods_code'])->value('id'); } $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(){ $user = $this->getUser(); $order_id = input('order_id'); $list = ShopOrder::mk()->where('uuid',$user['id'])->where('id',$order_id)->find(); if($list['status']==2){ $list['time'] = strtotime($list['create_at'])+30*60-time(); } $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['admin_name']= SystemUser::mk()->where('id',$list['admin_id'])->value('nickname'); $list['admin_headimag']= SystemUser::mk()->where('id',$list['admin_id'])->value('headimg'); $list['user_info']=DataUser::mk()->where('id',$list['uuid'])->field('headimg,nickname')->find(); $this->success('店铺订单列表',$list); } /** * @Title ("提醒发货") * @Method ("post") * @Param ("order_id",desc="订单id") * @return void */ public function remind(){ $user = $this->getUser(); $order_id = input('order_id'); ShopOrder::mk()->where('uuid',$user['id'])->where('id',$order_id)->save(['remind'=>1]); $this->success('已提醒发货'); } /** * @Title ("取消订单") * @Method ("post") * @Param ("order_id",desc="订单id") * @Param ("cancel_remark",desc="取消原因") * @return void */ public function cancel_order(){ $user = $this->getUser(); $order_id = input('order_id'); $cancel_remark = input('cancel_remark'); ShopOrder::mk()->where('uuid',$user['id'])->where('id',$order_id)->save(['status'=>0,'cancel_remark'=>$cancel_remark]); $this->success('已取消订单'); } /** * @Title ("申请退款") * @Method ("post") * @Param ("type",desc="退款类型") * @Param ("status",desc="收货状态") * @Param ("order_id",desc="订单id") * @Param ("reason",desc="退款原因") * @Param("desc",desc="描述") * @param ("images",desc="图片") */ public function refund(){ $user = $this->getUser(); $refund_type = input('type'); $goods_status = input('status','已收货'); $order_id = input('order_id'); $refund_money = ShopOrder::mk()->where(array('uuid'=>$user['id'],'id'=>$order_id))->value('payment_amount'); $refund_reason = input('reason'); $images = input('images'); if(empty($refund_reason)){ $this->error('退款原因不能为空'); } $refund_desc = input('desc'); $refund_data = [ 'refund_money'=>$refund_money, 'refund_reason'=>$refund_reason, 'refund_desc'=>$refund_desc, 'refund_nr'=>$images, 'refund_type'=>$refund_type, 'goods_status'=>$goods_status, 'refund_status'=>1, 'status'=>7, 'refund_time'=>date('Y-m-d H:i:s') ]; ShopOrder::mk()->where(array('uuid'=>$user['id'],'id'=>$order_id))->save($refund_data); $this->success('退款已提交'); } /** * @Title ("填写退回物流信息") * @Method ("post") * @Param ("express_name",desc="快递公司") * @Param ("express_no",desc="快递单号") * @return void */ public function refund_return(){ $user = $this->getUser(); $order_id = input("order_id"); $express_name = input('express_name'); $express_no = input('express_no'); ShopOrder::mk()->where(array('uuid'=>$user['id'],'order_id'=>$order_id))->save(['express_name'=>$express_name,'express_no'=>$express_no]); $this->success("退款退货物流信息"); } /** * @Title ("撤销退款申请表") * @Method ("post") * @Param ("order_id",desc="订单号") * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function cancel_refund(){ $user = $this->getUser(); $order_id = input('order_id'); $refund_order = ShopOrder::mk()->where(array('uuid'=>$user['id'],'id'=>$order_id,'status'=>6))->find(); if(empty($refund_order)){ $this->error('订单信息错误'); } ShopOrder::mk()->where(array('uuid'=>$user['id'],'order_id'=>$order_id))->save(['status'=>3]); $this->success('订单退款申请已撤回'); } public function pay_no($uuid){ $time_str = date('YmdHi'); $pay_no = 'PAY'.$time_str . rand(00000,99999).$uuid; return $pay_no; } public function refund_order(){ $config = [ 'app_id' => '2021003161685907', 'notify_url' => '', 'return_url' => '', 'ali_public_key' =>'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0+yqR2nQ7uZBHoHeeLspwvZcB/jgMyjAxkJk7Dm9IR5VhTTSXNQYmOOjs+g628G52xxHQ/Z1pPK3dFshqIBTQC0VrrTyWFhypb8veKeo5RFzgWKvl1awvOdf5r6qXM6b3OjaBYqiqvpLdpZdVkEY9rLOwh6LM8XKYE3CfM466KypxYBrUeXRmDhweWVScSuOJGuhmd1O2RI2TIHjosxG10v4/s3nfNZ+aGQ+UnASRZbJ0GyyFlqyJ+mZGyAJBahWI4YYG6ZJMp2YNNUAWeb++gVG1Zw+HYMG57C0W6PCZ0LvS454ZRyx72WP+nKi7LMj8fkintEPbOkRd3M/OF42gQIDAQAB', 'private_key' =>'MIIEogIBAAKCAQEA0+yqR2nQ7uZBHoHeeLspwvZcB/jgMyjAxkJk7Dm9IR5VhTTSXNQYmOOjs+g628G52xxHQ/Z1pPK3dFshqIBTQC0VrrTyWFhypb8veKeo5RFzgWKvl1awvOdf5r6qXM6b3OjaBYqiqvpLdpZdVkEY9rLOwh6LM8XKYE3CfM466KypxYBrUeXRmDhweWVScSuOJGuhmd1O2RI2TIHjosxG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lnRxYutfyVzww5rgxADMn8Gargrvr8/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,设置此参数,将进入沙箱模式 ]; $order = [ 'out_trade_no' => 'PAY2023021616109243658', 'refund_amount' => '0.01', ]; $result = Pay::alipay($config)->refund($order); print_r(json_decode($result,true));die; } }