InternalApiController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\common\controller;
  3. use app\api\logic\ServiceOrderLogic;
  4. use app\common\enum\PayEnum;
  5. use app\common\logic\PayNotifyLogic;
  6. use app\common\model\external\ExternalPlatform;
  7. use app\common\model\recharge\RechargeOrder;
  8. use app\common\model\works\ServiceWork;
  9. use think\facade\Config;
  10. class InternalApiController extends BaseLikeAdminController
  11. {
  12. public array $notNeedLogin = ['confirmServiceFinish','paymentSuccessful','cancelOrder'];
  13. private function checkSign(){
  14. $params = $this->request->param();
  15. // 验证IP
  16. $sign = ExternalPlatform::getSign(env('internal_api.api_sign_key'),$params);
  17. if ($sign && $sign === $params['sign']) {
  18. return true;
  19. }
  20. return false;
  21. }
  22. public function confirmServiceFinish()
  23. {
  24. try {
  25. $params = $this->request->param();
  26. if(!$this->checkSign()) throw new \Exception('签名错误',404);
  27. // 工单信息
  28. $service_work = ServiceWork::where('work_sn',$params['work_sn'])->findOrEmpty();
  29. if($service_work->isEmpty()) throw new \Exception('工单不存在',404);
  30. $result = ServiceOrderLogic::confirmServiceFinish([
  31. 'sn' => $params['sn'],
  32. 'user_id' => $service_work->user_id,
  33. 'user_info'=>['real_name' => $service_work->real_name],
  34. ]);
  35. if (false === $result) {
  36. throw new \Exception(ServiceOrderLogic::getError(),404);
  37. }
  38. // 工程师完单的时候设置该规则关闭,以及短信通知工程师
  39. ServiceOrderLogic::orderQuantityRule($params);
  40. return $this->success('内部确认服务完成', [], 0, 1);
  41. }catch(\Exception $e){
  42. return $this->fail($e->getMessage(),[],$e->getCode());
  43. }
  44. }
  45. public function paymentSuccessful()
  46. {
  47. try {
  48. $params = $this->request->param();
  49. if(!$this->checkSign()) throw new \Exception('签名错误',404);
  50. $params['sn'] = mb_substr($params['sn'], 0, 18);
  51. $order = RechargeOrder::where(['sn' => $params['sn']])->findOrEmpty();
  52. if($order->isEmpty() || $order->pay_status == PayEnum::ISPAID) {
  53. return $this->success('内部支付完成', [], 0, 1);
  54. }
  55. $payNotifyLogic = PayNotifyLogic::handle('goods', $params['sn'], $params['extra']??[]);
  56. if($payNotifyLogic === true){
  57. return $this->success('内部支付完成', [], 0, 1);
  58. }
  59. throw new \Exception($payNotifyLogic,404);
  60. }catch(\Exception $e){
  61. return $this->fail($e->getMessage(),[],$e->getCode());
  62. }
  63. }
  64. public function cancelOrder()
  65. {
  66. try {
  67. $params = $this->request->param();
  68. if(!$this->checkSign()) throw new \Exception('签名错误',404);
  69. // 工单信息
  70. $service_work = ServiceWork::where('work_sn',$params['work_sn'])->findOrEmpty();
  71. if($service_work->isEmpty()) throw new \Exception('工单不存在',404);
  72. //取消订单
  73. RechargeOrder::update([
  74. 'user_id'=>$service_work->user_id,
  75. 'work_id'=>$service_work->id,
  76. 'pay_status' => 2,
  77. ]);
  78. //更新工单状态为已取消
  79. $service_work->service_status = 4;
  80. $service_work->save();
  81. return $this->success('内部取消工单完成', [], 0, 1);
  82. }catch(\Exception $e){
  83. return $this->fail($e->getMessage(),[],$e->getCode());
  84. }
  85. }
  86. }