Member.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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\model\SystemMember;
  10. use app\common\model\SystemMemberMiniapp;
  11. use app\common\model\SystemMemberBank;
  12. use app\system\event\AppConfig;
  13. use app\common\facade\Alisms;
  14. class Member extends Common{
  15. public function initialize() {
  16. parent::initialize();
  17. if($this->user->parent_id){
  18. $this->error('仅创始人有权限访问');
  19. }
  20. if($this->member_miniapp_id){
  21. $pathMaps[] = ['name'=>$this->member_miniapp->appname,'url'=>'javascript:;'];
  22. }
  23. $pathMaps[] = ['name'=>'帐号管理','url'=>'javascript:;'];
  24. $this->assign('pathMaps',$pathMaps);
  25. }
  26. /**
  27. * 我的帐号信息
  28. */
  29. public function index(){
  30. $bank = SystemMemberBank::where(['member_id' => $this->user->id])->find();
  31. if(empty($bank)){
  32. $bank['money'] = money(0);
  33. $bank['lack_money'] = money(0);
  34. }
  35. $view['bank'] = $bank;
  36. return view()->assign($view);
  37. }
  38. /**
  39. * 修改登录手机号
  40. */
  41. public function phone(){
  42. if(request()->isPost()){
  43. $data = [
  44. 'id' => $this->user->id,
  45. 'phone_id' => $this->request->param('phone_id/s'),
  46. 'sms_code' => $this->request->param('sms_code/s'),
  47. 'login_password' => $this->request->param('safepassword/s'),
  48. ];
  49. $validate = $this->validate($data,'Member.updatephone');
  50. if(true !== $validate){
  51. return enjson(0,$validate);
  52. }
  53. //判断验证码
  54. if(!Alisms::isSms($data['phone_id'],$data['sms_code'])){
  55. return enjson(0,'验证码错误');
  56. }
  57. //验证安全密码
  58. if(!password_verify(md5($data['login_password']),$this->user->safe_password)) {
  59. return enjson(0,'安全密码错误');
  60. }
  61. //验证码通过
  62. $result = SystemMember::editPhone($data);
  63. if($result){
  64. return enjson(200,'修改成功',['url' => url('system/passport.member/index')]);
  65. }else{
  66. return enjson(0,'修改失败');
  67. }
  68. }else{
  69. return view();
  70. }
  71. }
  72. /**
  73. * 修改安全密码
  74. */
  75. public function safepassword(){
  76. if($this->user->lock_config){
  77. $this->error('你账户锁定配置权限');
  78. }
  79. if(request()->isPost()){
  80. $data = [
  81. 'id' => $this->user->id,
  82. 'login_password' => $this->request->param('login_password/s'),
  83. 'safepassword' => $this->request->param('safepassword/s'),
  84. 'safepassword_confirm' => $this->request->param('safepassword_confirm/s'),
  85. ];
  86. $validate = $this->validate($data,'Member.safepassword');
  87. if(true !== $validate){
  88. return enjson(0,$validate);
  89. }
  90. //验证密码
  91. if(!password_verify(md5($data['login_password']),$this->user->safe_password)) {
  92. return enjson(0,'安全密码错误');
  93. }
  94. //验证码通过
  95. $result = SystemMember::updateSafePasspord($this->user->id,$data['safepassword']);
  96. if($result){
  97. return enjson(200,'修改成功',['url' => url('system/passport.member/index')]);
  98. }else{
  99. return enjson(0,'修改失败');
  100. }
  101. }else{
  102. return view();
  103. }
  104. }
  105. /**
  106. * 员工管理
  107. */
  108. public function staff(){
  109. $list = SystemMember::where(['parent_id' => $this->user->id,'bind_member_miniapp_id' => $this->member_miniapp_id])->order('id desc')->paginate(20);
  110. foreach ($list as $key => $value) {
  111. $list[$key] = $value;
  112. switch ($value->miniapp->miniapp->types) {
  113. case 'mp':
  114. $head_img = $value->miniapp->mp_head_img;
  115. break;
  116. case 'program':
  117. $head_img = $value->miniapp->miniapp_head_img;
  118. break;
  119. case 'app':
  120. $head_img = $value->miniapp->head_img;
  121. break;
  122. default:
  123. $head_img = empty($value->miniapp->mp_head_img) ? $value->miniapp->miniapp_head_img : $value->miniapp->mp_head_img;
  124. break;
  125. }
  126. $list[$key]['logo'] = empty($head_img) ? "/static/{$value->miniapp->miniapp->miniapp_dir}/logo.png" : $head_img;
  127. $list[$key]['auth_group'] = AppConfig::auth($value->miniapp->miniapp->miniapp_dir);
  128. }
  129. $view['list'] = $list;
  130. return view()->assign($view);
  131. }
  132. /**
  133. * 添加员工
  134. */
  135. public function staffAdd(){
  136. if(request()->isPost()){
  137. $data = [
  138. 'user_id' => $this->user->id,
  139. 'miniapp_id' => $this->member_miniapp_id,
  140. 'username' => $this->request->param('username/s'),
  141. 'phone_id' => $this->request->param('phone_id/d'),
  142. 'auth' => $this->request->param('auth/d',0),
  143. 'login_password' => $this->request->param('login_password/s'),
  144. ];
  145. $validate = $this->validate($data,'Member.bindapp');
  146. if(true !== $validate){
  147. return json(['code'=>0,'msg'=>$validate]);
  148. }
  149. //判断手机号是否重复
  150. $info = SystemMember::where(['phone_id' => $data['phone_id']])->find();
  151. if(!empty($info)){
  152. return json(['code'=>0,'msg'=>'手机账号已存在']);
  153. }
  154. $result = SystemMember::bindEdit($data);
  155. if($result){
  156. return json(['code'=>200,'msg'=>'修改成功','url' => url('passport.member/staff')]);
  157. }else{
  158. return json(['code'=>0,'msg'=>'修改失败']);
  159. }
  160. }else{
  161. $miniapp = SystemMemberMiniapp::field('miniapp_id')->where(['id' => $this->member_miniapp_id])->find();
  162. $view['auth'] = AppConfig::auth($miniapp->miniapp->miniapp_dir);
  163. return view()->assign($view);
  164. }
  165. }
  166. /**
  167. * 添加员工
  168. */
  169. public function staffEdit(){
  170. if(request()->isPost()){
  171. $data = [
  172. 'user_id' => $this->user->id,
  173. 'id' => $this->request->param('id/d'),
  174. 'miniapp_id' => $this->member_miniapp_id,
  175. 'auth' => $this->request->param('auth/d',0),
  176. 'username' => $this->request->param('username/s'),
  177. 'phone_id' => $this->request->param('phone_id/d'),
  178. 'login_password' => $this->request->param('login_password/s'),
  179. ];
  180. $validate = $this->validate($data,'Member.bindapp');
  181. if(true !== $validate){
  182. return json(['code'=>0,'msg'=>$validate]);
  183. }
  184. //判断手机号是否重复
  185. $info = SystemMember::where(['phone_id' => $data['phone_id']])->where('id','<>',$data['id'])->find();
  186. if(!empty($info)){
  187. return json(['code'=>0,'msg'=>'手机账号已存在']);
  188. }
  189. $result = SystemMember::bindEdit($data);
  190. if($result){
  191. return json(['code'=>200,'msg'=>'修改成功','url' => url('passport.member/staff')]);
  192. }else{
  193. return json(['code'=>0,'msg'=>'修改失败']);
  194. }
  195. }else{
  196. $id = $this->request->param('id/d');
  197. $info = SystemMember::where(['parent_id' => $this->user->id,'id' => $id])->find();
  198. if(!$info){
  199. return $this->error("404 NOT FOUND");
  200. }
  201. $miniapp = SystemMemberMiniapp::field('miniapp_id')->where(['id' => $info->bind_member_miniapp_id])->find();
  202. $view['info'] = $info;
  203. $view['auth'] = AppConfig::auth($miniapp->miniapp->miniapp_dir);
  204. return view()->assign($view);
  205. }
  206. }
  207. /**
  208. * 读取权限配置
  209. */
  210. public function getuserAuth(){
  211. $auth = $this->request->param('auth/d');
  212. $miniapp = SystemMemberMiniapp::field('miniapp_id')->where(['id' => $this->member_miniapp_id])->find();
  213. if(!$miniapp){
  214. return enjson(204);
  215. }
  216. $authconfig = AppConfig::auth($miniapp->miniapp->miniapp_dir);
  217. if(!$authconfig){
  218. return enjson(204);
  219. }
  220. foreach ($authconfig as $key => $value) {
  221. if($auth == $value['auth'] && isset($value['group'])){
  222. return enjson(200,$value['group']);
  223. break;
  224. }
  225. }
  226. return enjson(204);
  227. }
  228. /**
  229. * 检测手机号是否重复
  230. */
  231. public function isphone(){
  232. $userid = $this->request->param('id/d');
  233. $value = $this->request->param('param/s');
  234. if($userid){
  235. $result = SystemMember::where('id','<>',$userid)->where(['phone_id' => $value])->find();
  236. }else{
  237. $result = SystemMember::where(['phone_id' => $value])->find();
  238. }
  239. if($result){
  240. return json(['status'=>'n','info'=>'手机号已存在']);
  241. }else{
  242. return json(['status'=>'y','info'=>'可以使用']);
  243. }
  244. }
  245. /**
  246. * 锁定
  247. * @param integer $id 用户ID
  248. */
  249. public function staffLock(int $id){
  250. $result = SystemMember::lock($id);
  251. if(!$result){
  252. return json(['code'=>0,'message'=>'操作失败']);
  253. }else{
  254. return json(['code'=>200,'message'=>'操作成功']);
  255. }
  256. }
  257. /**
  258. * [删除]
  259. * @access public
  260. * @return bool
  261. */
  262. public function staffDelete(){
  263. $id = $this->request->param('id/d');
  264. $result = SystemMember::where(['parent_id' => $this->user->id,'id' => $id])->delete();
  265. if(!$result){
  266. return json(['code' => 0,'msg'=>'操作失败']);
  267. }else{
  268. return json(['code' =>200,'msg'=>'操作成功']);
  269. }
  270. }
  271. /**
  272. * 获取登录/找回密码等验证码
  273. */
  274. public function getLoginSms(){
  275. if(request()->isPost()){
  276. $data = [
  277. 'phone_id' => $this->request->param('phone/s')
  278. ];
  279. $validate = $this->validate($data,'Sms.getsms');
  280. if(true !== $validate){
  281. return json(['code'=>0,'message'=>$validate]);
  282. }
  283. //判断是否登录
  284. if($data['phone_id'] != $this->user->phone_id){
  285. return json(['code'=>0,'message'=>"请输入正确的手机号"]);
  286. }
  287. $user = SystemMember::where(['phone_id' => $this->user->phone_id])->find();
  288. if(empty($user)) {
  289. return json(['code'=>0,'message'=>"用户不存在"]);
  290. }
  291. $sms = Alisms::putSms($this->user->phone_id);
  292. return json($sms);
  293. }else{
  294. return $this->error("404 NOT FOUND");
  295. }
  296. }
  297. }