UserConfirmController.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\api\controller\notify;
  3. use app\adminapi\logic\works\ServiceWorkLogic;
  4. use app\api\controller\BaseApiController;
  5. use app\api\logic\LoginLogic;
  6. use app\api\logic\ServiceOrderLogic;
  7. use app\api\validate\UserConfirmValidate;
  8. use app\common\enum\ThirdTypeEnum;
  9. use app\common\logic\ThirdOrderLogic;
  10. use app\common\model\master_worker\MasterWorker;
  11. use app\common\model\recharge\RechargeOrder;
  12. use app\common\model\user\User;
  13. use app\common\model\works\ServiceWork;
  14. use think\Exception;
  15. use think\facade\Log;
  16. /**
  17. *
  18. * Class UserConfirmController
  19. * @package app\api\controller\notify
  20. */
  21. class UserConfirmController extends BaseApiController
  22. {
  23. public array $notNeedLogin = ['confirmDoor','confirmPriceDetail'];
  24. public function confirmDoor()
  25. {
  26. $params = (new UserConfirmValidate())->post()->goCheck('confirmDoor');
  27. try {
  28. $work_sn = decrypt($params['code'], \think\facade\Config::get('project.work_sn_key'));
  29. $work = ServiceWork::where(['work_sn'=>$work_sn,'mobile'=>$params['phone']])->findOrEmpty();
  30. if($work->isEmpty()){
  31. throw new Exception('工单不存在');
  32. }
  33. $params['user_id'] = $work['master_worker_id'];//工程师信息
  34. $params['user_info'] = MasterWorker::where('id',$work['master_worker_id'])->field('worker_number,real_name')->findOrEmpty();//工程师信息
  35. $params['work_sn'] = $work_sn;
  36. $result = ServiceWorkLogic::confirmDoor($params);
  37. if($work->third_type == 1){
  38. $meituan_result = ThirdOrderLogic::updateorderfulfillinfo($work,ThirdTypeEnum::MEITUAN_ARRIVED);
  39. Log::write('美团确认上门'.json_encode($meituan_result));
  40. }
  41. if (false === $result) {
  42. throw new Exception(ServiceWorkLogic::getError());
  43. }
  44. }catch (\Exception $e){
  45. return $this->fail($e->getMessage());
  46. }
  47. return $this->success('已确认上门');
  48. }
  49. public function confirmPriceDetail()
  50. {
  51. $params = (new UserConfirmValidate())->post()->goCheck('confirmDoor');
  52. try {
  53. $work_sn = decrypt($params['code'], \think\facade\Config::get('project.work_sn_key'));
  54. $work = ServiceWork::where(['work_sn'=>$work_sn,'mobile'=>$params['phone']])->findOrEmpty();
  55. if($work->isEmpty()){
  56. throw new Exception('工单不存在');
  57. }
  58. // 先登录得到用户信息
  59. $userInfo = LoginLogic::login(['account'=>$params['phone'],'scene'=>2,'terminal'=>2]);
  60. $userId = User::where('mobile',$params['phone'])->value('id');
  61. $sn = RechargeOrder::where('work_id',$work->id)->where('user_id',$work->user_id)->value('sn');
  62. $result = ServiceOrderLogic::detail([
  63. 'sn' => $sn,
  64. 'user_id' => $userId,
  65. 'user_info' => $userInfo,
  66. 'domain'=>$this->request->domain()
  67. ]);
  68. if (false === $result) {
  69. throw new Exception(ServiceOrderLogic::getError());
  70. }
  71. $result['user_info'] = $userInfo;
  72. return $this->data($result);
  73. }catch (\Exception $e){
  74. return $this->fail($e->getMessage());
  75. }
  76. }
  77. }