This commit is contained in:
luofei 2023-08-09 14:41:05 +08:00
parent 25eb6ce7be
commit ef7d8a9ec2
2 changed files with 108 additions and 48 deletions

View File

@ -91,30 +91,13 @@ class LogisticsController extends BaseApiController
public function courierTakeGoods(): \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('courier_id',$user_id)->where('status',0)->find();
if (!$logistics) return $this->fail('物流信息不存在');
//获取配送员信息
$courier = Db::connect('mysql3')->name('la_admin')->field('name,phone')->where('id', $user_id)->find();
if (!$courier) return $this->fail('配送人员信息不存在');
//设置记录信息
$record = [
'lst_id' => $logistics['id'],
'type' => 2,
'user_name' => $courier['name'],
'user_phone' => $courier['phone'],
'content' => '已提取商品',
'create_time' => time(),
];
//更改物流信息状态
$res = $this->logisticsUpdate($logistics_id, 1,$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::takeGoods($params);
//返回数据
return $result['code'] ==1 ? $this->success('提取成功') : $this->fail($result['msg']);
}
/*
@ -126,30 +109,13 @@ class LogisticsController extends BaseApiController
public function courierCompleteDelivery(): \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('courier_id',$user_id)->where('status',1)->find();
if (!$logistics) return $this->fail('物流信息不存在');
//获取配送员信息
$courier = Db::connect('mysql3')->name('la_admin')->field('name,phone')->where('id', $user_id)->find();
if (!$courier) return $this->fail('配送人员信息不存在');
//设置记录信息
$record = [
'lst_id' => $logistics['id'],
'type' => 2,
'user_name' => $courier['name'],
'user_phone' => $courier['phone'],
'content' => '已完成配送',
'create_time' => time(),
];
//更改物流信息状态
$res = $this->logisticsUpdate($logistics_id, 2,$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::doneDelivery($params);
//返回数据
return $result['code'] ==1 ? $this->success('配送完成') : $this->fail($result['msg']);
}
/*

View File

@ -160,4 +160,98 @@ class LogisticsLogic extends BaseLogic
return ['code'=>0, 'msg'=>$e->getMessage()];
}
}
/*
* 配送员接单
* @param $params
* @return array
*/
public static function takeGoods($params):array {
//获取物流信息
$logistics = Logistics::where('id', $params['logistics_id'])->where('courier_id',$params['user_id'])->where('status',0)->find();
if (!$logistics) return ['code'=>0, 'msg'=>'物流信息不存在'];
//获取配送员信息
$courier = Courier::field('nickname,mobile')->where('id', $params['user_id'])->find();
if (!$courier) return ['code'=>0, 'msg'=>'配送员信息不存在'];
//设置记录信息
$record = [
'lst_id' => $logistics['id'],
'type' => 2,
'user_name' => $courier['nickname'],
'user_phone' => $courier['mobile'],
'content' => '已提取商品',
'create_time' => time(),
];
//更改物流信息状态
$res = self::status($params['logistics_id'], 1,$record);
if($res){
return ['code'=>1, 'msg'=>'操作成功'];
}else{
return ['code'=>0, 'msg'=>'操作失败'];
}
}
public static function doneDelivery($params) {
//获取物流信息
$logistics = Logistics::where('id', $params['logistics_id'])->where('courier_id',$params['user_id'])->where('status',1)->find();
if (!$logistics) return ['code'=>0, 'msg'=>'物流信息不存在'];
//获取配送员信息
$courier = Courier::field('nickname,mobile')->where('id', $params['user_id'])->find();
if (!$courier) return ['code'=>0, 'msg'=>'配送员信息不存在'];
//设置记录信息
$record = [
'lst_id' => $logistics['id'],
'type' => 2,
'user_name' => $courier['name'],
'user_phone' => $courier['phone'],
'content' => '已完成配送',
'create_time' => time(),
];
//更改物流信息状态
$res = self::status($params['logistics_id'], 1,$record);
if($res){
return ['code'=>1, 'msg'=>'操作成功'];
}else{
return ['code'=>0, 'msg'=>'操作失败'];
}
}
private static function status($id,$status,$data):bool
{
if(empty($id) || empty($status) || empty($data)) return false;
Logistics::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;
}
Logistics::where('id', $id)->update($update);
LogisticsRecord::create($data);
Logistics::commit();
return true;
} catch (\Exception $e) {
Logistics::rollback();
dump($e->getMessage());
return false;
}
}
}