UserCenterForm.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models;
  8. use app\models\Option;
  9. use yii\base\Model;
  10. class UserCenterForm extends Model
  11. {
  12. public $store_id;
  13. public $_platform;
  14. public $default_menu_list;
  15. public $data;
  16. /**
  17. * Undocumented function
  18. *
  19. * @Author LGL 24963@qq.com
  20. * @DateTime 2021-02-22
  21. * @desc: 保存数据
  22. * @return void
  23. */
  24. public function saveData()
  25. {
  26. if (!$this->validate()) {
  27. // 验证失败:$errors 是一个包含错误信息的数组
  28. return [
  29. 'code' => 1,
  30. "msg" => $this->getErrorSummary(false)[0]
  31. ];
  32. }
  33. self::set('user_center_data', json_decode($this->data, true), $this->store_id, 'store');
  34. // self::set('user_center_data', $this->data, $this->store_id, 'store');
  35. return [
  36. 'code' => 0,
  37. 'msg' => '保存成功',
  38. 'data' => $this->data,
  39. ];
  40. }
  41. /**
  42. * Undocumented function
  43. *
  44. * @Author LGL 24963@qq.com
  45. * @DateTime 2021-02-22
  46. * @desc: 获取数据
  47. */
  48. public function getData()
  49. {
  50. $default_data = $this->getDefaultData();
  51. return [
  52. 'code' => 0,
  53. 'data' => $default_data,
  54. ];
  55. }
  56. /**
  57. * Undocumented function
  58. *
  59. * @Author LGL 24963@qq.com
  60. * @DateTime 2021-02-22
  61. * @desc: 已更改数据的替换
  62. * @param array $list
  63. * @param array $default_list
  64. * @return void
  65. */
  66. public function checkData($list = array(), $default_list = array())
  67. {
  68. $new_list = [];
  69. foreach ($default_list as $index => $value) {
  70. if (isset($list[$index])) {
  71. if (is_array($value) && $index != 'menus') {
  72. $new_list[$index] = $this->checkData($list[$index], $value);
  73. } else {
  74. $new_list[$index] = $list[$index];
  75. }
  76. } else {
  77. $new_list[$index] = $value;
  78. }
  79. }
  80. return $new_list;
  81. }
  82. /**
  83. * @param $name string Name
  84. * @param $value mixed Value
  85. */
  86. public static function set($name, $value, $store_id = 0, $group = '')
  87. {
  88. if (empty($name)) {
  89. return false;
  90. }
  91. $model = Option::findOne([
  92. 'name' => $name,
  93. 'store_id' => $store_id,
  94. 'group' => $group,
  95. ]);
  96. if (!$model) {
  97. $model = new Option();
  98. $model->name = $name;
  99. $model->store_id = $store_id;
  100. $model->group = $group;
  101. }
  102. $model->value = json_encode($value);
  103. return $model->save();
  104. }
  105. /**
  106. * @param $name string Name
  107. */
  108. public static function get($name, $store_id = 0, $group = '', $default = null)
  109. {
  110. $model = Option::findOne([
  111. 'name' => $name,
  112. 'store_id' => $store_id,
  113. 'group' => $group,
  114. ]);
  115. if (!$model) {
  116. return $default;
  117. }
  118. return json_decode($model->value, true);
  119. }
  120. /**
  121. * menus sign 用于标识属于某个模块的功能及根据权限显示
  122. * @return array
  123. */
  124. public function getDefaultData()
  125. {
  126. $data = [
  127. 'orders' => [
  128. 'status_0' => [
  129. 'text' => '待付款',
  130. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-0.png',
  131. ],
  132. 'status_1' => [
  133. 'text' => '待发货',
  134. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-1.png',
  135. ],
  136. 'status_2' => [
  137. 'text' => '待收货',
  138. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-2.png',
  139. ],
  140. 'status_3' => [
  141. 'text' => '已完成',
  142. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-3.png',
  143. ],
  144. 'status_4' => [
  145. 'text' => '售后',
  146. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1' . '/statics/images/user-center/icon-order-4.png',
  147. ],
  148. ]
  149. ];
  150. return $data;
  151. }
  152. }