CreateOrderForm.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 $forward;
  23. public $historyDate;
  24. public $modifyPrice;
  25. public $product;
  26. public $unitGoodsPrice;
  27. public $zjGathering;
  28. public $lsGoodsPrice;
  29. public $reduceStock;
  30. public $dealPrice;
  31. public $needWork;
  32. public $isCashier;
  33. public $callErrand;
  34. public $payWay;
  35. public $deliveryPlatform;
  36. public $deliveryPrice;
  37. public $deliveryDistance;
  38. public $deliveryBracketContent;
  39. public $deliveryAllParams;
  40. public $pickupTime;
  41. public $weight;
  42. public $deliveryRemark;
  43. public $needPrint;
  44. public $hbId;
  45. public $hbAmount;
  46. // Common order fields
  47. public $remark;
  48. public $reachDate;
  49. public $reachPeriod;
  50. public $cardInfo;
  51. public $anonymity;
  52. public function rules()
  53. {
  54. return [
  55. [['version'], 'compare', 'compareValue' => 3, 'operator' => '>=', 'message' => '请升级版本,或用小程序'],
  56. [['customId'], 'required', 'message' => '请选择客户'], // Though controller checks existence later
  57. [['fromType'], 'validateFromType'],
  58. [['receiveMobile', 'bookMobile'], 'validateMobile'],
  59. [['forward'], 'validateForward'],
  60. [['zjGathering'], 'validateZjGathering'],
  61. [['unitGoodsPrice'], 'validateUnitGoodsPrice'],
  62. [['product'], 'validateProduct'],
  63. [['flowerNum', 'version', 'shopAdminId', 'getStaffId', 'groupId', 'fromType', 'customId', 'hasPay', 'sendType', 'forward', 'zjGathering', 'reduceStock', 'needWork', 'isCashier', 'callErrand', 'payWay', 'anonymity', 'needPrint', 'hbId'], 'integer'],
  64. [['modifyPrice', 'lsGoodsPrice', 'dealPrice', 'deliveryPrice', 'deliveryDistance', 'weight', 'hbAmount'], 'number'],
  65. [['shopAdminName', 'getStaffName', 'bookName', 'receiveMobile', 'bookMobile', 'historyDate', 'product', 'deliveryPlatform', 'deliveryBracketContent', 'pickupTime', 'remark', 'deliveryRemark', 'reachDate', 'reachPeriod', 'cardInfo'], 'string'],
  66. [['unitGoodsPrice', 'deliveryAllParams'], 'safe'],
  67. ];
  68. }
  69. public function attributeLabels()
  70. {
  71. return [
  72. 'customId' => '客户',
  73. 'product' => '花材',
  74. 'bookName' => '订花人姓名',
  75. 'receiveMobile' => '收花人手机号',
  76. 'bookMobile' => '订花人手机号',
  77. 'historyDate' => '订单日期',
  78. 'lsGoodsPrice' => '价格',
  79. ];
  80. }
  81. public function validateFromType($attribute, $params)
  82. {
  83. if (!$this->hasErrors()) {
  84. $friendType = dict::getDict('fromType', 'friend');
  85. if ($this->fromType == $friendType && empty($this->bookName)) {
  86. $this->addError('bookName', '请填写订花人姓名');
  87. }
  88. }
  89. }
  90. public function validateMobile($attribute, $params)
  91. {
  92. if (!$this->hasErrors() && !empty($this->$attribute)) {
  93. if (!stringUtil::isMobile($this->$attribute)) {
  94. $label = $this->getAttributeLabel($attribute);
  95. $this->addError($attribute, '请填写正确的' . $label);
  96. }
  97. }
  98. }
  99. public function validateForward($attribute, $params)
  100. {
  101. if (!$this->hasErrors() && $this->forward == 1) {
  102. if ($this->hasPay != 1) { // 1 is unPay? No, unPay is usually 0 or 1. Controller says: if ($hasPay != 1) fail('售后付款单只能走线下转账');
  103. // Need to check what 1 means. Controller: if ($hasPay != 1).
  104. // Let's assume 1 is the value expected.
  105. $this->addError('hasPay', '售后付款单只能走线下转账');
  106. }
  107. if (!empty($this->historyDate) && $this->historyDate != date("Y-m-d")) {
  108. $this->addError('historyDate', '售后付款单不能修改账单日期,只能今天');
  109. }
  110. }
  111. }
  112. public function validateZjGathering($attribute, $params)
  113. {
  114. if (!$this->hasErrors() && $this->zjGathering == 1) {
  115. if (!is_numeric($this->lsGoodsPrice) || $this->lsGoodsPrice <= 0) {
  116. $this->addError('lsGoodsPrice', '请填写价格');
  117. }
  118. }
  119. }
  120. public function validateUnitGoodsPrice($attribute, $params)
  121. {
  122. if (!$this->hasErrors() && !empty($this->unitGoodsPrice)) {
  123. $this->addError($attribute, '此功能停用,有需要请联系管理员');
  124. }
  125. }
  126. public function validateProduct($attribute, $params)
  127. {
  128. if (!$this->hasErrors()) {
  129. // If groupId is present, product might be empty (refer to controller logic line 668)
  130. // Controller: if (empty($productList) && empty($groupId)) { check unitGoodsPrice... }
  131. // So if groupId is set, product can be empty.
  132. if (!empty($this->groupId)) {
  133. return;
  134. }
  135. // Also if zjGathering is 1, product is constructed in Controller (line 699), so input product can be empty.
  136. if ($this->zjGathering == 1) {
  137. return;
  138. }
  139. $productJson = $this->$attribute;
  140. if (empty($productJson)) {
  141. $this->addError($attribute, '请选择花材');
  142. return;
  143. }
  144. $productList = json_decode($productJson, true);
  145. if (empty($productList)) {
  146. $this->addError($attribute, '请选择花材');
  147. }
  148. }
  149. }
  150. }