UserCenterForm.php 6.0 KB

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