| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace addons\Xhs\common\models;
- use Yii;
- use yii\db\Exception;
- use common\enums\StatusEnum;
- /**
- * This is the model class for table "qimall_addons_xhs_cate".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $sort 序号
- * @property string $name 分类名称
- * @property int $status -1是删除,0是禁用,1是启用
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class AddonsXhsCate extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_xhs_cate}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'sort', 'status', 'created_at', 'updated_at'], 'integer'],
- [['name'], 'string', 'max' => 150],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'sort' => '序号',
- 'name' => '分类名称',
- 'status' => '-1是删除,0是禁用,1是启用',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2021/01/04 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AddonsMaterial|bool
- */
- public static function setData(array $params){
- try{
- $where[] = ['mall_id' => $params['mall_id']];
- if($params['name']) $where[] = ['name' => $params['name']];
- $find_data = self::getOne($where);
- if($find_data&&!$params['id']){
- self::$static_error = "分类名称已经存在";
- return false;
- }
- if($params['id']) {
- $cont = ['id' => $params['id']];
- $model = self::findOne($cont);
- }
- //判断分类是否已经被使用
- if($params['status']=='-1'){
- $findMaterial = AddonsXhsContent::getOne([['cate_id' => $params['id']],['status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]]);
- if($findMaterial){
- self::$static_error = "分类名称已经使用,请先移除该分类的下素材";
- return false;
- }
- }
- if(empty($model)) {
- $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;
- }
- }
- }
|