request->post(['order_sn','shop_name','user_name','courier_name','status','page_no','page_size']); if(empty($params['page_no']) || empty($params['page_size'])){ return $this->fail('缺少必要参数'); } $where = []; foreach($params as $k => $v) { if($k=='page_no' || $k=='page_size'){ continue; } if($k != 'status'){ $where[] = [$k,'like','%'.$v.'%']; }else{ if($v==2){ $where[] = [$k,'in','2,3']; }else{ $where[] = [$k,'=',$v]; } } } $data = Logistics::field(['id','order_id','order_sn','shop_name','shop_phone','receiver_name','receiver_phone','receiver_address','courier_name','courier_company','status','qh_time','ps_time','qx_time','create_time']) ->where($where) ->order(['id' => 'desc']) ->page($params['page_no'],$params['page_size']) ->select() ->each(function ($item){ $item['status_name'] = $item->status_name; $product_count = 0; //获取产品信息 $item['products'] = Product::field('product_num,cart_info')->where('order_id', $item['order_id'])->select()->each(function($pro_item) use(&$product_count){ $pro_item['cart_info'] = json_decode($pro_item['cart_info'], true); $pro_item['goods_name'] = $pro_item['cart_info']['product']['store_name']; $pro_item['goods_unit'] = $pro_item['cart_info']['product']['unit_name']; $product_count += $pro_item['product_num']; unset($pro_item['cart_info']); return $pro_item; }); $item['product_count'] = $product_count; return $item; }) ->toArray(); $count = Logistics::field(['id'])->where($where)->count(); $result = [ 'lists'=>$data, 'count' => $count, 'page_no' => $params['page_no'], 'page_size' => $params['page_size'] ]; return $this->success('请求成功',$result); } public function detail(): \think\response\Json { $params = $this->request->post(['id']); if(empty($params['id'])){ return $this->fail('参数错误'); } $logistics = Logistics::findOrEmpty($params['id']); $logistics['status_name'] = $logistics->status_name; //获取商品信息 $product_count = 0; $product = Product::field('product_num,cart_info')->where('order_id', $logistics['order_id'])->select()->each(function($pro_item) use(&$product_count){ $pro_item['cart_info'] = json_decode($pro_item['cart_info'], true); $pro_item['goods_name'] = $pro_item['cart_info']['product']['store_name']; $pro_item['goods_unit'] = $pro_item['cart_info']['product']['unit_name']; $pro_item['goods_pic'] = $pro_item['cart_info']['product']['image']; $pro_item['goods_price'] = $pro_item['cart_info']['product']['price']; $pro_item['goods_sku'] = $pro_item['cart_info']['productAttr']['sku']; $pro_item['goods_total_price'] = $pro_item['cart_info']['product']['price'] * $pro_item['product_num']; $product_count += $pro_item['product_num']; unset($pro_item['cart_info']); return $pro_item; })->toArray(); $logistics['product'] = $product; //获取物流记录 $records = LogisticsRecord::field('type,user_name,content,create_time') ->where('lst_id', $logistics['id'])->order('create_time asc')->select()->each(function($red_item){ switch ($red_item['type']) { case 1: $red_item['content'] = '用户'.$red_item['user_name'].$red_item['content']; break; case 2: $red_item['content'] = '配送员'.$red_item['user_name'].$red_item['content']; break; case 3: $red_item['content'] = '平台'.$red_item['user_name'].$red_item['content']; break; default: $red_item['content'] = '未知'; } unset($red_item['type'], $red_item['user_name']); })->toArray(); $logistics['records'] = $records; //返回数据 return $this->success('请求成功',$logistics->toArray()); } /* * 获取配送员物流信息列表 * @method get * @param int $courier_id 配送员id * @param int $status 物流状态 * @param int $page_size 每页数量 * @param int $page_num 页码 * @return \think\response\Json */ public function courierLogisticsList(): \think\response\Json { //获取参数 $params = $this->request->post(['user_id','user_type','status','page_size','page_num','keywords']); //验证参数 if(empty($params['user_id'])) return $this->fail('参数错误'); if(!isset($params['user_type'])) return $this->fail('参数错误'); if(empty($params['keywords'])) $params['keywords'] = ''; //返回数据 return $this->data(LogisticsLogic::list($params)); } /* * 获取物流信息详情 * @method get * @param int $logistics_id 物流id * @return \think\response\Json */ public function courierLogisticsDetail(): \think\response\Json { //获取参数 $logistics_id = $this->request->post('logistics_id'); //验证参数 if(empty($logistics_id)) return $this->fail('参数错误'); //返回数据 return $this->data(LogisticsLogic::cDetail($logistics_id)); } /* * 配送员提取商品 * @method post * @param int $logistics_id 物流id * @return \think\response\Json */ public function courierTakeGoods(): \think\response\Json { //获取参数 $params = $this->request->post(['logistics_id','order_id','order_sn']); //验证参数 if(empty($params['logistics_id']) || empty($params['order_id']) || empty($params['order_sn'])) return $this->fail('参数错误'); //提取商品 $result = LogisticsLogic::takeGoods($params); //返回数据 return $result['code'] ==1 ? $this->success('提取成功') : $this->fail($result['msg']); } /* * 配送员完成配送 * @method post * @param int $logistics_id 物流id * @return \think\response\Json */ public function courierCompleteDelivery(): \think\response\Json { //获取参数 $params = $this->request->post(['logistics_id','take_code']); //验证参数 if(empty($params['logistics_id']) || empty($params['take_code'])) return $this->fail('参数错误'); //完成配送 $result = LogisticsLogic::doneDelivery($params); //返回数据 return $result['code'] ==1 ? $this->success('配送完成') : $this->fail($result['msg']); } // public function test() { // $push_result = push_message2('1507bfd3f6c212e2012','您有一条新的配送任务,请尽快处理!!'); // if($push_result['code'] == 0) { // Log::write('["极光推送:"]'.$push_result['msg'],'error'); // }else{ // return $this->success('ok',$push_result); // } // } }