| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\models\common;
- use app\models\Option;
- use yii\base\Model;
- use yii\helpers\Json;
- class CommonOverRun extends Model
- {
- public $max_picture;
- public $max_diy;
- public $over_picture;
- public $over_diy;
- public $max_file;
- public $over_file;
- public function rules()
- {
- return [
- [['max_file'], 'integer', 'min' => 0],
- [['over_diy'], 'integer', 'min' => 0],
- [['over_file'], 'integer', 'min' => 0],
- [['max_picture'], 'number', 'min' => 0],
- [['over_picture', 'over_diy'], 'default', 'value' => 0],
- [['max_picture'], 'default', 'value' => 1],
- [['max_diy'], 'default', 'value' => 20],
- ];
- }
- /**
- * @return array
- * @throws \yii\db\Exception
- */
- public function save()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0]
- ];
- }
- if (!isset($this->max_file)) {
- $this->max_file = $this->max_picture;
- }
- Option::set('overrun', Json::encode([
- 'max_picture' => $this->max_picture,
- 'max_diy' => $this->max_diy,
- 'max_file' => $this->max_file,
- 'over_picture' => $this->over_picture,
- 'over_diy' => $this->over_diy,
- 'over_file' => $this->over_file,
- ]), get_store_id(), 'store');
- return [
- 'code' => 0,
- 'msg' => '保存成功'
- ];
- }
- public function search()
- {
- $data = Option::get('overrun', get_store_id(), 'store')['value'];
- $data = Json::decode($data);
- if (!$data) {
- $data = [
- 'max_picture' => 1,
- 'max_diy' => 20,
- 'max_file' => 20,
- 'over_picture' => 0,
- 'over_diy' => 0,
- 'over_file' => 0,
- ];
- }
- if (!isset($data['max_file'])) {
- $data['max_file'] = $data['max_picture'];
- }
- if (!isset($data['over_file'])) {
- $data['over_file'] = $data['over_picture'];
- }
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => $data
- ];
- }
- }
|