| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- /*
- * @Descripttion:
- * @copyright: Copyright (c) 2021 广东七件事集团
- * @Author: lun
- * @Date: 2021-12-31 20:52:51
- */
- namespace app\plugins\rebate\models;
- use app\models\BaseActiveRecord;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "qimall_addons_rebate_ad".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property string $title 标题
- * @property string $cover 广告图片
- * @property string|null $link 跳转链接
- * @property int|null $sort 排序,越大排越前
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class RebateAd extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_rebate_ad';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'sort', 'status', 'created_at', 'updated_at'], 'integer'],
- [['title'], 'string', 'max' => 20],
- [['cover', 'link'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'title' => 'Title',
- 'cover' => 'Cover',
- 'link' => 'Link',
- 'sort' => 'Sort',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存数据
- *
- * @param [type] $mall_id
- * @param array $params
- * @return void
- */
- public static function setData($mall_id, array $params){
- try{
- 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字符串
- !empty($params['link']) && $params['link'] = Json::encode($params['link']);
- if(!$model->load($params,'') || !$model->save()) throw new \yii\db\Exception($model->getErrorMessage());
- return $model;
- }catch(\Exception $e){
- self::$error = $e->getMessage();
- return false;
- }
- }
- }
|