Member.php 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. <?php
  2. /**
  3. * 用户 控制器
  4. * Created by PhpStorm.
  5. * User: Administrator
  6. * Date: 2019/9/29
  7. * Time: 14:11
  8. */
  9. namespace app\home\controller;
  10. use app\api\controller\Api;
  11. use think\Config;
  12. use think\Db;
  13. use app\common\library\FileUpload;
  14. use app\common\library\HuaweiObs;
  15. class Member extends Home
  16. {
  17. private $_passwordSalt = ''; // 密码加密的盐
  18. private $_encryptMethod = ''; // 密码加密方法
  19. private $_passwordEncrypt = null; // 加密密码
  20. private $_password = null; // 密码明文
  21. private $_username = null; // 用户名
  22. private $_mobile = ''; // 手机号
  23. private $_nameLengthMin = 6; // 用户名最小长度
  24. private $_nameLengthMax = 11; // 用户名最大长度
  25. private $_pswdLengthMin = 6; // 密码最小长度
  26. private $_pswdLengthMax = 15; // 密码最大长度
  27. private $_registerMsgCode = 'SMS_462250586'; //'【祈盟文化游戏】您正在进行注册,验证码:[%s],有效期10分钟,请勿向任何人提供您收到的验证码。'; // 手机号注册短信验证码格式
  28. private $_findPwdMsgCode = 'SMS_462250586'; //'【祈盟文化游戏】您正在找回密码,验证码:[%s],有效期10分钟。请勿向任何人提供您收到的验证码。'; // 忘记密码-手机验证身份
  29. private $_bindEmailVLMobile = 'SMS_462250586'; //'【祈盟文化游戏】您正在换绑邮箱,验证码:[%s],有效期10分钟。请勿向任何人提供您收到的验证码。'; // 绑定邮箱-手机验证身份
  30. private $_bindEmail = 'SMS_462250586'; //'【祈盟文化游戏】您正在绑定邮箱,验证码:[%s],有效期10分钟。请勿向任何人提供您收到的验证码。'; // 绑定邮箱
  31. private $_bindMobile = 'SMS_462250586'; //'【祈盟文化游戏】您正在绑定手机,验证码:[%s],有效期10分钟。请勿向任何人提供您收到的验证码。'; // 绑定手机
  32. private $_bindMobileVLMobile = 'SMS_462250586'; //'【祈盟文化游戏】您正在换绑手机,验证码:[%s],有效期10分钟。请勿向任何人提供您收到的验证码。'; // 绑定手机-手机验证身份
  33. /**
  34. * 初始化操作
  35. */
  36. protected function _initialize()
  37. {
  38. parent::_initialize();
  39. }
  40. /**
  41. * 登录
  42. */
  43. public function login() {
  44. if ($this->request->isAjax()){
  45. $username = $this->request->param('username' , '' );
  46. $password = $this->request->param('password' , '' );
  47. $Ticket = $this->request->param('ticket' , '' );
  48. $Randstr = $this->request->param('randstr' , '' );
  49. $username = strtolower($username);
  50. if ( empty($username)) $this->jsonResult([],-1,'请输入用户名');
  51. if ( empty($password) ) $this->jsonResult([],-2,'请输入密码');
  52. $slider = $this->sliderVelidate($Ticket,$Randstr);
  53. if (!$slider['code']) $this->jsonResult([],0,$slider['msg']);
  54. $this->_username = $username;
  55. $this->_password = $password;
  56. $member = model('Members')->field(["id","username","password","email","fromflag","reg_time",'flag','nickname','avatar'])->where(["username"=>$this->_username])->find();
  57. if ( empty($member) ) $this->jsonResult([],-2,'用户名或密码错误');
  58. if ( !empty($member['flag']) ) $this->jsonResult([],-1,'该用户已被冻结,请联系客服');
  59. if ( $member['password'] != $this->getPassword() ) $this->jsonResult([],-2,'用户名或密码错误');
  60. unset($member['password']);
  61. session('front_userid',$member['id']);
  62. session('front_account',$member['username']);
  63. $userinfo = array('front_userid'=>$member['id'], 'front_account'=>$username);
  64. $userinfo = json_encode($userinfo);
  65. setcookie('t', auth_code($userinfo, 'ENCODE'), time()+86400, '/', SECOND_DOMAIN);
  66. if (empty($member['nickname'])) {
  67. $newNickname = model('Members')->creatNickname($member['id']);
  68. /*$member['nickname'] = $newNickname;*/
  69. }
  70. /*session('front_info',$member);*/
  71. $preUrl = $this->getPrePageUrl();
  72. $this->success('登录成功!',$preUrl);
  73. }
  74. if (session('front_userid')){
  75. $this->redirect($this->defaultPage);
  76. exit;
  77. }
  78. $this->setPreUrl();
  79. $appid = Config::get('SLIDER_VERIFICATION.APPID');
  80. $this->assign('appid',$appid);
  81. return $this->fetch();
  82. }
  83. /**
  84. * 退出登录
  85. */
  86. public function logout(){
  87. setcookie('t', '', time()-1, '/', SECOND_DOMAIN);
  88. session(null);
  89. session_destroy();
  90. $this->jsonResult([],1,'退出登录成功!');
  91. }
  92. // 获取加密密码
  93. public function getPassword() {
  94. $password = (string)$this->_passwordEncrypt;
  95. if ( empty($password) ) {
  96. switch ( strtoupper($this->_encryptMethod) ) {
  97. case 'MD5':
  98. $password = $this->_md5Code($this->_password, $this->_passwordSalt);
  99. break;
  100. default:
  101. $password = $this->_authCode($this->_password, $this->_passwordSalt);
  102. break;
  103. }
  104. $this->_passwordEncrypt = $password;
  105. }
  106. return $password;
  107. }
  108. private function _md5Code($password,$salt='') {
  109. return md5($password . $salt);
  110. }
  111. private function _authCode($password,$salt='') {
  112. return auth_code($password, 'ENCODE', $salt);
  113. }
  114. public function userReg(){
  115. if (session('front_userid')){
  116. $this->redirect($this->defaultPage);exit;
  117. }
  118. $this->setPreUrl();
  119. return $this->fetch('user_reg');
  120. }
  121. public function phoneReg(){
  122. if (session('front_userid')){
  123. $this->redirect($this->defaultPage);exit;
  124. }
  125. $this->setPreUrl();
  126. $appid = Config::get('SLIDER_VERIFICATION.APPID');
  127. $this->assign('appid',$appid);
  128. return $this->fetch('phone_reg');
  129. }
  130. /**
  131. * 注册
  132. */
  133. public function register(){
  134. if ($this->request->isPost()){
  135. $type = $this->request->param('type', '');
  136. $username = $this->request->param('username','');
  137. $password = $this->request->param('password','');
  138. $password_1 = $this->request->param('passwordone','');
  139. $sms_code = $this->request->param('smsCode','');
  140. if ( empty($username)) {
  141. $this->jsonResult([],-1,($type == 'phone') ? '请输入正确的手机号' : '请输入正确的用户名,'.$this->_nameLengthMin.'-'.$this->_nameLengthMax.'位字母或数字');
  142. }
  143. if ( empty($password_1) ) {
  144. $this->jsonResult([],-2,'请输入正确的密码,'.$this->_pswdLengthMin.'-'.$this->_pswdLengthMax.'位字符');
  145. }
  146. if ( empty($password) ) {
  147. $this->jsonResult([],-3,'请再次输入密码');
  148. }
  149. if ($password_1 != $password){
  150. $this->jsonResult([],-3,'两次输入的密码不一致');
  151. }
  152. if ( ! $this->checkPassword($password,false) ) {
  153. $this->jsonResult([],-2,"请输入正确的密码,{$this->_pswdLengthMin} - {$this->_pswdLengthMax}位字符");
  154. }
  155. $this->_username = $username;
  156. if($type == 'phone') {
  157. $result = (new \app\common\library\Sms)->checkCode($username,$sms_code);
  158. if(!$result['status']) {
  159. $this->error($result['msg']);
  160. }
  161. $this->_mobile = $username;
  162. } elseif($type == 'username') {
  163. $resUser = $this->checkUsername($username,false);
  164. if (!$resUser['code']) $this->jsonResult([],-1,$resUser['msg']);
  165. } else {
  166. $this->error('非法请求!');
  167. }
  168. if ( $this->isExistUser($this->_username) ) {
  169. $this->jsonResult([],-1,($type == 'phone') ? '该手机号已经被注册' : '该用户名已经被注册' );
  170. }
  171. if($type == 'username') {
  172. $Ticket = $this->request->param('ticket' , '' );
  173. $Randstr = $this->request->param('randstr' , '' );
  174. $resUser = $this->sliderVelidate($Ticket,$Randstr);
  175. if (!$resUser['code']) $this->jsonResult([],0,$resUser['msg'] );
  176. }
  177. $ip = GetIP(0);
  178. $device = getDevice();
  179. $agent = 'default';
  180. /*! empty($passwordSalt) && $this->setPasswordSalt($passwordSalt);
  181. ! empty($encryptMethod) && $this->setEncryptMethod($encryptMethod);*/
  182. $this->_passwordEncrypt = $this->getPassword();
  183. $last_user_id = model('Members')->insertGetId(["username"=>$this->_username,"password"=>$this->_passwordEncrypt,"mobile"=>$this->_mobile,"agent"=>$agent, "device"=>$device,"ip"=>$ip,"reg_time"=>$_SERVER['REQUEST_TIME'], 'channel_id'=>MEMBER_DEFAULT_CHANNEL_ID]);
  184. if ( $last_user_id <= '0' ) {
  185. $this->error('注册失败');
  186. return false;
  187. }
  188. $this->insertChangeLog($last_user_id, $password,null,$this->_mobile);
  189. session('front_userid',$last_user_id);
  190. session('front_account',$this->_username);
  191. // 加密用户信息,用于跨二级域名登录
  192. $userinfo = array('front_account'=>$username,'front_userid'=>$last_user_id);
  193. $userinfo = json_encode($userinfo);
  194. setcookie('t', auth_code($userinfo, 'ENCODE'), time()+86400, '/', SECOND_DOMAIN);
  195. $newNickname = model('Members')->creatNickname($last_user_id);
  196. /*$member = [
  197. 'id' => $last_user_id ,
  198. "username" => $this->_username ,
  199. 'nickname' => $newNickname ,
  200. "avatar" => '' ,
  201. "reg_time" => $_SERVER['REQUEST_TIME']
  202. ];
  203. session('front_info',$member);*/
  204. $this->success('注册成功!',$this->getPrePageUrl());
  205. }
  206. $this->error('非法请求!');
  207. }
  208. /**
  209. * 发送手机验证码
  210. */
  211. public function sendCode($isExistUser = false) {
  212. $phone = $this->request->param('phone', '');
  213. if (!$this->checkMobile($phone)) {
  214. $this->error('请输入正确的手机号');
  215. }
  216. if ($isExistUser){
  217. $res = $this->isExistUser($phone);
  218. if ($res) $this->jsonResult([],-1,'该手机号已被注册');
  219. }
  220. $Ticket = $this->request->param('ticket' , '' );
  221. $Randstr = $this->request->param('randstr' , '' );
  222. $slider = $this->sliderVelidate($Ticket,$Randstr);
  223. if (!$slider['code']) $this->jsonResult([],0,$slider['msg']);
  224. $result = (new \app\common\library\Sms)->sendCode($phone,$this->_registerMsgCode);
  225. if ($result['status']) $this->success('验证码发送成功');
  226. $this->error($result['msg']);
  227. }
  228. // 校验用户名是否符合规则
  229. public function checkUsername($username,$isExit = true) {
  230. if($this->checkMobile($username)) {
  231. if ($isExit) $this->error('手机号请选择手机号注册方式');
  232. return ['code'=>0,'msg'=>'手机号请选择手机号注册方式'];
  233. } elseif ( strlen($username) < $this->_nameLengthMin || strlen($username) > $this->_nameLengthMax || preg_match('/[^0-9A-Za-z_]/', $username)) {
  234. if ($isExit) $this->error("请输入正确的用户名,{$this->_nameLengthMin} - {$this->_nameLengthMax}位字母或数字");
  235. return ['code'=>0,'msg'=>"请输入正确的用户名,{$this->_nameLengthMin} - {$this->_nameLengthMax}位字母或数字"];
  236. }else {
  237. $this->_username = $username;
  238. return ['code'=>1,'msg'=>''];
  239. }
  240. }
  241. /**
  242. * 检查是否为手机号
  243. */
  244. public function checkMobile($phone){
  245. $preg = '/^1[0123456789]{1}\d{9}$/';
  246. if (0 == preg_match($preg, $phone)) {
  247. return false;
  248. }
  249. return true;
  250. }
  251. /**
  252. * 判断用户是否存在
  253. * @param string $username 用户名
  254. * @return boolean
  255. */
  256. public function isExistUser($username) {
  257. $username = filterAndTrimInput($username);
  258. $result = model('Members')->field('id')->where(["username"=>$username])->find();
  259. if ( isset($result['id']) && $result['id'] > 0 ) {
  260. return true;
  261. }
  262. return false;
  263. }
  264. public function insertChangeLog($userid,$password=null,$email=null,$mobile=null) {
  265. $record = ['userid' => $userid, 'ip' => GetIP(1), 'create_time' => NOW_TIMESTAMP];
  266. !empty($password) && $record['password'] = auth_code($password, 'ENCODE');
  267. !empty($email) && $record['email'] = $email;
  268. !empty($mobile) && $record['mobile'] = $mobile;
  269. return model('MemberHistory')->insertGetId($record);
  270. }
  271. /**
  272. * 校验密码是否符合规则
  273. * @param $password
  274. * @return bool
  275. */
  276. public function checkPassword($password,$isReturn = true) {
  277. if ( strlen($password) > $this->_pswdLengthMax || strlen($password) < $this->_pswdLengthMin ) {
  278. if ($isReturn) $this->error("请输入正确的密码,{$this->_pswdLengthMin} - {$this->_pswdLengthMax}位字符");
  279. return false;
  280. } else {
  281. $this->_password = strval($password);
  282. return true;
  283. }
  284. }
  285. /**
  286. * 忘记密码-- 确认账号
  287. */
  288. public function contactAccount(){
  289. if ($this->request->isAjax()){
  290. $username = input('post.username' , '' );
  291. if (empty($username)) $this->error('用户名不能为空');
  292. $Ticket = $this->request->param('ticket' , '' );
  293. $Randstr = $this->request->param('randstr' , '' );
  294. $slider = $this->sliderVelidate($Ticket,$Randstr);
  295. if (!$slider['code']) $this->jsonResult([],0,$slider['msg']);
  296. $info = model('Members')->field('id,email,mobile,username,flag')->where(["username" => $username])->find();
  297. if (empty($info)) $this->error('用户名不存在');
  298. if ( !empty($info['flag']) ) $this->error('该用户已被冻结,请联系客服');
  299. if ( !empty($info['email'])) $info['email'] = mailObfuscation($info['email']);
  300. if ( !empty($info['mobile'])) $info['mobile'] = stringObfuscation($info['mobile'] , 3);
  301. session('check_uid',$info);
  302. $this->success('',getForgetPwdUrl(2));
  303. }
  304. if (session('front_userid')){
  305. $this->redirect($this->defaultPage);exit;
  306. }
  307. $appid = Config::get('SLIDER_VERIFICATION.APPID');
  308. $this->assign('appid',$appid);
  309. return $this->fetch('contact_account');
  310. }
  311. /**
  312. * 忘记密码--提供验证方式
  313. */
  314. public function contactWay() {
  315. $info = session('check_uid');
  316. if (session('front_userid')){
  317. $this->redirect($this->defaultPage);exit;
  318. }
  319. if (!$info) $this->error('非法请求');
  320. $this->assign('info',$info);
  321. return $this->fetch('contact_way');
  322. }
  323. /**
  324. * 忘记密码--提供验证方式--邮箱或者手机号验证
  325. */
  326. public function contact() {
  327. if (session('front_userid')){
  328. $this->redirect($this->defaultPage);exit;
  329. }
  330. $typeArr = ['phone' , 'email'];
  331. $type = $this->request->param('type' , '' );
  332. $info = session('check_uid');
  333. if (!$info || !in_array($type,$typeArr)) $this->redirect(getForgetPwdUrl(2));
  334. $this->assign('info',$info);
  335. $this->assign('type',$type);
  336. return $this->fetch();
  337. }
  338. /**
  339. * 忘记密码--发送验证码
  340. */
  341. public function resetPwdSendCode(){
  342. $type = input('post.type' , '' );
  343. $id = session('check_uid')['id'];
  344. $typeArr = ['phone' , 'email'];
  345. if (!in_array($type,$typeArr) || empty($id)) $this->error('非法请求');
  346. $info = model('Members')->field('id,username,email,mobile')->where(["id" => $id , 'flag' => 0])->find();
  347. if ($type == $typeArr[0]){
  348. $result = (new \app\common\library\Sms)->sendCode($info['mobile'],$this->_findPwdMsgCode);
  349. }else{
  350. $result = (new \app\common\library\Mail)->sendCodeMailByType($info['username'], $info['email']);
  351. }
  352. if(isset($result) && $result['status']){
  353. $this->jsonResult([],1,'发送成功');
  354. }else{
  355. $this->jsonResult([],0,$result['msg']);
  356. }
  357. }
  358. /**
  359. * 忘记密码--验证验证码
  360. */
  361. public function resetPwdCheckCode() {
  362. $id = session('check_uid')['id'];
  363. $code = input('post.code' , 0 , 'intval');
  364. $type = input('post.type' , '' );
  365. $typeArr = ['phone' , 'email'];
  366. if ( !in_array($type , $typeArr) || empty($id)) $this->jsonResult([],0,'非法请求');
  367. if (empty($code)) $this->jsonResult([],0,'请输入验证码');
  368. $info = model('Members')->field('id,username,email,mobile')->where(["id" => $id , 'flag' => 0])->find();
  369. if ($type == $typeArr[0]) {
  370. $result = (new \app\common\library\Sms)->checkCode($info['mobile'] , $code);
  371. } else {
  372. $result = (new \app\common\library\Mail)->checkCode($info['username'] , $info['email'] , $code);
  373. }
  374. if (isset($result) && $result['status']) {
  375. session('hasCheck',true);
  376. $this->success('验证成功',getForgetPwdUrl(3));
  377. }
  378. $errMsg = $result['msg'];
  379. $this->jsonResult([],0,$errMsg);
  380. }
  381. /**
  382. * 忘记密码--重置密码
  383. */
  384. public function forgetPwdToReset(){
  385. if (session('front_userid')){
  386. $this->redirect($this->defaultPage);exit;
  387. }
  388. if ($this->request->isAjax()){
  389. $id = session('check_uid')['id'];
  390. $password1 = input('post.password1' , '' );
  391. $password2 = input('post.password2' , '' );
  392. if (empty($id)) $this->jsonResult([],0,'非法请求');
  393. if (empty($password1)) $this->jsonResult([],-1,'请输入新密码,'.$this->_pswdLengthMin.'-'.$this->_pswdLengthMax.'位字符');
  394. if (empty($password2)) $this->jsonResult([],-2,'请再次输入密码');
  395. //if (!session('hasCheck')) $this->error('请先通过身份验证');
  396. if ($password1 != $password2) $this->jsonResult([],-2,'两次输入的密码不一致');
  397. $res = $this->resetPassword($id,$password1);
  398. if ($res == 3) $this->jsonResult([],-1,'请输入正确的密码,'.$this->_pswdLengthMin.'-'.$this->_pswdLengthMax.'位字符');
  399. if ($res == 1 || $res == 2) {
  400. session('hasCheck',null);
  401. session('check_uid',null);
  402. $this->success('',getForgetPwdUrl('4.'.$res));
  403. }
  404. if ($res == 0) $this->jsonResult([],-2,'新密码不能与旧密码相同');
  405. }
  406. $appid = Config::get('SLIDER_VERIFICATION.APPID');
  407. $this->assign('appid',$appid);
  408. return $this->fetch('forget_pwd_to_reset');
  409. }
  410. /**
  411. * 重置密码
  412. *$flag: 账号是否解冻 1解冻 0不解冻
  413. * return:0新密码不能与旧密码相同,1密码重置成功,2密码重置失败,3密码格式不正确
  414. */
  415. public function resetPassword($id,$password1,$flag = 0){
  416. $res1 = $this->checkPassword($password1,false);
  417. if (!$res1) return 3;
  418. $info = model('Members')->field('id,username,email,mobile,password')->where(["id" => $id])->find();
  419. $this->_passwordEncrypt = $this->getPassword();
  420. if ($this->_passwordEncrypt == $info['password']) return 0;
  421. $data = ['password' => $this->_passwordEncrypt];
  422. if ($flag == 1) $data['flag'] = 0;
  423. $res = model('Members')->save($data,['id' => $id]);
  424. if ($res){
  425. session(null);
  426. session_destroy();
  427. setcookie('t', '', time()-1, '/', SECOND_DOMAIN);
  428. $record = [
  429. 'userid' => $id ,
  430. 'ip' => GetIP(1) ,
  431. 'password' => $this->_passwordEncrypt ,
  432. 'create_time' => NOW_TIMESTAMP,
  433. ];
  434. model('MemberHistory')->insertGetId($record);
  435. return 1;
  436. }
  437. return 2;
  438. }
  439. /**
  440. * 忘记密码--重置结果
  441. */
  442. public function forgetPwdResult(){
  443. if (session('front_userid')){
  444. $this->redirect($this->defaultPage);exit;
  445. }
  446. $res = input('res',2);
  447. $this->assign('res',$res);
  448. return $this->fetch('forget_pwd_result');
  449. }
  450. /**
  451. * 获取用户资料
  452. */
  453. public function getUserInfo(){
  454. $id = session('front_userid');
  455. $info = model('Members')->alias('m')
  456. ->join('cy_memberstwo t','m.id=t.userid','left')
  457. ->field('m.id,m.username,m.nickname,t.sex,t.qq,t.birthday,t.zipcode,t.address,t.id as memberstwo_id,m.avatar')
  458. ->where(["m.id" => $id , 'm.flag' => 0])
  459. ->find();
  460. return $info;
  461. }
  462. /**
  463. * 个人中心--个人资料
  464. */
  465. public function personalInfo(){
  466. $this->_isLogin();
  467. $defaultBrith = '0000-00-00';
  468. $info = $this->getUserInfo();
  469. if ($info['birthday'] == $defaultBrith) $info['birthday'] = null;
  470. $this->assign('info',$info);
  471. return $this->fetch('personal_info');
  472. }
  473. /**
  474. * 个人资料编辑
  475. */
  476. public function personalInfoEdit(){
  477. $this->_isLogin();
  478. $defaultBrith = '0000-00-00';
  479. $info = $this->getUserInfo();
  480. /*dump($info['avatar']);*/
  481. if ($this->request->isPost()){
  482. $qq = input('post.qq', '');
  483. $sex = input('post.sex', '');
  484. $birthday = input('post.birthday', '');
  485. $address = input('post.address', '');
  486. $zipcode = input('post.zipcode', '');
  487. $nickname = input('post.nickname', '');
  488. $birthday_bool = false;
  489. if ((empty($birthday) && $info['birthday'] == $defaultBrith) || $birthday == $info['birthday']){
  490. $birthday_bool = true;
  491. }
  492. // 是否修改了用户资料
  493. $isUpate1 = true;
  494. $isUpate2 = true;
  495. if ($qq == $info['qq'] &&$sex==$info['sex'] &&$birthday_bool &&$zipcode==$info['zipcode'] && $address==$info['address']){
  496. $isUpate1 = false;
  497. }
  498. if ($nickname == $info['nickname'] ){
  499. $isUpate2 = false;
  500. }
  501. if (!$isUpate1 && !$isUpate2) $this->jsonResult([],1,'请修改内容后保存');
  502. if ($isUpate2 ){
  503. $res = validataNickname($nickname);
  504. if (!$res['code']) $this->jsonResult('nickname',-4,$res['msg']);
  505. }
  506. if(!empty($qq) && 0 == preg_match('/^\d*$/', $qq)) {
  507. $this->jsonResult('',-1,'请输入正确的QQ号');
  508. }
  509. if(!empty($zipcode) && 0 == preg_match('/^(\d{6})?$/', $zipcode)) {
  510. $this->jsonResult('',-2,'请输入正确的邮政编码');
  511. }
  512. if(!empty($address) && iconv_strlen($address,"UTF-8") >40) {
  513. $this->jsonResult('',-3,'联系地址不能超过40个字');
  514. }
  515. $data = [
  516. 'sex' => $sex ,
  517. 'qq' => $qq ,
  518. 'address' => $address ,
  519. 'zipcode' => $zipcode ,
  520. 'birthday' => $birthday ,
  521. ];
  522. $id = session('front_userid');
  523. // 启动事务
  524. Db::startTrans();
  525. // 判断是否有添加过 cy_memberstwo
  526. if ( !empty($info['memberstwo_id'])) {
  527. $res = true;
  528. if ($isUpate1 ){
  529. $res = model('MembersTwo')->save($data , ['userid' => $id]);
  530. }
  531. } else {
  532. $data['userid'] = $id;
  533. $data['username'] = session('front_account');
  534. $res = model('MembersTwo')->insertGetId($data);
  535. }
  536. $rest = true;
  537. if ($isUpate2){
  538. $rest = model('Members')->save(['nickname'=>$nickname] , ['id' => $id]);
  539. }
  540. if ($res && $rest){
  541. Db::commit();
  542. // 更新个人资料缓存
  543. /*$data['nickname'] = $nickname;
  544. $this->_updateUserInfo($data);*/
  545. $this->jsonResult([],1,'个人资料修改成功');
  546. }
  547. Db::rollback();
  548. $this->jsonResult([],0,'操作失败');
  549. }
  550. if ($info['birthday'] == $defaultBrith) $info['birthday'] = '';
  551. $this->assign('info',$info);
  552. return $this->fetch('personal_info_edit');
  553. }
  554. /**
  555. * 查询条件--时间格式化
  556. * @param $start
  557. * @param $end
  558. * @param $fieldTime 字段名
  559. * @param $today 是否默认查询今天
  560. * @return array
  561. */
  562. public function _setParamTime($start,$end,$fieldTime='p.create_time',$today = true){
  563. $condition = [];
  564. //开始时间和结束时间不为空时
  565. if ($start != '' && $end != '') {
  566. $condition[$fieldTime] = [
  567. ['>=', strtotime($start)],
  568. ['<=', strtotime($end . ' 23:59:59')],
  569. ];
  570. } //开始时间不为空时
  571. elseif ($start != '') {
  572. $condition[$fieldTime] = ['>=', strtotime($start)];
  573. } //结束时间不为空时
  574. elseif ($end != '') {
  575. $condition[$fieldTime] = ['<=', strtotime($end . ' 23:59:59')];
  576. } else {
  577. if ($today){
  578. $end = date('Y-m-d', time());
  579. $condition[$fieldTime] = [
  580. ['>=', strtotime($start)],
  581. ['<=', strtotime($end . ' 23:59:59')],
  582. ];
  583. }
  584. }
  585. return ['condition'=>$condition,'start'=>$start,'end'=>$end];
  586. }
  587. /**
  588. * 个人中心--充值记录
  589. */
  590. public function personalPay(){
  591. $this->_isLogin();
  592. $start = $this->request->param('start');
  593. $end = $this->request->param('end');
  594. $nickname = $this->request->param('nickname', '');
  595. $orderid = $this->request->param('orderid', '');
  596. $status = $this->request->param('status', '');
  597. $condition = ['p.userid'=>session('front_userid')];
  598. if (!empty($nickname)) {
  599. $condition['g.nickname'] = ['like','%'.$nickname.'%'];
  600. }
  601. if (!empty($orderid)) {
  602. $condition['p.orderid'] = $orderid;
  603. }
  604. if ($status != '') {
  605. $condition['p.status'] = $status;
  606. }
  607. $timeArr = $this->_setParamTime($start,$end);
  608. $condition = array_merge($condition,$timeArr['condition']);
  609. // 统一显示为“微信支付”。
  610. $wxzfArr = ['wxpay','swiftwxpay','wxpay-h5','ipaywxpay','ios-wxpay'];
  611. // 统一显示为“微信混合支付”。
  612. $wxhhzfArr = ['mix-swiftwxpay','mix-ipaywxpay','mix-wxpay-h5'];
  613. // 统一显示为“支付宝支付”。
  614. $zfbzfArr = ['zfb','ios-zfb'];
  615. // 平台币支付显示规则
  616. $lbArr = array_merge(['ptb','mix-zfb'],$wxhhzfArr);
  617. // 第三方支付显示规则
  618. $thirdArr = array_merge(['mix-zfb'],$wxhhzfArr,$wxzfArr,$zfbzfArr);
  619. $PayModel = model('Common/Pay');
  620. $list = $PayModel->alias('p')->field('p.id,p.orderid,p.amount,p.real_ptb,p.paytype,p.real_amount,p.productname,p.status,p.pay_time,p.create_time,g.nickname')
  621. ->join('cy_game g','p.gameid=g.id','left')
  622. ->where($condition)
  623. ->order('p.create_time desc')
  624. ->paginate(10, false, ['query' => input('get.')])
  625. ->each(function($item, $key) use($wxzfArr,$wxhhzfArr,$lbArr,$thirdArr,$zfbzfArr){
  626. $item['lb_show'] = 0;
  627. $item['third_show'] = 0;
  628. if (in_array($item['paytype'],$lbArr)) $item['lb_show'] = 1;
  629. if (in_array($item['paytype'],$thirdArr)) $item['third_show'] = 1;
  630. if (in_array($item['paytype'],$wxzfArr)){
  631. $item['paytype'] = '微信支付';
  632. }elseif (in_array($item['paytype'],$wxhhzfArr)){
  633. $item['paytype'] = '微信混合支付';
  634. }elseif (in_array($item['paytype'],$zfbzfArr)){
  635. $item['paytype'] = '支付宝';
  636. }else{
  637. $item['paytype'] = config('paytype.'.$item['paytype']);
  638. }
  639. return $item;
  640. });
  641. $this->assign('start',$timeArr['start']);
  642. $this->assign('end',$timeArr['end']);
  643. $this->assign('list',$list);
  644. $this->assign('page', $list->render());
  645. $this->assign('game_list',model('Common/Game')->getAllByCondition('id,name'));
  646. return $this->fetch();
  647. }
  648. /**
  649. * 个人中心--存号箱
  650. */
  651. public function memberGift(){
  652. $this->_isLogin();
  653. $title = input('title' , '' );
  654. $start = $this->request->param('start');
  655. $end = $this->request->param('end');
  656. $condition = ['a.username'=>session('front_account')];
  657. if (!empty($title)){
  658. $condition['l.title'] = ['like','%'.$title.'%'];
  659. }
  660. $timeArr = $this->_setParamTime($start,$end,'a.create_time');
  661. $condition = array_merge($condition,$timeArr['condition']);
  662. $list = model('Libaolog')->alias('a')
  663. ->join('cy_libaoinfo l','l.id=a.libaoid')
  664. ->join('cy_game g','g.id=l.gameid','left')
  665. ->field('a.id,l.title,a.username,a.create_time,g.name,a.code,l.content,l.starttime,l.endtime')
  666. ->where($condition)
  667. ->order('a.create_time desc')
  668. ->paginate(10, false, ['query' => input('get.')]);
  669. $this->assign('start',$timeArr['start']);
  670. $this->assign('end',$timeArr['end']);
  671. $this->assign('list',$list);
  672. $this->assign('page', $list->render());
  673. return $this->fetch('member_gift');
  674. }
  675. /**
  676. * 个人中心--账号安全
  677. */
  678. public function personalAccount() {
  679. $this->_isLogin();
  680. $id = session('front_userid');
  681. $info = model('Members')->alias('m')
  682. ->join('cy_memberstwo t' , 'm.id=t.userid' , 'left')
  683. ->field('m.id,m.email,m.mobile,t.idcard,t.realname')
  684. ->where(["m.id" => $id , 'm.flag' => 0])
  685. ->find();
  686. $info['isVerified'] = 1;
  687. if (empty($info['realname']) || empty($info['idcard']) || ((- 1 == $info['realname']) && (- 1 == $info['idcard']))) {
  688. $info['isVerified'] = 0;
  689. }
  690. if ( !empty($info['email'])) $info['email'] = mailObfuscation($info['email']);
  691. if ( !empty($info['mobile'])) $info['mobile'] = mobileObfuscation($info['mobile']);
  692. $this->assign('info',$info);
  693. return $this->fetch();
  694. }
  695. /**
  696. * 个人中心--修改密码
  697. */
  698. public function personalChangePwd(){
  699. $this->_isLogin();
  700. if($this->request->isPost() ){
  701. $oldPwd = input('post.oldPwd' , '' );
  702. $password1 = input('post.password1' , '' );
  703. $password2 = input('post.password2' , '' );
  704. if (empty($oldPwd)) $this->jsonResult([],0,'请输入旧密码');
  705. if (empty($password1)) $this->jsonResult([],-1,'请输入密码,6-15位字符');
  706. if (empty($password2)) $this->jsonResult([],-2,'请再次输入密码');
  707. if ($oldPwd == $password1) $this->jsonResult([],-1,'新密码不能与旧密码相同');
  708. if ($password1 != $password2) $this->jsonResult([],-2,'两次输入的密码不一致');
  709. $this->checkPassword($password1);
  710. $id = session('front_userid');
  711. $info = model('Members')->field('id,username,email,mobile,password')->where(["id" => $id, 'flag' => 0])->find();
  712. $this->_password = $oldPwd;
  713. $this->_passwordEncrypt = $this->getPassword();
  714. if ($this->_passwordEncrypt != $info['password']) $this->jsonResult([],0,'输入的旧密码错误');
  715. $this->_password = $password1;$this->_passwordEncrypt = '';
  716. $this->_passwordEncrypt = $this->getPassword();
  717. $res = model('Members')->save(['password' => $this->_passwordEncrypt],['id' => $id]);
  718. model('MemberHistory')->insertGetId(['password' => $this->_passwordEncrypt,'userid'=> $id,'ip' => GetIP(1) ,'create_time' => NOW_TIMESTAMP]);
  719. if ($res) $this->success('修改成功',getUserCenterUrl('4'));
  720. $this->jsonResult([],0,'修改失败');
  721. }
  722. return $this->fetch();
  723. }
  724. /**
  725. * 个人中心--实名认证--页面
  726. */
  727. public function personalIdentityPage(){
  728. $this->_isLogin();
  729. $id = session('front_userid');
  730. $info = model('Members')->alias('m')
  731. ->join('cy_memberstwo t' , 'm.id=t.userid' , 'left')
  732. ->field('m.id,m.email,m.mobile,t.idcard,t.realname')
  733. ->where(["m.id" => $id , 'm.flag' => 0])
  734. ->find();
  735. if (empty($info['realname']) || empty($info['idcard']) || ((- 1 == $info['realname']) && (- 1 == $info['idcard']))) {
  736. // 未实名认证
  737. return $this->fetch('identity');
  738. }
  739. if ( !empty($info['realname'])) $info['realname'] = usernameObfuscation($info['realname']);
  740. if ( !empty($info['idcard'])) $info['idcard'] = idcardObfuscation($info['idcard']);
  741. $this->assign('info',$info);
  742. return $this->fetch('identity_info');
  743. }
  744. /**
  745. * 个人中心--实名认证
  746. */
  747. public function personalIdentity(){
  748. $this->_isLogin();
  749. $data = [
  750. 'realname' => input('post.realname', ''),
  751. 'idcard' => input('post.idcard', ''),
  752. ];
  753. $result = $this->validate($data, [
  754. ['realname', 'require|length:2,10|chs', '请输入姓名|姓名只能是2-10位的汉字|姓名只能是2-10位的汉字'],
  755. ['idcard', 'require|identityNumber', '请输入身份证号码|身份证号码格式不正确'],
  756. ]);
  757. if (true !== $result) $this->jsonResult($result,0,$result);
  758. // 通过身份证验证年龄
  759. if (!isMeetAgeByIDCard($data['idcard'],9,120)) $this->jsonResult([], 0, '您未满足年龄要求(9-120岁),无法通过认证');
  760. $res = model('MembersTwo')->updateInfo($data, session('front_userid'));
  761. if ($res) $this->success('实名认证成功',getUserCenterUrl('4'));
  762. $this->jsonResult('', 0, '认证失败');
  763. }
  764. /**
  765. * 个人中心--绑定手机或邮箱--1
  766. */
  767. public function toBindOne(){
  768. $this->_isLogin();
  769. $type = input('type', '');
  770. if (!in_array($type,['mobile','email'])) {
  771. $this->error('请求错误');
  772. }
  773. $id = session('front_userid');
  774. $info = model('Members')->alias('m')
  775. ->field('m.id,m.email,m.mobile')
  776. ->where(["m.id" => $id , 'm.flag' => 0])
  777. ->find();
  778. // 请求绑定手机,就判断是否绑定邮箱;请求绑定邮箱,就判断是否绑定手机
  779. $runable = 'no'; // 是否去先验证另外一个联系方式
  780. /*$lxfs = '';
  781. $infoData = '';*/
  782. if ($type == 'mobile' && (!empty($info['email']) || !empty($info['mobile'])) ) {
  783. $runable = 'email';
  784. /* $lxfs = $info['email'];*/
  785. /* $infoData = stringObfuscation($info['email'] , 3);*/
  786. }
  787. if ($type == 'email' && (!empty($info['email']) || !empty($info['mobile']))) {
  788. $runable = 'mobile';
  789. /* $lxfs = $info['mobile'];*/
  790. /*$infoData = stringObfuscation($info['mobile'] , 3);*/
  791. }
  792. if ($runable == 'no'){
  793. $appid = Config::get('SLIDER_VERIFICATION.APPID');
  794. $this->assign('appid',$appid);
  795. $this->assign('type',$type);
  796. return $this->fetch('bind_page');
  797. }
  798. session('velidate_info',['type'=>$type,'info_data'=>$info,'velidate_type'=>'']);
  799. $this->assign('type',$type);
  800. /*$this->assign('info_data',$infoData);*/
  801. $this->assign('info',$info);
  802. return $this->fetch('bind_other');
  803. }
  804. /**
  805. * 个人中心--绑定手机或邮箱--2 验证其他方式的页面
  806. */
  807. public function toVelidatePage(){
  808. $velidate_info = session('velidate_info');
  809. if (empty($velidate_info)) $this->redirect(getUserCenterUrl(1));
  810. $type = input('type', '');
  811. if (!in_array($type,['mobile','email'])) {
  812. $this->redirect(getUserCenterUrl(1));
  813. }
  814. $velidate_info['velidate_type'] = $type;
  815. session('velidate_info',$velidate_info);
  816. $appid = Config::get('SLIDER_VERIFICATION.APPID');
  817. $this->assign('appid',$appid);
  818. $this->assign('info',$velidate_info);
  819. return $this->fetch('velidate_page');
  820. }
  821. /**
  822. * 个人中心--绑定手机或邮箱--3 发送验证码
  823. */
  824. public function toVelidateSendCode(){
  825. $velidate_info = session('velidate_info');
  826. if (empty($velidate_info)) $this->error('系统繁忙!');
  827. $Ticket = $this->request->param('ticket' , '' );
  828. $Randstr = $this->request->param('randstr' , '' );
  829. $slider = $this->sliderVelidate($Ticket,$Randstr);
  830. if (!$slider['code']) $this->jsonResult([],0,$slider['msg']);
  831. $temple = ''; // 短信或邮件模板
  832. if ($velidate_info['velidate_type'] == 'mobile'){
  833. if ($velidate_info['type'] == 'mobile'){
  834. $temple = $this->_bindMobileVLMobile;
  835. }else{
  836. if (empty($velidate_info['info_data']['email'])){
  837. $temple = $this->_bindEmail;
  838. }else{
  839. $temple = $this->_bindEmailVLMobile;
  840. }
  841. }
  842. $result = (new \app\common\library\Sms)->sendCode($velidate_info['info_data']['mobile'],$temple);
  843. }else{
  844. if ($velidate_info['type'] == 'email'){
  845. $temple = 'bindEmailVLEmail';
  846. }else{
  847. if (empty($velidate_info['info_data']['mobile'])){
  848. $temple = 'bindMobil';
  849. }else{
  850. $temple = 'bindMobilVLEmail';
  851. }
  852. }
  853. $result = (new \app\common\library\Mail)->sendCodeMailByType(session('front_account'), $velidate_info['info_data']['email'],$temple);
  854. }
  855. if(isset($result) && $result['status']){
  856. $this->jsonResult([],1,'发送成功');
  857. }else{
  858. $this->jsonResult([],0,$result['msg']);
  859. }
  860. }
  861. /**
  862. * 个人中心--绑定手机或邮箱--4 验证 手机或邮箱验证码
  863. */
  864. public function velidateCode(){
  865. $velidate_info = session('velidate_info');
  866. if (empty($velidate_info)) $this->redirect(getUserCenterUrl(1));
  867. $code = input('post.code' , 0 , 'intval');
  868. if (empty($code)) $this->jsonResult([],0,'请输入验证码');
  869. if ($velidate_info['velidate_type'] == 'mobile') {
  870. $result = (new \app\common\library\Sms)->checkCode($velidate_info['info_data']['mobile'] , $code);
  871. } else {
  872. $result = (new \app\common\library\Mail)->checkCode(session('front_account') , $velidate_info['info_data']['email'] , $code);
  873. }
  874. if (isset($result) && $result['status']) {
  875. $this->success('验证成功',getAccountUrl(2.2) );
  876. }
  877. $this->jsonResult([],0,$result['msg']);
  878. }
  879. /**
  880. * 个人中心--绑定手机或邮箱--5 直接绑定的页面
  881. */
  882. public function bindPage(){
  883. $velidate_info = session('velidate_info');
  884. if (empty($velidate_info)) $this->redirect(getUserCenterUrl(1));
  885. $this->assign('type',$velidate_info['type']);
  886. $appid = Config::get('SLIDER_VERIFICATION.APPID');
  887. $this->assign('appid',$appid);
  888. return $this->fetch();
  889. }
  890. /**
  891. * 个人中心--绑定手机或邮箱--6 发送验证码
  892. */
  893. public function bindSendCode(){
  894. $velidate_info = session('velidate_info');
  895. if (empty($velidate_info)) $this->error('系统繁忙');
  896. $this->directBindSendCode($velidate_info['type']);
  897. }
  898. /**
  899. * 个人中心--绑定手机或邮箱--直接绑定页面--6 发送验证码
  900. */
  901. public function directBindSendCode($type=''){
  902. $contact = $this->request->param('contact');
  903. if (empty($type)) $this->error('系统繁忙');
  904. if (empty($contact)) {
  905. if ($type == 'mobile') $this->error('请输入正确的手机号');
  906. $this->error('请输入正确的邮箱');
  907. }
  908. $Ticket = $this->request->param('ticket' , '' );
  909. $Randstr = $this->request->param('randstr' , '' );
  910. $slider = $this->sliderVelidate($Ticket,$Randstr);
  911. if (!$slider['code']) $this->jsonResult([],0,$slider['msg']);
  912. $velidate_info = session('velidate_info');
  913. if ($type == 'mobile' && $contact == $velidate_info['info_data']['mobile']){
  914. $this->error('新旧手机号不能相同');
  915. }
  916. if ($type == 'email' && $contact == $velidate_info['info_data']['email']){
  917. $this->error('新旧邮箱不能相同');
  918. }
  919. if ($type == 'mobile'){
  920. $result = (new \app\common\library\Sms)->sendCode($contact,$this->_bindMobile);
  921. }else{
  922. $result = (new \app\common\library\Mail)->sendCodeMailByType(session('front_account'), $contact,'bindEmail');
  923. }
  924. if(isset($result) && $result['status']){
  925. $this->jsonResult([],1,'发送成功');
  926. }
  927. $this->jsonResult([],0,$result['msg']);
  928. }
  929. /**
  930. * 个人中心--绑定手机或邮箱--7 进行绑定操作
  931. */
  932. public function bindContact(){
  933. $velidate_info = session('velidate_info');
  934. if (empty($velidate_info)) $this->error('系统繁忙');
  935. $this->directBindContact($velidate_info['type']);
  936. }
  937. /**
  938. * 个人中心--绑定手机或邮箱--7 进行绑定操作(直接进行绑定)
  939. */
  940. public function directBindContact($type = ''){
  941. $contact = $this->request->param('contact');
  942. $code = $this->request->param('code' , 0 , 'intval');
  943. if (!in_array($type,['mobile','email'])) $this->error('系统繁忙');
  944. if (empty($contact)) {
  945. if ($type == 'mobile') $this->error('请输入正确的手机号');
  946. $this->error('请输入正确的邮箱');
  947. }
  948. if (empty($code)) $this->jsonResult([],0,'请输入验证码');
  949. if ($type == 'mobile') {
  950. $result = (new \app\common\library\Sms)->checkCode($contact , $code);
  951. } else {
  952. $result = (new \app\common\library\Mail)->checkCode(session('front_account') , $contact , $code);
  953. }
  954. if (isset($result) && $result['status']) {
  955. $userid = session('front_userid');
  956. $res = model('Members')->save([$type => $contact],['id' => $userid]);
  957. model('MemberHistory')->insertGetId([$type => $contact,'userid'=> $userid,'ip' => GetIP(1),'create_time' => NOW_TIMESTAMP]);
  958. session('velidate_info',null);
  959. $this->success('绑定成功',getUserCenterUrl(4));
  960. }
  961. $this->jsonResult([],0,$result['msg'] );
  962. }
  963. /**
  964. * 滑块验证
  965. * @param $Ticket
  966. * @param $Randstr
  967. * @return array
  968. */
  969. public function sliderVelidate($Ticket,$Randstr){
  970. // todo 开发环境跳过滑块验证
  971. if (APP_STATUS == 'dev') return ['code'=>1,'msg'=>''];
  972. if ( empty($Ticket) || empty($Randstr) ) return ['code'=>0,'msg'=>'非法请求'];
  973. $appid = Config::get('SLIDER_VERIFICATION.APPID');
  974. $AppSecretKey = Config::get('SLIDER_VERIFICATION.AppSecretKey');
  975. $url = Config::get('SLIDER_VERIFICATION.VERIFYURL');
  976. $UserIP = GetIP(1);
  977. $params = array(
  978. "aid" => "$appid" ,
  979. "AppSecretKey" => $AppSecretKey ,
  980. "Ticket" => $Ticket ,
  981. "Randstr" => $Randstr ,
  982. "UserIP" => $UserIP
  983. );
  984. $paramstring = http_build_query($params);
  985. $content = txcurl($url,$paramstring);
  986. $result = json_decode($content,true);
  987. if($result){
  988. if($result['response'] == 1){
  989. return ['code'=>1,'msg'=>''];
  990. }else{
  991. return ['code'=>0,'msg'=>'系统繁忙,请稍后再试!'];
  992. }
  993. }else{
  994. return ['code'=>0,'msg'=>'系统繁忙,请稍后再试!'];
  995. }
  996. }
  997. /**
  998. * 我的游戏--搜索条件
  999. */
  1000. private function _paramMyGame(){
  1001. $keyword = input('title','');
  1002. $status = input('status',0);
  1003. $where = [
  1004. 'a.member_id' => session('front_userid') ,
  1005. ];
  1006. if ($keyword) $where['c.nickname'] = ['like','%'.$keyword.'%'];
  1007. if ($status == 1){
  1008. $where['c.cooperation_status'] = ['in',[0,1,2]];
  1009. $where['c.is_show'] = 1;
  1010. }elseif ($status == 2){
  1011. $where['c.cooperation_status'] = ['in',[0,1,2]];
  1012. $where['c.is_show'] = 0;
  1013. }elseif ($status == 3){
  1014. $where['c.cooperation_status'] = 3;
  1015. }
  1016. return $where;
  1017. }
  1018. /**
  1019. * 我的游戏
  1020. */
  1021. public function mygame($copydata = 0){
  1022. $this->_isLogin();
  1023. $GameCtr = (new \app\home\controller\Game);
  1024. $where = $this->_paramMyGame();
  1025. $num = 10;
  1026. $mobile = 1;
  1027. if ($copydata) {
  1028. $num = 8;
  1029. $mobile = 2;
  1030. }
  1031. $listArr = $GameCtr->_getMyGame($where,$mobile);
  1032. $list = $listArr['list'];
  1033. $gameidArr = $typeArr = $subjectArr = [];
  1034. if (count($list)) {
  1035. $data = $list->toArray()['data'];
  1036. $typeArr = array_unique(array_column($data , 'type'));
  1037. $subjectArr = array_unique(array_column($data , 'subject'));
  1038. $gameidArr = array_unique(array_column($data , 'id'));
  1039. }
  1040. $isrand = 1;
  1041. $condition = [];
  1042. if (count($typeArr) || count($subjectArr) || count($gameidArr)) {
  1043. $isrand = 0;
  1044. $typeArr = array_merge(array_diff($typeArr , array(0)));
  1045. $subjectArr = array_merge(array_diff($subjectArr , array(0)));
  1046. $gameidArr = array_merge(array_diff($gameidArr , array(0)));
  1047. $condition = [
  1048. 'game.id' => ['not in' , $gameidArr] ,
  1049. 'game.type' => ['in' , $typeArr] ,
  1050. 'game.subject' => ['in' , $subjectArr] ,
  1051. ];
  1052. }
  1053. $guesList = $GameCtr->_guessLikeGame($isrand , $condition,$num,$mobile);
  1054. if ($copydata) return ['list'=>$list, 'page'=>$listArr['page'], 'guesList'=>$guesList];
  1055. $this->assign('list' , $list);
  1056. $this->assign('page' , $listArr['page']);
  1057. $this->assign('guesList' , $guesList);
  1058. return $this->fetch();
  1059. }
  1060. /**
  1061. * 我的游戏分页
  1062. */
  1063. public function ajaxMyGame(){
  1064. $where = $this->_paramMyGame();
  1065. $GameCtr = (new \app\home\controller\Game);
  1066. $listArr = $GameCtr->_getMyGame($where);
  1067. if ($this->request->isAjax()) $this->jsonResult($listArr,1);
  1068. $this->jsonResult([],0,'请求错误!');
  1069. }
  1070. /**
  1071. * 用户头像上传
  1072. * 由于用户头像经过裁剪,前端传过来的是base64位的数据流,故要先保存在服务器,然后调接口上传到华为云,最后删除服务器上的图片。
  1073. * @return bool
  1074. */
  1075. public function uploadUserImg(){
  1076. $img = input('file','');
  1077. if (empty($img)) $this->error('请上传图片');
  1078. $urlData = $this->base64_image_content($img);
  1079. if (!$urlData['code']) $this->error($urlData['msg']);
  1080. $obs = new HuaweiObs();
  1081. $fileName = explode('usericon/',$urlData['url'])[1];
  1082. $dir = 'image/members/icons/';
  1083. $result = $obs->putObject($urlData['url'],$fileName,$dir);
  1084. unlink($urlData['url']);
  1085. if($result){
  1086. if($result['HttpStatusCode']=='200'){
  1087. // 上传成功,写库
  1088. model('Members')->save(['avatar'=>$dir.$fileName],['id'=>session('front_userid')]);
  1089. /*$this->_updateUserInfo(['avatar'=>$dir.$fileName]);*/
  1090. $this->jsonResult($dir.$fileName,1,'上传成功');
  1091. }
  1092. }
  1093. $this->error('网络出现错误,请稍后再试');
  1094. }
  1095. /**
  1096. * base64格式编码转换为图片并保存对应文件夹
  1097. * @param $base64_image_content
  1098. * @param $path runtime目录下
  1099. * @param $type 图片格式要求
  1100. * @param $max 图片大小,兆为单位
  1101. * @return bool|string
  1102. */
  1103. public function base64_image_content($base64_image_content,$path = 'usericon',$typeArr=['jpg','png'],$max=3){
  1104. $path = RUNTIME_PATH.$path;
  1105. //匹配出图片的格式
  1106. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)){
  1107. $type = $result[2];
  1108. if(count($typeArr) && !in_array($type,$typeArr)) return ['code'=>0,'msg'=>'图片格式不对,请重新上传'];
  1109. $new_file = $path."/";
  1110. if(!file_exists($new_file)){
  1111. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  1112. mkdir($new_file, 0700,true);
  1113. }
  1114. $url = date('YmdHi',time()).uniqid().rand(1,999).".{$type}";
  1115. $new_file = $new_file.$url;
  1116. if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)))){
  1117. if($max && ceil(filesize($new_file)/1024/1024) > $max) {
  1118. unlink($new_file);
  1119. return ['code'=>0,'msg'=>'图片过大,请重新上传'];
  1120. }
  1121. return ['code'=>1,'msg'=>'','url'=>$new_file];
  1122. }else{
  1123. return ['code'=>0,'msg'=>'上传失败,请稍后再试'];
  1124. }
  1125. }else{
  1126. return ['code'=>0,'msg'=>'上传失败,请稍后再试'];
  1127. }
  1128. }
  1129. /**
  1130. * 我要反馈
  1131. */
  1132. public function feedback(){
  1133. $kefu = model('Kefu')->cache(Config::get('QUERY_RESULT_CACHE_TIME'))->field('qq')->find();
  1134. $this->assign('kefu',$kefu['qq']);
  1135. return $this->fetch();
  1136. }
  1137. public function ajaxFeedback($from = ''){
  1138. $data = [
  1139. 'type' => input('post.type') ,
  1140. 'content' => input('post.content') ,
  1141. 'qq' => input('post.qq') ,
  1142. ];
  1143. if (empty($data['type'])) $this->error('请选择反馈类型','','type');
  1144. if (empty($data['content']) || mb_strlen($data['content'],'UTF8') < 5) $this->error('请至少输入5个字','','content');
  1145. if (mb_strlen($data['content'],'UTF8') > 500) $this->error('不可超过500个字','','content');
  1146. $regexp = "/^[1-9]\d{4,9}$/";
  1147. if (!empty($qq) && !preg_match($regexp,$qq)) $this->error('请输入正确的QQ号','','qq');
  1148. //图片上传
  1149. $imgUrl = '';
  1150. $imgobj = request()->file('file1');
  1151. if (!empty($imgobj)){
  1152. $file = new FileUpload();
  1153. foreach ($imgobj as $value) {
  1154. $bigimage_url = $file->set('allowExt' , 'jpg,jpeg,png')->set('maxsize' , 1024000 * 3)->set('dir' , 'image/webfeedback/')->upload($value);
  1155. if ( !empty($value) && $bigimage_url == false) {
  1156. $this->error('图片上传错误,请稍后再试','','img');
  1157. }
  1158. if ( !empty($bigimage_url))
  1159. $imgUrl .= $bigimage_url.',';
  1160. }
  1161. $imgUrl = substr($imgUrl , 0 , - 1);
  1162. }
  1163. $data['img_url'] = $imgUrl;
  1164. $data['create_time'] = NOW_TIMESTAMP;
  1165. $data['order_num'] = date("YmdHis" , NOW_TIMESTAMP) . rand(100 , 999);
  1166. if ( $from == 'mobile') $data['from'] = 2;
  1167. if ( !empty(session('front_userid'))) $data['user_id'] = session('front_userid');
  1168. model('WebFeedback')->insert($data);
  1169. $this->success('提交成功,感谢您的反馈。');
  1170. }
  1171. }