| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- <?php
- namespace app\workerapi\controller;
- use app\adminapi\logic\master_worker\MasterWorkerLogic;
- use app\adminapi\logic\works\ServiceWorkLogic;
- use app\api\logic\UserCouponLogic;
- use app\common\model\works\IssueWork;
- use app\common\model\works\ReturnWork;
- use app\common\model\works\ServiceWork;
- use app\workerapi\lists\HistoryWorkLists;
- use app\workerapi\lists\ServiceAssignWorkLists;
- use app\workerapi\lists\GoodsFeeStandardsLists;
- use app\workerapi\lists\ServiceWorkGrabOrderLists;
- use app\workerapi\lists\ServiceWorkGrabOrderLogLists;
- use app\workerapi\lists\ServiceWorkLists;
- use app\workerapi\lists\ServiceWorkSparePartLists;
- use app\workerapi\lists\SparePartLists;
- use app\workerapi\validate\ServiceWorkValidate;
- use app\workerapi\validate\GoodsFeeStandardsValidate;
- use Exception;
- /**
- * 工单系统
- */
- class WorksController extends BaseApiController
- {
- public array $notNeedLogin = ['grabOrder'];
- /**
- * 首页数量统计
- * @return \think\response\Json
- * @throws \think\db\exception\DbException
- */
- public function statistics()
- {
- $result['service_work_count'] = ServiceWork::where(['master_worker_id'=>$this->userId])->whereIn('service_status','0,1,2')->where('work_status','<>',1)->where('work_pay_status','>',0)->count();
- $result['assign_work_count'] = ServiceWork::where(['master_worker_id'=>$this->userId,'work_status'=>1])->where('work_pay_status','>',0)->count();
- $result['pick_work_count'] = 0;
- $result['return_work_count'] = ReturnWork::where(['master_worker_id'=>$this->userId])->where('return_work_status','<>',4)->count();
- $result['issue_work_count'] = IssueWork::where(['master_worker_id'=>$this->userId])->whereIn('issue_approval','1,2,3')->count();
- $result['review_work_count'] = ServiceWork::where(['master_worker_id'=>$this->userId,'work_status'=>7])->count();
- return $this->data($result);
- }
- /**
- * 服务工单列表-全部
- * @return \think\response\Json
- */
- public function serviceWorkList()
- {
- return $this->dataLists(new ServiceWorkLists());
- }
- /**
- * 派单
- * @return \think\response\Json
- */
- public function assignWorkList()
- {
- return $this->dataLists(new ServiceAssignWorkLists());
- }
- /**
- * 历史工单
- * @return \think\response\Json
- */
- public function historyWorkList()
- {
- return $this->dataLists(new HistoryWorkLists());
- }
- /**
- * 领取服务单
- * @return \think\response\Json
- */
- public function pickWork()
- {
- $params = (new ServiceWorkValidate())->post()->goCheck('pick', [
- 'user_id' => $this->userId,
- 'user_info' => $this->userInfo
- ]);
- $result = ServiceWorkLogic::pickWork($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- // 用户订单被领单通知【给用户的通知】
- $workDetail = ServiceWorkLogic::detail($params);
- event('Notice', [
- 'scene_id' => 114,
- 'params' => [
- 'user_id' => $workDetail['user_id'],
- ]
- ]);
- return $this->success('领取成功', [], 1, 1);
- }
- /**
- * 工单详情
- * @return \think\response\Json
- */
- public function detail()
- {
- try {
- $params = (new ServiceWorkValidate())->goCheck('detail',[
- 'user_id' => $this->userId,
- 'user_info' => $this->userInfo,
- ]);
- if(empty($params['id']) && empty($params['work_sn'])){
- $this->fail('参数错误');
- }
- $result = ServiceWorkLogic::detail($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- return $this->data($result);
- } catch (Exception $e) {
- return $this->fail($e->getMessage());
- }
- }
- /**
- * 获取用户优惠券
- * @return \think\response\Json
- */
- public function getUserCoupons()
- {
- try {
- $params = (new ServiceWorkValidate())->goCheck('detail',[
- 'user_id' => $this->userId,
- ]);
- if(empty($params['id'])){
- $this->fail('参数错误');
- }
- $result = ServiceWorkLogic::getUserCouponDetails($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- return $this->data($result);
- } catch (Exception $e) {
- return $this->fail($e->getMessage());
- }
- }
- /**
- *
- * @return \think\response\Json
- */
- public function getDetailWorkServiceStatus()
- {
- $params = (new ServiceWorkValidate())->goCheck('detail',[
- 'user_id' => $this->userId,
- ]);
- $result = ServiceWorkLogic::getDetailWorkServiceStatus($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- return $this->data($result);
- }
- /**
- * 预约上门
- * @return \think\response\Json
- */
- public function appointWork()
- {
- $params = (new ServiceWorkValidate())->post()->goCheck('appoint', [
- 'user_id' => $this->userId,
- 'user_info' => $this->userInfo
- ]);
- $result = ServiceWorkLogic::appointWork($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- // 工程师预约上门通知【给用户的通知】
- $workDetail = ServiceWorkLogic::detail($params);
- $masterDetail = MasterWorkerLogic::detail(['id'=>$workDetail['master_worker_id']]);
- event('Notice', [
- 'scene_id' => 115,
- 'params' => [
- 'user_id' => $workDetail['user_id'],
- 'date' => $workDetail['appointment_time'],
- 'tel' => asteriskString($masterDetail['mobile'])
- ]
- ]);
- // 工程师预约上门通知【给工程师的通知,仅限公众号】
- event('Notice', [
- 'scene_id' => 116,
- 'params' => [
- 'user_id' => $workDetail['master_worker_id'],
- 'order_id' => $workDetail['id'],
- 'thing5' => $workDetail['title'],
- 'time10' => $workDetail['appointment_time'],
- 'thing3' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
- ]
- ]);
- return $this->success('预约成功,等待上门', [], 1, 1);
- }
- /**
- * 工程师确认上门
- * @return \think\response\Json
- */
- public function confirmDoor()
- {
- $params = (new ServiceWorkValidate())->post()->goCheck('door', [
- 'user_id' => $this->userId,
- 'user_info' => $this->userInfo
- ]);
- $result = ServiceWorkLogic::confirmDoor($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- return $this->success('操作成功,工程师已上门', [], 1, 1);
- }
- /**
- * 工程师确认报价单
- * @return \think\response\Json
- */
- public function confirmPrice()
- {
- $params = (new ServiceWorkValidate())->post()->goCheck('price', [
- 'user_id' => $this->userId,
- 'user_info' => $this->userInfo
- ]);
- $result = ServiceWorkLogic::confirmPrice($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- return $this->success('操作成功,工程师已填写报价单,等待用户确认中', [], 1, 1);
- }
- /**
- * 工程师确认服务完成
- * @return \think\response\Json
- */
- public function confirmServiceFinish()
- {
- $params = (new ServiceWorkValidate())->post()->goCheck('finished', [
- 'user_id' => $this->userId,
- 'user_info' => $this->userInfo
- ]);
- $result = ServiceWorkLogic::confirmServiceFinish($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- return $this->success('操作成功,工程师已确认服务完成,等待用户确认中', [], 1, 1);
- }
- /**
- * 配件列表
- * @return \think\response\Json
- */
- public function spareList()
- {
- // 查全部可选配件
- return $this->dataLists(new SparePartLists());
- }
- /**
- * 工单配件列表
- * @return \think\response\Json
- */
- public function serviceWorkSpareList()
- {
- // 查该订单的配件
- (new ServiceWorkValidate())->get()->goCheck('spare', [
- 'user_id' => $this->userId
- ]);
- return $this->dataLists(new ServiceWorkSparePartLists());
- }
- /**
- * 工单收费标准列表
- * @return \think\response\Json
- */
- public function serviceFeeStandards()
- {
- // 查该订单的配件
- (new GoodsFeeStandardsValidate())->get()->goCheck('standards', [
- 'user_id' => $this->userId
- ]);
- return $this->dataLists(new GoodsFeeStandardsLists());
- }
- /**
- * 预约通知确认
- * @return \think\response\Json
- */
- public function appointmentSubmitNotice()
- {
- $params = (new ServiceWorkValidate())->post()->goCheck('submitAppointment', [
- 'user_id' => $this->userId,
- 'user_info' => $this->userInfo
- ]);
- $result = ServiceWorkLogic::submitAppointment($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- // 工程师再次上门通知【给用户的通知】
- $workDetail = ServiceWorkLogic::detail(['work_sn'=>$params['work_sn']]);
- event('Notice', [
- 'scene_id' => 119,
- 'params' => [
- 'user_id' => $workDetail['user_id'],
- ]
- ]);
- return $this->success('操作成功,已确定新的预约时间', [], 1, 1);
- }
- /**
- * 再次上门
- * @return \think\response\Json
- */
- public function againDoor()
- {
- $params = (new ServiceWorkValidate())->post()->goCheck('againDoor', [
- 'user_id' => $this->userId,
- 'user_info' => $this->userInfo
- ]);
- $result = ServiceWorkLogic::againDoor($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- // 工程师再次上门通知【给用户的通知】
- $workDetail = ServiceWorkLogic::detail(['work_sn'=>$params['work_sn']]);
- event('Notice', [
- 'scene_id' => 119,
- 'params' => [
- 'user_id' => $workDetail['user_id'],
- ]
- ]);
- return $this->success('操作成功,已确定新的预约时间', [], 1, 1);
- }
-
- /**
- * 第一次电话联系客户
- * @return \think\response\Json
- */
- public function contactCustomer()
- {
- $params = (new ServiceWorkValidate())->post()->goCheck('contact', [
- 'user_id' => $this->userId,
- 'user_info' => $this->userInfo
- ]);
- $result = ServiceWorkLogic::contactCustomer($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
-
- return $this->success('成功', [], 1, 1);
- }
- /**
- * 上门码和完成码
- * @return \think\response\Json
- */
- public function showDoorCode(): \think\response\Json
- {
- $params = (new ServiceWorkValidate())->get()->goCheck('door', [
- 'user_id' => $this->userId,
- 'user_info' => $this->userInfo
- ]);
- $result = ServiceWorkLogic::confirmDoorCode($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- return $this->success('操作成功,工程师已上门,请用户扫码确认', $result, 1, 1);
- }
- /**
- * 工程师取消自己的分配
- * @return \think\response\Json
- * @author liugc <466014217@qq.com>
- * @date 2025/4/28 15:08
- */
- public function cancelMasterWorker()
- {
- $params = (new ServiceWorkValidate())->post()->goCheck('cancel', [
- 'user_id' => $this->userId,
- 'user_info' => $this->userInfo
- ]);
- $result = ServiceWorkLogic::cancelAllocation(['id'=>$params['id'],'master_worker_id'=>$this->userId],['admin_id'=>$this->userId,'name'=>'工程师-'.$this->userInfo['mobile']]);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- return $this->success('成功', [], 1, 1);
- }
- /**
- * 工程师抢单池
- * @return \think\response\Json
- * @author liugc <466014217@qq.com>
- * @date 2025/5/7 15:08
- */
- public function grabOrderList()
- {
- return $this->dataLists(new ServiceWorkGrabOrderLists());
- }
- /**
- * 工程师抢单记录列表
- * @return \think\response\Json
- * @author liugc <466014217@qq.com>
- * @date 2025/5/7 15:08
- */
- public function grabOrderLog()
- {
- return $this->dataLists(new ServiceWorkGrabOrderLogLists());
- }
- /**
- * 工程师抢单
- * @return \think\response\Json
- * @author liugc <466014217@qq.com>
- * @date 2025/5/7 15:08
- */
- public function grabOrder()
- {
- $params = (new ServiceWorkValidate())->post()->goCheck('cancel');
- $result = ServiceWorkLogic::grabOrder(['id'=>$params['id'],'master_worker_id'=>$this->userId]);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- return $this->success('抢单成功', [], 1, 1);
- }
- /**
- * 工程师修改自选配件信息
- * @return \think\response\Json
- * @author liugc <466014217@qq.com>
- * @date 2025/5/7 15:08
- */
- public function selfSparePart()
- {
- $params = (new ServiceWorkValidate())->post()->goCheck('sparepart');
- $result = ServiceWorkLogic::selfSparePart($params);
- if (false === $result) {
- return $this->fail(ServiceWorkLogic::getError());
- }
- return $this->success('修改成功', [], 1, 1);
- }
- }
|