diff --git a/app/adminapi/lists/logistics/LogisticsLists.php b/app/adminapi/lists/logistics/LogisticsLists.php index 58ce115e..688f7ffd 100755 --- a/app/adminapi/lists/logistics/LogisticsLists.php +++ b/app/adminapi/lists/logistics/LogisticsLists.php @@ -19,6 +19,8 @@ use app\adminapi\lists\BaseAdminDataLists; use app\common\model\logistics\Courier; use app\common\model\logistics\Logistics; use app\common\lists\ListsSearchInterface; +use app\common\model\logistics\Product; +use think\db\Query; /** @@ -39,12 +41,11 @@ class LogisticsLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '%like%' => ['order_sn','shop_name','shop_phone','shop_address','user_name','user_address','user_phone'], + '%like%' => ['order_sn','shop_name','shop_phone','shop_address','receiver_name','receiver_phone','receiver_address','courier_name','courier_company'], '=' => ['order_id', 'status', 'qh_time', 'ps_time', 'qx_time'], ]; } - /** * @notes 获取列表 * @return array @@ -54,21 +55,28 @@ class LogisticsLists extends BaseAdminDataLists implements ListsSearchInterface * @author likeadmin * @date 2023/08/10 15:41 */ - public function lists(): array + public function lists + (): array { return Logistics::where($this->searchWhere) - ->field(['id', 'order_id', 'order_sn', 'courier_id', 'shop_id', 'shop_name', 'shop_phone', 'shop_address', 'shop_long', 'shop_lat', 'user_id', 'user_name', 'user_phone', 'user_address', 'status', 'qh_time', 'ps_time', 'qx_time','create_time', 'user_take_code']) + ->field(['id', 'order_id', 'order_sn', 'courier_name','courier_company', 'shop_name', 'shop_phone', 'shop_address', 'receiver_name', 'receiver_phone', 'receiver_address', 'status', 'qh_time', 'ps_time', 'qx_time','create_time']) ->where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() - ->each(function ($item) { + ->each(function ($item){ $item['status_name'] = $item->status_name; - $item['courier'] = Courier::alias('u') - ->field('u.nickname,a.phone,c.company_name') - ->leftjoin('la_admin a', 'u.admin_id = a.id') - ->leftjoin('la_company c', 'c.id = u.company_id') - ->where('u.id', $item['courier_id'])->find(); + $product_count = 0; + //获取产品信息 + $lst_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(); diff --git a/app/adminapi/logic/logistics/LogisticsLogic.php b/app/adminapi/logic/logistics/LogisticsLogic.php index 3d6878b4..29a7c342 100755 --- a/app/adminapi/logic/logistics/LogisticsLogic.php +++ b/app/adminapi/logic/logistics/LogisticsLogic.php @@ -42,13 +42,6 @@ class LogisticsLogic extends BaseLogic { $logistics = Logistics::findOrEmpty($params['id']); $logistics['status_name'] = $logistics->status_name; - //获取配送员信息 - $courier = Courier::alias('u') - ->field('u.nickname,a.phone,c.company_name') - ->leftjoin('la_admin a', 'u.admin_id = a.id') - ->leftjoin('la_company c', 'c.id = u.company_id') - ->where('u.id', $logistics['courier_id'])->find(); - $logistics['courier'] = $courier; //获取商品信息 $product_count = 0; $product = Product::field('product_num,cart_info')->where('order_id', $logistics['order_id'])->select()->each(function($pro_item) use(&$product_count){ @@ -83,9 +76,6 @@ class LogisticsLogic extends BaseLogic unset($red_item['type'], $red_item['user_name']); })->toArray(); $logistics['records'] = $records; - //获取下单用户信息 - $orderUser = User::field('uid,nickname,phone')->where('uid',$logistics['user_id'])->find(); - $logistics['order_user'] = $orderUser; //返回数据 return $logistics->toArray(); } diff --git a/app/api/logic/LogisticsLogic.php b/app/api/logic/LogisticsLogic.php index 168f5296..0411c34b 100644 --- a/app/api/logic/LogisticsLogic.php +++ b/app/api/logic/LogisticsLogic.php @@ -17,6 +17,7 @@ namespace app\api\logic; use app\common\logic\BaseLogic; use app\common\model\logistics\Courier; use app\common\model\logistics\Logistics; +use app\common\model\logistics\Merchant; use app\common\model\logistics\Order; use app\common\model\logistics\Product; use app\common\model\logistics\LogisticsRecord; @@ -44,7 +45,7 @@ class LogisticsLogic extends BaseLogic } $logistics = Logistics::where('courier_id', $params['courier_id']) ->where([$status]) - ->where('(order_sn LIKE "%'.$params['keywords'].'%" OR shop_phone LIKE "%'.$params['keywords'].'%" OR shop_name LIKE "%'.$params['keywords'].'%" OR user_phone LIKE "%'.$params['keywords'].'%" OR user_name LIKE "%'.$params['keywords'].'%")') + ->where('(order_sn LIKE "%'.$params['keywords'].'%" OR shop_phone LIKE "%'.$params['keywords'].'%" OR shop_name LIKE "%'.$params['keywords'].'%" OR receiver_phone LIKE "%'.$params['keywords'].'%" OR receiver_name LIKE "%'.$params['keywords'].'%")') ->order('update_time desc') ->paginate([ 'list_rows'=> !empty($params['page_size'])? $params['page_size'] : 6, @@ -75,7 +76,7 @@ class LogisticsLogic extends BaseLogic */ public static function cDetail($id):array { //获取物流信息 - $logistics = Logistics::field('id,order_id,order_sn,shop_name,shop_phone,shop_address,user_name,user_phone,user_address,shop_long,shop_lat,status,create_time') + $logistics = Logistics::field('id,order_id,order_sn,shop_name,shop_user,shop_phone,shop_address,shop_long,shop_lat,receiver_name,receiver_phone,receiver_address,status,create_time') ->where('id', $id)->find(); //获取商品信息 $product_count = 0; @@ -121,7 +122,7 @@ class LogisticsLogic extends BaseLogic */ public static function uDetail($params):array { //获取物流信息 - $logistics = Logistics::field('id,order_id,order_sn,courier_id,shop_name,shop_phone,shop_address,user_name,user_address,status,create_time') + $logistics = Logistics::field('id,order_id,order_sn,courier_name,courier_phone,shop_name,shop_user,shop_phone,shop_address,receiver_name,receiver_phone,receiver_address,status,create_time') ->where('order_id', $params['order_id'])->where('order_sn',$params['order_sn'])->find(); //获取物流记录 $records = LogisticsRecord::field('type,user_name,content,create_time') @@ -141,14 +142,9 @@ class LogisticsLogic extends BaseLogic } unset($red_item['type'], $red_item['user_name']); })->toArray(); - $courier = Courier::alias('u') - ->field('u.nickname,a.phone') - ->leftjoin('la_admin a', 'u.admin_id = a.id') - ->where('u.id', $logistics['courier_id'])->find(); //返回数据 return[ 'logistics' => $logistics, - 'courier' => $courier, 'record' => $records, ]; } @@ -163,50 +159,54 @@ class LogisticsLogic extends BaseLogic $logistics = Logistics::where('order_id', $params['order_id'])->where('order_sn', $params['order_sn'])->find(); if($logistics) return ['code'=>0, 'msg'=>'物流信息已存在']; //查找订单信息 - $order = Order::alias('s') - ->leftjoin('eb_merchant m', 'm.mer_id = s.mer_id') - ->field('s.real_name,s.user_phone,s.uid, s.user_address,s.user_address_code,s.logistics_code,m.mer_id,m.mer_name,m.real_name as mer_user_name,m.mer_phone,m.mer_address,m.long,m.lat') - ->where('order_id', $params['order_id'])->where('order_sn', $params['order_sn'])->find(); + $order = Order::alias('s')->where('order_id', $params['order_id'])->where('order_sn', $params['order_sn'])->find(); if(empty($order['user_address_code'])) return ['code'=>1, 'msg'=>'用户地址信息错误']; + //查找商家信息 + $shop = Merchant::field('mer_id,mer_name,real_name,mer_phone,mer_address,long,lat')->where('mer_id',$order['mer_id'])->find(); //匹配配送员 $courier = Courier::alias('u') ->leftjoin('la_company c', 'c.id = u.company_id') + ->leftjoin('la_user a','c.user_id = a.id') + ->field('a.id,a.nickname,a.mobile,c.company_name') ->where("CONCAT_WS(',',u.province,u.city,u.area,u.street,u.village,u.brigade) = '". $order['user_address_code']."'") ->where('u.is_contract', 1) ->where('u.is_captain',1) - ->value('c.user_id'); + ->find(); //判断配送员是否存在 if(!$courier) return ['code'=>0, 'msg'=>'配送员未匹配']; - //获取配送员信息 - $courierInfo = Courier::alias('u') - ->field('u.id,u.nickname,a.phone') - ->leftjoin('la_admin a', 'u.admin_id = a.id') - ->where('u.id', $courier)->find(); //获取下单用户信息 - $orderUser = User::field('nickname,phone')->where('uid', $order['uid'])->find(); + $orderUser = User::field('uid,nickname,phone')->where('uid', $order['uid'])->find(); //写入数据 Logistics::startTrans(); try { $lst = Logistics::create([ 'order_id' => $params['order_id'], 'order_sn' => $params['order_sn'], - 'courier_id' => $courier, - 'shop_id' => $order['mer_id'], - 'shop_name' => $order['mer_name'], - 'shop_user' => $order['mer_user_name'], - 'shop_phone' => $order['mer_phone'], - 'shop_address' => $order['mer_address'], - 'shop_long' => $order['long'], - 'shop_lat' => $order['lat'], - 'user_id' => $order['uid'], - 'user_name' => $order['real_name'], - 'user_phone' => $order['user_phone'], - 'user_address' => $order['user_address'], - 'is_notice' => 0, - 'user_take_code' => '', 'status' => 0, + 'user_id' => $orderUser['uid'], + 'user_name' => $orderUser['nickname'], + 'user_phone' => $orderUser['phone'], + 'courier_id' => $courier['id'], + 'courier_name' => $courier['nickname'], + 'courier_phone' => $courier['mobile'], + 'courier_company' => $courier['company_name'], + 'shop_id' => $shop['mer_id'], + 'shop_name' => $shop['mer_name'], + 'shop_user' => $shop['real_name'], + 'shop_phone' => $shop['mer_phone'], + 'shop_address' => $shop['mer_address'], + 'shop_long' => $shop['long'], + 'shop_lat' => $shop['lat'], + 'receiver_name' => $order['real_name'], + 'receiver_phone' => $order['user_phone'], + 'receiver_address' => $order['user_address'], + 'receiver_take_code' => 0, 'create_time' => time(), 'update_time' => time(), + 'delete_time' => 0, + 'qh_time' => 0, + 'ps_time' => 0, + 'qx_time' => 0, ]); LogisticsRecord::create([ 'lst_id' => $lst->id, @@ -217,7 +217,7 @@ class LogisticsLogic extends BaseLogic 'create_time' => time(), ]); Logistics::commit(); - return ['code'=>1, 'msg'=>'操作成功','data'=>$courierInfo->toArray()]; + return ['code'=>1, 'msg'=>'操作成功','data'=>['nickname'=>$courier['nickname'],'phone'=>$courier['mobile']]]; } catch (\Exception $e) { Logistics::rollback(); return ['code'=>0, 'msg'=>$e->getMessage()]; @@ -244,8 +244,6 @@ class LogisticsLogic extends BaseLogic case 3: return ['code'=>0, 'msg'=>'该订单已经被取消']; } - //获取配送员信息 - $courier = Courier::field('nickname,mobile')->where('id', $logistics['courier_id'])->find(); //更改物流信息状态 Logistics::startTrans(); try { @@ -255,13 +253,13 @@ class LogisticsLogic extends BaseLogic 'status' => 1, 'update_time' => time(), 'qh_time' => time(), - 'user_take_code' => $order['logistics_code'] + 'receiver_take_code' => $order['logistics_code'] ]); LogisticsRecord::create([ 'lst_id' => $logistics['id'], 'type' => 2, - 'user_name' => $courier['nickname'], - 'user_phone' => $courier['mobile'], + 'user_name' => $logistics['courier_name'], + 'user_phone' => $logistics['courier_phone'], 'content' => '已提取商品', 'create_time' => time(), ]); @@ -295,9 +293,7 @@ class LogisticsLogic extends BaseLogic return ['code'=>0, 'msg'=>'订单已被取消']; } //验证取件码 - if($logistics['user_take_code'] !== $params['take_code']) return ['code'=>0, 'msg'=>'取件码错误']; - //获取配送员信息 - $courier = Courier::field('nickname,mobile')->where('id', $logistics['courier_id'])->find(); + if($logistics['receiver_take_code'] !== $params['take_code']) return ['code'=>0, 'msg'=>'取件码错误']; //更改物流信息状态 Logistics::startTrans(); try { @@ -309,8 +305,8 @@ class LogisticsLogic extends BaseLogic LogisticsRecord::create([ 'lst_id' => $logistics['id'], 'type' => 2, - 'user_name' => $courier['nickname'], - 'user_phone' => $courier['mobile'], + 'user_name' => $logistics['courier_name'], + 'user_phone' => $logistics['courier_phone'], 'content' => '已完成配送', 'create_time' => time(), ]); diff --git a/app/common/model/logistics/Courier.php b/app/common/model/logistics/Courier.php index 1ea28e1b..b934dfa9 100644 --- a/app/common/model/logistics/Courier.php +++ b/app/common/model/logistics/Courier.php @@ -20,16 +20,12 @@ use app\common\model\BaseModel; /** - * Logistics模型 - * Class Logistics + * Courier模型 + * Class Courier * @package app\common\model */ class Courier extends BaseModel { - protected $connection = 'mysql3'; protected $name = 'la_user'; - - - } diff --git a/app/common/model/logistics/Merchant.php b/app/common/model/logistics/Merchant.php new file mode 100644 index 00000000..c8c75179 --- /dev/null +++ b/app/common/model/logistics/Merchant.php @@ -0,0 +1,33 @@ +