cxgj/models/common/CommonCat1EditForm.php
2023-11-28 15:18:01 +08:00

120 lines
3.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @author Any
* @description KISS
* @date 2021年6月29日
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\models\common;
use app\models\Cat1;
use app\models\Model;
class CommonCat1EditForm extends Model
{
public $name;
public $type;
public $desc;
public $img_url;
public $parent_id;
public $sort;
public $cx_mch_id;
public $status;
public $is_hide;
public $big_img_url;
public $advert_pic;
public $advert_url;
public $advert_url_type;
public $advert_open_params;
public $model;
public function rules()
{
return [
[['name', 'desc', 'img_url', 'big_img_url', 'advert_pic', 'advert_url', 'advert_open_params'], 'trim'],
[['name', 'desc', 'img_url', 'big_img_url', 'advert_pic', 'advert_url', 'advert_open_params'], 'string'],
[['type', 'parent_id', 'sort', 'cx_mch_id', 'status', 'is_hide'], 'integer'],
[['sort'], 'default', 'value' => 100],
[['is_hide'], 'default', 'value' => 0],
[['status'], 'default', 'value' => 1],
[['model'], 'safe'],
[['type', 'parent_id', 'cx_mch_id', 'name', ], 'required'],
];
}
public function attributeLabels()
{
return [
'cx_mch_id' => '平台商户ID',
'type' => '类型',
'name' => '名称',
'desc' => '描述',
'img_url' => '图片',
'parent_id' => '父ID',
'sort' => '排序默认100升序',
'status' => '是否启用0=否1=是',
'is_hide' => '是否隐藏0=否1=是',
'big_img_url' => '大图',
'advert_pic' => '广告图',
'advert_url' => '广告链接',
'advert_url_type' => '广告链接类型',
'advert_open_params' => '广告链接打开参数',
];
}
public function save()
{
if(!$this->validate()){
return $this->getModelError();
}
if($this->model->isNewRecord){
$this->model->is_delete = 0;
$this->model->cx_mch_id = $this->cx_mch_id;
$this->model->type = $this->type;
$this->model->created_at = time();
}
if(!empty($this->parent_id)){
//父节点是否存在
$temp = Cat1::findOne([
'id' => $this->parent_id,
'type' => $this->type,
'cx_mch_id' => $this->cx_mch_id,
'is_delete' => 0
]);
if($temp == null){
return $this->apiReturnError('父节点不存在');
}
if(!$this->model->isNewRecord && $this->model->id == $temp->id){
return $this->apiReturnError('父节点不能为本身');
}
} else {
$this->parent_id = 0;
}
$this->model->name = $this->name;
$this->model->img_url = $this->img_url;
$this->model->desc = $this->desc == null ? $this->name : $this->desc;
$this->model->parent_id = $this->parent_id;
$this->model->sort = $this->sort;
$this->model->status = $this->status;
$this->model->is_hide = $this->is_hide;
$this->model->big_img_url = $this->big_img_url;
$this->model->advert_pic = $this->advert_pic;
$this->model->advert_url = $this->advert_url;
$this->model->advert_url_type = $this->advert_url_type;
$this->model->advert_open_params = $this->advert_open_params;
if(!$this->model->save()){
return $this->getModelError($this->model);
}
return $this->apiReturnSuccess('保存成功');
}
}