Bladeren bron

还原创建订单API的数据验证代码

shizhongqi 7 maanden geleden
bovenliggende
commit
5352b40c2c

+ 14 - 2
app-ghs/controllers/OrderController.php

@@ -1008,7 +1008,12 @@ class OrderController extends BaseController
         $post = Yii::$app->request->post();
 
         $shopId = $this->shopId;
-        $customId = $post['customId'];
+        $customId = $post['customId'] ?? 0;
+        $post['customId'] = $customId;
+        //开单必须选客户
+        if (empty($customId)) {
+            util::fail('请选择客户');
+        }
 
         $modifyPrice = $post['modifyPrice'] ?? 0;
         $pattern = '/^\d+(\.\d{1,2})?$/';
@@ -1196,8 +1201,15 @@ class OrderController extends BaseController
         }
 
         $post['xj'] = $newXj;
-        $productJson = $post['product'];
+
+        $productJson = $post['product'] ?? '';
+        if (empty($productJson)) {
+            util::fail('请选择花材');
+        }
         $productList = json_decode($productJson, true);
+        if (empty($productList)) {
+            util::fail('请选择花材');
+        }
 
         $ids = array_unique(array_filter(array_column($productList, 'productId')));
         $itemInfo = ProductClass::getByIds($ids, null, 'id');

+ 2 - 1
app-ghs/models/order/CreateOrderForm.php

@@ -34,6 +34,7 @@ class CreateOrderForm extends BaseForm
     public $payWay;
     public $weight;
     public $deliveryRemark;
+    public $needPrint;
     
     // Additional fields that might be passed or processed
     public $bookSn;
@@ -43,7 +44,7 @@ class CreateOrderForm extends BaseForm
         return [
             ['customId', 'required', 'message' => '请选择客户'],
             ['product', 'required', 'message' => '请选择花材'],
-            [['customId', 'expressId', 'book', 'sendType', 'transType', 'hasPay', 'callErrand', 'isCashier', 'getStaffId', 'shopAdminId', 'bookSn'], 'integer'],
+            [['customId', 'expressId', 'book', 'sendType', 'transType', 'hasPay', 'callErrand', 'isCashier', 'getStaffId', 'shopAdminId', 'bookSn', 'needPrint'], 'integer'],
             [['modifyPrice', 'dealPrice', 'sendCost', 'packCost', 'deliveryPrice', 'deliveryDistance', 'weight'], 'number'],
             [['getStaffName', 'shopAdminName', 'deliveryPlatform', 'deliveryBracketContent', 'pickupTime', 'historyDate', 'deliveryRemark'], 'string'],
             [['xj', 'product', 'payWay', 'deliveryAllParams'], 'safe'],

+ 36 - 4
app-hd/controllers/OrderController.php

@@ -588,6 +588,9 @@ class OrderController extends BaseController
         $post['flowerNum'] = isset($post['flowerNum']) && $post['flowerNum'] > 0 ? $post['flowerNum'] : 0;
 
         $version = $post['version'] ?? 0; //验证已移至 CreateOrderForm
+        if ($version < 3) {
+            util::fail('请升级版本,或用小程序');
+        }
 
         //默认情况开单员工和收款员工是同个人
         $staffId = $this->shopAdminId ?? 0;
@@ -603,7 +606,12 @@ class OrderController extends BaseController
         
         $groupId = !empty($post['groupId']) ? $post['groupId'] : 0;
         $post['fromType'] = $post['fromType'] ?? 1;
-        $customId = $post['customId'];
+        if ($post['fromType'] == dict::getDict('fromType', 'friend')) {
+            if (empty($post['bookName'])) {
+                util::fail('请填写订花人姓名');
+            }
+        }
+        $customId = $post['customId'] ?? 0;
         $custom = CustomClass::getById($customId, true);
         if (empty($custom)) {
             util::fail('没有找到客户哦');
@@ -619,12 +627,30 @@ class OrderController extends BaseController
         $customName = $custom->name ?? '';
         $post['customName'] = $customName;
         $post['customNamePy'] = stringUtil::py($customName);
+        if (!empty($post['receiveMobile'])) {
+            if (!stringUtil::isMobile($post['receiveMobile'])) {
+                util::fail('请填写正确的收花人手机号');
+            }
+        }
+        if (!empty($post['bookMobile'])) {
+            if (!stringUtil::isMobile($post['bookMobile'])) {
+                util::fail('请填写正确的订花人手机号');
+            }
+        }
 
         $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
         $post['sendType'] = $post['sendType'] ?? 1;
         $forward = $post['forward'] ?? 0;
         if ($forward == 1) {
-            // 售后付款单验证已移至 CreateOrderForm
+            if ($hasPay != 1) {
+                util::fail('售后付款单只能走线下转账');
+            }
+            $historyDate = $post['historyDate'] ?? '';
+            if (!empty($historyDate)) {
+                if ($historyDate != date("Y-m-d")) {
+                    util::fail('售后付款单不能修改账单日期,只能今天');
+                }
+            }
         } else {
             //如果不是售后付款单,并且选的不是余额支付,余额又够付当前订单,则自动切到余额支付
             $balance = $custom->balance ?? 0;
@@ -643,7 +669,11 @@ class OrderController extends BaseController
         if (empty($productList) && empty($groupId)) {
             //商家手机上开单并生成制作单
             if (!empty($post['unitGoodsPrice'])) {
-                // 此功能停用,验证已移至 CreateOrderForm
+                util::fail('此功能停用,有需要请联系管理员');
+                $unitGoodsPrice = $post['unitGoodsPrice'];
+                if (!is_numeric($unitGoodsPrice)) {
+                    util::fail('请输入正确的单价');
+                }
                 $productList = GoodsClass::orderCreateGoods($post);
             }
         }
@@ -652,7 +682,9 @@ class OrderController extends BaseController
         $zjGathering = $post['zjGathering'] ?? 0;
         if ($zjGathering == 1) {
             $lsGoodsPrice = $post['lsGoodsPrice'] ?? 0;
-            // 验证已移至 CreateOrderForm
+            if (!is_numeric($lsGoodsPrice) || $lsGoodsPrice <= 0) {
+                util::fail('请填写价格');
+            }
             //直接收款不需要打印小票
             $post['needPrint'] = dict::getDict('needPrint', 'noNeed');
             $shopId = $this->shopId;

+ 2 - 1
app-hd/models/order/CreateOrderForm.php

@@ -42,6 +42,7 @@ class CreateOrderForm extends BaseForm
     public $pickupTime;
     public $weight;
     public $deliveryRemark;
+    public $needPrint;
     
     // Common order fields
     public $remark;
@@ -64,7 +65,7 @@ class CreateOrderForm extends BaseForm
             [['unitGoodsPrice'], 'validateUnitGoodsPrice'],
             [['product'], 'validateProduct'],
             
-            [['flowerNum', 'version', 'shopAdminId', 'getStaffId', 'groupId', 'fromType', 'customId', 'hasPay', 'sendType', 'forward', 'zjGathering', 'reduceStock', 'needWork', 'isCashier', 'callErrand', 'payWay', 'anonymity'], 'integer'],
+            [['flowerNum', 'version', 'shopAdminId', 'getStaffId', 'groupId', 'fromType', 'customId', 'hasPay', 'sendType', 'forward', 'zjGathering', 'reduceStock', 'needWork', 'isCashier', 'callErrand', 'payWay', 'anonymity', 'needPrint'], 'integer'],
             [['modifyPrice', 'lsGoodsPrice', 'dealPrice', 'deliveryPrice', 'deliveryDistance', 'weight'], 'number'],
             [['shopAdminName', 'getStaffName', 'bookName', 'receiveMobile', 'bookMobile', 'historyDate', 'product', 'deliveryPlatform', 'deliveryBracketContent', 'pickupTime', 'remark', 'deliveryRemark', 'reachDate', 'reachPeriod', 'cardInfo'], 'string'],
             [['unitGoodsPrice', 'deliveryAllParams'], 'safe'],