You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.9 KiB

  1. <?php
  2. namespace backend\modules\shop\models\ars;
  3. use Yii;
  4. use yii\behaviors\TimestampBehavior;
  5. /**
  6. * This is the model class for table "ats_order".
  7. *
  8. * @property int $id
  9. * @property int $user_id 用户id
  10. * @property string $order_sn 订单号
  11. * @property string $invoice_id 发票单号
  12. * @property int $status 状态
  13. * @property int $type 类型
  14. * @property int $goods_count 商品数量
  15. * @property int $goods_amount 商品金额
  16. * @property int $shipping_amount 物流金额
  17. * @property int $shipping_type 物流类型
  18. * @property string $consignee 收件人
  19. * @property string $phone 手机号码
  20. * @property string $province 省份
  21. * @property string $city 城市
  22. * @property string $area 区域
  23. * @property int $taking_site 自提点
  24. * @property int $pay_type 支付方式
  25. * @property int $pay_at 支付时间
  26. * @property string $payment_sn 付款单号
  27. * @property int $payment_amount 支付金额
  28. * @property int $receivables 应收款
  29. * @property string $remarks 备注
  30. * @property int $discount_amount 折扣金额
  31. * @property string $discount_description 折扣说明
  32. * @property int $updated_at 更新时间
  33. * @property int $created_at 创建时间
  34. * @property string $address 详细地址
  35. */
  36. class Order extends \yii\db\ActiveRecord
  37. {
  38. const TYPE_SHOPPING = 1;//普通购物订单
  39. const SHIPPING_TYPE_VIRTUAL_GOODS = 0;//虚拟货物
  40. const SHIPPING_TYPE_PICKED_UP = 1;//自提
  41. const SHIPPING_TYPE_EXPRESS = 2;//快递物流
  42. const STATUS_UNCONFIRMED = 0;
  43. const STATUS_NONPAYMENT = 1;
  44. const STATUS_CANCEL = 2;
  45. const STATUS_PAYMENT_TO_BE_CONFIRMED = 3;
  46. const STATUS_TO_BE_SHIPPING = 6;
  47. const STATUS_APPLY_REFUND = 4;
  48. const STATUS_REFUND = 5;
  49. const STATUS_SHIPMENT_ALL = 7;
  50. const STATUS_SHIPMENT_PORTION = 8;
  51. const STATUS_FINISH = 9;
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public static function tableName()
  56. {
  57. return 'ats_order';
  58. }
  59. public function fields()
  60. {
  61. $fields = parent::fields();
  62. unset($fields['user_id']);
  63. unset($fields['payment_sn']);
  64. return $fields;
  65. }
  66. /**
  67. * {@inheritdoc}
  68. */
  69. public function rules()
  70. {
  71. return [
  72. [['user_id'], 'required'],
  73. [['user_id', 'status', 'type', 'goods_count', 'goods_amount', 'shipping_amount', 'shipping_type', 'taking_site', 'pay_type', 'pay_at', 'payment_amount', 'receivables', 'discount_amount'], 'integer'],
  74. [['discount_description', 'address'], 'string'],
  75. [['order_sn', 'invoice_id'], 'string', 'max' => 64],
  76. [['consignee', 'phone'], 'string', 'max' => 20],
  77. [['province', 'city', 'area'], 'string', 'max' => 10],
  78. [['payment_sn'], 'string', 'max' => 120],
  79. [['remarks'], 'string', 'max' => 255],
  80. ];
  81. }
  82. /**
  83. * {@inheritdoc}
  84. */
  85. public function attributeLabels()
  86. {
  87. return [
  88. 'id' => 'id',
  89. 'user_id' => '用户id',
  90. 'order_sn' => '订单号',
  91. 'invoice_id' => '发票单号',
  92. 'status' => '状态',
  93. 'type' => '类型',
  94. 'goods_count' => '商品数量',
  95. 'goods_amount' => '商品金额',
  96. 'shipping_amount' => '物流金额',
  97. 'shipping_type' => '物流类型',
  98. 'consignee' => '收件人',
  99. 'phone' => '手机号码',
  100. 'province' => '省份',
  101. 'city' => '城市',
  102. 'area' => '区域',
  103. 'taking_site' => '自提点',
  104. 'pay_type' => '支付方式',
  105. 'pay_at' => '支付时间',
  106. 'payment_sn' => '付款单号',
  107. 'payment_amount' => '支付金额',
  108. 'receivables' => '应收款',
  109. 'remarks' => '备注',
  110. 'discount_amount' => '折扣金额',
  111. 'discount_description' => '折扣说明',
  112. 'updated_at' => '更新时间',
  113. 'created_at' => '创建时间',
  114. 'address' => '详细地址',
  115. ];
  116. }
  117. public function beforeSave($insert)
  118. {
  119. if ($this->status === self::STATUS_UNCONFIRMED && $this->type == self::TYPE_SHOPPING) {
  120. $this->shipping_amount = $this->countShippingAmount();
  121. $this->receivables = $this->goods_amount + $this->shipping_amount;
  122. $this->payment_amount = $this->receivables - $this->discount_amount;
  123. }
  124. return parent::beforeSave($insert);
  125. }
  126. /**
  127. * @author linyao
  128. * @email 602604991@qq.com
  129. * @created Nov 8, 2019
  130. *
  131. * 行为存储创建时间和更新时间
  132. */
  133. public function behaviors()
  134. {
  135. return [
  136. [
  137. 'class' => TimestampBehavior::className(),
  138. 'createdAtAttribute' => 'created_at',
  139. 'updatedAtAttribute' => 'updated_at',
  140. 'value' => function () {
  141. return time();
  142. },
  143. ],
  144. ];
  145. }
  146. }