PreviewForm.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. namespace addons\TinyShop\common\forms;
  3. use Yii;
  4. use common\helpers\ArrayHelper;
  5. use common\models\member\Member;
  6. use common\models\member\Address;
  7. use addons\TinyShop\common\models\marketing\Coupon;
  8. use addons\TinyShop\common\models\order\OrderProduct;
  9. use addons\TinyShop\common\models\product\Product;
  10. use addons\TinyShop\common\models\merchant\Merchant;
  11. use addons\TinyShop\common\models\order\Order;
  12. /**
  13. * Class PreviewForm
  14. * @package addons\TinyShop\common\forms
  15. * @author jianyan74 <751393839@qq.com>
  16. */
  17. class PreviewForm extends Order
  18. {
  19. /** ------------- 提交的必填数据 ------------- */
  20. /**
  21. * 数据
  22. *
  23. * @var
  24. */
  25. public $data;
  26. /**
  27. * 提交的类型
  28. *
  29. * @var
  30. */
  31. public $type;
  32. /**
  33. * 超值换购
  34. *
  35. * @var array|string
  36. */
  37. public $plus_buy;
  38. /** ------------- 处理后的数据 ------------- */
  39. /**
  40. * 触发的营销
  41. *
  42. * @var
  43. */
  44. public $marketing;
  45. /**
  46. * 优惠
  47. *
  48. * @var array
  49. */
  50. public $marketingDetails = [];
  51. /**
  52. * 默认的系统商品
  53. *
  54. * @var Product|array
  55. */
  56. public $defaultProducts = [];
  57. /**
  58. * 生成的订单商品
  59. *
  60. * @var array|OrderProduct
  61. */
  62. public $orderProducts = [];
  63. /**
  64. * 生成的订单商品组别
  65. *
  66. * @var array|OrderProduct
  67. */
  68. public $groupOrderProducts = [];
  69. /**
  70. * sku数据
  71. *
  72. * @var array
  73. */
  74. public $sku = [];
  75. /**
  76. * 全部商品ID
  77. *
  78. * @var array
  79. */
  80. public $productIds = [];
  81. /**
  82. * 商家分类ID
  83. *
  84. * @var array
  85. */
  86. public $cateIds = [];
  87. /**
  88. * 平台分类ID
  89. *
  90. * @var array
  91. */
  92. public $platformCateIds = [];
  93. /**
  94. * @var Address
  95. */
  96. public $address;
  97. public $address_id;
  98. /**
  99. * 门店自提点
  100. *
  101. * @var
  102. */
  103. public $store;
  104. /**
  105. * @var Member
  106. */
  107. public $member;
  108. /**
  109. * @var Merchant
  110. */
  111. public $merchant;
  112. /**
  113. * 优惠券
  114. *
  115. * @var Coupon
  116. */
  117. public $coupon;
  118. public $coupon_id;
  119. /**
  120. * 发票
  121. *
  122. * @var
  123. */
  124. public $invoice;
  125. public $invoice_id;
  126. public $invoice_content;
  127. /**
  128. * 物流ID
  129. *
  130. * @var int
  131. */
  132. public $company_id;
  133. /**
  134. * 全部包邮
  135. *
  136. * @var int
  137. */
  138. public $is_full_mail = 0;
  139. /**
  140. * 包邮商品
  141. *
  142. * @var array
  143. */
  144. public $fullProductIds = [];
  145. /**
  146. * 计算运费
  147. *
  148. * @var bool
  149. */
  150. public $freight = false;
  151. /**
  152. * 最多可抵扣积分
  153. *
  154. * @var
  155. */
  156. public $max_use_point = 0;
  157. /**
  158. * 使用积分
  159. *
  160. * @var int
  161. */
  162. public $use_point = 0;
  163. /**
  164. * @var array
  165. */
  166. public $config = [];
  167. /**
  168. * @return array
  169. */
  170. public function rules()
  171. {
  172. return ArrayHelper::merge(parent::rules(), [
  173. [['data', 'type'], 'required'],
  174. [['plus_buy'], 'safe'],
  175. [['invoice_content'], 'string'],
  176. [['coupon_id', 'address_id', 'company_id', 'use_point'], 'integer', 'min' => 0],
  177. [['shipping_type'], 'required', 'on' => ['create']],
  178. [['invoice_id'], 'invoiceVerify', 'on' => ['create']],
  179. ]);
  180. }
  181. /**
  182. * @return array
  183. */
  184. public function attributeLabels()
  185. {
  186. return ArrayHelper::merge(parent::attributeLabels(), [
  187. 'member' => '用户',
  188. 'data' => '数据',
  189. 'type' => '数据类型',
  190. 'plus_buy' => '超值换购',
  191. 'coupon' => '优惠券',
  192. 'coupon_id' => '优惠券',
  193. 'address' => '收货地址',
  194. 'address_id' => '收货地址',
  195. 'company_id' => '物流公司',
  196. 'use_point' => '使用积分',
  197. 'invoice_content' => '开票内容',
  198. ]);
  199. }
  200. /**
  201. * 场景
  202. *
  203. * @return array
  204. */
  205. public function scenarios()
  206. {
  207. $scenarios = parent::scenarios();
  208. $scenarios['create'] = ArrayHelper::merge(array_keys($this->attributeLabels()), ['address_id']);
  209. return $scenarios;
  210. }
  211. /**
  212. * 使用积分验证
  213. *
  214. * @param $attribute
  215. */
  216. public function usePointVerify($attribute)
  217. {
  218. if ($this->use_point > $this->max_use_point) {
  219. $this->addError($attribute, '积分不可超出最大可用额度');
  220. }
  221. }
  222. /**
  223. * 发票校验
  224. *
  225. * @param $attribute
  226. */
  227. public function invoiceVerify($attribute)
  228. {
  229. if (!empty($this->invoice_id)) {
  230. $this->invoice = Yii::$app->services->memberInvoice->findById($this->invoice_id, $this->member->id);
  231. if (!$this->invoice) {
  232. $this->addError($attribute, '发票信息不存在');
  233. }
  234. }
  235. }
  236. }
粤ICP备19079148号