This commit is contained in:
luofei 2023-08-09 15:00:12 +08:00
parent ef7d8a9ec2
commit 7a64016981
2 changed files with 77 additions and 88 deletions

View File

@ -127,28 +127,13 @@ class LogisticsController extends BaseApiController
public function userConfirmReceipt(): \think\response\Json
{
//获取参数
$logistics_id = input('logistics_id', 0, 'intval');
$user_id = input('user_id', 0, 'intval');
//获取物流信息
$logistics = Db::name('logistics')->where('id', $logistics_id)->where('user_id',$user_id)->find();
if (!$logistics) return $this->fail('物流信息不存在');
if ($logistics['status'] == 4) return $this->fail('不可更改物流状态');
//设置记录信息
$record = [
'lst_id' => $logistics['id'],
'type' => 1,
'user_name' => $logistics['user_name'],
'user_phone' => $logistics['user_phone'],
'content' => '已确认收货',
'create_time' => time(),
];
//更改物流信息状态
$res = $this->logisticsUpdate($logistics_id, 3,$record);
if($res){
return $this->success('操作成功');
}else{
return $this->fail('操作失败');
}
$params = $this->request->post(['logistics_id','user_id']);
//验证参数
if(empty($params['logistics_id']) || empty($params['user_id'])) return $this->fail('参数错误');
//完成配送
$result = LogisticsLogic::receipt($params);
//返回数据
return $result['code'] ==1 ? $this->success('确认收货成功') : $this->fail($result['msg']);
}
/*
@ -160,68 +145,13 @@ class LogisticsController extends BaseApiController
public function userCancelOrder(): \think\response\Json
{
//获取参数
$logistics_id = input('logistics_id', 0, 'intval');
$user_id = input('user_id', 0, 'intval');
//获取物流信息
$logistics = Db::name('logistics')->where('id', $logistics_id)->where('user_id',$user_id)->find();
if (!$logistics) return $this->fail('物流信息不存在');
if ($logistics['status'] == 2 || $logistics['status'] == 3 || $logistics['status'] == 4) return $this->fail('订单已完成不能取消订单');
//设置记录信息
$record = [
'lst_id' => $logistics['id'],
'type' => 1,
'user_name' => $logistics['user_name'],
'user_phone' => $logistics['user_phone'],
'content' => '已取消订单',
'create_time' => time(),
];
//更改物流信息状态
$res = $this->logisticsUpdate($logistics_id, 4,$record);
if($res){
return $this->success('操作成功', [], 1, 200);
}else{
return $this->fail('操作失败', [], 0, 200);
}
$params = $this->request->post(['logistics_id','user_id']);
//验证参数
if(empty($params['logistics_id']) || empty($params['user_id'])) return $this->fail('参数错误');
//完成配送
$result = LogisticsLogic::cancel($params);
//返回数据
return $result['code'] ==1 ? $this->success('取消成功') : $this->fail($result['msg']);
}
/*
* 更新物流信息
* @method post
* @param int $logistics_id 物流id
* @return bool
*/
private function logisticsUpdate($id,$status,$data):bool
{
if(empty($id) || empty($status) || empty($data)) return false;
Db::startTrans();
try {
$update = [
'status' => $status,
'update_time' => time(),
];
switch($status){
case 1:
$update['qh_time'] = time();
break;
case 2:
$update['pc_time'] = time();
break;
case 3:
$update['sh_time'] = time();
break;
case 4:
$update['qx_time'] = time();
break;
default:
break;
}
Db::name('logistics')->where('id', $id)->update($update);
Db::name('logistics_record')->insert($data);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return false;
}
}
}

View File

@ -36,9 +36,15 @@ class LogisticsLogic extends BaseLogic
*/
public static function list($params):array {
//获取物流列表
if(empty($params['status'])){
$status = ['status','in','0,1'];
}else{
$status = ['status','=',$params['status']];
}
$logistics = Logistics::where('courier_id', $params['courier_id'])
->where('status', $params['status'] ?? 0)
->where([$status])
->where('(order_sn="'.$params['keywords'].'" OR shop_name LIKE "%'.$params['keywords'].'%" OR user_name LIKE "%'.$params['keywords'].'%")')
->order('update_time desc')
->paginate([
'list_rows'=> !empty($params['page_size'])? $params['page_size'] : 6,
'page' => !empty($params['page_num'])? $params['page_num'] : 1,
@ -192,7 +198,12 @@ class LogisticsLogic extends BaseLogic
}
public static function doneDelivery($params) {
/*
* 配送员配送
* @param $params
* @return array
*/
public static function doneDelivery($params):array {
//获取物流信息
$logistics = Logistics::where('id', $params['logistics_id'])->where('courier_id',$params['user_id'])->where('status',1)->find();
if (!$logistics) return ['code'=>0, 'msg'=>'物流信息不存在'];
@ -209,7 +220,7 @@ class LogisticsLogic extends BaseLogic
'create_time' => time(),
];
//更改物流信息状态
$res = self::status($params['logistics_id'], 1,$record);
$res = self::status($params['logistics_id'], 2,$record);
if($res){
return ['code'=>1, 'msg'=>'操作成功'];
}else{
@ -217,7 +228,56 @@ class LogisticsLogic extends BaseLogic
}
}
/*
* 用户确认收货
* @param $params
* @return array
*/
public static function receipt($params):array {
//获取物流信息
$logistics = Logistics::where('id', $params['logistics_id'])->where('user_id',$params['user_id'])->find();
if (!$logistics) return ['code'=>0, 'msg'=>'物流信息不存在'];
if ($logistics['status'] == 4) return ['code'=>0, 'msg'=>'状态不可更改'];
//设置记录信息
$record = [
'lst_id' => $logistics['id'],
'type' => 1,
'user_name' => $logistics['user_name'],
'user_phone' => $logistics['user_phone'],
'content' => '已确认收货',
'create_time' => time(),
];
//更改物流信息状态
$res = self::status($params['logistics_id'], 3,$record);
if($res){
return ['code'=>1, 'msg'=>'操作成功'];
}else{
return ['code'=>0, 'msg'=>'操作失败'];
}
}
public static function cancel($params):array {
//获取物流信息
$logistics = Logistics::where('id', $params['logistics_id'])->where('user_id',$params['user_id'])->find();
if (!$logistics) return ['code'=>0, 'msg'=>'物流信息不存在'];
if ($logistics['status'] == 2 || $logistics['status'] == 3 || $logistics['status'] == 4) return ['code'=>0, 'msg'=>'状态不可更改'];;;
//设置记录信息
$record = [
'lst_id' => $logistics['id'],
'type' => 1,
'user_name' => $logistics['user_name'],
'user_phone' => $logistics['user_phone'],
'content' => '已取消订单',
'create_time' => time(),
];
//更改物流信息状态
$res = self::status($params['logistics_id'], 4,$record);
if($res){
return ['code'=>1, 'msg'=>'操作成功'];
}else{
return ['code'=>0, 'msg'=>'操作失败'];
}
}
private static function status($id,$status,$data):bool
{
@ -250,7 +310,6 @@ class LogisticsLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Logistics::rollback();
dump($e->getMessage());
return false;
}
}