AfterSale.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace addons\TinyShop\common\models\order;
  3. use Yii;
  4. use yii\db\ActiveQuery;
  5. use common\models\member\Member;
  6. use common\models\base\BaseModel;
  7. use addons\TinyShop\common\models\product\Product;
  8. /**
  9. * This is the model class for table "{{%addon_tiny_shop_order_after_sale}}".
  10. *
  11. * @property int $id 主键id
  12. * @property int|null $merchant_id 店铺ID
  13. * @property int|null $type 售后类型[1:售中;2:售后]
  14. * @property int|null $order_id 订单id
  15. * @property string|null $order_sn 订单编号
  16. * @property int|null $order_product_id 订单项id
  17. * @property int|null $store_id 门店id
  18. * @property int|null $buyer_id 用户id
  19. * @property string|null $buyer_nickname 用户昵称
  20. * @property int|null $product_id 商品id
  21. * @property int|null $sku_id skuID
  22. * @property int|null $number 购买数量
  23. * @property float|null $refund_apply_money 退款申请金额
  24. * @property int|null $refund_type 退款方式
  25. * @property int|null $refund_pay_type 付款方式
  26. * @property string|null $refund_reason 退款原因
  27. * @property string|null $refund_explain 退款说明
  28. * @property string|null $refund_evidence 退款凭证
  29. * @property int|null $refund_status 退款状态
  30. * @property float|null $refund_money 订单退款余额
  31. * @property int|null $refund_time 退款时间
  32. * @property string|null $member_express_company 退款物流公司名称
  33. * @property string|null $member_express_no 退款物流单号
  34. * @property int|null $member_express_mobile 手机号码
  35. * @property int|null $member_express_time 退款物流时间
  36. * @property int|null $merchant_shipping_type 发货方式1 需要物流 0无需物流
  37. * @property int|null $merchant_express_company_id 快递公司id
  38. * @property string|null $merchant_express_company 物流公司名称
  39. * @property string|null $merchant_express_no 运单编号
  40. * @property int|null $merchant_express_mobile 商家手机号码
  41. * @property int|null $merchant_express_time 退款物流时间
  42. * @property string|null $memo 备注
  43. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  44. * @property int|null $created_at
  45. * @property int|null $updated_at
  46. */
  47. class AfterSale extends BaseModel
  48. {
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public static function tableName()
  53. {
  54. return '{{%addon_tiny_shop_order_after_sale}}';
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function rules()
  60. {
  61. return [
  62. [['refund_money'], 'required'],
  63. [
  64. [
  65. 'merchant_id',
  66. 'type',
  67. 'order_id',
  68. 'order_product_id',
  69. 'store_id',
  70. 'buyer_id',
  71. 'product_id',
  72. 'sku_id',
  73. 'number',
  74. 'refund_type',
  75. 'refund_pay_type',
  76. 'refund_status',
  77. 'refund_time',
  78. 'member_express_time',
  79. 'merchant_shipping_type',
  80. 'merchant_express_company_id',
  81. 'merchant_express_time',
  82. 'status',
  83. 'created_at',
  84. 'updated_at',
  85. ],
  86. 'integer',
  87. ],
  88. [['refund_apply_money', 'refund_money'], 'number'],
  89. [['refund_evidence'], 'safe'],
  90. [['order_sn'], 'string', 'max' => 30],
  91. [['merchant_express_mobile', 'member_express_mobile'], 'string', 'max' => 20],
  92. [['buyer_nickname', 'member_express_company', 'member_express_no'], 'string', 'max' => 100],
  93. [['refund_reason', 'merchant_express_company', 'memo'], 'string', 'max' => 255],
  94. [['refund_explain'], 'string', 'max' => 200],
  95. [['merchant_express_no'], 'string', 'max' => 50],
  96. ];
  97. }
  98. /**
  99. * {@inheritdoc}
  100. */
  101. public function attributeLabels()
  102. {
  103. return [
  104. 'id' => '主键id',
  105. 'merchant_id' => '店铺ID',
  106. 'type' => '出售状态', // 售后
  107. 'order_id' => '订单id',
  108. 'order_sn' => '订单编号',
  109. 'order_product_id' => '订单项id',
  110. 'store_id' => '门店id',
  111. 'buyer_id' => '用户id',
  112. 'buyer_nickname' => '用户昵称',
  113. 'product_id' => '商品id',
  114. 'sku_id' => 'skuID',
  115. 'number' => '购买数量',
  116. 'refund_apply_money' => '退款申请金额',
  117. 'refund_type' => '退款方式',
  118. 'refund_pay_type' => '付款方式',
  119. 'refund_reason' => '退款原因',
  120. 'refund_explain' => '退款说明',
  121. 'refund_evidence' => '退款凭证',
  122. 'refund_status' => '退款状态',
  123. 'refund_money' => '退款金额',
  124. 'refund_time' => '退款时间',
  125. 'member_express_company' => '退款物流公司名称',
  126. 'member_express_no' => '退款物流单号',
  127. 'member_express_mobile' => '退款手机号码',
  128. 'member_express_time' => '退款物流时间',
  129. 'merchant_shipping_type' => '发货方式', // 1 需要物流 0 无需物流
  130. 'merchant_express_company_id' => '快递公司id',
  131. 'merchant_express_company' => '物流公司名称',
  132. 'merchant_express_no' => '运单编号',
  133. 'merchant_express_mobile' => '手机号码',
  134. 'merchant_express_time' => '退款物流时间',
  135. 'memo' => '备注',
  136. 'status' => '状态',
  137. 'created_at' => 'Created At',
  138. 'updated_at' => 'Updated At',
  139. ];
  140. }
  141. /**
  142. * @return ActiveQuery
  143. */
  144. public function getOrder()
  145. {
  146. return $this->hasOne(Order::class, ['id' => 'order_id']);
  147. }
  148. /**
  149. * @return ActiveQuery
  150. */
  151. public function getProduct()
  152. {
  153. return $this->hasOne(Product::class, ['id' => 'product_id']);
  154. }
  155. /**
  156. * @return ActiveQuery
  157. */
  158. public function getOrderProduct()
  159. {
  160. return $this->hasOne(OrderProduct::class, ['id' => 'order_product_id']);
  161. }
  162. /**
  163. * @return ActiveQuery
  164. */
  165. public function getMember()
  166. {
  167. return $this->hasOne(Member::class, ['id' => 'buyer_id']);
  168. }
  169. /**
  170. * @param $insert
  171. * @param $changedAttributes
  172. * @return void
  173. */
  174. public function afterSave($insert, $changedAttributes)
  175. {
  176. if ($insert) {
  177. OrderProduct::updateAll(['refund_status' => $this->refund_status, 'refund_type' => $this->refund_type, 'after_sale_id' => $this->id], ['id' => $this->order_product_id]);
  178. } else {
  179. OrderProduct::updateAll(['refund_status' => $this->refund_status], ['after_sale_id' => $this->id]);
  180. }
  181. parent::afterSave($insert, $changedAttributes);
  182. }
  183. }
粤ICP备19079148号