| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\models\Option;
- use yii\base\Model;
- class UserCenterForm extends Model
- {
- public $store_id;
- public $_platform;
- public $default_menu_list;
- public $data;
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-02-22
- * @desc: 保存数据
- * @return void
- */
- public function saveData()
- {
- if (!$this->validate()) {
- // 验证失败:$errors 是一个包含错误信息的数组
- return [
- 'code' => 1,
- "msg" => $this->getErrorSummary(false)[0]
- ];
- }
- self::set('user_center_data', json_decode($this->data, true), $this->store_id, 'store');
- // self::set('user_center_data', $this->data, $this->store_id, 'store');
- return [
- 'code' => 0,
- 'msg' => '保存成功',
- 'data' => $this->data,
- ];
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-02-22
- * @desc: 获取数据
- */
- public function getData()
- {
- $default_data = $this->getDefaultData();
- return [
- 'code' => 0,
- 'data' => $default_data,
- ];
- }
- /**
- * Undocumented function
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-02-22
- * @desc: 已更改数据的替换
- * @param array $list
- * @param array $default_list
- * @return void
- */
- public function checkData($list = array(), $default_list = array())
- {
- $new_list = [];
- foreach ($default_list as $index => $value) {
- if (isset($list[$index])) {
- if (is_array($value) && $index != 'menus') {
- $new_list[$index] = $this->checkData($list[$index], $value);
- } else {
- $new_list[$index] = $list[$index];
- }
- } else {
- $new_list[$index] = $value;
- }
- }
- return $new_list;
- }
-
- /**
- * @param $name string Name
- * @param $value mixed Value
- */
- public static function set($name, $value, $store_id = 0, $group = '')
- {
- if (empty($name)) {
- return false;
- }
- $model = Option::findOne([
- 'name' => $name,
- 'store_id' => $store_id,
- 'group' => $group,
- ]);
- if (!$model) {
- $model = new Option();
- $model->name = $name;
- $model->store_id = $store_id;
- $model->group = $group;
- }
- $model->value = json_encode($value);
- return $model->save();
- }
- /**
- * @param $name string Name
- */
- public static function get($name, $store_id = 0, $group = '', $default = null)
- {
- $model = Option::findOne([
- 'name' => $name,
- 'store_id' => $store_id,
- 'group' => $group,
- ]);
- if (!$model) {
- return $default;
- }
- return json_decode($model->value, true);
- }
- /**
- * menus sign 用于标识属于某个模块的功能及根据权限显示
- * @return array
- */
- public function getDefaultData()
- {
- $data = [
- 'orders' => [
- 'status_0' => [
- 'text' => '待付款',
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-0.png',
- ],
- 'status_1' => [
- 'text' => '待发货',
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-1.png',
- ],
- 'status_2' => [
- 'text' => '待收货',
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-2.png',
- ],
- 'status_3' => [
- 'text' => '已完成',
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-3.png',
- ],
- 'status_4' => [
- 'text' => '售后',
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-4.png',
- ],
- ]
- ];
- return $data;
- }
- }
|