Bläddra i källkod

新增拆散功能

shish 3 år sedan
förälder
incheckning
2663df0c2e

+ 102 - 0
app-hd/controllers/PartController.php

@@ -0,0 +1,102 @@
+<?php
+
+namespace hd\controllers;
+use bizGhs\product\classes\ProductClass;
+use bizHd\part\classes\PartClass;
+use common\components\dict;
+use common\components\util;
+use Yii;
+
+class PartController extends BaseController
+{
+
+    public $guestAccess = [];
+
+    //拆散花材 ssh 20230208
+    public function actionPartItem()
+    {
+        $shopAdmin = $this->shopAdmin;
+        if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
+            util::fail('超管才能拆散');
+        }
+
+        $post = Yii::$app->request->post();
+        $post['shopId'] = $this->shopId;
+        $post['sjId'] = $this->sjId;
+        $post['mainId'] = $this->mainId;
+        $post['shopAdminId'] = $this->shopAdminId;
+        $shopAdmin = $this->shopAdmin;
+        $adminName = $shopAdmin['name'] ?? '';
+        $post['shopAdminName'] = $adminName;
+        $productJson = $post['product'] ?? '';
+        if (empty($productJson)) {
+            util::fail('请选择花材');
+        }
+        $productList = json_decode($productJson, true);
+        if (empty($productList)) {
+            util::fail('请选择花材');
+        }
+
+        //有unitType数据,说明是收银台传过来的数据,转换成和手机端结构一致
+        $hasUnitType = array_column($productList, 'unitType');
+        if (!empty($hasUnitType)) {
+            $newProductList = [];
+            foreach ($productList as $key => $val) {
+                $unitType = $val['unitType'] ?? 0;
+                $bigNum = 0;
+                $smallNum = 0;
+                $num = $val['num'] ?? 0;
+                $id = $val['productId'] ?? 0;
+                if ($unitType == dict::getDict('unitType', 'big')) {
+                    $bigNum = $num;
+                } else {
+                    $smallNum = $num;
+                }
+                $newProductList[] = ['productId' => $id, 'bigNum' => $bigNum, 'smallNum' => $smallNum, 'classId' => 0, 'itemId' => 0];
+            }
+            $productList = $newProductList;
+        }
+
+        foreach ($productList as $v) {
+            $bigNum = $v['bigNum'] ?? 0;
+            $smallNum = $v['smallNum'] ?? 0;
+            if ($bigNum <= 0 && $smallNum <= 0) {
+                util::fail('数量不能为0');
+            }
+            if (isset($v['property']) && $v['property'] == 0) {
+                util::fail('花材和商品请分开拆散');
+            }
+        }
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            ProductClass::valid($productList, $this->mainId);
+            $post['product'] = $productList;
+            $post['ptStyle'] = dict::getDict('ptStyle', 'hd');
+            $return = PartClass::addOrder($post);
+            $transaction->commit();
+            util::success($return);
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("拆散失败原因:" . $e->getMessage());
+            util::fail('拆散保存失败');
+        }
+    }
+
+    //列表
+    public function actionList()
+    {
+        $where = [];
+        $where['mainId'] = $this->mainId;
+        $list = PartClass::getOrderList($where);
+        util::success($list);
+    }
+
+    public function actionDetail()
+    {
+        $orderSn = Yii::$app->request->get('orderSn', '');
+        $orderData = PartClass::getOrderDetail($orderSn, $this->mainId);
+        util::success($orderData);
+    }
+
+}

+ 12 - 0
biz-hd/part/classes/PartClass.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace bizHd\part\classes;
+use bizHd\base\classes\BaseClass;
+use Yii;
+
+class PartClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\part\models\Part';
+
+}

+ 12 - 0
biz-hd/part/classes/PartItemClass.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace bizHd\part\classes;
+use bizHd\base\classes\BaseClass;
+use Yii;
+
+class PartItemClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\part\models\PartItem';
+
+}

+ 12 - 0
biz-hd/part/classes/PartSnClass.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace bizHd\part\classes;
+use bizHd\base\classes\BaseClass;
+use Yii;
+
+class PartSnClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\part\models\PartSn';
+
+}

+ 12 - 0
biz-hd/part/classes/StatPartClass.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace bizHd\part\classes;
+use bizHd\base\classes\BaseClass;
+use Yii;
+
+class StatPartClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\part\models\StatPart';
+
+}

+ 12 - 0
biz-hd/part/classes/StatPartMonthClass.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace bizHd\part\classes;
+use bizHd\base\classes\BaseClass;
+use Yii;
+
+class StatPartMonthClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\part\models\StatPartMonth';
+
+}

+ 13 - 0
biz-hd/part/models/Part.php

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

+ 13 - 0
biz-hd/part/models/PartItem.php

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

+ 13 - 0
biz-hd/part/models/PartSn.php

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

+ 13 - 0
biz-hd/part/models/StatPart.php

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

+ 13 - 0
biz-hd/part/models/StatPartMonth.php

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

+ 10 - 0
biz-hd/part/services/PartService.php

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