UserConfirmController.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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'];
  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 || ($work->external_platform_id > 0)){
  38. http_request('https://developer.kyjlkj.com/platf/performanceNotice', http_build_query([
  39. 'external_platform_id'=> $work->external_platform_id,
  40. 'send_code'=>1003,
  41. 'work_sn'=>$work['work_sn'],
  42. ]));
  43. $meituan_result = ThirdOrderLogic::updateorderfulfillinfo($work,ThirdTypeEnum::MEITUAN_ARRIVED);
  44. Log::write('美团确认上门'.json_encode($meituan_result));
  45. }
  46. if (false === $result) {
  47. throw new Exception(ServiceWorkLogic::getError());
  48. }
  49. }catch (\Exception $e){
  50. return $this->fail($e->getMessage());
  51. }
  52. return $this->success('已确认上门');
  53. }
  54. public function confirmPriceDetail()
  55. {
  56. $params = (new UserConfirmValidate())->post()->goCheck('confirmDoor');
  57. try {
  58. $work_sn = decrypt($params['code'], \think\facade\Config::get('project.work_sn_key'));
  59. $work = ServiceWork::where(['work_sn'=>$work_sn,'mobile'=>$params['phone']])->findOrEmpty();
  60. if($work->isEmpty()){
  61. throw new Exception('工单不存在');
  62. }
  63. // 先登录得到用户信息
  64. $userInfo = LoginLogic::login(['account'=>$params['phone'],'scene'=>2,'terminal'=>2]);
  65. $userId = User::where('mobile',$params['phone'])->value('id');
  66. $sn = RechargeOrder::where('work_id',$work->id)->where('user_id',$work->user_id)->value('sn');
  67. $result = ServiceOrderLogic::detail([
  68. 'sn' => $sn,
  69. 'user_id' => $userId,
  70. 'user_info' => $userInfo,
  71. 'domain'=>$this->request->domain()
  72. ]);
  73. if (false === $result) {
  74. throw new Exception(ServiceOrderLogic::getError());
  75. }
  76. $result['user_info'] = $userInfo;
  77. return $this->data($result);
  78. }catch (\Exception $e){
  79. return $this->fail($e->getMessage());
  80. }
  81. }
  82. }