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.

201 lines
6.3 KiB

  1. <?php
  2. namespace backend\modules\shop\models\ars;
  3. use common\models\User;
  4. use Yii;
  5. use yii\behaviors\TimestampBehavior;
  6. use yii\helpers\ArrayHelper;
  7. /**
  8. * This is the model class for table "ats_order".
  9. *
  10. * @property int $id
  11. * @property int $user_id 用户id
  12. * @property string $order_sn 订单号
  13. * @property string $invoice_id 发票单号
  14. * @property int $status 状态
  15. * @property int $type 类型
  16. * @property int $goods_count 商品数量
  17. * @property int $goods_amount 商品金额
  18. * @property int $shipping_amount 物流金额
  19. * @property int $shipping_type 物流类型
  20. * @property string $consignee 收件人
  21. * @property string $phone 手机号码
  22. * @property string $province 省份
  23. * @property string $city 城市
  24. * @property string $area 区域
  25. * @property int $taking_site 自提点
  26. * @property int $pay_type 支付方式
  27. * @property int $pay_at 支付时间
  28. * @property string $payment_sn 付款单号
  29. * @property int $payment_amount 支付金额
  30. * @property int $receivables 应收款
  31. * @property string $remarks 备注
  32. * @property int $discount_amount 折扣金额
  33. * @property string $discount_description 折扣说明
  34. * @property int $updated_at 更新时间
  35. * @property int $created_at 创建时间
  36. * @property string $address 详细地址
  37. */
  38. class Order extends \yii\db\ActiveRecord
  39. {
  40. const TYPE_SHOPPING = 1;//普通购物订单
  41. const SHIPPING_TYPE_VIRTUAL_GOODS = 0;//虚拟货物
  42. const SHIPPING_TYPE_PICKED_UP = 1;//自提
  43. const SHIPPING_TYPE_EXPRESS = 2;//快递物流
  44. const STATUS_UNCONFIRMED = 0;
  45. const STATUS_NONPAYMENT = 1;
  46. const STATUS_CANCEL = 2;
  47. const STATUS_PAYMENT_TO_BE_CONFIRMED = 3;
  48. const STATUS_TO_BE_SHIPPING = 6;
  49. const STATUS_APPLY_REFUND = 4;
  50. const STATUS_REFUND = 5;
  51. const STATUS_SHIPMENT_ALL = 7;
  52. const STATUS_SHIPMENT_PORTION = 8;
  53. const STATUS_FINISH = 9;
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public static function tableName()
  58. {
  59. return 'ats_order';
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function rules()
  65. {
  66. return [
  67. [['user_id'], 'required'],
  68. [['user_id', 'status', 'type', 'goods_count', 'goods_amount', 'shipping_amount', 'shipping_type', 'taking_site', 'pay_type', 'pay_at', 'payment_amount', 'receivables', 'discount_amount'], 'integer'],
  69. [['discount_description', 'address'], 'string'],
  70. [['order_sn', 'invoice_id'], 'string', 'max' => 64],
  71. [['consignee', 'phone'], 'string', 'max' => 20],
  72. [['province', 'city', 'area'], 'string', 'max' => 10],
  73. [['payment_sn'], 'string', 'max' => 120],
  74. [['remarks'], 'string', 'max' => 255],
  75. ];
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function attributeLabels()
  81. {
  82. return [
  83. 'id' => 'id',
  84. 'user_id' => '用户id',
  85. 'order_sn' => '订单号',
  86. 'invoice_id' => '发票单号',
  87. 'status' => '状态',
  88. 'type' => '类型',
  89. 'goods_count' => '商品数量',
  90. 'goods_amount' => '商品金额',
  91. 'shipping_amount' => '物流金额',
  92. 'shipping_type' => '物流类型',
  93. 'consignee' => '收件人',
  94. 'phone' => '手机号码',
  95. 'province' => '省份',
  96. 'city' => '城市',
  97. 'area' => '区域',
  98. 'taking_site' => '自提点',
  99. 'pay_type' => '支付方式',
  100. 'pay_at' => '支付时间',
  101. 'payment_sn' => '付款单号',
  102. 'payment_amount' => '支付金额',
  103. 'receivables' => '应收款',
  104. 'remarks' => '备注',
  105. 'discount_amount' => '折扣金额',
  106. 'discount_description' => '折扣说明',
  107. 'updated_at' => '更新时间',
  108. 'created_at' => '创建时间',
  109. 'address' => '详细地址',
  110. ];
  111. }
  112. /**
  113. * @author linyao
  114. * @email 602604991@qq.com
  115. * @created Nov 8, 2019
  116. *
  117. * 行为存储创建时间和更新时间
  118. */
  119. public function behaviors()
  120. {
  121. return [
  122. [
  123. 'class' => TimestampBehavior::className(),
  124. 'createdAtAttribute' => 'created_at',
  125. 'updatedAtAttribute' => 'updated_at',
  126. 'value' => function() {
  127. return time();
  128. },
  129. ],
  130. ];
  131. }
  132. public function getUser()
  133. {
  134. return $this->hasOne(User::className(), ['id' => 'user_id']);
  135. }
  136. public function getProvinceId()
  137. {
  138. return $this->hasOne(Province::className(), ['province_id' => 'province']);
  139. }
  140. public function getCityId()
  141. {
  142. return $this->hasOne(City::className(), ['city_id' => 'city']);
  143. }
  144. public function getAreaId()
  145. {
  146. return $this->hasOne(Area::className(), ['area_id' => 'area']);
  147. }
  148. /**
  149. * @param $column
  150. * @param null $value
  151. * @return bool
  152. * 获取各状态数组
  153. */
  154. public static function dropDown($column, $value = null)
  155. {
  156. $dropDownList = [
  157. 'shipping_type' => [
  158. self::SHIPPING_TYPE_VIRTUAL_GOODS => '虚拟货物',
  159. self::SHIPPING_TYPE_PICKED_UP => '自提',
  160. self::SHIPPING_TYPE_EXPRESS => '快递物流',
  161. ],
  162. 'type' => [
  163. self::TYPE_SHOPPING => '普通购物订单',
  164. ],
  165. 'status' => [
  166. self::STATUS_UNCONFIRMED => '待确认',
  167. self::STATUS_NONPAYMENT => '待支付',
  168. self::STATUS_CANCEL => '已取消',
  169. self::STATUS_PAYMENT_TO_BE_CONFIRMED => '支付待确认',
  170. self::STATUS_APPLY_REFUND => '申请退款',
  171. self::STATUS_REFUND => '已退款',
  172. self::STATUS_TO_BE_SHIPPING => '待发货',
  173. self::STATUS_SHIPMENT_ALL => '全部发货',
  174. self::STATUS_SHIPMENT_PORTION => '部分发货',
  175. self::STATUS_FINISH => '已完成',
  176. ]
  177. ];
  178. //根据具体值显示对应的值
  179. if ($value !== null)
  180. return array_key_exists($column, $dropDownList) ? $dropDownList[$column][$value] : false;
  181. //返回关联数组,用户下拉的filter实现
  182. else
  183. return array_key_exists($column, $dropDownList) ? $dropDownList[$column] : false;
  184. }
  185. }