Browse Source

采购和结账优化

shish 11 months ago
parent
commit
eeec712b09

+ 52 - 1
app-hd/controllers/ClearController.php

@@ -6,6 +6,7 @@ use biz\ghs\classes\GhsClass;
 use bizGhs\clear\classes\ClearClass;
 use bizGhs\clear\services\ClearService;
 use bizGhs\custom\classes\CustomClass;
+use bizGhs\order\classes\OrderClearClass;
 use bizHd\shop\classes\ShopClass;
 use common\components\dict;
 use common\components\imgUtil;
@@ -42,7 +43,7 @@ class ClearController extends BaseController
             util::fail('账单已取消');
         }
         $clear->status = ClearClass::STATUS_EXPIRE;
-        $clear->remark = "客户手动取消 ".date('Y-m-d H:i:s');
+        $clear->remark = "客户手动取消 " . date('Y-m-d H:i:s');
         $clear->save();
         $orderSn = $clear->orderSn ?? '';
 
@@ -148,7 +149,57 @@ class ClearController extends BaseController
         $remainSecond = $remainSecond > 0 ? $remainSecond : 0;
         $clear['remainSecond'] = $remainSecond;
         $clear['hasRenew'] = 1;
+
+        //如果是虚拟关系,暂时允许花店一键结账
+        $ghsId = $clear['ghsId'] ?? 0;
+        $ghs = GhsClass::getById($ghsId, true);
+        $live = $ghs->live ?? 1;
+        $clear['live'] = $live;
+
         util::success($clear);
     }
 
+    public function actionHasWxPay()
+    {
+        $id = Yii::$app->request->get('id');
+        $clear = ClearClass::getById($id, true);
+        if (empty($clear)) {
+            util::fail('没有结账信息哦');
+        }
+        if ($clear->customShopId != $this->shopId) {
+            util::fail('不是你的结账单');
+        }
+
+        util::checkRepeatCommit($this->adminId, 4);
+
+        //暂时用批发端的写法来顶替一下
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $payWay = 0;
+            $amount = $clear->actPrice ?? 0;
+            $customId = $clear->customId ?? 0;
+            $custom = CustomClass::getLockById($customId);
+            $shop = $this->shop;
+            $staff = $this->shopAdmin;
+            //充值
+            $return = CustomClass::rechargeBalance($custom, $amount, $shop, $staff, $payWay);
+            $custom = $return['custom'];
+            $ghs = $return['ghs'];
+            //结账
+            OrderClearClass::confirmClear($clear, $payWay);
+            $clearInfo = OrderClearClass::getLockById($id);
+            //结账消余额
+            CustomClass::clearConsumeBalance($amount, $custom, $ghs, $shop, $staff, $clearInfo);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            Yii::info("失败:" . $exception->getMessage());
+            util::fail('操作失败');
+        }
+
+    }
+
 }

+ 2 - 0
app-hd/controllers/ItemController.php

@@ -128,6 +128,8 @@ class ItemController extends BaseController
             $list = ProductClass::partItemGroup($list, $level);
         } elseif ($requestType == 'check') {
             $list = ProductClass::checkItemGroup($list, $level);
+        } elseif ($requestType == 'cg') {
+            $list = ProductClass::cgItemGroup($list, $level);
         } elseif ($requestType == 'changeStock') {
             $list = ProductClass::changeStockGroup($list, $level);
         } elseif ($requestType == 'stockOut') {

+ 5 - 0
app-hd/controllers/PurchaseClearController.php

@@ -89,6 +89,11 @@ class PurchaseClearController extends BaseController
         $respond['remainSecond'] = $remainSecond;
         $getPayType = dict::getDict('getPayType');
         $respond['getPayType'] = $getPayType;
+
+        //如果是虚拟关系,暂时允许花店一键结账
+        $live = $ghs->live ?? 1;
+        $respond['live'] = $live;
+
         util::success($respond);
     }
 

+ 5 - 2
biz-ghs/custom/classes/CustomClass.php

@@ -453,11 +453,14 @@ class CustomClass extends BaseClass
         $amount = $order->remainDebtPrice ?? 0;
         $custom->isDebt = CustomClass::IS_DEBT_YES;
         $debtLimit = $custom->debtLimit ?? 0;
-        if ($bookOrder == false) {
+        if (!$bookOrder) {
             if (isset($order->shopAdminId) && $order->shopAdminId == 0) {
                 //客户自己下单要受额度限制
                 if ($custom->debtAmount > $debtLimit) {
-                    util::fail("已欠款{$custom->debtAmount},请先结账哦");
+                    //虚拟供货商和客户关系不受影响
+                    if($custom->live == 1){
+                        util::fail("已欠款{$custom->debtAmount},请先结账哦");
+                    }
                 }
             }
         }

+ 23 - 0
biz-hd/product/classes/ProductClass.php

@@ -319,6 +319,29 @@ class ProductClass extends BaseClass
         return $list;
     }
 
+    public static function cgItemGroup($list, $level = 0)
+    {
+        $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
+        $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
+        foreach ($list as $k => $v) {
+            $shortCover = $v['cover'] ?? '';
+            $list[$k]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
+            $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 1;
+            $stockInfo = self::formatStock($v['stock'], $ratio);
+            $list[$k]['bigNum'] = $stockInfo['bigNum'];
+            $list[$k]['smallNum'] = $stockInfo['smallNum'];
+
+            $price = \bizGhs\product\classes\ProductClass::getFinalPrice($v, $level, $priceMap, $addPriceMap);
+            $list[$k]['price'] = $price;
+            $list[$k]['bigPrice'] = $price;
+            $smallRatio = $v['smallRatio'] ?? 0;
+            $smallPrice = bcdiv($price, $ratio, 2);
+            $smallPrice = bcmul($smallPrice, $smallRatio, 2);
+            $list[$k]['smallPrice'] = $smallPrice;
+        }
+        return $list;
+    }
+
     //通用花材列表数组组合
     public static function changeStockGroup($list, $level = 0)
     {