Index.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 会员管理首页
  7. */
  8. namespace app\system\controller\passport;
  9. use app\common\event\Passport;
  10. use app\common\model\SystemMemberMiniapp;
  11. use app\common\model\SystemMember;
  12. use app\common\model\SystemMiniapp;
  13. use app\system\event\AppConfig;
  14. use think\facade\Request;
  15. class Index extends Common{
  16. /**
  17. * 后台主框架
  18. */
  19. public function index(){
  20. $condition = [];
  21. $condition['is_lock'] = 0;
  22. if($this->user->parent_id){
  23. $condition['id'] = $this->user->bind_member_miniapp_id;
  24. }else{
  25. $condition['member_id'] = $this->user->id;
  26. }
  27. $lists = SystemMemberMiniapp::where($condition)->field('id,miniapp_id,appname,head_img,miniapp_head_img,mp_head_img,is_lock')->order('id desc')->select();
  28. $apps = [];
  29. foreach ($lists as $key => $value) {
  30. $apps[$key]['id'] = $value->id;
  31. $apps[$key]['appname'] = $value->appname;
  32. $apps[$key]['is_lock'] = $value->is_lock;
  33. if(empty($value->head_img)){
  34. switch ($value->miniapp->types) {
  35. case 'mp':
  36. $head_img = $value->mp_head_img;
  37. break;
  38. case 'program':
  39. $head_img = $value->miniapp_head_img;
  40. break;
  41. case 'app':
  42. $head_img = $value->head_img;
  43. break;
  44. default:
  45. $head_img = empty($value->mp_head_img) ? $value->mp_head_img : $value->miniapp_head_img;
  46. break;
  47. }
  48. }else{
  49. $head_img = $value->head_img;;
  50. }
  51. $apps[$key]['logo'] = empty($head_img) ? "/static/{$value->miniapp->miniapp_dir}/logo.png" : $head_img;
  52. }
  53. $view['apps'] = $apps;
  54. if ($this->member_miniapp_id){
  55. $view['appname'] = $this->member_miniapp->appname;
  56. $view['welcome'] = url($this->member_miniapp->miniapp->miniapp_dir.'/manage.index/index');
  57. }else{
  58. $view['appname'] = '应用中心';
  59. $view['welcome'] = url('system/passport.appshop/index');
  60. }
  61. //判断帐号是否设置手机号
  62. return view('passport/index/index')->assign($view);
  63. }
  64. /**
  65. * 管理菜单
  66. * @return json
  67. */
  68. public function appmenu(){
  69. $app_menu = [];
  70. $miniapp_dir = 'system';
  71. if ($this->member_miniapp_id) {
  72. if($this->member_miniapp->is_lock == 0){
  73. $miniapp = SystemMiniapp::field('miniapp_dir,types,is_wechat_pay,is_alipay_pay,is_openapp')->where(['id' => $this->member_miniapp->miniapp_id])->find();
  74. if($miniapp){
  75. $miniapp_dir = $miniapp->miniapp_dir;
  76. if($this->user->parent_id == 0 && $this->user->lock_config == 0){
  77. $app_menu['name'] = '应用管理';
  78. $app_menu['icon'] = 'yingyongyuanma';
  79. if(!empty($this->member_miniapp->mp_appid) && !empty($this->member_miniapp->miniapp_appid)){
  80. if ($miniapp->types == 'mp' || $miniapp->types == 'mp_program' || $miniapp->types == 'mp_program_app'){
  81. $app_menu['nav'][] = ['name' => '自定义菜单','url' => url('system/passport.official/index'),'icon' => 'news_icon'];
  82. }
  83. $app_menu['nav'][] = ['name' => '自动回复','url' => url('system/passport.keyword/index'),'icon' => 'zhuanzhang'];
  84. }
  85. $app_menu['nav'][] = ['name' => '关于应用','url' => url('system/passport.setting/index'),'icon' => 'information'];
  86. }
  87. }
  88. }
  89. }
  90. $menu = AppConfig::menu($miniapp_dir);
  91. if(!empty($app_menu)){
  92. array_push($menu,$app_menu);
  93. }
  94. return json($menu);
  95. }
  96. /**
  97. * 修改密码
  98. * @access public
  99. */
  100. public function password(){
  101. if($this->user->lock_config){
  102. $this->error('你账户锁定配置权限');
  103. }
  104. if(request()->isAjax()){
  105. $data = [
  106. 'id' => $this->user->id,
  107. 'login_password' => Request::param('safe_password'),
  108. 'password' => Request::param('password/s'),
  109. 'password_confirm' => Request::param('repassword/s'),
  110. ];
  111. $validate = $this->validate($data,'Member.password');
  112. if(true !== $validate){
  113. return enjson(0,$validate);
  114. }
  115. //验证密码
  116. if(!password_verify(md5($data['login_password']),$this->user->safe_password)) {
  117. return enjson(0,"安全密码错误");
  118. }
  119. $result = SystemMember::upDatePasspowrd($this->user->id,$data['password']);
  120. if($result){
  121. return enjson(200,"修改成功",['url' => url('system/passport.login/logout')]);
  122. }
  123. return enjson(0);
  124. }else{
  125. return view();
  126. }
  127. }
  128. /**
  129. * 切换当前管理的应用
  130. * @param int 当前应用APP的ID
  131. * */
  132. public function changeApp(int $id){
  133. $condition = [];
  134. $condition['is_lock'] = 0;
  135. if($this->user->parent_id){
  136. $condition['id'] = $this->user->bind_member_miniapp_id;
  137. }else{
  138. $condition['id'] = $id;
  139. $condition['member_id'] = $this->user->id;
  140. }
  141. $rel = SystemMemberMiniapp::where($condition)->find();
  142. if(empty($rel)){
  143. return json(['code'=>0,'msg'=>'操作失败']);
  144. }else{
  145. if($rel['is_lock'] == 1){
  146. return json(['code'=>0,'msg'=>'应用已被锁定,禁止管理']);
  147. }
  148. $param = [
  149. 'member_id' => $rel['member_id'],
  150. 'miniapp_id' => $rel['miniapp_id'],
  151. 'member_miniapp_id' => $rel['id'],
  152. ];
  153. Passport::setMiniapp($param);
  154. return json(['code'=>200,'msg'=>'操作成功','url'=>url('system/passport.index/index')]);
  155. }
  156. }
  157. /**
  158. * 用户已经开通的应用(弹窗选项)
  159. * @access public
  160. */
  161. public function selectMemberMiniapp(){
  162. if($this->user->parent_id){
  163. $this->error('你不是创始人,禁止访问.');
  164. }
  165. $view['input'] = Request::param('input/s');
  166. $apps = SystemMemberMiniapp::where(['member_id'=>$this->user->id])->order('id desc')->select();
  167. foreach ($apps as $key => $value) {
  168. $apps[$key] = $value;
  169. switch ($value->miniapp->types) {
  170. case 'mp':
  171. $head_img = $value->mp_head_img;
  172. break;
  173. case 'program':
  174. $head_img = $value->miniapp_head_img;
  175. break;
  176. case 'app':
  177. $head_img = $value->head_img;
  178. break;
  179. default:
  180. $head_img = empty($value->mp_head_img) ? $value->miniapp_head_img : $value->mp_head_img;
  181. break;
  182. }
  183. $apps[$key]['logo'] = empty($head_img) ? "/static/{$value->miniapp->miniapp_dir}/logo.png" : $head_img;
  184. }
  185. $view['list'] = $apps;
  186. return view()->assign($view);
  187. }
  188. }