RebateVirtualOrderLog.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /*
  3. * @Descripttion:
  4. * @copyright: Copyright (c) 2021 广东七件事集团
  5. * @Author: lun
  6. * @Date: 2022-01-01 01:10:32
  7. */
  8. namespace addons\Rebate\common\models;
  9. use common\models\user\User;
  10. use yii\db\Exception;
  11. /**
  12. *
  13. * @property-read mixed $user
  14. */
  15. class RebateVirtualOrderLog extends \common\models\base\BaseActiveRecord
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public static function tableName()
  21. {
  22. return '{{%addons_rebate_virtual_order_log}}';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function rules()
  28. {
  29. return [
  30. [['mall_id', 'user_id', 'rebate_id', 'rebate_buy_id'], 'required'],
  31. [['mall_id', 'user_id', 'rebate_id', 'rebate_buy_id', 'user_parent_id'], 'integer'],
  32. ];
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function attributeLabels()
  38. {
  39. return [
  40. 'id' => 'ID',
  41. 'user_id' => 'User Id',
  42. 'mall_id' => 'Mall Id',
  43. 'user_parent_id' => 'User Parent Id',
  44. 'rebate_id' => 'Rebate Id',
  45. 'rebate_buy_id' => 'Rebate Buy Id',
  46. 'created_at' => 'Created At',
  47. 'updated_at' => 'Updated At',
  48. ];
  49. }
  50. /***
  51. * 关联用户
  52. */
  53. public function getUser()
  54. {
  55. return $this->hasOne(User::class, ['id' => 'user_id']);
  56. }
  57. /***
  58. * 关联上级用户
  59. */
  60. public function getParentUser()
  61. {
  62. return $this->hasOne(User::class, ['id' => 'user_parent_id']);
  63. }
  64. /***
  65. * 关联推三返一活动
  66. */
  67. public function getRebate()
  68. {
  69. return $this->hasOne(Rebate::class, ['id' => 'rebate_id']);
  70. }
  71. /***
  72. * 关联推三返一活动购买信息
  73. */
  74. public function getRebateBuy()
  75. {
  76. return $this->hasOne(RebateBuy::class, ['id' => 'rebate_buy_id']);
  77. }
  78. /**
  79. * 保存数据
  80. *
  81. * @Author : lun
  82. * @DateTime : 2022/1/15 0015 9:36
  83. * @Copyright: copyright (c) 2021 广东七件事集团
  84. *
  85. * @param $mall_id
  86. * @param array $params
  87. *
  88. * @return array|bool
  89. */
  90. public static function setData($mall_id, array $params)
  91. {
  92. try {
  93. $model = new self();
  94. $model->loadDefaultValues();
  95. $model->mall_id = $mall_id;
  96. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  97. return $model->toArray();
  98. } catch (\Exception $e) {
  99. self::setStaticError($e->getMessage());
  100. return false;
  101. }
  102. }
  103. }