From 29c1757a3296d0685c2dbf0349fe4d6ac3bb37bb Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Thu, 10 Aug 2023 16:17:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AE=A1=E7=90=86=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E4=B8=AD=E7=89=A9=E6=B5=81=E5=88=97=E8=A1=A8=E5=92=8C?= =?UTF-8?q?=E7=89=A9=E6=B5=81=E8=AF=A6=E6=83=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logistics/LogisticsController.php | 13 +- .../logistics/LogisticsRecordController.php | 8 +- .../lists/logistics/LogisticsLists.php | 162 +++++------ .../lists/logistics/LogisticsRecordLists.php | 153 +++++------ .../logic/logistics/LogisticsLogic.php | 133 ++++----- .../logic/logistics/LogisticsRecordLogic.php | 2 +- .../logistics/LogisticsRecordValidate.php | 208 +++++++------- .../validate/logistics/LogisticsValidate.php | 253 ++++++++++-------- app/common/model/logistics/Logistics.php | 4 +- 9 files changed, 463 insertions(+), 473 deletions(-) diff --git a/app/adminapi/controller/logistics/LogisticsController.php b/app/adminapi/controller/logistics/LogisticsController.php index 6434bc80..c72cbb32 100755 --- a/app/adminapi/controller/logistics/LogisticsController.php +++ b/app/adminapi/controller/logistics/LogisticsController.php @@ -13,13 +13,13 @@ // +---------------------------------------------------------------------- -namespace app\adminapi\controller; +namespace app\adminapi\controller\logistics; use app\adminapi\controller\BaseAdminController; -use app\adminapi\lists\LogisticsLists; -use app\adminapi\logic\LogisticsLogic; -use app\adminapi\validate\LogisticsValidate; +use app\adminapi\lists\logistics\LogisticsLists; +use app\adminapi\logic\logistics\LogisticsLogic; +use app\adminapi\validate\logistics\LogisticsValidate; /** @@ -35,7 +35,7 @@ class LogisticsController extends BaseAdminController * @notes 获取列表 * @return \think\response\Json * @author likeadmin - * @date 2023/08/07 15:00 + * @date 2023/08/10 15:41 */ public function lists() { @@ -48,12 +48,13 @@ class LogisticsController extends BaseAdminController * @notes 获取详情 * @return \think\response\Json * @author likeadmin - * @date 2023/08/07 15:00 + * @date 2023/08/10 15:41 */ public function detail() { $params = (new LogisticsValidate())->goCheck('detail'); $result = LogisticsLogic::detail($params); + dump($result);die; return $this->data($result); } diff --git a/app/adminapi/controller/logistics/LogisticsRecordController.php b/app/adminapi/controller/logistics/LogisticsRecordController.php index 3c636ef3..4cb8a414 100755 --- a/app/adminapi/controller/logistics/LogisticsRecordController.php +++ b/app/adminapi/controller/logistics/LogisticsRecordController.php @@ -16,10 +16,10 @@ namespace app\adminapi\controller; -use app\adminapi\controller\BaseAdminController; -use app\adminapi\lists\LogisticsRecordLists; -use app\adminapi\logic\LogisticsRecordLogic; -use app\adminapi\validate\LogisticsRecordValidate; +use app\adminapi\controller\logistics\BaseAdminController; +use app\adminapi\lists\logistics\LogisticsRecordLists; +use app\adminapi\logic\logistics\LogisticsRecordLogic; +use app\adminapi\validate\logistics\LogisticsRecordValidate; /** diff --git a/app/adminapi/lists/logistics/LogisticsLists.php b/app/adminapi/lists/logistics/LogisticsLists.php index 39f5d39d..ed1654e9 100755 --- a/app/adminapi/lists/logistics/LogisticsLists.php +++ b/app/adminapi/lists/logistics/LogisticsLists.php @@ -1,77 +1,87 @@ - ['order_id', 'order_sn', 'courier_id', 'shop_name', 'shop_phone', 'shop_address', 'user_name', 'user_phone', 'user_address', 'status'], - ]; - } - - - /** - * @notes 获取列表 - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public function lists(): array - { - return Logistics::where($this->searchWhere) - ->field(['id', 'order_id', 'order_sn', 'courier_id', 'shop_name', 'shop_phone', 'shop_address', 'user_name', 'user_phone', 'user_address', 'status']) - ->limit($this->limitOffset, $this->limitLength) - ->order(['id' => 'desc']) - ->select() - ->toArray(); - } - - - /** - * @notes 获取数量 - * @return int - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public function count(): int - { - return Logistics::where($this->searchWhere)->count(); - } - + ['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', 'user_take_code'], + + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/08/10 15:41 + */ + 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', 'user_take_code']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->each(function ($item) { + $item['status_name'] = $item->status_name; + $item['courier'] = Courier::alias('u') + ->field('u.nickname,a.phone') + ->leftjoin('la_admin a', 'u.admin_id = a.id') + ->where('u.id', $item['courier_id'])->find(); + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2023/08/10 15:41 + */ + public function count(): int + { + return Logistics::where($this->searchWhere)->count(); + } + } \ No newline at end of file diff --git a/app/adminapi/lists/logistics/LogisticsRecordLists.php b/app/adminapi/lists/logistics/LogisticsRecordLists.php index 8d2d5a9b..1c051d52 100755 --- a/app/adminapi/lists/logistics/LogisticsRecordLists.php +++ b/app/adminapi/lists/logistics/LogisticsRecordLists.php @@ -1,77 +1,78 @@ - ['lst_id', 'type', 'user_name', 'user_phone', 'content'], - ]; - } - - - /** - * @notes 获取列表 - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public function lists(): array - { - return LogisticsRecord::where($this->searchWhere) - ->field(['id', 'lst_id', 'type', 'user_name', 'user_phone', 'content']) - ->limit($this->limitOffset, $this->limitLength) - ->order(['id' => 'desc']) - ->select() - ->toArray(); - } - - - /** - * @notes 获取数量 - * @return int - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public function count(): int - { - return LogisticsRecord::where($this->searchWhere)->count(); - } - + ['lst_id', 'type', 'user_name', 'user_phone', 'content'], + + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/08/07 15:00 + */ + public function lists(): array + { + return LogisticsRecord::where($this->searchWhere) + ->field(['id', 'lst_id', 'type', 'user_name', 'user_phone', 'content']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2023/08/07 15:00 + */ + public function count(): int + { + return LogisticsRecord::where($this->searchWhere)->count(); + } + } \ No newline at end of file diff --git a/app/adminapi/logic/logistics/LogisticsLogic.php b/app/adminapi/logic/logistics/LogisticsLogic.php index c778268c..50a374d7 100755 --- a/app/adminapi/logic/logistics/LogisticsLogic.php +++ b/app/adminapi/logic/logistics/LogisticsLogic.php @@ -12,12 +12,14 @@ // | author: likeadminTeam // +---------------------------------------------------------------------- -namespace app\adminapi\logic; +namespace app\adminapi\logic\logistics; -use app\common\model\Logistics; +use app\common\model\logistics\Courier; +use app\common\model\logistics\Logistics; use app\common\logic\BaseLogic; -use think\facade\Db; +use app\common\model\logistics\LogisticsRecord; +use app\common\model\logistics\Product; /** @@ -28,97 +30,54 @@ use think\facade\Db; class LogisticsLogic extends BaseLogic { - - /** - * @notes 添加 - * @param array $params - * @return bool - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public static function add(array $params): bool - { - Db::startTrans(); - try { - Logistics::create([ - 'order_id' => $params['order_id'], - 'order_sn' => $params['order_sn'], - 'courier_id' => $params['courier_id'], - 'shop_name' => $params['shop_name'], - 'shop_phone' => $params['shop_phone'], - 'shop_address' => $params['shop_address'], - 'user_name' => $params['user_name'], - 'user_phone' => $params['user_phone'], - 'user_address' => $params['user_address'], - 'status' => $params['status'], - ]); - - Db::commit(); - return true; - } catch (\Exception $e) { - Db::rollback(); - self::setError($e->getMessage()); - return false; - } - } - - - /** - * @notes 编辑 - * @param array $params - * @return bool - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public static function edit(array $params): bool - { - Db::startTrans(); - try { - Logistics::where('id', $params['id'])->update([ - 'order_id' => $params['order_id'], - 'order_sn' => $params['order_sn'], - 'courier_id' => $params['courier_id'], - 'shop_name' => $params['shop_name'], - 'shop_phone' => $params['shop_phone'], - 'shop_address' => $params['shop_address'], - 'user_name' => $params['user_name'], - 'user_phone' => $params['user_phone'], - 'user_address' => $params['user_address'], - 'status' => $params['status'], - ]); - - Db::commit(); - return true; - } catch (\Exception $e) { - Db::rollback(); - self::setError($e->getMessage()); - return false; - } - } - - - /** - * @notes 删除 - * @param array $params - * @return bool - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public static function delete(array $params): bool - { - return Logistics::destroy($params['id']); - } - - /** * @notes 获取详情 * @param $params * @return array * @author likeadmin - * @date 2023/08/07 15:00 + * @date 2023/08/10 15:41 */ public static function detail($params): array { - return Logistics::findOrEmpty($params['id'])->toArray(); + $logistics = Logistics::findOrEmpty($params['id']); + $logistics['status_name'] = $logistics->status_name; + //获取配送员信息 + $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(); + $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){ + $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; + })->toArray(); + $logistics['product'] = $product; + //获取物流记录 + $records = LogisticsRecord::field('type,user_name,content,create_time') + ->where('lst_id', $logistics['id'])->order('create_time desc')->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 $logistics->toArray(); } } \ No newline at end of file diff --git a/app/adminapi/logic/logistics/LogisticsRecordLogic.php b/app/adminapi/logic/logistics/LogisticsRecordLogic.php index 33572717..20b406b0 100755 --- a/app/adminapi/logic/logistics/LogisticsRecordLogic.php +++ b/app/adminapi/logic/logistics/LogisticsRecordLogic.php @@ -12,7 +12,7 @@ // | author: likeadminTeam // +---------------------------------------------------------------------- -namespace app\adminapi\logic; +namespace app\adminapi\logic\logistics; use app\common\model\LogisticsRecord; diff --git a/app/adminapi/validate/logistics/LogisticsRecordValidate.php b/app/adminapi/validate/logistics/LogisticsRecordValidate.php index 0c5862e0..ce42b5c5 100755 --- a/app/adminapi/validate/logistics/LogisticsRecordValidate.php +++ b/app/adminapi/validate/logistics/LogisticsRecordValidate.php @@ -1,104 +1,106 @@ - 'require', - 'lst_id' => 'require', - 'type' => 'require', - 'user_name' => 'require', - 'user_phone' => 'require', - 'content' => 'require', - ]; - - - /** - * 参数描述 - * @var string[] - */ - protected $field = [ - 'id' => 'id', - 'lst_id' => '物流信息id', - 'type' => '操作类型 1:用户操作 2:配送员操作 3:平台操作', - 'user_name' => '操作者名称', - 'user_phone' => '操作者电话', - 'content' => '操作详情', - ]; - - - /** - * @notes 添加场景 - * @return LogisticsRecordValidate - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public function sceneAdd() - { - return $this->only(['lst_id','type','user_name','user_phone','content']); - } - - - /** - * @notes 编辑场景 - * @return LogisticsRecordValidate - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public function sceneEdit() - { - return $this->only(['id','lst_id','type','user_name','user_phone','content']); - } - - - /** - * @notes 删除场景 - * @return LogisticsRecordValidate - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public function sceneDelete() - { - return $this->only(['id']); - } - - - /** - * @notes 详情场景 - * @return LogisticsRecordValidate - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public function sceneDetail() - { - return $this->only(['id']); - } - + 'require', + 'lst_id' => 'require', + 'type' => 'require', + 'user_name' => 'require', + 'user_phone' => 'require', + 'content' => 'require', + + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'lst_id' => '物流信息id', + 'type' => '操作类型 1:用户操作 2:配送员操作 3:平台操作', + 'user_name' => '操作者名称', + 'user_phone' => '操作者电话', + 'content' => '操作详情', + + ]; + + + /** + * @notes 添加场景 + * @return LogisticsRecordValidate + * @author likeadmin + * @date 2023/08/07 15:00 + */ + public function sceneAdd() + { + return $this->only(['lst_id','type','user_name','user_phone','content']); + } + + + /** + * @notes 编辑场景 + * @return LogisticsRecordValidate + * @author likeadmin + * @date 2023/08/07 15:00 + */ + public function sceneEdit() + { + return $this->only(['id','lst_id','type','user_name','user_phone','content']); + } + + + /** + * @notes 删除场景 + * @return LogisticsRecordValidate + * @author likeadmin + * @date 2023/08/07 15:00 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return LogisticsRecordValidate + * @author likeadmin + * @date 2023/08/07 15:00 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + } \ No newline at end of file diff --git a/app/adminapi/validate/logistics/LogisticsValidate.php b/app/adminapi/validate/logistics/LogisticsValidate.php index d69dff84..489283db 100755 --- a/app/adminapi/validate/logistics/LogisticsValidate.php +++ b/app/adminapi/validate/logistics/LogisticsValidate.php @@ -1,119 +1,136 @@ - 'require', - 'order_id' => 'require', - 'order_sn' => 'require', - 'courier_id' => 'require', - 'shop_name' => 'require', - 'shop_phone' => 'require', - 'shop_address' => 'require', - 'user_name' => 'require', - 'user_phone' => 'require', - 'user_address' => 'require', - 'status' => 'require', - ]; - - - /** - * 参数描述 - * @var string[] - */ - protected $field = [ - 'id' => 'id', - 'order_id' => '订单id', - 'order_sn' => '订单编号', - 'courier_id' => '配送人员id', - 'shop_name' => '商家名称', - 'shop_phone' => '商家联系电话', - 'shop_address' => '商家联系地址', - 'user_name' => '买家名称', - 'user_phone' => '买家联系电话', - 'user_address' => '买家收货地址', - 'status' => '物流状态 - 0:待揽件 - 1:配送中 - 2:已配送(快递员已配送,买家未确认收货) - 3:已完成 - 4:已取消', - ]; - - - /** - * @notes 添加场景 - * @return LogisticsValidate - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public function sceneAdd() - { - return $this->only(['order_id','order_sn','courier_id','shop_name','shop_phone','shop_address','user_name','user_phone','user_address','status']); - } - - - /** - * @notes 编辑场景 - * @return LogisticsValidate - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public function sceneEdit() - { - return $this->only(['id','order_id','order_sn','courier_id','shop_name','shop_phone','shop_address','user_name','user_phone','user_address','status']); - } - - - /** - * @notes 删除场景 - * @return LogisticsValidate - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public function sceneDelete() - { - return $this->only(['id']); - } - - - /** - * @notes 详情场景 - * @return LogisticsValidate - * @author likeadmin - * @date 2023/08/07 15:00 - */ - public function sceneDetail() - { - return $this->only(['id']); - } - + 'require', + 'order_id' => 'require', + 'order_sn' => 'require', + 'courier_id' => 'require', + 'shop_id' => 'require', + 'shop_name' => 'require', + 'shop_phone' => 'require', + 'shop_address' => 'require', + 'shop_long' => 'require', + 'shop_lat' => 'require', + 'user_id' => 'require', + 'user_name' => 'require', + 'user_phone' => 'require', + 'user_address' => 'require', + 'status' => 'require', + 'qh_time' => 'require', + 'ps_time' => 'require', + 'qx_time' => 'require', + 'user_take_code' => 'require', + + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'order_id' => '订单id', + 'order_sn' => '订单编号', + 'courier_id' => '配送人员id', + 'shop_id' => '商家id', + 'shop_name' => '商家名称', + 'shop_phone' => '商家联系电话', + 'shop_address' => '商家联系地址', + 'shop_long' => '商家地址经度', + 'shop_lat' => '商家地址纬度', + 'user_id' => '买家会员id', + 'user_name' => '买家名称', + 'user_phone' => '买家联系电话', + 'user_address' => '买家收货地址', + 'status' => '物流状态 + 0:待揽件 + 1:配送中 + 2:已配送 + 3:已取消', + 'qh_time' => 'qh_time', + 'ps_time' => 'ps_time', + 'qx_time' => 'qx_time', + 'user_take_code' => '用户取件码', + + ]; + + + /** + * @notes 添加场景 + * @return LogisticsValidate + * @author likeadmin + * @date 2023/08/10 15:41 + */ + public function sceneAdd() + { + return $this->only(['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','user_take_code']); + } + + + /** + * @notes 编辑场景 + * @return LogisticsValidate + * @author likeadmin + * @date 2023/08/10 15:41 + */ + public function sceneEdit() + { + return $this->only(['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','user_take_code']); + } + + + /** + * @notes 删除场景 + * @return LogisticsValidate + * @author likeadmin + * @date 2023/08/10 15:41 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return LogisticsValidate + * @author likeadmin + * @date 2023/08/10 15:41 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + } \ No newline at end of file diff --git a/app/common/model/logistics/Logistics.php b/app/common/model/logistics/Logistics.php index 19d98d6f..c4d62c7b 100755 --- a/app/common/model/logistics/Logistics.php +++ b/app/common/model/logistics/Logistics.php @@ -31,7 +31,7 @@ class Logistics extends BaseModel public function getStatusNameAttr($value,$data): string { - $status = [0=>'待取货',1=>'配送中',2=>'已配送',3=>'已完成',4=>'已取消']; + $status = [0=>'待取货',1=>'配送中',2=>'已配送',3=>'已取消']; return $status[$data['status']]; } @@ -50,7 +50,7 @@ class Logistics extends BaseModel return !empty($value) ? date('Y-m-d H:i:s',$value) : $value; } - public function getPcTimeAttr($value): string + public function getPsTimeAttr($value): string { return !empty($value) ? date('Y-m-d H:i:s',$value) : $value; }