cxgj/models/common/cms/CommonNoticeEditForm.php
2023-11-27 09:45:13 +08:00

96 lines
2.8 KiB
PHP
Raw Permalink 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年7月2日
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\models\common\cms;
use app\models\cms\Notice;
use app\models\cms\RichText;
use app\models\Model;
use yii\data\Pagination;
use app\components\SiteHelper;
class CommonNoticeEditForm extends Model
{
public $cx_mch_id;
public $title;
public $content;
public $status;
public $sort;
public $is_top;
public $is_index;
public $model;
public $store_id;
public $cover;
public function rules()
{
return [
[['title', 'content','cover'], 'trim'],
[['title', 'content','cover'], 'string'],
[['cx_mch_id', 'status', 'sort', 'is_top', 'is_index','store_id'], 'integer'],
[['is_top', 'is_index'], 'in', 'range' => [0, 1]],
[['status'], 'in', 'range' => [0, 1, 2]],
[['model',], 'safe'],
[['sort'], 'default', 'value' => 100],
[['title', 'content', 'cx_mch_id', 'status', 'is_top', 'model', 'is_index','store_id','cover'], 'required'],
];
}
public function attributeLabels()
{
return [
'cx_mch_id' => '平台商户ID',
'title' => '标题',
'content' => '内容',
'status' => '状态0=草稿1=已发布2=回收站',
'sort' => '排序默认100升序',
'is_top' => '是否置顶0=否1=是',
'store_id' => '门店ID',
'cover' => '封面图'
];
}
public function save()
{
if(!$this->validate()){
return $this->getModelError();
}
$t = \Yii::$app->db->beginTransaction();
if($this->model->isNewRecord){
$this->model->cx_mch_id = $this->cx_mch_id;
$this->model->is_delete = 0;
$this->model->rich_text_id = 0;
}
$res = RichText::saveRichText($this->model->rich_text_id, $this->title, $this->content, null, null, null, $this->cx_mch_id);
if($res['code'] != 0)
return $res;
$this->model->rich_text_id = $res['data']['rich_text_id'];
$this->model->status = $this->status;
$this->model->sort = $this->sort;
$this->model->is_top = $this->is_top;
$this->model->is_index = $this->is_index;
$this->model->store_id = $this->store_id;
$this->model->cover = $this->cover;
if($this->status == Notice::STATUS_PUBLISHED && empty($this->model->published_at)){
$this->model->published_at = time();
}
if(!$this->model->save()){
$t->rollBack();
return $this->getModelError($this->model);
}
$t->commit();
return $this->apiReturnSuccess("保存成功");
}
}