增加管理系统中物流列表和物流详情接口

This commit is contained in:
luofei 2023-08-10 16:17:46 +08:00
parent a0d6e12927
commit 29c1757a32
9 changed files with 463 additions and 473 deletions

View File

@ -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);
}

View File

@ -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;
/**

View File

@ -12,11 +12,12 @@
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists;
namespace app\adminapi\lists\logistics;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\Logistics;
use app\common\model\logistics\Courier;
use app\common\model\logistics\Logistics;
use app\common\lists\ListsSearchInterface;
@ -33,12 +34,13 @@ class LogisticsLists extends BaseAdminDataLists implements ListsSearchInterface
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/08/07 15:00
* @date 2023/08/10 15:41
*/
public function setSearch(): array
{
return [
'=' => ['order_id', 'order_sn', 'courier_id', 'shop_name', 'shop_phone', 'shop_address', 'user_name', 'user_phone', 'user_address', 'status'],
'=' => ['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'],
];
}
@ -50,15 +52,23 @@ class LogisticsLists extends BaseAdminDataLists implements ListsSearchInterface
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/08/07 15:00
* @date 2023/08/10 15:41
*/
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'])
->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();
}
@ -67,7 +77,7 @@ class LogisticsLists extends BaseAdminDataLists implements ListsSearchInterface
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/08/07 15:00
* @date 2023/08/10 15:41
*/
public function count(): int
{

View File

@ -15,7 +15,7 @@
namespace app\adminapi\lists;
use app\adminapi\lists\BaseAdminDataLists;
use app\adminapi\lists\logistics\BaseAdminDataLists;
use app\common\model\LogisticsRecord;
use app\common\lists\ListsSearchInterface;
@ -39,6 +39,7 @@ class LogisticsRecordLists extends BaseAdminDataLists implements ListsSearchInte
{
return [
'=' => ['lst_id', 'type', 'user_name', 'user_phone', 'content'],
];
}

View File

@ -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();
}
}

View File

@ -12,7 +12,7 @@
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic;
namespace app\adminapi\logic\logistics;
use app\common\model\LogisticsRecord;

View File

@ -12,7 +12,7 @@
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate;
namespace app\adminapi\validate\logistics;
use app\common\validate\BaseValidate;
@ -37,6 +37,7 @@ class LogisticsRecordValidate extends BaseValidate
'user_name' => 'require',
'user_phone' => 'require',
'content' => 'require',
];
@ -51,6 +52,7 @@ class LogisticsRecordValidate extends BaseValidate
'user_name' => '操作者名称',
'user_phone' => '操作者电话',
'content' => '操作详情',
];

View File

@ -12,7 +12,7 @@
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate;
namespace app\adminapi\validate\logistics;
use app\common\validate\BaseValidate;
@ -35,13 +35,22 @@ class LogisticsValidate extends BaseValidate
'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',
];
@ -54,18 +63,26 @@ class LogisticsValidate extends BaseValidate
'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:已完成
4:已取消',
2:已配送
3:已取消',
'qh_time' => 'qh_time',
'ps_time' => 'ps_time',
'qx_time' => 'qx_time',
'user_take_code' => '用户取件码',
];
@ -73,11 +90,11 @@ class LogisticsValidate extends BaseValidate
* @notes 添加场景
* @return LogisticsValidate
* @author likeadmin
* @date 2023/08/07 15:00
* @date 2023/08/10 15:41
*/
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']);
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']);
}
@ -85,11 +102,11 @@ class LogisticsValidate extends BaseValidate
* @notes 编辑场景
* @return LogisticsValidate
* @author likeadmin
* @date 2023/08/07 15:00
* @date 2023/08/10 15:41
*/
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']);
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']);
}
@ -97,7 +114,7 @@ class LogisticsValidate extends BaseValidate
* @notes 删除场景
* @return LogisticsValidate
* @author likeadmin
* @date 2023/08/07 15:00
* @date 2023/08/10 15:41
*/
public function sceneDelete()
{
@ -109,7 +126,7 @@ class LogisticsValidate extends BaseValidate
* @notes 详情场景
* @return LogisticsValidate
* @author likeadmin
* @date 2023/08/07 15:00
* @date 2023/08/10 15:41
*/
public function sceneDetail()
{

View File

@ -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;
}