where('id',$goods_id)->find()->toArray(); $spec_info = StoreGoodsItem::where('id',$spec_id)->find()->toArray(); $goods_info['total_price']= bcmul($spec_info['sell_price'],$num,2); $goods_info['goods_spec']= $spec_info['goods_spec']; $goods_info['goods_no']= $spec_info['goods_no']; $goods_info['sell_price']= $spec_info['sell_price']; $add_info = DeliveryAddress::where(['user_id'=>$this->user_id,'is_mr'=>1])->find(); $freight = 0; if($add_info){ $goods_freight = ExpressService::getGoodsExpressPrice($goods_info,$add_info->id,$num); if($goods_freight['code'] !=200){ $this->is_commit = false; $this->ret_msg = $goods_freight['msg']; } if($goods_freight['code'] == 200) $freight = $goods_freight['freight']; } $this->success('ok',['goods_info'=>$goods_info, 'add_info' =>$add_info ? $add_info->toArray():null, 'freight' =>$freight, 'freight_msg' => $this->ret_msg, 'freight_code' => $this->is_commit ? 1 :0 ]); } /** * @title 生成订单(立即购买) * @desc 立即购买场景 * @author qc * @url /api/Order/createOrderImmediately * @method POST * @header name:Authorization require:1 desc:Token * @param name:goods_id type:int require:1 default:0 desc:商品id * @param name:spec_id type:int require:1 default:0 desc:商品多规格的规格id * @param name:num type:int default:1 desc:数量 * @param name:add_id type:int default:1 desc:收货地址id * @param name:remark type:string default:1 desc:订单备注 * @return name:order_id type:int default:1 desc:订单id */ public function createOrderImmediately() { $goods_id = input('post.goods_id'); $spec_id = input('post.spec_id'); $num = input('post.num'); $add_id = input('post.add_id'); $remark = input('post.remark'); if(!$goods_id || !$spec_id) $this->error('请选择商品'); if($num <=0 ) $this->error('数量有误'); if(!$add_id ) $this->error('请选择收货地址'); Db::startTrans(); try { $add_info = DeliveryAddress::find($add_id)->toArray(); $order_insert = [ 'user_id' => $this->user_id, 'order_no' => get_order_sn(), 'goods_num' => $num, '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'], 'remark' => $remark, ]; $goods_info = StoreGoods::with(['itemList'=>function($query)use($spec_id){ return $query->where('id',$spec_id)->where('is_deleted',0); }])->where('id',$goods_id)->where('is_deleted',0)->where('status',1)->find(); if(!$goods_info) throw new Exception('商品已下架'); $goods_info = $goods_info->toArray(); if(empty($goods_info['item_list'])) throw new Exception('该规格已下架'); if($goods_info['item_list'][0]['stock'] < $num) throw new Exception('库存不足'); $order_insert['original_price'] = bcmul($num,$goods_info['item_list'][0]['original_price'],2);// 原价 $true_cost = $goods_info['item_list'][0]['sell_price'];//实际售价 $spec_info = $goods_info['item_list'][0]; $price_goods = bcmul($num,$true_cost,2); // 需要支付商品价格 // 获取运费信息 $exp_data = ExpressService::getGoodsExpressPrice($goods_info,$add_info,$num); if($exp_data['code'] != 200 ) throw new Exception($exp_data['msg']); $price_express = $exp_data['freight']; // 商品运费 //订单金额 = 商品金额 + 运费 $order_money = bcadd($price_goods,$price_express ,2); if($order_money < 0) $this->exception('订单金额有误'); $order_insert['price_total'] = $order_money; $order_insert['price_goods'] = $price_goods; $order_insert['price_express'] = $price_express; $order_info = GoodsOrder::create($order_insert); $order_item = [ 'user_id' => $this->user_id, 'order_id' => $order_info->id, 'goods_id' => $goods_id, 'goods_no' => $spec_info['goods_no'], 'goods_spec' => $spec_info['goods_spec'], 'goods_name' => $goods_info['name'], 'spec_title' => $spec_info['spec_title'], 'spec_id' => $spec_info['id'], 'cover' => $goods_info['cover'], 'original_price' => $spec_info['original_price'], 'sell_price' => $true_cost, 'pay_price' => $order_money, 'num' => $num, ]; GoodsOrderItem::create($order_item); StoreGoods::where('id',$goods_id)->setDec('stock',$num); StoreGoodsItem::where('id',$spec_id)->setDec('stock',$num); Db::commit(); }catch (\Exception $e){ $this->is_commit = false; $this->ret_msg = $e->getMessage(); Db::rollback(); } $this->is_commit ? $this->success('添加成功',['order_id'=>$order_info->id]):$this->error($this->ret_msg); } /** * @title 生成订单(购物车) * @desc 购物车场景 * @author qc * @url /api/Order/createOrderByTrolley * @method POST * @header name:Authorization require:1 desc:Token * @param name:ids type:int require:1 default:0 desc:购物车记录id * @param name:add_id type:int default:1 desc:收货地址id * @param name:remark type:string default:1 desc:订单备注 * @return name:order_id type:int default:1 desc:订单id */ public function createOrderByTrolley() { $ids = input('post.ids'); $add_id = input('post.add_id'); if(!$ids) $this->error('请选择商品'); if(!$add_id ) $this->error('请选择收货地址'); $ret_data = ['order_id'=>0]; Db::startTrans(); try{ $add_info = DeliveryAddress::where('id',$add_id)->find()->toArray(); $trolley_list = ShoppingTrolley::with(['goodsSpec','goodsInfo'])->where('id','in',$ids)->select()->toArray(); if(empty($trolley_list)) $this->exception('购物车记录有误'); // 计算运费 $price_express = 0;// 总运费 $goods_list = ShoppingTrolley::where('id','in',$ids)->field('goods_id,sum(num) as total_num')->group('goods_id')->select()->toArray(); foreach ($goods_list as $v){ $goods_info = StoreGoods::field('name,freight_type,freight_id,postage')->where('id',$v['goods_id'])->find()->toArray(); $freight_data = ExpressService::getGoodsExpressPrice($goods_info,$add_info,$v['total_num']); if($freight_data['code'] != 200){ $this->exception($goods_info['name'].$freight_data['msg']); break; } $price_express += $freight_data['freight']; } // 计算运费 end $price_goods = 0; // 商品总金额 $original_total = 0; // 商品总原价 $total_num = 0;// 商品总数量 $order_item = [];// 订单列表 foreach ($trolley_list as $trolley) { $price_goods += $trolley['num'] * $trolley['goods_spec']['sell_price']; $original_total += $trolley['num'] * $trolley['goods_spec']['original_price']; $total_num +=$trolley['num']; $order_item[] = [ 'user_id' => $this->user_id, 'goods_id' => $trolley['goods_id'], 'goods_no' => $trolley['goods_spec']['goods_no'], 'goods_name' => $trolley['goods_info']['name'], 'goods_spec' => $trolley['goods_spec']['goods_spec'], 'spec_title' => $trolley['goods_spec']['spec_title'], 'spec_id' => $trolley['spec_id'], 'cover' => $trolley['goods_info']['cover'], 'original_price' => $trolley['goods_spec']['original_price'], 'sell_price' => $trolley['goods_spec']['sell_price'], 'num' => $trolley['num'], 'trolley_id' => $trolley['id'], ]; } $order_insert = [ 'user_id' => $this->user_id, 'order_no' => get_order_sn(), 'goods_num' => $total_num, 'pro_name' => $add_info['pro_name'], 'city_name' => $add_info['city_name'], 'county_name' => $add_info['county_name'], 'user_name' => $add_info['name'], 'add_detail' => $add_info['detail'], 'phone' => $add_info['phone'], ]; $price_total = bcadd($price_goods ,$price_express,2); $order_insert['price_total'] = $price_total; $order_insert['price_goods'] = $price_goods ; $order_insert['original_total'] = $original_total ; $order_insert['price_express'] = $price_express ; $order_info = GoodsOrder::create($order_insert);// 生成订单 array_walk($order_item,function (&$v,$k)use ($order_info){ $v['order_id'] = $order_info->id; }); (new GoodsOrderItem())->insertAll($order_item);// 生成订单商品详情 ShoppingTrolley::where('id','in',$ids)->delete();// 删除购物车 $ret_data['order_id'] = $order_info->id; Db::commit(); }catch (\Exception $e){ $this->ret_msg = $e->getMessage(); $this->is_commit = false; Db::rollback(); } $this->transReturn($ret_data); } /** * @title 订单支付 * @desc 订单支付 * @author qc * @url /api/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:支付方式(1.h5微信,2.h5支付宝,3移动支付(微信),4移动支付(支付宝),5.h5微信内支付) * @return name:config type:array default:0 desc:小程序支付配置 * @return name:config.appId type:string default:-- desc:公众账号ID(小程序支付) * @return name:config.signType type:string default:-- desc:签名类型(小程序支付) * @return name:config.paySign type:string default:-- desc:签名(小程序支付) * @return name:config.nonceStr type:string default:-- desc:随机字符串(小程序支付&&APP支付) * @return name:config.timestamp type:string default:-- desc:时间戳小程序支付&&APP支付) * @return name:config.partnerid type:string default:-- desc:商户号(App支付) * @return name:config.prepayid type:string default:-- desc:唯一支付号(App支付) * @return name:config.package type:string default:-- desc:package(App支付) * @return name:config.sign type:string default:-- desc:签名(App支付) * @return name:code_url type:string default:-- desc:付款码url */ public function payOrder() { $order_id = input('post.order_id'); $pay_type = input('post.pay_type'); $order_info = GoodsOrder::with('orderItem')->where('id',$order_id)->find()->toArray(); if($order_info['status'] != 0) $this->error('订单状态错误'); if($order_info['cancel_state'] != 0 || $order_info['is_deleted'] != 0) $this->error('订单异常'); if($order_info['price_total'] <= 0) $this->error('订单金额错误'); $pay_no = $order_info['pay_no'] ? $order_info['pay_no'] : get_order_sn();// 支付单号 if(!$order_info['pay_no']) GoodsOrder::where('id',$order_id)->update(['pay_no'=>$pay_no]); $user_info = User::with('wallet')->where('id',$this->user_id)->find()->toArray(); $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'']; Db::startTrans(); GoodsOrder::where('id',$order_id)->update(['pay_type'=>$pay_type]); try { switch ($pay_type){ case 1://微信 $notify_url = $this->request->root(true) . '/api/we_chat_pay/goodsOrderNotify'; $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'MWEB'); if($pay_config['code'] != 200) $this->exception($pay_config['msg']); $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id']; $pay_config['config']['pay_no'] = $pay_no; $pay_config['config']['notify_url'] = $notify_url; $pay_config['config']['mweb_url'] = $pay_config['mweb_url']; $pay_config['config']['total_fee'] = $order_info['price_total'] * 100; $ret_data['config'] = $pay_config['config']; break; case 2: $notify_url = $this->request->root(true) . '/api/Alipay/goodsOrderNotify'; $return_url ='https://'.$_SERVER['HTTP_HOST']."/dist/#/my"; $config = Alipay::ali_pay_pc('订单支付',$pay_no,$order_info['price_total'],$notify_url,$return_url); $ret_data['config']['ali_url'] = $config; $ret_data['ali_url'] = $config; break; case 3: //移动支付(微信) $notify_url = $this->request->root(true) . '/api/we_chat_pay/goodsOrderNotify'; $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'APP'); if($pay_config['code'] != 200) $this->exception($pay_config['msg']); $ret_data['config'] = $pay_config['config']; break; case 4://移动支付(支付宝) $notify_url = $this->request->root(true) . '/api/Alipay/goodsOrderNotify'; $config = Alipay::ali_pay('订单支付',$pay_no,$order_info['price_total'],$notify_url,); $ret_data['config']['ali_url'] = $config; $ret_data['ali_url'] = $config; break; case 5 : if(!$user_info['openid']) $this->exception('请绑定openid'); $notify_url = $this->request->root(true) . '/api/we_chat_pay/goodsOrderNotify'; $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; } Db::commit(); }catch (\Exception $e){ $this->is_commit = false; $this->ret_msg = $e->getMessage(); Db::rollback(); } $this->transReturn($ret_data); } /** * @title 获取订单列表 * @desc 订单优惠:int_cash + coupon_cash * @author qc * @method GET * @url /api/Order/getOrderList * @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:pay_state type:int default:-1 desc:支付状态(-1全部,0未支付,1已支付) * @param name:cancel_state type:int default:-1 desc:取消状态(-1全部,0未取消,1已取消) * @param name:apply_refund type:int default:-1 desc:申请退款状态(-1全部,0未申请||已取消,1已申请) * @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:original_total type:float default:-- desc:总原价(下划线) * @return name:pay_state type:int default:-- desc:支付状态(0未支付1已支付) * @return name:pay_type type:int default:-- desc:支付方式(1.h5微信,2.h5支付宝,3移动支付(微信),4移动支付(支付宝),5.h5微信内支付) * @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:refund_state type:int default:-- desc:退款状态(0未申请1待审核,2审核通过,3审核拒绝) * @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:integral type:string default:-- desc:使用积分数量 * @return name:int_cash type:float default:-- desc:使用积分抵扣金额 * @return name:cl_ids type:string default:-- desc:使用优惠券id串 * @return name:coupon_cash type:string default:-- desc:使用优惠券抵扣金额 * @return name:blance type:string default:-- desc:使用余额支付金额 * @return name:redu_money type:float default:-- desc:订单满减金额 * @return name:remark type:string default:-- desc:订单备注 * @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:act_type type:int default:-- desc:活动类型0无1秒杀2拼团 * @return name:act_id type:int default:-- desc:活动id * @return name:share_user type:int default:-- desc:分享人id * @return name:order_item type:array default:-- desc:订单商品列表 * @return name:order_item.name type:float default:-- desc:商品名 * @return name:order_item.cover type:float default:-- desc:商品图 * @return name:order_item.sell_price type:float default:-- desc:购买价格 * @return name:order_item.goods_spec type:float default:-- desc:规格 * @return name:order_item.num type:int default:-- desc:数量 */ public function getOrderList() { $status = input('get.status',-1); $pay_state = input('get.pay_state',-1); $cancel_state = input('get.cancel_state',-1); $refund_state = input('get.apply_refund',-1); $where = []; $where[] = ['user_id','=',$this->user_id]; if($status > -1) $where[] = ['status','=',$status]; if($pay_state > -1) $where[] = ['pay_state','=',$pay_state]; if($cancel_state > -1) $where[] = ['cancel_state','=',$cancel_state]; if($refund_state == 0) $where[] = ['refund_state','=',$refund_state]; if($refund_state == 1) $where[] = ['refund_state','in','1,2,3,4']; $list = GoodsOrder::with(['orderItem'])->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/Order/getOrderDetail * @header name:Authorization require:1 desc:Token * @param name:order_id type:int default:-- 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:original_total type:float default:-- desc:总原价(下划线) * @return name:original_total type:float default:-- desc:总原价(下划线) * @return name:pay_state type:int default:-- desc:支付状态(0未支付1已支付) * @return name:pay_type type:int default:-- desc:支付方式(1.h5微信,2.h5支付宝,3移动支付(微信),4移动支付(支付宝),5.h5微信内支付) * @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:refund_state type:int default:-- desc:退款状态(0未申请1待审核,2审核拒绝,3审核通过) * @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:blance type:string default:-- desc:使用余额支付金额(余额抵扣) * @return name:remark type:string default:-- desc:订单备注 * @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:order_item type:array default:-- desc:订单商品列表(按商品id分组) * @return name:order_item.name type:float default:-- desc:商品名 * @return name:order_item.cover type:float default:-- desc:商品图 * @return name:order_item.sell_price type:float default:-- desc:购买价格 * @return name:order_item.goods_spec type:float default:-- desc:规格 * @return name:order_item.num type:int default:-- desc:数量 */ public function getOrderDetail() { $order_id = input('get.order_id'); $detail = GoodsOrder::where('id',$order_id)->find()->toArray(); $detail['order_item'] = (new GoodsOrderItem())->getOrderItem($order_id); $this->success('ok',['detail'=>$detail]); } /** * @title 计算商品运费(一个商品id) * @desc 计算商品运费(一个商品id) * @author qc * @url /api/Order/getGoodsFreight * @method GET * @header name:Authorization require:1 desc:Token * @param name:goods_id type:int require:1 default:0 desc:商品id * @param name:num type:int require:1 default:0 desc:商品数量 * @param name:add_id type:int require:1 default:0 desc:收货地址id * @return name:freight type:float require:0 default:0 desc运费金额 */ public function getGoodsFreight() { $goods_id = input('get.goods_id'); $num = input('get.num'); $add_id = input('get.add_id'); $goods_info = StoreGoods::where('id',$goods_id)->find()->toArray(); $add_info = DeliveryAddress::where('id',$add_id)->find()->toArray(); $freight_data = ExpressService::getGoodsExpressPrice($goods_info,$add_info,$num); if($freight_data['code'] != 200 ) $this->error($freight_data['msg']); $this->success('ok',['freight'=>$freight_data['freight']]); } /** * @title 计算购物车商品运费 * @desc 计算购物车商品运费 * @author qc * @url /api/Order/getTrolleyFreight * @method GET * @header name:Authorization require:1 desc:Token * @param name:ids type:int require:1 default:0 desc:购物车商品id串 * @param name:add_id type:int require:1 default:0 desc:收货地址id * @return name:freight type:float require:0 default:0 desc运费金额 */ public function getTrolleyFreight() { $trolley_ids = input('get.ids'); $add_id = input('get.add_id'); $goods_list = ShoppingTrolley::where('id','in',$trolley_ids) ->field('goods_id,sum(num) as total_num') ->group('goods_id') ->select()->toArray(); $total_price = 0; $add_info = DeliveryAddress::where('id',$add_id)->find()->toArray(); foreach ($goods_list as $v){ $goods_info = StoreGoods::field('name,freight_type,freight_id,postage')->where('id',$v['goods_id'])->find()->toArray(); $freight_data = ExpressService::getGoodsExpressPrice($goods_info,$add_info,$v['total_num']); if($freight_data['code'] != 200){ $this->error($goods_info['name'].$freight_data['msg']); break; } $total_price += $freight_data['freight']; } $this->success('ok',['freight'=>$total_price]); } /** * @title 取消订单 * @desc 取消订单 * @author qc * @url /api/Order/cancelOrder * @method POST * @header name:Authorization require:1 desc:Token * @param name:order_id type:int require:1 default:0 desc:订单id */ public function cancelOrder() { $order_id = input('post.order_id'); Db::startTrans(); try { $detail = GoodsOrder::with('orderItem')->where('id',$order_id)->find()->toArray(); if($detail['status'] != 0) $this->exception('订单状态有误'); // 取消订单状态 GoodsOrder::update(['status'=>9],['id'=>$order_id]); // 订单处理 foreach ($detail['order_item'] as $item_info) { // 更改订单详情状态 GoodsOrderItem::update(['status'=>9],['id'=>$item_info['id']]); // 商品规格库存返回 StoreGoodsItem::where('id',$item_info['spec_id'])->setInc('stock',$item_info['num']); // 商品总库存增加 StoreGoods::where('id',$item_info['goods_id'])->setInc('stock',$item_info['num']); } Db::commit(); }catch (\Exception $e){ $this->ret_msg = $e->getMessage(); $this->is_commit = false; Db::rollback(); } $this->is_commit ? $this->success('取消成功') : $this->error($this->ret_msg); } /** * @title 删除订单 * @desc 删除订单 * @author qc * @url /api/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 = GoodsOrder::with('orderItem')->where('id',$order_id)->find()->toArray(); if($detail['status'] == 0) $this->error('请先取消订单'); GoodsOrder::update(['is_deleted'=>1],['id'=>$order_id]); $this->success('删除成功'); } /** * @title 更换订单收货地址 * @desc 更换订单收货地址(仅待支付订单可以修改地址) * @author qc * @url /api/Order/changeOrderDelivery * @method POST * @header name:Authorization require:1 desc:Token * @param name:order_id type:int require:1 default:0 desc:订单id * @param name:add_id type:int require:1 default:0 desc:收货地址id */ public function changeOrderDelivery() { $order_id = input('post.order_id'); $add_id = input('post.add_id'); $detail = GoodsOrder::where('id',$order_id)->find()->toArray(); if($detail['status'] != 0) $this->error('操作错误'); $add_info = DeliveryAddress::where('id',$add_id)->find()->toArray(); $order_update =[ 'pro_name' => $add_info['pro_name'], 'city_name' => $add_info['city_name'], 'county_name' => $add_info['county_name'], 'street_name' => $add_info['street_name'], 'add_detail' => $add_info['detail'], 'user_name' => $add_info['name'], 'phone' => $add_info['phone'], ]; GoodsOrder::update($order_update,['id'=>$order_id]); $this->success('修改成功'); } /** * @title 确认收货 * @desc 确认收货 * @author qc * @url /api/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 = GoodsOrder::with('orderItem')->where('id',$order_id)->find()->toArray(); if($detail['status'] == 0) $this->error('订单未支付'); if($detail['status'] == 1) $this->error('订单未发货'); if($detail['status'] == 3) $this->error('订单已收货'); GoodsOrder::update(['status'=>3,'express_state'=>2],['id'=>$order_id]); GoodsOrderItem::update(['status'=>3,'express_state'=>2],['order_id'=>$order_id]); UserMessage::create(['user_id'=>$this->user_id,'type_id'=>3,'relation_id'=>$order_id,'content'=>'订单收货成功']); $this->success('已确认收货'); } /** * @title 订单评价 * @desc 订单评价 * @author qc * @url /api/Order/orderComment * @method POST * @header name:Authorization require:1 desc:Token * @param name:item_id type:int require:1 default:0 desc:订单item表id * @param name:content type:string require:1 default:0 desc:评论内容 * @param name:images type:string default:0 desc:图片 * @param name:video type:string default:0 desc:视频 * @param name:goods_core type:int default:0 desc:商品评分 * @param name:wl_core type:int default:0 desc:物流评分 * @param name:serve_core type:int default:0 desc:服务评分 */ public function orderComment() { $item_id = input('post.item_id',''); $content = input('post.content',''); $images = input('post.images',''); $video = input('post.video',''); $goods_core = input('post.goods_core',''); $wl_core = input('post.wl_core',''); $serve_core = input('post.serve_core',''); $item = GoodsOrderItem::get($item_id); if(!$item) $this->error('订单不存在'); $order_info = GoodsOrder::where('id',$item->order_id)->find(); if($order_info->status < 3) $this->error('请先确认收货'); GoodsOrderItem::where('id',$item->id)->update(['status'=>4]); GoodsOrder::where('id',$item->order_id)->update(['status'=>4]); $data = [ 'user_id' => $this->user_id, 'order_id' =>$item->order_id, 'goods_id' =>$item->goods_id, 'spec_id' =>$item->spec_id, 'content' =>$content, 'images' =>$images, 'video' =>$video, 'goods_core' =>$goods_core, 'wl_core' =>$wl_core, 'serve_core' =>$serve_core, ]; OrderComment::create($data); $this->success('评论成功'); } /** * @title 获取物流详情 * @desc 获取物流详情 * @author qc * @url /api/Order/deliveryDetails * @method GET * @header name:Authorization require:1 desc:Token * @param name:order_id type:string require:1 default:-- desc:订单id * @return name:number type:string default:-- desc:单号 * @return name:type type:string default:-- desc:快递类型 * @return name:list type:array default:-- desc:数据列表 * @return name:list.time type:string default:-- desc:时间 * @return name:list.status type:string default:-- desc:内容 * @return name:deliverystatus type:int default:-- desc:0:快递收件(揽件)1.在途中2.正在派件3.已签收4.派送失败5.疑难件6.退件签收 * @return name:issign type:int default:-- desc:是否签收(1.是否签收) * @return name:expName type:string default:-- desc:快递公司名称 * @return name:expSite type:string default:-- desc:快递公司官网 * @return name:expPhone type:string default:-- desc:快递公司电话 * @return name:courier type:string default:-- desc:快递员 或 快递站(没有则为空) * @return name:courierPhone type:string default:-- desc:快递员电话 (没有则为空) * @return name:updateTime type:string default:-- desc:快递轨迹信息最新时间 * @return name:takeTime type:string default:-- desc:发货到收货消耗时长 (截止最新轨迹) * @return name:logo type:string default:-- desc:快递公司LOGO */ public function deliveryDetails(){ $send_no = GoodsOrder::where('id',input('get.order_id'))->value('express_send_no'); if(!$send_no) $this->error('订单没有发货'); $data = get_delivery($send_no); $this->success('ok',$data); } }