PkInviteLog.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace addons\Pk\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\user\User;
  5. use Yii;
  6. /**
  7. * This is the model class for table "%addons_pk_invite_log".
  8. *
  9. * @property int $id
  10. * @property int $activity_id 活动ID
  11. * @property int $share_user_id 分享者用户ID
  12. * @property int $mall_id 商城ID
  13. * @property int $team_id 战队ID
  14. * @property int $invitee_id 被邀请者ID
  15. * @property int $activity_type 类型【1 个人PK 2战队PK】
  16. * @property string $year 年
  17. * @property string $month 月
  18. * @property string $date 日
  19. * @property int $status 状态[-1:删除;0:禁用;1启用]
  20. * @property int $created_at 创建时间
  21. * @property int $updated_at 更新时间
  22. */
  23. class PkInviteLog extends \common\models\base\BaseActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%addons_pk_invite_log}}';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['activity_id', 'share_user_id', 'mall_id', 'team_id', 'invitee_id', 'activity_type', 'status', 'created_at', 'updated_at'], 'integer'],
  39. [['year', 'month', 'date'], 'required'],
  40. [['year'], 'string', 'max' => 4],
  41. [['month', 'date'], 'string', 'max' => 2],
  42. ];
  43. }
  44. public function getUser()
  45. {
  46. return $this->hasOne(User::class, ['id' => 'invitee_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function attributeLabels()
  52. {
  53. return [
  54. 'id' => 'ID',
  55. 'activity_id' => 'Activity ID',
  56. 'share_user_id' => 'Share User ID',
  57. 'mall_id' => 'Mall ID',
  58. 'team_id' => 'Team ID',
  59. 'invitee_id' => 'Invitee ID',
  60. 'activity_type' => 'Activity Type',
  61. 'year' => 'Year',
  62. 'month' => 'Month',
  63. 'date' => 'Date',
  64. 'status' => 'Status',
  65. 'created_at' => 'Created At',
  66. 'updated_at' => 'Updated At',
  67. ];
  68. }
  69. /**
  70. * 保存数据
  71. * @Author: ltm
  72. * @DateTime: 2022/6/8 0015 9:26
  73. * @Copyright: copyright (c) 2021
  74. * @param $mall_id
  75. * @param array $params
  76. * @return Rebate|bool
  77. */
  78. public static function setData(array $params){
  79. try{
  80. $mall_id = $params['mall_id'];
  81. if(!empty($params['id'])){
  82. $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['<>','status', StatusEnum::ENABLED]]);
  83. if(empty($model)) throw new \Exception('活动不存在或已删除');
  84. }else{
  85. $model = new self();
  86. $model->loadDefaultValues();
  87. $model->mall_id = $mall_id;
  88. }
  89. if(!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
  90. return $model;
  91. }catch(\Exception $e){ var_dump($e->getMessage());
  92. self::setStaticError($e->getMessage());
  93. return false;
  94. }
  95. }
  96. }