| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace addons\Recommen\common\models;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_recommen}}".
- *
- * @property int $id
- * @property int|null $mall_id 商城ID
- * @property string|null $name 活动名称
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $type 类型(1阶梯奖励,2条件奖励)
- * @property int|null $start_time 活动开始时间
- * @property int|null $end_time 活动结束时间
- * @property int|null $active_time 活动时间
- * @property int|null $arrive_num 到达人数
- * @property string|null $recommen_reward 推荐奖励
- * @property int|null $be_status 被推荐人奖励开启状态
- * @property string|null $be_recommen_reward 被推荐人奖励
- * @property int|null $num 参与人数
- * @property int|null $new_num 拉新人数
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- * @property int $settle_type 更新时间
- */
- class Recommen extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_recommen}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'status', 'type', 'start_time', 'end_time', 'active_time', 'arrive_num',
- 'be_status', 'num', 'new_num', 'created_at', 'updated_at', 'settle_type'], 'integer'],
- [['recommen_reward', 'be_recommen_reward'], 'string'],
- [['name'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'name' => '活动名称',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'type' => '类型(1阶梯奖励,2条件奖励)',
- 'start_time' => '活动开始时间',
- 'end_time' => '活动结束时间',
- 'active_time' => '活动时间',
- 'arrive_num' => '到达人数',
- 'recommen_reward' => '推荐奖励',
- 'be_status' => '被推荐人奖励开启状态',
- 'be_recommen_reward' => '被推荐人奖励',
- 'num' => '参与人数',
- 'new_num' => '拉新人数',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2022/5/16 0015 9:26
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @param array $params
- * @return Rebate|bool
- */
- public static function setData(array $params){
- try{
- $mall_id = $params['mall_id'];
- if(!empty($params['id'])){
- $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['<>','status', -1]]);
- if(empty($model)) throw new \Exception('活动不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- }
- // 将内容转为json字符串
- if(!empty($params['reward_info'])) $params['recommen_reward'] = json_encode($params['reward_info']);
- if(!empty($params['be_reward_info'])) $params['be_recommen_reward'] = json_encode($params['be_reward_info']);
- if(!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }catch(\Exception $e){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|