Преглед изворни кода

Merge remote-tracking branch 'origin/master'

林海涛 пре 1 година
родитељ
комит
43b0761efd

+ 1 - 1
app/api/controller/IssueWorkController.php

@@ -53,7 +53,7 @@ class IssueWorkController extends BaseApiController
         if (false === $result) {
             return $this->fail(IssueWorkLogic::getError());
         }
-        return $this->success('投诉成功', [], 1, 1);
+        return $this->success('投诉成功', ['id'=>$result], 1, 1);
     }
 
     public function complaintInfo()

+ 6 - 8
app/api/logic/IssueWorkLogic.php

@@ -38,13 +38,11 @@ class IssueWorkLogic extends BaseLogic
 
 
     /**
-     * @notes 添加
+     * 添加
      * @param array $params
-     * @return bool
-     * @author likeadmin
-     * @date 2024/07/10 15:06
+     * @return false|int|string
      */
-    public static function add(array $params): bool
+    public static function add(array $params)
     {
         Db::startTrans();
         try {
@@ -56,7 +54,8 @@ class IssueWorkLogic extends BaseLogic
             if($work['work_status']!=8){
                 throw new Exception('订单暂未结束,不允许投诉,请直接联系客服');
             }
-            IssueWork::create([
+            $IssueWork = new IssueWork();
+            $id = $IssueWork->insertGetId([
                 'sn' => $params['sn'],
                 'work_sn' => $work['work_sn'],
                 'service_work_id' => $work['id'],
@@ -68,9 +67,8 @@ class IssueWorkLogic extends BaseLogic
                 'complaint_mobile'=>$params['complaint_mobile'],
                 'user_id'=>$params['user_id']
             ]);
-
             Db::commit();
-            return true;
+            return $id;
         } catch (\Exception $e) {
             Db::rollback();
             self::setError($e->getMessage());

+ 0 - 1
app/api/logic/PerformanceLogic.php

@@ -31,7 +31,6 @@ class PerformanceLogic extends BaseLogic
             $work->work_pay_status = 2;
         }
         $work->save();
-
         //师傅金额结算
         if(!$rule->isEmpty()){
             if($rule['type']==0){

+ 1 - 1
app/common/logic/EffectiveLogic.php

@@ -20,7 +20,7 @@ class EffectiveLogic extends BaseLogic
                 'effective_id' => $effective->effectiveRule->id,
                 'sn' => $orderGoods['sn'],
                 'user_id' => $work['user_id'],
-                'work_id' => $work->work_id,
+                'work_id' => $work->id,
                 'goods_id' => $orderGoods->goods_id,
                 'effective_unit' => $effective->effectiveRule->effective_unit,
                 'effective_num' => $effective->effectiveRule->effective_num,

+ 24 - 20
app/common/logic/PayNotifyLogic.php

@@ -92,33 +92,37 @@ class PayNotifyLogic extends BaseLogic
     public static function goods($orderSn, array $extra = [])
     {
         $order = RechargeOrder::where('sn', $orderSn)->findOrEmpty();
+
         if(!$order->isEmpty()){
             // 更新充值订单状态
             $order->transaction_id = $extra['transaction_id'] ?? '';
             $order->pay_status = PayEnum::ISPAID;
             $order->pay_time = time();
             $order->save();
-        }
-        $work = ServiceWork::findOrEmpty($order->work_id);
-        if(!$work->isEmpty()){
-            $work->work_pay_status = WorkEnum::IS_PAY_STATUS;
-            $orders = \app\common\model\orders\RechargeOrder::where(['work_id'=>$order->work_id])->select()->toArray();
-            $order_total = 0;
-            $order_amount = 0;
-            foreach ($orders as $k=>$v){
-                $order_total += $v['order_total'];
-                $order_amount += $v['order_amount'];
-            }
-            $work->work_total = $order_total;
-            $work->work_amount = $order_amount;
-            if($work->work_status != 0){
-                $work->work_status = 7;
-                $work->user_confirm_status = 5;
-                $work->service_status = 3;
+            $work = ServiceWork::findOrEmpty($order->work_id);
+
+            if(!$work->isEmpty()){
+                $work->work_pay_status = WorkEnum::IS_PAY_STATUS;
+
+                $orders = \app\common\model\orders\RechargeOrder::where(['work_id'=>$order->work_id])->select()->toArray();
+
+                $order_total = 0;
+                $order_amount = 0;
+                foreach ($orders as $k=>$v){
+                    $order_total += $v['order_total'];
+                    $order_amount += $v['order_amount'];
+                }
+                $work->work_total = $order_total;
+                $work->work_amount = $order_amount;
+                if($work->work_status != 0){
+                    $work->work_status = 7;
+                    $work->user_confirm_status = 5;
+                    $work->service_status = 3;
+                }
+                $work->work_pay_status = 1;
+                $work->finished_time = time();
+                $work->save();
             }
-            $work->work_pay_status = 1;
-            $work->finished_time = time();
-            $work->save();
         }
     }
 

+ 0 - 1
app/common/service/pay/WeChatPayService.php

@@ -372,7 +372,6 @@ class WeChatPayService extends BasePayService
         $server = $this->app->getServer();
         // 支付通知
         $server->handlePaid(function (Message $message) {
-            Log::write(json_encode($message, JSON_UNESCAPED_UNICODE),'info');
             if ($message['trade_state'] === 'SUCCESS') {
                 $extra['transaction_id'] = $message['transaction_id'];
                 $attach = $message['attach'];

+ 45 - 1
app/common/service/pay/WorkerWeChatPayService.php

@@ -57,7 +57,9 @@ class WorkerWeChatPayService extends BasePayService
         $this->terminal = $terminal;
         $this->config = WeChatConfigService::getPayConfigByTerminal($terminal);
         $this->app = new Application($this->config);
-        $this->auth = MasterWorkerAuth::where(['worker_id' => $userId, 'terminal' => $terminal])->findOrEmpty();
+        if ($userId !== null) {
+            $this->auth = MasterWorkerAuth::where(['worker_id' => $userId, 'terminal' => $terminal])->findOrEmpty();
+        }
     }
 
 
@@ -171,4 +173,46 @@ class WorkerWeChatPayService extends BasePayService
     {
         return $this->app->getUtils()->buildBridgeConfig($prepayId, $appId);
     }
+
+    /**
+     * @notes 支付回调
+     * @return \Psr\Http\Message\ResponseInterface
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
+     * @throws \ReflectionException
+     * @throws \Throwable
+     * @author 段誉
+     * @date 2023/2/28 14:20
+     */
+    public function notify()
+    {
+        $server = $this->app->getServer();
+        // 支付通知
+        $server->handlePaid(function (Message $message) {
+            if ($message['trade_state'] === 'SUCCESS') {
+                $extra['transaction_id'] = $message['transaction_id'];
+                $attach = $message['attach'];
+                $message['out_trade_no'] = mb_substr($message['out_trade_no'], 0, 18);
+                $order = RechargeOrder::where(['sn' => $message['out_trade_no']])->findOrEmpty();
+                if($order->isEmpty() || $order->pay_status == PayEnum::ISPAID) {
+                    return true;
+                }
+                switch ($attach) {
+                    case 'recharge':
+                        PayNotifyLogic::handle('recharge', $message['out_trade_no'], $extra);
+                        break;
+                    case 'goods':
+                        PayNotifyLogic::handle('goods', $message['out_trade_no'], $extra);
+                        break;
+                }
+            }
+            return true;
+        });
+
+        // 退款通知
+        $server->handleRefunded(function (Message $message) {
+            return true;
+        });
+        return $server->serve();
+    }
 }

+ 4 - 1
app/workerapi/controller/PayController.php

@@ -6,6 +6,8 @@ use app\common\enum\user\UserTerminalEnum;
 use app\common\logic\PaymentLogic;
 use app\common\service\pay\AliPayService;
 use app\common\service\pay\WeChatPayService;
+use app\common\service\pay\WorkerWeChatPayService;
+use think\facade\Log;
 
 /**
  * 支付
@@ -14,6 +16,7 @@ use app\common\service\pay\WeChatPayService;
  */
 class PayController extends \app\workerapi\controller\BaseApiController
 {
+    public array $notNeedLogin = ['notifyMnp'];
 
     /**
      * @notes 工程师代支付
@@ -62,6 +65,6 @@ class PayController extends \app\workerapi\controller\BaseApiController
      */
     public function notifyMnp()
     {
-        return (new WeChatPayService(UserTerminalEnum::WECHAT_MMP))->notify();
+        return (new WorkerWeChatPayService(UserTerminalEnum::WECHAT_MMP))->notify();
     }
 }

+ 1 - 1
config/database.php

@@ -52,7 +52,7 @@ return [
             // 是否需要断线重连
             'break_reconnect' => false,
             // 监听SQL
-            'trigger_sql'     => env('app_debug', false),
+            'trigger_sql'     => false,
             // 开启字段缓存
             'fields_cache'    => false,
         ],