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; } } }