Parcourir la source

售后结果通知

shish il y a 3 ans
Parent
commit
66350fa4ca

+ 34 - 2
app-ghs/controllers/RefundController.php

@@ -4,6 +4,9 @@ namespace ghs\controllers;
 
 use bizGhs\order\classes\RefundOrderItemClass;
 use bizGhs\order\services\RefundOrderService;
+use bizGhs\shop\classes\ShopClass;
+use bizHd\cg\classes\CgRefundClass;
+use bizHd\notice\classes\NoticeClass;
 use bizHd\purchase\classes\PurchaseClearClass;
 use common\components\imgUtil;
 use Yii;
@@ -35,6 +38,15 @@ class RefundController extends BaseController
         try {
             RefundOrderService::passRefund($refund);
             $transaction->commit();
+
+            $cgRefundId = $refund->cgRefundId ?? 0;
+            $cgRefund = CgRefundClass::getById($cgRefundId, true);
+            $cgShopId = $cgRefund->shopId ?? 0;
+            $cgShop = ShopClass::getById($cgShopId, true);
+            if (!empty($cgRefund) && !empty($cgShop)) {
+                NoticeClass::afterSaleNotice($cgShop, $cgRefund);
+            }
+
             util::complete('操作成功');
         } catch (\Exception $e) {
             $transaction->rollBack();
@@ -56,8 +68,28 @@ class RefundController extends BaseController
         $rejectReason = $post['rejectReason'] ?? '';
         $refund = RefundOrderClass::getById($id, true);
         RefundOrderClass::valid($refund, $this->mainId);
-        RefundOrderClass::rejectRefund($refund, $rejectReason);
-        util::complete('操作成功');
+
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+
+            RefundOrderClass::rejectRefund($refund, $rejectReason);
+            $transaction->commit();
+
+            $cgRefundId = $refund->cgRefundId ?? 0;
+            $cgRefund = CgRefundClass::getById($cgRefundId, true);
+            $cgShopId = $cgRefund->shopId ?? 0;
+            $cgShop = ShopClass::getById($cgShopId, true);
+            if (!empty($cgRefund) && !empty($cgShop)) {
+                NoticeClass::afterSaleNotice($cgShop, $cgRefund);
+            }
+
+            util::complete('操作成功');
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("操作失败原因:" . $e->getMessage());
+            util::fail('操作失败');
+        }
     }
 
     //退款之后报损 ssh 20230409

+ 55 - 0
biz-hd/notice/classes/NoticeClass.php

@@ -14,6 +14,61 @@ use Yii;
 class NoticeClass extends BaseClass
 {
 
+    //售后结果通知 ssh 20230813
+    public static function afterSaleNotice($shop, $refund)
+    {
+        $result = [];
+        $mainId = $shop->mainId ?? 0;
+        $staffList = StaffClass::getAllByCondition(['mainId' => $mainId], null, 'adminId');
+        $merchant = WxOpenClass::getWxInfo();
+        $ptStyle = dict::getDict('ptStyle', 'hd');
+        if (getenv('YII_ENV') == 'production') {
+            $msgList = dict::getDict('hdMiniMessage');
+        } else {
+            $msgList = dict::getDict('hdMiniMessageDev');
+        }
+        $msgId = $msgList['afterSale']['msgId'] ?? '';
+        if (empty($msgId)) {
+            return $result;
+        }
+        if (!empty($staffList)) {
+            $ids = array_column($staffList, 'adminId');
+            if (!empty($ids)) {
+                $adminList = AdminClass::getByIds($ids);
+                if (!empty($adminList)) {
+                    $orderSn = $refund->orderSn ?? '';
+                    $refundType = $refund->refundType ?? 1;
+                    $name = $refundType == 1 ? '退货退款' : '只退款';
+                    $addTime = $refund->addTime ?? '';
+                    $status = $refund->status ?? 0;
+                    $statusName = '已通过';
+                    if ($status == 2) {
+                        $statusName = '已驳回';
+                    }
+                    foreach ($adminList as $admin) {
+                        $miniOpenId = $admin['miniOpenId'] ?? '';
+                        if (!empty($miniOpenId)) {
+                            $msg = [
+                                "thing4" => ["value" => $name],
+                                "time5" => ["value" => $addTime],
+                                "character_string3" => ["value" => $orderSn],
+                                "phrase2" => ["value" => $statusName],
+                                "thing6" => ["value" => "点击查看详情"],
+                            ];
+                            $page = 'pagesPurchase/refundDetail?id=' . $refund->id;
+                            Yii::info(json_encode($msg));
+                            $respond = miniUtil::commonSendSubscribeMessage($merchant, $ptStyle, $msgId, $miniOpenId, $page, $msg);
+                            if (isset($respond['errcode']) && $respond['errcode'] === 0) {
+                                $result['hasNotice'] = 1;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return $result;
+    }
+
     //有新的结账单 ssh 20230514
     public static function newClearNotice($shop, $clear)
     {