shish vor 3 Jahren
Ursprung
Commit
3db042ff25

+ 87 - 0
app-ghs/controllers/CgRefundController.php

@@ -0,0 +1,87 @@
+<?php
+
+namespace ghs\controllers;
+
+
+use bizGhs\cg\classes\CgRefundClass;
+use bizGhs\cg\services\CgRefundService;
+use bizGhs\order\classes\PurchaseOrderClass;
+use common\components\util;
+use Yii;
+
+class CgRefundController extends BaseController
+{
+
+    //退款 ssh 20220909
+    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 = PurchaseOrderClass::getLockById($id);
+
+            if ($order->mainId != $this->mainId) {
+                util::fail('没有权限');
+            }
+            if ($order->status != PurchaseOrderClass::PURCHASE_ORDER_STATUS_COMPLETE) {
+                util::fail('已完成订单才能申请退货退款');
+            }
+            if ($order->debt != 1) {
+                util::fail('欠款单才能申请退货退款');
+            }
+
+            //退款类型 1退货并退款 2 仅退款
+            $refundType = $post['refundType'] ?? 1;
+
+            if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD) {
+                //花材列表结构
+                // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称
+                $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->realPrice, 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;
+
+            CgRefundService::addRefund($order, $post);
+
+            $transaction->commit();
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            Yii::info("退款申请出错了,报错信息:" . $exception->getMessage());
+            util::fail('操作失败');
+        }
+        util::complete();
+    }
+}

+ 5 - 5
app-ghs/controllers/ConsoleController.php

@@ -135,15 +135,15 @@ class ConsoleController extends BaseController
             ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/home/mall"],
             ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
             ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
-            ["name" => "供应商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
-            ["name" => "采购", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
-            ["name" => "报损", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
+            ["name" => "采购", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
+            ["name" => "采购记录", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
+            ["name" => "报损", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
             ["name" => "预订单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/statBook"],
-            ["name" => "新增出库", "img" => "ghs/home/dbck.png", "url" => "/admin/shop/selectShop"],
+            ["name" => "出库", "img" => "ghs/home/dbck.png", "url" => "/admin/shop/selectShop"],
             ["name" => "出库记录", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
             ["name" => "入库记录", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
             ["name" => "结账记录", "img" => "ghs/home/kcyjs.png", "url" => "/admin/clear/customList"],
-            ["name" => "支出登记", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/addExpend"],
+            ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/addExpend"],
         ];
 
         util::success(['asset' => $this->main, 'notice' => $notice,

+ 1 - 9
app-ghs/controllers/PurchaseOrderController.php

@@ -128,6 +128,7 @@ class PurchaseOrderController extends BaseController
         GhsClass::valid($ghsInfo, $this->shopId);
         $post['ghsInfo'] = json_encode($ghsInfo);
         $post['ghsName'] = $ghsInfo['name'] ?? '';
+        $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
 
         //判断花材里的信息
         foreach ($ghsItemInfo as $v) {
@@ -194,7 +195,6 @@ class PurchaseOrderController extends BaseController
     //订单详情
     public function actionDetail()
     {
-
         if (getenv('YII_ENV') == 'production') {
             //阿东的创始人才能查看采购单
             if (in_array($this->mainId, [742])) {
@@ -203,15 +203,7 @@ class PurchaseOrderController extends BaseController
                     util::fail('没有权限');
                 }
             }
-        } else {
-            if (in_array($this->mainId, [644])) {
-                $staff = $this->shopAdmin;
-                if (isset($staff->founder) == false || $staff->founder != 2) {
-                    util::fail('没有权限');
-                }
-            }
         }
-
         $orderSn = Yii::$app->request->get('orderSn', '');
         $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
         util::success($orderData);

+ 17 - 0
biz-ghs/cg/classes/CgRefundClass.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace bizGhs\cg\classes;
+
+use bizGhs\base\classes\BaseClass;
+use common\components\util;
+use Yii;
+
+class CgRefundClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\cg\models\CgRefund';
+
+    const REFUND_TYPE_MONEY_GOOD = 1; //退款退货
+    const REFUND_TYPE_MONEY = 2; // 仅退款
+
+}

+ 52 - 0
biz-ghs/cg/classes/CgRefundItemClass.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace bizGhs\cg\classes;
+
+use bizGhs\base\classes\BaseClass;
+use common\components\util;
+use Yii;
+use bizGhs\product\classes\ProductClass;
+use bizGhs\stock\classes\StockRecordClass;
+
+class CgRefundItemClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\cg\models\CgRefundItem';
+
+    public static function addData($data, $order)
+    {
+
+        $productId = $data['productId'] ?? 0;
+        $smallNum = 0;
+        $bigNum = $data['num'] ?? 0;
+        $refundSn = $data['refundSn'] ?? '';
+        $ptItemId = $data['ptItemId'] ?? 0;
+
+        $mainId = $order->mainId ?? 0;
+        $shopId = $order->shopId ?? 0;
+        $sjId = $order->sjId ?? 0;
+        $ghsName = $order->ghsName ?? '';
+
+        $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum);
+        $oldStock = $stockInfo['oldStock'] ?? 0;
+        $newStock = $stockInfo['newStock'] ?? 0;
+
+        $recordData = [];
+        $recordData['shopId'] = $data['shopId'];
+        $recordData['itemNum'] = $bigNum;
+        $recordData['sjId'] = $sjId;
+        $recordData['shopId'] = $shopId;
+        $recordData['mainId'] = $mainId;
+        $recordData['orderSn'] = $refundSn;
+        $recordData['itemId'] = $ptItemId;
+        $recordData['oldStock'] = $oldStock; //当时库存
+        $recordData['productId'] = $productId;
+        $recordData['newStock'] = $newStock;// 最新库存
+        $recordData['relateName'] = $ghsName;
+        StockRecordClass::ghsCgApplyRefundAddRecord($recordData);
+
+        self::add($data);
+
+    }
+
+}

+ 14 - 0
biz-ghs/cg/classes/CgRefundSnClass.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace bizGhs\cg\classes;
+
+use bizGhs\base\classes\BaseClass;
+use common\components\util;
+use Yii;
+
+class CgRefundSnClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\cg\models\CgRefundSn';
+
+}

+ 13 - 0
biz-ghs/cg/models/CgRefund.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizGhs\cg\models;
+use bizGhs\base\models\Base;
+
+class CgRefund extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhGhsCgRefund';
+    }
+
+}

+ 13 - 0
biz-ghs/cg/models/CgRefundItem.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizGhs\cg\models;
+use bizGhs\base\models\Base;
+
+class CgRefundItem extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhGhsCgRefundItem';
+    }
+
+}

+ 13 - 0
biz-ghs/cg/models/CgRefundSn.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizGhs\cg\models;
+use bizGhs\base\models\Base;
+
+class CgRefundSn extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhGhsCgRefundSn';
+    }
+
+}

+ 16 - 0
biz-ghs/cg/services/CgRefundItemService.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace bizGhs\cg\services;
+
+use bizGhs\base\services\BaseService;
+use bizGhs\cg\classes\CgRefundClass;
+use common\components\dict;
+use common\components\util;
+use Yii;
+
+class CgRefundItemService extends BaseService
+{
+
+    public static $baseFile = '\bizGhs\cg\classes\CgRefundItemClass';
+
+}

+ 96 - 0
biz-ghs/cg/services/CgRefundService.php

@@ -0,0 +1,96 @@
+<?php
+
+namespace bizGhs\cg\services;
+
+use bizGhs\base\services\BaseService;
+use bizGhs\cg\classes\CgRefundClass;
+use bizGhs\cg\classes\CgRefundItemClass;
+use bizGhs\order\classes\PurchaseOrderItemClass;
+use bizGhs\product\classes\ProductClass;
+use common\components\dict;
+use common\components\orderSn;
+use common\components\util;
+use Yii;
+
+class CgRefundService extends BaseService
+{
+
+    public static $baseFile = '\bizGhs\cg\classes\CgRefundClass';
+
+    //退款
+    public static function addRefund($order, $post)
+    {
+        $refundPrice = $post['price'] ?? 0;
+        if ($refundPrice <= 0) {
+            util::fail('请填写退款金额');
+        }
+        $order->refundPrice = $refundPrice;
+        $actPrice = $order->actPrice ?? 0;
+        $realPrice = $order->realPrice ?? 0;
+        $currentActPrice = bcsub($actPrice, $refundPrice, 2);
+        $currentRealPrice = bcsub($realPrice, $refundPrice, 2);
+        $order->actPrice = $currentActPrice;
+        $order->realPrice = $currentRealPrice;
+        $order->refund = 2;
+        $order->save();
+
+        $data = [];
+        $data['status'] = 1;
+        $orderSn = orderSn::getGhsCgRefundSn();
+        $data['refundSn'] = $orderSn;
+        $data['relateOrderSn'] = $order->orderSn ?? '';
+        $sjId = $post['sjId'] ?? 0;
+        $refundType = $post['refundType'] ?? 0;
+        $shopId = $post['shopId'] ?? 0;
+        $mainId = $post['mainId'] ?? 0;
+        $data['sjId'] = $sjId;
+        $data['shopId'] = $shopId;
+        $data['mainId'] = $mainId;
+        $data['shopAdminId'] = $post['shopAdminId'] ?? 0;
+        $data['shopAdminName'] = $post['shopAdminName'] ?? '';
+
+        $productData = $post['product'] ?? '';
+
+        if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD) {
+            //前端传过来的结构 [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}]
+            if (empty($productData)) {
+                util::fail('没有退款花材');
+            }
+            $cgItemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $order->orderSn], null, '*', 'productId', true);
+            foreach ($productData as $currentProduct) {
+                $num = $currentProduct['num'] ?? 0;
+                $productId = $currentProduct['productId'] ?? 0;
+                if (empty($productId)) {
+                    util::fail('发现无效花材');
+                }
+                $currentCgItem = $cgItemList[$productId] ?? null;
+                $hasRefundNum = $currentCgItem->refundNum ?? 0;
+                $totalNum = $currentCgItem->itemNum ?? 0;
+                $couldRefundNum = bcsub($totalNum, $hasRefundNum);
+                if ($couldRefundNum < $num) {
+                    util::fail('超过可退数量');
+                }
+                $name = $currentCgItem->name ?? '';
+                $cover = $currentCgItem->cover ?? '';
+                $ptItemId = $currentCgItem->itemId ?? 0;
+                $refundItemData = [
+                    'refundSn' => $orderSn,
+                    'name' => $name,
+                    'cover' => $cover,
+                    'itemId' => $productId,
+                    'ptItemId' => $ptItemId,
+                    'num' => $num,
+                ];
+                CgRefundItemClass::addData($refundItemData, $order);
+            }
+
+        }
+        $data['customId'] = $order->customId ?? 0;
+        $data['remark'] = $post['remark'] ?? '';
+        $data['refundPrice'] = $refundPrice;
+        $data['refundType'] = $post['refundType'] ?? 0;
+        $refund = CgRefundClass::add($data, true);
+        return $refund;
+    }
+
+}

+ 5 - 8
biz-ghs/order/classes/PurchaseOrderClass.php

@@ -369,15 +369,14 @@ class PurchaseOrderClass extends BaseClass
     //获取订单详情信息 lqh 2021.1.20
     public static function getOrderDetail($orderSn, $shopId)
     {
-        $where = [
-            'orderSn' => $orderSn,
-            'shopId' => $shopId,
-        ];
+        $where = ['orderSn' => $orderSn];
         $orderData = self::getByCondition($where);
-        $orderData['ghsInfo'] = json_decode($orderData['ghsInfo']);
-        if (!$orderData) {
+        if (empty($orderData)) {
             util::fail('订单不存在');
         }
+        if (isset($orderData['shopId']) == false || $orderData['shopId'] != $shopId) {
+            util::fail('没有权限访问');
+        }
         $orderInfo = PurchaseOrderItemClass::getOrderItemDetail($orderSn);
         if ($orderInfo) {
             foreach ($orderInfo as $key => $val) {
@@ -388,7 +387,6 @@ class PurchaseOrderClass extends BaseClass
             }
         }
         $orderData = self::groupAdmin($orderData);
-
         //供应商信息
         $ghsId = $orderData['ghsId'] ?? 0;
         $ghsInfo = GhsClass::getGhsInfo($ghsId);
@@ -398,7 +396,6 @@ class PurchaseOrderClass extends BaseClass
         $orderData['debtAmount'] = $ghsInfo['debtAmount'] ?? 0;
         $orderData['itemInfo'] = $orderInfo;
         $orderData['statusName'] = self::getStatusName($orderData['status']);
-
         return $orderData;
     }
 

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

@@ -30,6 +30,7 @@ class StockRecordClass extends BaseClass
     const STOCK_RECORD_TYPE_GOODS_CONSUME_CANCEL = 14;//取消制作
     const STOCK_RECORD_TYPE_GOODS_WASTAGE_CANCEL = 15;//取消制作已报损
     const STOCK_RECORD_TYPE_HD_REFUND = 16;//花店退货退款
+    const STOCK_RECORD_TYPE_GHS_REFUND = 17;//供应商申请退货退款
 
     public static $typeMap = [
         self::STOCK_RECORD_TYPE_PURCHASE => '采购入库',
@@ -48,6 +49,7 @@ class StockRecordClass extends BaseClass
         self::STOCK_RECORD_TYPE_GOODS_CONSUME_CANCEL => '取消制作',
         self::STOCK_RECORD_TYPE_GOODS_WASTAGE_CANCEL => '取消制作损耗',
         self::STOCK_RECORD_TYPE_HD_REFUND => '退货退款',
+        self::STOCK_RECORD_TYPE_GHS_REFUND => '退货退款',
     ];
 
     public static function getRecordList($where)
@@ -230,4 +232,12 @@ class StockRecordClass extends BaseClass
         $data['recordType'] = self::STOCK_RECORD_TYPE_GOODS_WASTAGE_CANCEL;
         return self::addRecord($data);
     }
+
+    //二批申请退货退款库存变动记录 ssh 20220909
+    public static function ghsCgApplyRefundAddRecord($refundRecord)
+    {
+        $refundRecord['recordType'] = self::STOCK_RECORD_TYPE_GHS_REFUND;
+        self::add($refundRecord);
+    }
+
 }

+ 1 - 0
biz/ghs/classes/GhsClass.php

@@ -170,6 +170,7 @@ class GhsClass extends BaseClass
         $shopInfo = ShopClass::getByIds($ids, null, 'id');
         foreach ($list as $key => $val) {
             $avatar = $val['avatar'] ?? '';
+            $list[$key]['shortAvatar'] = $avatar;
             $list[$key]['avatar'] = imgUtil::groupImg($avatar);
             $currentShopId = $val['shopId'] ?? 0;
             //新人福利和推荐福利

+ 15 - 0
common/components/orderSn.php

@@ -324,4 +324,19 @@ class orderSn
         return $prefix . $id;
     }
 
+    //二批采购退款 ssh 20220909
+    public static function getGhsCgRefundSn()
+    {
+        $prefix = 'GCRD_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'GCRD';
+        }
+        $respond = \bizGhs\cg\classes\CgRefundClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
 }