| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace common\models\wechat;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%wechat_material}}".
- *
- *
- * @property int $id
- * @property int $mall_id
- * @property string $wechat_app_id 公众号appid
- * @property string $media_id media_id
- * @property string|null $url url
- * @property string $name
- * @property string|null $media_type 类型:image video voice text
- * @property string|null $material_desc 描述
- * @property int $status 状态【1启用 0禁用 -1删除】
- * @property int $created_at
- * @property int $updated_at
- */
- class Material extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%wechat_material}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'wechat_app_id', 'media_id', 'name'], 'required'],
- [['mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['wechat_app_id'], 'string', 'max' => 64],
- [['media_id'], 'string', 'max' => 128],
- [['url', 'material_desc'], 'string', 'max' => 255],
- [['name'], 'string', 'max' => 45],
- [['media_type'], 'string', 'max' => 12],
- [['material_desc'], 'safe'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'wechat_app_id' => '公众号appid',
- 'media_id' => 'media_id',
- 'url' => 'url',
- 'name' => 'Name',
- 'media_type' => '类型:image video voice text',
- 'material_desc' => '描述',
- 'status' => '状态【1启用 0禁用 -1删除】',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存数据
- * @Author lun
- * @DateTime 2021-09-17 14:16:24
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param array $params
- * @return object|boolean
- */
- public static function setData(int $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;
- }
- if(!$model->load($params,'') || !$model->save()){
- throw new \Exception($model->getErrorMessage());
- }
- return $model;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|