|
|
@@ -0,0 +1,107 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller\notify;
|
|
|
+
|
|
|
+use app\api\controller\BaseApiController;
|
|
|
+use app\api\logic\ServiceOrderLogic;
|
|
|
+use app\common\enum\PayEnum;
|
|
|
+use app\common\logic\PayNotifyLogic;
|
|
|
+use app\common\model\external\ExternalPlatform;
|
|
|
+use app\common\model\recharge\RechargeOrder;
|
|
|
+use app\common\model\works\ServiceWork;
|
|
|
+use think\facade\Config;
|
|
|
+
|
|
|
+class InternalApi extends BaseApiController
|
|
|
+{
|
|
|
+ public array $notNeedLogin = ['confirmServiceFinish','paymentSuccessful','cancelOrder'];
|
|
|
+
|
|
|
+ private function checkSign(){
|
|
|
+ $params = $this->request->param();
|
|
|
+ // 验证IP
|
|
|
+
|
|
|
+ $sign = ExternalPlatform::getSign(Config::get('internal_api.api_sign_key'),$params);
|
|
|
+ if ($sign && $sign === $params['sign']) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function confirmServiceFinish()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $params = $this->request->param();
|
|
|
+ if(!$this->checkSign()) throw new \Exception('签名错误',404);
|
|
|
+
|
|
|
+ // 工单信息
|
|
|
+ $service_work = ServiceWork::where('work_sn',$params['work_sn'])->findOrEmpty();
|
|
|
+ if($service_work->isEmpty()) throw new \Exception('工单不存在',404);
|
|
|
+
|
|
|
+ $result = ServiceOrderLogic::confirmServiceFinish([
|
|
|
+ 'sn' => $params['sn'],
|
|
|
+ 'user_id' => $service_work->user_id,
|
|
|
+ 'user_info'=>['real_name' => $service_work->real_name],
|
|
|
+ ]);
|
|
|
+ if (false === $result) {
|
|
|
+ throw new \Exception(ServiceOrderLogic::getError(),404);
|
|
|
+ }
|
|
|
+ // 工程师完单的时候设置该规则关闭,以及短信通知工程师
|
|
|
+ ServiceOrderLogic::orderQuantityRule($params);
|
|
|
+ return $this->success('确认服务完成', [], 0, 1);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ return $this->fail($e->getMessage(),[],$e->getCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function paymentSuccessful()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $params = $this->request->param();
|
|
|
+ if(!$this->checkSign()) throw new \Exception('签名错误',404);
|
|
|
+
|
|
|
+ $params['sn'] = mb_substr($params['sn'], 0, 18);
|
|
|
+ $order = RechargeOrder::where(['sn' => $params['sn']])->findOrEmpty();
|
|
|
+ if($order->isEmpty() || $order->pay_status == PayEnum::ISPAID) {
|
|
|
+ return $this->success('内部支付完成', [], 0, 1);
|
|
|
+ }
|
|
|
+ $payNotifyLogic = PayNotifyLogic::handle('goods', $params['sn'], $params['extra']??[]);
|
|
|
+ if($payNotifyLogic === true){
|
|
|
+ return $this->success('内部支付完成', [], 0, 1);
|
|
|
+ }
|
|
|
+ throw new \Exception($payNotifyLogic,404);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ return $this->fail($e->getMessage(),[],$e->getCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function cancelOrder()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $params = $this->request->param();
|
|
|
+ if(!$this->checkSign()) throw new \Exception('签名错误',404);
|
|
|
+
|
|
|
+ // 工单信息
|
|
|
+ $service_work = ServiceWork::where('work_sn',$params['work_sn'])->findOrEmpty();
|
|
|
+ if($service_work->isEmpty()) throw new \Exception('工单不存在',404);
|
|
|
+
|
|
|
+ //取消订单
|
|
|
+ RechargeOrder::update([
|
|
|
+ 'user_id'=>$service_work->user_id,
|
|
|
+ 'work_id'=>$service_work->id,
|
|
|
+ 'pay_status' => 2,
|
|
|
+ ]);
|
|
|
+ //更新工单状态为已取消
|
|
|
+ $service_work->service_status = 4;
|
|
|
+ $service_work->save();
|
|
|
+
|
|
|
+ return $this->success('内部取消工单完成', [], 0, 1);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ return $this->fail($e->getMessage(),[],$e->getCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|