error('请选择收货地址'); $add_info = DeliveryAddress::where('id',$add_id)->find(); $add_info = $add_info ? $add_info->toArray(): ['pro_name'=>'','city_name'=>'','county_name'=>'','street_name'=>'','name'=>'','detail'=>'','phone'=>'']; $goods_info = GiftGoods::field('s.*,g.name,g.cover,g.low_price') ->alias('s') ->leftJoin('StoreGoods g','g.id = s.goods_id') ->where(['s.status'=>1,'s.is_custom'=>1,'s.is_deleted'=>0,'g.is_deleted'=>0,'g.status'=>1,'s.goods_id'=>$goods_id,'s.cate_id'=>$gift_cate]) ->find(); if(!$goods_info) $this->error('商品已下架'); // 规格详情 $item_info = StoreGoodsItem::where('id',$spec_id)->with('depotItemInfo')->find()->toArray(); // $item_info['stock'] = $item_info['depot_item_info']['stock']; if($item_info['stock'] < $num ) $this->error('商品库存不足'); if($item_info['status'] == 0) $this->error('改规格已下架'); if($item_info['status'] == 0 || $item_info['is_deleted'] == 1) $this->error('改规格已下架'); $order_insert = [ 'user_id' => $this->user_id, 'order_no' => get_order_sn(), 'goods_id' => $goods_id, 'spec_id' => $spec_id, 'goods_num' => $num, 'price_total' => bcmul($num,$item_info['sell_price']), 'price_goods' => bcmul($num,$item_info['sell_price']), 'pro_name' => $add_info['pro_name'], 'city_name' => $add_info['city_name'], 'county_name' => $add_info['county_name'], 'street_name' => $add_info['street_name'], 'user_name' => $add_info['name'], 'add_detail' => $add_info['detail'], 'phone' => $add_info['phone'], 'custom_cover' => $custom_cover, 'logo' => $logo, 'remark' => $remark, 'custom_color' => $custom_color, 'self_cover' => $self_cover, 'title' => $title, 'gift_cate' => $gift_cate, ]; $res = GiftOrder::create($order_insert); DepotGoodsItem::where('id',$item_info['depot_item_info']['id'])->setDec('stock',$num); $this->success('定制订单已提交',['order_id'=>$res->id]); } /** * @title 获取订单列表 * @desc 待审核:sh_status=0;待付款:sh_status=1&&status=0;待发货:status=1;待收货:status=3; * @author qc * @method GET * @url /api/Custom_order/getCustomOrderList * @header name:Authorization require:1 desc:Token * @param name:page type:int default:1 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @param name:status type:int default:-1 desc:状态(0待支付,1已支付(待发货),2已发货(待收货),3已收货(待评论)4已完成,8已退款,9取消) * @param name:sh_status type:int default:-1 desc:审核状态(0待审核1审核通过2审核拒绝) * @return name:id type:int default:-- desc:订单id * @return name:order_no type:string default:-- desc:订单号 * @return name:price_total type:float default:-- desc:待支付金额(商品价格+运费+包装费) * @return name:price_goods type:float default:-- desc:商品金额 * @return name:price_express type:float default:-- desc:运费金额 * @return name:price_pack type:float default:-- desc:包装费 * @return name:pay_state type:int default:-- desc:支付状态(0未支付1已支付) * @return name:pay_type type:int default:-- desc:支付方式(1微信2余额3支付宝) * @return name:pay_no type:string default:-- desc:支付号 * @return name:pay_at type:string default:-- desc:支付时间 * @return name:cancel_state type:int default:-- desc:取消状态(0未取消1已取消) * @return name:cancel_at type:string default:-- desc:取消时间 * @return name:cancel_desc type:string default:-- desc:取消原因 * @return name:cancel_desc type:string default:-- desc:取消原因 * @return name:express_state type:int default:-- desc:发货状态(0未发货,1已发货,2已签收) * @return name:express_company_title type:string default:-- desc:发货快递公司名称 * @return name:express_send_no type:string default:-- desc:物流单号 * @return name:express_send_at type:string default:-- desc:发货时间 * @return name:status type:int default:-- desc:订单状态(0待支付,1已支付(待发货),2已发货(待收货),3已收货(待评论)4已完成,8已退款,9取消) * @return name:create_at type:string default:-- desc:下单时间 * @return name:remark type:string default:-- desc:订单备注 * @return name:goods_id type:int default:-- desc:订单商品id * @return name:goods_num type:int default:-- desc:订单商品总数量 * @return name:pro_name type:string default:-- desc:省名称(收货地址) * @return name:city_name type:string default:-- desc:市名称(收货地址) * @return name:county_name type:string default:-- desc:县区名称(收货地址) * @return name:street_name type:string default:-- desc:街道名称(收货地址) * @return name:add_detail type:string default:-- desc:详细地址(收货地址) * @return name:user_name type:string default:-- desc:收货人 * @return name:phone type:string default:-- desc:收货人联系电话 * @return name:goods_spec type:string default:-- desc:商品规格 * @return name:sell_price type:string default:-- desc:售价(单价【不含包装】) * @return name:spec_title type:string default:-- desc:规格标题 * @return name:goods type:array default:-- desc:订单商品 * @return name:goods.name type:string default:-- desc:商品名 * @return name:goods.cover type:string default:-- desc:商品封面 */ public function getCustomOrderList() { $status = input('get.status',-1); $sh_status = input('get.sh_status',-1); $where = []; $where[] = ['o.user_id','=',$this->user_id]; if($status > -1) $where[] = ['o.status','=',$status]; if($sh_status > -1) $where[] = ['o.sh_status','=',$sh_status]; $list = GiftOrder::with('goods') ->field('o.*,i.goods_spec,i.sell_price,i.spec_title') ->leftJoin('StoreGoodsItem i','i.id = o.spec_id') ->alias('o') ->where($where)->order('id desc') ->limit($this->off_set,$this->page_num) ->select()->toArray(); $this->success('',['list'=>$list]); } /** * @title 获取订单详情 * @desc 获取订单详情 * @author qc * @method GET * @url /api/Custom_order/getCustomOrderDetail * @header name:Authorization require:1 desc:Token * @param name:order_id type:int default:1 desc:订单id * @return name:id type:int default:-- desc:订单id * @return name:order_no type:string default:-- desc:订单号 * @return name:price_total type:float default:-- desc:待支付金额(商品价格+运费+包装费) * @return name:price_goods type:float default:-- desc:商品金额 * @return name:price_express type:float default:-- desc:运费金额 * @return name:price_pack type:float default:-- desc:包装费 * @return name:pay_state type:int default:-- desc:支付状态(0未支付1已支付) * @return name:pay_type type:int default:-- desc:支付方式(1微信2余额3支付宝) * @return name:pay_no type:string default:-- desc:支付号 * @return name:pay_at type:string default:-- desc:支付时间 * @return name:cancel_state type:int default:-- desc:取消状态(0未取消1已取消) * @return name:cancel_at type:string default:-- desc:取消时间 * @return name:cancel_desc type:string default:-- desc:取消原因 * @return name:cancel_desc type:string default:-- desc:取消原因 * @return name:express_state type:int default:-- desc:发货状态(0未发货,1已发货,2已签收) * @return name:express_company_title type:string default:-- desc:发货快递公司名称 * @return name:express_send_no type:string default:-- desc:物流单号 * @return name:express_send_at type:string default:-- desc:发货时间 * @return name:status type:int default:-- desc:订单状态(0待支付,1已支付(待发货),2已发货(待收货),3已收货(待评论)4已完成,8已退款,9取消) * @return name:create_at type:string default:-- desc:下单时间 * @return name:remark type:string default:-- desc:订单备注 * @return name:goods_id type:int default:-- desc:订单商品id * @return name:goods_num type:int default:-- desc:订单商品总数量 * @return name:pro_name type:string default:-- desc:省名称(收货地址) * @return name:city_name type:string default:-- desc:市名称(收货地址) * @return name:county_name type:string default:-- desc:县区名称(收货地址) * @return name:street_name type:string default:-- desc:街道名称(收货地址) * @return name:add_detail type:string default:-- desc:详细地址(收货地址) * @return name:user_name type:string default:-- desc:收货人 * @return name:phone type:string default:-- desc:收货人联系电话 * @return name:goods type:array default:-- desc:订单商品 * @return name:goods.name type:string default:-- desc:商品名 * @return name:goods.cover type:string default:-- desc:商品封面 * @return name:goods_spec type:string default:-- desc:商品规格 * @return name:sell_price type:string default:-- desc:售价(单价【不含包装】) * @return name:spec_title type:string default:-- desc:规格标题 */ public function getCustomOrderDetail() { $order_id =input('get.order_id'); $detail = GiftOrder::with(['goods'])->where('id',$order_id)->find()->toArray(); $item = StoreGoodsItem::field('goods_spec,sell_price,spec_title')->where('id',$detail['spec_id'])->find()->toArray(); $detail['goods_spec'] = $item['goods_spec']; $detail['sell_price'] = $item['sell_price']; $detail['spec_title'] = $item['spec_title']; $this->success('',['detail'=>$detail]); } /** * @title 取消订单 * @desc 取消订单 * @author qc * @url /api/Custom_order/cancelOrder * @method POST * @header name:Authorization require:1 desc:Token * @param name:order_id type:int require:1 default:0 desc:订单id * @param name:cancel_desc type:string require:0 default:0 desc:取消描述 */ public function cancelOrder() { $order_id = input('post.order_id'); $cancel_desc = input('post.cancel_desc'); $order_info = GiftOrder::where('id',$order_id)->find(); if($order_info['status'] != 0) $this->error('订单已支付'); if($order_info['is_deleted'] != 0) $this->error('订单不存在'); if($order_info['cancel_state'] != 0) $this->error('订单已取消'); $order_info->cancel_state = 1; $order_info->status = 9; $order_info->cancel_at = date('Y-m-d H:i:s'); $order_info->cancel_desc = $cancel_desc; $order_info->save(); $this->success('订单已取消'); } /** * @title 删除订单 * @desc 删除订单 * @author qc * @url /api/Custom_order/deleteOrder * @method POST * @header name:Authorization require:1 desc:Token * @param name:order_id type:int require:1 default:0 desc:订单id */ public function deleteOrder() { $order_id = input('post.order_id'); $detail = GiftOrder::where('id',$order_id)->find()->toArray(); if(!in_array($detail['status'],[0,9])) $this->error('订单已支付'); GiftOrder::update(['is_deleted'=>1],['id'=>$order_id]); $this->success('删除成功'); } /** * @title 订单支付 * @desc 订单支付 * @author qc * @url /api/Custom_order/payOrder * @method POST * @header name:Authorization require:1 desc:Token * @param name:order_id type:int require:1 default:0 desc:订单id * @param name:pay_type type:int require:1 default:0 desc:支付方式 */ public function payOrder() { $order_id = input('post.order_id'); $pay_type = input('post.pay_type'); $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'']; Db::startTrans(); try { $order_info = GiftOrder::where('id',$order_id)->find()->toArray(); if($order_info['status'] != 0) $this->exception('订单状态错误'); if($order_info['sh_status'] == 0) $this->exception('订单未审核'); if($order_info['sh_status'] == 2) $this->exception('审核未通过'); $pay_no = $order_info['pay_no'] ? $order_info['pay_no']:get_order_sn();// 支付单号 if(!$order_info['pay_no']) GiftOrder::where('id',$order_id)->update(['pay_no'=>$pay_no]); $user_info = User::with('wallet')->where('id',$this->user_id)->find()->toArray(); switch ($pay_type){ case 1://微信小程序 $notify_url = $this->request->root(true) . '/api/we_chat_pay/customOrderNotify'; $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'JSAPI',$user_info['openid']); if($pay_config['code'] != 200) $this->exception($pay_config['msg']); $ret_data['config'] = $pay_config['config']; break; case 2://佣金余额 if($user_info['wallet']['money'] < $order_info['price_total'])$this->exception('余额不足'); // 扣除余额 UserWallet::userMoneyChange($this->user_id,$order_info['price_total'],'订单支付',1,-1,$order_id); // 支付完成后回调 $back_res = OrderCallback::goodsOrderCallBack($order_info,$pay_type); if(!$back_res['ret_val']) $this->exception($back_res['msg']); $ret_data['pay_status'] = 1; break; case 3://移动支付(支付宝) break; case 4: //4移动支付(微信) $notify_url = $this->request->root(true) . '/api/we_chat_pay/customOrderNotify'; $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'APP',$user_info['openid']); if($pay_config['code'] != 200) $this->exception($pay_config['msg']); $ret_data['config'] = $pay_config['config']; break; case 5: //pc(微信扫码) $notify_url = $this->request->root(true) . '/api/we_chat_pay/customOrderNotify'; $app = Factory::payment(config('app.wx_pay')); $result = $app->order->unify([ 'body' => '微信扫码支付', 'out_trade_no' => $pay_no, 'total_fee' => $order_info['price_total'] * 100, 'notify_url' => $notify_url, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 'trade_type' => 'NATIVE', // 请对应换成你的支付方式对应的值类型 ]); if(!isset($result['code_url']))$this->exception('获取微信付款码失败'); $ret_data['code_url'] = $result['code_url']; break; case 6: //pc(支付宝扫码) break; } Db::commit(); }catch (\Exception $e){ $this->is_commit = false; $this->ret_msg = $e->getMessage(); Db::rollback(); } $this->transReturn($ret_data); } /** * @title 确认收货 * @desc 确认收货 * @author qc * @url /api/Custom_order/confirmReceipt * @method POST * @header name:Authorization require:1 desc:Token * @param name:order_id type:int require:1 default:0 desc:订单id */ public function confirmReceipt() { $order_id = input('post.order_id'); $detail = GiftOrder::where('id',$order_id)->find()->toArray(); if($detail['status'] == 0) $this->error('订单未支付'); if($detail['status'] == 1) $this->error('订单未发货'); if($detail['status'] == 3) $this->error('订单已收货'); GiftOrder::update(['status'=>3],['id'=>$order_id]); $this->success('已确认收货'); } /** * @title 催促发货 * @desc 催促发货 * @author qc * @url /api/Custom_order/urgeExpress * @method POST * @header name:Authorization require:1 desc:Token * @param name:order_id type:int require:1 default:0 desc:订单id */ public function urgeExpress() { $order_id = input('post.order_id'); $detail = GiftOrder::where('id',$order_id)->find()->toArray(); if($detail['status'] == 1) $this->error('订单状态有误'); $check_urge = OrderUrge::where(['order_table'=>'gift_order','order_id'=>$order_id,'day'=>date('Y-m-d')])->count(); if($check_urge) $this->error('今天已经催发过了...'); OrderUrge::create(['order_id'=>$order_id,'user_id'=>$this->user_id,'order_table'=>'gift_order','day'=>date('Y-m-d')]); $this->success('催发成功'); } }