param(); $user_id = $param['uid']?Crypt::decrypt($param['uid']):''; if(!$user_id){ return unauthorized('请先授权'); } $action = $param['action']; $info = Order::info($param, $user_id); if (!$info) { return client_error('商品信息不存在'); } if($info['code'] == 0) { return client_error($info['msg']); } if ($action == 'info') { return success($info['data']); } $order = Order::add($user_id, $info['data'], $param); if($order['code']==0){ return client_error($order['msg']); } return success($order['data']['order_sn'],'下单成功,正在调取支付'); } //下单接口 public function consignment_buy(Request $request) { $param = $request->param(); $user_id = $param['uid']?Crypt::decrypt($param['uid']):''; if(!$user_id){ return unauthorized('请先授权'); } $json_value = $param['json_value']; if (!$json_value) { return client_error('商品信息不存在'); } $json_value=json_decode($json_value,true); $info = ConsignmentOrder::info($json_value, $user_id); if (!$info) { return client_error('商品信息不存在'); } if($info['code'] == 0) { return client_error($info['msg']); } $order = ConsignmentOrder::add($user_id, $info['data']); if($order['code']==0){ return client_error($order['msg']); } $order_id=Crypt::encrypt($order['data']['order_id']); return success($order_id,'寄卖订单已提交'); } //寄卖参数 public function consignment_config(Request $request) { //寄卖流程 $procedure =ShopConfig::get('policy', 'procedure'); //寄卖规则 $rule =ShopConfig::get('policy', 'rule'); //寄卖成功提醒 $consignment =ShopConfig::get('policy', 'consignment'); //品相 $phaseconfig =PhaseConfig::field('name')->select(); //购买渠道 $channel =ShopConfig::get('website', 'channel'); $channel=explode(',',$channel); //寄卖数量限制 $jmnum =ShopConfig::get('website', 'jmnum'); $data=array( 'procedure'=>$procedure, 'rule'=>$rule, 'consignment'=>$consignment, 'phaseconfig'=>$phaseconfig, 'channel'=>$channel, 'jmnum'=>$jmnum, ); return success($data); } //上传图片 public function icon(Request $request) { $param = $request->param(); $file = request()->file('image'); if($file){ $info = $file->validate(['size'=>10*1024*1024,'ext'=>'jpg,png,gif'])->move(Env::get('root_path').'public/uploads/attachment'); if($info){ $data['avatar_logo']='/uploads/attachment/'.$info->getSaveName(); $data['avatar']=$this->img_url.$data['avatar_logo']; return success($data); }else{ // 上传失败获取错误信息 return client_error($file->getError()); } }else{ return client_error('请上传图片'); } } //寄卖订单列表(审核中,待上架,已上架,取消/退回) public function consignment_list(Request $request,ConsignmentOrder $model) { $param = $request->param(); $user_id = $param['uid']?Crypt::decrypt($param['uid']):''; if(!$user_id){ return unauthorized('请先授权'); } $where[] = ['o.user_id', '=', $user_id]; //订单类型 if ($param['status'] == '1') { $where[] = ['o.order_status', 'in','0']; } if ($param['status'] == '2') { $where[] = ['o.order_status', 'in',"1,3,4,5,6"]; } if ($param['status'] == '3') { $where[] = ['o.order_status', 'in','2']; } if ($param['status'] == '4') { $where[] = ['o.order_status', 'in','7,8']; } $size=$param['size']>0?$param['size']:12; $page_l=$param['page']>1?$param['page']:1; $page=$size * ($page_l - 1); $order_count = $model ->alias('o') ->join('consignment_order_goods g', 'g.order_id = o.id') ->with(['consignment_order_goods']) ->where($where) ->order('o.id desc') ->group('o.id') ->count(); $totalPages = ceil($order_count / $size); $order_list = $model ->alias('o') ->field('o.order_sn,o.order_status,o.id') ->join('consignment_order_goods g', 'g.order_id = o.id') ->with(['consignment_order_goods']) ->where($where) ->order('o.id desc') ->group('o.id') ->limit($page, $size) ->select(); if (!$order_list) { return success(array('list'=>[])); } foreach ($order_list as $k1 => $v1) { $order_list[$k1]['order_id'] = Crypt::encrypt($v1['id']); $order_list[$k1]['order_status_text'] = $v1['order_status_text']; unset($v1['id']); foreach ($v1['consignment_order_goods'] as &$order_goods){ $order_goods['goods_img']=$this->img_url.$order_goods['goods_img']; $order_goods['refund_status_text'] = $order_goods['refund_status_text']; unset($order_goods['id'],$order_goods['goods_id'],$order_goods['order_id']); } } $page=array( 'count'=>$order_count, 'num'=>$page_l, 'size'=>$size, 'page'=>$totalPages ); return success(array('list'=>$order_list,'page'=>$page)); } //寄卖订单列表(已售出) public function consignment_sold(Request $request,ConsignmentOrderGoods $cogmodel) { $param = $request->param(); $user_id = $param['uid']?Crypt::decrypt($param['uid']):''; if(!$user_id){ return unauthorized('请先授权'); } $where[] = ['o.user_id', '=', $user_id]; $size=$param['size']>0?$param['size']:12; $page_l=$param['page']>1?$param['page']:1; $page=$size * ($page_l - 1); $order_count = $cogmodel ->alias('cog') ->join('consignment_order co', 'cog.order_id = co.id and co.order_status=2') ->join('order_goods og', 'og.goods_id = cog.goods_id') ->join('order o', 'og.order_id = o.id and o.order_status in (1,2,3)') ->where($where) ->order('o.id desc') ->group('o.id') ->count(); $totalPages = ceil($order_count / $size); $order_list = $cogmodel ->alias('cog') ->field('cog.item_value,cog.goods_name,cog.goods_img,cog.goods_price,cog.brand_name,cog.phase_name,cog.class_name,cog.channel_name') ->join('consignment_order co', 'cog.order_id = co.id and co.order_status=2') ->join('order_goods og', 'og.goods_id = cog.goods_id') ->join('order o', 'og.order_id = o.id and o.order_status in (1,2,3)') ->where($where) ->order('cog.id desc') ->limit($page, $size) ->select(); if (!$order_list) { return success(array('list'=>[])); } foreach ($order_list as $k1 => $v1) { $order_list[$k1]['goods_img'] = $this->img_url.$v1['goods_img']; } $page=array( 'count'=>$order_count, 'num'=>$page_l, 'size'=>$size, 'page'=>$totalPages ); return success(array('list'=>$order_list,'page'=>$page)); } //寄卖订单详情 public function consignment_detail(Request $request,ConsignmentOrder $model) { $param = $request->param(); $user_id = $param['uid']?Crypt::decrypt($param['uid']):''; if(!$user_id){ return unauthorized('请先授权'); } $order_id = $param['order_id']?Crypt::decrypt($param['order_id']):''; if(!$order_id){ return client_error('该订单不存在'); } $where[] = ['o.user_id', '=', $user_id]; $where[] = ['o.id', '=', $order_id]; $order_info = $model ->alias('o') // ->field('o.order_sn,o.order_status,o.id,o.pay_time,total_amount,shipping_time,invoice_name,invoice_no,transaction_id,user_remark,confirm_take_time,cancel_time,o.create_time,province,city,district,address,mobile,consignee') ->with(['consignment_order_goods','logs']) ->where($where) ->find(); if (!$order_info) { return client_error('该订单不存在'); } $order_info['order_id'] = Crypt::encrypt($order_info['id']); $order_info['order_status_text'] = $order_info['order_status_text']; foreach ($order_info['consignment_order_goods'] as &$order_goods){ $order_goods['goods_img']=$this->img_url.$order_goods['goods_img']; $order_goods['id'] = Crypt::encrypt($order_goods['id']); $order_goods['refund_status_text'] = $order_goods['refund_status_text']; unset($order_goods['goods_id'],$order_goods['order_id']); } foreach ($order_info['logs'] as &$logs){ unset($logs['id'],$logs['order_id']); } unset($order_info['id'],$order_info['user_id'],$order_info['update_time'],$order_info['delete_time']); return success($order_info); } /** * Notes: 取消寄卖订单 * @param $order_id * @param $user_id */ public static function consignment_cancel(Request $request,ConsignmentOrder $model) { $param = $request->param(); $user_id = $param['uid']?Crypt::decrypt($param['uid']):''; if(!$user_id){ return unauthorized('请先授权'); } $order_id = $param['order_id']?Crypt::decrypt($param['order_id']):''; if(!$order_id){ return client_error('该订单不存在'); } $order = ConsignmentOrder::get([ 'user_id' => $user_id, 'id' => $order_id ]); if (!$order || ($order['order_status']!='0' && $order['order_status']!='3')) { return client_error('很抱歉!订单无法取消'); } $model->startTrans(); try { //取消订单 $update = [ 'cancel_time' => time(), 'order_status' => 8, ]; $model->where(['id' => $order_id])->update($update); //记录日志 ConsignmentOrderLog::record( $order_id, '寄卖订单已取消' ); $model->commit(); } catch (Exception $e) { $model->rollback(); return client_error($e->getMessage()); } return success('','取消成功'); } /** * Notes: 确认估价 * @param $order_id * @param $user_id */ public static function consignment_confirm(Request $request,ConsignmentOrder $model,ConsignmentOrderGoods $cogmodel) { $param = $request->param(); $user_id = $param['uid']?Crypt::decrypt($param['uid']):''; if(!$user_id){ return unauthorized('请先授权'); } $order_id = $param['order_id']?Crypt::decrypt($param['order_id']):''; if(!$order_id){ return client_error('该订单不存在'); } $goods_id = $param['goods_id']?$param['goods_id']:''; if(!$goods_id){ return client_error('请选择确认估价商品'); } $is_return = $param['is_return']; $consignee = $param['consignee']?$param['consignee']:''; $address = $param['address']?$param['address']:''; $mobile = $param['mobile']?$param['mobile']:''; if(!$consignee || !$address || !$mobile){ return client_error('请选择取货地址'); } $th_consignee = $param['th_consignee']?$param['th_consignee']:''; $th_address = $param['th_address']?$param['th_address']:''; $th_mobile = $param['th_mobile']?$param['th_mobile']:''; if($is_return==1 && (!$th_consignee || !$th_address || !$th_mobile)){ return client_error('请选择退回地址'); } $takeparts_time = $param['takeparts_time']?$param['takeparts_time']:''; if(!$takeparts_time){ return client_error('请选择取件时间'); } $goods_id=json_decode($goods_id,true); //寄卖数量限制 $jmnum =ShopConfig::get('website', 'jmnum'); if($jmnum>count($goods_id)){ return client_error('寄卖满'.$jmnum.'件才可下单'); } $goods_ids=array(); foreach ($goods_id as $key => $value) { $goods_id=Crypt::decrypt($value); if($goods_id>0){ $goods_ids[]=$goods_id; } } //寄卖数量限制 $jmnum =ShopConfig::get('website', 'jmnum'); if($jmnum>count($goods_ids)){ return client_error('寄卖满'.$jmnum.'件才可下单'); } $order = ConsignmentOrder::get([ 'user_id' => $user_id, 'id' => $order_id ]); if (!$order || $order['order_status']!='3') { return client_error('很抱歉!订单无法进行确认估价'); } $model->startTrans(); try { //确认订单 $update = [ 'update_time' => time(), 'order_status' => 4, 'is_return' => $is_return, 'consignee' => $consignee, 'address' => $address, 'mobile' => $mobile, 'th_consignee' => $th_consignee, 'th_address' => $th_address, 'th_mobile' => $th_mobile, 'takeparts_time'=>$takeparts_time ]; $model->where(['id' => $order_id])->update($update); $update_goods = [ 'is_confirm' => 1, ]; $where_goods[]=array('id','in',$goods_ids); $cogmodel->where($where_goods)->update($update_goods); //记录日志 ConsignmentOrderLog::record( $order_id, '您确认评估价格进行寄卖' ); $model->commit(); } catch (Exception $e) { $model->rollback(); return client_error($e->getMessage()); } return success('','确认成功'); } }