| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace addons\ShareRedpack\common\models;
- use common\enums\StatusEnum;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "qimall_addons_share_redpack".
- *
- * @property int $id
- * @property int $mall_id
- * @property string $name 海报名称
- * @property string|null $key_word 关键词
- * @property int|null $look_num 浏览次数
- * @property int $scan_code_num 扫码次数
- * @property string $poster_content 海报内容
- * @property string $status 状态【1启用 0禁用 -1删除】
- * @property string|null $share_url 分享图片
- * @property int $created_at
- * @property int $updated_at
- */
- class ShareRedpack extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_share_redpack';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'name', 'poster_content'], 'required'],
- [['mall_id', 'look_num', 'scan_code_num', 'created_at', 'updated_at'], 'integer'],
- [['poster_content'], 'string'],
- [['name', 'key_word', 'status', 'share_url'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'name' => 'Name',
- 'key_word' => 'Key Word',
- 'look_num' => 'Look Num',
- 'scan_code_num' => 'Scan Code Num',
- 'poster_content' => 'Poster Content',
- 'status' => 'Status',
- 'share_url' => 'Share Url',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存数据
- * @Author lun
- * @DateTime 2021-09-16 14:16:24
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param array $params
- * @return object|boolean
- */
- 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',StatusEnum::DELETE]]);
- if(empty($model)) throw new \Exception('海报不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- }
- // 将内容转为json字符串
- $params['poster_content'] = Json::encode($params['poster_content']);
- if(!$model->load($params,'') || !$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|