CreateOrderForm.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. // Common order fields
  45. public $remark;
  46. public $reachDate;
  47. public $reachPeriod;
  48. public $cardInfo;
  49. public $anonymity;
  50. public function rules()
  51. {
  52. return [
  53. [['version'], 'compare', 'compareValue' => 3, 'operator' => '>=', 'message' => '请升级版本,或用小程序'],
  54. [['customId'], 'required', 'message' => '请选择客户'], // Though controller checks existence later
  55. [['fromType'], 'validateFromType'],
  56. [['receiveMobile', 'bookMobile'], 'validateMobile'],
  57. [['forward'], 'validateForward'],
  58. [['zjGathering'], 'validateZjGathering'],
  59. [['unitGoodsPrice'], 'validateUnitGoodsPrice'],
  60. [['product'], 'validateProduct'],
  61. [['flowerNum', 'version', 'shopAdminId', 'getStaffId', 'groupId', 'fromType', 'customId', 'hasPay', 'sendType', 'forward', 'zjGathering', 'reduceStock', 'needWork', 'isCashier', 'callErrand', 'payWay', 'anonymity', 'needPrint'], 'integer'],
  62. [['modifyPrice', 'lsGoodsPrice', 'dealPrice', 'deliveryPrice', 'deliveryDistance', 'weight'], '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 validateForward($attribute, $params)
  98. {
  99. if (!$this->hasErrors() && $this->forward == 1) {
  100. if ($this->hasPay != 1) { // 1 is unPay? No, unPay is usually 0 or 1. Controller says: if ($hasPay != 1) fail('售后付款单只能走线下转账');
  101. // Need to check what 1 means. Controller: if ($hasPay != 1).
  102. // Let's assume 1 is the value expected.
  103. $this->addError('hasPay', '售后付款单只能走线下转账');
  104. }
  105. if (!empty($this->historyDate) && $this->historyDate != date("Y-m-d")) {
  106. $this->addError('historyDate', '售后付款单不能修改账单日期,只能今天');
  107. }
  108. }
  109. }
  110. public function validateZjGathering($attribute, $params)
  111. {
  112. if (!$this->hasErrors() && $this->zjGathering == 1) {
  113. if (!is_numeric($this->lsGoodsPrice) || $this->lsGoodsPrice <= 0) {
  114. $this->addError('lsGoodsPrice', '请填写价格');
  115. }
  116. }
  117. }
  118. public function validateUnitGoodsPrice($attribute, $params)
  119. {
  120. if (!$this->hasErrors() && !empty($this->unitGoodsPrice)) {
  121. $this->addError($attribute, '此功能停用,有需要请联系管理员');
  122. }
  123. }
  124. public function validateProduct($attribute, $params)
  125. {
  126. if (!$this->hasErrors()) {
  127. // If groupId is present, product might be empty (refer to controller logic line 668)
  128. // Controller: if (empty($productList) && empty($groupId)) { check unitGoodsPrice... }
  129. // So if groupId is set, product can be empty.
  130. if (!empty($this->groupId)) {
  131. return;
  132. }
  133. // Also if zjGathering is 1, product is constructed in Controller (line 699), so input product can be empty.
  134. if ($this->zjGathering == 1) {
  135. return;
  136. }
  137. $productJson = $this->$attribute;
  138. if (empty($productJson)) {
  139. $this->addError($attribute, '请选择花材');
  140. return;
  141. }
  142. $productList = json_decode($productJson, true);
  143. if (empty($productList)) {
  144. $this->addError($attribute, '请选择花材');
  145. }
  146. }
  147. }
  148. }