| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- namespace addons\Material\common\models;
- use addons\Material\common\enums\MaterialEnum;
- use common\enums\StatusEnum;
- use common\models\goods\Goods;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "qimall_addons_material".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property string $user_avatar_url 发布者头像
- * @property string $user_name 发布者
- * @property int $create_type 创建类型:1-用户;2-平台;
- * @property int|null $virtual_download_num 虚拟下载次数
- * @property int|null $download_num 实际下载次数
- * @property int $download_type 上传类型:1-图文;2-短视频
- * @property int $cate_id 素材分类id
- * @property int $second_cate_id 素材二级分类id
- * @property string $describe 素材 文案
- * @property int $goods_id 关联商品
- * @property string|null $pic_url 素材集合
- * @property int|null $sort 排序(越大排越前)
- * @property string|null $remark 备注
- * @property String|null $thumb_url 封面
- * @property String|null $video_url 视频集合
- * @property int|null $check_status 审核状态:0:未审核 1:审核通过 2:审核不通过
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- * @property int|null $check_at 审核时间
- */
- class Material extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_material}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'download_type', 'cate_id', 'second_cate_id', 'describe'], 'required'],
- [['mall_id','goods_id', 'user_id', 'create_type', 'virtual_download_num', 'download_num', 'download_type', 'cate_id', 'sort', 'check_status', 'status', 'created_at', 'updated_at', 'check_at'], 'integer'],
- [['describe', 'pic_url','thumb_url','video_url'], 'string'],
- [['user_avatar_url', 'remark'], 'string', 'max' => 255],
- [['user_name'], 'string', 'max' => 20],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户ID',
- 'user_avatar_url' => '发布者头像',
- 'user_name' => '发布者',
- 'create_type' => '创建类型:1-用户;2-平台;',
- 'virtual_download_num' => '虚拟下载次数',
- 'download_num' => '实际下载次数',
- 'download_type' => '上传类型:1-图文;2-短视频',
- 'cate_id' => '素材分类id',
- 'second_cate_id' => '素材二级分类id',
- 'describe' => ' 素材 文案',
- 'goods_id' => '关联商品',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'pic_url' => '图片集合',
- 'thumb_url' => '视频封面',
- 'video_url' => '视频集合',
- 'sort' => '排序(越大排越前)',
- 'remark' => '备注',
- 'check_status' => '审核状态:0:未审核 1:审核通过 2:审核不通过',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- 'check_at' => '审核时间',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
- }
- //管理商品
- public function getGoods()
- {
- return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select('id,goods_name,price,cover_pic,sales_num,virtual_sales');
- }
- /**
- * 获取分类
- * @Author: ltm
- * @DateTime: 2021/12/13 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AddonsMaterial|bool
- */
- public function getCate(){
- return $this->hasOne(MaterialCate::class, ['id' => 'cate_id'])->andWhere(['<>','status',StatusEnum::DELETE]);
- }
- public function getSecondCate(){
- return $this->hasOne(MaterialCate::class, ['id' => 'second_cate_id'])->andWhere(['<>','status',StatusEnum::DELETE]);
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2021/12/13 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AddonsMaterial|bool
- */
- public static function setData(array $params){
- try{
- if (!empty($params['id'])) {
- $model = self::findOne(['and',['id'=>$params['id'],'mall_id'=>$params['mall_id']],['<>','status',StatusEnum::DELETE]]);
- 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::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|