暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Users.php 124KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\user\controller;
  14. use think\Db;
  15. use think\Config;
  16. use think\Page;
  17. use think\Verify;
  18. use app\user\logic\SmtpmailLogic;
  19. class Users extends Base
  20. {
  21. public $smtpmailLogic;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->smtpmailLogic = new SmtpmailLogic;
  26. $this->users_db = Db::name('users'); // 会员数据表
  27. $this->users_level_db = Db::name('users_level'); // 会员等级表
  28. $this->users_parameter_db = Db::name('users_parameter'); // 会员属性表
  29. $this->users_list_db = Db::name('users_list'); // 会员属性信息表
  30. $this->users_config_db = Db::name('users_config');// 会员配置表
  31. $this->users_money_db = Db::name('users_money');// 会员金额明细表
  32. $this->smtp_record_db = Db::name('smtp_record');// 发送邮箱记录表
  33. $this->sms_log_db = Db::name('sms_log');// 发送手机记录表
  34. // 微信配置信息
  35. $this->pay_wechat_config = unserialize(getUsersConfigData('pay.pay_wechat_config'));
  36. // 查询部分模型开启信息 下载 视频 问答
  37. $partChannel = [];
  38. $usersOrderUrl = '';
  39. if (in_array(ACTION_NAME, ['index', 'article_index', 'download_index', 'media_index'])) {
  40. $where = [
  41. 'nid' => ['IN', ['media', 'article', 'download']]
  42. ];
  43. $partChannel = Db::name('channeltype')->where($where)->field('id, nid, ntitle, status, data')->order('id asc')->getAllWithIndex('nid');
  44. foreach ($partChannel as $key => $value) {
  45. $value['data'] = !empty($value['data']) ? json_decode($value['data'], true) : [];
  46. if ('media' == $key && !empty($this->eyou['global']['php_servicemeal']) && 1 < intval($this->eyou['global']['php_servicemeal'])) {
  47. $value['data']['is_media_pay'] = 1;
  48. }
  49. if (empty($usersOrderUrl)) {
  50. if (!empty($value['data']['is_article_pay']) && 1 === intval($value['data']['is_article_pay'])) {
  51. $usersOrderUrl = url('user/Users/article_index');
  52. } else if (!empty($value['data']['is_download_pay']) && 1 === intval($value['data']['is_download_pay'])) {
  53. $usersOrderUrl = url('user/Users/download_index');
  54. } else if (!empty($value['data']['is_media_pay']) && 1 === intval($value['data']['is_media_pay'])) {
  55. $usersOrderUrl = url('user/Users/media_index');
  56. }
  57. }
  58. $partChannel[$key] = $value;
  59. }
  60. }
  61. $this->assign('partChannel', $partChannel);
  62. $this->assign('usersOrderUrl', $usersOrderUrl);
  63. $isCount = Db::name('users_menu')->where([
  64. 'mca' => 'plugins/PointsShop/index',
  65. 'lang' => 'cn',
  66. ])->count();
  67. if (empty($isCount)) {
  68. Db::name('users_menu')->add([
  69. 'title' => '积分兑换',
  70. 'mca' => 'plugins/PointsShop/index',
  71. 'is_userpage' => 0,
  72. 'sort_order' => 100,
  73. 'status' => 1,
  74. 'lang' => 'cn',
  75. 'add_time' => getTime(),
  76. 'update_time' => getTime(),
  77. ]);
  78. }
  79. }
  80. // 会员中心首页
  81. public function index()
  82. {
  83. if (1 == config('global.opencodetype')) {
  84. return action('user/Users/index2');
  85. }
  86. if ($this->usersTplVersion == 'v1') {
  87. return action('user/Users/info');
  88. }
  89. $result = [];
  90. // 资料信息
  91. $result['users_para'] = model('Users')->getDataParaList($this->users_id);
  92. $this->assign('users_para', $result['users_para']);
  93. $eyou = array(
  94. 'field' => $result,
  95. );
  96. $this->assign('eyou', $eyou);
  97. // 是否绑定了微站点,否则自动绑定
  98. $referurl = '';
  99. if (!empty($this->users_id)) {
  100. auto_bind_wechatlogin($this->users, $referurl);
  101. if (!empty($referurl)) {
  102. header('Location: '. $referurl);
  103. exit;
  104. }
  105. }
  106. //其他数据
  107. $others = array();
  108. $users_id = $this->users_id;
  109. //收藏数
  110. $others['collect_num'] = Db::name('users_collection')->where(['users_id'=>$users_id])->count("id");
  111. //足迹
  112. $others['footprint_num'] = Db::name('users_footprint')->where(['users_id'=>$users_id])->count('id');
  113. //今日签到信息
  114. $others['signin_conf'] = getUsersConfigData('score');
  115. if ($others['signin_conf'] && isset($others['signin_conf']['score_signin_status']) && $others['signin_conf']['score_signin_status'] == 1) {
  116. $now_time = time();
  117. $today_start = mktime(0,0,0,date("m",$now_time),date("d",$now_time),date("Y",$now_time));
  118. $today_end = mktime(23,59,59,date("m",$now_time),date("d",$now_time),date("Y",$now_time));
  119. $others['signin_info'] = Db::name('users_signin')->where(['users_id'=>$users_id,'add_time'=>['BETWEEN',[$today_start,$today_end]]])->value("id");
  120. }
  121. //查询插件信息
  122. $weapp_menu_info = Db::name('users_menu')->field("id,title,version,mca")->where(['version'=>'weapp','status'=>1])->select();
  123. $others['weapp_menu_info'] = [];
  124. if ($weapp_menu_info) {
  125. $weapp_row = Db::name('weapp')->field("code,name,config")->where(['status'=>1])->getAllWithIndex('code');
  126. foreach ($weapp_menu_info as $k=>$v) {
  127. preg_match_all('/\/(\w+)\//i', $v['mca'],$preg_res);
  128. if (!empty($preg_res[1])) {
  129. $code_str = $preg_res[1][0];
  130. $weapp_info = empty($weapp_row[$code_str]) ? [] : $weapp_row[$code_str];
  131. if (empty($weapp_info)/* || ('PointsShop' == $weapp_info['code'] && empty($weapp_row['DiyminiproMall']))*/) {
  132. unset($weapp_menu_info[$k]);
  133. continue;
  134. }
  135. $weapp_menu_info[$k]['litpic'] = json_decode($weapp_info['config'],true)['litpic'];
  136. }
  137. }
  138. $others['weapp_menu_info'] = $weapp_menu_info;
  139. }
  140. $this->assign('others', $others);
  141. //查询部分模型开启信息 下载 视频 问答
  142. $part_channel = Db::name('channeltype')
  143. ->where('nid','in',['ask','download','media','article'])
  144. ->field('nid,status,data')
  145. ->getAllWithIndex('nid');
  146. if (!empty($part_channel['article']['data'])){
  147. $part_channel['article']['data'] = json_decode($part_channel['article']['data'], true);
  148. }
  149. if (!empty($part_channel['download']['data'])){
  150. $part_channel['download']['data'] = json_decode($part_channel['download']['data'], true);
  151. }
  152. $this->assign('part_channel', $part_channel);
  153. // 多语言
  154. $condition_bottom['a.status'] = array('eq', 1);
  155. $condition_bottom['a.display'] = array('eq', 1);
  156. $bottom_menu_list = Db::name('users_bottom_menu')->field('a.*')
  157. ->alias('a')
  158. ->where($condition_bottom)
  159. ->order('a.sort_order asc, a.id asc')
  160. ->limit(4)
  161. ->select();
  162. $this->assign('bottom_menu_list', $bottom_menu_list);
  163. // 问候语
  164. $hour = date('H');
  165. $greeting = '晚上好~';
  166. if (0 < intval($hour) && intval($hour) < 12) {
  167. $greeting = '早上好~';
  168. } else if (12 < intval($hour) && intval($hour) < 19) {
  169. $greeting = '下午好~';
  170. }
  171. $this->assign('greeting', $greeting);
  172. // 积分兑换是否已在用
  173. $shopLogic = new \app\admin\logic\ShopLogic;
  174. $useFunc = $shopLogic->useFuncLogic();
  175. $this->assign('useFunc', $useFunc);
  176. $clear_session_url = $this->root_dir."/index.php?m=api&c=Ajax&a=clear_session";
  177. $replace = <<<EOF
  178. <script type="text/javascript">
  179. clear_session();
  180. function clear_session()
  181. {
  182. $.ajax({
  183. url: "{$clear_session_url}",
  184. type: 'post',
  185. dataType: 'JSON',
  186. data: {_ajax: 1},
  187. success: function(res){
  188. }
  189. });
  190. }
  191. </script>
  192. </body>
  193. EOF;
  194. $html = $this->fetch('users_welcome');
  195. $html = str_ireplace('</body>', $replace, $html);
  196. return $html;
  197. }
  198. // 个人信息
  199. public function info()
  200. {
  201. $result = [];
  202. // 资料信息
  203. $result['users_para'] = model('Users')->getDataParaList($this->users_id);
  204. $this->assign('users_para', $result['users_para']);
  205. // 邮箱发送限制时间
  206. $this->assign('email_send_time', config('global.email_send_time'));
  207. // 手机发送限制时间
  208. $this->assign('mobile_send_time', config('global.mobile_send_time'));
  209. // 菜单名称
  210. $result['title'] = Db::name('users_menu')->where([
  211. 'mca' => 'user/Users/index',
  212. ])->getField('title');
  213. $eyou = array(
  214. 'field' => $result,
  215. );
  216. $this->assign('eyou', $eyou);
  217. $thirdparty = [];
  218. $loginApp = Db::name("weapp")->where(['code'=>['in',['QqLogin','WxLogin']]])->getAllWithIndex('code');
  219. //qq绑定信息
  220. if (!empty($loginApp['QqLogin']) && $loginApp['QqLogin']['status'] == 1){ //qq登陆插件安装且处于开启状态
  221. $qqlogin_config = json_decode($loginApp['QqLogin']['config'],true);
  222. if (!empty($qqlogin_config['version']) && $qqlogin_config['version'] >= 'v1.4.2'){
  223. try{
  224. $thirdparty['qq'] = Db::name("weapp_qqlogin")->where(['users_id'=>$this->users_id])->find();
  225. $thirdparty['is_qq'] = 1;
  226. }catch(\Exception $e){}
  227. }
  228. }
  229. //微信绑定信息
  230. if (!empty($loginApp['WxLogin']) && $loginApp['WxLogin']['status'] == 1){ //qq登陆插件安装且处于开启状态
  231. $wxlogin_config = json_decode($loginApp['WxLogin']['config'],true);
  232. if (!empty($wxlogin_config['version']) && $wxlogin_config['version'] >= 'v1.2.2'){
  233. try{
  234. $thirdparty['wx'] = Db::name("weapp_wxlogin")->where(['users_id'=>$this->users_id])->find();
  235. $thirdparty['is_wx'] = 1;
  236. }catch(\Exception $e){}
  237. }
  238. }
  239. $this->assign('thirdparty',$thirdparty);
  240. /*等保密码复杂度验证 start*/
  241. $pwdJsCode = '';
  242. if (is_dir('./weapp/Equal/')) {
  243. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  244. $pwdJsCode = $equalLogic->pwdJsCode();
  245. }
  246. if ('close' == $pwdJsCode) {
  247. $pwdJsCode = '';
  248. }
  249. $this->assign('pwdJsCode', $pwdJsCode);
  250. /*等保密码复杂度验证 end*/
  251. $html = $this->fetch('users_centre');
  252. // 会员模板版本号
  253. if ($this->usersTplVersion == 'v1') {
  254. /*第三方注册的用户,无需修改登录密码*/
  255. if (!empty($this->users['thirdparty'])) {
  256. $html = str_ireplace('onclick="ChangePwdMobile();"', 'onclick="ChangePwdMobile();" style="display: none;"', $html);
  257. $html = str_ireplace('onclick="ChangePwd();"', 'onclick="ChangePwd();" style="display: none;"', $html);
  258. }
  259. /*end*/
  260. // 美化昵称输入框
  261. $html = str_ireplace('type="text" name="nickname"', 'type="text" name="nickname" class="input-txt"', $html);
  262. }
  263. $token_input = token('__token_users_centre_update__');
  264. $replace =<<<EOF
  265. {$token_input}
  266. </form>
  267. EOF;
  268. $html = str_ireplace('</form>', $replace, $html);
  269. return $html;
  270. }
  271. // 会员选择登陆方式界面
  272. public function users_select_login()
  273. {
  274. // 若存在则调转至会员中心
  275. if ($this->users_id > 0) {
  276. $this->redirect('user/Users/centre');
  277. exit;
  278. }
  279. // 跳转链接
  280. $referurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : url("user/Users/centre");
  281. $referurl = strip_tags($referurl);
  282. session('eyou_referurl', $referurl);
  283. // 拼装url
  284. $result = [
  285. 'wechat_url' => url("user/Users/ajax_wechat_login"),
  286. 'website_url' => $this->root_dir . "/index.php?m=user&c=Users&a=login&website=website",
  287. ];
  288. // 若为微信端并且开启微商城模式则重定向
  289. if (isWeixin() && !empty($this->usersConfig['shop_micro'])) {
  290. $WeChatLoginConfig = !empty($this->usersConfig['wechat_login_config']) ? unserialize($this->usersConfig['wechat_login_config']) : [];
  291. if (!empty($WeChatLoginConfig)) {
  292. $this->redirect($result['wechat_url']);
  293. }
  294. }
  295. // 若后台功能设置-登录设置中,微信端本站登录为关闭状态,则直接跳转到微信授权页面
  296. if (isset($this->usersConfig['users_open_website_login']) && empty($this->usersConfig['users_open_website_login'])) {
  297. $this->redirect($result['wechat_url']);
  298. exit;
  299. }
  300. // 数据加载
  301. $eyou = array(
  302. 'field' => $result,
  303. );
  304. $this->assign('eyou', $eyou);
  305. // 默认开启验证码
  306. $is_vertify = 1;
  307. $users_login_captcha = config('captcha.users_login');
  308. if (!function_exists('imagettftext') || empty($users_login_captcha['is_on'])) {
  309. $is_vertify = 0; // 函数不存在,不符合开启的条件
  310. }
  311. $this->assign('is_vertify', $is_vertify);
  312. return $this->fetch('users_select_login');
  313. }
  314. // 使用ajax微信授权登陆
  315. public function ajax_wechat_login()
  316. {
  317. $WeChatLoginConfig = !empty($this->usersConfig['wechat_login_config']) ? unserialize($this->usersConfig['wechat_login_config']) : [];
  318. // 微信授权登陆
  319. if (!empty($WeChatLoginConfig['appid']) && !empty($WeChatLoginConfig['appsecret'])) {
  320. if (isMobile() && isWeixin()) {
  321. // 判断登陆成功跳转的链接,若为空则默认会员中心链接并存入session
  322. $referurl = session('eyou_referurl');
  323. if (empty($referurl)) {
  324. $referurl = url('user/Users/index', '', true, true);
  325. session('eyou_referurl', $referurl);
  326. }
  327. // 获取微信配置授权登陆
  328. $appid = $WeChatLoginConfig['appid'];
  329. $NewUrl = urlencode(url('user/Users/get_wechat_info', '', true, true));
  330. $ReturnUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appid . "&redirect_uri=" . $NewUrl . "&response_type=code&scope=snsapi_userinfo&state=eyoucms&#wechat_redirect";
  331. if (isset($this->usersConfig['users_open_website_login']) && empty($this->usersConfig['users_open_website_login'])) {
  332. $this->redirect($ReturnUrl);
  333. } else {
  334. if (IS_AJAX_POST) {
  335. $this->success('授权成功!', $ReturnUrl);
  336. } else {
  337. $this->redirect($ReturnUrl);
  338. }
  339. }
  340. }
  341. $this->error('非手机端微信、小程序,不可以使用微信登陆,请选择本站登陆!');
  342. }
  343. $this->error('后台微信配置尚未配置AppSecret,不可以微信登陆,请选择本站登陆!');
  344. }
  345. // 在微信端,非微站点登录成功后,进行授权获取openid
  346. public function auto_bind_wechat_info()
  347. {
  348. $eyou_referurl = session('eyou_referurl');
  349. if (empty($eyou_referurl)) {
  350. $eyou_referurl = url('user/Users/index', '', true, true);
  351. }
  352. // 微信配置信息
  353. $WeChatLoginConfig = !empty($this->usersConfig['wechat_login_config']) ? unserialize($this->usersConfig['wechat_login_config']) : [];
  354. $appid = $WeChatLoginConfig['appid'];
  355. $secret = $WeChatLoginConfig['appsecret'];
  356. $code = input('param.code/s');
  357. // 获取到会员openid
  358. $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $secret . '&code=' . $code . '&grant_type=authorization_code';
  359. $result = json_decode(httpRequest($url), true);
  360. // 授权过期,请重新授权
  361. if (empty($result) || (!empty($result['errcode']) && !empty($result['errmsg']))) $this->error('微信授权过期,请重新授权');
  362. // 授权成功,记录授权信息并重定向回原页面
  363. if (!empty($result) && !empty($result['openid'])) {
  364. // 记录微信授权 cookie
  365. model('ShopPublicHandle')->weChatauthorizeCookie($this->users_id, 'set', ['openid' => $result['openid'], 'expire' => 86400]);
  366. }
  367. // 重定向回原页面
  368. $this->redirect($eyou_referurl);
  369. // // 获取到会员openid
  370. // $get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $secret . '&code=' . $code . '&grant_type=authorization_code';
  371. // $data = httpRequest($get_token_url);
  372. // $WeChatData = json_decode($data, true);
  373. // if (empty($WeChatData) || (!empty($WeChatData['errcode']) && !empty($WeChatData['errmsg']))) {
  374. // session('auto_bind_wechat_info', '-1');
  375. // $this->redirect($eyou_referurl);
  376. // exit;
  377. // }
  378. // // 获取会员信息
  379. // $get_userinfo = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $WeChatData["access_token"] . '&openid=' . $WeChatData["openid"] . '&lang=zh_CN';
  380. // $UserInfo = httpRequest($get_userinfo);
  381. // $UserInfo = json_decode($UserInfo, true);
  382. // if (empty($UserInfo['nickname']) && empty($UserInfo['headimgurl'])) {
  383. // session('auto_bind_wechat_info', '-1');
  384. // $this->redirect($eyou_referurl);
  385. // exit;
  386. // }
  387. // $UserInfo['unionid'] = !empty($UserInfo['unionid']) ? $UserInfo['unionid'] : '';
  388. // $Users = $this->users_db->where(['users_id'=>$this->users_id])->find();
  389. // if (!empty($Users)) {
  390. // if (empty($Users['union_id']) && !empty($UserInfo['unionid'])){
  391. // $row = Db::name('users')->where(['union_id'=>$UserInfo['unionid']])->find();
  392. // if (empty($row)) {
  393. // $Users['union_id'] = $UserInfo['unionid'];
  394. // $this->users_db->where('users_id', $Users['users_id'])->update(['union_id'=>$UserInfo['unionid'],'update_time'=>getTime()]);
  395. // }
  396. // }
  397. // if (!empty($UserInfo['openid'])) {
  398. // $wxlogin_info = [];
  399. // if (is_dir('./weapp/WxLogin/')) {
  400. // $wxlogin_info = Db::name("weapp_wxlogin")->where(['users_id'=>$Users['users_id']])->find();
  401. // }
  402. // if (empty($Users['open_id']) || (isset($wxlogin_info['openid']) && $Users['open_id'] == $wxlogin_info['openid'])) {
  403. // $row = Db::name('users')->where(['union_id'=>$UserInfo['openid']])->find();
  404. // if (empty($row)) {
  405. // $Users['open_id'] = $UserInfo['openid'];
  406. // $this->users_db->where('users_id', $Users['users_id'])->update(['open_id'=>$UserInfo['openid'],'update_time'=>getTime()]);
  407. // }
  408. // }
  409. // }
  410. // // 已注册
  411. // session('users_id', $Users['users_id']);
  412. // session('users', $Users);
  413. // session('eyou_referurl', '');
  414. // cookie('users_id', $Users['users_id']);
  415. // $this->redirect($eyou_referurl);
  416. // exit;
  417. // } else {
  418. // session('auto_bind_wechat_info', '-1');
  419. // $this->redirect($eyou_referurl);
  420. // exit;
  421. // }
  422. }
  423. // 授权之后,获取会员信息
  424. public function get_wechat_info()
  425. {
  426. $WeChatLoginConfig = !empty($this->usersConfig['wechat_login_config']) ? unserialize($this->usersConfig['wechat_login_config']) : [];
  427. // 微信配置信息
  428. $appid = $WeChatLoginConfig['appid'];
  429. $secret = $WeChatLoginConfig['appsecret'];
  430. $code = input('param.code/s');
  431. // 获取到会员openid
  432. $get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $secret . '&code=' . $code . '&grant_type=authorization_code';
  433. $data = httpRequest($get_token_url);
  434. $WeChatData = json_decode($data, true);
  435. if (empty($WeChatData) || (!empty($WeChatData['errcode']) && !empty($WeChatData['errmsg']))) {
  436. $this->error('AppSecret错误或已过期', $this->root_dir.'/');
  437. }
  438. // 获取会员信息
  439. $get_userinfo = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $WeChatData["access_token"] . '&openid=' . $WeChatData["openid"] . '&lang=zh_CN';
  440. $UserInfo = httpRequest($get_userinfo);
  441. $UserInfo = json_decode($UserInfo, true);
  442. if (empty($UserInfo['nickname']) && empty($UserInfo['headimgurl'])) {
  443. $this->error('用户授权异常,建议清理手机缓存再进行登录', $this->root_dir.'/');
  444. }
  445. $UserInfo['unionid'] = !empty($UserInfo['unionid']) ? $UserInfo['unionid'] : '';
  446. $Users = [];
  447. if (!empty($UserInfo['unionid'])){
  448. // 查询这个unionid是否已注册
  449. $where = [
  450. 'union_id' => $UserInfo['unionid'],
  451. ];
  452. $Users = $this->users_db->where($where)->find();
  453. }
  454. if (empty($Users)){
  455. //根据openid和空union_id查询是否为老用户
  456. $where = [
  457. 'open_id' => $UserInfo['openid'],
  458. ];
  459. $Users = $this->users_db->where($where)->find();
  460. }
  461. if (!empty($Users)) {
  462. if (empty($Users['union_id']) && !empty($UserInfo['unionid'])){
  463. $Users['union_id'] = $UserInfo['unionid'];
  464. $this->users_db->where('users_id', $Users['users_id'])->update(['union_id'=>$UserInfo['unionid'],'update_time'=>getTime()]);
  465. }
  466. if (!empty($UserInfo['openid'])) {
  467. $wxlogin_info = [];
  468. if (is_dir('./weapp/WxLogin/')) {
  469. $wxlogin_info = Db::name("weapp_wxlogin")->where(['users_id'=>$Users['users_id']])->find();
  470. }
  471. if (empty($Users['open_id']) || (isset($wxlogin_info['openid']) && $Users['open_id'] == $wxlogin_info['openid'])) {
  472. $Users['open_id'] = $UserInfo['openid'];
  473. $this->users_db->where('users_id', $Users['users_id'])->update(['open_id'=>$UserInfo['openid'],'update_time'=>getTime()]);
  474. }
  475. }
  476. // 已注册
  477. $eyou_referurl = session('eyou_referurl');
  478. if (empty($eyou_referurl)) {
  479. $eyou_referurl = url('user/Users/index', '', true, true);
  480. }
  481. session('users_id', $Users['users_id']);
  482. session('users', $Users);
  483. session('eyou_referurl', '');
  484. cookie('users_id', $Users['users_id']);
  485. model('EyouUsers')->loginAfter($Users);
  486. $this->redirect($eyou_referurl);
  487. } else {
  488. // 未注册
  489. $username = substr($WeChatData['openid'], 6, 8);
  490. // 查询用户名是否已存在
  491. $result = $this->users_db->where('username', $username)->count();
  492. if (!empty($result)) {
  493. $username = $username . rand('100,999');
  494. }
  495. // 新增会员和微信绑定
  496. $UsersData = [
  497. 'username' => $username,
  498. 'nickname' => filterNickname($UserInfo['nickname']),
  499. 'open_id' => $WeChatData['openid'],
  500. 'password' => '', // 密码默认为空
  501. 'reg_time' => getTime(),
  502. 'last_ip' => clientIP(),
  503. 'last_login' => getTime(),
  504. 'is_activation' => 1, // 微信注册会员,默认开启激活
  505. 'register_place' => 2, // 前台微信注册会员
  506. 'thirdparty' => 5, // 微站点
  507. 'login_count' => Db::raw('login_count+1'),
  508. 'head_pic' => $UserInfo['headimgurl'],
  509. 'union_id' => $UserInfo['unionid'],
  510. 'lang' => $this->home_lang,
  511. ];
  512. //来源
  513. if (isMobile()){
  514. if (isWeixin()){
  515. $UsersData['source'] = 3;//1-PC端 2-H5 3-微信公众号/微站点 4-微信小程序 5-百度小程序 6-抖音小程序
  516. }else{
  517. $UsersData['source'] = 2;//1-PC端 2-H5 3-微信公众号 4-微信小程序 5-百度小程序 6-抖音小程序
  518. }
  519. }
  520. // 查询默认会员级别,存入会员表
  521. $level_id = $this->users_level_db->where([
  522. 'is_system' => 1,
  523. ])->getField('level_id');
  524. $UsersData['level'] = $level_id;
  525. $users_id = $this->users_db->add($UsersData);
  526. if (!empty($users_id)) {
  527. if (6 > strlen($users_id)){
  528. $users_id = sprintf("%06d",$users_id);//不足6位补0
  529. }
  530. $username = 'U'.$users_id;
  531. $username = rand_username($username, 'U', 3);
  532. $this->users_db->where('users_id', $users_id)->update(['username'=>$username,'update_time'=>getTime()]);
  533. // 新增成功,将会员信息存入session
  534. $eyou_referurl = session('eyou_referurl');
  535. if (empty($eyou_referurl)) {
  536. $eyou_referurl = url('user/Users/index', '', true, true);
  537. }
  538. $GetUsers = $this->users_db->where('users_id', $users_id)->find();
  539. session('users_id', $GetUsers['users_id']);
  540. session('users', $GetUsers);
  541. session('eyou_referurl', '');
  542. cookie('users_id', $GetUsers['users_id']);
  543. model('EyouUsers')->loginAfter($GetUsers);
  544. $this->redirect($eyou_referurl);
  545. } else {
  546. $this->error('未知错误,无法继续!');
  547. }
  548. }
  549. }
  550. // 登陆
  551. public function login()
  552. {
  553. /*$config = Config::get('session');
  554. var_dump($config);
  555. dump(config('session'));
  556. var_dump(session_id());
  557. echo session('openid');
  558. session('openid', '123456');
  559. die;*/
  560. // 若已登录则重定向
  561. if ($this->users_id > 0) $this->redirect('user/Users/centre');
  562. // 回跳路径
  563. $referurl = input('param.referurl/s', null, 'htmlspecialchars_decode,urldecode');
  564. if (empty($referurl)) {
  565. if (isset($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'], $this->request->host())) {
  566. $referurl = $_SERVER['HTTP_REFERER'];
  567. } else {
  568. $referurl = url("user/Users/centre");
  569. }
  570. }
  571. $referurl = strip_tags($referurl);
  572. // 切换账号后,在动态URL模式下登录404,与付费文档有关
  573. $referurl_2 = input('param.referurl/s', null, 'htmlspecialchars_decode');
  574. if (stristr($referurl_2, '&referurl=')) {
  575. parse_str($referurl_2, $parse);
  576. $referurl = str_replace("&referurl={$parse['referurl']}", "&referurl=".urlencode($parse['referurl']), $referurl);
  577. }
  578. session('eyou_referurl', $referurl);
  579. // 若为微信端并且开启微商城模式则重定向直接使用微信登录
  580. if (isWeixin() && !empty($this->usersConfig['shop_micro'])) {
  581. $WeChatLoginConfig = !empty($this->usersConfig['wechat_login_config']) ? unserialize($this->usersConfig['wechat_login_config']) : [];
  582. if (!empty($WeChatLoginConfig) && !IS_AJAX) {
  583. $this->redirect('user/Users/ajax_wechat_login');
  584. exit;
  585. }
  586. }
  587. // 若为微信端并且没有开启微商城模式则重定向到登录选择页
  588. $website = input('param.website/s');
  589. if (isWeixin() && empty($website)) $this->redirect('user/Users/users_select_login');
  590. // 默认开启验证码
  591. $is_vertify = 1;
  592. $users_login_captcha = config('captcha.users_login');
  593. if (!function_exists('imagettftext') || empty($users_login_captcha['is_on'])) {
  594. $is_vertify = 0; // 函数不存在,不符合开启的条件
  595. }
  596. $this->assign('is_vertify', $is_vertify);
  597. if (IS_AJAX_POST) {
  598. $post = input('post.');
  599. $post['username'] = trim($post['username']);
  600. if (empty($post['username'])) {
  601. $this->error('用户名不能为空!', null, ['status' => 1]);
  602. } else if (!preg_match("/^[\x{4e00}-\x{9fa5}\w\-\_\@\#]{2,30}$/u", $post['username'])) {
  603. $this->error('用户名不正确!', null, ['status' => 1]);
  604. }
  605. if (empty($post['password']) || !trim($post['password'])) {
  606. $this->error('密码不能为空!', null, ['status' => 1]);
  607. }
  608. if (1 == $is_vertify) {
  609. if (empty($post['vertify'])) {
  610. $this->error('图片验证码不能为空!', null, ['status' => 1]);
  611. }
  612. $verify = new Verify();
  613. if (!$verify->check($post['vertify'], "users_login")) {
  614. $this->error('验证码错误', null, ['status' => 'vertify']);
  615. }
  616. }
  617. $where = [];
  618. $rawStr = " username = '{$post['username']}' ";
  619. if (check_mobile($post['username'])) {
  620. $rawStr .= " OR (mobile = '{$post['username']}' AND is_mobile = 1)";
  621. }
  622. $where[] = Db::raw($rawStr);
  623. $users = $this->users_db->where($where)->find();
  624. if (!empty($users['is_del'])) $users = [];
  625. $uc_uid = 0;
  626. if (is_dir('./weapp/UCenter/')) {
  627. $ucenter = new \weapp\UCenter\logic\UCenterLogic();
  628. $uc_uid = $ucenter->uc_login_synlogin($post, $users);
  629. }
  630. if (!empty($users)) {
  631. if (!empty($users['admin_id'])) {
  632. // 后台账号不允许在前台通过账号密码登录,只能后台登录时同步到前台
  633. $this->error('前台禁止管理员登录!', null, ['status' => 'vertify']);
  634. }
  635. if (empty($users['is_activation'])) {
  636. $this->error('该会员尚未激活,请联系管理员!', null, ['status' => 'vertify']);
  637. }
  638. $users_id = $users['users_id'];
  639. /*等保密码复杂度验证 start*/
  640. if (is_dir('./weapp/Equal/')) {
  641. $equal_privkey = input('post.equal_privkey/s');
  642. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  643. $equalLogic->loginLogic($post['password'], $equal_privkey);
  644. }
  645. /*等保密码复杂度验证 end*/
  646. $encry_password = func_encrypt($post['password'], false, pwd_encry_type($users['password']));
  647. if ($uc_uid > 0 || strval($users['password']) === strval($encry_password)) {
  648. // 判断是前台还是后台注册的会员,后台注册不受注册验证影响,1为后台注册,2为前台注册。
  649. if (2 == $users['register_place']) {
  650. $usersVerificationRow = M('users_config')->where([
  651. 'name' => 'users_verification',
  652. ])->find();
  653. if ($usersVerificationRow['update_time'] <= $users['reg_time']) {
  654. // 判断是否需要后台审核
  655. if ($usersVerificationRow['value'] == 1 && $users['is_activation'] == 0) {
  656. $this->error('管理员审核中,请稍等!', null, ['status' => 2]);
  657. }
  658. }
  659. }
  660. // 会员users_id存入session
  661. model('EyouUsers')->loginAfter($users);
  662. $users_config = getUsersConfigData('users');
  663. if (!empty($users_config['users_login_jump_type']) && 1 == $users_config['users_login_jump_type']){
  664. $referurl = ROOT_DIR."/";//跳到首页
  665. }elseif (!empty($users_config['users_login_jump_type']) && 3 == $users_config['users_login_jump_type']){
  666. $referurl = url('user/Users/centre');//跳到会员中心
  667. }elseif (!empty($users_config['users_login_jump_type']) && 4 == $users_config['users_login_jump_type']){
  668. $referurl = htmlspecialchars_decode($users_config['users_login_jump_url']);//跳到自定义URL
  669. $referurl = strip_tags($referurl);
  670. }
  671. // 是否绑定了微站点,否则自动绑定
  672. auto_bind_wechatlogin($users, $referurl);
  673. $this->success('登录成功', $referurl);
  674. } else {
  675. $this->error('密码不正确!', null, ['status' => 'vertify']);
  676. }
  677. } else {
  678. $this->error('该用户名不存在,请注册!', null, ['status' => 'vertify']);
  679. }
  680. }
  681. /*微信登录插件 - 判断是否显示微信登录按钮*/
  682. $weapp_wxlogin = 0;
  683. if (is_dir('./weapp/WxLogin/')) {
  684. $wx = Db::name('weapp')->field('data,status,config')->where(['code' => 'WxLogin'])->find();
  685. if ($wx) {
  686. $wx['data'] = unserialize($wx['data']);
  687. if ($wx['status'] == 1 && $wx['data']['login_show'] == 1) {
  688. $weapp_wxlogin = 1;
  689. }
  690. // 使用场景 0 PC+手机 1 手机 2 PC
  691. $wx['config'] = json_decode($wx['config'], true);
  692. if (isMobile() && !in_array($wx['config']['scene'], [0,1])) {
  693. $weapp_wxlogin = 0;
  694. } else if (!isMobile() && !in_array($wx['config']['scene'], [0,2])) {
  695. $weapp_wxlogin = 0;
  696. }
  697. }
  698. }
  699. $this->assign('weapp_wxlogin', $weapp_wxlogin);
  700. /*end*/
  701. /*QQ登录插件 - 判断是否显示QQ登录按钮*/
  702. $weapp_qqlogin = 0;
  703. if (is_dir('./weapp/QqLogin/')) {
  704. $qq = Db::name('weapp')->field('data,status,config')->where(['code' => 'QqLogin'])->find();
  705. if (!empty($qq)) {
  706. $qq['data'] = unserialize($qq['data']);
  707. if ($qq['status'] == 1 && $qq['data']['login_show'] == 1) {
  708. $weapp_qqlogin = 1;
  709. }
  710. // 使用场景 0 PC+手机 1 手机 2 PC
  711. $qq['config'] = json_decode($qq['config'], true);
  712. if (isMobile() && !in_array($qq['config']['scene'], [0,1])) {
  713. $weapp_qqlogin = 0;
  714. } else if (!isMobile() && !in_array($qq['config']['scene'], [0,2])) {
  715. $weapp_qqlogin = 0;
  716. }
  717. }
  718. }
  719. $this->assign('weapp_qqlogin', $weapp_qqlogin);
  720. /*end*/
  721. /*微博插件 - 判断是否显示微博按钮*/
  722. $weapp_wblogin = 0;
  723. if (is_dir('./weapp/Wblogin/')) {
  724. $wb = Db::name('weapp')->field('data,status,config')->where(['code' => 'Wblogin'])->find();
  725. if (!empty($wb)) {
  726. $wb['data'] = unserialize($wb['data']);
  727. if ($wb['status'] == 1 && $wb['data']['login_show'] == 1) {
  728. $weapp_wblogin = 1;
  729. }
  730. // 使用场景 0 PC+手机 1 手机 2 PC
  731. $wb['config'] = json_decode($wb['config'], true);
  732. if (isMobile() && !in_array($wb['config']['scene'], [0,1])) {
  733. $weapp_wblogin = 0;
  734. } else if (!isMobile() && !in_array($wb['config']['scene'], [0,2])) {
  735. $weapp_wblogin = 0;
  736. }
  737. }
  738. }
  739. $this->assign('weapp_wblogin', $weapp_wblogin);
  740. /*end*/
  741. /*等保密码复杂度验证 start*/
  742. $pwdJsCode = '';
  743. if (is_dir('./weapp/Equal/')) {
  744. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  745. $pwdJsCode = $equalLogic->pwdJsCode();
  746. }
  747. if ('close' == $pwdJsCode) {
  748. $pwdJsCode = '';
  749. }
  750. $this->assign('pwdJsCode', $pwdJsCode);
  751. /*等保密码复杂度验证 end*/
  752. if (1 == config('global.opencodetype')) {
  753. $type = input('param.type/s');
  754. $this->assign('type', $type);
  755. }
  756. cookie('referurl', $referurl);
  757. $this->assign('referurl', $referurl);
  758. return $this->fetch('users_login');
  759. }
  760. // 手机号登陆
  761. public function mobile_login()
  762. {
  763. if (IS_AJAX_POST) {
  764. $post = input('post.');
  765. if (empty($post['mobile'])){
  766. $this->error('手机号码不能为空!', null, ['status' => 1]);
  767. }
  768. if (!check_mobile($post['mobile'])){
  769. $this->error('手机号码格式不正确!', null, ['status' => 1]);
  770. }
  771. if (empty($post['mobile_code'])) {
  772. $this->error('验证码不能为空!', null, ['status' => 1]);
  773. }
  774. // 验证验证码
  775. $RecordWhere = [
  776. 'source' => 2,
  777. 'mobile' => $post['mobile'],
  778. 'code' => $post['mobile_code'],
  779. 'is_use' => 0,
  780. 'lang' => $this->home_lang
  781. ];
  782. $is_verify = $this->sms_log_db->where($RecordWhere)->find();
  783. if (!empty($is_verify)){
  784. $RecordData = [
  785. 'is_use' => 1,
  786. 'update_time' => getTime()
  787. ];
  788. // 更新数据
  789. $this->sms_log_db->where($RecordWhere)->update($RecordData);
  790. }else{
  791. $this->error('验证码已失效!', null, ['status' => 1]);
  792. }
  793. $users = $this->users_db->where([
  794. 'mobile' => $post['mobile'],
  795. 'is_del' => 0,
  796. ])->find();
  797. if (!empty($users)) {
  798. if (!empty($users['admin_id'])) {
  799. // 后台账号不允许在前台通过账号密码登录,只能后台登录时同步到前台
  800. $this->error('前台禁止管理员登录!', null, ['status' => 'vertify']);
  801. }
  802. if (empty($users['is_activation'])) {
  803. $this->error('该会员尚未激活,请联系管理员!', null, ['status' => 'vertify']);
  804. }
  805. // 判断是前台还是后台注册的会员,后台注册不受注册验证影响,1为后台注册,2为前台注册。
  806. if (2 == $users['register_place']) {
  807. $usersVerificationRow = M('users_config')->where([
  808. 'name' => 'users_verification',
  809. ])->find();
  810. if ($usersVerificationRow['update_time'] <= $users['reg_time']) {
  811. // 判断是否需要后台审核
  812. if ($usersVerificationRow['value'] == 1 && $users['is_activation'] == 0) {
  813. $this->error('管理员审核中,请稍等!', null, ['status' => 2]);
  814. }
  815. }
  816. }
  817. // 会员users_id存入session
  818. model('EyouUsers')->loginAfter($users);
  819. $referurl = input('param.referurl/s', null, 'htmlspecialchars_decode,urldecode');
  820. if (empty($referurl)) {
  821. if (isset($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'], $this->request->host())) {
  822. $referurl = $_SERVER['HTTP_REFERER'];
  823. } else {
  824. $referurl = url("user/Users/centre");
  825. }
  826. }
  827. $referurl = strip_tags($referurl);
  828. session('eyou_referurl', $referurl);
  829. $users_config = getUsersConfigData('users');
  830. if (!empty($users_config['users_login_jump_type']) && 1 == $users_config['users_login_jump_type']){
  831. $referurl = ROOT_DIR."/";//跳到首页
  832. }elseif (!empty($users_config['users_login_jump_type']) && 3 == $users_config['users_login_jump_type']){
  833. $referurl = url('user/Users/centre');//跳到会员中心
  834. }elseif (!empty($users_config['users_login_jump_type']) && 4 == $users_config['users_login_jump_type']){
  835. $referurl = htmlspecialchars_decode($users_config['users_login_jump_url']);//跳到自定义URL
  836. $referurl = strip_tags($referurl);
  837. }
  838. // 是否绑定了微站点,否则自动绑定
  839. auto_bind_wechatlogin($users, $referurl);
  840. $this->success('登录成功', $referurl);
  841. } else {
  842. $this->error('该用户名不存在,请注册!', null, ['status' => 'vertify']);
  843. }
  844. }
  845. $this->error('请求错误', null, ['status' => 'vertify']);
  846. }
  847. // 会员注册
  848. public function reg()
  849. {
  850. if ($this->users_id > 0) {
  851. $url = url('user/Users/centre');
  852. $this->redirect($url);
  853. exit;
  854. }
  855. $is_vertify = 1; // 默认开启验证码
  856. $users_reg_captcha = config('captcha.users_reg');
  857. if (!function_exists('imagettftext') || empty($users_reg_captcha['is_on'])) {
  858. $is_vertify = 0; // 函数不存在,不符合开启的条件
  859. }
  860. $this->assign('is_vertify', $is_vertify);
  861. if (IS_AJAX_POST) {
  862. $post = input('post.');
  863. if (isset($post['username'])) {
  864. $post['username'] = trim($post['username']);
  865. $users_reg_notallow = explode(',', getUsersConfigData('users.users_reg_notallow'));
  866. if (!empty($users_reg_notallow)) {
  867. if (in_array($post['username'], $users_reg_notallow)) {
  868. $this->error('用户名为系统禁止注册!', null, ['status' => 1]);
  869. }
  870. }
  871. if (empty($post['username'])) {
  872. $this->error('用户名不能为空!', null, ['status' => 1]);
  873. } else if (!preg_match("/^[\x{4e00}-\x{9fa5}\w\-\_\@\#]{2,30}$/u", $post['username'])) {
  874. $this->error('请输入2-30位的汉字、英文、数字、下划线等组合', null, ['status' => 1]);
  875. }
  876. }
  877. if (isset($post['password'])) {
  878. if (empty($post['password']) || !trim($post['password'])) {
  879. $this->error('登录密码不能为空!', null, ['status' => 1]);
  880. }
  881. if (empty($post['password2']) || !trim($post['password2'])) {
  882. $this->error('重复密码不能为空!', null, ['status' => 1]);
  883. }
  884. /*等保密码复杂度验证 start*/
  885. if (is_dir('./weapp/Equal/')) {
  886. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  887. $eqData = $equalLogic->pwdValidate($post['password']);
  888. if (isset($eqData['code']) && empty($eqData['code'])) {
  889. $this->error($eqData['msg']);
  890. }
  891. }
  892. /*等保密码复杂度验证 end*/
  893. }
  894. if (1 == $is_vertify) {
  895. if (empty($post['vertify'])) {
  896. $this->error('图片验证码不能为空!', null, ['status' => 1]);
  897. }
  898. }
  899. if (isset($post['username'])) {
  900. $count = $this->users_db->where([
  901. 'username' => $post['username'],
  902. ])->count();
  903. if (!empty($count)) {
  904. $this->error('用户名已存在!', null, ['status' => 1]);
  905. }
  906. }
  907. if (isset($post['password'])) {
  908. $post['password'] = trim($post['password']);
  909. $post['password2'] = trim($post['password2']);
  910. if (empty($post['password']) && empty($post['password2'])) {
  911. $this->error('登录密码不能为空!', null, ['status' => 1]);
  912. } else {
  913. if ($post['password'] != $post['password2']) {
  914. $this->error('两次密码输入不一致!', null, ['status' => 1]);
  915. }
  916. }
  917. }
  918. // 处理会员属性数据
  919. $ParaData = [];
  920. if (isset($post['users_'])) {
  921. if (is_array($post['users_'])) {
  922. $ParaData = $post['users_'];
  923. }
  924. unset($post['users_']);
  925. }
  926. // 处理提交的会员属性中必填项是否为空
  927. // 必须传入提交的会员属性数组
  928. $EmptyData = model('Users')->isEmpty($ParaData, 'reg', 'array');
  929. if (!empty($EmptyData)) {
  930. if (is_array($EmptyData)) {
  931. $this->error($EmptyData['msg'], null, ['status' => 1, 'field'=>$EmptyData['field']]);
  932. } else {
  933. $this->error($EmptyData, null, ['status' => 1]);
  934. }
  935. }
  936. // 处理提交的会员属性中邮箱和手机是否已存在
  937. // IsRequired方法传入的参数有2个
  938. // 第一个必须传入提交的会员属性数组
  939. // 第二个users_id,注册时不需要传入,修改时需要传入。
  940. $RequiredData = model('Users')->isRequired($ParaData, '', 'reg');
  941. if (!empty($RequiredData) && !is_array($RequiredData)) {
  942. $this->error($RequiredData, null, ['status' => 1]);
  943. }
  944. // 处理判断验证码
  945. if (1 == $is_vertify) {
  946. $verify = new Verify();
  947. if (!$verify->check($post['vertify'], "users_reg")) {
  948. $this->error('图片验证码错误', null, ['status' => 'vertify']);
  949. }
  950. }
  951. if (is_dir('./weapp/UCenter/')) {
  952. $ucenter = new \weapp\UCenter\logic\UCenterLogic();
  953. $ucenter->uc_reg_synlogin($post, $RequiredData);
  954. }
  955. if (!empty($RequiredData['email'])) {
  956. // 查询会员输入的邮箱并且为找回密码来源的所有验证码
  957. $RecordWhere = [
  958. 'source' => 2,
  959. 'email' => $RequiredData['email'],
  960. 'users_id' => 0,
  961. 'status' => 0,
  962. 'lang' => $this->home_lang,
  963. ];
  964. $RecordData = [
  965. 'status' => 1,
  966. 'update_time' => getTime(),
  967. ];
  968. // 更新数据
  969. $this->smtp_record_db->where($RecordWhere)->update($RecordData);
  970. }
  971. if (!empty($RequiredData['mobile'])) {
  972. // 查询会员输入的邮箱并且为找回密码来源的所有验证码
  973. $RecordWhere = [
  974. 'source' => 0,
  975. 'mobile' => $RequiredData['mobile'],
  976. 'is_use' => 0,
  977. 'lang' => $this->home_lang
  978. ];
  979. $RecordData = [
  980. 'is_use' => 1,
  981. 'update_time' => getTime()
  982. ];
  983. // 更新数据
  984. $this->sms_log_db->where($RecordWhere)->update($RecordData);
  985. }
  986. // 会员设置
  987. $users_verification = !empty($this->usersConfig['users_verification']) ? $this->usersConfig['users_verification'] : 0;
  988. // 处理判断是否为后台审核,verification=1为后台审核。
  989. if (1 == $users_verification) $data['is_activation'] = 0;
  990. // 添加会员到会员表
  991. $data['username'] = !empty($post['username']) ? trim($post['username']) : 'yun'.getTime().rand(0,100);
  992. $data['nickname'] = !empty($post['nickname']) ? $post['nickname'] : $data['username'];
  993. if (0 == config('global.opencodetype')) {
  994. $data['password'] = func_encrypt($post['password'], false, pwd_encry_type('bcrypt'));
  995. }
  996. $data['is_mobile'] = !empty($ParaData['mobile_1']) ? 1 : 0;
  997. $data['is_email'] = !empty($ParaData['email_2']) ? 1 : 0;
  998. $data['head_pic'] = ROOT_DIR . '/public/static/common/images/dfboy.png';
  999. $data['reg_time'] = getTime();
  1000. $data['last_login'] = getTime();
  1001. $data['last_ip'] = clientIP();
  1002. $data['register_place'] = 2; // 注册位置,后台注册不受注册验证影响,1为后台注册,2为前台注册。
  1003. $data['lang'] = $this->home_lang;
  1004. //来源
  1005. if (isMobile()){
  1006. if (isWeixin()){
  1007. $data['source'] = 3;//1-PC端 2-H5 3-微信公众号/微站点 4-微信小程序 5-百度小程序 6-抖音小程序
  1008. }else{
  1009. $data['source'] = 2;//1-PC端 2-H5 3-微信公众号 4-微信小程序 5-百度小程序 6-抖音小程序
  1010. }
  1011. }
  1012. $level_id = $this->users_level_db->where([
  1013. 'is_system' => 1,
  1014. ])->getField('level_id');
  1015. $data['level'] = $level_id;
  1016. /*特定场景专用*/
  1017. $opencodetype = config('global.opencodetype');
  1018. if (1 == $opencodetype) {
  1019. $origin_mid = cookie('origin_mid');
  1020. if (!empty($origin_mid)) {
  1021. $data['origin_mid'] = intval($origin_mid);
  1022. }
  1023. $origin_type = cookie('origin_type');
  1024. if (!empty($origin_type)) {
  1025. $data['origin_type'] = intval($origin_type);
  1026. }
  1027. }
  1028. /*end*/
  1029. $users_id = $this->users_db->insertGetId($data);
  1030. // 判断会员是否添加成功
  1031. if (!empty($users_id)) {
  1032. $data['users_id'] = $users_id;
  1033. // 批量添加会员属性到属性信息表
  1034. if (!empty($ParaData)) {
  1035. $betchData = [];
  1036. $usersparaRow = $this->users_parameter_db->where([
  1037. 'is_hidden' => 0,
  1038. ])->getAllWithIndex('name');
  1039. foreach ($ParaData as $key => $value) {
  1040. if (preg_match('/(_code|_vertify)$/i', $key)) {
  1041. continue;
  1042. }elseif ('imgs' == $usersparaRow[$key]['dtype']){
  1043. $value = array_filter($value);
  1044. }
  1045. // 若为数组,则拆分成字符串
  1046. if (is_array($value)) $value = implode(',', $value);
  1047. $para_id = intval($usersparaRow[$key]['para_id']);
  1048. $betchData[] = [
  1049. 'users_id' => $users_id,
  1050. 'para_id' => $para_id,
  1051. 'info' => $value,
  1052. 'lang' => $this->home_lang,
  1053. 'add_time' => getTime(),
  1054. ];
  1055. }
  1056. $this->users_list_db->insertAll($betchData);
  1057. }
  1058. // 查询属性表的手机号码和邮箱地址,拼装数组$UsersListData
  1059. $UsersListData = model('Users')->getUsersListData('*', $users_id);
  1060. $UsersListData['login_count'] = 1;
  1061. $UsersListData['update_time'] = getTime();
  1062. if (2 == $users_verification) {
  1063. // 若开启邮箱验证并且通过邮箱验证则绑定到会员
  1064. $UsersListData['is_email'] = 1;
  1065. if (!isset($post['username'])) {
  1066. $username = rand_username();
  1067. $UsersListData['username'] = $username;
  1068. $UsersListData['nickname'] = $username;
  1069. }
  1070. } else if (3 == $users_verification) {
  1071. // 若开启手机验证并且通过手机验证则绑定到会员
  1072. $UsersListData['is_mobile'] = 1;
  1073. if (!isset($post['username'])) {
  1074. $new_username = 'yun'.substr($UsersListData['mobile'], -6);
  1075. $username = rand_username($new_username, 'yun', 2);
  1076. $UsersListData['username'] = $username;
  1077. $UsersListData['nickname'] = $username;
  1078. }
  1079. }
  1080. // 同步修改会员信息
  1081. $this->users_db->where('users_id', $users_id)->update($UsersListData);
  1082. // 回跳路径
  1083. $referurl = input('post.referurl/s', null, 'htmlspecialchars_decode,urldecode');
  1084. $referurl = strip_tags($referurl);
  1085. if (1 == config('global.opencodetype')) {
  1086. cookie('origin_type', null);
  1087. cookie('origin_mid', null);
  1088. }
  1089. session('users_id', $users_id);
  1090. if (session('users_id')) {
  1091. cookie('users_id', $users_id);
  1092. if (empty($users_verification)) {
  1093. // 无需审核,直接登陆
  1094. $url = !empty($referurl) ? $referurl : url('user/Users/centre');
  1095. // 是否绑定了微站点,否则自动绑定
  1096. auto_bind_wechatlogin($data, $url);
  1097. $this->success('注册成功,正在跳转中……', $url, ['status' => 3]);
  1098. } else if (1 == $users_verification) {
  1099. // 需要后台审核
  1100. session('users_id', null);
  1101. $url = url('user/Users/login');
  1102. $this->success('注册成功,等管理员激活才能登录!', $url, ['status' => 2]);
  1103. } else if (2 == $users_verification) {
  1104. // 注册成功
  1105. $url = !empty($referurl) ? $referurl : url('user/Users/centre');
  1106. // 是否绑定了微站点,否则自动绑定
  1107. auto_bind_wechatlogin($data, $url);
  1108. $this->success('注册成功,正在跳转中……', $url, ['status' => 0]);
  1109. } else if (3 == $users_verification) {
  1110. // 注册成功
  1111. $url = !empty($referurl) ? $referurl : url('user/Users/centre');
  1112. // 是否绑定了微站点,否则自动绑定
  1113. auto_bind_wechatlogin($data, $url);
  1114. $this->success('注册成功,正在跳转中……', $url, ['status' => 0]);
  1115. }
  1116. } else {
  1117. $url = url('user/Users/login');
  1118. $this->success('注册成功,请登录!', $url, ['status' => 2]);
  1119. }
  1120. }
  1121. $this->error('注册失败', null, ['status' => 4]);
  1122. }
  1123. // 会员属性资料信息
  1124. $users_para = model('Users')->getDataPara('reg');
  1125. $this->assign('users_para', $users_para);
  1126. // 跳转链接
  1127. $referurl = input('param.referurl/s');
  1128. if (empty($referurl)) {
  1129. if (isset($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'], $this->request->host())) {
  1130. $referurl = $_SERVER['HTTP_REFERER'];
  1131. } else {
  1132. $referurl = url("user/Users/centre");
  1133. }
  1134. } else {
  1135. $referurl = urldecode($referurl);
  1136. }
  1137. $referurl = strip_tags($referurl);
  1138. cookie('referurl', $referurl);
  1139. $this->assign('referurl', $referurl);
  1140. /*微信登录插件 - 判断是否显示微信登录按钮*/
  1141. $weapp_wxlogin = 0;
  1142. if (is_dir('./weapp/WxLogin/')) {
  1143. $wx = Db::name('weapp')->field('data,status,config')->where(['code' => 'WxLogin'])->find();
  1144. $wx['data'] = unserialize($wx['data']);
  1145. if ($wx['status'] == 1 && $wx['data']['login_show'] == 1) {
  1146. $weapp_wxlogin = 1;
  1147. }
  1148. // 使用场景 0 PC+手机 1 手机 2 PC
  1149. $wx['config'] = json_decode($wx['config'], true);
  1150. if (isMobile() && !in_array($wx['config']['scene'], [0,1])) {
  1151. $weapp_wxlogin = 0;
  1152. } else if (!isMobile() && !in_array($wx['config']['scene'], [0,2])) {
  1153. $weapp_wxlogin = 0;
  1154. }
  1155. }
  1156. $this->assign('weapp_wxlogin', $weapp_wxlogin);
  1157. /*end*/
  1158. /*QQ登录插件 - 判断是否显示QQ登录按钮*/
  1159. $weapp_qqlogin = 0;
  1160. if (is_dir('./weapp/QqLogin/')) {
  1161. $qq = Db::name('weapp')->field('data,status,config')->where(['code' => 'QqLogin'])->find();
  1162. $qq['data'] = unserialize($qq['data']);
  1163. if ($qq['status'] == 1 && $qq['data']['login_show'] == 1) {
  1164. $weapp_qqlogin = 1;
  1165. }
  1166. // 使用场景 0 PC+手机 1 手机 2 PC
  1167. $qq['config'] = json_decode($qq['config'], true);
  1168. if (isMobile() && !in_array($qq['config']['scene'], [0,1])) {
  1169. $weapp_qqlogin = 0;
  1170. } else if (!isMobile() && !in_array($qq['config']['scene'], [0,2])) {
  1171. $weapp_qqlogin = 0;
  1172. }
  1173. }
  1174. $this->assign('weapp_qqlogin', $weapp_qqlogin);
  1175. /*end*/
  1176. /*微博插件 - 判断是否显示微博按钮*/
  1177. $weapp_wblogin = 0;
  1178. if (is_dir('./weapp/Wblogin/')) {
  1179. $wb = Db::name('weapp')->field('data,status,config')->where(['code' => 'Wblogin'])->find();
  1180. $wb['data'] = unserialize($wb['data']);
  1181. if ($wb['status'] == 1 && $wb['data']['login_show'] == 1) {
  1182. $weapp_wblogin = 1;
  1183. }
  1184. // 使用场景 0 PC+手机 1 手机 2 PC
  1185. $wb['config'] = json_decode($wb['config'], true);
  1186. if (isMobile() && !in_array($wb['config']['scene'], [0,1])) {
  1187. $weapp_wblogin = 0;
  1188. } else if (!isMobile() && !in_array($wb['config']['scene'], [0,2])) {
  1189. $weapp_wblogin = 0;
  1190. }
  1191. }
  1192. $this->assign('weapp_wblogin', $weapp_wblogin);
  1193. /*end*/
  1194. /*等保密码复杂度验证 start*/
  1195. $pwdJsCode = '';
  1196. if (is_dir('./weapp/Equal/')) {
  1197. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  1198. $pwdJsCode = $equalLogic->pwdJsCode();
  1199. }
  1200. if ('close' == $pwdJsCode) {
  1201. $pwdJsCode = '';
  1202. }
  1203. $this->assign('pwdJsCode', $pwdJsCode);
  1204. /*等保密码复杂度验证 end*/
  1205. $html = $this->fetch('users_reg');
  1206. if (!empty($pwdJsCode) && !stristr($html, "var password_value = $.trim(password.val());")) {
  1207. $str = <<<EOF
  1208. {$pwdJsCode}
  1209. if (password2.val() != password.val()) {
  1210. EOF;
  1211. $html = str_ireplace('if (password2.val() != password.val()) {', $str, $html);
  1212. }
  1213. if (isMobile()) {
  1214. $str = <<<EOF
  1215. <div id="update_mobile_file" style="display: none;">
  1216. <form id="form1" style="text-align: center;" >
  1217. <input type="button" value="点击上传" onclick="up_f.click();" class="btn btn-primary form-control"/><br>
  1218. <p><input type="file" id="up_f" name="up_f" onchange="MobileHeadPic();" style="display:none"/></p>
  1219. </form>
  1220. </div>
  1221. </body>
  1222. EOF;
  1223. $html = str_ireplace('</body>', $str, $html);
  1224. }
  1225. return $html;
  1226. }
  1227. // 会员手机注册
  1228. public function mobile_reg()
  1229. {
  1230. if (IS_AJAX_POST) {
  1231. $post = input('post.');
  1232. if (empty($post['mobile'])){
  1233. $this->error('手机号码不能为空!', null, ['status' => 1]);
  1234. }
  1235. if (!check_mobile($post['mobile'])){
  1236. $this->error('手机号码格式不正确!', null, ['status' => 1]);
  1237. }
  1238. //查询手机号是否已经注册过
  1239. $is_reg = Db::name('users')->where('mobile',$post['mobile'])->find();
  1240. if (!empty($is_reg)){
  1241. $this->error('手机号码已经注册!', null, ['status' => 1]);
  1242. }
  1243. if (empty($post['mobile_code'])) {
  1244. $this->error('验证码不能为空!', null, ['status' => 1]);
  1245. }
  1246. // 验证验证码
  1247. $RecordWhere = [
  1248. 'source' => 0,
  1249. 'mobile' => $post['mobile'],
  1250. 'code' => $post['mobile_code'],
  1251. 'is_use' => 0,
  1252. 'lang' => $this->home_lang
  1253. ];
  1254. $is_verify = $this->sms_log_db->where($RecordWhere)->find();
  1255. if (!empty($is_verify)){
  1256. $RecordData = [
  1257. 'is_use' => 1,
  1258. 'update_time' => getTime()
  1259. ];
  1260. // 更新数据
  1261. $this->sms_log_db->where($RecordWhere)->update($RecordData);
  1262. }else{
  1263. $this->error('验证码已失效!', null, ['status' => 1]);
  1264. }
  1265. // 会员设置
  1266. $users_verification = !empty($this->usersConfig['users_verification']) ? $this->usersConfig['users_verification'] : 0;
  1267. // 处理判断是否为后台审核,verification=1为后台审核。
  1268. if (1 == $users_verification) $data['is_activation'] = 0;
  1269. // 添加会员到会员表
  1270. $data['username'] = rand_username('tel' . substr($post['mobile'], -6), 'tel');
  1271. $data['nickname'] = $data['username'];
  1272. $data['is_mobile'] = !empty($post['mobile']) ? 1 : 0;
  1273. $data['mobile'] = $post['mobile'];
  1274. $data['head_pic'] = ROOT_DIR . '/public/static/common/images/dfboy.png';
  1275. $data['reg_time'] = getTime();
  1276. $data['last_login'] = getTime();
  1277. $data['last_ip'] = clientIP();
  1278. $data['register_place'] = 2; // 注册位置,后台注册不受注册验证影响,1为后台注册,2为前台注册。
  1279. $data['lang'] = $this->home_lang;
  1280. $level_id = $this->users_level_db->where([
  1281. 'is_system' => 1,
  1282. ])->getField('level_id');
  1283. $data['level'] = $level_id;
  1284. //来源
  1285. if (isMobile()){
  1286. if (isWeixin()){
  1287. $data['source'] = 3;//1-PC端 2-H5 3-微信公众号/微站点 4-微信小程序 5-百度小程序 6-抖音小程序
  1288. }else{
  1289. $data['source'] = 2;//1-PC端 2-H5 3-微信公众号 4-微信小程序 5-百度小程序 6-抖音小程序
  1290. }
  1291. }
  1292. $users_id = $this->users_db->insertGetId($data);
  1293. // 判断会员是否添加成功
  1294. if (!empty($users_id)) {
  1295. $data['users_id'] = $users_id;
  1296. Db::name('users_list')->insert(['users_id'=>$users_id,'para_id'=>1,'info'=>$post['mobile'],'add_time'=>getTime(),'update_time'=>getTime()]);
  1297. // 回跳路径
  1298. $referurl = input('post.referurl/s', null, 'htmlspecialchars_decode,urldecode');
  1299. $referurl = strip_tags($referurl);
  1300. session('users_id', $users_id);
  1301. if (session('users_id')) {
  1302. cookie('users_id', $users_id);
  1303. if (empty($users_verification)) {
  1304. // 无需审核,直接登陆
  1305. $url = !empty($referurl) ? $referurl : url('user/Users/centre');
  1306. // 是否绑定了微站点,否则自动绑定
  1307. auto_bind_wechatlogin($data, $url);
  1308. $this->success('注册成功,正在跳转中……', $url, ['status' => 3]);
  1309. } else if (1 == $users_verification) {
  1310. // 需要后台审核
  1311. session('users_id', null);
  1312. $url = url('user/Users/login');
  1313. $this->success('注册成功,等管理员激活才能登录!', $url, ['status' => 2]);
  1314. } else if (2 == $users_verification) {
  1315. // 注册成功
  1316. $url = !empty($referurl) ? $referurl : url('user/Users/centre');
  1317. // 是否绑定了微站点,否则自动绑定
  1318. auto_bind_wechatlogin($data, $url);
  1319. $this->success('注册成功,正在跳转中……', $url, ['status' => 0]);
  1320. } else if (3 == $users_verification) {
  1321. // 注册成功
  1322. $url = !empty($referurl) ? $referurl : url('user/Users/centre');
  1323. // 是否绑定了微站点,否则自动绑定
  1324. auto_bind_wechatlogin($data, $url);
  1325. $this->success('注册成功,正在跳转中……', $url, ['status' => 0]);
  1326. }
  1327. } else {
  1328. $url = url('user/Users/login');
  1329. $this->success('注册成功,请登录!', $url, ['status' => 2]);
  1330. }
  1331. }
  1332. $this->error('注册失败', null, ['status' => 4]);
  1333. }
  1334. }
  1335. // 会员中心
  1336. public function centre()
  1337. {
  1338. $mca = Db::name('users_menu')->where(['is_userpage' => 1])->getField('mca');
  1339. $mca = !empty($mca) ? $mca : 'user/Users/index';
  1340. $this->redirect($mca);
  1341. }
  1342. // 修改资料
  1343. public function centre_update()
  1344. {
  1345. if (IS_AJAX_POST) {
  1346. $post = input('post.');
  1347. if ($this->usersTplVersion != 'v1') {
  1348. if (!empty($post['password_edit']) && trim($post['password_edit'])) {
  1349. $password_new = func_encrypt($post['password_edit'], false, pwd_encry_type('bcrypt'));
  1350. }
  1351. }
  1352. /*if (empty($this->users['password'])) {
  1353. // 密码为空则表示第三方注册会员,强制设置密码
  1354. if (empty($post['password'])) {
  1355. $this->error('第三方注册会员,为确保账号安全,请设置密码。');
  1356. } else {
  1357. $password_new = func_encrypt($post['password'], false, pwd_encry_type('bcrypt'));
  1358. }
  1359. }*/
  1360. if (!empty($password_new) && trim($password_new)) {
  1361. /*等保密码复杂度验证 start*/
  1362. if (is_dir('./weapp/Equal/')) {
  1363. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  1364. $eqData = $equalLogic->pwdValidate($post['password_edit']);
  1365. if (isset($eqData['code']) && empty($eqData['code'])) {
  1366. $this->error($eqData['msg']);
  1367. }
  1368. }
  1369. /*等保密码复杂度验证 end*/
  1370. }
  1371. $nickname = trim($post['nickname']);
  1372. if (!empty($post['nickname']) && empty($nickname)) {
  1373. $this->error('昵称不可为纯空格');
  1374. }
  1375. $ParaData = [];
  1376. if (isset($post['users_'])){
  1377. if (is_array($post['users_'])) {
  1378. $ParaData = $post['users_'];
  1379. }
  1380. unset($post['users_']);
  1381. }
  1382. // 处理提交的会员属性中必填项是否为空
  1383. // 必须传入提交的会员属性数组
  1384. $EmptyData = model('Users')->isEmpty($ParaData);
  1385. if (!empty($EmptyData)) $this->error($EmptyData);
  1386. // 处理提交的会员属性中邮箱和手机是否已存在
  1387. // IsRequired方法传入的参数有2个
  1388. // 第一个必须传入提交的会员属性数组
  1389. // 第二个users_id,注册时不需要传入,修改时需要传入。
  1390. $RequiredData = model('Users')->isRequired($ParaData, $this->users_id);
  1391. if (!empty($RequiredData)) $this->error($RequiredData);
  1392. // 处理数据验证
  1393. $validata = ['users_id'=>$this->users_id, '__token_users_centre_update__'=>$post['__token_users_centre_update__']];
  1394. $error = handleEyouDataValidate('users_id', '__token_users_centre_update__', $validata);
  1395. if (!empty($error)) $this->error($error);
  1396. /*处理属性表的数据修改添加*/
  1397. $row2 = $this->users_parameter_db->field('para_id,name,dtype')->getAllWithIndex('name');
  1398. if (!empty($row2)) {
  1399. foreach ($ParaData as $key => $value) {
  1400. if (!isset($row2[$key]) || in_array($row2[$key]['dtype'], ['mobile','email'])) {
  1401. continue;
  1402. }elseif ('imgs' == $row2[$key]['dtype']){
  1403. $value = array_filter($value);
  1404. }
  1405. // 若为数组,则拆分成字符串
  1406. if (is_array($value)) {
  1407. $value = implode(',', $value);
  1408. }
  1409. $data = [];
  1410. $para_id = intval($row2[$key]['para_id']);
  1411. $where = [
  1412. 'users_id' => $this->users_id,
  1413. 'para_id' => $para_id,
  1414. ];
  1415. if ('date' == $row2[$key]['dtype'] && !empty($value)){
  1416. $data['info'] = strtotime($value);
  1417. }else{
  1418. $data['info'] = $value;
  1419. }
  1420. $data['update_time'] = getTime();
  1421. // 若信息表中无数据则添加
  1422. $row = $this->users_list_db->where($where)->count();
  1423. if (empty($row)) {
  1424. $data['users_id'] = $this->users_id;
  1425. $data['para_id'] = $para_id;
  1426. $data['lang'] = $this->home_lang;
  1427. $data['add_time'] = getTime();
  1428. $this->users_list_db->add($data);
  1429. } else {
  1430. $this->users_list_db->where($where)->update($data);
  1431. }
  1432. }
  1433. }
  1434. // 查询属性表的手机和邮箱信息,同步修改会员信息
  1435. $usersData = model('Users')->getUsersListData('*', $this->users_id);
  1436. $usersData['nickname'] = trim($post['nickname']);
  1437. if (!empty($password_new) && trim($password_new)) $usersData['password'] = $password_new;
  1438. if (!empty($post['head_pic']) && !empty($post['head_pic_edit'])) $usersData['head_pic'] = $post['head_pic'];
  1439. $usersData['update_time'] = getTime();
  1440. $return = $this->users_db->where('users_id', $this->users_id)->update($usersData);
  1441. if ($return !== false) {
  1442. \think\Cache::clear('users_list');
  1443. $this->success('操作成功');
  1444. }
  1445. $this->error('操作失败');
  1446. }
  1447. $this->error('访问错误!');
  1448. }
  1449. // 更改密码
  1450. public function change_pwd()
  1451. {
  1452. if (IS_AJAX_POST) {
  1453. $post = input('post.');
  1454. if (empty($post['oldpassword']) || !trim($post['oldpassword'])) {
  1455. $this->error('原密码不能为空!');
  1456. } else if (empty($post['password']) || !trim($post['password'])) {
  1457. $this->error('新密码不能为空!');
  1458. } else if ($post['password'] != $post['password2']) {
  1459. $this->error('重复密码与新密码不一致!');
  1460. }
  1461. $users = $this->users_db->field('password')->where([
  1462. 'users_id' => $this->users_id,
  1463. ])->find();
  1464. if (!empty($users)) {
  1465. $encry_password = func_encrypt($post['oldpassword'], false, pwd_encry_type($users['password']));
  1466. if (strval($users['password']) !== strval($encry_password)) {
  1467. $this->error('原密码错误,请重新输入!');
  1468. }
  1469. $r = $this->users_db->where([
  1470. 'users_id' => $this->users_id,
  1471. ])->update([
  1472. 'password' => func_encrypt($post['password'], false, pwd_encry_type('bcrypt')),
  1473. 'update_time' => getTime(),
  1474. ]);
  1475. if ($r) {
  1476. $this->success('修改成功');
  1477. }
  1478. $this->error('修改失败');
  1479. }
  1480. $this->error('登录失效,请重新登录!');
  1481. }
  1482. return $this->fetch('users_change_pwd');
  1483. }
  1484. // 找回密码
  1485. public function retrieve_password()
  1486. {
  1487. if ($this->users_id > 0) $this->redirect('user/Users/centre');
  1488. if (!empty($this->usersConfig['users_retrieve_password']) && 2 == $this->usersConfig['users_retrieve_password']) {
  1489. $this->redirect('user/Users/retrieve_password_mobile');
  1490. }
  1491. $is_vertify = 1; // 默认开启验证码
  1492. $users_retrieve_pwd_captcha = config('captcha.users_retrieve_password');
  1493. if (!function_exists('imagettftext') || empty($users_retrieve_pwd_captcha['is_on'])) {
  1494. $is_vertify = 0; // 函数不存在,不符合开启的条件
  1495. }
  1496. $this->assign('is_vertify', $is_vertify);
  1497. if (IS_AJAX_POST) {
  1498. $post = input('post.');
  1499. // POST数据基础判断
  1500. if (empty($post['email'])) {
  1501. $this->error('邮箱地址不能为空!');
  1502. }
  1503. if (1 == $is_vertify) {
  1504. if (empty($post['vertify'])) {
  1505. $this->error('图片验证码不能为空!');
  1506. }
  1507. }
  1508. if (empty($post['email_code'])) {
  1509. $this->error('邮箱验证码不能为空!');
  1510. }
  1511. // 判断会员输入的邮箱是否存在
  1512. $ListWhere = array(
  1513. 'info' => array('eq', $post['email']),
  1514. );
  1515. $ListData = $this->users_list_db->where($ListWhere)->field('users_id')->find();
  1516. if (empty($ListData)) {
  1517. $this->error('邮箱不存在,不能找回密码!');
  1518. }
  1519. // 判断会员输入的邮箱是否已绑定
  1520. $UsersWhere = array(
  1521. 'email' => array('eq', $post['email']),
  1522. );
  1523. $UsersData = $this->users_db->where($UsersWhere)->field('is_email')->find();
  1524. if (empty($UsersData['is_email'])) {
  1525. $this->error('邮箱未绑定,不能找回密码!');
  1526. }
  1527. // 查询会员输入的邮箱验证码是否存在
  1528. $RecordWhere = [
  1529. 'code' => $post['email_code'],
  1530. 'lang' => $this->home_lang,
  1531. 'email' => ['eq', $post['email']],
  1532. 'users_id' => $ListData['users_id'],
  1533. ];
  1534. $RecordData = $this->smtp_record_db->where($RecordWhere)->field('status,add_time,email')->find();
  1535. if (!empty($RecordData)) {
  1536. // 邮箱验证码是否超时
  1537. $time = getTime();
  1538. $RecordData['add_time'] += Config::get('global.email_default_time_out');
  1539. if ('1' == $RecordData['status'] || $RecordData['add_time'] <= $time) {
  1540. $this->error('邮箱验证码已被使用或超时,请重新发送!');
  1541. } else {
  1542. // 图形验证码判断
  1543. if (1 == $is_vertify) {
  1544. $verify = new Verify();
  1545. if (!$verify->check($post['vertify'], "users_retrieve_password")) {
  1546. $this->error('图形验证码错误,请重新输入!');
  1547. }
  1548. }
  1549. session('users_retrieve_password_email', $post['email']); // 标识邮箱验证通过
  1550. $em = rand(10, 99) . base64_encode($post['email']) . '/=';
  1551. $url = url('user/Users/reset_password', ['em' => base64_encode($em)]);
  1552. $this->success('操作成功', $url);
  1553. }
  1554. } else {
  1555. $this->error('邮箱验证码不正确,请重新输入!');
  1556. }
  1557. }
  1558. session('users_retrieve_password_email', null); // 标识邮箱验证通过
  1559. /*检测会员邮箱属性是否开启*/
  1560. $usersparamRow = $this->users_parameter_db->where([
  1561. 'name' => ['LIKE', 'email_%'],
  1562. 'is_hidden' => 1,
  1563. ])->find();
  1564. if (!empty($usersparamRow)) {
  1565. $this->error('会员邮箱属性已关闭,请联系网站管理员 !');
  1566. }
  1567. /*--end*/
  1568. return $this->fetch();
  1569. }
  1570. // 重置密码
  1571. public function reset_password()
  1572. {
  1573. if (IS_AJAX_POST) {
  1574. $post = input('post.');
  1575. if (empty($post['password']) || !trim($post['password'])) {
  1576. $this->error('新密码不能为空!');
  1577. }
  1578. if ($post['password'] != $post['password_']) {
  1579. $this->error('两次密码输入不一致!');
  1580. }
  1581. /*等保密码复杂度验证 start*/
  1582. if (is_dir('./weapp/Equal/')) {
  1583. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  1584. $eqData = $equalLogic->pwdValidate($post['password']);
  1585. if (isset($eqData['code']) && empty($eqData['code'])) {
  1586. $this->error($eqData['msg']);
  1587. }
  1588. }
  1589. /*等保密码复杂度验证 end*/
  1590. $email = session('users_retrieve_password_email');
  1591. if (!empty($email)) {
  1592. // 处理数据验证
  1593. $validata = ['email'=>$email, '__token_reset_password__'=>$post['__token_reset_password__']];
  1594. $error = handleEyouDataValidate('email', '__token_reset_password__', $validata);
  1595. if (!empty($error)) $this->error($error);
  1596. $data = [
  1597. 'password' => func_encrypt($post['password'], false, pwd_encry_type('bcrypt')),
  1598. 'update_time' => getTime(),
  1599. ];
  1600. $return = $this->users_db->where([
  1601. 'email' => $email,
  1602. ])->update($data);
  1603. if ($return) {
  1604. session('users_retrieve_password_email', null); // 标识邮箱验证通过
  1605. $url = url('user/Users/login');
  1606. $this->success('重置成功!', $url);
  1607. }
  1608. }
  1609. $this->error('重置失败!');
  1610. }
  1611. // 没有传入邮箱,重定向至找回密码页面
  1612. $em = input('param.em/s');
  1613. $em = base64_decode(input('param.em/s'));
  1614. $em = base64_decode(msubstr($em, 2, -2));
  1615. $email = session('users_retrieve_password_email');
  1616. if (empty($email) || !check_email($em) || $em != $email) {
  1617. $this->redirect('user/Users/retrieve_password');
  1618. exit;
  1619. }
  1620. $users = $this->users_db->where([
  1621. 'email' => $email,
  1622. ])->find();
  1623. if (!empty($users)) {
  1624. // 查询会员输入的邮箱并且为找回密码来源的所有验证码
  1625. $RecordWhere = [
  1626. 'source' => 4,
  1627. 'email' => $email,
  1628. 'users_id' => 0,
  1629. 'status' => 0,
  1630. 'lang' => $this->home_lang,
  1631. ];
  1632. // 更新数据
  1633. $RecordData = [
  1634. 'status' => 1,
  1635. 'update_time' => getTime(),
  1636. ];
  1637. $this->smtp_record_db->where($RecordWhere)->update($RecordData);
  1638. }
  1639. $this->assign('users', $users);
  1640. /*等保密码复杂度验证 start*/
  1641. $pwdJsCode = '';
  1642. if (is_dir('./weapp/Equal/')) {
  1643. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  1644. $pwdJsCode = $equalLogic->pwdJsCode();
  1645. }
  1646. if ('close' == $pwdJsCode) {
  1647. $pwdJsCode = '';
  1648. }
  1649. $this->assign('pwdJsCode', $pwdJsCode);
  1650. /*等保密码复杂度验证 end*/
  1651. $html = $this->fetch();
  1652. if (!empty($pwdJsCode) && !stristr($html, "var password_value = password;")) {
  1653. $str = <<<EOF
  1654. {$pwdJsCode}
  1655. if(password != password_){
  1656. EOF;
  1657. $html = str_ireplace('if(password != password_){', $str, $html);
  1658. }
  1659. $token_input = token('__token_reset_password__');
  1660. $replace =<<<EOF
  1661. {$token_input}
  1662. </form>
  1663. EOF;
  1664. $html = str_ireplace('</form>', $replace, $html);
  1665. return $html;
  1666. }
  1667. // 手机找回密码
  1668. public function retrieve_password_mobile()
  1669. {
  1670. if ($this->users_id > 0) $this->redirect('user/Users/centre');
  1671. if (!empty($this->usersConfig['users_retrieve_password']) && 1 == $this->usersConfig['users_retrieve_password']) {
  1672. $this->redirect('user/Users/retrieve_password');
  1673. }
  1674. $is_vertify = 1; // 默认开启验证码
  1675. $users_retrieve_pwd_captcha = config('captcha.users_retrieve_password');
  1676. if (!function_exists('imagettftext') || empty($users_retrieve_pwd_captcha['is_on'])) {
  1677. $is_vertify = 0; // 函数不存在,不符合开启的条件
  1678. }
  1679. $this->assign('is_vertify', $is_vertify);
  1680. if (IS_AJAX_POST) {
  1681. $post = input('post.');
  1682. // POST数据基础判断
  1683. if (empty($post['mobile'])) $this->error('请输入手机号码');
  1684. if (empty($post['mobile_code'])) $this->error('请输入手机验证码');
  1685. if (1 == $is_vertify) {
  1686. if (empty($post['vertify'])) $this->error('请输入图片验证码');
  1687. }
  1688. // 判断会员输入的手机是否存在
  1689. $ListWhere = array(
  1690. 'info' => array('eq', $post['mobile']),
  1691. );
  1692. $ListData = $this->users_list_db->where($ListWhere)->field('users_id')->find();
  1693. if (empty($ListData)) $this->error('手机号码不存在,不能找回密码!');
  1694. // 判断会员输入的手机是否已绑定
  1695. $UsersWhere = array(
  1696. 'mobile' => array('eq', $post['mobile']),
  1697. );
  1698. $UsersData = $this->users_db->where($UsersWhere)->field('is_mobile')->find();
  1699. if (empty($UsersData['is_mobile'])) $this->error('手机号码未绑定,不能找回密码!');
  1700. // 判断验证码是否存在并且是否可用
  1701. $RecordWhere = [
  1702. 'mobile' => $post['mobile'],
  1703. 'code' => $post['mobile_code'],
  1704. 'lang' => $this->home_lang
  1705. ];
  1706. $RecordData = $this->sms_log_db->where($RecordWhere)->field('is_use, add_time')->order('id desc')->find();
  1707. if (!empty($RecordData)) {
  1708. // 验证码存在
  1709. $time = getTime();
  1710. $RecordData['add_time'] += Config::get('global.mobile_default_time_out');
  1711. if (1 == $RecordData['is_use'] || $RecordData['add_time'] <= $time) {
  1712. $this->error('手机验证码已被使用或超时,请重新发送!');
  1713. } else {
  1714. // 处理手机验证码
  1715. $RecordWhere = [
  1716. 'source' => 4,
  1717. 'mobile' => $post['mobile'],
  1718. 'is_use' => 0,
  1719. 'lang' => $this->home_lang
  1720. ];
  1721. // 更新数据
  1722. $RecordData = [
  1723. 'is_use' => 1,
  1724. 'update_time' => $time
  1725. ];
  1726. $this->sms_log_db->where($RecordWhere)->update($RecordData);
  1727. session('users_retrieve_password_mobile', $post['mobile']);
  1728. $this->success('验证通过', url('user/Users/reset_password_mobile'));
  1729. }
  1730. } else {
  1731. $this->error('手机验证码不正确,请重新输入!');
  1732. }
  1733. }
  1734. session('users_retrieve_password_mobile', null);
  1735. /*检测会员邮箱属性是否开启*/
  1736. $usersparamRow = $this->users_parameter_db->where([
  1737. 'name' => ['LIKE', 'mobile_%'],
  1738. 'is_hidden' => 1,
  1739. ])->find();
  1740. if (!empty($usersparamRow)) $this->error('会员手机属性已关闭,请联系网站管理员!');
  1741. /*--end*/
  1742. return $this->fetch();
  1743. }
  1744. public function reset_password_mobile()
  1745. {
  1746. if (IS_AJAX_POST) {
  1747. $post = input('post.');
  1748. if (empty($post['password']) || !trim($post['password'])) $this->error('请输入新密码');
  1749. if (empty($post['password_']) || !trim($post['password_'])) $this->error('请输入确认新密码');
  1750. if ($post['password'] != $post['password_']) $this->error('两次密码输入不一致!');
  1751. /*等保密码复杂度验证 start*/
  1752. if (is_dir('./weapp/Equal/')) {
  1753. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  1754. $eqData = $equalLogic->pwdValidate($post['password']);
  1755. if (isset($eqData['code']) && empty($eqData['code'])) {
  1756. $this->error($eqData['msg']);
  1757. }
  1758. }
  1759. /*等保密码复杂度验证 end*/
  1760. $mobile = session('users_retrieve_password_mobile');
  1761. if (!empty($mobile)) {
  1762. // 处理数据验证
  1763. $validata = ['mobile'=>$mobile, '__token_reset_password_mobile__'=>$post['__token_reset_password_mobile__']];
  1764. $error = handleEyouDataValidate('mobile', '__token_reset_password_mobile__', $validata);
  1765. if (!empty($error)) $this->error($error);
  1766. $data = [
  1767. 'password' => func_encrypt($post['password'], false, pwd_encry_type('bcrypt')),
  1768. 'update_time' => getTime()
  1769. ];
  1770. $return = $this->users_db->where(['mobile'=>$mobile])->update($data);
  1771. if ($return) {
  1772. session('users_retrieve_password_mobile', null);
  1773. $url = url('user/Users/login');
  1774. $this->success('重置成功!', $url);
  1775. }
  1776. }
  1777. $this->error('重置失败!');
  1778. }
  1779. // 没有手机号则重定向至找回密码页面
  1780. $mobile = session('users_retrieve_password_mobile');
  1781. if (empty($mobile)) $this->redirect('user/Users/retrieve_password_mobile');
  1782. // 查询会员信息
  1783. $username = $this->users_db->where(['mobile'=>$mobile])->getField('username');
  1784. $this->assign('username', $username);
  1785. /*等保密码复杂度验证 start*/
  1786. $pwdJsCode = '';
  1787. if (is_dir('./weapp/Equal/')) {
  1788. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  1789. $pwdJsCode = $equalLogic->pwdJsCode();
  1790. }
  1791. if ('close' == $pwdJsCode) {
  1792. $pwdJsCode = '';
  1793. }
  1794. $this->assign('pwdJsCode', $pwdJsCode);
  1795. /*等保密码复杂度验证 end*/
  1796. $html = $this->fetch();
  1797. if (!empty($pwdJsCode) && !stristr($html, "var password_value = password;")) {
  1798. $str = <<<EOF
  1799. {$pwdJsCode}
  1800. if(password != password_){
  1801. EOF;
  1802. $html = str_ireplace('if(password != password_){', $str, $html);
  1803. }
  1804. $token_input = token('__token_reset_password_mobile__');
  1805. $replace =<<<EOF
  1806. {$token_input}
  1807. </form>
  1808. EOF;
  1809. $html = str_ireplace('</form>', $replace, $html);
  1810. return $html;
  1811. }
  1812. /**
  1813. * 上传头像
  1814. * @return [type] [description]
  1815. */
  1816. public function edit_users_head_pic()
  1817. {
  1818. if (IS_AJAX_POST) {
  1819. $head_pic_url = input('param.filename/s', '');
  1820. if (!empty($head_pic_url) && preg_match('/^((https:|http:)?\/\/([\w\-\_\.]+))?\/([^.\\\]+)\.([a-zA-Z]+)$/i', $head_pic_url)) {
  1821. if (is_http_url($head_pic_url)) {
  1822. $data = getWeappObjectBucket();
  1823. if (!empty($data['domain']) && !stristr($head_pic_url, "//{$data['domain']}/")) {
  1824. $this->error('上传失败');
  1825. }
  1826. } else {
  1827. $head_pic = handle_subdir_pic($head_pic_url, 'img', false, true);
  1828. if (!is_http_url($head_pic) && !file_exists('.'.$head_pic)) {
  1829. $this->error('上传失败');
  1830. }
  1831. }
  1832. $old_head_pic = Db::name('users')->where(['users_id'=>$this->users_id])->value('head_pic');
  1833. $usersData['head_pic'] = $head_pic_url;
  1834. $usersData['update_time'] = getTime();
  1835. $return = $this->users_db->where([
  1836. 'users_id' => $this->users_id,
  1837. ])->update($usersData);
  1838. if (false !== $return) {
  1839. /*同步头像到管理员表对应的管理员*/
  1840. if (!empty($this->users['admin_id'])) {
  1841. Db::name('admin')->where(['admin_id'=>$this->users['admin_id']])->update([
  1842. 'head_pic' => $head_pic_url,
  1843. 'update_time' => getTime(),
  1844. ]);
  1845. }
  1846. /*end*/
  1847. /*删除之前的头像文件*/
  1848. if (!is_http_url($old_head_pic) && preg_match('/^\/([^.\\\]+)\.([a-zA-Z]+)$/i', $head_pic_url)){
  1849. if (stristr($old_head_pic, "/uploads/user/{$this->users_id}/allimg/")) {
  1850. @unlink('.'.handle_subdir_pic($old_head_pic, 'img', false, true));
  1851. }
  1852. }
  1853. /*end*/
  1854. if (!is_http_url($head_pic_url)){
  1855. $head_pic_url = func_thumb_img($head_pic_url, 250, 250);
  1856. }
  1857. $this->success('上传成功', null, ['head_pic'=>$head_pic_url]);
  1858. }
  1859. }
  1860. }
  1861. $this->error('上传失败');
  1862. }
  1863. //绑定邮箱
  1864. public function bind_email()
  1865. {
  1866. if (IS_AJAX_POST) {
  1867. $post = input('post.');
  1868. if (!empty($post['email']) && !empty($post['email_code'])) {
  1869. // 邮箱格式验证是否正确
  1870. if (!check_email($post['email'])) $this->error('邮箱格式不正确');
  1871. // 是否已存在相同邮箱地址
  1872. $where = [
  1873. 'info' => $post['email'],
  1874. 'users_id' => ['NEQ', $this->users_id],
  1875. ];
  1876. $isCount = $this->users_list_db->where($where)->count();
  1877. if (!empty($isCount)) $this->error('该邮箱已存在,不可绑定');
  1878. // 判断验证码是否存在并且是否可用
  1879. $where = [
  1880. 'email' => $post['email'],
  1881. 'code' => $post['email_code'],
  1882. 'users_id' => $this->users_id,
  1883. 'lang' => $this->home_lang,
  1884. ];
  1885. $smtpRecord = $this->smtp_record_db->where($where)->field('record_id, email, status, add_time')->find();
  1886. if (!empty($smtpRecord)) {
  1887. // 验证码存在
  1888. $time = getTime();
  1889. $smtpRecord['add_time'] += Config::get('global.email_default_time_out');
  1890. if (1 === intval($smtpRecord['status']) || $smtpRecord['add_time'] <= $time) {
  1891. // 验证码不可用
  1892. $this->error('邮箱验证码已被使用或超时,请重新发送');
  1893. } else {
  1894. // 查询会员输入的邮箱并且为绑定邮箱来源的所有验证码
  1895. $where = [
  1896. 'source' => 3,
  1897. 'email' => $smtpRecord['email'],
  1898. 'users_id' => $this->users_id,
  1899. 'status' => 0,
  1900. 'lang' => $this->home_lang,
  1901. ];
  1902. $update = [
  1903. 'status' => 1,
  1904. 'update_time' => $time,
  1905. ];
  1906. $this->smtp_record_db->where($where)->update($update);
  1907. // 匹配查询邮箱
  1908. $where = [
  1909. 'is_system' => 1,
  1910. 'name' => ['LIKE', "email_%"],
  1911. ];
  1912. $paraID = $this->users_parameter_db->where($where)->getField('para_id');
  1913. // 修改会员属性表信息
  1914. $where = [
  1915. 'para_id' => $paraID,
  1916. 'users_id' => ['EQ', $this->users_id],
  1917. ];
  1918. $isCount = $this->users_list_db->where($where)->count();
  1919. if (empty($isCount)) {
  1920. $insert = [
  1921. 'users_id' => $this->users_id,
  1922. 'para_id' => $paraID,
  1923. 'info' => $post['email'],
  1924. 'lang' => $this->home_lang,
  1925. 'add_time' => $time,
  1926. ];
  1927. $result = $this->users_list_db->insert($insert);
  1928. } else {
  1929. $update = [
  1930. 'info' => $post['email'],
  1931. 'update_time' => $time,
  1932. ];
  1933. $result = $this->users_list_db->where($where)->update($update);
  1934. }
  1935. if (!empty($result)) {
  1936. // 同步修改会员表邮箱地址,并绑定邮箱地址到会员账号
  1937. $update = [
  1938. 'users_id' => $this->users_id,
  1939. 'is_email' => '1',
  1940. 'email' => $post['email'],
  1941. 'update_time' => $time,
  1942. ];
  1943. $this->users_db->update($update);
  1944. \think\Cache::clear('users_list');
  1945. $this->success('操作成功');
  1946. } else {
  1947. $this->error('未知错误,邮箱地址修改失败,请重新获取验证码');
  1948. }
  1949. }
  1950. } else {
  1951. $this->error('输入的邮箱地址和邮箱验证码不一致,请重新输入');
  1952. }
  1953. }
  1954. }
  1955. $title = input('param.title/s');
  1956. $this->assign('title', $title);
  1957. return $this->fetch();
  1958. }
  1959. // 绑定手机
  1960. public function bind_mobile()
  1961. {
  1962. if (IS_AJAX_POST) {
  1963. $post = input('post.');
  1964. if (!empty($post['mobile']) && !empty($post['mobile_code'])) {
  1965. // 手机格式验证是否正确
  1966. if (!check_mobile($post['mobile'])) $this->error('手机格式不正确');
  1967. // 是否已存在相同手机号码
  1968. $where = [
  1969. 'info' => $post['mobile'],
  1970. 'users_id' => ['NEQ', $this->users_id],
  1971. ];
  1972. $isCount = $this->users_list_db->where($where)->count();
  1973. if (!empty($isCount)) $this->error('手机号码已存在,不可绑定');
  1974. // 判断验证码是否存在并且是否可用
  1975. $where = [
  1976. 'mobile' => $post['mobile'],
  1977. 'code' => $post['mobile_code'],
  1978. 'lang' => $this->home_lang
  1979. ];
  1980. $smsLog = $this->sms_log_db->where($where)->field('is_use, add_time')->order('id desc')->find();
  1981. if (!empty($smsLog)) {
  1982. // 验证码存在
  1983. $time = getTime();
  1984. $smsLog['add_time'] += Config::get('global.mobile_default_time_out');
  1985. if (1 === intval($smsLog['is_use']) || $smsLog['add_time'] <= $time) {
  1986. // 验证码不可用
  1987. $this->error('手机验证码已被使用或超时,请重新发送');
  1988. } else {
  1989. // 查询会员输入的邮箱并且为绑定邮箱来源的所有验证码
  1990. $where = [
  1991. 'source' => 1,
  1992. 'mobile' => $post['mobile'],
  1993. 'is_use' => 0,
  1994. 'lang' => $this->home_lang
  1995. ];
  1996. $update = [
  1997. 'is_use' => 1,
  1998. 'update_time' => $time
  1999. ];
  2000. $this->sms_log_db->where($where)->update($update);
  2001. // 匹配查询手机
  2002. $where = [
  2003. 'is_system' => 1,
  2004. 'name' => ['LIKE', "mobile_%"],
  2005. ];
  2006. $paraID = $this->users_parameter_db->where($where)->getField('para_id');
  2007. // 修改会员属性表信息
  2008. $where = [
  2009. 'para_id' => $paraID,
  2010. 'users_id' => ['EQ', $this->users_id],
  2011. ];
  2012. $isCount = $this->users_list_db->where($where)->count();
  2013. if (empty($isCount)) {
  2014. // 后台新增会员,没有会员属性记录的情况
  2015. $insert = [
  2016. 'users_id' => $this->users_id,
  2017. 'para_id' => $paraID,
  2018. 'info' => $post['mobile'],
  2019. 'lang' => $this->home_lang,
  2020. 'add_time' => $time
  2021. ];
  2022. $result = $this->users_list_db->insert($insert);
  2023. } else {
  2024. $where = [
  2025. 'users_id' => $this->users_id,
  2026. 'para_id' => $paraID,
  2027. ];
  2028. $update = [
  2029. 'info' => $post['mobile'],
  2030. 'update_time' => $time
  2031. ];
  2032. $result = $this->users_list_db->where($where)->update($update);
  2033. }
  2034. if (!empty($result)) {
  2035. // 同步修改会员表邮箱地址,并绑定邮箱地址到会员账号
  2036. $update = [
  2037. 'users_id' => $this->users_id,
  2038. 'is_mobile' => 1,
  2039. 'mobile' => $post['mobile'],
  2040. 'update_time' => $time
  2041. ];
  2042. $this->users_db->update($update);
  2043. \think\Cache::clear('users_list');
  2044. $this->success('操作成功!');
  2045. } else {
  2046. $this->error('未知错误,手机号码修改失败,请重新获取验证码');
  2047. }
  2048. }
  2049. } else {
  2050. $this->error('输入的手机号码和手机验证码不一致,请重新输入');
  2051. }
  2052. }
  2053. }
  2054. if (1 == config('global.opencodetype')) {
  2055. $opt = input('param.opt/s');
  2056. $this->assign('opt', $opt);
  2057. }
  2058. $title = input('param.title/s');
  2059. $this->assign('title', $title);
  2060. return $this->fetch();
  2061. }
  2062. // 退出登陆
  2063. public function logout()
  2064. {
  2065. // 清除微信授权 Cookie
  2066. model('ShopPublicHandle')->weChatauthorizeCookie($this->users_id, 'del');
  2067. // 清除登录信息
  2068. session('users_id', null);
  2069. session('users', null);
  2070. cookie('users_id', null);
  2071. cookie('dealerParam', null);
  2072. session('dealerParam', null);
  2073. // 设置不重复执行生成游客标记,3秒后自动过期失效
  2074. \think\Cookie::delete('doNotExecute');
  2075. \think\Cookie::set('doNotExecute', '1', 3);
  2076. // 跳转链接
  2077. $gourl = input('param.gourl/s');
  2078. $referurl = input('param.referurl/s', $gourl);
  2079. if (empty($referurl)) {
  2080. $referurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ROOT_DIR . '/';
  2081. }
  2082. // 开启微站点模式,强制退出到网站首页
  2083. if (!empty($this->usersConfig['shop_micro']) && 1 == $this->usersConfig['shop_micro']) {
  2084. $referurl = ROOT_DIR . '/';
  2085. }
  2086. // 只跳转本站链接
  2087. $domain = request()->host(true);
  2088. if (!stristr($referurl, "//{$domain}/")) {
  2089. $referurl = ROOT_DIR . '/';
  2090. }
  2091. $referurl = strip_tags($referurl);
  2092. $this->redirect($referurl);
  2093. }
  2094. /**
  2095. * 我的足迹首页
  2096. * @return mixed
  2097. */
  2098. public function footprint_index()
  2099. {
  2100. // 查询条件
  2101. $where = [
  2102. 'c.aid' => ['GT', 0],
  2103. 'a.users_id' => $this->users_id,
  2104. 'c.lang' => $this->home_lang,
  2105. ];
  2106. // 关键字查询
  2107. $keywords = input('keywords/s');
  2108. if (!empty($keywords)) $where['a.title'] = ['LIKE', "%{$keywords}%"];
  2109. // 所属模型
  2110. $params = [];
  2111. $allow_release_channel_list = $this->get_allow_release_channel_list();
  2112. if (!empty($allow_release_channel_list)) {
  2113. $channel_id = input('channel_id/d');
  2114. if (!empty($channel_id)) $params['channel_id'] = $where['a.channel'] = $channel_id;
  2115. }
  2116. // 查询足迹内容
  2117. $count = Db::name('users_footprint')->alias('a')->where($where)->join('__ARCHIVES__ c', 'a.aid = c.aid', 'LEFT')->count('id');
  2118. $Page = $pager = new Page($count, config('paginate.list_rows'));
  2119. $result['data'] = Db::name('users_footprint')
  2120. ->field('d.*, a.*, c.*, a.update_time as update_time')
  2121. ->alias('a')
  2122. ->join('__ARCTYPE__ d', 'a.typeid = d.id')
  2123. ->join('__ARCHIVES__ c', 'a.aid = c.aid', 'LEFT')
  2124. ->where($where)
  2125. ->order('a.update_time desc')
  2126. ->limit($Page->firstRow.','.$Page->listRows)
  2127. ->select();
  2128. foreach ($result['data'] as $key => $value) {
  2129. $value['litpic'] = get_default_pic($value['litpic']); // 支持子目录
  2130. $value['arcurl'] = get_arcurl($value, false);
  2131. $valueNew = $value;
  2132. $valueNew['id'] = $valueNew['typeid'];
  2133. $value['typeurl'] = get_typeurl($valueNew, false);
  2134. $result['data'][$key] = $value;
  2135. }
  2136. $result['delurl'] = url('user/Users/footprint_del');
  2137. $eyou = array(
  2138. 'field' => $result,
  2139. );
  2140. //导航栏url
  2141. $params['barurl'] = MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
  2142. $show = $Page->show();
  2143. $this->assign('page', $show);
  2144. $this->assign('eyou', $eyou);
  2145. $this->assign('pager', $pager);
  2146. $this->assign('params', $params);
  2147. $this->assign('allow_release_channel_list', $allow_release_channel_list);
  2148. return $this->fetch('users_footprint_index');
  2149. }
  2150. //获取启用的模型
  2151. protected function get_allow_release_channel_list()
  2152. {
  2153. $allow_release_channel_list = cache('extra_global_channeltype');
  2154. $res = array();
  2155. if ($allow_release_channel_list) {
  2156. foreach ($allow_release_channel_list as $item) {
  2157. if ($item['status'] == 1) {
  2158. $value = array();
  2159. $value['id'] = $item['id'];
  2160. $value['nid'] = $item['nid'];
  2161. $value['title'] = $item['title'];
  2162. $value['ntitle'] = $item['ntitle'];
  2163. $res[] = $value;
  2164. }
  2165. }
  2166. }
  2167. return $res;
  2168. }
  2169. /**
  2170. * 删除
  2171. */
  2172. public function footprint_del()
  2173. {
  2174. if (IS_POST) {
  2175. $id_arr = input('del_id/a');
  2176. $id_arr = eyIntval($id_arr);
  2177. if (!empty($id_arr)) {
  2178. $r = Db::name('users_footprint')->where([
  2179. 'id' => ['IN', $id_arr],
  2180. 'users_id' => $this->users_id,
  2181. ])->delete();
  2182. if (!empty($r)) {
  2183. $this->success('删除成功');
  2184. }
  2185. }
  2186. }
  2187. $this->error('删除失败');
  2188. }
  2189. /*
  2190. * 收藏
  2191. */
  2192. public function collection_index()
  2193. {
  2194. // 查询条件
  2195. $where = [
  2196. 'c.aid' => ['GT', 0],
  2197. 'a.users_id' => $this->users_id,
  2198. 'c.lang' => $this->home_lang,
  2199. ];
  2200. // 关键字查询
  2201. $keywords = input('keywords/s');
  2202. if (!empty($keywords)) $where['a.title'] = ['LIKE', "%{$keywords}%"];
  2203. // 所属模型
  2204. $params = [];
  2205. $allow_release_channel_list = $this->get_allow_release_channel_list();
  2206. if (!empty($allow_release_channel_list)) {
  2207. $channel_id = input('channel_id/d');
  2208. if (!empty($channel_id)) $params['channel_id'] = $where['a.channel'] = $channel_id;
  2209. }
  2210. // 查询收藏内容
  2211. $count = Db::name('users_collection')->alias('a')->where($where)->join('__ARCHIVES__ c', 'a.aid = c.aid', 'LEFT')->count('id');
  2212. $Page = $pager = new Page($count, config('paginate.list_rows'));
  2213. $result['data'] = Db::name('users_collection')
  2214. ->field('d.*, a.*, c.*')
  2215. ->alias('a')
  2216. ->join('__ARCTYPE__ d', 'a.typeid = d.id', 'LEFT')
  2217. ->join('__ARCHIVES__ c', 'a.aid = c.aid', 'LEFT')
  2218. ->where($where)
  2219. ->order('a.id desc')
  2220. ->limit($Page->firstRow.','.$Page->listRows)
  2221. ->select();
  2222. // 如果当前分页没有数据则去除分页参数重载
  2223. if (empty($result['data']) && input('param.p/d', 0)) $this->redirect('user/Users/collection_index');
  2224. foreach ($result['data'] as $key => $value) {
  2225. $value['users_price'] = floatval($value['users_price']);
  2226. $value['litpic'] = get_default_pic($value['litpic']); // 支持子目录
  2227. $value['arcurl'] = get_arcurl($value, false);
  2228. $valueNew = $value;
  2229. $valueNew['id'] = $valueNew['typeid'];
  2230. $value['typeurl'] = get_typeurl($valueNew, false);
  2231. $result['data'][$key] = $value;
  2232. }
  2233. $result['delurl'] = url('user/Users/collection_del');
  2234. $eyou = array(
  2235. 'field' => $result,
  2236. );
  2237. //导航栏url
  2238. $params['barurl'] = MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
  2239. $show = $Page->show();
  2240. $this->assign('page', $show);
  2241. $this->assign('eyou', $eyou);
  2242. $this->assign('pager', $pager);
  2243. $this->assign('params', $params);
  2244. $this->assign('allow_release_channel_list', $allow_release_channel_list);
  2245. return $this->fetch('users_collection_index');
  2246. }
  2247. /**
  2248. * 删除收藏
  2249. */
  2250. public function collection_del()
  2251. {
  2252. if (IS_POST) {
  2253. $id_arr = input('del_id/a');
  2254. $id_arr = eyIntval($id_arr);
  2255. if(!empty($id_arr)){
  2256. $r = Db::name('users_collection')->where([
  2257. 'id' => ['IN', $id_arr],
  2258. 'users_id' => $this->users_id,
  2259. ])->delete();
  2260. if(!empty($r)){
  2261. $this->success('删除成功');
  2262. }
  2263. }
  2264. }
  2265. $this->error('删除失败');
  2266. }
  2267. //我的视频
  2268. public function media_index()
  2269. {
  2270. $keywords = input('keywords/s');
  2271. $condition = array();
  2272. $order_code = input('order_code/s');
  2273. if (!empty($order_code)) $condition['a.order_code'] = ['LIKE', "%{$order_code}%"];
  2274. $condition['a.users_id'] = $this->users_id;
  2275. $order_status = input('order_status/s');
  2276. $this->assign('order_status', $order_status);
  2277. if (!empty($order_status)) {
  2278. if (-1 == $order_status) $order_status = 0;
  2279. $condition['a.order_status'] = $order_status;
  2280. }else{
  2281. $condition['a.order_status'] = 1;//默认查询已购买
  2282. }
  2283. $count = Db::name('media_order')->alias('a')->where($condition)->count('order_id');
  2284. $Page = $pager = new Page($count, config('paginate.list_rows'));
  2285. $result['data'] = Db::name('media_order')->where($condition)
  2286. ->field('a.*,c.aid,c.typeid,c.channel,d.*,a.add_time as order_add_time')
  2287. ->alias('a')
  2288. ->join('__ARCHIVES__ c', 'a.product_id = c.aid', 'LEFT')
  2289. ->join('__ARCTYPE__ d', 'c.typeid = d.id', 'LEFT')
  2290. ->order('a.order_id desc')
  2291. ->limit($Page->firstRow.','.$Page->listRows)
  2292. ->select();
  2293. $array_new = get_archives_data($result['data'], 'product_id');
  2294. foreach ($result['data'] as $key => $value) {
  2295. $arcurl = '';
  2296. $vars = !empty($array_new[$value['product_id']]) ? $array_new[$value['product_id']] : [];
  2297. if (!empty($vars)) {
  2298. $arcurl = urldecode(arcurl('home/Media/view', $vars));
  2299. }
  2300. $result['data'][$key]['arcurl'] = $arcurl;
  2301. }
  2302. $result['delurl'] = url('user/Users/collection_del');
  2303. $eyou = array(
  2304. 'field' => $result,
  2305. );
  2306. $show = $Page->show();
  2307. $this->assign('page',$show);
  2308. // 数据
  2309. $this->assign('eyou', $eyou);
  2310. $this->assign('pager',$pager);
  2311. // 会员订单数量查询 (文章、下载、视频)
  2312. $this->usersOrderQuantityQuery();
  2313. return $this->fetch('users_media_index');
  2314. }
  2315. // 视频订单详情页
  2316. public function media_order_details()
  2317. {
  2318. $order_id = input('param.order_id');
  2319. if (!empty($order_id)) {
  2320. // 查询订单信息
  2321. $OrderData = Db::name('media_order')
  2322. ->field('a.*, product_id,c.aid,c.typeid,c.channel,d.*')
  2323. ->alias('a')
  2324. ->join('__ARCHIVES__ c', 'a.product_id = c.aid', 'LEFT')
  2325. ->join('__ARCTYPE__ d', 'c.typeid = d.id', 'LEFT')
  2326. ->find($order_id);
  2327. // 查询会员数据
  2328. $UsersData = $this->users_db->find($OrderData['users_id']);
  2329. // 用于点击视频文档跳转到前台
  2330. $array_new = get_archives_data([$OrderData], 'product_id');
  2331. // 内页地址
  2332. $arcurl = '';
  2333. $vars = !empty($array_new[$OrderData['product_id']]) ? $array_new[$OrderData['product_id']] : [];
  2334. if (!empty($vars)) {
  2335. $arcurl = urldecode(arcurl('home/Media/view', $vars));
  2336. }
  2337. $OrderData['arcurl'] = $arcurl;
  2338. // 支持子目录
  2339. $OrderData['product_litpic'] = get_default_pic($OrderData['product_litpic']);
  2340. // 加载数据
  2341. $this->assign('OrderData', $OrderData);
  2342. $this->assign('UsersData', $UsersData);
  2343. return $this->fetch();
  2344. } else {
  2345. $this->error('非法访问!');
  2346. }
  2347. }
  2348. /*
  2349. * 积分明细
  2350. */
  2351. public function score_index()
  2352. {
  2353. //积分类型
  2354. $score_type_arr = config('global.score_type');
  2355. if (empty($score_type_arr)) {
  2356. $score_type_arr = [1=>'提问',2=>'回答',3=>'最佳答案',4=>'悬赏退回',5=>'每日签到',6=>'后台操作',7=>'问答悬赏',8=>'消费赠送',9=>'积分兑换',10=>'登录赠送',11=>'积分兑换',12=>'订单退回'];
  2357. config('global.score_type', $score_type_arr);
  2358. }
  2359. $this->assign('score_type_arr', $score_type_arr);
  2360. $condition = [
  2361. 'a.users_id' => $this->users_id,
  2362. ];
  2363. $queryID = input('param.queryID/d', 0);
  2364. $this->assign('queryID', $queryID);
  2365. if (!empty($queryID)) {
  2366. // 支出、收入
  2367. if (in_array($queryID, [10, 20])) {
  2368. $condition['a.score'] = 10 === intval($queryID) ? ['LT', 0] : ['GT', 0];
  2369. }
  2370. // 签到
  2371. else if (in_array($queryID, [30])) {
  2372. $condition['a.type'] = 5;
  2373. $condition['a.admin_id'] = ['EQ', 0];
  2374. }
  2375. // 管理员操作
  2376. else if (in_array($queryID, [40])) {
  2377. $condition['a.type'] = 6;
  2378. $condition['a.admin_id'] = ['GT', 0];
  2379. }
  2380. // 问答悬赏
  2381. else if (in_array($queryID, [50])) {
  2382. $condition['a.type'] = 7;
  2383. $condition['a.ask_id'] = ['GT', 0];
  2384. }
  2385. // 兑换商品
  2386. else if (in_array($queryID, [60])) {
  2387. $condition['a.type'] = 9;
  2388. }
  2389. }
  2390. // 积分类型筛选(0全部,1收入,2支出)
  2391. $score_type = input('param.score_type/d', 0);
  2392. $this->assign('score_type', $score_type);
  2393. if (!empty($score_type) && 1 === intval($score_type)) {
  2394. $condition[] = Db::raw('a.score > 0');
  2395. } else if (!empty($score_type) && 2 === intval($score_type)) {
  2396. $condition[] = Db::raw('a.score < 0');
  2397. }
  2398. $count = Db::name('users_score')->alias('a')->where($condition)->count('id');
  2399. $Page = $pager = new Page($count, config('paginate.list_rows'));
  2400. $result['data'] = Db::name('users_score')
  2401. ->field('a.*')
  2402. ->alias('a')
  2403. ->where($condition)
  2404. ->order('a.id desc')
  2405. ->limit($Page->firstRow.','.$Page->listRows)
  2406. ->select();
  2407. $eyou = array(
  2408. 'field' => $result,
  2409. );
  2410. $show = $Page->show();
  2411. $this->assign('page',$show);
  2412. $this->assign('eyou', $eyou);
  2413. $this->assign('pager',$pager);
  2414. return $this->fetch('users_score_index');
  2415. }
  2416. //我的文章
  2417. public function article_index()
  2418. {
  2419. $keywords = input('keywords/s');
  2420. $condition = array();
  2421. $order_code = input('order_code/s');
  2422. if (!empty($order_code)) $condition['a.order_code'] = ['LIKE', "%{$order_code}%"];
  2423. $condition['a.users_id'] = $this->users_id;
  2424. $order_status = input('order_status/s');
  2425. $this->assign('order_status', $order_status);
  2426. if (!empty($order_status)) {
  2427. if (-1 == $order_status) $order_status = 0;
  2428. $condition['a.order_status'] = $order_status;
  2429. }else{
  2430. $condition['a.order_status'] = 1;//默认查询已购买
  2431. }
  2432. $count = Db::name('article_order')->alias('a')->where($condition)->count('order_id');
  2433. $Page = $pager = new Page($count, config('paginate.list_rows'));
  2434. $result['data'] = Db::name('article_order')->where($condition)
  2435. ->field('a.*,c.aid,c.typeid,c.channel,d.*,a.add_time as order_add_time')
  2436. ->alias('a')
  2437. ->join('__ARCHIVES__ c', 'a.product_id = c.aid', 'LEFT')
  2438. ->join('__ARCTYPE__ d', 'c.typeid = d.id', 'LEFT')
  2439. ->order('a.order_id desc')
  2440. ->limit($Page->firstRow.','.$Page->listRows)
  2441. ->select();
  2442. $array_new = get_archives_data($result['data'], 'product_id');
  2443. foreach ($result['data'] as $key => $value) {
  2444. $arcurl = '';
  2445. $vars = !empty($array_new[$value['product_id']]) ? $array_new[$value['product_id']] : [];
  2446. if (!empty($vars)) {
  2447. $arcurl = urldecode(arcurl('home/Article/view', $vars));
  2448. }
  2449. $result['data'][$key]['arcurl'] = $arcurl;
  2450. }
  2451. $result['delurl'] = url('user/Users/collection_del');
  2452. $eyou = array(
  2453. 'field' => $result,
  2454. );
  2455. $show = $Page->show();
  2456. $this->assign('page',$show);
  2457. // 数据
  2458. $this->assign('eyou', $eyou);
  2459. $this->assign('pager',$pager);
  2460. // 会员订单数量查询 (文章、下载、视频)
  2461. $this->usersOrderQuantityQuery();
  2462. return $this->fetch('users_article_index');
  2463. }
  2464. // 文章订单详情页
  2465. public function article_order_details()
  2466. {
  2467. $order_id = input('param.order_id');
  2468. if (!empty($order_id)) {
  2469. // 查询订单信息
  2470. $OrderData = Db::name('article_order')
  2471. ->field('a.*, product_id,c.aid,c.typeid,c.channel,d.*')
  2472. ->alias('a')
  2473. ->join('__ARCHIVES__ c', 'a.product_id = c.aid', 'LEFT')
  2474. ->join('__ARCTYPE__ d', 'c.typeid = d.id', 'LEFT')
  2475. ->find($order_id);
  2476. // 查询会员数据
  2477. $UsersData = $this->users_db->find($OrderData['users_id']);
  2478. // 用于点击视频文档跳转到前台
  2479. $array_new = get_archives_data([$OrderData], 'product_id');
  2480. // 内页地址
  2481. $arcurl = '';
  2482. $vars = !empty($array_new[$OrderData['product_id']]) ? $array_new[$OrderData['product_id']] : [];
  2483. if (!empty($vars)) {
  2484. $arcurl = urldecode(arcurl('home/Article/view', $vars));
  2485. }
  2486. $OrderData['arcurl'] = $arcurl;
  2487. // 支持子目录
  2488. $OrderData['product_litpic'] = get_default_pic($OrderData['product_litpic']);
  2489. // 加载数据
  2490. $this->assign('OrderData', $OrderData);
  2491. $this->assign('UsersData', $UsersData);
  2492. return $this->fetch();
  2493. } else {
  2494. $this->error('非法访问!');
  2495. }
  2496. }
  2497. //我的下载
  2498. public function download_index()
  2499. {
  2500. $keywords = input('keywords/s');
  2501. $condition = array();
  2502. $order_code = input('order_code/s');
  2503. if (!empty($order_code)) $condition['a.order_code'] = ['LIKE', "%{$order_code}%"];
  2504. $condition['a.users_id'] = $this->users_id;
  2505. $order_status = input('order_status/s');
  2506. $this->assign('order_status', $order_status);
  2507. if (!empty($order_status)) {
  2508. if (-1 == $order_status) $order_status = 0;
  2509. $condition['a.order_status'] = $order_status;
  2510. }else{
  2511. $condition['a.order_status'] = 1;//默认查询已购买
  2512. }
  2513. $count = Db::name('download_order')->alias('a')->where($condition)->count('order_id');
  2514. $Page = $pager = new Page($count, config('paginate.list_rows'));
  2515. $result['data'] = Db::name('download_order')->where($condition)
  2516. ->field('a.*,c.aid,c.typeid,c.channel,d.*,a.add_time as order_add_time')
  2517. ->alias('a')
  2518. ->join('__ARCHIVES__ c', 'a.product_id = c.aid', 'LEFT')
  2519. ->join('__ARCTYPE__ d', 'c.typeid = d.id', 'LEFT')
  2520. ->order('a.order_id desc')
  2521. ->limit($Page->firstRow.','.$Page->listRows)
  2522. ->select();
  2523. $array_new = get_archives_data($result['data'], 'product_id');
  2524. foreach ($result['data'] as $key => $value) {
  2525. $arcurl = '';
  2526. $vars = !empty($array_new[$value['product_id']]) ? $array_new[$value['product_id']] : [];
  2527. if (!empty($vars)) {
  2528. $arcurl = urldecode(arcurl('home/Article/view', $vars));
  2529. }
  2530. $result['data'][$key]['arcurl'] = $arcurl;
  2531. }
  2532. $result['delurl'] = url('user/Users/collection_del');
  2533. $eyou = array(
  2534. 'field' => $result,
  2535. );
  2536. $show = $Page->show();
  2537. $this->assign('page',$show);
  2538. // 数据
  2539. $this->assign('eyou', $eyou);
  2540. $this->assign('pager',$pager);
  2541. // 会员订单数量查询 (文章、下载、视频)
  2542. $this->usersOrderQuantityQuery();
  2543. return $this->fetch('users_download_index');
  2544. }
  2545. // 下载订单详情页
  2546. public function download_order_details()
  2547. {
  2548. $order_id = input('param.order_id');
  2549. if (!empty($order_id)) {
  2550. // 查询订单信息
  2551. $OrderData = Db::name('download_order')
  2552. ->field('a.*, product_id,c.aid,c.typeid,c.channel,d.*')
  2553. ->alias('a')
  2554. ->join('__ARCHIVES__ c', 'a.product_id = c.aid', 'LEFT')
  2555. ->join('__ARCTYPE__ d', 'c.typeid = d.id', 'LEFT')
  2556. ->find($order_id);
  2557. // 查询会员数据
  2558. $UsersData = $this->users_db->find($OrderData['users_id']);
  2559. // 用于点击视频文档跳转到前台
  2560. $array_new = get_archives_data([$OrderData], 'product_id');
  2561. // 内页地址
  2562. $arcurl = '';
  2563. $vars = !empty($array_new[$OrderData['product_id']]) ? $array_new[$OrderData['product_id']] : [];
  2564. if (!empty($vars)) {
  2565. $arcurl = urldecode(arcurl('home/Article/view', $vars));
  2566. }
  2567. $OrderData['arcurl'] = $arcurl;
  2568. // 支持子目录
  2569. $OrderData['product_litpic'] = get_default_pic($OrderData['product_litpic']);
  2570. // 加载数据
  2571. $this->assign('OrderData', $OrderData);
  2572. $this->assign('UsersData', $UsersData);
  2573. return $this->fetch('article_order_details');
  2574. } else {
  2575. $this->error('非法访问!');
  2576. }
  2577. }
  2578. // 会员订单数量查询 (文章、下载、视频)
  2579. private function usersOrderQuantityQuery()
  2580. {
  2581. $where = [
  2582. 'order_status' => 1,
  2583. 'users_id' => $this->users_id
  2584. ];
  2585. // 查询视频订单
  2586. $mediaOrder = Db::name('media_order')->where($where)->count();
  2587. $mediaOrder = !empty($mediaOrder) ? intval($mediaOrder) : 0;
  2588. // 查询文章订单
  2589. $articleOrder = Db::name('article_order')->where($where)->count();
  2590. $articleOrder = !empty($articleOrder) ? intval($articleOrder) : 0;
  2591. // 查询下载订单
  2592. $downloadOrder = Db::name('download_order')->where($where)->count();
  2593. $downloadOrder = !empty($downloadOrder) ? intval($downloadOrder) : 0;
  2594. // 加载页面数据
  2595. $this->assign('mediaOrder', $mediaOrder);
  2596. $this->assign('articleOrder', $articleOrder);
  2597. $this->assign('downloadOrder', $downloadOrder);
  2598. }
  2599. public function log_off()
  2600. {
  2601. $users_id = session('users_id');
  2602. if (empty($users_id)) $this->error('请先登录');
  2603. $users_open_log_off = getUsersConfigData('users.users_open_log_off','', 'cn'); // 开启注销
  2604. if (empty($users_open_log_off)) $this->error('未开启会员注销');
  2605. $users = Db::name('users')->where('users_id', $users_id)->find();
  2606. if (empty($users)) $this->error('注销失败');
  2607. $insert = [
  2608. 'users_id' => $users_id,
  2609. 'username' => $users['username'],
  2610. 'nickname' => $users['nickname'],
  2611. 'mobile' => $users['mobile'],
  2612. 'add_time' => getTime(),
  2613. 'update_time' => getTime(),
  2614. ];
  2615. $users_log_off_check = getUsersConfigData('users.users_log_off_check','', 'cn'); // 注销审核
  2616. if (empty($users_log_off_check)) {
  2617. //开启注销审核
  2618. $insert['status'] = 0;
  2619. $msg = '申请注销成功,请等待管理员审核';
  2620. } else {
  2621. //直接注销
  2622. $insert['status'] = 1;
  2623. $msg = '注销成功';
  2624. }
  2625. $r = Db::name('users_log_off')->insert($insert);
  2626. if (false !== $r){
  2627. if (!empty($insert['status'])){
  2628. //直接删除
  2629. Db::name('users')->where('users_id', $users_id)->delete();
  2630. $memberModel = new \app\admin\model\Member();
  2631. $memberModel->afterDel([$users_id]);
  2632. }
  2633. $this->success($msg);
  2634. }
  2635. $this->error('注销失败');
  2636. }
  2637. }