CreateOrderForm.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace hd\models\order;
  3. use common\components\dict;
  4. use common\components\stringUtil;
  5. use hd\models\BaseForm;
  6. class CreateOrderForm extends BaseForm
  7. {
  8. public $flowerNum;
  9. public $version;
  10. public $shopAdminId;
  11. public $shopAdminName;
  12. public $getStaffId;
  13. public $getStaffName;
  14. public $groupId;
  15. public $fromType;
  16. public $bookName;
  17. public $customId;
  18. public $receiveMobile;
  19. public $bookMobile;
  20. public $hasPay;
  21. public $sendType;
  22. public $historyDate;
  23. public $modifyPrice;
  24. public $product;
  25. public $unitGoodsPrice;
  26. public $zjGathering;
  27. public $lsGoodsPrice;
  28. public $reduceStock;
  29. public $dealPrice;
  30. public $needWork;
  31. public $isCashier;
  32. public $callErrand;
  33. public $payWay;
  34. public $deliveryPlatform;
  35. public $deliveryPrice;
  36. public $deliveryDistance;
  37. public $deliveryBracketContent;
  38. public $deliveryAllParams;
  39. public $pickupTime;
  40. public $weight;
  41. public $deliveryRemark;
  42. public $needPrint;
  43. public $hbId;
  44. public $hbAmount;
  45. // Common order fields
  46. public $remark;
  47. public $reachDate;
  48. public $reachPeriod;
  49. public $cardInfo;
  50. public $anonymity;
  51. public function rules()
  52. {
  53. return [
  54. [['version'], 'compare', 'compareValue' => 3, 'operator' => '>=', 'message' => '请升级版本,或用小程序'],
  55. [['customId'], 'required', 'message' => '请选择客户'], // Though controller checks existence later
  56. [['fromType'], 'validateFromType'],
  57. [['receiveMobile', 'bookMobile'], 'validateMobile'],
  58. [['zjGathering'], 'validateZjGathering'],
  59. [['unitGoodsPrice'], 'validateUnitGoodsPrice'],
  60. [['product'], 'validateProduct'],
  61. [['flowerNum', 'version', 'shopAdminId', 'getStaffId', 'groupId', 'fromType', 'customId', 'hasPay', 'sendType', 'zjGathering', 'reduceStock', 'needWork', 'isCashier', 'callErrand', 'payWay', 'anonymity', 'needPrint', 'hbId'], 'integer'],
  62. [['modifyPrice', 'lsGoodsPrice', 'dealPrice', 'deliveryPrice', 'deliveryDistance', 'weight', 'hbAmount'], 'number'],
  63. [['shopAdminName', 'getStaffName', 'bookName', 'receiveMobile', 'bookMobile', 'historyDate', 'product', 'deliveryPlatform', 'deliveryBracketContent', 'pickupTime', 'remark', 'deliveryRemark', 'reachDate', 'reachPeriod', 'cardInfo'], 'string'],
  64. [['unitGoodsPrice', 'deliveryAllParams'], 'safe'],
  65. ];
  66. }
  67. public function attributeLabels()
  68. {
  69. return [
  70. 'customId' => '客户',
  71. 'product' => '花材',
  72. 'bookName' => '订花人姓名',
  73. 'receiveMobile' => '收花人手机号',
  74. 'bookMobile' => '订花人手机号',
  75. 'historyDate' => '订单日期',
  76. 'lsGoodsPrice' => '价格',
  77. ];
  78. }
  79. public function validateFromType($attribute, $params)
  80. {
  81. if (!$this->hasErrors()) {
  82. $friendType = dict::getDict('fromType', 'friend');
  83. if ($this->fromType == $friendType && empty($this->bookName)) {
  84. $this->addError('bookName', '请填写订花人姓名');
  85. }
  86. }
  87. }
  88. public function validateMobile($attribute, $params)
  89. {
  90. if (!$this->hasErrors() && !empty($this->$attribute)) {
  91. if (!stringUtil::isMobile($this->$attribute)) {
  92. $label = $this->getAttributeLabel($attribute);
  93. $this->addError($attribute, '请填写正确的' . $label);
  94. }
  95. }
  96. }
  97. public function validateZjGathering($attribute, $params)
  98. {
  99. if (!$this->hasErrors() && $this->zjGathering == 1) {
  100. if (!is_numeric($this->lsGoodsPrice) || $this->lsGoodsPrice <= 0) {
  101. $this->addError('lsGoodsPrice', '请填写价格');
  102. }
  103. }
  104. }
  105. public function validateUnitGoodsPrice($attribute, $params)
  106. {
  107. if (!$this->hasErrors() && !empty($this->unitGoodsPrice)) {
  108. $this->addError($attribute, '此功能停用,有需要请联系管理员');
  109. }
  110. }
  111. public function validateProduct($attribute, $params)
  112. {
  113. if (!$this->hasErrors()) {
  114. // If groupId is present, product might be empty (refer to controller logic line 668)
  115. // Controller: if (empty($productList) && empty($groupId)) { check unitGoodsPrice... }
  116. // So if groupId is set, product can be empty.
  117. if (!empty($this->groupId)) {
  118. return;
  119. }
  120. // Also if zjGathering is 1, product is constructed in Controller (line 699), so input product can be empty.
  121. if ($this->zjGathering == 1) {
  122. return;
  123. }
  124. $productJson = $this->$attribute;
  125. if (empty($productJson)) {
  126. $this->addError($attribute, '请选择花材');
  127. return;
  128. }
  129. $productList = json_decode($productJson, true);
  130. if (empty($productList)) {
  131. $this->addError($attribute, '请选择花材');
  132. }
  133. }
  134. }
  135. }