CreateOrderForm.php 5.8 KB

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