OrderModel.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace addons\RandFee\common\models;
  3. use common\models\common\PaymentTrade;
  4. use common\models\order\Order;
  5. use common\models\user\User;
  6. use Yii;
  7. use yii\db\ActiveRecord;
  8. /**
  9. * This is the model class for table "{{%addons_rand_fee_order}}".
  10. *
  11. * @property int $id
  12. * @property int $mall_id
  13. * @property int $trade_id 支付流水ID
  14. * @property int $order_id 订单ID
  15. * @property string $order_no 订单号
  16. * @property int $user_id 会员ID
  17. * @property float $rand_fee 订单减免金额
  18. * @property float $total_rand_fee 减免金额
  19. * @property string $order_type 订单类型
  20. * @property int|null $created_at
  21. */
  22. class OrderModel extends ActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_rand_fee_order}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id', 'trade_id', 'order_id', 'user_id', 'created_at'], 'integer'],
  38. [['rand_fee', 'total_rand_fee'], 'number'],
  39. [['order_no'], 'string', 'max' => 64],
  40. [['order_type'], 'string', 'max' => 32],
  41. ];
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => 'ID',
  50. 'mall_id' => 'Mall ID',
  51. 'trade_id' => 'Trade ID',
  52. 'order_id' => 'Order ID',
  53. 'order_no' => 'Order No',
  54. 'user_id' => 'User ID',
  55. 'rand_fee' => 'Rand Fee',
  56. 'total_rand_fee' => 'Total Rand Fee',
  57. 'order_type' => 'Order Type',
  58. 'created_at' => 'Created At',
  59. ];
  60. }
  61. /**
  62. * 订单表
  63. *
  64. * @return ActiveQuery
  65. */
  66. public function getOrder()
  67. {
  68. return $this->hasOne(Order::class, ['id' => 'order_id']);
  69. }
  70. /**
  71. * 会员表
  72. *
  73. * @return ActiveQuery
  74. */
  75. public function getUser()
  76. {
  77. return $this->hasOne(User::class, ['id' => 'user_id']);
  78. }
  79. /**
  80. * 流水
  81. *
  82. * @return ActiveQuery
  83. */
  84. public function getTrade()
  85. {
  86. return $this->hasOne(PaymentTrade::class, ['id' => 'trade_id']);
  87. }
  88. /**
  89. * 通过ID获取
  90. *
  91. * @param array $ids
  92. * @return array
  93. */
  94. public static function getRandFeeByOrderIds(array $ids)
  95. {
  96. return static::find()
  97. ->where(['order_id' => $ids])
  98. ->all();
  99. }
  100. }