InternalApi.php 3.6 KB

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