feat: 完成服务接口
This commit is contained in:
parent
f6dfba93f7
commit
ebe4f9549a
|
|
@ -4,6 +4,7 @@ namespace app\services;
|
|||
|
||||
use app\api\library\ApiException;
|
||||
use app\common\controller\WorkerApi;
|
||||
use app\common\Logic\OrderLogic;
|
||||
use app\common\model\Worker;
|
||||
use think\Log;
|
||||
|
||||
|
|
@ -101,5 +102,13 @@ class BaseService
|
|||
return app(Order::class, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OrderLogic
|
||||
*/
|
||||
protected function getOrderLogic()
|
||||
{
|
||||
return app(OrderLogic::class);
|
||||
}
|
||||
|
||||
//{%add function code%}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ class OrderDispatchService extends BaseService
|
|||
}
|
||||
|
||||
/**
|
||||
* 移出字符串中的 cdnUrl
|
||||
* 移除字符串中的 cdnUrl
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -266,6 +266,54 @@ class OrderDispatchService extends BaseService
|
|||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $workerId 师傅id
|
||||
* @param array $params 请求参数
|
||||
* @return void
|
||||
*/
|
||||
public function completeService(int $workerId, array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$time = datetime(time());
|
||||
$orderDispatch = $this->getOrderDispatchInfo($workerId, $params['order_dispatch_id']);
|
||||
$orderDispatch->status = OrderDispatch::STATUS_FINISH;
|
||||
$orderDispatch->images = $this->removeStrCdnUrl($params['complete_images']);
|
||||
$orderDispatch->image = $this->removeStrCdnUrl($params['payment_image']);
|
||||
$orderDispatch->offline_total_type = $params['offline_total_type'];
|
||||
$orderDispatch->finish_time = $time;
|
||||
|
||||
//线下尾款
|
||||
if ($params['final_payment_method'] == 1) {
|
||||
$orderDispatch->total = $params['amount'];
|
||||
}
|
||||
|
||||
//线上尾款
|
||||
if ($params['final_payment_method'] == 2) {
|
||||
$orderDispatch->online_total = $params['amount'];
|
||||
}
|
||||
|
||||
$orderDispatch->save();
|
||||
|
||||
//派单状态变更
|
||||
$orderDispatchChangeParams = [
|
||||
'dispatch' => $orderDispatch,
|
||||
'remark' => '师傅已完成服务,完成时间:' . $time,
|
||||
];
|
||||
Hook::listen('order_dispatch_change', $orderDispatchChangeParams);
|
||||
|
||||
//修改订单状态
|
||||
$orderDispatchInfo = OrderDispatch::get($params['order_dispatch_id']);
|
||||
$roleInfo = ['role' => 2, 'auth' => $this->getWorkerModel()->find($workerId), 'remark' => '师傅完成服务'];
|
||||
$this->getOrderLogic()->dispachFinishAfter($orderDispatchInfo, $roleInfo);
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
$this->apiError('操作失败', $e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -117,6 +117,10 @@ class OrderDispatch extends WorkerApi
|
|||
$this->error($validate);
|
||||
}
|
||||
|
||||
if ($params['final_payment_method'] == 1 && empty($params['offline_total_type'])) {
|
||||
$this->error('线下尾款需选择尾款收款方');
|
||||
}
|
||||
|
||||
$res = $this->getOrderDispatchService()->completeService($this->user['id'], $params);
|
||||
$this->success('操作成功', $res);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@ class OrderDispatch extends Validate
|
|||
'workbench_type|工作台类型' => 'require|in:ongoing,today,tomorrow,all',
|
||||
'plan_time|预约时间' => 'require|date',
|
||||
'images|上门图片' => 'require|max:3000',
|
||||
|
||||
'complete_images|完成图片' => 'require|max:3000',
|
||||
'final_payment_method|收款方式' => 'require|in:1,2',
|
||||
'amount|收款金额' => 'require|number|between:0,10000000',
|
||||
'payment_image|收款图片' => 'require|max:255',
|
||||
'offline_total_type|尾款收款方' => 'in:1,2',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
|
|
@ -24,5 +30,6 @@ class OrderDispatch extends Validate
|
|||
'info' => ['order_dispatch_id'],
|
||||
'appointmentTime' => ['order_dispatch_id', 'plan_time'],
|
||||
'arrivedOnSite' => ['order_dispatch_id', 'images'],
|
||||
'completeService' => ['order_dispatch_id', 'complete_images', 'offline_total_type', 'amount', 'payment_image', 'offline_total_type'],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user