Recommen.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace addons\Recommen\common\models;
  3. use Yii;
  4. use yii\db\Exception;
  5. /**
  6. * This is the model class for table "{{%addons_recommen}}".
  7. *
  8. * @property int $id
  9. * @property int|null $mall_id 商城ID
  10. * @property string|null $name 活动名称
  11. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  12. * @property int|null $type 类型(1阶梯奖励,2条件奖励)
  13. * @property int|null $start_time 活动开始时间
  14. * @property int|null $end_time 活动结束时间
  15. * @property int|null $active_time 活动时间
  16. * @property int|null $arrive_num 到达人数
  17. * @property string|null $recommen_reward 推荐奖励
  18. * @property int|null $be_status 被推荐人奖励开启状态
  19. * @property string|null $be_recommen_reward 被推荐人奖励
  20. * @property int|null $num 参与人数
  21. * @property int|null $new_num 拉新人数
  22. * @property int|null $created_at 创建时间
  23. * @property int|null $updated_at 更新时间
  24. * @property int $settle_type 更新时间
  25. */
  26. class Recommen extends \common\models\base\BaseActiveRecord
  27. {
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%addons_recommen}}';
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['mall_id', 'status', 'type', 'start_time', 'end_time', 'active_time', 'arrive_num',
  42. 'be_status', 'num', 'new_num', 'created_at', 'updated_at', 'settle_type'], 'integer'],
  43. [['recommen_reward', 'be_recommen_reward'], 'string'],
  44. [['name'], 'string', 'max' => 255],
  45. ];
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function attributeLabels()
  51. {
  52. return [
  53. 'id' => 'ID',
  54. 'mall_id' => '商城ID',
  55. 'name' => '活动名称',
  56. 'status' => '状态[-1:删除;0:禁用;1启用]',
  57. 'type' => '类型(1阶梯奖励,2条件奖励)',
  58. 'start_time' => '活动开始时间',
  59. 'end_time' => '活动结束时间',
  60. 'active_time' => '活动时间',
  61. 'arrive_num' => '到达人数',
  62. 'recommen_reward' => '推荐奖励',
  63. 'be_status' => '被推荐人奖励开启状态',
  64. 'be_recommen_reward' => '被推荐人奖励',
  65. 'num' => '参与人数',
  66. 'new_num' => '拉新人数',
  67. 'created_at' => '创建时间',
  68. 'updated_at' => '更新时间',
  69. ];
  70. }
  71. /**
  72. * 保存数据
  73. * @Author: ltm
  74. * @DateTime: 2022/5/16 0015 9:26
  75. * @Copyright: copyright (c) 2021 广东七件事集团
  76. * @param $mall_id
  77. * @param array $params
  78. * @return Rebate|bool
  79. */
  80. public static function setData(array $params){
  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', -1]]);
  85. if(empty($model)) throw new \Exception('活动不存在或已删除');
  86. }else{
  87. $model = new self();
  88. $model->loadDefaultValues();
  89. $model->mall_id = $mall_id;
  90. }
  91. // 将内容转为json字符串
  92. if(!empty($params['reward_info'])) $params['recommen_reward'] = json_encode($params['reward_info']);
  93. if(!empty($params['be_reward_info'])) $params['be_recommen_reward'] = json_encode($params['be_reward_info']);
  94. if(!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
  95. return $model;
  96. }catch(\Exception $e){
  97. self::setStaticError($e->getMessage());
  98. return false;
  99. }
  100. }
  101. }