| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- 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;
- public $md_id;
- /**
- * @return array
- * 验证
- */
- public function rules()
- {
- return [
- [['store_id', 'pic_url',], 'required'],
- [['store_id', 'type', 'md_id'], '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, $mch_id = 0)
- {
- $query = Banner::find()->andWhere(['is_delete' => 0, 'store_id' => $store_id, 'mch_id' => intval($mch_id), 'type' => Banner::TYPE_FOOD]);
- if ($this->md_id) {
- $query->andWhere(['md_id' => $this->md_id]);
- }
- $query->select('*')->orderBy('sort DESC');
- $list = pagination_make($query);
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ],
- ];
- }
- public function save($params = [])
- {
- if ($this->validate()) {
- $banner = $this->banner;
- if ($banner->isNewRecord) {
- $banner->is_delete = 0;
- $banner->created_at = time();
- if($params['mch']) {
- $banner->mch_id = $params['mch_id'];
- }
- }
- $banner->md_id = $this->md_id;
- $banner->type = $this->type;
- $banner->attributes = $this->attributes;
- return $banner->saveBanner();
- } else {
- return $this->getErrorSummary(false)[0];
- }
- }
- }
|