BlindBoxRecommendUserLog.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace addons\BlindBox\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_blind_box_recommend_user_log".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城id
  11. * @property int $user_id 会员id
  12. * @property int $parent_id 上级id
  13. * @property int $bonus_log_id 分红记录id
  14. * @property int $status 状态[-1:删除;0:禁用;1启用]
  15. * @property int $created_at
  16. * @property int $updated_at
  17. */
  18. class BlindBoxRecommendUserLog extends BaseActiveRecord
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%addons_blind_box_recommend_user_log}}';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['mall_id', 'user_id', 'parent_id','bonus_log_id', 'status', 'created_at', 'updated_at'], 'integer'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => '商城id',
  44. 'user_id' => '会员id',
  45. 'parent_id' => '上级id',
  46. 'bonus_log_id' => '分红记录id',
  47. 'status' => '状态[-1:删除;0:禁用;1启用]',
  48. 'created_at' => 'Created At',
  49. 'updated_at' => 'Updated At',
  50. ];
  51. }
  52. public static function addData(array $params)
  53. {
  54. try {
  55. $model = self::findOne([
  56. 'mall_id' => $params['mall_id'],
  57. 'user_id' => $params['user_id'],
  58. 'parent_id' => $params['parent_id'],
  59. 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  60. if (empty($model)) {
  61. $model = new self();
  62. $model->loadDefaultValues();
  63. }
  64. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  65. $res = $model->save();
  66. if ($res == false) throw new \Exception($model->getErrorMessage());
  67. return $model;
  68. } catch (\Exception $e) {
  69. self::$static_error = $e->getMessage();
  70. return false;
  71. }
  72. }
  73. }