From f53d5f8f24e5ec86c59dbd03fa403ab6da9a636e Mon Sep 17 00:00:00 2001
From: luofei <604446095@qq.com>
Date: Tue, 30 Jan 2024 16:23:59 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=80=80=E8=BF=98=E7=BA=A2?=
 =?UTF-8?q?=E5=8C=85=E7=9A=84=E9=94=99=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/common/dao/store/StoreActivityOrderDao.php |  8 +++++---
 .../dao/store/consumption/CommissionDao.php    | 18 ++++++++++--------
 .../consumption/StoreConsumptionUserDao.php    |  2 +-
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/app/common/dao/store/StoreActivityOrderDao.php b/app/common/dao/store/StoreActivityOrderDao.php
index e212cca6..d9f7310d 100755
--- a/app/common/dao/store/StoreActivityOrderDao.php
+++ b/app/common/dao/store/StoreActivityOrderDao.php
@@ -62,9 +62,11 @@ class StoreActivityOrderDao extends BaseDao
     public function repeal(int $groupOrderId)
     {
         $model = StoreActivityOrder::where('group_order_id', $groupOrderId)->find();
-        $model->status = StoreActivityOrder::STATUS_INVALID;
-        if (!$model->save()) {
-            throw new \Exception('活动订单保存失败');
+        if ($model) {
+            $model->status = StoreActivityOrder::STATUS_INVALID;
+            if (!$model->save()) {
+                throw new \Exception('活动订单保存失败');
+            }
         }
     }
 
diff --git a/app/common/dao/store/consumption/CommissionDao.php b/app/common/dao/store/consumption/CommissionDao.php
index 56c4115f..74489f6f 100755
--- a/app/common/dao/store/consumption/CommissionDao.php
+++ b/app/common/dao/store/consumption/CommissionDao.php
@@ -6,10 +6,9 @@ use app\common\dao\system\financial\FinancialDao;
 use app\common\model\store\consumption\StoreConsumption;
 use app\common\model\store\consumption\StoreConsumptionUser;
 use app\common\model\store\order\StoreOrder;
-use app\common\model\system\financial\Financial;
+use app\common\model\system\merchant\FinancialRecord;
 use app\common\model\system\merchant\Merchant;
 use app\common\model\user\User;
-use app\common\repositories\system\merchant\FinancialRecordRepository;
 use app\common\repositories\system\merchant\MerchantRepository;
 use crmeb\utils\Curl;
 use think\facade\Log;
@@ -140,7 +139,7 @@ class CommissionDao
         $iv = $aes->buildIv($timestamp);
         $encrypt = $aes->encrypt($json, $iv);
         $api = in_array($type, [1, 2]) ? 'user_first_order_share_profit' : 'user_order_share_profit';
-        $url = env('task.worker_host_url') . '/api/shop_call/' . $api;
+        $url = env('task.new_worker_host_url') . '/api/shop_call/' . $api;
         $result = $curl->post($url, ['timestamp' => $timestamp, 'data' => $encrypt]);
         $result = json_decode($result, true);
         if ($result['code'] != 1) {
@@ -156,7 +155,7 @@ class CommissionDao
     public function refundByOrder($refundOrder)
     {
         // 是否已经退过佣金
-        $refunded = Financial::where('order_id', $refundOrder->order['order_id'])
+        $refunded = FinancialRecord::where('order_id', $refundOrder->order['order_id'])
             ->whereIn('financial_type', ['order_commission_refund', 'first_order_commission_refund'])
             ->count();
         if ($refunded > 0) {
@@ -164,7 +163,7 @@ class CommissionDao
         }
         $commission = bcmul($refundOrder->order['pay_price'], 0.01, 2);
         $financeDao = new FinancialDao();
-        if ($commission > 0 && $refundOrder->order['order_type'] == 1) {
+        if ($commission > 0 && $refundOrder->order['order_type'] == 1 && $refundOrder->order['source'] != 105) {
             // 订单为自提,且佣金大于0,下单的店铺退佣金
             $financeDao->user = $refundOrder->order->user;
             $financeDao->order = $refundOrder->order;
@@ -173,15 +172,18 @@ class CommissionDao
         }
 
         // 退佣金和红包
-        $financeRecord = Financial::where('order_id', $refundOrder->order['order_id'])
+        $financeRecord = FinancialRecord::where('order_id', $refundOrder->order['order_id'])
             ->whereIn('financial_type', ['order_commission', 'first_order_commission'])
             ->field('user_id uid,user_info nickname')->select()->toArray();
+        if (empty($financeRecord)) {
+            return;
+        }
         $redPack = bcmul($refundOrder->order['pay_price'], 0.07, 2);
-        (new StoreConsumptionUserDao())->refundByCommission($refundOrder->order['uid'], $refundOrder->order->order_id, $redPack);
         foreach ($financeRecord as $item) {
             $financeDao->user = $item;
             $financeDao->order = $refundOrder->order;
             $financeDao->platformIn($item['number'], $item['financial_type'] . '_refund');
+            (new StoreConsumptionUserDao())->refundByCommission($item['uid'], $refundOrder->order->order_id, $redPack);
         }
         $financeDao->save();
 
@@ -193,7 +195,7 @@ class CommissionDao
             $json = ['timestamp' => $timestamp, 'data' => ['order_sn' => $refundOrder->order['order_sn']]];
             $iv = $aes->buildIv($timestamp);
             $encrypt = $aes->encrypt($json, $iv);
-            $url = env('task.worker_host_url') . '/api/shop_call/handleRefund';
+            $url = env('task.new_worker_host_url') . '/api/shop_call/handleRefund';
             $result = $curl->post($url, ['timestamp' => $timestamp, 'data' => $encrypt]);
             $result = json_decode($result, true);
             if ($result['code'] != 1) {
diff --git a/app/common/dao/store/consumption/StoreConsumptionUserDao.php b/app/common/dao/store/consumption/StoreConsumptionUserDao.php
index 3a507c01..9e8c7876 100755
--- a/app/common/dao/store/consumption/StoreConsumptionUserDao.php
+++ b/app/common/dao/store/consumption/StoreConsumptionUserDao.php
@@ -380,7 +380,7 @@ class StoreConsumptionUserDao extends BaseDao
     {
         $order = StoreOrder::where('order_id', $refundOrder['order_id'])->find();
         $model = StoreConsumptionUser::where('uid', $refundOrder['uid'])->where('coupon_user_id', $order['consumption_id'])->find();
-        if (empty($model)) {
+        if (empty($model) || $order['source'] == 105) {
             return;
         }
         $model->balance = bcadd($model->balance, $refundOrder['refund_consumption'], 2);