ソースを参照

绿植和采购相关

shish 3 年 前
コミット
1db59248a2
46 ファイル変更1140 行追加496 行削除
  1. 1 1
      app-ghs/controllers/AuthController.php
  2. 0 5
      app-ghs/controllers/StatKdController.php
  3. 7 4
      app-hd/controllers/CategoryController.php
  4. 41 0
      app-hd/controllers/CgItemController.php
  5. 9 5
      app-hd/controllers/CheckOrderController.php
  6. 30 0
      app-hd/controllers/GhsController.php
  7. 6 3
      app-hd/controllers/GoodsController.php
  8. 13 1
      app-hd/controllers/KindController.php
  9. 79 0
      app-hd/controllers/PdGoodsController.php
  10. 4 0
      app-hd/controllers/ProductController.php
  11. 83 1
      app-hd/controllers/PurchaseController.php
  12. 18 56
      app-hd/controllers/StatController.php
  13. 16 59
      app-hd/controllers/StatKdController.php
  14. 2 1
      biz-ghs/apply/services/ApplyService.php
  15. 1 1
      biz-ghs/item/classes/ItemClassClass.php
  16. 3 0
      biz-ghs/merchant/services/MerchantService.php
  17. 7 1
      biz-ghs/order/classes/OrderClass.php
  18. 24 17
      biz-ghs/order/classes/OrderItemClass.php
  19. 22 19
      biz-ghs/order/classes/RefundOrderItemClass.php
  20. 56 67
      biz-ghs/product/classes/ProductClass.php
  21. 5 2
      biz-ghs/shop/classes/MainClass.php
  22. 29 1
      biz-ghs/stat/classes/StatSaleClass.php
  23. 21 16
      biz-hd/cg/classes/CgRefundItemClass.php
  24. 10 0
      biz-hd/common/classes/MobileSnClass.php
  25. 13 0
      biz-hd/common/models/MobileSn.php
  26. 57 0
      biz-hd/ghs/services/GhsService.php
  27. 90 7
      biz-hd/goods/classes/GoodsClass.php
  28. 55 6
      biz-hd/goods/classes/KindClass.php
  29. 11 1
      biz-hd/merchant/services/SjService.php
  30. 17 13
      biz-hd/order/classes/OrderItemClass.php
  31. 111 0
      biz-hd/pd/classes/PdGoodsClass.php
  32. 13 0
      biz-hd/pd/classes/PdGoodsDetailClass.php
  33. 13 0
      biz-hd/pd/classes/PdGoodsSnClass.php
  34. 13 0
      biz-hd/pd/models/PdGoods.php
  35. 13 0
      biz-hd/pd/models/PdGoodsDetail.php
  36. 13 0
      biz-hd/pd/models/PdGoodsSn.php
  37. 10 0
      biz-hd/pd/services/PdGoodsService.php
  38. 44 0
      biz-hd/product/classes/ProductClass.php
  39. 55 177
      biz-hd/purchase/classes/PurchaseClass.php
  40. 22 16
      biz-hd/purchase/services/PurchaseService.php
  41. 15 13
      biz-hd/refund/classes/HdRefundItemClass.php
  42. 5 0
      biz/ghs/classes/GhsClass.php
  43. 16 2
      biz/stock/classes/GoodsStockRecordClass.php
  44. 29 0
      common/components/orderSn.php
  45. 2 1
      console/controllers/CustomController.php
  46. 36 0
      console/controllers/KindController.php

+ 1 - 1
app-ghs/controllers/AuthController.php

@@ -65,7 +65,7 @@ class AuthController extends PublicController
         }
         $admin = AdminClass::getByCondition(['mobile' => $phoneNumber]);
         if (empty($admin)) {
-            util::fail('请注册或联系批发店添加');
+            util::fail('请先注册或请店长添加自己为员工');
         }
         $currentShopId = $admin['currentGhsShopId'] ?? 0;
         $openShop = $admin['openGhsShop'] ?? 1;

+ 0 - 5
app-ghs/controllers/StatKdController.php

@@ -12,23 +12,19 @@ class StatKdController extends BaseController
     //各渠道收入 ssh 20220711
     public function actionProfile()
     {
-
         $shopAdmin = $this->shopAdmin;
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
             util::fail('超管才能查看');
         }
-
         //惠雅鲜花员工不能看收入情况
         $shopAdmin = $this->shopAdmin;
         $adminId = $shopAdmin->adminId ?? 0;
         if (in_array($adminId, [2366, 2812, 4004, 3405, 3407])) {
             util::fail('暂无权限');
         }
-
         $get = Yii::$app->request->get();
         $contain = $get['contain'] ?? 0;
         $incomeList = StatKdClass::eachChannelIncome($this->mainId, $this->shop, $contain);
-
         $totalIncome = 0;
         if (!empty($incomeList)) {
             foreach ($incomeList as $item) {
@@ -37,7 +33,6 @@ class StatKdController extends BaseController
                 $totalIncome = floatval($totalIncome);
             }
         }
-
         util::success(['list' => $incomeList, 'totalIncome' => $totalIncome]);
     }
 

+ 7 - 4
app-hd/controllers/CategoryController.php

@@ -84,12 +84,11 @@ class CategoryController extends BaseController
     {
         $get = Yii::$app->request->get();
         $catId = $get['catId'] ?? 0;
-        if (empty($catId)) {
-            util::fail('没有分类');
-        }
         $where = [];
         $where['mainId'] = $this->mainId;
-        $where['cId'] = $catId;
+        if (!empty($catId)) {
+            $where['cId'] = $catId;
+        }
         $flower = $get['flower'] ?? '';
         if (is_numeric($flower)) {
             $where['flower'] = $flower;
@@ -103,6 +102,10 @@ class CategoryController extends BaseController
         if (!empty($flowerNum)) {
             $where['flowerNum'] = $flowerNum;
         }
+        $searchText = $get['searchText'] ?? '';
+        if (!empty($searchText)) {
+            $where['name'] = ['like', $searchText];
+        }
         $data = GoodsCategoryService::getGoodsList($where);
         util::success($data);
     }

+ 41 - 0
app-hd/controllers/CgItemController.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace hd\controllers;
+
+use bizHd\purchase\classes\PurchaseClass;
+use bizHd\purchase\classes\PurchaseItemClass;
+use common\components\imgUtil;
+use Yii;
+use common\components\util;
+
+class CgItemController extends BaseController
+{
+
+    //采购成功后改价时获取列表 ssh 2023311
+    public function actionGetCgItemInfo()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $cg = PurchaseClass::getById($id, true);
+        if (empty($cg)) {
+            util::fail('没有找到采购信息');
+        }
+        if ($cg->mainId != $this->mainId) {
+            util::fail('没有权限操作');
+        }
+        $orderSn = $cg->orderSn ?? '';
+        $list = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
+        if (!empty($list)) {
+            foreach ($list as $key => $item) {
+                $shortCover = $item['cover'] ?? '';
+                $cover = imgUtil::groupImg($shortCover);
+                $list[$key]['cover'] = $cover;
+                $list[$key]['shortCover'] = $shortCover;
+            }
+        }
+        $shop = $this->shop;
+        $onlyCg = $shop->onlyCg ?? 1;
+        util::success(['list' => $list, 'onlyCg' => $onlyCg]);
+    }
+
+}

+ 9 - 5
app-hd/controllers/CheckOrderController.php

@@ -39,10 +39,7 @@ class CheckOrderController extends BaseController
         $post['sjId'] = $this->sjId;
         $post['shopId'] = $this->shopId;
         $post['adminId'] = $this->adminId;
-        //盘点是否有未处理的草稿,有的话先处理之前的草稿??
-        //todo
         $this->saveOrder($post, false, false);
-
     }
 
     //盘点存草稿 lqh 2021.1.22
@@ -93,12 +90,20 @@ class CheckOrderController extends BaseController
         if (empty($ghsItemInfo)) {
             util::fail('请选择花材');
         }
-        $ghsItemInfo = json_decode($ghsItemInfo, true); // [{productId:0,bigNum:1,smallNum:0}]
+        $ghsItemInfo = json_decode($ghsItemInfo, true);
         if (!is_array($ghsItemInfo)) {
             util::fail('花材格式不正确');
         }
         //判断花材格式,是否属于当前门店
         ProductClass::valid($ghsItemInfo, $this->mainId);
+
+        foreach ($ghsItemInfo as $key => $item) {
+            //如果盘点数是99999则转为0
+            if (isset($item['bigNum']) && $item['bigNum'] == 99999) {
+                $ghsItemInfo[$key]['bigNum'] = 0;
+            }
+        }
+
         $post['itemInfo'] = $ghsItemInfo;
         if ($update === true) {
             //编辑
@@ -106,7 +111,6 @@ class CheckOrderController extends BaseController
         } else {
             $order = CheckOrderClass::opOrder($post, $draft, $update);
         }
-
         if ($order) {
             util::success($order);
         } else {

+ 30 - 0
app-hd/controllers/GhsController.php

@@ -10,6 +10,7 @@ use bizGhs\custom\classes\CustomLevelClass;
 use bizHd\stat\classes\StatVisitClass;
 use common\components\dict;
 use common\components\imgUtil;
+use common\components\stringUtil;
 use common\components\util;
 use Yii;
 
@@ -24,6 +25,35 @@ class GhsController extends BaseController
         'zs' => ['name' => '金店', 'num' => 0, 'amount' => 0, 'key' => 'zs'],
     ];
 
+    //添加虚拟的供货商 ssh 20230305
+    public function actionAddGhs()
+    {
+        $post = Yii::$app->request->post();
+        $name = $post['name'] ?? '';
+        if (empty($name)) {
+            util::fail('请填写名称');
+        }
+        if (stringUtil::getWordNum($name) > 8) {
+            util::fail('名称不能超过8个汉字');
+        }
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $shopId = $this->shopId;
+            $has = GhsClass::getByCondition(['ownShopId' => $shopId, 'name' => $name], true);
+            if (!empty($has)) {
+                util::fail($name . ' 已经存在了');
+            }
+            \bizHd\ghs\services\GhsService::addVirtualGhs($post, $this->shop);
+            $transaction->commit();
+            util::complete('添加成功');
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::error("添加失败原因:" . $e->getMessage());
+            util::fail('添加失败');
+        }
+    }
+
     //是否屏蔽 ssh 20230226
     public function actionChangeDelStatus()
     {

+ 6 - 3
app-hd/controllers/GoodsController.php

@@ -63,7 +63,8 @@ class GoodsController extends BaseController
         $data['shopId'] = $this->shopId ?? 0;
         $data['property'] = 0;
         $data['flower'] = 1;
-        unset($data['stock']);
+        $staff = $this->shopAdmin;
+        $data['staffName'] = $staff->name ?? '';
         $return = GoodsClass::addGoods($data);
         util::success($return);
     }
@@ -150,13 +151,15 @@ class GoodsController extends BaseController
         $data['flower'] = $info['flower'] ?? 0;
 
         if (isset($info['spu']) && !empty($info['spu'])) {
-            util::fail('美团商品暂时不能修改,请在美团APP上修改');
+            util::fail('美团商品暂时不能修改');
         }
 
+        $staff = $this->shopAdmin;
+
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
-            GoodsClass::updateGoods($info, $data);
+            GoodsClass::updateGoods($info, $data, $staff);
             $transaction->commit();
             util::complete();
         } catch (Exception $e) {

+ 13 - 1
app-hd/controllers/KindController.php

@@ -14,7 +14,19 @@ class KindController extends BaseController
     //品类列表
     public function actionList()
     {
-        $list = KindClass::getKindList($this->mainId);
+        $get = Yii::$app->request->get();
+        $mainId = $this->mainId ?? 0;
+        $where = ['mainId' => $mainId, 'delStatus' => 0];
+        $name = isset($get['name']) ? $get['name'] : '';
+        $name = trim($name);
+        if (!empty($name)) {
+            $where['name'] = ['like', $name];
+        }
+        $flower = $get['flower'] ?? '';
+        if (is_numeric($flower)) {
+            $where['flower'] = $flower;
+        }
+        $list = KindClass::getKindList($where);
         util::success($list);
     }
 

+ 79 - 0
app-hd/controllers/PdGoodsController.php

@@ -0,0 +1,79 @@
+<?php
+
+namespace hd\controllers;
+
+use bizHd\pd\classes\PdGoodsClass;
+use bizHd\pd\classes\PdGoodsDetailClass;
+use Yii;
+use common\components\util;
+
+class PdGoodsController extends BaseController
+{
+
+    //订单列表 ssh 20230302
+    public function actionList()
+    {
+        $get = Yii::$app->request->get();
+        $orderStatus = isset($get['status']) ? $get['status'] : '';
+        $where = [];
+        $where['shopId'] = $this->shopId;
+        if (!empty($orderStatus)) {
+            $where['status'] = $orderStatus;
+        }
+        $list = PdGoodsClass::getPdList($where);
+        util::success($list);
+    }
+
+    //订单详情
+    public function actionGetInfo()
+    {
+        $get = Yii::$app->request->get();
+        $orderSn = $get['orderSn'] ?? '';
+        $info = PdGoodsClass::getByCondition(['orderSn' => $orderSn], true);
+        if (empty($info) || $info->mainId != $this->mainId) {
+            util::fail('没有找到盘点记录');
+        }
+        $detail = PdGoodsDetailClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+        $data = ['info' => $info, 'goodsList' => $detail];
+        util::success($data);
+    }
+
+    //创建盘点 ssh 20230302
+    public function actionCreateOrder()
+    {
+        $post = Yii::$app->request->post();
+        $post['sjId'] = $this->sjId;
+        $post['shopId'] = $this->shopId;
+        $staff = $this->shopAdmin;
+        $post['adminId'] = $this->adminId;
+        $post['staffName'] = $staff->name ?? '';
+        $post['mainId'] = $this->mainId;
+        $goodsItemInfo = $post['goodsInfo'] ?? '';
+        if (empty($goodsItemInfo)) {
+            util::fail('请选择花材');
+        }
+        $goodsItemInfo = json_decode($goodsItemInfo, true);
+        if (!is_array($goodsItemInfo)) {
+            util::fail('商品格式错误');
+        }
+        foreach ($goodsItemInfo as $key => $item) {
+            //如果盘点数是99999则转为0
+            if (isset($item['num']) && $item['num'] == 99999) {
+                $goodsItemInfo[$key]['num'] = 0;
+            }
+        }
+        $post['goodsInfo'] = $goodsItemInfo;
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            PdGoodsClass::createPd($post);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("操作原因:" . $e->getMessage());
+            util::fail('操作失败');
+        }
+    }
+
+}

+ 4 - 0
app-hd/controllers/ProductController.php

@@ -72,10 +72,14 @@ class ProductController extends BaseController
         $post['mainId'] = $this->mainId;
 
         $price = $post['price'] ?? 0;
+        if ($price <= 0) {
+            util::fail('请填写价格');
+        }
         $addPrice = $post['addPrice'] ?? 0;
         if ($addPrice > $price) {
             util::fail('加价不能大于售价');
         }
+        $post['skPrice'] = $price;
         $cost = bcsub($price, $addPrice, 2);
         $post['cost'] = $cost;
         ItemClass::addItem($post, $this->shop);

+ 83 - 1
app-hd/controllers/PurchaseController.php

@@ -22,12 +22,94 @@ use common\components\noticeUtil;
 use Yii;
 use common\components\util;
 use biz\wx\classes\WxMessageClass;
+use bizGhs\order\services\OrderService;
 
 class PurchaseController extends BaseController
 {
 
     public $guestAccess = ['detail'];
 
+    //虚拟供货商的采购 ssh 20230308
+    public function actionAddVirtualCg()
+    {
+        $post = Yii::$app->request->post();
+        $ghsId = $post['ghsId'] ?? 0;
+        $payMode = $post['payMode'] ?? 0;
+        $payWay = $post['payWay'] ?? 0;
+        $ghsInfo = GhsClass::getById($ghsId);
+        if (empty($ghsInfo)) {
+            util::fail('没有找到供货商');
+        }
+        if (isset($ghsInfo['mainId']) && !empty($ghsInfo['mainId']) && $ghsInfo['mainId'] == $ghsInfo['ownMainId']) {
+            util::fail('这个是你自己的批发店');
+        }
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $post['book'] = $post['book'] ?? 0;
+            $post['sjId'] = $this->sjId;
+            $post['shopId'] = $this->shopId;
+            $post['shopAdminId'] = $this->shopAdminId;
+            $post['ghsId'] = $ghsId;
+            $post['ghsName'] = $ghsInfo['name'] ?? '';
+            $post['ghsMobile'] = $ghsInfo['mobile'] ?? '';
+            $post['ghsAvatar'] = $ghsInfo['avatar'] ?? '';
+            $post['ghsFullAddress'] = $ghsInfo['fullAddress'] ?? '';
+            $customId = $ghsInfo['customId'] ?? 0;
+            $post['customId'] = $customId;
+            $shopAdmin = $this->shopAdmin ?? null;
+            $name = $shopAdmin->name ?? '';
+            $post['shopAdminName'] = $name;
+            $post['mainId'] = $this->mainId;
+            $product = $post['product'] ?? '';
+            $productList = json_decode($product, true);
+            //判断product数据是不是同个供货商的
+            $ids = array_unique(array_filter(array_column($productList, 'productId')));
+            $productInfoList = ProductClass::getByIds($ids, null, 'id');
+            if (!empty($productInfoList)) {
+                foreach ($productInfoList as $currentInfo) {
+                    if (isset($currentInfo['mainId']) == false || $currentInfo['mainId'] != $this->mainId) {
+                        util::fail('只能选择同一家的商品哦');
+                    }
+                }
+                if (count($productInfoList) != count($ids)) {
+                    util::fail('存在无效商品');
+                }
+            } else {
+                util::fail('花材不存在');
+            }
+            //供货商预订单最低公斤数要求和每公斤服务费
+            $ghsInfo['kiloFee'] = 0;
+            $ghsInfo['miniKilo'] = 0;
+            $post['product'] = $productList;
+            $packCost = 0;
+            $post['packCost'] = $packCost;
+            $post['sendCost'] = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
+            $respond = PurchaseService::createPurchase($post, $ghsInfo);
+
+            if ($payMode == 0) {
+                //欠款
+                PurchaseService::debt($respond);
+            } else {
+                //线下支付
+                PurchaseService::payAfter($respond, $payWay);
+                $saleId = $respond->saleId ?? 0;
+                $order = OrderClass::getById($saleId, true);
+                if (empty($order)) {
+                    util::fail('没有找到订单');
+                }
+                OrderService::payAfter($order, $payWay, true);
+            }
+
+            $transaction->commit();
+            util::success($respond);
+        } catch (Exception $e) {
+            $transaction->rollBack();
+            util::fail();
+        }
+    }
+
     //生成采购单 ssh 2021.1.17
     public function actionCreateOrder()
     {
@@ -60,7 +142,7 @@ class PurchaseController extends BaseController
         $ghsShopId = $ghsInfo['shopId'] ?? 0;
 
         if (isset($ghsInfo['mainId']) && !empty($ghsInfo['mainId']) && $ghsInfo['mainId'] == $ghsInfo['ownMainId']) {
-            util::fail('这个是你的批发店');
+            util::fail('这个是你自己的批发店');
         }
 
         $connection = Yii::$app->db;//事务处理

+ 18 - 56
app-hd/controllers/StatController.php

@@ -14,74 +14,36 @@ use common\components\util;
 class StatController extends BaseController
 {
 
-    //利润表 ssh 20210829
+    //利润表 ssh 20230303
     public function actionProfit()
     {
-        $get = Yii::$app->request->get();
-        $where = [];
-        $where['mainId'] = $this->mainId;
-        $searchTime = $get['searchTime'] ?? 'today';
-        if (!empty($searchTime)) {
-            $startTime = $get['startTime'] ?? '';
-            $endTime = $get['endTime'] ?? '';
-            $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
-            $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
+        $shopAdmin = $this->shopAdmin;
+        if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
+            util::fail('超管才能查看');
         }
 
         //惠雅鲜花员工不能看利润表
         $shopAdmin = $this->shopAdmin;
         $adminId = $shopAdmin->adminId ?? 0;
-        if (in_array($adminId, [2366, 2812, 4004])) {
+        if (in_array($adminId, [2366, 2812, 4004, 3405, 3407])) {
             util::fail('暂无权限');
         }
 
-        //开单
-        $sale = StatSaleClass::getSum($where);
-
-        //调拨出库
-        $stockOut = StatStockOutClass::getSum($where);
-        //盘盈
-        //$pdAdd = StatPdAddClass::getSum($where);
-
-        //采购入库
-        $cg = StatCgClass::getSum($where);
-        //报损
-        //$wast = StatWastClass::getSum($where);
-        //调拨入库
-        $stockIn = StatStockInClass::getSum($where);
-        //盘亏
-        //$pdSub = StatPdSubClass::getSum($where);
-        //退款
-        $refund = StatRefundClass::getSum($where);
-
-        $in = $sale;
-        $in = bcadd($in, $stockOut, 2);
-        //$in = bcadd($in, $pdAdd, 2);
-        $out = $cg;
-        //$out = bcadd($out, $wast, 2);
-        $out = bcadd($out, $stockIn, 2);
-        //$out = bcadd($out, $pdSub, 2);
-        $out = bcadd($out, $refund, 2);
-        $balance = bcsub($in, $out, 2);
-
-        $out = [
-            'income' => [
-                ['name' => '销售', 'amount' => $sale],
-                ['name' => '调拨出库', 'amount' => $stockOut],
-                //['name' => '盘盈', 'amount' => $pdAdd],
-            ],
-            'expend' => [
-                ['name' => '采购', 'amount' => $cg],
-                //['name' => '损耗', 'amount' => $wast],
-                ['name' => '调拨入库', 'amount' => $stockIn],
-                //['name' => '盘亏', 'amount' => $pdSub],
-                ['name' => '退款', 'amount' => $refund],
-            ],
-            'balance' => $balance,
-        ];
+        $mainId = $this->mainId;
+        $respond = \bizGhs\stat\classes\StatSaleClass::profile($mainId);
+        $income = $respond['income'] ?? 0;
+        $expend = $respond['expend'] ?? 0;
+        $balance = $respond['balance'] ?? 0;
 
-        util::success($out);
+        //由于损耗而造成少赚的钱
+        $wastageRespond = \bizGhs\stat\classes\StatSaleClass::wastage($mainId);
+        $wastagePrice = $wastageRespond['totalPrice'] ?? 0;
+        $wastagePrice = floatval($wastagePrice);
 
+        util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance), 'wastagePrice' => $wastagePrice]);
     }
 
     //统计列表 ssh 2020.1.5

+ 16 - 59
app-hd/controllers/StatKdController.php

@@ -1,79 +1,36 @@
 <?php
 
 namespace hd\controllers;
-
-use biz\stat\classes\StatKdClass;
-use biz\stat\classes\StatRefundClass;
-use common\components\dateUtil;
 use Yii;
 use common\components\util;
-
 class StatKdController extends BaseController
 {
 
-    //开单收入统计 ssh 20211017
+    //各渠道收入 ssh 20220711
     public function actionProfile()
     {
-        $get = Yii::$app->request->get();
-        $where = [];
-        $where['shopId'] = $this->shopId;
-        if (isset($get['shopId']) && !empty($get['shopId'])) {
-            $where['shopId'] = $get['shopId'];
+        $shopAdmin = $this->shopAdmin;
+        if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
+            util::fail('超管才能查看');
         }
-
-        //惠雅鲜花员工不能看利润表
+        //惠雅鲜花员工不能看收入情况
         $shopAdmin = $this->shopAdmin;
         $adminId = $shopAdmin->adminId ?? 0;
-        if (in_array($adminId, [2366, 2812, 4004])) {
+        if (in_array($adminId, [2366, 2812, 4004, 3405, 3407])) {
             util::fail('暂无权限');
         }
-
-        $searchTime = $get['searchTime'] ?? 'today';
-        if (!empty($searchTime)) {
-            $startTime = $get['startTime'] ?? '';
-            $endTime = $get['endTime'] ?? '';
-            $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
-            $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
-        }
-        $kdList = StatKdClass::getAllByCondition($where, null, '*');
-
-        $kd = ['wx' => 0, 'alipay' => 0, 'balance' => 0, 'cash' => 0, 'bank' => 0, 'debt' => 0, 'amount' => 0];
-        if (!empty($kdList)) {
-            foreach ($kdList as $key => $item) {
-                $kd['wx'] = bcadd($kd['wx'], $item['wx']);
-                $kd['alipay'] = bcadd($kd['alipay'], $item['alipay']);
-                $kd['balance'] = bcadd($kd['balance'], $item['balance']);
-                $kd['cash'] = bcadd($kd['cash'], $item['cash']);
-                $kd['bank'] = bcadd($kd['bank'], $item['bank']);
-                $kd['debt'] = bcadd($kd['debt'], $item['debt']);
-                $kd['amount'] = bcadd($kd['amount'], $item['amount']);
-            }
-        }
-
-        $refund = ['wx' => 0, 'alipay' => 0, 'balance' => 0, 'cash' => 0, 'bank' => 0, 'debt' => 0, 'amount' => 0];
-        $refundList = StatRefundClass::getAllByCondition($where, null, '*');
-        if (!empty($refundList)) {
-            foreach ($refundList as $key => $item) {
-                $refund['wx'] = bcadd($refund['wx'], $item['wx']);
-                $refund['alipay'] = bcadd($refund['alipay'], $item['alipay']);
-                $refund['balance'] = bcadd($refund['balance'], $item['balance']);
-                $refund['cash'] = bcadd($refund['cash'], $item['cash']);
-                $refund['bank'] = bcadd($refund['bank'], $item['bank']);
-                $refund['debt'] = bcadd($refund['debt'], $item['debt']);
-                $refund['amount'] = bcadd($refund['amount'], $item['amount']);
+        $get = Yii::$app->request->get();
+        $contain = $get['contain'] ?? 0;
+        $incomeList = \bizGhs\stat\classes\StatKdClass::eachChannelIncome($this->mainId, $this->shop, $contain);
+        $totalIncome = 0;
+        if (!empty($incomeList)) {
+            foreach ($incomeList as $item) {
+                $amount = $item['amount'] ?? 0;
+                $totalIncome = bcadd($totalIncome, $amount, 2);
+                $totalIncome = floatval($totalIncome);
             }
         }
-        $arr = [
-            ['name' => '微信支付', 'kd' => $kd['wx'], 'refund' => $refund['wx']],
-            ['name' => '支付宝', 'kd' => $kd['alipay'], 'refund' => $refund['alipay']],
-            ['name' => '欠账', 'kd' => $kd['debt'], 'refund' => $refund['debt']],
-            ['name' => '余额', 'kd' => $kd['balance'], 'refund' => $refund['balance']],
-            ['name' => '现金', 'kd' => $kd['cash'], 'refund' => $refund['cash']],
-            ['name' => '银行卡', 'kd' => $kd['bank'], 'refund' => $refund['bank']],
-            ['name' => '总计', 'kd' => $kd['amount'], 'refund' => $refund['amount']],
-        ];
-        $income = floatval(bcsub($kd['amount'], $refund['amount'], 2));
-        util::success(['list' => $arr, 'income' => $income]);
+        util::success(['list' => $incomeList, 'totalIncome' => $totalIncome]);
     }
 
 }

+ 2 - 1
biz-ghs/apply/services/ApplyService.php

@@ -21,10 +21,11 @@ class ApplyService extends BaseService
             util::fail('没有找到申请记录');
         }
         $applyId = $apply['id'];
+        $live = isset($apply['live']) ? $apply['live'] : 1;
         ApplyClass::updateById($applyId, ['status' => ApplyClass::STATUS_PASS, 'remark' => $remark]);
         $apply['name'] = isset($apply['name']) ? $apply['name'] : '';
         //初始化常用花材
-        $main = \bizGhs\shop\classes\MainClass::addMainInitItem();
+        $main = \bizGhs\shop\classes\MainClass::addMainInitItem($live);
 
         $respond = MerchantService::initGhsBaseInfo($apply, $main, true);
         $shop = $respond['shop'] ?? [];

+ 1 - 1
biz-ghs/item/classes/ItemClassClass.php

@@ -147,7 +147,7 @@ class ItemClassClass extends BaseClass
         if (!$res) {
             //没有则新增
             $classData = ['mainId' => $mainId, 'name' => '默认分类', 'inTurn' => -1, 'isDefault' => 1];
-            $res = self::add($classData);
+            $res = self::add($classData, true);
         }
         return $res->id ?? 0;
     }

+ 3 - 0
biz-ghs/merchant/services/MerchantService.php

@@ -34,6 +34,7 @@ class MerchantService extends BaseService
     {
         $applyId = $applyData['id'] ?? 0;
         $adminId = $applyData['adminId'] ?? 0;
+        $live = isset($applyData['live']) ? $applyData['live'] : 1;
         $mainId = $main->id ?? 0;
         unset($applyData['id']);
 
@@ -60,6 +61,7 @@ class MerchantService extends BaseService
 
         $sjData = $applyData;
         $sjData['style'] = dict::getDict('ptStyle', 'ghs');
+        $sjData['live'] = $live;
         $sj = self::add($sjData, true);
         $sjId = $sj->id;
         $sjName = $sj->name ?? 0;
@@ -136,6 +138,7 @@ class MerchantService extends BaseService
             'long' => $applyData['long'] ?? '',
             'img' => ['/example/shop/1.jpg'],
             'ptStyle' => $ptStyle,
+            'live' => $live,
         ];
         $shopRespond = \bizGhs\shop\classes\ShopClass::addShop($shopData);
         $shopId = $shopRespond->id;

+ 7 - 1
biz-ghs/order/classes/OrderClass.php

@@ -384,7 +384,7 @@ class OrderClass extends BaseClass
         $data['orderSn'] = $orderSn;
         $data['payStatus'] = self::PAY_STATUS_UN_PAY;
         $data['customId'] = isset($data['customId']) && !empty($data['customId']) ? $data['customId'] : 0;
-
+        $live = isset($data['live']) ? $data['live'] : 1;
         $currentShopId = $data['shopId'] ?? 0;
         $shop = ShopClass::getLockById($currentShopId);
         if (empty($shop)) {
@@ -405,6 +405,12 @@ class OrderClass extends BaseClass
             $stockMayChange = false;
             $data['stockChange'] = 0;
         }
+
+        //花店向虚拟批发店采购的,批发店没有的花材需要补充
+        if ($live == 0) {
+            $product = \bizHd\product\classes\ProductClass::hdToggleGhs($product, $shop);
+        }
+
         $respond = OrderItemClass::replaceItem($orderSn, $product, $data, $stockMayChange);
 
         $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;

+ 24 - 17
biz-ghs/order/classes/OrderItemClass.php

@@ -55,7 +55,8 @@ class OrderItemClass extends BaseClass
         $customId = $post['customId'] ?? 0;
         $custom = CustomClass::getById($customId, true);
         $level = $custom->level ?? 0;
-        $respond = ProductClass::formatProductInfo($product, $level);
+        $live = isset($custom->live) ? $custom->live : 1;
+        $respond = ProductClass::formatProductInfo($product, $level, $live);
         $product = $respond['product'];
         $weight = 0;
         $mainId = $post['mainId'] ?? 0;
@@ -114,22 +115,28 @@ class OrderItemClass extends BaseClass
             $weight = bcadd($w, $weight, 2);
 
             if ($stockMayChange == true) {
-
-                $checkStock = true;
-                $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum, $checkStock);
-                $recordData = [];
-                $recordData['sjId'] = $post['sjId'] ?? 0;
-                $recordData['shopId'] = $post['shopId'] ?? 0;
-                $recordData['mainId'] = $post['mainId'] ?? 0;
-                $recordData['itemId'] = $val['itemId'] ?? 0;
-                $recordData['itemNum'] = $itemNum;
-                $recordData['oldStock'] = $stockInfo['oldStock'];
-                $recordData['newStock'] = $stockInfo['newStock'];
-                $recordData['productId'] = $productId;
-                $recordData['orderSn'] = $orderSn;
-                $recordData['relateName'] = $post['customName'] ?? '';
-                $recordData['ptStyle'] = dict::getDict('ptStyle', 'ghs');
-                StockRecordClass::addSellStockOrderRecord($recordData);
+                //小单位花材开单暂时不扣库存
+                if (intval($itemNum) > 0) {
+                    $checkStock = true;
+                    //如果是虚拟客户,说明自己也是虚拟批发店,虚拟批发店不用考虑库存
+                    if ($live == 0) {
+                        $checkStock = false;
+                    }
+                    $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum, $checkStock);
+                    $recordData = [];
+                    $recordData['sjId'] = $post['sjId'] ?? 0;
+                    $recordData['shopId'] = $post['shopId'] ?? 0;
+                    $recordData['mainId'] = $post['mainId'] ?? 0;
+                    $recordData['itemId'] = $val['itemId'] ?? 0;
+                    $recordData['itemNum'] = intval($itemNum);
+                    $recordData['oldStock'] = $stockInfo['oldStock'];
+                    $recordData['newStock'] = $stockInfo['newStock'];
+                    $recordData['productId'] = $productId;
+                    $recordData['orderSn'] = $orderSn;
+                    $recordData['relateName'] = $post['customName'] ?? '';
+                    $recordData['ptStyle'] = dict::getDict('ptStyle', 'ghs');
+                    StockRecordClass::addSellStockOrderRecord($recordData);
+                }
             }
         }
         $respond['weight'] = $weight;

+ 22 - 19
biz-ghs/order/classes/RefundOrderItemClass.php

@@ -33,25 +33,28 @@ class RefundOrderItemClass extends BaseClass
             $bigNum = $num;
         }
 
-        //退货加库存
-        $stockInfo = ProductClass::addStock($productId, $bigNum, $smallNum);
-        $oldStock = $stockInfo['oldStock'] ?? 0;
-        $newStock = $stockInfo['newStock'] ?? 0;
-
-        //库存变动记录
-        $recordData = [];
-        $recordData['shopId'] = $data['shopId'];
-        $recordData['relateName'] = $order->customName ?? '';
-        $recordData['itemNum'] = $totalNum;
-        $recordData['sjId'] = $data['sjId'] ?? 0;
-        $recordData['shopId'] = $data['shopId'] ?? 0;
-        $recordData['mainId'] = $data['mainId'] ?? 0;
-        $recordData['orderSn'] = $orderSn;
-        $recordData['itemId'] = $data['itemId'] ?? 0;
-        $recordData['oldStock'] = $oldStock; //当时库存
-        $recordData['productId'] = $productId;
-        $recordData['newStock'] = $newStock;// 最新库存
-        StockRecordClass::ghsRefundAddRecord($recordData);
+        $oldStock = 0;
+        $newStock = 0;
+        if ($bigNum > 0) {
+            //退货加库存
+            $stockInfo = ProductClass::addStock($productId, $bigNum, $smallNum);
+            $oldStock = $stockInfo['oldStock'] ?? 0;
+            $newStock = $stockInfo['newStock'] ?? 0;
+            //库存变动记录
+            $recordData = [];
+            $recordData['shopId'] = $data['shopId'];
+            $recordData['relateName'] = $order->customName ?? '';
+            $recordData['itemNum'] = $totalNum;
+            $recordData['sjId'] = $data['sjId'] ?? 0;
+            $recordData['shopId'] = $data['shopId'] ?? 0;
+            $recordData['mainId'] = $data['mainId'] ?? 0;
+            $recordData['orderSn'] = $orderSn;
+            $recordData['itemId'] = $data['itemId'] ?? 0;
+            $recordData['oldStock'] = $oldStock; //当时库存
+            $recordData['productId'] = $productId;
+            $recordData['newStock'] = $newStock;// 最新库存
+            StockRecordClass::ghsRefundAddRecord($recordData);
+        }
 
 
         $data['itemStock'] = $oldStock;

+ 56 - 67
biz-ghs/product/classes/ProductClass.php

@@ -627,17 +627,12 @@ class ProductClass extends BaseClass
     }
 
 
-
     //加库存,允许负库存,负数数量(盘点时)
-
-    /**
-     * @param $productId  门店下的花材ID(xhGhsItemInfo 主键ID)
-     * @param $itemNumBundle  花材数量(扎)
-     * @param $itemNumPiece  花材数量(支)
-     * @return mixed
-     */
     public static function addStock($productId, $itemNumBundle, $itemNumPiece)
     {
+        //小单位库存不再考虑 ssh 20230303
+        $itemNumPiece = 0;
+
         $key = self::LOCK_STOCK . '_' . $productId;
         $lock = util::lock($key);
         if (!$lock) {
@@ -665,15 +660,12 @@ class ProductClass extends BaseClass
 
 
     //todo 库存修改 加锁
-
-    /**
-     * 对商品ID 加库存
-     * @param $productId  商品ID
-     * @param $itemNum  数量
-     * @return mixed
-     */
+    //对商品ID 加库存
     public static function addStockByItemNum($productId, $itemNum)
     {
+        //小单位库存不再考虑 ssh 20230303
+        $itemNum = intval($itemNum);
+
         $key = self::LOCK_STOCK . '_' . $productId;
         $lock = util::lock($key);
         if (!$lock) {
@@ -695,16 +687,13 @@ class ProductClass extends BaseClass
     }
 
     //减库存,允许负库存,负数数量(盘点时)
-
-    /**
-     * @param $productId  门店下的花材ID(xhGhsItemInfo 主键ID)
-     * @param $itemNumBundle  花材数量(扎)
-     * @param $itemNumPiece  花材数量(支)
-     * @param $checkStock boolean 是否需要判断库存
-     * @return mixed
-     */
+    //checkStock boolean 是否需要判断库存
     public static function decreaseStock($productId, $itemNumBundle, $itemNumPiece, $checkStock = false)
     {
+
+        //小单位库存不再考虑 ssh 20230303
+        $itemNumPiece = 0;
+
         $key = self::LOCK_STOCK . '_' . $productId;
         $lock = util::lock($key);
         if (!$lock) {
@@ -744,12 +733,6 @@ class ProductClass extends BaseClass
 
 
     //根据数量减库存
-
-    /**
-     * @param $productId
-     * @param $itemNum
-     * @return mixed  返回减之前的库存,和减之后的库存
-     */
     public static function decreaseStockByItemNum($productId, $itemNum, $checkStock = false)
     {
         $key = self::LOCK_STOCK . '_' . $productId;
@@ -1016,16 +999,23 @@ class ProductClass extends BaseClass
     }
 
     //下单时计算商品的价格  lqh 2021.1.28
-    public static function formatProductInfo($itemInfo, $level = 0)
+    public static function formatProductInfo($itemInfo, $level = 0, $live = 1)
     {
         $data = [];
         if (empty($itemInfo)) {
             util::fail('请选择花材');
         }
         $itemInfo = self::mergeItemInfo($itemInfo);
+
         $productIds = array_column($itemInfo, 'productId');
-        $productData = ProductClass::getProductByIds($productIds);
-        $productData = array_column($productData, NULL, 'id');
+        $ghsProductData = ProductClass::getProductByIds($productIds);
+        $ghsProductData = array_column($ghsProductData, NULL, 'id');
+        if ($live == 1) {
+            $hdProductData = [];
+        } else {
+            $hdIds = array_column($itemInfo, 'hdProductId');
+            $hdProductData = ProductClass::getByIds($hdIds, null, 'id');
+        }
 
         $totalPrice = 0;
         $totalBigNum = 0;
@@ -1038,11 +1028,12 @@ class ProductClass extends BaseClass
         $totalItemNum = 0;
 
         foreach ($itemInfo as $v) {
-            $productId = $v['productId'];
-            $itemId = $productData[$productId]['itemId'] ?? 0;
-            $ratio = $productData[$productId]['ratio'] ?? 0;
-            $smallRatio = $productData[$productId]['smallRatio'] ?? 1;
-            $cost = $productData[$productId]['cost'] ?? 0;
+            $ghsProductId = $v['productId'];
+
+            $currentGhsProduct = $ghsProductData[$ghsProductId] ?? [];
+            $itemId = $currentGhsProduct['itemId'] ?? 0;
+            $ratio = $currentGhsProduct['ratio'] ?? 0;
+            $cost = $currentGhsProduct['cost'] ?? 0;
 
             $bigNum = $v['bigNum'] ?? 0;
             $smallNum = $v['smallNum'] ?? 0;
@@ -1051,42 +1042,39 @@ class ProductClass extends BaseClass
             $itemNum = self::mergeItemNum($bigNum, $smallNum, $ratio);
             $totalItemNum = bcadd($totalItemNum, $itemNum, 2);
 
-            //供货商开单可以传单价过来
-            $changePrice = isset($v['price']) && $v['price'] > 0 ? $v['price'] : 0;
-
-            //今日特价、会员价
-            $currentProduct = $productData[$productId] ?? [];
-            $itemPrice = self::getFinalPrice($currentProduct, $level, $priceMap, $addPriceMap, $changePrice);
-
-            $bigItemPrice = $itemPrice;
+            if ($live == 1) {
+                //供货商开单可以传单价过来
+                $changePrice = isset($v['price']) && $v['price'] > 0 ? $v['price'] : 0;
+                //今日特价、会员价
+                $itemPrice = self::getFinalPrice($currentGhsProduct, $level, $priceMap, $addPriceMap, $changePrice);
+                $thisPrice = $itemPrice;
+            } else {
+                $itemPrice = $v['unitPrice'] ?? 0;
+                $thisPrice = $itemPrice;
+            }
 
             if ($smallNum > 0) {
-                //如果是小单位数量,则传过来的就是小单位价格,无需转换
-                if (empty($changePrice)) {
-                    $itemPrice = bcdiv($itemPrice, $ratio, 2);
-                    $itemPrice = bcmul($itemPrice, $smallRatio, 2);
-                }
                 $price = bcmul($smallNum, $itemPrice, 2);
             } else {
                 $price = bcmul($bigNum, $itemPrice, 2);
             }
 
             $tmp = [];
-            $tmp['productId'] = $productId;
+            $tmp['productId'] = $ghsProductId;
             $tmp['price'] = $price;
 
             $totalPrice = bcadd($totalPrice, $price, 2);
 
-            $tmp['name'] = $productData[$productId]['name'] ?? '';
-            $tmp['smallUnit'] = $productData[$productId]['smallUnit'] ?? '支';
-            $tmp['bigUnit'] = $productData[$productId]['bigUnit'] ?? '扎';
-            $tmp['cover'] = $productData[$productId]['cover'] ?? '';
+            $tmp['name'] = $currentGhsProduct['name'] ?? '';
+            $tmp['smallUnit'] = $currentGhsProduct['smallUnit'] ?? '支';
+            $tmp['bigUnit'] = $currentGhsProduct['bigUnit'] ?? '扎';
+            $tmp['cover'] = $currentGhsProduct['cover'] ?? '';
             $tmp['itemId'] = $itemId;
-            $tmp['rank'] = $productData[$productId]['rank'] ?? '';
-            $tmp['ratio'] = $productData[$productId]['ratio'] ?? 1;
-            $tmp['variety'] = $productData[$productId]['variety'] ?? 0;
-            $tmp['unitPrice'] = $bigItemPrice;
-            $tmp['unitWeight'] = $productData[$productId]['weight'] ?? 0;;
+            $tmp['rank'] = $currentGhsProduct['rank'] ?? '';
+            $tmp['ratio'] = $currentGhsProduct['ratio'] ?? 1;
+            $tmp['variety'] = $currentGhsProduct['variety'] ?? 0;
+            $tmp['unitPrice'] = $thisPrice;
+            $tmp['unitWeight'] = $currentGhsProduct['weight'] ?? 0;;
             $tmp['num'] = $itemNum;
             $tmp['bigNum'] = $v['bigNum'];
             $tmp['smallNum'] = $v['smallNum'];
@@ -1094,13 +1082,12 @@ class ProductClass extends BaseClass
             $tmp['preBigNum'] = $v['bigNum'];
             $tmp['preSmallNum'] = $v['smallNum'];
             $tmp['userPrice'] = $price;
-            $tmp['weight'] = $productData[$productId]['weight'] ?? 0;
-            $tmp['sjId'] = $productData[$productId]['sjId'] ?? 0;
-            $tmp['shopId'] = $productData[$productId]['shopId'] ?? 0;
-            $tmp['mainId'] = $productData[$productId]['mainId'] ?? 0;
+            $tmp['weight'] = $currentGhsProduct['weight'] ?? 0;
+            $tmp['sjId'] = $currentGhsProduct['sjId'] ?? 0;
+            $tmp['shopId'] = $currentGhsProduct['shopId'] ?? 0;
+            $tmp['mainId'] = $currentGhsProduct['mainId'] ?? 0;
             $tmp['smallUnitPrice'] = $itemPrice;
 
-
             $totalBigNum += $bigNum;
             $totalSmallNum += $smallNum;
 
@@ -1512,9 +1499,10 @@ class ProductClass extends BaseClass
 
         foreach ($productList as $k => $v) {
             $itemId = $v['itemId'] ?? 0;
+            $ghsProductId = $v['productId'] ?? 0;
             if (!isset($hdProductData[$itemId])) {
                 //不存在,则从平台新增
-                $ptItem = \biz\item\classes\PtItemClass::getById($itemId);
+                $ptItem = PtItemClass::getById($itemId);
                 unset($ptItem['addTime']);
                 unset($ptItem['updateTime']);
                 $productData = $ptItem;
@@ -1534,7 +1522,8 @@ class ProductClass extends BaseClass
             } else {
                 $hdProductId = $hdProductData[$itemId]['id'];
             }
-            $productList[$k]['hdProductId'] = $hdProductId;
+            $productList[$k]['productId'] = $hdProductId;
+            $productList[$k]['ghsProductId'] = $ghsProductId;
         }
 
         return $productList;

+ 5 - 2
biz-ghs/shop/classes/MainClass.php

@@ -17,11 +17,14 @@ class MainClass extends BaseClass
     }
 
     //首次开店时创建main并初始化花材 ssh 20220502
-    public static function addMainInitItem()
+    public static function addMainInitItem($live = 1)
     {
         $main = self::addMain();
         $newMainId = $main->id ?? 0;
-        ItemClass::initItem($newMainId);
+        //活的商家要生成花材,虚拟的商家不需要
+        if ($live == 1) {
+            ItemClass::initItem($newMainId);
+        }
         return $main;
     }
 

+ 29 - 1
biz-ghs/stat/classes/StatSaleClass.php

@@ -9,8 +9,10 @@ use bizGhs\expend\classes\ExpendClass;
 use bizGhs\order\classes\PurchaseOrderClass;
 use bizGhs\order\classes\StockWastageOrderClass;
 use bizGhs\staff\classes\SalaryClass;
+use bizHd\goods\classes\PlantCgClass;
 use bizHd\order\classes\OrderClass as HdOrderClass;
 use bizGhs\order\classes\OrderClass;
+use bizHd\purchase\classes\PurchaseClass;
 use common\components\dateUtil;
 use common\components\dict;
 use Yii;
@@ -89,6 +91,30 @@ class StatSaleClass extends BaseClass
         }
         $cg = floatval($cg);
 
+        $lsCgWhere = ['mainId' => $mainId, 'status' => 4];
+        $lsCgWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
+        $lsCgList = PurchaseClass::getAllByCondition($lsCgWhere, null, '*');
+        $lsCgAmount = 0;
+        if (!empty($lsCgList)) {
+            foreach ($lsCgList as $lsCgItem) {
+                $actPrice = $lsCgItem['actPrice'] ?? 0;
+                $lsCgAmount = bcadd($lsCgAmount, $actPrice, 2);
+            }
+        }
+        $lsCgAmount = floatval($lsCgAmount);
+
+        $lzWhere = ['mainId' => $mainId, 'status' => 3];
+        $lzWhere['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
+        $lzCgList = PlantCgClass::getAllByCondition($lzWhere, null, '*');
+        $lzCgAmount = 0;
+        if (!empty($lzCgList)) {
+            foreach ($lzCgList as $lzInfo) {
+                $actPrice = $lzInfo['actPrice'] ?? 0;
+                $lzCgAmount = bcadd($actPrice, $lzCgAmount, 2);
+            }
+        }
+        $lzCgAmount = floatval($lzCgAmount);
+
         //调拨入库
         $stockIn = StatStockInClass::getSum($where);
 
@@ -166,7 +192,9 @@ class StatSaleClass extends BaseClass
             ['name' => '批发运费', 'id' => 'pfSendCost', 'amount' => floatval($pfSendCost)],
             ['name' => '零售运费', 'id' => 'lsSendCost', 'amount' => floatval($lsSendCost)],
             ['name' => '美团手续费', 'id' => 'mtFee', 'amount' => floatval($lsServiceFee)],
-            ['name' => '采购', 'id' => 'cg', 'amount' => floatval($cg)],
+            ['name' => '花材采购', 'id' => 'cg', 'amount' => floatval($cg)],
+            ['name' => '绿植资材采购', 'id' => 'cg', 'amount' => floatval($lzCgAmount)],
+            ['name' => '零售花材采购', 'id' => 'cg', 'amount' => floatval($lsCgAmount)],
             ['name' => '调拨入库', 'id' => 'allot', 'amount' => floatval($stockIn)],
             ['name' => '员工工资', 'id' => 'salary', 'amount' => floatval($salary)],
         ];

+ 21 - 16
biz-hd/cg/classes/CgRefundItemClass.php

@@ -37,23 +37,28 @@ class CgRefundItemClass extends BaseClass
             $smallNum = $num;
             $totalNum = bcdiv($num, $ratio, 2);
         }
-        $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum);
-        $oldStock = $stockInfo['oldStock'] ?? 0;
-        $newStock = $stockInfo['newStock'] ?? 0;
 
-        $recordData = [];
-        $recordData['shopId'] = $data['shopId'];
-        $recordData['itemNum'] = $totalNum;
-        $recordData['sjId'] = $sjId;
-        $recordData['shopId'] = $shopId;
-        $recordData['mainId'] = $mainId;
-        $recordData['orderSn'] = $orderSn;
-        $recordData['itemId'] = $ptItemId;
-        $recordData['oldStock'] = $oldStock; //当时库存
-        $recordData['productId'] = $productId;
-        $recordData['newStock'] = $newStock;// 最新库存
-        $recordData['relateName'] = $ghsName;
-        StockRecordClass::hdCgApplyRefundAddRecord($recordData);
+        $newStock = 0;
+        $oldStock = 0;
+        if ($bigNum > 0) {
+            $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum);
+            $oldStock = $stockInfo['oldStock'] ?? 0;
+            $newStock = $stockInfo['newStock'] ?? 0;
+
+            $recordData = [];
+            $recordData['shopId'] = $data['shopId'];
+            $recordData['itemNum'] = $totalNum;
+            $recordData['sjId'] = $sjId;
+            $recordData['shopId'] = $shopId;
+            $recordData['mainId'] = $mainId;
+            $recordData['orderSn'] = $orderSn;
+            $recordData['itemId'] = $ptItemId;
+            $recordData['oldStock'] = $oldStock; //当时库存
+            $recordData['productId'] = $productId;
+            $recordData['newStock'] = $newStock;// 最新库存
+            $recordData['relateName'] = $ghsName;
+            StockRecordClass::hdCgApplyRefundAddRecord($recordData);
+        }
 
         $data['itemStock'] = $oldStock;
         $data['newStock'] = $newStock;

+ 10 - 0
biz-hd/common/classes/MobileSnClass.php

@@ -0,0 +1,10 @@
+<?php
+namespace bizHd\common\classes;
+use Yii;
+use bizHd\base\classes\BaseClass;
+class MobileSnClass extends BaseClass
+{
+
+	public static $baseFile = '\bizHd\common\models\MobileSn';
+
+}

+ 13 - 0
biz-hd/common/models/MobileSn.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizHd\common\models;
+use bizHd\base\models\Base;
+
+class MobileSn extends Base
+{
+	
+	public static function tableName()
+	{
+		return 'xhMobileSn';
+	}
+
+}

+ 57 - 0
biz-hd/ghs/services/GhsService.php

@@ -3,6 +3,11 @@
 namespace bizHd\ghs\services;
 
 use bizHd\base\services\BaseService;
+use bizHd\saas\classes\ApplyClass;
+use bizHd\saas\services\ApplyService;
+use bizHd\shop\classes\ShopClass;
+use common\components\dict;
+use common\components\orderSn;
 use common\components\util;
 use Yii;
 
@@ -11,4 +16,56 @@ class GhsService extends BaseService
 
     public static $baseFile = '\bizHd\ghs\classes\GhsClass';
 
+    //添加虚拟供货商 ssh 20230305
+    public static function addVirtualGhs($data, $hdShop)
+    {
+        $mobile = orderSn::getMobileSn();
+        $name = $data['name'] ?? '';
+
+        $hasApply = ApplyClass::getByCondition(['mobile' => $mobile], true);
+        if (!empty($hasApply)) {
+            util::fail('手机号已存在,请和管理员联系');
+        }
+        $has = ShopClass::getByCondition(['mobile' => $mobile], true);
+        if (!empty($has)) {
+            util::fail('手机号已经存在,请跟管理联系');
+        }
+
+        //将下面的环境定义为批发环境,后继代码可能要用到,不确定,避免风险 ssh 20230306
+        Yii::$app->params['ptStyle'] = 2;
+
+        $adminInfo = ['name' => $name, 'mobile' => $mobile, 'style' => 2, 'ghsMiniOpenId' => ''];
+        $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
+        $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
+        $adminId = $admin['id'] ?? 0;
+        $applyData = [
+            'mobile' => $mobile,
+            'name' => $name,
+            'from' => ApplyClass::FROM_GHS,
+            'lat' => '40.023916',
+            'long' => '116.298875',
+            'live' => 0,
+            'adminId' => $adminId,
+            'province' => '北京市',
+            'city' => '北京市',
+            'address' => '上地',
+            'showAddress' => '上地',
+            'style' => 0,
+        ];
+        $apply = ApplyService::replaceGhs($applyData);
+        $applyId = $apply['id'] ?? 0;
+        if (empty($applyId)) {
+            util::fail('没有找到申请记录');
+        }
+        \bizGhs\apply\services\ApplyService::pass($applyId);
+
+        $ghsShop = ShopClass::getByCondition(['mobile' => $mobile, 'ptStyle' => dict::getDict('ptStyle', 'ghs')], true);
+        if (empty($ghsShop)) {
+            util::fail('供货商没有生成,请联系管理员');
+        }
+        $ghsShopId = $ghsShop->id ?? 0;
+        $hdShopId = $hdShop->id ?? 0;
+        \bizGhs\custom\classes\CustomClass::build($ghsShopId, $hdShopId);
+    }
+
 }

+ 90 - 7
biz-hd/goods/classes/GoodsClass.php

@@ -3,6 +3,7 @@
 namespace bizHd\goods\classes;
 
 use biz\shop\classes\MainClass;
+use biz\stock\classes\GoodsStockRecordClass;
 use biz\shop\classes\ShopCapitalClass;
 use biz\stat\classes\StatCgPlantClass;
 use biz\stat\classes\StatOutClass;
@@ -73,7 +74,6 @@ class GoodsClass extends BaseClass
 
     public static function cgPlant($data, $shop)
     {
-        //[{"goodsId":"1486","num":"1","price":"2"}]
         $goodsData = $data['goods'] ?? '';
         if (empty($goodsData)) {
             $name = $data['name'] ?? '';
@@ -85,6 +85,8 @@ class GoodsClass extends BaseClass
             $shopId = $data['shopId'] ?? 0;
             $mainId = $data['mainId'] ?? 0;
             $status = $data['status'] ?? 0;
+            $kindId = $data['kindId'] ?? 0;
+            $kindName = $data['kindName'] ?? '';
             $delStatus = $data['delStatus'] ?? 0;
             $num = $data['num'] ?? 0;
             $cgPrice = $data['cgPrice'] ?? 0;
@@ -97,7 +99,24 @@ class GoodsClass extends BaseClass
             $cover = isset($shopImg[0]) ? $shopImg[0] : '';
             $catId = $data['catId'] ?? 0;
             if (empty($catId)) {
-                util::fail('请选择分类');
+                $hasCat = CategoryClass::getByCondition(['mainId' => $mainId, 'flower' => 0, 'default' => 1], true);
+                if (empty($hasCat)) {
+                    $catData = [
+                        'mainId' => $mainId,
+                        'sjId' => $sjId,
+                        'shopId' => $shopId,
+                        'default' => 1,
+                        'flower' => 0,
+                        'categoryName' => '未分类绿植',
+                        'inTurn' => 0,
+                        'status' => 0,
+                    ];
+                    $hasCat = CategoryClass::add($catData, true);
+                }
+                $catId = $hasCat->id ?? 0;
+                if (empty($catId)) {
+                    util::fail('还是没有找到分类');
+                }
             }
             $catIds = [$catId];
             $addGoodsData = [
@@ -113,6 +132,8 @@ class GoodsClass extends BaseClass
                 'shopImg' => $shopImg,
                 'catIds' => $catIds,
                 'cover' => $cover,
+                'kindId' => $kindId,
+                'kindName' => $kindName
             ];
             $respond = self::addGoods($addGoodsData);
             $goodsId = $respond->id ?? 0;
@@ -169,6 +190,7 @@ class GoodsClass extends BaseClass
             PlantCgItemClass::addData($addCgItem);
             $goodsPrice = bcadd($totalPrice, $goodsPrice, 2);
         }
+        $remark = $data['remark'] ?? '';
         $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
         $labourCost = $data['labourCost'] ?? 0;
         $otherCost = bcadd($sendCost, $labourCost, 2);
@@ -191,6 +213,7 @@ class GoodsClass extends BaseClass
             'staffName' => $staffName,
             'staffId' => $staffId,
             'status' => 3,
+            'remark' => $remark,
         ];
         $return = PlantCgClass::addData($orderData);
         $id = $return->id ?? 0;
@@ -312,6 +335,8 @@ class GoodsClass extends BaseClass
         $flowerNum = $data['flowerNum'] ?? 0;
         $sn = orderSn::getGoodsSn();
         $data['sn'] = $sn;
+        $addStock = $data['stock'] ?? 0;
+        unset($data['stock']);
         $info = self::add($data, true);
         $id = $info->id;
         $name = $info->name;
@@ -321,6 +346,25 @@ class GoodsClass extends BaseClass
         $shopId = $data['shopId'] ?? 0;
         $flower = $data['flower'] ?? 0;
         $status = $data['status'] ?? 0;
+        $staffName = $data['staffName'] ?? '';
+
+        if ($addStock > 0) {
+            $stockRespond = GoodsClass::addStock($id, $mainId, $addStock);
+            $oldStock = $stockRespond['oldStock'] ?? 0;
+            $newStock = $stockRespond['newStock'] ?? 0;
+            $recordData = [];
+            $recordData['sjId'] = $sjId;
+            $recordData['shopId'] = $shopId;
+            $recordData['mainId'] = $mainId;
+            $recordData['orderSn'] = '';
+            $recordData['goodsId'] = $id;
+            $recordData['goodsNum'] = $addStock;
+            $recordData['oldStock'] = $oldStock;
+            $recordData['newStock'] = $newStock;
+            $recordData['relateName'] = $staffName;
+            GoodsStockRecordClass::pdGoods($recordData);
+        }
+
         $delStatus = $data['delStatus'] ?? 0;
         $setItemNum = $data['setItemNum'] ?? 0;
         $categoryData = CategoryClass::getCategory($mainId);
@@ -412,7 +456,7 @@ class GoodsClass extends BaseClass
     }
 
     //更新商品 ssh 2019.12.7
-    public static function updateGoods($info, $data)
+    public static function updateGoods($info, $data, $staff)
     {
         $id = $info['id'] ?? 0;
         $preSetItemNum = $info['setItemNum'] ?? 0;
@@ -465,8 +509,47 @@ class GoodsClass extends BaseClass
         $data['cover'] = $data['shopImg'][0] ?? '';
         $data['shopImg'] = json_encode($data['shopImg']);
         $data['py'] = $py;
-        //库存不可修改
-        unset($data['stock']);
+
+        //库存可以修改
+        if (isset($data['stock']) && is_numeric($data['stock'])) {
+            $preStock = $info['stock'] ?? 0;
+            $newStock = $data['stock'];
+            if ($newStock != $preStock) {
+                if ($staff->super != 1) {
+                    util::fail('管理员才能修改库存');
+                }
+                if ($newStock < 0) {
+                    util::fail("库存不能小于0");
+                }
+                if (floor($newStock) != $newStock) {
+                    util::fail('库存请填写整数');
+                }
+                if ($newStock > $preStock) {
+                    $diffNum = bcsub($newStock, $preStock);
+                    $respond = GoodsClass::addStock($id, $mainId, $diffNum);
+                } else {
+                    $diffNum = bcsub($preStock, $newStock);
+                    $checkStock = false;
+                    $params = [];
+                    $respond = GoodsClass::decreaseStock($id, $mainId, $diffNum, $checkStock, $params);
+                }
+                $oldStock = $respond['oldStock'] ?? 0;
+                $newStock = $respond['newStock'] ?? 0;
+                $recordData = [];
+                $recordData['sjId'] = $sjId;
+                $recordData['shopId'] = $shopId;
+                $recordData['mainId'] = $mainId;
+                $recordData['orderSn'] = '';
+                $recordData['goodsId'] = $id;
+                $recordData['goodsNum'] = $diffNum;
+                $recordData['oldStock'] = $oldStock;
+                $recordData['newStock'] = $newStock;
+                $recordData['relateName'] = $staff->name ?? '';
+                GoodsStockRecordClass::pdGoods($recordData);
+            }
+            unset($data['stock']);
+        }
+
         self::updateById($id, $data);
 
         $itemList = $data['itemList'] ?? '';
@@ -603,7 +686,7 @@ class GoodsClass extends BaseClass
             $cardInfo = $params['cardInfo'] ?? '';
             $anonymity = $params['anonymity'] ?? 0;
             $manyType = $params['manyType'] ?? 0;
-            $sendNum = $params['sendNum']??'';
+            $sendNum = $params['sendNum'] ?? '';
             $hasReachTime = 0;
             $reachPeriod = 0;
             $reachDate = '0000-00-00';
@@ -647,7 +730,7 @@ class GoodsClass extends BaseClass
                 'anonymity' => $anonymity,
                 'sh' => $sh,
                 'manyType' => $manyType,
-                'sendNum'=>$sendNum,
+                'sendNum' => $sendNum,
             ];
             $main = MainClass::getById($mainId, true);
             if (empty($main)) {

+ 55 - 6
biz-hd/goods/classes/KindClass.php

@@ -5,6 +5,7 @@ namespace bizHd\goods\classes;
 use common\components\business;
 use common\components\stringUtil;
 use common\components\util;
+use common\components\validate;
 use Yii;
 use bizHd\base\classes\BaseClass;
 
@@ -13,6 +14,54 @@ class KindClass extends BaseClass
 
     public static $baseFile = '\bizHd\goods\models\Kind';
 
+    //初始化开店需要的种类 ssh 20230301
+    public static function initKind($data)
+    {
+        $mainId = $data['mainId'] ?? 0;
+        $sjId = $data['sjId'] ?? 0;
+        $arr = [
+            ['name' => '花束', 'flower' => 1, 'inTurn' => 9900],
+            ['name' => '开业花篮', 'flower' => 1, 'inTurn' => 9800],
+            ['name' => '送礼花篮', 'flower' => 1, 'inTurn' => 9700],
+            ['name' => '婚车', 'flower' => 1, 'inTurn' => 9600],
+            ['name' => '手棒花', 'flower' => 1, 'inTurn' => 9500],
+            ['name' => '讲台花', 'flower' => 1, 'inTurn' => 9400],
+            ['name' => '蝴蝶兰', 'flower' => 0, 'inTurn' => 9300],
+            ['name' => '花瓶', 'flower' => 0, 'inTurn' => 9200],
+            ['name' => '绿植', 'flower' => 0, 'inTurn' => 9150],
+            ['name' => '发财树', 'flower' => 0, 'inTurn' => 9100],
+            ['name' => '平安树', 'flower' => 0, 'inTurn' => 9000],
+            ['name' => '绿宝', 'flower' => 0, 'inTurn' => 8900],
+            ['name' => '绿萝', 'flower' => 0, 'inTurn' => 8700],
+            ['name' => '多肉', 'flower' => 0, 'inTurn' => 8600],
+            ['name' => '天堂鸟', 'flower' => 0, 'inTurn' => 8500],
+            ['name' => '龟背竹', 'flower' => 0, 'inTurn' => 8400],
+            ['name' => '常春藤', 'flower' => 0, 'inTurn' => 8300],
+            ['name' => '富贵竹', 'flower' => 0, 'inTurn' => 8200],
+            ['name' => '豆瓣绿', 'flower' => 0, 'inTurn' => 8100],
+            ['name' => '万年青', 'flower' => 0, 'inTurn' => 8000],
+            ['name' => '散尾葵', 'flower' => 0, 'inTurn' => 7900],
+            ['name' => '一品红', 'flower' => 0, 'inTurn' => 7800],
+            ['name' => '虎尾兰', 'flower' => 0, 'inTurn' => 7700],
+            ['name' => '君子兰', 'flower' => 0, 'inTurn' => 7600],
+            ['name' => '金钱树', 'flower' => 0, 'inTurn' => 7500],
+            ['name' => '三角梅', 'flower' => 0, 'inTurn' => 7400],
+        ];
+        foreach ($arr as $item) {
+            $name = $item['name'];
+            $flower = $item['flower'];
+            $inTurn = $item['inTurn'];
+            $single = [
+                'mainId' => $mainId,
+                'sjId' => $sjId,
+                'name' => $name,
+                'flower' => $flower,
+                'inTurn' => $inTurn,
+            ];
+            self::add($single);
+        }
+    }
+
     public static function addData($post)
     {
         $name = $post['name'] ?? '';
@@ -30,14 +79,14 @@ class KindClass extends BaseClass
         self::add($post, true);
     }
 
-    public static function getKindList($mainId)
+    public static function getKindList($where)
     {
-        $where = ['mainId' => $mainId, 'delStatus' => 0];
-        $kindList = self::getAllByCondition($where, 'flower DESC,inTurn DESC', '*');
-        if (empty($kindList)) {
-            return $kindList;
+        $data = self::getList('*', $where);
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
         }
-        return $kindList;
+        return $data;
     }
 
 }

+ 11 - 1
biz-hd/merchant/services/SjService.php

@@ -5,6 +5,7 @@ namespace bizHd\merchant\services;
 use bizGhs\custom\services\CustomService;
 use bizHd\base\services\BaseService;
 use bizHd\custom\classes\CustomClass;
+use bizHd\goods\classes\KindClass;
 use bizHd\merchant\classes\SjAssetClass;
 use bizHd\merchant\classes\SjClass;
 use bizHd\merchant\classes\SjExtendClass;
@@ -25,6 +26,7 @@ class SjService extends BaseService
     {
         $applyId = $applyData['id'] ?? 0;
         $adminId = $applyData['adminId'] ?? 0;
+        $live = isset($applyData['live']) ? $applyData['live'] : 1;
         $mainId = $main->id ?? 0;
         unset($applyData['id']);
         $ptStyle = dict::getDict('ptStyle', 'hd');
@@ -51,6 +53,7 @@ class SjService extends BaseService
 
         $jsData = $applyData;
         $sjData['style'] = $ptStyle;
+        $sjData['live'] = $live;
         $sj = self::add($jsData, true);
         $sjId = $sj->id;
         $sjName = $sj->name ?? 0;
@@ -125,7 +128,8 @@ class SjService extends BaseService
             'lat' => $applyData['lat'] ?? '',
             'long' => $applyData['long'] ?? '',
             'img' => ['/example/shop/1.jpg'],
-            'ptStyle' => $ptStyle
+            'ptStyle' => $ptStyle,
+            'live' => $live,
         ];
         $shopInfo = ShopClass::addShop($shopData);
         $shopId = $shopInfo->id;
@@ -150,6 +154,12 @@ class SjService extends BaseService
         $shopInfo->defaultCustomId = $customId;
         $shopInfo->save();
 
+        if ($live == 1) {
+            //初始化种类
+            $initKindData = ['mainId' => $mainId, 'sjId' => $sjId];
+            KindClass::initKind($initKindData);
+        }
+
         return ['sj' => $sj, 'shop' => $shopInfo];
     }
 

+ 17 - 13
biz-hd/order/classes/OrderItemClass.php

@@ -37,21 +37,25 @@ class OrderItemClass extends BaseClass
         } else {
             $smallNum = $num;
         }
+
         //库存减少
-        $stockInfo = ProductClass::decreaseStock($itemId, $bigNum, $smallNum, true);
-        $recordData = [];
-        $recordData['sjId'] = $sjId;
-        $recordData['shopId'] = $shopId;
-        $recordData['mainId'] = $mainId;
-        $recordData['itemId'] = $ptItemId;
         $itemNum = ProductClass::mergeItemNum($bigNum, $smallNum, $ratio);
-        $recordData['itemNum'] = $itemNum;
-        $recordData['oldStock'] = $stockInfo['oldStock'];
-        $recordData['newStock'] = $stockInfo['newStock'];
-        $recordData['productId'] = $itemId;
-        $recordData['orderSn'] = $orderSn;
-        $recordData['relateName'] = $customName;
-        StockRecordClass::hdKdAddRecord($recordData);
+        //开单时如果是小单位暂时不扣库存
+        if (intval($itemNum) > 0) {
+            $stockInfo = ProductClass::decreaseStock($itemId, $bigNum, $smallNum, true);
+            $recordData = [];
+            $recordData['sjId'] = $sjId;
+            $recordData['shopId'] = $shopId;
+            $recordData['mainId'] = $mainId;
+            $recordData['itemId'] = $ptItemId;
+            $recordData['itemNum'] = $itemNum;
+            $recordData['oldStock'] = $stockInfo['oldStock'];
+            $recordData['newStock'] = $stockInfo['newStock'];
+            $recordData['productId'] = $itemId;
+            $recordData['orderSn'] = $orderSn;
+            $recordData['relateName'] = $customName;
+            StockRecordClass::hdKdAddRecord($recordData);
+        }
 
         $result = self::add($data, true);
 

+ 111 - 0
biz-hd/pd/classes/PdGoodsClass.php

@@ -0,0 +1,111 @@
+<?php
+
+namespace bizHd\pd\classes;
+
+use biz\stock\classes\GoodsStockRecordClass;
+use bizHd\base\classes\BaseClass;
+use bizHd\goods\classes\GoodsClass;
+use common\components\orderSn;
+use common\components\util;
+use Yii;
+
+class PdGoodsClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\pd\models\PdGoods';
+
+    public static function addBase($data, $bool = false)
+    {
+        return self::add($data, $bool);
+    }
+
+    public static function getPdList($where)
+    {
+        $data = self::getList('*', $where, 'addTime DESC');
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
+        }
+        return $data;
+    }
+
+    //创建盘点 ssh 20230302
+    public static function createPd($data)
+    {
+        $goodsList = $data['goodsInfo'];
+        $mainId = $data['mainId'] ?? 0;
+        $sjId = $data['sjId'] ?? 0;
+        $shopId = $data['shopId'] ?? 0;
+        $staffName = $data['staffName'] ?? '';
+        $orderSn = orderSn::getPdGoodsSn();
+        $data['orderSn'] = $orderSn;
+        $ids = array_column($goodsList, 'goodsId');
+        $ids = array_unique(array_filter($ids));
+        $goodsInfo = GoodsClass::getByIds($ids, null, 'id');
+        if (empty($goodsInfo)) {
+            util::fail('没有商品');
+        }
+        foreach ($goodsInfo as $goodsData) {
+            $name = $goodsData['name'] ?? '';
+            if (isset($goodsData['mainId']) == false || $goodsData['mainId'] != $mainId) {
+                util::fail($name . '没有权限盘点');
+            }
+        }
+        foreach ($goodsList as $item) {
+            $goodsId = $item['goodsId'] ?? 0;
+            $name = $item['name'] ?? '';
+            $cover = $item['cover'] ?? '';
+            $flower = $item['flower'] ?? 0;
+            $kindId = $item['kindId'] ?? 0;
+            $num = $item['num'] ?? 0;
+            $current = $goodsInfo[$goodsId] ?? [];
+            if (empty($current)) {
+                util::fail('存在有问题商品');
+            }
+            $stock = $current['stock'];
+            $price = $current['price'] ?? 0;
+            $cost = $current['cost'] ?? 0;
+            if ($num != $stock) {
+                if ($num > $stock) {
+                    $diffNum = bcsub($num, $stock);
+                    $respond = GoodsClass::addStock($goodsId, $mainId, $diffNum);
+                } else {
+                    $diffNum = bcsub($stock, $num);
+                    $checkStock = false;
+                    $params = [];
+                    $respond = GoodsClass::decreaseStock($goodsId, $mainId, $diffNum, $checkStock, $params);
+                }
+                $oldStock = $respond['oldStock'] ?? 0;
+                $newStock = $respond['newStock'] ?? 0;
+                $recordData = [];
+                $recordData['sjId'] = $sjId;
+                $recordData['shopId'] = $shopId;
+                $recordData['mainId'] = $mainId;
+                $recordData['orderSn'] = $orderSn;
+                $recordData['goodsId'] = $goodsId;
+                $recordData['goodsNum'] = $diffNum;
+                $recordData['oldStock'] = $oldStock;
+                $recordData['newStock'] = $newStock;
+                $recordData['relateName'] = $staffName;
+                GoodsStockRecordClass::pdGoods($recordData);
+                $itemData = [
+                    'orderSn' => $orderSn,
+                    'goodsId' => $goodsId,
+                    'name' => $name,
+                    'cover' => $cover,
+                    'flower' => $flower,
+                    'kindId' => $kindId,
+                    'num' => $num,
+                    'stock' => $oldStock,
+                    'price' => $price,
+                    'cost' => $cost,
+                ];
+                PdGoodsDetailClass::add($itemData);
+            }
+        }
+        $data['status'] = 2;
+        $result = self::addBase($data, true);
+        return $result;
+    }
+
+}

+ 13 - 0
biz-hd/pd/classes/PdGoodsDetailClass.php

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

+ 13 - 0
biz-hd/pd/classes/PdGoodsSnClass.php

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

+ 13 - 0
biz-hd/pd/models/PdGoods.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizHd\pd\models;
+use bizHd\base\models\Base;
+
+class PdGoods extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhPdGoods';
+    }
+
+}

+ 13 - 0
biz-hd/pd/models/PdGoodsDetail.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizHd\pd\models;
+use bizHd\base\models\Base;
+
+class PdGoodsDetail extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhPdGoodsDetail';
+    }
+
+}

+ 13 - 0
biz-hd/pd/models/PdGoodsSn.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizHd\pd\models;
+use bizHd\base\models\Base;
+
+class PdGoodsSn extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhPdGoodsSn';
+    }
+
+}

+ 10 - 0
biz-hd/pd/services/PdGoodsService.php

@@ -0,0 +1,10 @@
+<?php
+namespace bizHd\pd\services;
+use bizHd\base\services\BaseService;
+
+class PdGoodsService extends BaseService
+{
+
+    public static $baseFile = '\bizHd\pd\classes\PdGoodsClass';
+
+}

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

@@ -2,9 +2,11 @@
 
 namespace bizHd\product\classes;
 
+use biz\item\classes\PtItemClass;
 use bizHd\base\classes\BaseClass;
 use common\components\noticeUtil;
 use common\components\sms;
+use common\components\util;
 use Yii;
 
 class ProductClass extends BaseClass
@@ -12,6 +14,48 @@ class ProductClass extends BaseClass
 
     public static $baseFile = '\bizHd\product\models\Product';
 
+    //花店的花材转成批发店花材 ssh 20230308
+    public static function hdToggleGhs($list, $ghsShop)
+    {
+        $ghsMainId = $ghsShop->mainId ?? 0;
+        $ptItemIds = array_column($list, 'itemId');
+        $ghsHasProduct = ProductClass::getAllByCondition(['mainId' => $ghsMainId, 'itemId' => ['in', $ptItemIds]], null, '*', 'itemId');
+        $ghsSjId = $ghsShop->sjId ?? 0;
+        $ghsShopId = $ghsShop->id ?? 0;
+        $defaultClassId = \bizGhs\item\classes\ItemClassClass::getDefaultClassId($ghsMainId);
+        if (empty($defaultClassId)) {
+            util::fail('没有找到花材的默认分类');
+        }
+        foreach ($list as $k => $v) {
+            $ptItemId = $v['itemId'] ?? 0;
+            $hdProductId = $v['productId'] ?? 0;
+            if (isset($ghsHasProduct[$ptItemId]) == false) {
+                //不存在,则从平台新增
+                $ptItem = PtItemClass::getById($ptItemId);
+                unset($ptItem['addTime']);
+                unset($ptItem['updateTime']);
+                $productData = $ptItem;
+                $productData['sjId'] = $ghsSjId;
+                $productData['shopId'] = $ghsShopId;
+                $productData['mainId'] = $ghsMainId;
+                $productData['itemId'] = $ptItemId;
+                $productData['classId'] = $defaultClassId;
+                unset($productData['id']);
+                $productData['rank'] = '';
+                $cost = $v['cost'] ?? 0;
+                $addPrice = $v['addPrice'] ?? 0;
+                $productData['price'] = bcadd($cost, $addPrice, 2);
+                $addProduct = ProductClass::addBaseData($productData);
+                $ghsProductId = $addProduct->id ?? 0;
+            } else {
+                $ghsProductId = $ghsHasProduct[$ptItemId]['id'] ?? 0;
+            }
+            $list[$k]['productId'] = $ghsProductId;
+            $list[$k]['hdProductId'] = $hdProductId;
+        }
+        return $list;
+    }
+
     public static function addBaseData($data)
     {
         $respond = self::add($data, true);

+ 55 - 177
biz-hd/purchase/classes/PurchaseClass.php

@@ -388,6 +388,7 @@ class PurchaseClass extends BaseClass
         $orderSn = orderSn::getPurchaseSn();
         $data['orderSn'] = $orderSn;
         $prePrice = 0;
+        $live = isset($ghs['live']) ? $ghs['live'] : 1;
         $sendTimeWant = isset($data['sendTimeWant']) && !empty($data['sendTimeWant']) ? $data['sendTimeWant'] : date("Y-m-d");
         if ($sendTimeWant < date("Y-m-d")) {
             util::fail('您选了过去时间');
@@ -406,10 +407,16 @@ class PurchaseClass extends BaseClass
         $sjId = $data['sjId'] ?? 0;
         $mainId = $data['mainId'] ?? 0;
         $ghsId = $data['ghsId'] ?? 0;
-        $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId);
 
-        $productData = self::getProductMapData($productList, "productId");
-        $hdProductData = self::getProductMapData($productList, "hdProductId");
+        if ($live == 1) {
+            //花店真实向批发店采购花材,因为拿的供货商的ID,所以需要转化花店的id
+            $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId);
+            $ghsProductData = self::getProductMapData($productList, "ghsProductId");
+        } else {
+            //虚拟采购用的自己的ID所以不需要转化
+            $ghsProductData = [];
+        }
+        $hdProductData = self::getProductMapData($productList, "productId");
 
         $giveLevel = $ghs['giveLevel'] ?? 0;
         $priceMap = CustomClass::$levelPriceKeyMap;
@@ -427,8 +434,13 @@ class PurchaseClass extends BaseClass
             $bigNum += $product['bigNum'] ?? 0;
             $smallNum += $product['smallNum'] ?? 0;
             $productList[$key]['orderSn'] = $orderSn;
-            $productId = $product['productId'];
-            $hdProductId = $product['hdProductId'];
+            if ($live == 1) {
+                $ghsProductId = $product['ghsProductId'];
+                $hdProductId = $product['productId'];
+            } else {
+                $hdProductId = $product['productId'] ?? 0;
+                $ghsProductId = 0;
+            }
 
             $unitWeight = $hdProductData[$hdProductId]['weight'] ?? 0;
             $variety = $hdProductData[$hdProductId]['variety'] ?? 0;
@@ -444,43 +456,46 @@ class PurchaseClass extends BaseClass
             $currentWeight = bcmul($weight, $itemNum, 2);
             $totalWeight = bcadd($currentWeight, $totalWeight, 2);
 
-            //供货商开单改价,这个价格优先级最高
-            $changePrice = isset($product['userPrice']) && $product['userPrice'] > 0 ? $product['userPrice'] : 0;
-
-            $currentProduct = $productData[$productId] ?? [];
-            $price = ProductClass::getFinalPrice($currentProduct, $giveLevel, $priceMap, $addPriceMap, $changePrice);
-            $bigPrice = $price;
+            //1、供货商开单改价 2、花店向虚拟供货商采购录入价格
+            $userPrice = isset($product['userPrice']) && $product['userPrice'] > 0 ? $product['userPrice'] : 0;
+            $currentGhsProduct = $ghsProductData[$ghsProductId] ?? [];
+
+            if (!empty($currentGhsProduct)) {
+                //用批发店的花材名称
+                $itemName = $currentGhsProduct['name'] ?? '';
+                $cover = $currentGhsProduct['cover'] ?? '';
+                //用批发店花材的价格
+                $price = ProductClass::getFinalPrice($currentGhsProduct, $giveLevel, $priceMap, $addPriceMap, $userPrice);
+                $thisPrice = $price;
+            } else {
+                $currentHdProduct = $hdProductData[$hdProductId] ?? [];
+                if (empty($currentHdProduct)) {
+                    util::fail('花材有问题哦');
+                }
+                $itemName = $currentHdProduct['name'] ?? '';
+                $cover = $currentHdProduct['cover'] ?? '';
+                $price = $userPrice;
+                $thisPrice = $userPrice;
+            }
 
             if ($currentSmallNum > 0) {
-                //如果是小单位数量,则传过来的就是小单位价格,无需转换
-                if (empty($changePrice)) {
-                    $ghsRatio = $currentProduct['ratio'] ?? 0;
-                    $ghsSmallRatio = $currentProduct['smallRatio'] ?? 1;
-                    $price = bcdiv($price, $ghsRatio, 2);
-                    $price = bcmul($price, $ghsSmallRatio, 2);
-                }
                 $productTotalPrice = bcmul($currentSmallNum, $price, 2);
             } else {
                 $productTotalPrice = bcmul($currentBigNum, $price, 2);
             }
 
-            //$itemName = $hdProductData[$hdProductId]['name'] ?? '';
-            //用批发店的花材名称
-            $itemName = $currentProduct['name'] ?? '';
-            //$cover = $hdProductData[$hdProductId]['cover'] ?? '';
-            $cover = $currentProduct['cover'] ?? '';
             $itemInfo = [
-                'itemName' => $itemName,//花材名称
-                'itemCover' => $cover,//花材图片
-                'bigNum' => $product['bigNum'] ?? 0,//采购数量(大单位)
-                'smallNum' => $product['smallNum'] ?? 0,//采购数量(小单位)
-                'bigNumStock' => $stockFormat['bigNum'],// 当时库存大单位数
-                'smallNumStock' => $stockFormat['smallNum'],//当时库存 小单位数
-                'itemUnit' => $ratio ? 2 : 1,//单位
-                'ratio' => $ratio,// 比例
-                'rank' => $rank,// 花材级别
-                'bigUnit' => $hdProductData[$hdProductId]['bigUnit'],//大单位名称 扎
-                'smallUnit' => $hdProductData[$hdProductId]['smallUnit'],//小单位名称 支
+                'itemName' => $itemName,
+                'itemCover' => $cover,
+                'bigNum' => $product['bigNum'] ?? 0,
+                'smallNum' => $product['smallNum'] ?? 0,
+                'bigNumStock' => $stockFormat['bigNum'],
+                'smallNumStock' => $stockFormat['smallNum'],
+                'itemUnit' => $ratio ? 2 : 1,
+                'ratio' => $ratio,
+                'rank' => $rank,
+                'bigUnit' => $hdProductData[$hdProductId]['bigUnit'],
+                'smallUnit' => $hdProductData[$hdProductId]['smallUnit'],
             ];
 
             $productList[$key]['itemInfo'] = json_encode($itemInfo);
@@ -490,16 +505,18 @@ class PurchaseClass extends BaseClass
             $productList[$key]['itemNum'] = $itemNum;
             $productList[$key]['bigNum'] = $product['bigNum'] ?? 0;
             $productList[$key]['smallNum'] = $product['smallNum'] ?? 0;
-            $productList[$key]['price'] = $bigPrice;
+            $productList[$key]['price'] = $thisPrice;
             $productList[$key]['ratio'] = $ratio;
             $productList[$key]['unitWeight'] = $unitWeight;
             $productList[$key]['totalPrice'] = $productTotalPrice;
             $productList[$key]['preTotalPrice'] = $productTotalPrice;
             $productList[$key]['productId'] = $hdProductId;
-            $productList[$key]['ghsProductId'] = $productId;
+            $productList[$key]['ghsProductId'] = $ghsProductId;
             $productList[$key]['smallPrice'] = $price;
             $productList[$key]['mainId'] = $mainId;
             $productList[$key]['ghsId'] = $ghsId;
+            $productList[$key]['name'] = $itemName;
+            $productList[$key]['cover'] = $cover;
 
             $currentBigUnit = $hdProductData[$hdProductId]['bigUnit'] ?? '';
             $currentSmallUnit = $hdProductData[$hdProductId]['smallUnit'] ?? '';
@@ -582,6 +599,7 @@ class PurchaseClass extends BaseClass
         $data['bigNum'] = $bigNum;
         $data['smallNum'] = $smallNum;
         $data['discount'] = 1;
+        $data['status'] = self::STATUS_UN_PAY;
 
         //采购单有效期
         $currentTime = time();
@@ -643,147 +661,7 @@ class PurchaseClass extends BaseClass
     //添加采购 ssh 2021.1.18
     public static function updatePurchase($purchase, $data)
     {
-        $orderSn = $purchase->orderSn ?? '';
-        $shopId = $purchase->shopId ?? 0;
-        $sjId = $purchase->sjId ?? 0;
-
-        $prePrice = 0;
-
-        $data['sendTimeWant'] = date("Y-m-d") . ' ' . $data['sendTime'];
-        unset($data['sendTime']);
-
-        if (isset($data['product']) == false || empty($data['product'])) {
-            util::fail('请选择花材');
-        }
-        $productList = $data['product'];
-        $productList = self::mergeItemInfo($productList);
-        $data['kindNum'] = count($productList); //多少种花材
-        //供货商productId转成零售的productId
-        $mainId = $purchase->mainId ?? 0;
-        $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId);
-
-        $productData = self::getProductMapData($productList, "productId");
-        $hdProductData = self::getProductMapData($productList, "hdProductId");
-
-        //计算价格= 各个productId的price*num(bigNum,smallNum) + sendCost(配送费)
-        $bigNum = 0; //总共多少扎
-        $smallNum = 0; //总共多少支
-        foreach ($productList as $key => $product) {
-
-            $bigNum += $product['bigNum'] ?? 0;
-            $smallNum += $product['smallNum'] ?? 0;
-            $productList[$key]['orderSn'] = $orderSn;
-            $productId = $product['productId'];
-            $hdProductId = $product['hdProductId'];
-
-            $ratio = $hdProductData[$hdProductId]['ratio'] ?? 0; //比例必须一致
-            $itemId = $hdProductData[$hdProductId]['itemId'] ?? 0;
-            $rank = $hdProductData[$hdProductId]['rank'] ?? 'B';// 花材级别
-            $stock = $hdProductData[$hdProductId]['stock'] ?? 0;//当时库存
-            $stockFormat = ProductClass::formatStock($stock, $ratio);
-
-            $itemNum = ProductClass::mergeItemNum($product['bigNum'], $product['smallNum'], $ratio);//采购数量
-            $price = $productData[$productId]['price']; //卖的单价
-            //每个花材总价(原价)
-            $productPrePrice = bcmul($itemNum, $price, 2); //采购总价
-            //供货商开单的每个花材总价,可能会改价
-            $productTotalPrice = isset($product['userPrice']) && $product['userPrice'] > 0 ? $product['userPrice'] : $productPrePrice;
-
-            $itemInfo = [
-                'itemName' => $hdProductData[$hdProductId]['name'] ?? '',//花材名称
-                'itemCover' => $hdProductData[$hdProductId]['cover'] ?? '',//花材图片
-                'bigNum' => $product['bigNum'] ?? 0,//采购数量(大单位)
-                'smallNum' => $product['smallNum'] ?? 0,//采购数量(小单位)
-                'bigNumStock' => $stockFormat['bigNum'],// 当时库存大单位数
-                'smallNumStock' => $stockFormat['smallNum'],//当时库存 小单位数
-                'itemUnit' => $ratio ? 2 : 1,//单位
-                'ratio' => $ratio,// 比例
-                'rank' => $rank,// 花材级别
-                'bigUnit' => $hdProductData[$hdProductId]['bigUnit'],//大单位名称 扎
-                'smallUnit' => $hdProductData[$hdProductId]['smallUnit'],//小单位名称 支
-            ];
-
-            $productList[$key]['itemInfo'] = json_encode($itemInfo);
-            $productList[$key]['itemId'] = $itemId;
-            $productList[$key]['itemNum'] = $itemNum;
-            $productList[$key]['price'] = $price;
-            $productList[$key]['ratio'] = $ratio;
-            $productList[$key]['totalPrice'] = $productTotalPrice;
-            $productList[$key]['preTotalPrice'] = $productPrePrice;
-            $productList[$key]['productId'] = $hdProductId;
-            $productList[$key]['ghsProductId'] = $productId;
-            //小单位单价
-            $smallPrice = bcdiv($price, $ratio, 2);
-            $productList[$key]['smallPrice'] = $smallPrice;
-
-            $prePrice = bcadd($prePrice, $productTotalPrice, 2);
-
-        }
-        //删除花材再添加
-        PurchaseItemClass::deleteByCondition(['orderSn' => $orderSn]);
-        PurchaseItemClass::batchAdd($productList);
-
-        $data['itemPrice'] = $prePrice;
-        $sendCost = $data['sendCost'] ?? 0.00;
-        $prePrice = bcadd($prePrice, $sendCost, 2);
-        $actPrice = $prePrice;
-        $realPrice = $prePrice;
-        if (isset($data['modifyPrice'])) {
-            //商家打折,修改金额
-            $modifyPrice = $data['modifyPrice'] ?? 0;
-            if ($modifyPrice > $prePrice) {
-                util::fail('实收金额大于订单总金额');
-            }
-            if ($modifyPrice < $prePrice) {
-                $data['discountAmount'] = bcsub($prePrice, $modifyPrice, 2);
-                $data['discountType'] = dict::getDict('discountType', 'discount');
-                $actPrice = $modifyPrice;
-                $realPrice = $modifyPrice;
-            }
-        } else {
-            //验证优惠券
-            $hbId = isset($data['hbId']) ? $data['hbId'] : 0;
-            if (!empty($hbId)) {
-                $coupon = ShopCouponClass::getLockById($hbId);
-                ShopCouponClass::valid($coupon, $data['shopId']);
-                if ($coupon->miniCost != 0 && $coupon->miniCost > $prePrice) {
-                    util::fail('达到最低消费才能使用优惠券');
-                }
-                if ($prePrice < $coupon->amount) {
-                    util::fail('总价应大于优惠金额');
-                }
-                $coupon->take = ShopCouponClass::TAKE_HAS;
-                $coupon->save();
-                $realPrice = bcsub($actPrice, $coupon->amount, 2);
-                $data['discountType'] = dict::getDict('discountType', 'usePtCoupon');
-                $data['discountAmount'] = $coupon->amount;
-                $data['hbId'] = $hbId;
-            }
-
-        }
-        $data['prePrice'] = $prePrice;
-        $data['actPrice'] = $actPrice;
-        $data['realPrice'] = $realPrice;
-        $data['bigNum'] = $bigNum;
-        $data['smallNum'] = $smallNum;
-        //采购单有效期
-        $validTime = dict::getDict('order_pay_has_time');
-        $current = time() + $validTime;
-        $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current);
-
-        $purchaseId = $purchase->id ?? 0;
-        self::updateById($purchaseId, $data);
-        $respond = self::getLockById($purchaseId);
-
-        $shop = ShopClass::getLockById($shopId);
-        if (empty($shop)) {
-            util::fail('没有找到门店');
-        }
-        $shop->cancelOrder -= 1;
-        $shop->cgUnPay += 1;
-        $shop->save();
-
-        return $respond;
+        util::fail('已删除');
     }
 
     //组合数据 ssh 2021.1.25

+ 22 - 16
biz-hd/purchase/services/PurchaseService.php

@@ -47,6 +47,7 @@ class PurchaseService extends BaseService
         $sendCost = $data['sendCost'] ?? 0;
         $packCost = $data['packCost'] ?? 0;
         $customId = $ghs['customId'] ?? 0;
+        $live = isset($ghs['live']) ? $ghs['live'] : 1;
         $custom = CustomClass::getById($customId);
         if (empty($custom)) {
             util::fail('没有找到客户');
@@ -68,7 +69,7 @@ class PurchaseService extends BaseService
         $sendTimeWant = isset($data['sendTimeWant']) && !empty($data['sendTimeWant']) ? $data['sendTimeWant'] : date("Y-m-d");
         $orderType = 2;
         $book = $data['book'] ?? 0;
-        $presell = $data['presell'] ?? 0;
+        $preSell = $data['presell'] ?? 0;
         $mainId = $custom['ownMainId'] ?? 0;
         $fromType = dict::getDict('fromType', 'mall');
         $arr = [
@@ -107,8 +108,9 @@ class PurchaseService extends BaseService
             'discount' => $discount,
             'orderType' => $orderType,
             'fromType' => $fromType,
-            'presell' => $presell,
+            'presell' => $preSell,
             'wlName' => $wlName,
+            'live' => $live,
         ];
         $result = OrderClass::addOrder($arr);
         $saleId = $result['id'] ?? 0;
@@ -372,20 +374,24 @@ class PurchaseService extends BaseService
             $orderSn = $info->orderSn;
             $purchaseItem = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, "*");
             foreach ($purchaseItem as $v) {
-                $stockInfo = ProductClass::addStockByItemNum($v['productId'], $v['itemNum']);
-                //记录库存流水
-                $recordData = [];
-                $recordData['sjId'] = $info->sjId;
-                $recordData['shopId'] = $info->shopId;
-                $recordData['mainId'] = $info->mainId;
-                $recordData['itemId'] = $v['itemId'] ?? 0;
-                $recordData['itemNum'] = $v['itemNum'];
-                $recordData['oldStock'] = $stockInfo['oldStock'];
-                $recordData['newStock'] = $stockInfo['newStock'];
-                $recordData['productId'] = $v['productId'];
-                $recordData['orderSn'] = $orderSn;
-                $recordData['relateName'] = $info->ghsName ?? '';
-                StockRecordClass::addPurchaseOrderRecord($recordData);
+                //小单位库存不考虑入库 ssh 202310
+                $itemNum = intval($v['itemNum']);
+                if ($itemNum > 0) {
+                    $stockInfo = ProductClass::addStockByItemNum($v['productId'], $itemNum);
+                    //记录库存流水
+                    $recordData = [];
+                    $recordData['sjId'] = $info->sjId;
+                    $recordData['shopId'] = $info->shopId;
+                    $recordData['mainId'] = $info->mainId;
+                    $recordData['itemId'] = $v['itemId'] ?? 0;
+                    $recordData['itemNum'] = $itemNum;
+                    $recordData['oldStock'] = $stockInfo['oldStock'];
+                    $recordData['newStock'] = $stockInfo['newStock'];
+                    $recordData['productId'] = $v['productId'];
+                    $recordData['orderSn'] = $orderSn;
+                    $recordData['relateName'] = $info->ghsName ?? '';
+                    StockRecordClass::addPurchaseOrderRecord($recordData);
+                }
             }
             $info->stockChange = 1;
             $info->save();

+ 15 - 13
biz-hd/refund/classes/HdRefundItemClass.php

@@ -33,19 +33,21 @@ class HdRefundItemClass extends BaseClass
         $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);
+        if ($bigNum > 0) {
+            $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);
     }

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

@@ -24,6 +24,7 @@ class GhsClass extends BaseClass
 
     public static $baseFile = '\biz\ghs\models\Ghs';
 
+
     //补充供货商 ssh 20211028
     public static function bcGhs($hdShopId)
     {
@@ -50,6 +51,7 @@ class GhsClass extends BaseClass
         $ghsAvatar = $ghsShop['shortAvatar'] ?? '';
         $ghsDefault = $ghsShop['default'] ?? 0;
         $allowDebt = $ghsShop['allowDebt'] ?? 0;
+        $live = isset($ghsShop['live']) ? $ghsShop['live'] : 1;
         $allowDebtAmount = $ghsShop['allowDebtAmount'] ?? 5000;
 
         $name = $ghsDefault == 1 && $ghsShop['shopName'] == '首店' ? $ghsShop['merchantName'] : $ghsShop['merchantName'] . ' ' . $ghsShop['shopName'];
@@ -77,6 +79,7 @@ class GhsClass extends BaseClass
             'fullAddress' => $ghsShop['fullAddress'] ?? '',
             'lat' => $ghsShop['lat'] ?? '',
             'long' => $ghsShop['long'] ?? '',
+            'live' => $live,
         ];
         $ghs = self::addGhs($data);
         $ghsId = $ghs['id'] ?? 0;
@@ -124,6 +127,7 @@ class GhsClass extends BaseClass
             'debtLimit' => $debtLimit,
             'debt' => $allowDebt,
             'debtLimit' => $allowDebtAmount,
+            'live' => $live,
         ];
         $custom = CustomClass::addCustom($customData);
         $customId = $custom['id'] ?? 0;
@@ -148,6 +152,7 @@ class GhsClass extends BaseClass
         return $custom;
     }
 
+
     //增加供货商 ssh 2021.3.29
     public static function addGhs($data)
     {

+ 16 - 2
biz/stock/classes/GoodsStockRecordClass.php

@@ -40,6 +40,12 @@ class GoodsStockRecordClass extends BaseClass
         self::STOCK_RECORD_TYPE_CANCEL_ORDER => '取消订单',
     ];
 
+    public static function pdGoods($data)
+    {
+        $data['recordType'] = self::STOCK_RECORD_TYPE_CHECK_STOCK;
+        return self::addRecord($data);
+    }
+
     //取消订单 ssh 20220516
     public static function cancelOrder($data)
     {
@@ -107,8 +113,16 @@ class GoodsStockRecordClass extends BaseClass
         $record['goodsId'] = $data['goodsId'] ?? '';
         $record['goodsNum'] = $data['goodsNum'] ?? '';
         $record['relateName'] = $data['relateName'] ?? '';
-        $record['oldStock'] = $data['oldStock'] ?? '';
-        $record['newStock'] = $data['newStock'] ?? '';
+        $record['oldStock'] = $data['oldStock'] ?? 0;
+        $record['newStock'] = $data['newStock'] ?? 0;
+        $io = -1;
+        if ($record['newStock'] > $record['oldStock']) {
+            $io = 1;
+        }
+        if ($record['newStock'] < $record['oldStock']) {
+            $io = 0;
+        }
+        $record['io'] = $io;
         $respond = self::add($record);
         return $respond;
     }

+ 29 - 0
common/components/orderSn.php

@@ -5,11 +5,13 @@ namespace common\components;
 use biz\sj\classes\CashSnClass;
 use bizGhs\order\classes\OrderClass;
 use bizHd\cg\classes\CgRefundSnClass;
+use bizHd\common\classes\MobileSnClass;
 use bizHd\goods\classes\GoodsCgSnClass;
 use bizHd\goods\classes\GoodsSnClass;
 use bizHd\ljh\classes\LjhSnClass;
 use bizHd\order\classes\SettleSnClass;
 use bizHd\part\classes\PartSnClass;
+use bizHd\pd\classes\PdGoodsSnClass;
 use bizHd\purchase\classes\PurchaseClearSnClass;
 use biz\recharge\classes\RechargeSnClass;
 use bizGhs\check\classes\CheckSnClass;
@@ -86,6 +88,20 @@ class orderSn
         return $prefix . $id;
     }
 
+    public static function getPdGoodsSn()
+    {
+        $prefix = 'PDG_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'PDG';
+        }
+        $respond = PdGoodsSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('盘点单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
     //零售商采购单号 ssh 2021.1.19
     public static function getPurchaseSn()
     {
@@ -370,6 +386,18 @@ class orderSn
         return $prefix . $id;
     }
 
+
+    //生成虚拟手机号 ssh 20230303
+    public static function getMobileSn()
+    {
+        $respond = MobileSnClass::add(['id' => null]);
+        $id = isset($respond['id']) ? (string)$respond['id'] : '';
+        if (empty($id)) {
+            util::fail('没有生成手机号');
+        }
+        return $id;
+    }
+
     //零交会报名单号 ssh 20230303
     public static function getLjhApplySn()
     {
@@ -385,4 +413,5 @@ class orderSn
         return $prefix . $id;
     }
 
+
 }

+ 2 - 1
console/controllers/CustomController.php

@@ -203,7 +203,8 @@ class CustomController extends Controller
                 //增加或更新申请
                 $respond = ApplyService::replaceRetail($post);
                 $id = $respond['id'] ?? 0;
-                Yii::$app->params['ptStyle'] = 2; // 后继代码,要用到此参数
+                //后继代码,要用到此参数
+                Yii::$app->params['ptStyle'] = 2;
                 ApplyService::pass($id, '批发商手动添加');
                 $transaction->commit();
                 noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 由批发商添加成功");

+ 36 - 0
console/controllers/KindController.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace console\controllers;
+
+use bizHd\goods\classes\KindClass;
+use bizHd\shop\classes\ShopClass;
+use yii\console\Controller;
+use Yii;
+
+class KindController extends Controller
+{
+
+    //种类初始化 ssh 20230301
+    public function actionInit()
+    {
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+        $shopList = ShopClass::getAllByCondition(['ptStyle' => 1], null, '*', null, true);
+        if (!empty($shopList)) {
+            foreach ($shopList as $shop) {
+                $mainId = $shop->mainId ?? 0;
+                $sjId = $shop->sjId ?? 0;
+                $has = KindClass::getByCondition(['mainId' => $mainId], true);
+                if (!empty($has)) {
+                    continue;
+                }
+                $data = [
+                    'mainId' => $mainId,
+                    'sjId' => $sjId,
+                ];
+                KindClass::initKind($data);
+            }
+        }
+    }
+
+}