PkPersonalMember.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace addons\Pk\common\models;
  3. use common\models\user\User;
  4. use Yii;
  5. /**
  6. * This is the model class for table "addons_pk_personal_member".
  7. *
  8. * @property int $id
  9. * @property int $user_id
  10. * @property int $mall_id
  11. * @property int $activity_id 活动id
  12. * @property float $performance 人数;业绩金额
  13. * @property int $performance_goal 业绩目标
  14. * @property int $created_at
  15. * @property int $updated_at
  16. * @property int $performance_type 业绩类型;1拉新;2业绩
  17. * @property int|null $performance_rank 业绩排名
  18. * @property int $order_id 订单id
  19. * @property int $status 状态[-1:删除;0:禁用;1启用]
  20. */
  21. class PkPersonalMember extends \common\models\base\BaseActiveRecord
  22. {
  23. const EABLE_STATUS = 1;
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_pk_personal_member}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['user_id', 'mall_id', 'activity_id', 'performance_type'], 'required'],
  38. [['user_id', 'mall_id', 'activity_id', 'created_at', 'updated_at', 'performance_type', 'performance_rank', 'order_id', 'status'], 'integer'],
  39. [['performance', 'performance_goal'], 'number'],
  40. ];
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'id' => 'ID',
  49. 'user_id' => 'User ID',
  50. 'mall_id' => 'Mall ID',
  51. 'activity_id' => '活动id',
  52. 'performance' => '人数;业绩金额',
  53. 'performance_goal' => '业绩目标',
  54. 'created_at' => 'Created At',
  55. 'updated_at' => 'Updated At',
  56. 'performance_type' => '业绩类型;1拉新;2业绩',
  57. 'performance_rank' => '业绩排名',
  58. 'order_id' => '订单id',
  59. 'status' => '状态[-1:删除;0:禁用;1启用]',
  60. ];
  61. }
  62. public function getUser()
  63. {
  64. return $this->hasOne(User::ClassName(), ['id' => 'user_id']);
  65. }
  66. public function getActivity()
  67. {
  68. return $this->hasOne(PkActivity::ClassName(), ['id' => 'activity_id']);
  69. }
  70. /**
  71. * 保存数据
  72. * @Author: ltm
  73. * @DateTime: 2022/6/8 0015 9:26
  74. * @Copyright: copyright (c) 2021
  75. * @param $mall_id
  76. * @param array $params
  77. * @return Rebate|bool
  78. */
  79. public static function setData(array $params)
  80. {
  81. try {
  82. $mall_id = $params['mall_id'];
  83. if (!empty($params['id'])) {
  84. $model = self::findOne(['and', ['id' => $params['id'], 'mall_id' => $mall_id], ['<>', 'status', StatusEnum::ENABLED]]);
  85. if (empty($model)) throw new \Exception('活动不存在或已删除');
  86. } else {
  87. $model = new self();
  88. $model->loadDefaultValues();
  89. $model->mall_id = $mall_id;
  90. }
  91. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  92. return $model;
  93. } catch (\Exception $e) {
  94. self::setStaticError($e->getMessage());
  95. return false;
  96. }
  97. }
  98. }