| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- namespace hd\models\order;
- use common\components\dict;
- use common\components\stringUtil;
- use hd\models\BaseForm;
- class CreateOrderForm extends BaseForm
- {
- public $flowerNum;
- public $version;
- public $shopAdminId;
- public $shopAdminName;
- public $getStaffId;
- public $getStaffName;
- public $groupId;
- public $fromType;
- public $bookName;
- public $customId;
- public $receiveMobile;
- public $bookMobile;
- public $hasPay;
- public $sendType;
- public $forward;
- public $historyDate;
- public $modifyPrice;
- public $product;
- public $unitGoodsPrice;
- public $zjGathering;
- public $lsGoodsPrice;
- public $reduceStock;
- public $dealPrice;
- public $needWork;
- public $isCashier;
- public $callErrand;
- public $payWay;
- public $deliveryPlatform;
- public $deliveryPrice;
- public $deliveryDistance;
- public $deliveryBracketContent;
- public $deliveryAllParams;
- public $pickupTime;
- public $weight;
- public $deliveryRemark;
- public $needPrint;
- public $hbId;
- public $hbAmount;
-
- // Common order fields
- public $remark;
- public $reachDate;
- public $reachPeriod;
- public $cardInfo;
- public $anonymity;
- public function rules()
- {
- return [
- [['version'], 'compare', 'compareValue' => 3, 'operator' => '>=', 'message' => '请升级版本,或用小程序'],
-
- [['customId'], 'required', 'message' => '请选择客户'], // Though controller checks existence later
-
- [['fromType'], 'validateFromType'],
- [['receiveMobile', 'bookMobile'], 'validateMobile'],
- [['forward'], 'validateForward'],
- [['zjGathering'], 'validateZjGathering'],
- [['unitGoodsPrice'], 'validateUnitGoodsPrice'],
- [['product'], 'validateProduct'],
- [['flowerNum', 'version', 'shopAdminId', 'getStaffId', 'groupId', 'fromType', 'customId', 'hasPay', 'sendType', 'forward', 'zjGathering', 'reduceStock', 'needWork', 'isCashier', 'callErrand', 'payWay', 'anonymity', 'needPrint', 'hbId'], 'integer'],
- [['modifyPrice', 'lsGoodsPrice', 'dealPrice', 'deliveryPrice', 'deliveryDistance', 'weight', 'hbAmount'], 'number'],
- [['shopAdminName', 'getStaffName', 'bookName', 'receiveMobile', 'bookMobile', 'historyDate', 'product', 'deliveryPlatform', 'deliveryBracketContent', 'pickupTime', 'remark', 'deliveryRemark', 'reachDate', 'reachPeriod', 'cardInfo'], 'string'],
- [['unitGoodsPrice', 'deliveryAllParams'], 'safe'],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'customId' => '客户',
- 'product' => '花材',
- 'bookName' => '订花人姓名',
- 'receiveMobile' => '收花人手机号',
- 'bookMobile' => '订花人手机号',
- 'historyDate' => '订单日期',
- 'lsGoodsPrice' => '价格',
- ];
- }
- public function validateFromType($attribute, $params)
- {
- if (!$this->hasErrors()) {
- $friendType = dict::getDict('fromType', 'friend');
- if ($this->fromType == $friendType && empty($this->bookName)) {
- $this->addError('bookName', '请填写订花人姓名');
- }
- }
- }
- public function validateMobile($attribute, $params)
- {
- if (!$this->hasErrors() && !empty($this->$attribute)) {
- if (!stringUtil::isMobile($this->$attribute)) {
- $label = $this->getAttributeLabel($attribute);
- $this->addError($attribute, '请填写正确的' . $label);
- }
- }
- }
- public function validateForward($attribute, $params)
- {
- if (!$this->hasErrors() && $this->forward == 1) {
- if ($this->hasPay != 1) { // 1 is unPay? No, unPay is usually 0 or 1. Controller says: if ($hasPay != 1) fail('售后付款单只能走线下转账');
- // Need to check what 1 means. Controller: if ($hasPay != 1).
- // Let's assume 1 is the value expected.
- $this->addError('hasPay', '售后付款单只能走线下转账');
- }
-
- if (!empty($this->historyDate) && $this->historyDate != date("Y-m-d")) {
- $this->addError('historyDate', '售后付款单不能修改账单日期,只能今天');
- }
- }
- }
-
- public function validateZjGathering($attribute, $params)
- {
- if (!$this->hasErrors() && $this->zjGathering == 1) {
- if (!is_numeric($this->lsGoodsPrice) || $this->lsGoodsPrice <= 0) {
- $this->addError('lsGoodsPrice', '请填写价格');
- }
- }
- }
- public function validateUnitGoodsPrice($attribute, $params)
- {
- if (!$this->hasErrors() && !empty($this->unitGoodsPrice)) {
- $this->addError($attribute, '此功能停用,有需要请联系管理员');
- }
- }
- public function validateProduct($attribute, $params)
- {
- if (!$this->hasErrors()) {
- // If groupId is present, product might be empty (refer to controller logic line 668)
- // Controller: if (empty($productList) && empty($groupId)) { check unitGoodsPrice... }
- // So if groupId is set, product can be empty.
- if (!empty($this->groupId)) {
- return;
- }
-
- // Also if zjGathering is 1, product is constructed in Controller (line 699), so input product can be empty.
- if ($this->zjGathering == 1) {
- return;
- }
- $productJson = $this->$attribute;
- if (empty($productJson)) {
- $this->addError($attribute, '请选择花材');
- return;
- }
- $productList = json_decode($productJson, true);
- if (empty($productList)) {
- $this->addError($attribute, '请选择花材');
- }
- }
- }
- }
|