| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace app\common\controller;
- 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;
- use think\facade\Log;
- class InternalApiController extends BaseLikeAdminController
- {
- public array $notNeedLogin = ['changeAppointment','confirmServiceFinish','paymentSuccessful','cancelOrder'];
- private function checkSign(){
- $params = $this->request->param();
- // 验证IP
- Log::info('内部请求参数'.json_encode($params));
- $sign = ExternalPlatform::getSign(env('internal_api.api_sign_key'),$params);
- if ($sign && $sign === $params['sign']) {
- return true;
- }
- return false;
- }
- public function changeAppointment()
- {
- try {
- $params = $this->request->param();
- if(!$this->checkSign()) throw new \Exception('签名错误',404);
- //sn appointment_time
- if(!isset($params['appointment_time']) || empty($params['appointment_time'])){
- throw new \Exception('预约时间不能为空',404);
- }
- if(!isset($params['sn']) || empty($params['sn'])){
- throw new \Exception('订单号不能为空',404);
- }
- $result = ServiceOrderLogic::approvalChangeAppointment($params);
- if (false === $result) {
- throw new \Exception(ServiceOrderLogic::getError(),404);
- }
- return $this->success('内部重新预约完成', [], 0, 1);
- }catch(\Exception $e){
- return $this->fail($e->getMessage(),[],$e->getCode());
- }
- }
- 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);
- if($service_work->user_confirm_status < 3){
- throw new \Exception('正在服务中,请稍后再试...',404);
- }
- if(in_array($service_work->service_status,[3,4,5])){
- return $this->success('内部确认服务完成', [], 0, 1);
- }
- $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()) {
- throw new \Exception('内部订单不存在:'.$params['sn'],404);
- }
- if($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::where(['user_id'=>$service_work->user_id,'work_id'=>$service_work->id])->update([
- '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());
- }
- }
- }
|