shish 5 роки тому
батько
коміт
2243376f6a

+ 10 - 7
app-ghs/controllers/OrderController.php

@@ -76,17 +76,21 @@ class OrderController extends BaseController
         $shopId = $this->shopId;
         $customId = $post['customId'] ?? 0;
         $post['customId'] = $customId;
-        //开单允许不选客户
-        if (!empty($customId)) {
-            $custom = CustomClass::getCustom($customId);
-            CustomClass::valid($custom, $this->shopId);
+        //开单必须选客户
+        if (empty($customId)) {
+            util::fail('请选择客户');
+        }
+        $custom = CustomClass::getCustom($customId);
+        if (empty($custom)) {
+            util::fail('请选客户哦');
         }
+        CustomClass::valid($custom, $this->shopId);
+        $post['ghsId'] = $custom['ghsId'] ?? 0;
         $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;
         $post['shopAdminName'] = $shopAdmin['name'] ?? '';
@@ -94,7 +98,6 @@ class OrderController extends BaseController
         $post['payWay'] = $this->isWx == true ? 0 : 1;
         $post['merchantId'] = $this->sjId;
         $post['fromType'] = 1;
-
         $post['expressId'] = $post['expressId'] ?? 0;
         $post['clearType'] = $post['clearType'] ?? OrderClass::CLEAR_DEBT;
 
@@ -112,7 +115,7 @@ class OrderController extends BaseController
             //判断花材有效性
             ProductClass::valid($productList, $this->shopId);
             $post['product'] = $productList;
-            $return = OrderService::addOrder($post, $custom);
+            $return = OrderService::createOrder($post);
             $transaction->commit();
             util::success($return);
         } catch (\Exception $e) {

+ 53 - 26
app-hd/controllers/PurchaseController.php

@@ -4,6 +4,7 @@ namespace hd\controllers;
 
 use biz\admin\classes\AdminClass;
 use biz\ghs\classes\GhsClass;
+use bizGhs\custom\classes\CustomClass;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\purchase\services\PurchaseService;
 use bizGhs\product\classes\ProductClass;
@@ -22,34 +23,45 @@ class PurchaseController extends BaseController
         $post = Yii::$app->request->post();
         $ghsId = $post['ghsId'] ?? 0;
         //供货商
-        $supplier = GhsClass::getById($ghsId);
-        if (empty($supplier)) {
+        $ghsInfo = GhsClass::getById($ghsId);
+        if (empty($ghsInfo)) {
             util::fail('没有找到供货商');
         }
-        $currentShopId = $supplier['shopId'] ?? 0;
-        $post['merchantId'] = $this->sjId;
-        $post['shopId'] = $this->shopId;
-        $post['shopAdminId'] = $this->shopAdminId;
-        $shopAdmin = $this->shopAdmin;
-        $name = $shopAdmin['name'] ?? '';
-        $post['shopAdminName'] = $name;
-        $product = $post['product'] ?? '';
-        $productList = json_decode($product, true);
-        //判断product数据是不是同个供货商的
-        ProductClass::valid($productList, $currentShopId);
-        $post['product'] = $productList;
-        $post['sendCost'] = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
-        $respond = PurchaseService::addPurchase($post);
-        $orderSn = $respond['orderSn'] ?? '';
-        $actPrice = $respond['actPrice'] ?? '';
-        $data = [
-            'orderSn' => $orderSn,
-            'actPrice' => $actPrice,
-            'hasBalancePay' => 1,
-            'hasPayPassword' => 0,
-            'hasDebtPay' => 1,
-        ];
-        util::success($data);
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            $currentShopId = $ghsInfo['shopId'] ?? 0;
+            $post['merchantId'] = $this->sjId;
+            $post['shopId'] = $this->shopId;
+            $post['shopAdminId'] = $this->shopAdminId;
+            $post['ghsId'] = $ghsId;
+            $customId = $ghsInfo['customId'] ?? 0;
+            $post['customId'] = $customId;
+            $shopAdmin = $this->shopAdmin;
+            $name = $shopAdmin['name'] ?? '';
+            $post['shopAdminName'] = $name;
+            $product = $post['product'] ?? '';
+            $productList = json_decode($product, true);
+            //判断product数据是不是同个供货商的
+            ProductClass::valid($productList, $currentShopId);
+            $post['product'] = $productList;
+            $post['sendCost'] = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
+            $respond = PurchaseService::createPurchase($post);
+            $orderSn = $respond['orderSn'] ?? '';
+            $actPrice = $respond['actPrice'] ?? '';
+            $transaction->commit();
+            $data = [
+                'orderSn' => $orderSn,
+                'actPrice' => $actPrice,
+                'hasBalancePay' => 1,
+                'hasPayPassword' => 0,
+                'hasDebtPay' => 1,
+            ];
+            util::success($data);
+        } catch (Exception $e) {
+            $transaction->rollBack();
+            util::fail();
+        }
     }
 
     //延期支付 ssh 2021.1.24
@@ -59,6 +71,21 @@ class PurchaseController extends BaseController
         $orderSn = $get['orderSn'] ?? 0;
         $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
         PurchaseClass::valid($info->attributes, $this->shopId);
+        $deadline = $info->deadline;
+        if ($deadline <= date("Y-m-d H:i:s")) {
+            PurchaseClass::cancel($info);
+            util::fail('订单已失效,请重新采购');
+        }
+        $ghsId = $info->ghsId;
+        $ghs = GhsClass::getGhsInfo($ghsId);
+        $customId = $ghs['customId'] ?? 0;
+        $custom = CustomClass::getCustom($customId);
+        if (empty($custom)) {
+            util::fail('没有找到客户');
+        }
+        if (isset($custom['debt']) == false || $custom['debt'] == CustomClass::IS_DEBT_NO) {
+            util::fail('您没有延期付款权限');
+        }
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
         try {

+ 5 - 5
biz-ghs/order/classes/OrderClass.php

@@ -127,10 +127,10 @@ class OrderClass extends BaseClass
         $shop->totalOrder += 1;
         $shop->unPayOrder += 1;
         $shop->save();
-
+        $current = time() + 300;
+        $data['deadline'] = isset($data['deadline']) ? $data['deadline'] : date("Y-m-d H:i:s", $current);
         $return = self::add($data);
-
-        return ['return' => $return, 'product' => $product, 'shop' => $shop];
+        return $return;
     }
 
     //根据订单编号查询 ssh 2021.19
@@ -182,8 +182,8 @@ class OrderClass extends BaseClass
 
             //待确认订单显示延期付和已付款
             if ($order['status'] == OrderClass::ORDER_STATUS_UN_PAY) {
-                $debtPay = ['type' => 'debtPay', 'show' => 1, 'disable' => 0];
-                $hasPay = ['type' => 'hasPay', 'show' => 1, 'disable' => 0];
+                $debtPay = ['type' => 'debtPay', 'show' => 0, 'disable' => 0];
+                $hasPay = ['type' => 'hasPay', 'show' => 0, 'disable' => 0];
                 return [$debtPay, $hasPay];
             }
 

+ 15 - 13
biz-ghs/order/services/OrderService.php

@@ -3,10 +3,10 @@
 namespace bizGhs\order\services;
 
 use biz\ghs\classes\GhsClass;
+use biz\shop\models\Shop;
 use bizGhs\base\services\BaseService;
 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;
@@ -17,19 +17,17 @@ class OrderService extends BaseService
     public static $baseFile = '\bizGhs\order\classes\OrderClass';
 
     //添加订单
-    public static function addOrder($data, $custom)
+    public static function createOrder($data)
     {
         //供货商销售单
-        $arr = OrderClass::addOrder($data);
-        $return = $arr['return'];
-        $product = $arr['product'];
-        $shop = $arr['shop'];
+        $return = OrderClass::addOrder($data);
 
-        $customSjId = $custom['sjId'] ?? 0;
-        $customShopId = $custom['shopId'] ?? 0;
+        $customSjId = $data['sjId'] ?? 0;
+        $customShopId = $data['shopId'] ?? 0;
         $ghsShopAdminId = $data['shopAdminId'] ?? 0;
         $ghsShopAdminName = $data['shopAdminName'] ?? '';
-        $ghsId = $custom['ghsId'] ?? 0;
+        $customId = $data['customId'] ?? 0;
+        $ghsId = $data['ghsId'] ?? 0;
         $ghs = GhsClass::getById($ghsId);
         if (empty($ghs)) {
             util::fail('没有找到供货商');
@@ -46,11 +44,18 @@ class OrderService extends BaseService
             'merchantId' => $customSjId,
             'shopId' => $customShopId,
             'saleId' => $saleId,
+            'ghsId' => $ghsId,
+            'customId' => $customId,
         ];
         $purchase = PurchaseClass::addPurchase($purchaseData);
         $purchaseId = $purchase['id'] ?? 0;
         OrderClass::updateById($saleId, ['purchaseId' => $purchaseId]);
 
+        $currentShopId = $data['shopId'] ?? 0;
+        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $currentShopId])->one();
+        if (empty($shop)) {
+            util::fail('没有找到门店');
+        }
         //0正常订单 1欠款
         $debt = $data['debt'] ?? 0;
         if ($debt == 1) {
@@ -60,10 +65,7 @@ class OrderService extends BaseService
             //已收款
             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);

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

@@ -21,11 +21,12 @@ class PurchaseClass extends BaseClass
     use OrderTrait;
     public static $baseFile = '\bizHd\purchase\models\Purchase';
 
-    //订单状态 1待付款,待确认,2待配送,3配送中,4已完成
+    //订单状态 1待付款,待确认,2待配送,3配送中,4已完成,5取消,失败
     const STATUS_UN_PAY = 1;
     const STATUS_UN_SEND = 2;
     const STATUS_SENDING = 3;
     const STATUS_COMPLETE = 4;
+    const STATUS_CANCEL = 5;
 
     //未知
     const DEBT_UNKNOWN = 0;
@@ -34,6 +35,11 @@ class PurchaseClass extends BaseClass
     //没有欠款
     const DEBT_NO = 2;
 
+    //配送
+    const GET_TYPE_SEND = 1;
+    //自取
+    const GET_TYPE_SELF_GET = 2;
+
     //添加采购 ssh 2021.1.18
     public static function addPurchase($data)
     {
@@ -114,6 +120,9 @@ class PurchaseClass extends BaseClass
         $data['actPrice'] = $actPrice;
         $data['bigNum'] = $bigNum;
         $data['smallNum'] = $smallNum;
+        //采购单5分钟有效期
+        $current = time() + 300;
+        $data['deadline'] = isset($data['deadline']) ? $data['deadline'] : date("Y-m-d H:i:s", $current);
         $respond = self::add($data);
         if (isset($data['product']) == false || empty($data['product'])) {
             util::fail('请选择花材');
@@ -278,7 +287,7 @@ class PurchaseClass extends BaseClass
         $saleId = $info->saleId ?? 0;
         $ghsOrder = OrderClass::getById($saleId, true);
         if (empty($ghsOrder)) {
-            util::fail('没有找到对应供货商订单');
+            util::fail('没有找到对应供货商的销售单订单');
         }
         $ghsOrder->status = OrderClass::ORDER_STATUS_UN_SEND;
         $ghsOrder->debt = OrderClass::DEBT_YES;
@@ -307,4 +316,11 @@ class PurchaseClass extends BaseClass
         $custom->save();
     }
 
+    //订单取消,变更状态,占用库存释放 shish 2021.5.8
+    public static function cancel($order)
+    {
+        $order->status = self::STATUS_CANCEL;
+        $order->save();
+    }
+
 }

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

@@ -1,6 +1,7 @@
 <?php
 
 namespace bizHd\purchase\services;
+
 use biz\ghs\classes\GhsClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\order\classes\OrderClass;
@@ -15,7 +16,7 @@ class PurchaseService extends BaseService
 
     public static $baseFile = '\bizHd\purchase\classes\PurchaseClass';
 
-    public static function addPurchase($data)
+    public static function createPurchase($data)
     {
         //零售采购单
         $respond = PurchaseClass::addPurchase($data);
@@ -39,6 +40,14 @@ class PurchaseService extends BaseService
         $customNamePy = $custom['py'] ?? '';
         $customMobile = $custom['mobile'] ?? '';
         $purchaseId = $respond['id'] ?? 0;
+        $shopAdminId = $data['shopAdminId'] ?? 0;
+        $shopAdminName = $data['shopAdminName'] ?? '';
+        //客户采购时选了自取,则供货商的销售单就是自取
+        $sendType = OrderClass::SEND_TYPE_UNKNOWN;
+        $getType = $data['getType'] ?? PurchaseClass::GET_TYPE_SELF_GET;
+        if ($getType == PurchaseClass::GET_TYPE_SELF_GET) {
+            $sendType = OrderClass::SEND_TYPE_NO;
+        }
         $arr = [
             'product' => $product,
             'merchantId' => $currentSjId,
@@ -50,9 +59,13 @@ class PurchaseService extends BaseService
             'customNamePy' => $customNamePy,
             'customMobile' => $customMobile,
             'purchaseId' => $purchaseId,
+            'sendType' => $sendType,
+            'customShopAdminId' => $shopAdminId,
+            'customShopAdminName' => $shopAdminName,
+            'ghsId' => $ghsId,
         ];
-        $return = OrderClass::addOrder($arr, $currentShopId);
-        $saleId = $return['id'] ?? 0;
+        $result = OrderClass::addOrder($arr);
+        $saleId = $result['id'] ?? 0;
         PurchaseClass::updateById($purchaseId, ['saleId' => $saleId]);
         return $respond;
     }

+ 6 - 1
sql.sql

@@ -2383,4 +2383,9 @@ ALTER TABLE xhPurchase MODIFY `ghsOrderId` INT(11) NOT NULL DEFAULT '0' COMMENT
 ALTER TABLE `xhPurchase` CHANGE `ghsOrderId` `saleOrderId` INT(11) NOT NULL DEFAULT '0' COMMENT '供货商的销售单id';
 ALTER TABLE xhGhsOrder CHANGE `hdOrderId` `purchaseOrderId` INT(11) NOT NULL DEFAULT '0' COMMENT '花店采购单id';
 ALTER TABLE `xhPurchase` CHANGE `saleOrderId` `saleId` INT(11) NOT NULL DEFAULT '0' COMMENT '供货商的销售单id';
-ALTER TABLE xhGhsOrder CHANGE `purchaseOrderId` `purchaseId` INT(11) NOT NULL DEFAULT '0' COMMENT '花店采购单id';
+ALTER TABLE xhGhsOrder CHANGE `purchaseOrderId` `purchaseId` INT(11) NOT NULL DEFAULT '0' COMMENT '花店采购单id';
+ALTER TABLE `xhGhsOrder` CHANGE `customAdminId` `customShopAdminId` INT(11) NOT NULL DEFAULT '0' COMMENT '客户员工id';
+ALTER TABLE `xhGhsOrder` ADD customShopAdminName VARCHAR(50) NOT NULL DEFAULT '' COMMENT '客户员工名称' AFTER `customShopAdminId`;
+ALTER TABLE xhGhsOrder MODIFY `customId` INT(11) NOT NULL DEFAULT '0' COMMENT '客户id 对应xhGhsCustom id字段';
+ALTER TABLE xhPurchase ADD customId INT NOT NULL DEFAULT 0 COMMENT '客户id,冗余字段' AFTER `changePrice`;
+ALTER TABLE xhGhsOrder ADD ghsId INT NOT NULL DEFAULT 0 COMMENT '供货商id,冗余字段' AFTER `shopAdminName`;