| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace addons\BusinessCard\common\models;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Exception;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_business_card_material".
- *
- * @property int $id 名片素材
- * @property int|null $mall_id 商城ID
- * @property int|null $user_id 用户ID
- * @property string|null $title 标题
- * @property string|null $intro 简介
- * @property string|null $ext_type 素材格式:pdf=PDF,video=视频,pic_text=图文,link=链接
- * @property int|null $cate_id 分类ID
- * @property int|null $is_show 是否展示
- * @property string|null $share_title 分享标题
- * @property string|null $share_desc 分享描述
- * @property string|null $cover_img 封面图片
- * @property string|null $material_link 素材链接,如link链接、video链接和pdf文件链接
- * @property string|null $material_cont 素材内容,例如图文
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- */
- class BusinessCardMaterials extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_business_card_material';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'cate_id', 'is_show', 'status', 'created_at', 'updated_at'], 'integer'],
- [['material_cont'], 'string'],
- [['title', 'share_title'], 'string', 'max' => 128],
- [['intro', 'share_desc', 'cover_img', 'material_link'], 'string', 'max' => 255],
- [['ext_type'], 'string', 'max' => 16],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'title' => 'Title',
- 'intro' => 'Intro',
- 'ext_type' => 'Ext Type',
- 'cate_id' => 'Cate ID',
- 'is_show' => 'Is Show',
- 'share_title' => 'Share Title',
- 'share_desc' => 'Share Desc',
- 'cover_img' => 'Cover Img',
- 'material_link' => 'Material Link',
- 'material_cont' => 'Material Cont',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- // 分类
- public function getCate()
- {
- return $this->hasOne(BusinessCardMaterialsCate::class, ['id' => 'cate_id'])->select('id,name');
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
- }
- /**
- * 数据设置
- */
- public static function setData(array $params)
- {
- try{
- if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID');
- if (isset($params['id']) && !empty($params['id'])) {
- $model = self::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if(empty($model)) throw new Exception('素材不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- }
- if (!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }catch(Exception $e){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|