| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\food\models\form;
- use app\models\Banner;
- use yii\base\Model;
- use yii\data\Pagination;
- class BannerForm extends Model
- {
- /**
- * @var $banner Banner
- */
- public $banner;
- public $store_id;
- public $pic_url;
- public $title;
- public $page_url;
- public $sort;
- public $open_type;
- public $type;
- /**
- * @return array
- * 验证
- */
- public function rules()
- {
- return [
- [['store_id', 'pic_url',], 'required'],
- [['store_id', 'type'], 'integer'],
- [['pic_url', 'page_url','open_type'], 'string'],
- [['title'], 'string', 'max' => 255],
- [['title'], 'default', 'value' => '暂无标题'],
- [['sort'], 'default', 'value' => 0],
- [['sort'], 'integer', 'min' => 0, 'max' => 999999]
- ];
- }
- /**
- * @return array
- */
- public function attributeLabels()
- {
- return [
- 'store_id' => '商城id',
- 'pic_url' => '图片',
- 'title' => '标题',
- 'page_url' => '页面路径',
- 'sort' => '排序',
- 'is_delete' => '是否删除:0=未删除,1=已删除',
- ];
- }
- /**
- * 获取列表
- * @return array
- */
- public function getList($store_id)
- {
- $query = Banner::find()->andWhere(['is_delete' => 0, 'store_id' => $store_id, 'type' => Banner::TYPE_FOOD])->select('*')->orderBy('sort ASC');
- $list = pagination_make($query);
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ],
- ];
- }
- public function save()
- {
- if ($this->validate()) {
- $banner = $this->banner;
- if ($banner->isNewRecord) {
- $banner->is_delete = 0;
- $banner->created_at = time();
- }
- $banner->type = $this->type;
- $banner->attributes = $this->attributes;
- return $banner->saveBanner();
- } else {
- return $this->getErrorSummary(false)[0];
- }
- }
- }
|