shish 5 роки тому
батько
коміт
536c821aaa

+ 16 - 17
app-ghs/controllers/OrderController.php

@@ -76,18 +76,17 @@ class OrderController extends BaseController
         $shopId = $this->shopId;
         $customId = $post['customId'] ?? 0;
         $post['customId'] = $customId;
-        if (!empty($customId)) {
-            $custom = CustomClass::getCustom($customId);
-            if (empty($custom)) {
-                util::fail('客户无效');
-            }
-            CustomClass::valid($custom, $this->sjId);
-            $post['customMobile'] = $custom['mobile'] ?? '';
-            $customName = $custom['name'] ?? '';
-            $post['customName'] = $customName;
-            $post['customNamePy'] = $custom['py'] ?? '';
-            $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
+
+        $custom = CustomClass::getCustom($customId);
+        if (empty($custom)) {
+            util::fail('客户无效');
         }
+        CustomClass::valid($custom, $this->sjId);
+        $post['customMobile'] = $custom['mobile'] ?? '';
+        $customName = $custom['name'] ?? '';
+        $post['customName'] = $customName;
+        $post['customNamePy'] = $custom['py'] ?? '';
+        $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
 
         $post['shopAdminId'] = $this->shopAdminId;
         $shopAdmin = $this->shopAdmin;
@@ -114,7 +113,7 @@ class OrderController extends BaseController
             //判断花材有效性
             ProductClass::valid($productList, $this->shopId);
             $post['product'] = $productList;
-            $return = OrderClass::addOrder($post, $this->shopId);
+            $return = OrderService::addOrder($post, $custom);
             $transaction->commit();
             util::success($return);
         } catch (\Exception $e) {
@@ -159,7 +158,7 @@ class OrderController extends BaseController
         //强制使用小程序的miniOpenId
         $openId = $this->admin['miniOpenId'];
 
-        $capitalType = dict::getDict('capitalType','xhGhsOrder','id');
+        $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
         //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
         $wxPayType = 0;
         if (httpUtil::isMiniProgram()) {
@@ -253,7 +252,7 @@ class OrderController extends BaseController
         //2021.3.28 接入达达
         $get = Yii::$app->request->get();
         $post = Yii::$app->request->post();
-        if(empty($get)){
+        if (empty($get)) {
             $get = $post;
         }
         $orderId = $get['id'] ?? 0; //订单ID
@@ -404,7 +403,7 @@ class OrderController extends BaseController
             $admin = AdminClass::getAdminById($this->adminId);
             //小程序使用miniOpenId
             $openId = $admin['miniOpenId'];
-            $capitalType = dict::getDict('capitalType','xhGhsOrder','id');
+            $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
             //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
             $wxPayType = 0;
             if (httpUtil::isMiniProgram()) {
@@ -483,7 +482,7 @@ class OrderController extends BaseController
             $body = '';//商品描述,可空
             $timeout_express = "1m";//超时时间
 
-            $capitalType = dict::getDict('capitalType','xhGhsOrder','id');
+            $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
             $passBackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、优惠卷传过去
             $passBackParams = urlencode($passBackParams);
 
@@ -504,7 +503,7 @@ class OrderController extends BaseController
             //直接将支付宝的html返回给前端
             echo $result;
         } elseif ($payWay == 2) {
-            $capitalType = dict::getDict('capitalType','xhGhsOrder','id');
+            $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
             $callbackParams = [];
             $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
             $balance = isset($respond['balance']) ? $respond['balance'] : 0;

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

@@ -38,7 +38,7 @@ class PurchaseController extends BaseController
         ProductClass::valid($productList, $currentShopId);
         $post['product'] = $productList;
         $post['sendCost'] = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
-        $respond = PurchaseClass::addPurchase($post);
+        $respond = PurchaseService::addPurchase($post);
         $orderSn = $respond['orderSn'] ?? '';
         $actPrice = $respond['actPrice'] ?? '';
         $data = [

+ 2 - 2
app-pt/controllers/ShopAdminController.php

@@ -31,8 +31,8 @@ class ShopAdminController extends BaseController
             util::fail('没有找到员工');
         }
 
-        if (getenv('YII_ENV') != 'local' || getenv('YII_ENV') != 'dev') {
-            //util::fail('生产环境不能执行删除操作');
+        if (getenv('YII_ENV', 'local') == 'production') {
+            util::fail('生产环境不能执行删除操作');
         }
 
         $adminId = $shopAdmin['adminId'] ?? 0;

+ 86 - 26
biz-ghs/order/classes/OrderClass.php

@@ -2,28 +2,22 @@
 
 namespace bizGhs\order\classes;
 
-use biz\express\classes\ExpressClass;
 use biz\shop\classes\ShopAdminClass;
 use biz\shop\classes\ShopClass;
 use biz\shop\models\Shop;
-use biz\shop\services\ShopService;
-use biz\sj\classes\MerchantClass;
 use bizGhs\express\services\DadaExpressServices;
 use bizGhs\order\traits\OrderTrait;
 use bizGhs\product\classes\ProductClass;
-use biz\sj\classes\MerchantAssetClass;
 use bizGhs\admin\classes\AdminClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\stat\classes\StatOrderCountClass;
 use bizGhs\stat\classes\StatYjClass;
 use bizHd\stat\classes\StatIncomeClass;
 use bizHd\stat\classes\StatOrderClass;
-use bizHd\stat\classes\StatOrderMonthClass;
 use common\components\imgUtil;
 use common\components\orderSn;
 use common\components\stringUtil;
 use common\components\util;
-use Yii;
 use bizGhs\base\classes\BaseClass;
 
 class OrderClass extends BaseClass
@@ -88,8 +82,9 @@ class OrderClass extends BaseClass
         self::SEND_TYPE_THIRD => '快递配送',
     ];
 
+
     //添加订单 ssh 2019.12.5
-    public static function addOrder($data, $currentShopId, $customOrder = false)
+    public static function addOrder($data)
     {
         $sjId = $data['merchantId'] ?? 0;
         $month = date("Ym");
@@ -124,6 +119,7 @@ class OrderClass extends BaseClass
         $data['weight'] = $weight;
 
         //门店总订单数+1
+        $currentShopId = $data['shopId'] ?? 0;
         $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $currentShopId])->one();
         if (empty($shop)) {
             util::fail('没有找到门店');
@@ -134,28 +130,92 @@ class OrderClass extends BaseClass
 
         $return = self::add($data);
 
-        if ($customOrder == false) {
-            //0正常订单 1欠款
-            $debt = $data['debt'] ?? 0;
-            if ($debt == 1) {
-                //欠款
-                self::staffKdPay($return, 1, $shop);
-            } else {
-                //已收款
-                self::staffKdPay($return, 2, $shop);
-            }
-            //扣库存 2021.2.23 linqh
-            foreach ($product as $key => $val) {
-                ProductClass::decreaseStock($val['productId'], $val['bigNum'], $val['smallNum']);
-            }
-            //自取订单直接完成
-            if (isset($data['sendType']) && $data['sendType'] == self::SEND_TYPE_NO) {
-                OrderClass::withoutSend($return);
-            }
+        return ['return' => $return, 'product' => $product, 'shop' => $shop];
+    }
+
+    //备用方法,需要删除,后面
+    public static function addGhsOrder($respond, $data)
+    {
+        $hdSjId = $data['merchantId'] ?? 0;
+        $hdShopId = $data['shopId'] ?? 0;
+
+        $productList = $data['product'];
+        $productList = self::mergeItemInfo($productList);
+
+        $prePrice = $respond->prePrice;
+        $actPrice = $respond->actPrice;
+        $bigNum = $respond->bigNum;
+        $smallNum = $respond->smallNum;
+
+        //零售的供货商增加订单
+        $ghsId = $data['ghsId'] ?? 0;
+        if (empty($ghsId)) {
+            util::fail('没有找到供货商');
+        }
+        $ghs = GhsClass::getGhsInfo($ghsId);
+        if (empty($ghs)) {
+            util::fail('还是没有找到供货商');
+        }
+        $ghsSjId = $ghs['sjId'] ?? 0;
+        $ghsShopId = $ghs['shopId'] ?? 0;
+        $getType = $data['getType'] ?? 0;
+        $hdOrderId = $respond['id'] ?? 0;
+
+        //增加供货商的客户
+        $custom = CustomClass::getByCondition(['ownSjId' => $ghsSjId, 'sjId' => $hdSjId, 'shopId' => $hdShopId]);
+        if (empty($custom)) {
+            $hdShop = ShopClass::getShopInfo($hdShopId);
+            $name = $hdShop['shopName'] ?? '';
+            $py = stringUtil::py($name);
+            $mobile = $hdShop['mobile'];
+            $customData = [
+                'sjId' => $hdSjId,
+                'shopId' => $hdShopId,
+                'ownSjId' => $ghsSjId,
+                'name' => $name,
+                'py' => $py,
+                'mobile' => $mobile,
+                'city' => $shop['city'] ?? '',
+                'dist' => $shop['dist'] ?? '',
+                'address' => $shop['address'] ?? '',
+                'fullAddress' => $shop['fullAddress'] ?? '',
+                'long' => $shop['long'] ?? '',
+                'lat' => $shop['lat'] ?? '',
+            ];
+            $custom = CustomClass::addCustom($customData);
         }
-        return $return;
+        if (empty($custom)) {
+            util::fail('还是没有找到客户');
+        }
+        $customId = $custom['id'] ?? 0;
+        $customName = $custom['name'] ?? '';
+        $customNamePy = $custom['py'] ?? '';
+        $customAvatar = $custom['avatar'] ?? '';
+        $customMobile = $custom['mobile'] ?? '';
+        $orderData = [
+            'prePrice' => $prePrice,
+            'actPrice' => $actPrice,
+            'bigNum' => $bigNum,
+            'smallNum' => $smallNum,
+            'product' => $productList,
+            'merchantId' => $ghsSjId,
+            'shopId' => $ghsShopId,
+            'sendType' => $getType,
+            'hdOrderId' => $hdOrderId,
+            'customId' => $customId,
+            'customName' => $customName,
+            'customNamePy' => $customNamePy,
+            'customAvatar' => $customAvatar,
+            'customMobile' => $customMobile,
+        ];
+        //增加供货商的销售单
+        $arr = OrderClass::addOrder1($orderData, $ghsShopId);
+        $return = $arr['return'];
+        $id = $return['id'] ?? 0;
+        self::updateById($hdOrderId, ['ghsOrderId' => $id]);
     }
 
+
     //根据订单编号查询 ssh 2021.19
     public static function getByOrderSn($orderSn)
     {

+ 52 - 3
biz-ghs/order/services/OrderService.php

@@ -2,9 +2,14 @@
 
 namespace bizGhs\order\services;
 
+use biz\ghs\classes\GhsClass;
 use bizGhs\base\services\BaseService;
+use bizGhs\custom\classes\CustomClass;
 use bizGhs\order\classes\OrderClass;
 use common\components\util;
+use bizGhs\product\classes\ProductClass;
+use bizHd\purchase\classes\PurchaseClass;
+use common\components\stringUtil;
 use Yii;
 
 class OrderService extends BaseService
@@ -12,11 +17,55 @@ class OrderService extends BaseService
 
     public static $baseFile = '\bizGhs\order\classes\OrderClass';
 
-
     //添加订单
-    public static function addOrder($data)
+    public static function addOrder($data, $custom)
     {
-        return OrderClass::addOrder($data);
+        //增加供货商的销售单
+        $arr = OrderClass::addOrder($data);
+        $return = $arr['return'];
+        $product = $arr['product'];
+        $shop = $arr['shop'];
+
+        $sjId = $data['merchantId'] ?? 0;
+        $shopId = $data['shopId'] ?? 0;
+        $customSjId = $custom['sjId'] ?? 0;
+        $customShopId = $custom['shopId'] ?? 0;
+        $ghsShopAdminId = $data['shopAdminId'] ?? 0;
+        $ghsShopAdminName = $data['shopAdminName'] ?? '';
+        $ghs = GhsClass::getByCondition(['ownSjId' => $customSjId, 'sjId' => $sjId, 'shopId' => $shopId]);
+        if (empty($ghs)) {
+            util::fail('没有找到供货商');
+        }
+        //待供货商和客户结构关系改完 todo shish
+        $purchaseData = [
+            'product' => $data['product'],
+            'sendTime' => date("H:i:s"),
+            'sendCost' => 1,
+            'ghsShopAdminId' => $ghsShopAdminId,
+            'ghsShopAdminName' => $ghsShopAdminName,
+            'merchantId' => $customSjId,
+            'shopId' => $customShopId,
+        ];
+        //增加零售的采购单
+        PurchaseClass::addPurchase($purchaseData);
+
+        //0正常订单 1欠款
+        $debt = $data['debt'] ?? 0;
+        if ($debt == 1) {
+            //欠款
+            OrderClass::staffKdPay($return, 1, $shop);
+        } else {
+            //已收款
+            OrderClass::staffKdPay($return, 2, $shop);
+        }
+        //扣库存 2021.2.23 linqh
+        foreach ($product as $key => $val) {
+            ProductClass::decreaseStock($val['productId'], $val['bigNum'], $val['smallNum']);
+        }
+        //自取订单直接完成
+        if (isset($data['sendType']) && $data['sendType'] == OrderClass::SEND_TYPE_NO) {
+            OrderClass::withoutSend($return);
+        }
     }
 
     //获取订单信息 ssh 2019.11.28

+ 2 - 73
biz-hd/purchase/classes/PurchaseClass.php

@@ -4,18 +4,15 @@ namespace bizHd\purchase\classes;
 
 use biz\ghs\classes\GhsClass;
 use biz\ghs\models\Ghs;
-use biz\shop\classes\ShopClass;
 use biz\shop\models\Shop;
 use bizGhs\admin\classes\AdminClass;
 use bizGhs\custom\classes\CustomClass;
-use biz\sj\classes\MerchantClass;
 use bizGhs\custom\models\Custom;
 use bizGhs\order\traits\OrderTrait;
 use bizGhs\product\classes\ProductClass;
 use bizGhs\order\classes\OrderClass;
 use common\components\dict;
 use common\components\orderSn;
-use common\components\stringUtil;
 use common\components\util;
 use bizHd\base\classes\BaseClass;
 
@@ -47,8 +44,6 @@ class PurchaseClass extends BaseClass
         $data['sendTimeWant'] = date("Y-m-d") . ' ' . $data['sendTime'];
         unset($data['sendTime']);
 
-        $hdSjId = $data['merchantId'] ?? 0;
-        $hdShopId = $data['shopId'] ?? 0;
         if (isset($data['product']) == false || empty($data['product'])) {
             util::fail('请选择花材');
         }
@@ -98,7 +93,8 @@ class PurchaseClass extends BaseClass
             $productList[$key]['totalPrice'] = $sellPrice;
             $prePrice = bcadd($prePrice, $sellPrice, 2);
         }
-        $prePrice = bcadd($prePrice, $data['sendCost'], 2);
+        $sendCost = $data['sendCost'] ?? 0.00;
+        $prePrice = bcadd($prePrice, $sendCost, 2);
         $actPrice = $prePrice;
         $data['prePrice'] = $prePrice;
         $data['actPrice'] = $actPrice;
@@ -108,74 +104,7 @@ class PurchaseClass extends BaseClass
         if (isset($data['product']) == false || empty($data['product'])) {
             util::fail('请选择花材');
         }
-
         PurchaseItemClass::batchAdd($productList);
-
-        //零售的供货商增加订单
-        $ghsId = $data['ghsId'] ?? 0;
-        if (empty($ghsId)) {
-            util::fail('没有找到供货商');
-        }
-        $ghs = GhsClass::getGhsInfo($ghsId);
-        if (empty($ghs)) {
-            util::fail('还是没有找到供货商');
-        }
-        $ghsSjId = $ghs['sjId'] ?? 0;
-        $ghsShopId = $ghs['shopId'] ?? 0;
-        $getType = $data['getType'] ?? 0;
-        $hdOrderId = $respond['id'] ?? 0;
-
-        //增加供货商的客户
-        $custom = CustomClass::getByCondition(['ownSjId' => $ghsSjId, 'sjId' => $hdSjId, 'shopId' => $hdShopId]);
-        if (empty($custom)) {
-            $hdShop = ShopClass::getShopInfo($hdShopId);
-            $name = $hdShop['shopName'] ?? '';
-            $py = stringUtil::py($name);
-            $mobile = $hdShop['mobile'];
-            $customData = [
-                'sjId' => $hdSjId,
-                'shopId' => $hdShopId,
-                'ownSjId' => $ghsSjId,
-                'name' => $name,
-                'py' => $py,
-                'mobile' => $mobile,
-                'city' => $shop['city'] ?? '',
-                'dist' => $shop['dist'] ?? '',
-                'address' => $shop['address'] ?? '',
-                'fullAddress' => $shop['fullAddress'] ?? '',
-                'long' => $shop['long'] ?? '',
-                'lat' => $shop['lat'] ?? '',
-            ];
-            $custom = CustomClass::addCustom($customData);
-        }
-        if (empty($custom)) {
-            util::fail('还是没有找到客户');
-        }
-        $customId = $custom['id'] ?? 0;
-        $customName = $custom['name'] ?? '';
-        $customNamePy = $custom['py'] ?? '';
-        $customAvatar = $custom['avatar'] ?? '';
-        $customMobile = $custom['mobile'] ?? '';
-        $orderData = [
-            'prePrice' => $prePrice,
-            'actPrice' => $actPrice,
-            'bigNum' => $bigNum,
-            'smallNum' => $smallNum,
-            'product' => $productList,
-            'merchantId' => $ghsSjId,
-            'shopId' => $ghsShopId,
-            'sendType' => $getType,
-            'hdOrderId' => $hdOrderId,
-            'customId' => $customId,
-            'customName' => $customName,
-            'customNamePy' => $customNamePy,
-            'customAvatar' => $customAvatar,
-            'customMobile' => $customMobile,
-        ];
-        //增加供货商的销售单
-        $return = OrderClass::addOrder($orderData, $ghsShopId, true);
-        $id = $return['id'] ?? 0;
-        self::updateById($hdOrderId, ['ghsOrderId' => $id]);
         return $respond;
     }
 

+ 42 - 1
biz-hd/purchase/services/PurchaseService.php

@@ -3,17 +3,58 @@
 namespace bizHd\purchase\services;
 
 use biz\ghs\classes\GhsClass;
+use bizGhs\custom\classes\CustomClass;
+use bizGhs\order\classes\OrderClass;
 use bizHd\base\services\BaseService;
 use bizHd\purchase\classes\PurchaseClass;
 use bizGhs\admin\classes\AdminClass;
 use common\components\imgUtil;
-use Yii;
+use common\components\util;
 
 class PurchaseService extends BaseService
 {
 
     public static $baseFile = '\bizHd\purchase\classes\PurchaseClass';
 
+    public static function addPurchase($data)
+    {
+        //增加零售的采购单
+        $respond = PurchaseClass::addPurchase($data);
+        //增加供货商的销售单
+        $ghsId = $data['ghsId'] ?? 0;
+        $ghs = GhsClass::getGhsInfo($ghsId);
+        if (empty($ghs)) {
+            util::fail('没有找到供货商');
+        }
+        $sjId = $data['merchantId'] ?? 0;
+        $shopId = $data['shopId'] ?? 0;
+        $currentShopId = $ghs['shopId'] ?? 0;
+        $currentSjId = $ghs['sjId'] ?? 0;
+        $product = $data['product'] ?? [];
+        $price = 0.01;
+        $custom = CustomClass::getByCondition(['ownSjId' => $currentSjId, 'sjId' => $sjId, 'shopId' => $shopId]);
+        if (empty($custom)) {
+            util::fail('没有找到客户');
+        }
+        $customId = $custom['id'] ?? 0;
+        $customName = $custom['name'] ?? '';
+        $customNamePy = $custom['py'] ?? '';
+        $customMobile = $custom['mobile'] ?? '';
+        $arr = [
+            'product' => $product,
+            'merchantId' => $currentSjId,
+            'shopId' => $currentShopId,
+            'prePrice' => $price,
+            'actPrice' => $price,
+            'customId' => $customId,
+            'customName' => $customName,
+            'customNamePy' => $customNamePy,
+            'customMobile' => $customMobile,
+        ];
+        OrderClass::addOrder($arr, $currentShopId);
+        return $respond;
+    }
+
     //采购记录 ssh 2021.1.24
     public static function getPurchaseList($where)
     {

+ 2 - 0
sql.sql

@@ -2351,6 +2351,8 @@ ALTER TABLE xhPurchaseClear CHANGE `merchantId` `sjId` INT(11) NOT NULL DEFAULT
 ALTER TABLE xhPurchaseClear ADD ghsId INT NOT NULL DEFAULT 0 COMMENT '供货商id' AFTER `orderSn`;
 ALTER TABLE xhGhsCustom ADD debtNum INT NOT NULL DEFAULT 0 COMMENT '欠款笔数' AFTER `debtAmount`;
 ALTER TABLE xhShopAdmin ADD lastLogin TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后登陆时间' AFTER `status`;
+ALTER TABLE `xhPurchase` ADD ghsShopAdminId INT NOT NULL DEFAULT 0 COMMENT '' AFTER `shopId`;
+ALTER TABLE `xhPurchase` ADD ghsShopAdminName VARCHAR(50) NOT NULL DEFAULT '' COMMENT '员工姓名' AFTER `ghsShopAdminId`;
 
 -------- ruidian 20210505
 ALTER TABLE `xhGoods`