瀏覽代碼

零售订单退款

shish 4 年之前
父節點
當前提交
6aec7df35d

+ 10 - 24
app-hd/controllers/OrderController.php

@@ -60,7 +60,7 @@ class OrderController extends BaseController
                 require_once($wx . '/example/WxPay.MicroPay.php');
 
                 //获取微信商户号等信息
-                $sjExtend = WxOpenClass::getWxInfo();
+                $sjExtend = WxOpenClass::getMallWxInfo();
 
                 $microPay = new \MicroPay();
                 $payReturn = $microPay->query($orderSn, $sjExtend);
@@ -197,7 +197,7 @@ class OrderController extends BaseController
                 $input->SetOut_trade_no($orderSn);
 
                 //获取微信商户号等信息
-                $sjExtend = WxOpenClass::getWxInfo();
+                $sjExtend = WxOpenClass::getMallWxInfo();
 
                 $microPay = new \MicroPay();
                 $res = $microPay->pay($input, $sjExtend);
@@ -657,7 +657,7 @@ class OrderController extends BaseController
         $post = Yii::$app->request->post();
         $id = $post['id'];
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->shopId);
+        OrderService::valid($order, $this->mainId);
         if ($order['grade'] > 0) {
             util::fail('您已经评过了');
         }
@@ -669,22 +669,8 @@ class OrderController extends BaseController
     public function actionDetail()
     {
         $id = Yii::$app->request->get('id', 0);
-        $orderSn = Yii::$app->request->get('orderSn', '');
-        $detail = [];
-        if (!empty($id)) {
-            $detail = OrderService::getOrderById($id);
-        }
-        if (!empty($orderSn)) {
-            $detail = OrderService::getOrderBySn($orderSn);
-        }
-        OrderService::valid($detail, $this->shopId);
-
-        //因前端未修改,这里先做一下兼容,好像打印时要调用到
-        $detail['receiveProvince'] = $detail['province'] ?? '';
-        $detail['receiveCity'] = $detail['city'] ?? '';
-        $detail['receiveAddress'] = $detail['address'] ?? '';
-        $detail['receiveFloor'] = $detail['floor'] ?? '';
-
+        $detail = OrderClass::getFullInfo($id);
+        OrderService::valid($detail, $this->mainId);
         util::success($detail);
     }
 
@@ -728,7 +714,7 @@ class OrderController extends BaseController
         $post = Yii::$app->request->post();
         $id = isset($post['id']) ? $post['id'] : 0;
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->shopId);
+        OrderService::valid($order, $this->mainId);
         $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
         $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
         OrderService::classify($id, $categoryId, $usageId);
@@ -742,7 +728,7 @@ class OrderController extends BaseController
         $id = isset($post['id']) ? $post['id'] : 0;
         unset($post['id']);
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->shopId);
+        OrderService::valid($order, $this->mainId);
         OrderService::updateSheet($order, $post);
         util::complete('提交成功');
     }
@@ -798,7 +784,7 @@ class OrderController extends BaseController
     {
         $id = Yii::$app->request->get('id');
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->shopId);
+        OrderService::valid($order, $this->mainId);
         //配送流程变更
         $currentFlow = OrderSendClass::withoutSend($order);
         util::success(['currentFlow' => $currentFlow]);
@@ -810,7 +796,7 @@ class OrderController extends BaseController
         $id = Yii::$app->request->get('id');
         $price = Yii::$app->request->get('price', 1);
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->shopId);
+        OrderService::valid($order, $this->mainId);
         if (isset($order['modPrice']) && $order['modPrice'] == 0) {
             util::fail('已发起支付,不能修改价格');
         }
@@ -823,7 +809,7 @@ class OrderController extends BaseController
     {
         $id = Yii::$app->request->get('id', 0);
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->shopId);
+        OrderService::valid($order, $this->mainId);
         $reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
         $reachPeriodId = $order['reachPeriod'];
         $reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];

+ 115 - 0
app-hd/controllers/RefundController.php

@@ -0,0 +1,115 @@
+<?php
+//退款退货
+namespace hd\controllers;
+
+use bizHd\order\classes\OrderClass;
+use bizHd\refund\classes\HdRefundClass;
+use bizHd\refund\classes\HdRefundGoodsClass;
+use bizHd\refund\classes\HdRefundItemClass;
+use bizHd\refund\services\HdRefundService;
+use Yii;
+use common\components\util;
+
+class RefundController extends BaseController
+{
+
+    //列表
+    public function actionList()
+    {
+        $get = Yii::$app->request->get();
+        $where = [];
+        $where['mainId'] = $this->mainId;
+        $orderSn = $get['orderSn'] ?? '';
+        if (!empty($orderSn)) {
+            $where['relateOrderSn'] = $orderSn;
+        }
+        $list = HdRefundClass::getOrderList($where);
+        util::success($list);
+    }
+
+    //退款单详情 ssh 20220427
+    public function actionDetail()
+    {
+        $id = Yii::$app->request->get('id', 0);
+        $refund = HdRefundClass::getById($id, true);
+        HdRefundClass::valid($refund, $this->mainId);
+        $orderSn = $refund->orderSn ?? '';
+        $itemList = HdRefundItemClass::getItemListBySn($orderSn);
+        $goodsList = HdRefundGoodsClass::getGoodsListBySn($orderSn);
+        util::success(['info' => $refund, 'itemList' => $itemList, 'goodsList' => $goodsList]);
+    }
+
+    //退款 ssh 20220427
+    public function actionCreateOrder()
+    {
+        $shopAdmin = $this->shopAdmin;
+        if (isset($shopAdmin['super']) == false || $shopAdmin['super'] != 1) {
+            util::fail('超管才能操作退款');
+        }
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+
+            $post = Yii::$app->request->post();
+            $id = isset($post['id']) ? $post['id'] : 0;
+            $order = OrderClass::getById($id, true);
+            OrderClass::valid($order, $this->mainId);
+            if ($order->status != OrderClass::ORDER_STATUS_COMPLETE) {
+                util::fail("完成的订单才能发起退款");
+            }
+            $addTime = $order->addTime ?? '';
+            $current = time();
+            if ((strtotime($addTime) + 3 * 30 * 24 * 60 * 60) < $current) {
+                util::fail('历史订单,不能再发起退款');
+            }
+            if (strtotime($addTime) <= strtotime('2022-03-30 00:00:00')) {
+                util::fail('历史订单,不能发起退款哦');
+            }
+            //退款类型 1退货并退款 2 仅退款
+            $refundType = $post['refundType'] ?? 1;
+
+            if ($refundType == HdRefundClass::REFUND_TYPE_MONEY_GOOD) {
+                //商品花材结构 property 0成品 1花材
+                //[{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎',property:1}]
+                $productJson = $post['product'] ?? '';
+                if (empty($productJson)) {
+                    util::fail('请选择商品');
+                }
+                $productList = json_decode($productJson, true);
+                if (!is_array($productList)) {
+                    util::fail('请选择商品哦');
+                }
+
+                $post['product'] = $productList;
+            } else {
+                //仅退款商品花材直接设置为空
+                $post['product'] = [];
+            }
+            $post['price'] = $post['price'] ?? 0;
+            if ($post['price'] <= 0) {
+                util::fail("退款金额不能小于0");
+            }
+            if (bccomp($post['price'], $order['orderPrice'], 2) == 1) {
+                util::fail("退款金额超过订单金额");
+            }
+
+            $post['shopId'] = $this->shopId;
+            $post['sjId'] = $this->sjId;
+            $post['shopAdminId'] = $this->shopAdminId;
+            $post['mainId'] = $this->mainId;
+            $shopAdmin = $this->shopAdmin;
+            $adminName = $shopAdmin['name'] ?? '';
+            $post['shopAdminName'] = $adminName;
+            HdRefundService::addRefund($id, $post);
+            $transaction->commit();
+
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            Yii::info("出错了:" . $exception->getMessage());
+            util::fail('操作失败');
+        }
+        util::complete();
+    }
+
+}

+ 72 - 0
app-mall/controllers/NoticeController.php

@@ -2,6 +2,8 @@
 
 namespace mall\controllers;
 
+use bizHd\wx\classes\WxOpenClass;
+use common\components\noticeUtil;
 use common\components\payUtil;
 use Yii;
 use common\components\util;
@@ -10,6 +12,76 @@ use common\components\dict;
 class NoticeController extends PublicController
 {
 
+    //微信退款结果通知
+    public function actionWxRefundCallback()
+    {
+        $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
+        if (empty($postStr)) {
+            util::end();
+        }
+        $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
+        if ($postObj->return_code != 'SUCCESS') {
+            $msg = $postObj->return_msg ?? '';
+            $text = '微信退款结果通知,报错了,报错内容:' . $msg;
+            Yii::warning($text);
+            noticeUtil::push($text, '15280215347');
+            util::end();
+        }
+
+        //解密req_info
+        $wx = WxOpenClass::getWxInfo();
+        $req_info = $postObj->req_info ?? '';
+        $key = $wx['wxPayKey'] ?? '';
+        $xml = openssl_decrypt(base64_decode($req_info), 'AES-256-ECB', MD5($key), OPENSSL_RAW_DATA, '');
+        $req_info_obj = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
+
+        $refund_status = $req_info_obj->refund_status ?? '';
+
+        $orderSn = $req_info_obj->out_trade_no ?? '';
+        $out_refund_no = $req_info_obj->out_refund_no ?? '';
+        //订单总金额
+        $total_fee = $req_info_obj->total_fee ?? 0.00;
+        //申请退款金额
+        //$refund_fee = $req_info_obj->refund_fee ?? 0.00;
+        //退款金额
+        $settlement_refund_fee = $req_info_obj->settlement_refund_fee ?? 0.00;
+
+        $new_total_fee = bcdiv($total_fee, 100, 2);
+        $new_total_fee = floatval($new_total_fee);
+        $new_settlement_refund_fee = bcdiv($settlement_refund_fee, 100, 2);
+        $new_settlement_refund_fee = floatval($new_settlement_refund_fee);
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            if ($refund_status == 'SUCCESS') {
+                $cgRefund = HdRefundClass::getByCondition(['orderSn' => $out_refund_no], true);
+                if (!empty($cgRefund)) {
+                    $cgRefund->status = HdRefundClass::STATUS_COMPLETE;
+                    $cgRefund->save();
+                    $saleRefundId = $cgRefund->saleRefundId ?? 0;
+                    $saleRefund = RefundOrderClass::getById($saleRefundId, true);
+                    if (!empty($saleRefund)) {
+                        $saleRefund->status = RefundOrderClass::STATUS_COMPLETE;
+                        $saleRefund->save();
+                    }
+                }
+                $text = "【退款成功】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
+            } elseif ($refund_status == 'REFUNDCLOSE') {
+                $text = "【退款关闭】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
+            } else {
+                $text = "【退款失败】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
+            }
+            $transaction->commit();
+            noticeUtil::push($text, '15280215347');
+            echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::error("失败原因:" . $e->getMessage());
+        }
+
+    }
+
     //微信支付异步回调
     public function actionWxCallback()
     {

+ 9 - 0
biz-ghs/stock/classes/StockRecordClass.php

@@ -28,6 +28,7 @@ class StockRecordClass extends BaseClass
     const STOCK_RECORD_TYPE_GOODS_WASTAGE = 13;//制作成品损耗
     const STOCK_RECORD_TYPE_GOODS_CONSUME_CANCEL = 14;//取消制作
     const STOCK_RECORD_TYPE_GOODS_WASTAGE_CANCEL = 15;//取消制作已报损
+    const STOCK_RECORD_TYPE_HD_REFUND = 16;//花店退货退款
 
     public static $typeMap = [
         self::STOCK_RECORD_TYPE_PURCHASE => '采购入库',
@@ -45,6 +46,7 @@ class StockRecordClass extends BaseClass
         self::STOCK_RECORD_TYPE_GOODS_WASTAGE => '制作成品损耗',
         self::STOCK_RECORD_TYPE_GOODS_CONSUME_CANCEL => '取消制作',
         self::STOCK_RECORD_TYPE_GOODS_WASTAGE_CANCEL => '取消制作损耗',
+        self::STOCK_RECORD_TYPE_HD_REFUND => '退货退款',
     ];
 
     public static function getRecordList($where)
@@ -195,6 +197,13 @@ class StockRecordClass extends BaseClass
         return self::addRecord($data);
     }
 
+    //零售花店退货退款 ssh 20220427
+    public static function hdRefundAddRecord($data)
+    {
+        $data['recordType'] = self::STOCK_RECORD_TYPE_HD_REFUND;
+        return self::addRecord($data);
+    }
+
     //制作成品 lqh 2022.03.20
     public static function makeGoodsConsume($data)
     {

+ 4 - 1
biz-hd/goods/classes/GoodsClass.php

@@ -435,9 +435,12 @@ class GoodsClass extends BaseClass
             util::unlock($key);
             util::fail("非法参数");
         }
-
         //改库存
         $newStock = $goodsData['stock'] - $num;
+        if ($newStock < 0) {
+            $goodsName = $goodsData['name'] ?? '';
+            util::fail($goodsName . '库存不足,剩余:' . $goodsData['stock']);
+        }
         $data['stock'] = $newStock;
         self::updateById($goodsId, $data);
         util::unlock($key);

+ 19 - 2
biz-hd/order/classes/OrderClass.php

@@ -52,6 +52,11 @@ class OrderClass extends BaseClass
     //快递送
     const SEND_TYPE_THIRD = 3;
 
+    //正常订单
+    const REFUND_NO = 1;
+    //已退款订单
+    const REFUND_YES = 2;
+
     //送达时间段
     public static $reachPeriod = [0 => '上午', 1 => '下午', 2 => '晚上'];
 
@@ -76,8 +81,8 @@ class OrderClass extends BaseClass
     //添加订单 ssh 2019.12.5
     public static function addOrder($data)
     {
-        $data['orderSn'] = orderSn::getOrderSn();
-        $data['payStatus'] = 0;
+        $data['orderSn'] = $data['orderSn'] ?? orderSn::getOrderSn();
+        $data['payStatus'] = $data['payStatus'] ?? 0;
         $shopId = $data['shopId'] ?? 0;
 
         //累计订单增加
@@ -108,6 +113,18 @@ class OrderClass extends BaseClass
         return self::updateById($id, $data);
     }
 
+    public static function getFullInfo($id)
+    {
+        $order = self::getById($id);
+        if (empty($order)) {
+            return [];
+        }
+        $sn = $order['orderSn'] ?? '';
+        $order['goodsInfoList'] = OrderGoodsClass::getListBySn($sn);
+        $order['itemInfoList'] = OrderItemClass::getListBySn($sn);
+        return $order;
+    }
+
     //订单
     public static function getOrderById($id)
     {

+ 32 - 8
biz-hd/order/classes/OrderGoodsClass.php

@@ -9,6 +9,7 @@ use bizGhs\stock\services\StockRecordService;
 use bizHd\goods\classes\GoodsClass;
 use common\components\business;
 use common\components\dict;
+use common\components\imgUtil;
 use common\components\util;
 use Yii;
 use bizHd\base\classes\BaseClass;
@@ -52,15 +53,19 @@ class OrderGoodsClass extends BaseClass
 
     public static function getListBySn($sn)
     {
-        $arr = self::getAllByCondition(['orderSn' => $sn], null, '*');
-        if (empty($arr)) {
+        $list = self::getAllByCondition(['orderSn' => $sn], null, '*');
+        if (empty($list)) {
             return [];
         }
-        foreach ($arr as $key => $val) {
-            $val = business::formatOrderGoodsCover($val);
-            $arr[$key] = $val;
+        foreach ($list as $key => $val) {
+            $shortCover = isset($val['cover']) && !empty($val['cover']) ? $val['cover'] : 'hhb_small.png';
+            $smallCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+            $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
+            $list[$key]['shortCover'] = $shortCover;
+            $list[$key]['smallCover'] = $smallCover;
+            $list[$key]['bigCover'] = $bigCover;
         }
-        return $arr;
+        return $list;
     }
 
     //批量取订单 ssh 2020.1.2
@@ -72,13 +77,32 @@ class OrderGoodsClass extends BaseClass
         }
         $data = [];
         foreach ($arr as $info) {
-            $orderId = $info['orderId'];
+            $orderId = $info['id'];
             $info = business::formatOrderGoodsCover($info);
             $data[$orderId][] = $info;
         }
         return $data;
     }
 
+    //退货增加库存 ssh 20220427
+    public static function refundAddStock($orderSn, $sjId, $shopId, $mainId, $goodsId, $goodsNum, $shopAdminName)
+    {
+        //加成品库存
+        $respond = GoodsClass::addStock($goodsId, $mainId, $goodsNum);
+        //成品流水记录
+        $data = [];
+        $data['sjId'] = $sjId;
+        $data['shopId'] = $shopId;
+        $data['mainId'] = $mainId;
+        $data['orderSn'] = $orderSn;
+        $data['goodsId'] = $goodsId;
+        $data['goodsNum'] = $goodsNum;
+        $data['oldStock'] = $respond['oldStock'] ?? 0;
+        $data['newStock'] = $respond['newStock'] ?? 0;
+        $data['relateName'] = $shopAdminName;
+        GoodsStockRecordClass::refund($data);
+        return true;
+    }
 
     //制作工单完成,新增成品库存
     public static function addGoodsStockByMakeGoods($orderSn, $sjId, $shopId, $mainId, $goodsId, $goodsNum)
@@ -416,7 +440,7 @@ class OrderGoodsClass extends BaseClass
                 $record['productId'] = $productId;
                 $record['itemNum'] = $stockInfo['itemNum'];
                 $record['oldStock'] = $stockInfo['oldStock'];
-                $record['newStock'] = $stockInfo['newStock']; //
+                $record['newStock'] = $stockInfo['newStock'];
                 StockRecordClass::makeGoodsWastage($record);
             }
         }

+ 18 - 0
biz-hd/order/classes/OrderItemClass.php

@@ -5,6 +5,7 @@ namespace bizHd\order\classes;
 use bizGhs\product\classes\ProductClass;
 use bizGhs\stock\classes\StockRecordClass;
 use common\components\dict;
+use common\components\imgUtil;
 use Yii;
 use bizHd\base\classes\BaseClass;
 
@@ -53,4 +54,21 @@ class OrderItemClass extends BaseClass
         return self::add($data);
     }
 
+    public static function getListBySn($sn)
+    {
+        $list = self::getAllByCondition(['orderSn' => $sn], null, '*');
+        if (empty($list)) {
+            return $list;
+        }
+        foreach ($list as $key => $val) {
+            $shortCover = isset($val['cover']) && !empty($val['cover']) ? $val['cover'] : 'hhb_small.png';
+            $smallCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+            $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
+            $list[$key]['shortCover'] = $shortCover;
+            $list[$key]['smallCover'] = $smallCover;
+            $list[$key]['bigCover'] = $bigCover;
+        }
+        return $list;
+    }
+
 }

+ 3 - 2
biz-hd/order/services/OrderService.php

@@ -253,6 +253,7 @@ class OrderService extends BaseService
         $data['shopId'] = $shopId;
         $data['mainId'] = $mainId;
         $data['payWay'] = $payWay;
+        $data['orderSn'] = $orderSn;
         $data['status'] = OrderClass::ORDER_STATUS_UN_PAY;
 
         //保存订单
@@ -359,13 +360,13 @@ class OrderService extends BaseService
     }
 
     //商家验证是否有效 ssh 2019.12.15
-    public static function valid($order, $shopId)
+    public static function valid($order, $mainId)
     {
         OrderClass::setExpire($order);
         if (empty($order)) {
             util::fail('订单无效');
         }
-        if ($order['shopId'] != $shopId) {
+        if ($order['mainId'] != $mainId) {
             util::fail('不是您的订单');
         }
     }

+ 43 - 0
biz-hd/refund/classes/HdRefundClass.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace bizHd\refund\classes;
+
+use Yii;
+use bizHd\base\classes\BaseClass;
+
+class HdRefundClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\refund\models\HdRefund';
+
+    const REFUND_TYPE_MONEY_GOOD = 1; //退款退货
+    const REFUND_TYPE_MONEY = 2; // 仅退款
+
+    const STATUS_UN_COMPLETE = 0; //退款处理中
+    const STATUS_COMPLETE = 1; //已完成
+
+    // 订单列表
+    public static function getOrderList($where)
+    {
+        $data = self::getList('*', $where, 'addTime DESC');
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
+        }
+        $data['list'] = $list;
+        return $data;
+    }
+
+    //验证信息 ssh 20220401
+    public static function valid($refund, $mainId)
+    {
+        if (empty($refund)) {
+            util::fail('没有找到退款信息');
+        }
+        if (isset($refund->mainId) == false || $refund->mainId != $mainId) {
+            util::fail('没有权限操作');
+        }
+        return true;
+    }
+
+}

+ 35 - 0
biz-hd/refund/classes/HdRefundGoodsClass.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace bizHd\refund\classes;
+
+use bizHd\order\classes\OrderGoodsClass;
+use Yii;
+use bizHd\base\classes\BaseClass;
+
+class HdRefundGoodsClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\refund\models\HdRefundGoods';
+
+    public static function getGoodsListBySn($orderSn)
+    {
+        $list = self::getAllByCondition(['refundSn' => $orderSn], null, '*');
+        return $list;
+    }
+
+    //添加
+    public static function addData($data, $refundSn, $post)
+    {
+        $sjId = $data['sjId'] ?? 0;
+        $shopId = $data['shopId'] ?? 0;
+        $mainId = $data['mainId'] ?? 0;
+        $goodsId = $data['goodsId'] ?? 0;
+        $num = $data['num'] ?? 0;
+        $shopAdminName = $post['shopAdminName'] ?? '';
+
+        OrderGoodsClass::refundAddStock($refundSn, $sjId, $shopId, $mainId, $goodsId, $num, $shopAdminName);
+
+        return self::add($data);
+    }
+
+}

+ 53 - 0
biz-hd/refund/classes/HdRefundItemClass.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace bizHd\refund\classes;
+
+use bizGhs\product\classes\ProductClass;
+use bizGhs\stock\classes\StockRecordClass;
+use Yii;
+use bizHd\base\classes\BaseClass;
+
+class HdRefundItemClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\refund\models\HdRefundItem';
+
+    public static function getItemListBySn($orderSn)
+    {
+        $list = self::getAllByCondition(['refundSn' => $orderSn], null, '*');
+        return $list;
+    }
+
+    //退款的花材 ssh 20220427
+    public static function addData($data, $refundSn, $post)
+    {
+        $itemId = $data['itemId'] ?? 0;
+        $num = $data['num'] ?? 0;
+        $unitType = $data['unitType'] ?? 0;
+        $bigNum = $unitType == 0 ? $num : 0;
+        $smallNum = $unitType == 1 ? $num : 0;
+        $ratio = $data['ratio'] ?? 0;
+        $ptItemId = $data['ptItemId'] ?? 0;
+        $mainId = $data['mainId'] ?? 0;
+        $shopId = $data['shopId'] ?? 0;
+        $sjId = $data['sjId'] ?? 0;
+        $shopAdminName = $post['shopAdminName'] ?? '';
+
+        $stockInfo = ProductClass::addStock($itemId, $bigNum, $smallNum);
+        $recordData = [];
+        $recordData['sjId'] = $sjId;
+        $recordData['shopId'] = $shopId;
+        $recordData['mainId'] = $mainId;
+        $recordData['itemId'] = $ptItemId;
+        $recordData['itemNum'] = ProductClass::mergeItemNum($bigNum, $smallNum, $ratio);
+        $recordData['oldStock'] = $stockInfo['oldStock'];
+        $recordData['newStock'] = $stockInfo['newStock'];
+        $recordData['productId'] = $itemId;
+        $recordData['orderSn'] = $refundSn;
+        $recordData['relateName'] = $shopAdminName;
+        StockRecordClass::hdRefundAddRecord($recordData);
+
+        return self::add($data);
+    }
+
+}

+ 13 - 0
biz-hd/refund/classes/HdRefundSnClass.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace bizHd\refund\classes;
+
+use Yii;
+use bizHd\base\classes\BaseClass;
+
+class HdRefundSnClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\refund\models\HdRefundSn';
+
+}

+ 15 - 0
biz-hd/refund/models/HdRefund.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace bizHd\refund\models;
+
+use bizHd\base\models\Base;
+
+class HdRefund extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhHdRefund';
+    }
+
+}

+ 15 - 0
biz-hd/refund/models/HdRefundGoods.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace bizHd\refund\models;
+
+use bizHd\base\models\Base;
+
+class HdRefundGoods extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhHdRefundGoods';
+    }
+
+}

+ 15 - 0
biz-hd/refund/models/HdRefundItem.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace bizHd\refund\models;
+
+use bizHd\base\models\Base;
+
+class HdRefundItem extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhHdRefundItem';
+    }
+
+}

+ 15 - 0
biz-hd/refund/models/HdRefundSn.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace bizHd\refund\models;
+
+use bizHd\base\models\Base;
+
+class HdRefundSn extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhHdRefundSn';
+    }
+
+}

+ 13 - 0
biz-hd/refund/services/HdRefundGoodsService.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace bizHd\refund\services;
+
+use bizHd\base\services\BaseService;
+use Yii;
+
+class HdRefundGoodsService extends BaseService
+{
+
+    public static $baseFile = '\bizHd\refund\classes\HdRefundGoodsClass';
+
+}

+ 13 - 0
biz-hd/refund/services/HdRefundItemService.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace bizHd\refund\services;
+
+use bizHd\base\services\BaseService;
+use Yii;
+
+class HdRefundItemService extends BaseService
+{
+
+    public static $baseFile = '\bizHd\refund\classes\HdRefundItemClass';
+
+}

+ 270 - 0
biz-hd/refund/services/HdRefundService.php

@@ -0,0 +1,270 @@
+<?php
+
+namespace bizHd\refund\services;
+
+use biz\product\classes\ProductClass;
+use biz\shop\classes\MainClass;
+use biz\shop\classes\ShopCapitalClass;
+use biz\stat\classes\StatOutClass;
+use biz\stat\classes\StatRefundClass;
+use bizHd\base\services\BaseService;
+use bizHd\goods\classes\GoodsClass;
+use bizHd\merchant\classes\ShopClass;
+use bizHd\order\classes\OrderClass;
+use bizHd\order\classes\OrderGoodsClass;
+use bizHd\order\classes\OrderItemClass;
+use bizHd\refund\classes\HdRefundClass;
+use bizHd\refund\classes\HdRefundGoodsClass;
+use bizHd\refund\classes\HdRefundItemClass;
+use bizHd\wx\classes\WxOpenClass;
+use common\components\dict;
+use common\components\orderSn;
+use common\components\util;
+use Yii;
+
+class HdRefundService extends BaseService
+{
+
+    public static $baseFile = '\bizHd\refund\classes\HdRefundClass';
+
+    //新增退款
+    public static function addRefund($post, $order)
+    {
+        $refundPrice = $post['price'] ?? 0;
+        if ($refundPrice <= 0) {
+            util::fail('请填写退款金额');
+        }
+
+        //记录总的退款金额
+        $order->refundPrice = $refundPrice;
+        $currentTkPrice = bcadd($order->tkPrice, $refundPrice, 2);
+        $order->tkPrice = $currentTkPrice;
+        $order->refund = OrderClass::REFUND_YES;
+        $currentActPrice = bcsub($order->actPrice, $refundPrice, 2);
+        if ($currentActPrice < 0) {
+            util::fail('退款金额有问题!');
+        }
+        $order->actPrice = $currentActPrice;
+        $order->realPrice = $currentActPrice;
+        $order->save();
+
+        $transaction_id = $order->thirdNo ?? '';
+
+        $data = [];
+        $data['status'] = HdRefundClass::STATUS_UN_COMPLETE;
+        $refundSn = orderSn::getHdRefundSn();
+        $data['refundSn'] = $refundSn;
+        $data['orderSn'] = $order->orderSn ?? '';
+        $data['orderId'] = $order->id ?? 0;
+        $sjId = $post['sjId'] ?? 0;
+        $refundType = $post['refundType'] ?? 0;
+        $shopId = $post['shopId'] ?? 0;
+        $mainId = $post['mainId'] ?? 0;
+        $xsOrderSn = $order->orderSn ?? '';
+        $data['sjId'] = $sjId;
+        $data['shopId'] = $shopId;
+        $data['mainId'] = $mainId;
+        $data['shopAdminId'] = $post['shopAdminId'] ?? 0;
+        $data['shopAdminName'] = $post['shopAdminName'] ?? '';
+
+        $postProduct = $post['product'] ?? '';
+        if ($refundType == HdRefundClass::REFUND_TYPE_MONEY_GOOD) {
+            //商品花材结构 property 0成品 1花材
+            //[{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎',property:1}]
+            if (empty($postProduct)) {
+                util::fail('没有退款商品');
+            }
+            $goodsInfoList = [];
+            $itemInfoList = [];
+            foreach ($postProduct as $current) {
+                $property = $current['property'] ?? 0;
+                if ($property == 0) {
+                    $goodsInfoList[] = $current;
+                } else {
+                    $itemInfoList[] = $current;
+                }
+            }
+            if (!empty($itemInfoList)) {
+                $ids = array_column($itemInfoList, 'productId');
+                $productInfo = ProductClass::getByids($ids, null, 'id');
+                $orderItemData = OrderItemClass::getAllByCondition(['orderSn' => $xsOrderSn], null, '*', 'itemId', true);
+                if (empty($orderItemData)) {
+                    util::fail('没有找到商品');
+                }
+                foreach ($itemInfoList as $currentProduct) {
+                    $id = $currentProduct['productId'] ?? 0;
+                    $unitType = $currentProduct['unitType'] ?? 0;
+                    $unitName = $currentProduct['unitName'] ?? '';
+                    $currentRefundNum = $currentProduct['num'] ?? 0;
+                    $name = $productInfo[$id]['name'] ?? '';
+                    $ptItemId = $productInfo[$id]['itemId'] ?? 0;
+                    $cover = $productInfo[$id]['cover'] ?? '';
+                    $ratio = $productInfo[$id]['ratio'] ?? '';
+                    $bigUnit = $productInfo[$id]['bigUnit'] ?? '';
+                    $smallUnit = $productInfo[$id]['smallUnit'] ?? '';
+                    $currentOrderItem = $orderItemData[$id] ?? null;
+                    if (empty($currentOrderItem)) {
+                        util::fail('没有找到退款的花材');
+                    }
+                    $orderItemNum = $currentOrderItem->num ?? 0;
+                    //已退货数
+                    $hasRefundNum = $currentOrderItem->refundNum ?? 0;
+                    $remainNum = bcsub($orderItemNum, $hasRefundNum);
+                    if ($currentRefundNum > $remainNum) {
+                        util::fail("{$name}超过可退数量");
+                    }
+                    $currentOrderItem->refundNum = bcadd($hasRefundNum, $currentRefundNum);
+                    $currentOrderItem->save();
+                    $thisItemData = [
+                        'refundSn' => $refundSn,
+                        'mainId' => $mainId,
+                        'sjId' => $sjId,
+                        'shopId' => $shopId,
+                        'name' => $name,
+                        'itemId' => $id,
+                        'ptItemId' => $ptItemId,
+                        'num' => $currentRefundNum,
+                        'unitName' => $unitName,
+                        'unitType' => $unitType,
+                        'cover' => $cover,
+                        'ratio' => $ratio,
+                        'bigUnit' => $bigUnit,
+                        'smallUnit' => $smallUnit,
+                    ];
+                    HdRefundItemClass::addData($thisItemData, $refundSn, $post);
+                }
+            }
+            if (!empty($goodsInfoList)) {
+                $ids = array_column($goodsInfoList, 'productId');
+                $goodsData = GoodsClass::getByIds($ids, null, 'id');
+                $orderGoodsData = OrderGoodsClass::getAllByCondition(['orderSn' => $xsOrderSn], null, '*', 'goodsId', true);
+                foreach ($goodsInfoList as $currentGoods) {
+                    $goodsId = $currentGoods['productId'] ?? 0;
+                    $name = $goodsData[$goodsId]['name'] ?? '';
+                    $currentRefundNum = $currentGoods['num'] ?? 0;
+                    $currentOrderGoods = $orderGoodsData[$goodsId] ?? [];
+                    if (empty($currentOrderGoods)) {
+                        util::fail('没有找到商品呢');
+                    }
+                    $totalNum = $currentOrderGoods->num ?? 0;
+                    $hasRefundNum = $currentOrderGoods->refundNum ?? 0;
+                    $remainNum = bcsub($totalNum, $hasRefundNum);
+                    if ($currentRefundNum > $remainNum) {
+                        util::fail("{$name}超过可退数量");
+                    }
+                    $currentOrderGoods->refundNum = bcadd($hasRefundNum, $currentRefundNum);
+                    $currentOrderGoods->save();
+
+                    $cover = $goodsData[$goodsId]['cover'] ?? '';
+                    $num = $currentGoods['num'] ?? 0;
+                    $saveGoods = [
+                        'refundSn' => $refundSn,
+                        'mainId' => $mainId,
+                        'name' => $name,
+                        'cover' => $cover,
+                        'goodsId' => $goodsId,
+                        'num' => $num,
+                    ];
+                    HdRefundGoodsClass::addData($saveGoods, $refundSn, $post);
+                }
+            }
+        }
+
+        $data['customId'] = $order->customId ?? 0;
+        $data['remark'] = $post['remark'] ?? '';
+        $data['refundPrice'] = $refundPrice;
+        $data['refundType'] = $post['refundType'] ?? 0;
+
+        //写入订单表
+        $refund = HdRefundClass::add($data, true);
+
+        $payWay = $order->payWay;
+        $shopId = $order->shopId;
+        $main = MainClass::getLockById($mainId);
+        $shop = ShopClass::getLockById($shopId);
+        if (empty($main)) {
+            util::fail('main信息缺失');
+        }
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
+        //总支出增加
+        $currentTotalExpend = bcadd($main->totalExpend, $refundPrice, 2);
+        $main->totalExpend = $currentTotalExpend;
+        $totalRefund = bcadd($main->totalRefund, $refundPrice, 2);
+        $main->totalRefund = $totalRefund;
+        $main->save();
+
+        //支出流水
+        $thisType = dict::getDict('capitalType', 'hdOrderRefund', 'id');
+        $sjId = $order->sjId ?? 0;
+        $event = '销售退款';
+        $capitalData = [
+            'capitalType' => $thisType,
+            'io' => 0,
+            'totalExpend' => $currentTotalExpend,
+            'payWay' => 0,
+            'amount' => $refundPrice,
+            'sjId' => $sjId,
+            'shopId' => $shopId,
+            'event' => $event,
+        ];
+        ShopCapitalClass::addCapital($capitalData);
+        //当天和当月支出统计
+        StatOutClass::updateOrInsert($shop, $refundPrice);
+        //退款统计
+        StatRefundClass::replace($shop, $payWay, $refundPrice);
+
+        //退款流程
+        if ($payWay == dict::getDict('payWay', 'wxPay')) {
+
+            //门店余额减少
+            \biz\shop\classes\ShopClass::hdSaleRefundReduceBalance($main, $shop, $refund, $refundPrice);
+
+            //微信收款的原路退回
+            ini_set('date.timezone', 'Asia/Shanghai');
+            $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
+            require_once($wx . '/lib/WxPay.Api.php');
+            require_once($wx . '/example/WxPay.Config.php');
+
+            $totalFee = $order->orderPrice * 100;
+            $refundFee = $refundPrice * 100;
+
+            $merchantExt = WxOpenClass::getMallWxInfo();
+            $mid = $merchantExt['wxPayMerchantId'] ?? '';
+            $appId = $merchantExt['miniAppId'] ?? '';
+            $key = $merchantExt['wxPayKey'] ?? '';
+
+            $input = new \WxPayRefund();
+            $input->SetTransaction_id($transaction_id);
+            $input->SetTotal_fee($totalFee);
+            $input->SetRefund_fee($refundFee);
+            $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-refund-callback/');
+
+            $config = new \WxPayConfig();
+            $config->SetAppId($appId);
+            $config->SetMerchantId($mid);
+            $config->SetKey($key);
+
+            $input->SetOut_refund_no($refundSn);
+            $input->SetOp_user_id($mid);
+            $return = \WxPayApi::refund($config, $input);
+            if (isset($return['return_code']) == false || $return['return_code'] != 'SUCCESS' || isset($return['result_code']) == false || $return['result_code'] != 'SUCCESS') {
+                $msg = $return['return_msg'] ?? '';
+                $err_code_des = $return['err_code_des'] ?? '';
+                Yii::info("退款失败 hd orderId:{$order->id} msg:{$msg}");
+                Yii::info($err_code_des);
+                Yii::info('微信退款返回信息:' . json_encode($return));
+                util::fail('退款失败');
+            }
+            $wxRefundId = $return['refund_id'] ?? '';
+            $refund->thirdRefundNo = $wxRefundId;
+            $refund->save();
+
+        } else {
+            util::fail('暂时只支持微信支付订单退款');
+        }
+        return $refund;
+    }
+
+}

+ 57 - 0
biz/pt/classes/PtAssetClass.php

@@ -355,6 +355,63 @@ class PtAssetClass extends BaseClass
         PtYeChangeClass::addChange($change, true);
     }
 
+    public static function hdSaleRefundReduceBalance($shop, $refund, $refundPrice)
+    {
+        $ptStyle = $shop->ptStyle;
+        $asset = null;
+        if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
+            $asset = self::getHdBalance();
+        } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
+            $asset = self::getGhsBalance();
+        } else {
+            util::fail('没有找到平台');
+        }
+        if (bccomp($refundPrice, $asset->amount, 2) == 1) {
+            util::fail('平台余额不足');
+        }
+        $currentAmount = bcsub($asset->amount, $refundPrice, 2);
+        $asset->amount = $currentAmount;
+        $asset->save();
+
+        $txAsset = null;
+        if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
+            $txAsset = self::getHdTxBalance();
+        } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
+            $txAsset = self::getGhsTxBalance();
+        } else {
+            util::fail('没有找到平台');
+        }
+        $tx = dict::getDict('yeTx', 'can');
+        $currentTxBalance = $txAsset->amount;
+        if (!empty($currentTxBalance)) {
+            $reduceTxBalance = $currentTxBalance > $refundPrice ? $refundPrice : $currentTxBalance;
+            $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
+            $txAsset->amount = $currentTxBalance;
+            $txAsset->save();
+        }
+
+        $id = $refund->id;
+        $currentType = dict::getDict('capitalType', 'hdOrderRefund');
+        $change = [
+            'relateId' => $id,
+            'capitalType' => $currentType,
+            'amount' => $refundPrice,
+            'balance' => $currentAmount,
+            'txBalance' => $currentTxBalance,
+            'io' => 0,
+            'payWay' => 0,
+            'event' => "【{$shop->merchantName} {$shop->shopName}】的销售单发起退款",
+            'sjId' => $shop->sjId,
+            'shopId' => $shop->id,
+            'mainId' => $shop->mainId,
+            'tx' => $tx,
+            'ptStyle' => $ptStyle,
+            'shopName' => $shop->shopName,
+            'sjName' => $shop->merchantName,
+        ];
+        PtYeChangeClass::addChange($change, true);
+    }
+
     public static function saleRefundReduceBalance($shop, $refund, $refundPrice)
     {
         $ptStyle = $shop->ptStyle;

+ 60 - 5
biz/shop/classes/ShopClass.php

@@ -223,7 +223,7 @@ class ShopClass extends BaseClass
             'event' => $custom . "结帐(单号:{$order->orderSn})",
             'sjId' => $shop->sjId,
             'shopId' => $shop->id,
-            'mainId'=>$shop->mainId,
+            'mainId' => $shop->mainId,
             'tx' => $tx,
             'ptStyle' => $shop->ptStyle,
             'mainId' => $mainId,
@@ -417,7 +417,7 @@ class ShopClass extends BaseClass
             'event' => "采购余额付款{$amount}元",
             'sjId' => $sjId,
             'shopId' => $shopId,
-            'mainId'=>$mainId,
+            'mainId' => $mainId,
             'tx' => $tx,
             'ptStyle' => $shop->ptStyle,
         ];
@@ -507,7 +507,7 @@ class ShopClass extends BaseClass
             'event' => $event,
             'sjId' => $shop->sjId,
             'shopId' => $shop->id,
-            'mainId'=>$shop->mainId,
+            'mainId' => $shop->mainId,
             'tx' => $tx,
             'ptStyle' => $shop->ptStyle,
         ];
@@ -518,6 +518,61 @@ class ShopClass extends BaseClass
 
     }
 
+    //花店销售单退款减少余额
+    public static function hdSaleRefundReduceBalance($main, $shop, $refund, $refundPrice)
+    {
+        //门店余额减少
+        $currentBalance = bcsub($main->balance, $refundPrice, 2);
+        if ($currentBalance < 0) {
+            util::fail('余额不足,请先充值');
+        }
+        $main->balance = $currentBalance;
+        $currentTx = $main->txBalance;
+        if ($currentTx > 0) {
+            if ($refundPrice > $currentTx) {
+                $currentTx = 0;
+            } else {
+                $currentTx = bcsub($currentTx, $refundPrice, 2);
+            }
+        }
+        $main->txBalance = $currentTx;
+        $main->save();
+
+        $currentType = dict::getDict('capitalType', 'hdOrderRefund');
+        $id = $refund->id;
+        $event = "退款给客户(退款单 {$refund->refundSn})";
+
+        $relateOrderSn = $refund->orderSn ?? '';
+        if (!empty($relateOrderSn)) {
+            $relateOrder = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
+            $customName = $relateOrder->customName ?? '';
+            if (!empty($customName)) {
+                $event = "退款给{$customName}(退款单 {$refund->refundSn})";
+            }
+        }
+
+        $tx = dict::getDict('yeTx', 'can');
+        $change = [
+            'relateId' => $id,
+            'capitalType' => $currentType,
+            'amount' => $refundPrice,
+            'balance' => $currentBalance,
+            'txBalance' => $currentTx,
+            'io' => 0,
+            'payWay' => 0,
+            'event' => $event,
+            'sjId' => $shop->sjId,
+            'shopId' => $shop->id,
+            'mainId' => $shop->mainId,
+            'tx' => $tx,
+            'ptStyle' => $shop->ptStyle,
+        ];
+        ShopYeChangeClass::addChange($change, true);
+
+        //平台余额增加
+        PtAssetClass::hdSaleRefundReduceBalance($shop, $refund, $refundPrice);
+    }
+
     //销售单退款减少余额 ssh 2021.2.21
     public static function saleRefundReduceBalance($shop, $refund, $refundPrice)
     {
@@ -563,7 +618,7 @@ class ShopClass extends BaseClass
             'event' => $event,
             'sjId' => $shop->sjId,
             'shopId' => $shop->id,
-            'mainId'=>$shop->mainId,
+            'mainId' => $shop->mainId,
             'tx' => $tx,
             'ptStyle' => $shop->ptStyle,
         ];
@@ -632,7 +687,7 @@ class ShopClass extends BaseClass
             'event' => $customerSjName . '-' . $customerName . "提现" . $amount . "元获得佣金",
             'sjId' => $shop->sjId,
             'shopId' => $shop->id,
-            'mainId'=>$shop->mainId,
+            'mainId' => $shop->mainId,
             'tx' => $tx,
             'ptStyle' => $shop->ptStyle,
         ];

+ 6 - 0
biz/stock/classes/GoodsStockRecordClass.php

@@ -36,6 +36,12 @@ class GoodsStockRecordClass extends BaseClass
         self::STOCK_RECORD_TYPE_PURCHASE_CANCEL => '取消制作',
     ];
 
+    public static function refund($data)
+    {
+        $data['recordType'] = self::STOCK_RECORD_TYPE_REFUND;
+        return self::addRecord($data);
+    }
+
     //报损
     public static function wastage($data)
     {

+ 26 - 23
common/components/dict.php

@@ -220,32 +220,35 @@ class dict
             //花店预订补尾款
             'hdBookFinalPay' => ['id' => 52, 'name' => 'hdBookFinalPay'],
             'hdCgPlant' => ['id' => 53, 'name' => 'hdCgPlant'],
+            //花店订单退款
+            'hdOrderRefund' => ['id' => 54, 'name' => 'hdOrderRefund'],
         ],
         "capitalTypeList" => [//流水类型的对应链接,后台收支明细查看时跳转的链接
             0 => ['link' => '/capital/order-detail', 'name' => '网店', 'orderLink' => '/order/detail', 'id' => 0,],
-            2 => ['link' => '/capital/active-order-detail', 'name' => '活动报名', 'orderLink' => '', 'id' => 2,],
-            4 => ['link' => '/capital/recharge-detail', 'name' => '充值', 'orderLink' => '', 'id' => 4,],
-            5 => ['link' => '/capital/user-unite', 'name' => '帐号关联', 'orderLink' => '', 'id' => 5,],
-            6 => ['link' => '/capital/draw-cash', 'name' => '提现', 'orderLink' => '', 'id' => 6,],
-            7 => ['link' => '/capital/apply-order-detail', 'name' => '接入申请', 'orderLink' => '', 'id' => 7,],
-            8 => ['link' => '/capital/merge-user', 'name' => '帐号合并', 'orderLink' => '', 'id' => 8,],
-            9 => ['link' => '/capital/renew', 'name' => '续费', 'orderLink' => '', 'id' => 9,],
-            10 => ['link' => '/capital/order-detail', 'name' => '订单', 'orderLink' => '', 'id' => 10,],
-            11 => ['link' => '/capital/purchase-detail', 'name' => '订单', 'orderLink' => '', 'id' => 11,],
-            12 => ['link' => '/capital/purchase-detail', 'name' => '培训报名', 'orderLink' => '', 'id' => 12,],
-            20 => ['link' => '', 'name' => '采购结算', 'orderLink' => '', 'id' => 20,],
-            25 => ['link' => '', 'name' => '采购', 'orderLink' => '', 'id' => 25,],
-            30 => ['link' => '', 'name' => '使用平台优惠券', 'orderLink' => '', 'id' => 30,],
-            35 => ['link' => '', 'name' => '报损', 'orderLink' => '', 'id' => 35,],
-            38 => ['link' => '', 'name' => '采购退款', 'orderLink' => '', 'id' => 38,],
-            40 => ['link' => '', 'name' => '销售退款', 'orderLink' => '', 'id' => 40,],
-            45 => ['link' => '', 'name' => '盘点', 'orderLink' => '', 'id' => 45,],
-            46 => ['link' => '', 'name' => '佣金', 'orderLink' => '', 'id' => 46,],
-            48 => ['link' => '', 'name' => '预订单多退少补', 'orderLink' => '', 'id' => 48,],
-            50 => ['link' => '', 'name' => '预订单多退少补', 'orderLink' => '', 'id' => 50,],
-            51 => ['link' => '', 'name' => '预订单补款', 'orderLink' => '', 'id' => 51,],
-            52 => ['link' => '', 'name' => '花店预订补尾款', 'orderLink' => '', 'id' => 52,],
-            53 => ['link' => '', 'name' => '采购盆栽等', 'orderLink' => '', 'id' => 53,],
+            2 => ['link' => '/capital/active-order-detail', 'name' => '活动报名',  'id' => 2,],
+            4 => ['link' => '/capital/recharge-detail', 'name' => '充值',  'id' => 4,],
+            5 => ['link' => '/capital/user-unite', 'name' => '帐号关联',  'id' => 5,],
+            6 => ['link' => '/capital/draw-cash', 'name' => '提现',  'id' => 6,],
+            7 => ['link' => '/capital/apply-order-detail', 'name' => '接入申请',  'id' => 7,],
+            8 => ['link' => '/capital/merge-user', 'name' => '帐号合并',  'id' => 8,],
+            9 => ['link' => '/capital/renew', 'name' => '续费',  'id' => 9,],
+            10 => ['link' => '/capital/order-detail', 'name' => '订单',  'id' => 10,],
+            11 => ['link' => '/capital/purchase-detail', 'name' => '订单',  'id' => 11,],
+            12 => ['link' => '/capital/purchase-detail', 'name' => '培训报名',  'id' => 12,],
+            20 => ['link' => '', 'name' => '采购结算',  'id' => 20,],
+            25 => ['link' => '', 'name' => '采购',  'id' => 25,],
+            30 => ['link' => '', 'name' => '使用平台优惠券',  'id' => 30,],
+            35 => ['link' => '', 'name' => '报损',  'id' => 35,],
+            38 => ['link' => '', 'name' => '采购退款',  'id' => 38,],
+            40 => ['link' => '', 'name' => '销售退款',  'id' => 40,],
+            45 => ['link' => '', 'name' => '盘点',  'id' => 45,],
+            46 => ['link' => '', 'name' => '佣金',  'id' => 46,],
+            48 => ['link' => '', 'name' => '预订单多退少补',  'id' => 48,],
+            50 => ['link' => '', 'name' => '预订单多退少补',  'id' => 50,],
+            51 => ['link' => '', 'name' => '预订单补款',  'id' => 51,],
+            52 => ['link' => '', 'name' => '花店预订补尾款',  'id' => 52,],
+            53 => ['link' => '', 'name' => '采购盆栽等',  'id' => 53,],
+            54 => ['link' => '', 'name' => '退货退款',  'id' => 54,],
         ],
 
         //用户来源

+ 16 - 0
common/components/orderSn.php

@@ -13,6 +13,7 @@ use bizGhs\check\classes\CheckSnClass;
 use bizGhs\order\classes\OrderSnClass;
 use bizGhs\order\classes\PurchaseSnClass;
 use bizHd\px\classes\PxApplySnClass;
+use bizHd\refund\classes\HdRefundSnClass;
 use bizHd\work\classes\WorkSnClass;
 use bizMall\renew\classes\RenewSnClass;
 use Yii;
@@ -234,6 +235,21 @@ class orderSn
         return $prefix . $id;
     }
 
+    //花店销售单的退款单 ssh 20220427
+    public static function getHdRefundSn()
+    {
+        $prefix = 'RF_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'RF';
+        }
+        $respond = HdRefundSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('退款单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
     //供货商退款订单号 lqh 2021.6.26
     public static function getGhsRefundSn()
     {

+ 29 - 0
sql.txt

@@ -915,4 +915,33 @@ ALTER TABLE xhWork MODIFY `smallNum` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '
 
 ALTER TABLE xhOrder ADD cover VARCHAR(200) NOT NULL DEFAULT '' COMMENT '封面' AFTER `payWay`;
 
+ALTER TABLE xhOrderGoods ADD `refundNum` INT(11) NOT NULL DEFAULT '0' COMMENT '已退货数' AFTER `price`;
+ALTER TABLE xhOrderItem ADD `refundNum` INT(11) NOT NULL DEFAULT '0' COMMENT '已退货数' AFTER `price`;
+
+ALTER TABLE xhHdRefund ADD mainId INT NOT NULL DEFAULT 0 COMMENT '' AFTER `shopId`;
+ALTER TABLE xhHdRefundGoods ADD mainId INT NOT NULL DEFAULT 0 COMMENT '' AFTER `refundId`;
+ALTER TABLE xhHdRefundItem ADD mainId INT NOT NULL DEFAULT 0 COMMENT '' AFTER `refundId`;
+
+DROP TABLE IF EXISTS `xhHdRefundSn`;
+CREATE TABLE IF NOT EXISTS `xhHdRefundSn` (
+  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (`id`)
+) ENGINE=INNODB AUTO_INCREMENT=2681235 COMMENT='退款订单号';
+
+ALTER TABLE xhHdRefundItem ADD unitName CHAR(5) NOT NULL DEFAULT '' COMMENT '单位名称' AFTER `num`;
+ALTER TABLE xhHdRefundItem ADD unitType TINYINT NOT NULL DEFAULT 0 COMMENT '' AFTER `num`;
+ALTER TABLE xhHdRefundItem ADD cover VARCHAR(200) NOT NULL DEFAULT '' COMMENT '封面' AFTER `name`;
+ALTER TABLE xhHdRefundGoods ADD cover VARCHAR(300) NOT NULL DEFAULT '' COMMENT '封面' AFTER `name`;
+
+ALTER TABLE xhHdRefundItem ADD ratio TINYINT NOT NULL DEFAULT 20 COMMENT '比例' AFTER `itemId`;
+ALTER TABLE xhHdRefundItem ADD bigUnit CHAR(10) NOT NULL DEFAULT '' COMMENT '大单位' AFTER `ratio`;
+ALTER TABLE xhHdRefundItem ADD smallUnit CHAR(10) NOT NULL DEFAULT '' COMMENT '小单位' AFTER `ratio`;
+
+ALTER TABLE xhHdRefundItem ADD sjId INT NOT NULL DEFAULT 0 COMMENT '' AFTER `mainId`;
+ALTER TABLE xhHdRefundItem ADD shopId INT NOT NULL DEFAULT 0 COMMENT '' AFTER `mainId`;
+ALTER TABLE xhHdRefundGoods ADD sjId INT NOT NULL DEFAULT 0 COMMENT '' AFTER `mainId`;
+ALTER TABLE xhHdRefundGoods ADD shopId INT NOT NULL DEFAULT 0 COMMENT '' AFTER `mainId`;
+
+ ALTER TABLE xhHdRefund ADD `thirdRefundNo` CHAR(50) NOT NULL DEFAULT '' COMMENT '第三方支付id' AFTER `orderId`;
+
 ---ssh 20220424