Нема описа
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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684
  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\admin\controller;
  14. use think\Page;
  15. use think\Db;
  16. use think\Config;
  17. use app\admin\logic\MemberLogic;
  18. class Member extends Base {
  19. public $userConfig = [];
  20. /**
  21. * 构造方法
  22. */
  23. public function __construct(){
  24. parent::__construct();
  25. $this->language_access(); // 多语言功能操作权限
  26. /*会员中心数据表*/
  27. $this->users_db = Db::name('users'); // 会员信息表
  28. $this->users_list_db = Db::name('users_list'); // 会员资料表
  29. $this->users_level_db = Db::name('users_level'); // 会员等级表
  30. $this->users_config_db = Db::name('users_config'); // 会员配置表
  31. $this->users_money_db = Db::name('users_money'); // 会员充值表
  32. $this->field_type_db = Db::name('field_type'); // 字段属性表
  33. $this->users_parameter_db = Db::name('users_parameter'); // 会员属性表
  34. $this->users_type_manage_db = Db::name('users_type_manage'); // 会员属性表
  35. /*结束*/
  36. /*订单中心数据表*/
  37. $this->shop_address_db = Db::name('shop_address'); // 会员地址表
  38. $this->shop_cart_db = Db::name('shop_cart'); // 会员购物车表
  39. $this->shop_order_db = Db::name('shop_order'); // 会员订单主表
  40. $this->shop_order_log_db = Db::name('shop_order_log'); // 会员订单操作记录表
  41. $this->shop_order_details_db = Db::name('shop_order_details'); // 会员订单副表
  42. /*结束*/
  43. // 是否开启支付功能设置
  44. $this->userConfig = getUsersConfigData('all');
  45. $this->assign('userConfig', $this->userConfig);
  46. // 模型是否开启
  47. $channeltype_row = \think\Cache::get('extra_global_channeltype');
  48. $this->assign('channeltype_row', $channeltype_row);
  49. }
  50. // 会员列表
  51. public function users_index()
  52. {
  53. $list = array();
  54. $param = input('param.');
  55. $condition = array();
  56. // 应用搜索条件
  57. foreach (['keywords','level'] as $key) {
  58. if (isset($param[$key]) && $param[$key] !== '') {
  59. if ($key == 'keywords') {
  60. $condition['a.username|a.nickname|a.mobile|a.email|a.users_id'] = array('LIKE', "%{$param[$key]}%");
  61. } else {
  62. $condition['a.'.$key] = array('eq', $param[$key]);
  63. }
  64. }
  65. }
  66. if (!empty($param['source'])) {
  67. $condition['a.source'] = $param['source'];
  68. }
  69. if (isset($param['is_lock']) && '' !== $param['is_lock']) {
  70. $condition['a.is_lock'] = $param['is_lock'];
  71. }
  72. // 注册时间查询
  73. if (!empty($param['add_time'])) {
  74. $add_time = explode('~', $param['add_time']);
  75. $start = strtotime(rtrim($add_time[0]));
  76. $finish = strtotime(rtrim($add_time[1]).' 23:59:59');
  77. $condition['a.reg_time'] = ['between', "$start, $finish"];
  78. }
  79. $condition['a.is_del'] = 0;
  80. // 自定义排序
  81. $orderby = input('param.orderby/s');
  82. $orderway = input('param.orderway/s');
  83. if (!empty($orderby) && !empty($orderway)) {
  84. $orderby = "a.{$orderby} {$orderway}, a.users_id desc";
  85. } else {
  86. $orderby = "a.users_id desc";
  87. }
  88. $count = $this->users_db->alias('a')->where($condition)->count();
  89. $Page = new Page($count, config('paginate.list_rows'));
  90. $list = $this->users_db->field('a.*,b.level_name')
  91. ->alias('a')
  92. ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
  93. ->where($condition)
  94. ->order($orderby)
  95. ->limit($Page->firstRow.','.$Page->listRows)
  96. ->select();
  97. $users_ids = [];
  98. foreach ($list as $key => $val) {
  99. $users_ids[] = $val['users_id'];
  100. }
  101. /*微信登录插件*/
  102. $wxlogin = [];
  103. if (is_dir('./weapp/WxLogin/')) {
  104. $wxlogin = Db::name('weapp_wxlogin')->where(['users_id'=>['IN', $users_ids]])->getAllWithIndex('users_id');
  105. }
  106. $this->assign('wxlogin',$wxlogin);
  107. /*end*/
  108. /*QQ登录插件*/
  109. $qqlogin = [];
  110. if (is_dir('./weapp/QqLogin/')) {
  111. $qqlogin = Db::name('weapp_qqlogin')->where(['users_id'=>['IN', $users_ids]])->getAllWithIndex('users_id');
  112. }
  113. $this->assign('qqlogin',$qqlogin);
  114. /*end*/
  115. /*微博登录插件*/
  116. $wblogin = [];
  117. if (is_dir('./weapp/Wblogin/')) {
  118. $wblogin = Db::name('weapp_wblogin')->where(['users_id'=>['IN', $users_ids]])->getAllWithIndex('users_id');
  119. }
  120. $this->assign('wblogin',$wblogin);
  121. /*end*/
  122. $show = $Page->show();// 分页显示输出
  123. $this->assign('page',$show);// 赋值分页输出
  124. $this->assign('list',$list);// 赋值数据集
  125. $this->assign('pager',$Page);// 赋值分页集
  126. $LevelData = model('UsersLevel')->getList('level_id, level_name', [], 'level_id');
  127. $this->assign('level', $LevelData);
  128. /*纠正数据*/
  129. $web_is_authortoken = tpCache('global.web_is_authortoken');
  130. if (is_realdomain() && !empty($web_is_authortoken)) {
  131. getUsersConfigData('shop', ['shop_open'=>0]);
  132. }
  133. //计算会员人数
  134. $levelCountList = [
  135. 'all' => [
  136. 'level_id' => 0,
  137. 'level_name' => '全部会员',
  138. 'level_count' => 0,
  139. ],
  140. ];
  141. $LevelData = model('UsersLevel')->getList('level_id, level_name', [], 'level_id');
  142. $levelCountRow = Db::name('users')->field('count(users_id) as num, level')->order('level asc')->group('level')->getAllWithIndex('level');
  143. foreach ($LevelData as $key => $val) {
  144. $level_num = empty($levelCountRow[$val['level_id']]) ? 0 : $levelCountRow[$val['level_id']]['num'];
  145. $levelCountList[$val['level_id']] = [
  146. 'level_id' => $val['level_id'],
  147. 'level_name' => $val['level_name'],
  148. 'level_count' => $level_num,
  149. ];
  150. $levelCountList['all']['level_count'] += $level_num;
  151. }
  152. $this->assign('levelCountList', $levelCountList);
  153. // 手机端后台管理插件特定使用参数
  154. $isMobile = input('param.isMobile/d', 0);
  155. // 如果安装手机端后台管理插件并且在手机端访问时执行
  156. if (is_dir('./weapp/Mbackend/') && !empty($isMobile)) {
  157. $mbPage = input('param.p/d', 1);
  158. $nullShow = intval($Page->totalPages) === intval($mbPage) ? 1 : 0;
  159. $this->assign('nullShow', $nullShow);
  160. if ($mbPage >= 2) {
  161. return $this->display('member/users_list');
  162. } else {
  163. return $this->display('member/users_index');
  164. }
  165. } else {
  166. return $this->fetch();
  167. }
  168. }
  169. // 会员批量新增
  170. public function users_batch_add()
  171. {
  172. if (IS_POST) {
  173. $post = input('post.');
  174. $username = $post['username'];
  175. if (empty($username)) {
  176. $this->error('用户名不能为空!');
  177. }
  178. if (empty($post['password']) || !trim($post['password'])) {
  179. $this->error('登录密码不能为空!');
  180. } else {
  181. /*等保密码复杂度验证 start*/
  182. if (is_dir('./weapp/Equal/')) {
  183. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  184. $eqData = $equalLogic->pwdValidate($post['password']);
  185. if (isset($eqData['code']) && empty($eqData['code'])) {
  186. $this->error($eqData['msg']);
  187. }
  188. }
  189. /*等保密码复杂度验证 end*/
  190. }
  191. if (!empty($this->userConfig['level_member_upgrade']) && 1 == $this->userConfig['level_member_upgrade']) {
  192. if (1 != $post['level'] && !preg_match("/^([0-9]+)$/i", $post['level_maturity_days'])) {
  193. $this->error('请填写会员有效期天数!');
  194. }
  195. }
  196. // 处理数据验证
  197. $error = handleEyouDataValidate('username', '__token_users_batch_add__', $post, '用户名不能为空!');
  198. if (!empty($error)) $this->error($error);
  199. $post['level_maturity_days'] = intval($post['level_maturity_days']);
  200. $password = func_encrypt($post['password'], false, pwd_encry_type('bcrypt'));
  201. $usernameArr = explode("\r\n", $username);
  202. $usernameArr = array_filter($usernameArr);//去除数组空值
  203. $usernameArr = array_unique($usernameArr); //去重
  204. $addData = [];
  205. $usernameList = $this->users_db->where([
  206. 'username' => ['IN', $usernameArr],
  207. ])->column('username');
  208. foreach ($usernameArr as $key => $val) {
  209. if(trim($val) == '' || empty($val) || in_array($val, $usernameList) || !preg_match("/^[\x{4e00}-\x{9fa5}\w\-\_\@\#]{2,30}$/u", $val))
  210. {
  211. continue;
  212. }
  213. $addData[] = [
  214. 'username' => $val,
  215. 'nickname' => $val,
  216. 'password' => $password,
  217. 'level' => $post['level'],
  218. 'register_place' => 1,
  219. 'level_maturity_days' => $post['level_maturity_days'],
  220. 'open_level_time' => getTime(),
  221. 'reg_time' => getTime(),
  222. 'head_pic' => ROOT_DIR . '/public/static/common/images/dfboy.png',
  223. 'lang' => $this->admin_lang,
  224. ];
  225. }
  226. if (!empty($addData)) {
  227. $r = model('Member')->saveAll($addData);
  228. if (!empty($r)) {
  229. eyou_statistics_data(4, count($addData)); // 统计新增会员数
  230. adminLog('批量新增会员:'.implode(',', get_arr_column($addData, 'username')));
  231. $this->success('操作成功!', url('Member/users_index'));
  232. } else {
  233. $this->error('操作失败');
  234. }
  235. } else {
  236. $this->success('操作成功!', url('Member/users_index'));
  237. }
  238. }
  239. $user_level = model('UsersLevel')->getList('level_id, level_name');
  240. $this->assign('user_level',$user_level);
  241. /*等保密码复杂度验证 start*/
  242. $pwdJsCode = '';
  243. if (is_dir('./weapp/Equal/')) {
  244. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  245. $pwdJsCode = $equalLogic->pwdJsCode();
  246. }
  247. if ('close' == $pwdJsCode) {
  248. $pwdJsCode = '';
  249. }
  250. $this->assign('pwdJsCode', $pwdJsCode);
  251. /*等保密码复杂度验证 end*/
  252. return $this->fetch();
  253. }
  254. // 会员编辑
  255. public function users_edit()
  256. {
  257. if (IS_POST) {
  258. $post = input('post.');
  259. $post['users_id'] = intval($post['users_id']);
  260. $users_id = $post['users_id'];
  261. // if (!empty($this->userConfig['level_member_upgrade']) && 1 == $this->userConfig['level_member_upgrade']) {
  262. if (1 != $post['level'] && !preg_match("/^([0-9]+)$/i", $post['level_maturity_days_up'])) {
  263. $this->error('请填写会员有效期天数!');
  264. }
  265. /*会员级别到期天数*/
  266. $post['level_maturity_days_up'] = intval($post['level_maturity_days_up']);
  267. $post['level_maturity_days_old'] = intval($post['level_maturity_days_old']);
  268. if (0 >= $post['level_maturity_days_up']) {
  269. $days_new = 0;
  270. }else{
  271. if ($post['level_maturity_days_new'] >= $post['level_maturity_days_up']) {
  272. $days_new = $post['level_maturity_days_new'] - $post['level_maturity_days_up'];
  273. $days_new = $post['level_maturity_days_old'] - $days_new;
  274. }else{
  275. $days_new = $post['level_maturity_days_up'] - $post['level_maturity_days_new'];
  276. $days_new = $post['level_maturity_days_old'] + $days_new;
  277. }
  278. }
  279. $days_new = (99999999 < $days_new) ? 99999999 : $days_new;
  280. $post['level_maturity_days'] = $days_new;
  281. // }
  282. /*end*/
  283. $post['head_pic'] = htmlspecialchars_decode($post['head_pic']);
  284. if (isset($post['users_money'])) {
  285. $users_money = input('post.users_money/f');
  286. $post['users_money'] = (99999999 < $users_money) ? 99999999 : $users_money;
  287. }
  288. if (!empty($post['password']) && trim($post['password'])) {
  289. /*等保密码复杂度验证 start*/
  290. if (is_dir('./weapp/Equal/')) {
  291. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  292. $eqData = $equalLogic->pwdValidate($post['password']);
  293. if (isset($eqData['code']) && empty($eqData['code'])) {
  294. $this->error($eqData['msg']);
  295. }
  296. }
  297. /*等保密码复杂度验证 end*/
  298. if (!empty($this->globalConfig['security_verifyfunc']) && in_array('edit_pwd', $this->globalConfig['security_verifyfunc'])) {
  299. if (true !== security_answer_verify()) {
  300. $this->error("请先密保答案验证");
  301. }
  302. }
  303. $post['password'] = func_encrypt($post['password'], false, pwd_encry_type('bcrypt'));
  304. } else {
  305. unset($post['password']);
  306. }
  307. $ParaData = [];
  308. if (is_array($post['users_'])) {
  309. $ParaData = $post['users_'];
  310. }
  311. unset($post['users_']);
  312. // 处理提交的会员属性中邮箱和手机是否已存在
  313. // isRequired方法传入的参数有2个
  314. // 第一个必须传入提交的会员属性数组
  315. // 第二个users_id,注册时不需要传入,修改时需要传入。
  316. $RequiredData = model('Member')->isRequired($ParaData,$users_id);
  317. if ($RequiredData) {
  318. $this->error($RequiredData);
  319. }
  320. // 处理数据验证
  321. $error = handleEyouDataValidate('users_id', '__token_users_edit__', $post);
  322. if (!empty($error)) $this->error($error);
  323. $users_where = [
  324. 'users_id' => $users_id,
  325. ];
  326. $userinfo = $this->users_db->where($users_where)->find();
  327. $post['update_time'] = getTime();
  328. /*会员级别到期天数*/
  329. if(isset($post['level_maturity_days']) && !empty($post['level_maturity_days'])){
  330. if (empty($userinfo['open_level_time'])) {
  331. $post['open_level_time'] = getTime();
  332. }
  333. }else if (empty($post['level_maturity_days'])) {
  334. $post['open_level_time'] = '';
  335. $level_id = 1;
  336. $post['level'] = $level_id;
  337. }
  338. /*end*/
  339. unset($post['username']);
  340. $r = $this->users_db->where($users_where)->update($post);
  341. if ($r) {
  342. $row2 = $this->users_parameter_db->field('para_id,name,dtype')->getAllWithIndex('name');
  343. //兼容多选字段选择为空时保存失败
  344. foreach ($row2 as $k => $v) {
  345. if ($v['dtype'] == 'checkbox' && empty($ParaData[$v['name']])){
  346. $ParaData[$v['name']] = '';
  347. }
  348. }
  349. foreach ($ParaData as $key => $value) {
  350. $data = [];
  351. $para_id = intval($row2[$key]['para_id']);
  352. $where = [
  353. 'users_id' => $post['users_id'],
  354. 'para_id' => $para_id,
  355. ];
  356. if ('checkbox' == $row2[$key]['dtype']) {
  357. if (!empty($value)) {
  358. $data['info'] = implode(",", $value);
  359. } else {
  360. $data['info'] = '';
  361. }
  362. } elseif ('imgs' == $row2[$key]['dtype']) {
  363. $value = array_filter($value);
  364. if (!empty($value)) {
  365. $data['info'] = implode(",", $value);
  366. } else {
  367. $data['info'] = '';
  368. }
  369. } else {
  370. $data['info'] = $value;
  371. }
  372. $data['update_time'] = getTime();
  373. // 若信息表中无数据则添加
  374. $row = $this->users_list_db->where($where)->count();
  375. if (empty($row)) {
  376. $data['users_id'] = $post['users_id'];
  377. $data['para_id'] = $para_id;
  378. $data['lang'] = $this->admin_lang;
  379. $data['add_time'] = getTime();
  380. $this->users_list_db->add($data);
  381. } else {
  382. $this->users_list_db->where($where)->update($data);
  383. }
  384. }
  385. // 查询属性表的手机号码和邮箱地址,同步修改会员信息。
  386. $UsersListData = model('Member')->getUsersListData('*',$users_id);
  387. $UsersListData['update_time'] = getTime();
  388. $this->users_db->where($users_where)->update($UsersListData);
  389. /*同步头像到管理员表对应的管理员*/
  390. $syn_admin_id = $this->users_db->where(['users_id'=>$post['users_id']])->getField('admin_id');
  391. if (!empty($syn_admin_id)) {
  392. Db::name('admin')->where(['admin_id'=>$syn_admin_id])->update([
  393. 'head_pic' => $post['head_pic'],
  394. 'update_time' => getTime(),
  395. ]);
  396. }
  397. /*end*/
  398. \think\Cache::clear('users_list');
  399. adminLog('编辑会员'.$users_id.':'.$userinfo['username']);
  400. $this->success('操作成功', url('Member/users_index'));
  401. } else {
  402. $this->error('操作失败');
  403. }
  404. }
  405. $assign_data = [];
  406. $users_id = input('param.id/d');
  407. // 会员信息
  408. $info = $this->users_db->where([
  409. 'users_id' => $users_id,
  410. ])->find();
  411. // 计算剩余天数
  412. $days = intval($info['open_level_time']) + (intval($info['level_maturity_days']) * 86400);
  413. // 取整
  414. $days = ceil(($days - getTime()) / 86400);
  415. if (0 >= $days) {
  416. $info['level_maturity_days_new'] = '0';
  417. }else{
  418. $info['level_maturity_days_new'] = $days;
  419. }
  420. $assign_data['info'] = $info;
  421. /*微信登录插件*/
  422. if (is_dir('./weapp/WxLogin/')) {
  423. $assign_data['info']['wxlogin'] = Db::name('weapp_wxlogin')->where(['users_id'=>$users_id])->find();
  424. }
  425. /*end*/
  426. /*QQ登录插件*/
  427. if (is_dir('./weapp/QqLogin/')) {
  428. $assign_data['info']['qqlogin'] = Db::name('weapp_qqlogin')->where(['users_id'=>$users_id])->find();
  429. }
  430. /*end*/
  431. /*微博登录插件*/
  432. if (is_dir('./weapp/Wblogin/')) {
  433. $assign_data['info']['wblogin'] = Db::name('weapp_wblogin')->where(['users_id'=>$users_id])->find();
  434. }
  435. /*end*/
  436. // 等级信息
  437. $assign_data['level'] = model('UsersLevel')->getList('level_id, level_name');
  438. // 属性信息
  439. $assign_data['users_para'] = model('Member')->getDataParaList($users_id);
  440. // 积分
  441. $assign_data['scoreCofing'] = getUsersConfigData('score');
  442. // 上一个页面来源
  443. $from = input('param.from/s');
  444. if ('money_index' == $from) {
  445. $backurl = url('Member/money_index');
  446. } else {
  447. $backurl = url('Member/users_index');
  448. }
  449. $assign_data['backurl'] = $backurl;
  450. // 是否弹窗打开
  451. $iframe = input('param.iframe/d',0);
  452. $assign_data['iframe'] = $iframe;
  453. $assign_data['users_lock_model'] = config('global.users_lock_model');
  454. //订单信息
  455. $assign_data['order_count'] = Db::name('shop_order')->where('order_status',3)->where('users_id',$users_id)->field('count(*) as count,sum(order_amount) as sum')->select();
  456. $assign_data['refund_count'] = Db::name('shop_order_service')
  457. ->where('users_id',$users_id)
  458. ->where('service_type',2)
  459. ->where('status',7)
  460. ->field('count(*) as count,sum(refund_price) as sum')->select();
  461. $this->assign($assign_data);
  462. /*等保密码复杂度验证 start*/
  463. $pwdJsCode = '';
  464. if (is_dir('./weapp/Equal/')) {
  465. $equalLogic = new \weapp\Equal\logic\EqualLogic;
  466. $pwdJsCode = $equalLogic->pwdJsCode();
  467. }
  468. if ('close' == $pwdJsCode) {
  469. $pwdJsCode = '';
  470. }
  471. $this->assign('pwdJsCode', $pwdJsCode);
  472. /*等保密码复杂度验证 end*/
  473. // 如果安装手机端后台管理插件并且在手机端访问时执行
  474. $isMobile = input('param.isMobile/d', 0);
  475. if (is_dir('./weapp/Mbackend/') && !empty($isMobile)) {
  476. return $this->display('member/users_edit');
  477. } else {
  478. return $this->fetch();
  479. }
  480. }
  481. public function query_level_days()
  482. {
  483. $level_id = input('level_id/d', 0);
  484. if (IS_AJAX_POST && !empty($level_id)) {
  485. $maturity_days = 0;
  486. // 查询会员级别的天数
  487. $where = [
  488. 'level_id' => intval($level_id)
  489. ];
  490. $limitID = Db::name('users_type_manage')->where($where)->order('limit_id desc')->getField('limit_id');
  491. if (!empty($limitID)) {
  492. $adminMemberLimitArr = config('global.admin_member_limit_arr');
  493. $maturity_days = !empty($adminMemberLimitArr[$limitID]['maturity_days']) ? intval($adminMemberLimitArr[$limitID]['maturity_days']) : 0;
  494. }
  495. $this->success('查询正确', null, $maturity_days);
  496. }
  497. }
  498. // 会员删除
  499. public function users_del()
  500. {
  501. $users_id = input('del_id/a');
  502. $users_id = eyIntval($users_id);
  503. if (IS_AJAX_POST && !empty($users_id)) {
  504. // 删除统一条件
  505. $Where = [
  506. 'users_id' => ['IN', $users_id],
  507. ];
  508. $result = $this->users_db->field('username,users_id')->where($Where)->select();
  509. $username_list = $users_ids = [];
  510. foreach ($result as $key => $val) {
  511. $username_list[] = $val['username'];
  512. $users_ids[] = $val['users_id'];
  513. }
  514. $return = $this->users_db->where($Where)->delete();
  515. if (false !== $return) {
  516. \think\Cache::clear('users_list');
  517. adminLog('删除会员:'.implode(',', $username_list));
  518. // 如果安装了分销插件则执行
  519. if (is_dir('./weapp/DealerPlugin/')) {
  520. // 开启分销插件则执行
  521. $data = model('Weapp')->getWeappList('DealerPlugin');
  522. if (!empty($data['status']) && 1 == $data['status']) {
  523. // 调用分销逻辑层方法
  524. $dealerCommonLogic = new \weapp\DealerPlugin\logic\DealerCommonLogic;
  525. $dealerCommonLogic->dealerSynchronizeDelete($users_ids);
  526. }
  527. }
  528. model('Member')->afterDel($users_ids);
  529. $this->success('删除成功');
  530. }else{
  531. $this->error('删除失败');
  532. }
  533. }
  534. $this->error('参数有误');
  535. }
  536. // 级别列表
  537. public function level_index()
  538. {
  539. $list = array();
  540. $keywords = input('keywords/s');
  541. $condition = array();
  542. // 应用搜索条件
  543. if (!empty($keywords)) {
  544. $condition['a.level_name'] = array('LIKE', "%{$keywords}%");
  545. }
  546. /**
  547. * 数据查询
  548. */
  549. $count = $this->users_level_db->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  550. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  551. $list = $this->users_level_db->field('a.*')
  552. ->alias('a')
  553. ->where($condition)
  554. ->order('a.level_value asc, a.level_id asc')
  555. ->limit($Page->firstRow.','.$Page->listRows)
  556. ->select();
  557. $show = $Page->show();// 分页显示输出
  558. $this->assign('page',$show);// 赋值分页输出
  559. $this->assign('list',$list);// 赋值数据集
  560. $this->assign('pager',$Page);// 赋值分页集
  561. // 用于判断是否可以删除会员级别,当会员级别下存在会员时,不可删除。
  562. $levelgroup = $this->users_db->field('level')
  563. ->group('level')
  564. ->getAllWithIndex('level');
  565. $this->assign('levelgroup',$levelgroup);
  566. /*是否安装启用下载次数限制插件*/
  567. $isShowDownCount = 0;
  568. if (is_dir('./weapp/Downloads/')) {
  569. $DownloadsRow = model('Weapp')->getWeappList('Downloads');
  570. if (!empty($DownloadsRow['status']) && 1 == $DownloadsRow['status']) {
  571. $isShowDownCount = 1;
  572. }
  573. }
  574. $this->assign('isShowDownCount', $isShowDownCount);
  575. /*end*/
  576. return $this->fetch();
  577. }
  578. // 级别 - 新增
  579. public function level_add()
  580. {
  581. if (IS_POST) {
  582. $post = input('post.');
  583. // 级别名称不可重复
  584. $PostLevelName = array_unique($post['level_name']);
  585. if (count($PostLevelName) != count($post['level_name'])) {
  586. $this->error('级别名称不可重复!');
  587. }
  588. // 会员等级值不可重复
  589. $PostLevelValue = array_unique($post['level_value']);
  590. if (count($PostLevelValue) != count($post['level_value'])) {
  591. $this->error('会员等级值不可重复!');
  592. }
  593. // 数据拼装
  594. $AddUsersLevelData = $where = [];
  595. foreach ($post['level_name'] as $key => $value) {
  596. $level_id = $post['level_id'][$key];
  597. $level_name = trim($value);
  598. $level_value = intval(trim($post['level_value'][$key]));
  599. if (isset($post['discount'][$key])) {
  600. $discount = trim($post['discount'][$key]);
  601. if ($discount < 0 || $discount == '') {
  602. $discount = 100;
  603. }
  604. } else {
  605. $discount = 100;
  606. }
  607. $down_count = isset($post['down_count'][$key]) ? intval($post['down_count'][$key]) : 100;
  608. if (empty($level_name)) $this->error('级别名称不可为空!');
  609. if (empty($level_value)) $this->error('会员等级值不可为空!');
  610. $AddUsersLevelData[$key] = [
  611. 'level_id' => $level_id,
  612. 'level_name' => $level_name,
  613. 'level_value' => $level_value,
  614. 'discount' => $discount,
  615. 'down_count' => $down_count,
  616. 'update_time' => getTime(),
  617. ];
  618. if (empty($level_id)) {
  619. $AddUsersLevelData[$key]['lang'] = $this->admin_lang;
  620. $AddUsersLevelData[$key]['add_time'] = getTime();
  621. unset($AddUsersLevelData[$key]['level_id']);
  622. }
  623. }
  624. $ReturnId = model('UsersLevel')->saveAll($AddUsersLevelData);
  625. if ($ReturnId) {
  626. \think\Cache::clear('users_level');
  627. adminLog('新增会员级别:'.implode(',', $post['level_name']));
  628. $this->success('操作成功', url('Member/level_index'));
  629. } else {
  630. $this->error('操作失败');
  631. }
  632. }
  633. return $this->fetch();
  634. }
  635. // 级别 - 删除
  636. public function level_del()
  637. {
  638. $level_id = input('del_id/a');
  639. $level_id = eyIntval($level_id);
  640. if (IS_AJAX_POST && !empty($level_id)) {
  641. // 查询条件
  642. $where = [
  643. 'level_id' => ['IN', $level_id],
  644. ];
  645. // 查询会员级别
  646. $result = model('UsersLevel')->getList('level_name,is_system,level_value', $where);
  647. $level_name_list = get_arr_column($result, 'level_name');
  648. // 系统内置级别不可删除
  649. foreach ($result as $val) {
  650. if (1 == intval($val['is_system'])) {
  651. $this->error('系统内置,不可删除!');
  652. }
  653. }
  654. // 有使用的会员不可删除
  655. $info = $this->users_db->where([
  656. 'level' => ['IN', $level_id],
  657. ])->count();
  658. if (!empty($info)) {
  659. $this->error('选中的级别存在会员,不可删除!');
  660. }
  661. // 删除指定级别
  662. $return = $this->users_level_db->where($where)->delete();
  663. if ($return) {
  664. // 查询指定会员级别
  665. $where1 = [
  666. 'level_value' => ['>', $result[0]['level_value']],
  667. ];
  668. $result_1 = $this->users_level_db->where($where1)->order('level_value asc')->field('level_id')->find();
  669. if (empty($result_1)) {
  670. $where1 = [
  671. 'level_value' => ['<', $result[0]['level_value']],
  672. ];
  673. $result_1 = $this->users_level_db->where($where1)->order('level_value asc')->field('level_id')->find();
  674. }
  675. // 拼装更新条件
  676. $UpData = [
  677. 'level_id' => $result_1['level_id'],
  678. 'update_time' => getTime(),
  679. ];
  680. // 更新会员升级表数据
  681. Db::name('users_type_manage')->where($where)->update($UpData);
  682. \think\Cache::clear('users_level');
  683. adminLog('删除会员级别:'.implode(',', $level_name_list));
  684. $this->success('删除成功');
  685. }else{
  686. $this->error('删除失败');
  687. }
  688. }
  689. $this->error('参数有误');
  690. }
  691. // 属性列表
  692. public function attr_index()
  693. {
  694. //属性数据
  695. $info = $this->users_parameter_db->field('a.*,a.title,b.title as dtypetitle')
  696. ->alias('a')
  697. ->join('__FIELD_TYPE__ b', 'a.dtype = b.name', 'LEFT')
  698. ->order('a.is_system desc,a.sort_order asc,a.para_id desc')
  699. ->select();
  700. foreach ($info as $key => $value) {
  701. if ('email' == $value['dtype']) {
  702. $info[$key]['dtypetitle'] = '邮箱地址';
  703. } else if ('mobile' == $value['dtype']) {
  704. $info[$key]['dtypetitle'] = '手机号码';
  705. }else if ('datetime' == $value['dtype']) {
  706. $info[$key]['dtypetitle'] = '日期和时间';
  707. }
  708. }
  709. $this->assign('info',$info);
  710. return $this->fetch();
  711. }
  712. // 属性添加
  713. public function attr_add()
  714. {
  715. if (IS_POST) {
  716. $post = input('post.');
  717. $post['title'] = trim($post['title']);
  718. if (empty($post['title'])) {
  719. $this->error('属性标题不能为空!');
  720. }
  721. if (empty($post['dtype'])) {
  722. $this->error('请选择属性类型!');
  723. }
  724. $count = $this->users_parameter_db->where([
  725. 'title'=>$post['title']
  726. ])->count();
  727. if (!empty($count)) {
  728. $this->error('属性标题已存在!');
  729. }
  730. $post['dfvalue'] = str_replace(',', ',', $post['dfvalue']);
  731. $post['dfvalue'] = trim($post['dfvalue'], ',');
  732. /*判断默认值是否含有重复值*/
  733. if (in_array($post['dtype'], ['radio','checkbox','select'])) {
  734. if (!empty($post['dfvalue'])){
  735. $dfvalue_arr = [];
  736. $dfvalue_arr = explode(',', $post['dfvalue']);
  737. foreach ($dfvalue_arr as &$v) {
  738. $v = trim($v);
  739. }
  740. if (count($dfvalue_arr) != count(array_unique($dfvalue_arr))) {
  741. $this->error('默认值不能含有相同的值!');
  742. }
  743. }
  744. }
  745. /*end*/
  746. $post['add_time'] = getTime();
  747. $post['lang'] = $this->admin_lang;
  748. $post['sort_order'] = '100';
  749. $para_id = $this->users_parameter_db->insertGetId($post);
  750. if (!empty($para_id)) {
  751. $name = 'para_'.$para_id;
  752. $return = $this->users_parameter_db->where('para_id',$para_id)
  753. ->update([
  754. 'name' => $name,
  755. 'update_time' => getTime(),
  756. ]);
  757. if ($return !== false) {
  758. \think\Cache::clear('users_parameter');
  759. \think\Cache::clear('users_list');
  760. adminLog('新增会员属性:'.$post['title']);
  761. $this->success('操作成功',url('Member/attr_index'));
  762. }
  763. }
  764. $this->error('操作失败');
  765. }
  766. $field = $this->field_type_db->field('name,title,ifoption')
  767. ->where([
  768. 'name' => ['IN', ['text','checkbox','multitext','radio','select','img','file','datetime','imgs']]
  769. ])
  770. ->select();
  771. $this->assign('field',$field);
  772. return $this->fetch();
  773. }
  774. // 属性修改
  775. public function attr_edit()
  776. {
  777. $para_id = input('param.id/d');
  778. if (IS_POST && !empty($para_id)) {
  779. $post = input('post.');
  780. $post['title'] = trim($post['title']);
  781. if (empty($post['title'])) {
  782. $this->error('属性标题不能为空!');
  783. }
  784. if (empty($post['dtype'])) {
  785. $this->error('请选择属性类型!');
  786. }
  787. $count = $this->users_parameter_db->where([
  788. 'title' => $post['title'],
  789. 'para_id' => ['NEQ', $para_id],
  790. ])->count();
  791. if ($count) {
  792. $this->error('属性标题已存在!');
  793. }
  794. $post['dfvalue'] = str_replace(',', ',', $post['dfvalue']);
  795. $post['dfvalue'] = trim($post['dfvalue'], ',');
  796. /*判断默认值是否含有重复值*/
  797. if (in_array($post['dtype'], ['radio','checkbox','select'])) {
  798. if (!empty($post['dfvalue'])){
  799. $dfvalue_arr = [];
  800. $dfvalue_arr = explode(',', $post['dfvalue']);
  801. foreach ($dfvalue_arr as &$v) {
  802. $v = trim($v);
  803. }
  804. if (count($dfvalue_arr) != count(array_unique($dfvalue_arr))) {
  805. $this->error('默认值不能含有相同的值!');
  806. }
  807. }
  808. }
  809. /*end*/
  810. $post['update_time'] = getTime();
  811. $return = $this->users_parameter_db->where([
  812. 'para_id' => $para_id,
  813. ])->update($post);
  814. if ($return !== false) {
  815. \think\Cache::clear('users_parameter');
  816. \think\Cache::clear('users_list');
  817. adminLog('编辑会员属性:'.$post['title']);
  818. $this->success('操作成功',url('Member/attr_index'));
  819. }else{
  820. $this->error('操作失败');
  821. }
  822. }
  823. $info = $this->users_parameter_db->where([
  824. 'para_id' => $para_id,
  825. ])->find();
  826. $this->assign('info',$info);
  827. $field = $this->field_type_db->field('name,title,ifoption')
  828. ->where([
  829. 'name' => ['IN', ['text','checkbox','multitext','radio','select','img','file','datetime','imgs']]
  830. ])
  831. ->select();
  832. $this->assign('field',$field);
  833. return $this->fetch();
  834. }
  835. // 属性删除
  836. public function attr_del()
  837. {
  838. $para_id = input('del_id/a');
  839. $para_id = eyIntval($para_id);
  840. if (IS_AJAX_POST && !empty($para_id)) {
  841. $result = $this->users_parameter_db->field('title')
  842. ->where([
  843. 'para_id' => ['IN', $para_id],
  844. ])
  845. ->select();
  846. $title_list = get_arr_column($result, 'title');
  847. // 删除会员属性表数据
  848. $return = $this->users_parameter_db->where([
  849. 'para_id' => ['IN', $para_id],
  850. ])->delete();
  851. if ($return !== false) {
  852. // 删除会员属性信息表数据
  853. $this->users_list_db->where([
  854. 'para_id' => ['IN', $para_id],
  855. ])->delete();
  856. \think\Cache::clear('users_parameter');
  857. \think\Cache::clear('users_list');
  858. adminLog('删除会员属性:'.implode(',', $title_list));
  859. $this->success('删除成功');
  860. }
  861. }
  862. $this->error('删除失败');
  863. }
  864. // 功能设置
  865. public function users_config()
  866. {
  867. if (IS_POST) {
  868. $post = input('post.');
  869. // 邮件验证的检测
  870. if (2 == $post['users']['users_verification']) {
  871. $users_config_email = $this->users_config_email();
  872. if (!empty($users_config_email)) {
  873. $this->error($users_config_email);
  874. }
  875. }
  876. // 第三方登录
  877. if (!empty($post['oauth']['oauth_open']) && 1 == $post['oauth']['oauth_open']) {
  878. empty($post['oauth']['oauth_qq']) && $post['oauth']['oauth_qq'] = 0;
  879. empty($post['oauth']['oauth_weixin']) && $post['oauth']['oauth_weixin'] = 0;
  880. empty($post['oauth']['oauth_weibo']) && $post['oauth']['oauth_weibo'] = 0;
  881. }
  882. /*前台登录超时*/
  883. $users_login_expiretime = $post['users']['users_login_expiretime'];
  884. $login_expiretime_old = $post['users']['login_expiretime_old'];
  885. unset($post['users']['login_expiretime_old']);
  886. if ($login_expiretime_old != $users_login_expiretime) {
  887. $users_login_expiretime = preg_replace('/^(\d{0,})(.*)$/i', '${1}', $users_login_expiretime);
  888. empty($users_login_expiretime) && $users_login_expiretime = config('login_expire');
  889. if ($users_login_expiretime > 2592000) {
  890. $users_login_expiretime = 2592000; // 最多一个月
  891. }
  892. $post['users']['users_login_expiretime'] = $users_login_expiretime;
  893. //后台登录超时时间
  894. $web_login_expiretime = tpCache('global.web_login_expiretime');
  895. //前台和后台谁设置的时间大就用谁的做session过期时间
  896. $max_login_expiretime = $web_login_expiretime;
  897. if ($web_login_expiretime < $users_login_expiretime){
  898. $max_login_expiretime = $users_login_expiretime;
  899. }
  900. }
  901. /*--end*/
  902. // 会员投稿设置
  903. if (!empty($this->userConfig['users_open_release'])) {
  904. unset($post['release_typeids']);
  905. unset($post['users']['is_automatic_review']);
  906. unset($post['users']['is_open_posts_count']);
  907. }
  908. // 会员模板切换/前台会员登录过期时间
  909. tpCache('web', $post['web']);
  910. foreach ($post as $key => $val) {
  911. if ('web' == $key) {
  912. continue;
  913. }
  914. getUsersConfigData($key, $val);
  915. }
  916. // 主题色切换
  917. getUsersConfigData('theme', ['users_theme_style_uptime'=>getTime()]);
  918. $ajaxLogic = new \app\admin\logic\AjaxLogic;
  919. $ajaxLogic->users_update_theme_css();
  920. /*更改session会员设置 - session有效期(前台登录超时)*/
  921. if ($login_expiretime_old != $users_login_expiretime) {
  922. $session_conf = [];
  923. $session_file = APP_PATH.'admin/conf/session_conf.php';
  924. if (file_exists($session_file)) {
  925. require_once($session_file);
  926. $session_conf_tmp = EY_SESSION_CONF;
  927. if (!empty($session_conf_tmp)) {
  928. $session_conf_tmp = json_decode($session_conf_tmp, true);
  929. if (!empty($session_conf_tmp) && is_array($session_conf_tmp)) {
  930. $session_conf = $session_conf_tmp;
  931. }
  932. }
  933. }
  934. $session_conf['expire'] = $max_login_expiretime;
  935. $str_session_conf = '<?php'.PHP_EOL.'$session_1600593464 = json_encode('.var_export($session_conf,true).');'.PHP_EOL.'define(\'EY_SESSION_CONF\', $session_1600593464);';
  936. @file_put_contents(APP_PATH . 'admin/conf/session_conf.php', $str_session_conf);
  937. }
  938. /*--end*/
  939. \think\Cache::clear();
  940. delFile(RUNTIME_PATH);
  941. $this->success('操作成功');
  942. }
  943. // 获取会员配置信息
  944. $this->assign('info',$this->userConfig);
  945. // 获取会员配置信息
  946. $this->assign('web_users_tpl_theme', tpCache('global.web_users_tpl_theme'));
  947. // 左侧菜单
  948. $usersTplVersion = getUsersTplVersion();
  949. $this->assign('usersTplVersion', $usersTplVersion);
  950. /*允许发布文档列表的栏目*/
  951. $current_channel = [1,3,4,5]; // 允许投稿的模型
  952. $arctype = Db::name('arctype')->where([
  953. 'current_channel' => ['in',$current_channel],
  954. 'is_release' => 1,
  955. 'lang' => $this->admin_lang,
  956. ])->field('id')->select();
  957. $arctype = get_arr_column($arctype,'id');
  958. $release_select_html = allow_release_arctype($arctype, $current_channel);
  959. if (empty($current_channel)){
  960. $release_select_html = [];
  961. }
  962. $this->assign('release_select_html',$release_select_html);
  963. /*--end*/
  964. /*模板风格列表*/
  965. $web_tpl_theme = config('ey_config.web_tpl_theme');
  966. !empty($web_tpl_theme) && $web_tpl_theme .= '/';
  967. $tpl_theme_list = glob('./template/'.$web_tpl_theme.'pc/users*', GLOB_ONLYDIR);
  968. foreach ($tpl_theme_list as $key => &$val) {
  969. $val = str_replace('\\', '/', $val);
  970. $val = preg_replace('/^(.*)\/([^\/]*)$/i', '${2}', $val);
  971. }
  972. $this->assign('tpl_theme_list', $tpl_theme_list);
  973. /*end*/
  974. return $this->fetch();
  975. }
  976. // 邮件验证的检测
  977. public function ajax_users_config_email()
  978. {
  979. if (IS_AJAX) {
  980. // 邮件验证的检测
  981. $users_config_email = $this->users_config_email();
  982. if (!empty($users_config_email)) $this->error($users_config_email);
  983. $this->success('检验通过');
  984. }
  985. $this->error('参数有误');
  986. }
  987. private function users_config_email(){
  988. // 会员属性信息
  989. $where = array(
  990. 'name' => ['LIKE', "email_%"],
  991. 'is_system' => 1,
  992. );
  993. // 是否要为必填项
  994. $param = $this->users_parameter_db->where($where)->field('title,is_hidden')->find();
  995. if (empty($param) || 1 == $param['is_hidden']) {
  996. return "请先把会员字段的<font color='red'>{$param['title']}</font>设置为显示,且为必填项!";
  997. }
  998. $param = $this->users_parameter_db->where($where)->field('title,is_required')->find();
  999. if (empty($param) || 0 == $param['is_required']) {
  1000. return "请先把会员字段的<font color='red'>{$param['title']}</font>设置为必填项!";
  1001. }
  1002. // 是否开启邮箱发送扩展
  1003. $openssl_funcs = get_extension_funcs('openssl');
  1004. if (!$openssl_funcs) {
  1005. return "请联系空间商,开启php的 <font color='red'>openssl</font> 扩展!";
  1006. }
  1007. $send_email_scene = config('send_email_scene');
  1008. $scene = $send_email_scene[2]['scene'];
  1009. // 自动启用注册邮件模板
  1010. Db::name('smtp_tpl')->where([
  1011. 'send_scene' => $scene,
  1012. 'lang' => $this->admin_lang,
  1013. ])->update([
  1014. 'is_open' => 1,
  1015. 'update_time' => getTime(),
  1016. ]);
  1017. // 是否填写邮件配置
  1018. $globalConfig = tpCache('global');
  1019. if (empty($globalConfig['smtp_user']) || empty($globalConfig['smtp_pwd'])) {
  1020. return "请先完善<font color='red'>(邮件配置)</font>,具体步骤【基本信息】->【接口配置】->【邮件配置】";
  1021. }
  1022. return false;
  1023. }
  1024. // 手机验证的检测
  1025. public function ajax_users_config_mobile()
  1026. {
  1027. if (IS_AJAX) {
  1028. // 邮件验证的检测
  1029. $users_config_mobile = $this->users_config_mobile();
  1030. if (!empty($users_config_mobile)) $this->error($users_config_mobile);
  1031. $this->success('检验通过');
  1032. }
  1033. $this->error('参数有误');
  1034. }
  1035. private function users_config_mobile(){
  1036. // 会员属性信息
  1037. $where = array(
  1038. 'name' => ['LIKE', "mobile_%"],
  1039. 'is_system' => 1
  1040. );
  1041. // 是否要为必填项
  1042. $param = $this->users_parameter_db->where($where)->field('title, is_hidden')->find();
  1043. if (empty($param) || 1 == $param['is_hidden']) {
  1044. return "请先把会员字段的<font color='red'>{$param['title']}</font>设置为显示,且为必填项!";
  1045. }
  1046. $param = $this->users_parameter_db->where($where)->field('title, is_required')->find();
  1047. if (empty($param) || 0 == $param['is_required']) {
  1048. return "请先把会员字段的<font color='red'>{$param['title']}</font>设置为必填项!";
  1049. }
  1050. // 自动启用注册手机模板
  1051. Db::name('sms_template')->where([
  1052. 'send_scene' => 0,
  1053. 'lang' => $this->admin_lang,
  1054. ])->update([
  1055. 'is_open' => 1,
  1056. 'update_time' => getTime()
  1057. ]);
  1058. // 是否填写手机短信配置
  1059. $globalConfig = tpCache('global');
  1060. if ( (1 == $globalConfig['sms_type'] && (empty($globalConfig['sms_appkey']) || empty($globalConfig['sms_secretkey'])))
  1061. || (2 == $globalConfig['sms_type'] && (empty($globalConfig['sms_appid_tx']) || empty($globalConfig['sms_appkey_tx'])))
  1062. ) {
  1063. return "请先完善<font color='red'>(短信配置)</font>,具体步骤【基本信息】->【接口配置】->【短信配置】";
  1064. }
  1065. return false;
  1066. }
  1067. // 充值记录列表
  1068. public function money_index()
  1069. {
  1070. $list = array();
  1071. // 查询条件
  1072. $condition = [
  1073. 'a.cause_type' => 1,
  1074. ];
  1075. // 应用搜索条件
  1076. $keywords = input('keywords/s');
  1077. if (!empty($keywords)) $condition['a.order_number|b.username'] = array('LIKE', "%{$keywords}%");
  1078. // 支付方式查询
  1079. $pay_method = input('pay_method/s');
  1080. if (!empty($pay_method)) $condition['a.pay_method'] = $pay_method;
  1081. // 会员级别查询
  1082. $level = input('level/s');
  1083. if (!empty($level)) $condition['b.level'] = $level;
  1084. // 订单状态搜索
  1085. $order_status = input('param.status/d');
  1086. if ($order_status) $condition['a.status'] = in_array($order_status, [2, 3]) ? ['IN', [2, 3]] : $order_status;
  1087. // 时间检索条件
  1088. $begin = strtotime(input('param.add_time_begin/s'));
  1089. $end = input('param.add_time_end/s');
  1090. !empty($end) && $end .= ' 23:59:59';
  1091. $end = strtotime($end);
  1092. // 时间检索
  1093. if ($begin > 0 && $end > 0) {
  1094. $condition['a.add_time'] = array('between', "$begin, $end");
  1095. } else if ($begin > 0) {
  1096. $condition['a.add_time'] = array('egt', $begin);
  1097. } else if ($end > 0) {
  1098. $condition['a.add_time'] = array('elt', $end);
  1099. }
  1100. // 分页查询
  1101. $count = $this->users_money_db->alias('a')->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')->where($condition)->count();
  1102. $Page = new Page($count, config('paginate.list_rows'));
  1103. // 数据查询
  1104. $list = $this->users_money_db->field('a.*, b.head_pic, b.username, b.nickname, b.level')
  1105. ->alias('a')
  1106. ->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')
  1107. ->where($condition)
  1108. ->order('a.moneyid desc')
  1109. ->limit($Page->firstRow.','.$Page->listRows)
  1110. ->select();
  1111. foreach ($list as $key => $value) {
  1112. $value['username'] = !empty($value['nickname']) ? $value['nickname'] : $value['username'];
  1113. $value['head_pic'] = get_head_pic($value['head_pic']);
  1114. $list[$key] = $value;
  1115. }
  1116. $show = $Page->show();
  1117. $this->assign('page', $show);
  1118. $this->assign('list', $list);
  1119. $this->assign('pager', $Page);
  1120. // 会员等级列表
  1121. $usersLevel = model('UsersLevel')->getList('level_id, level_name', [], 'level_id');
  1122. $this->assign('usersLevel', $usersLevel);
  1123. // 充值状态
  1124. $pay_status_arr = config('global.pay_status_arr');
  1125. $this->assign('pay_status_arr', $pay_status_arr);
  1126. // 是否开启文章付费
  1127. $channelRow = Db::name('channeltype')->where('nid', 'in',['article','download'])->getAllWithIndex('nid');
  1128. foreach ($channelRow as &$val){
  1129. if (!empty($val['data'])) $val['data'] = json_decode($val['data'], true);
  1130. }
  1131. $this->assign('channelRow', $channelRow);
  1132. return $this->fetch();
  1133. }
  1134. // 充值记录编辑
  1135. public function money_edit()
  1136. {
  1137. $param = input('param.');
  1138. $MoneyData = $this->users_money_db->find($param['moneyid']);
  1139. $this->assign('MoneyData',$MoneyData);
  1140. $UsersData = $this->users_db->find($MoneyData['users_id']);
  1141. $this->assign('UsersData',$UsersData);
  1142. // 支付宝查询订单
  1143. if ('alipay' == $MoneyData['pay_method']) {
  1144. $return = $this->check_alipay_order($MoneyData['order_number']);
  1145. $this->assign('return',$return);
  1146. }
  1147. // 微信查询订单
  1148. if ('wechat' == $MoneyData['pay_method']) {
  1149. $return = $this->check_wechat_order($MoneyData['order_number']);
  1150. $this->assign('return',$return);
  1151. }
  1152. // 人为处理订单
  1153. if ('artificial' == $MoneyData['pay_method']) {
  1154. $return = '人为处理';
  1155. $this->assign('return',$return);
  1156. }
  1157. // 获取订单状态
  1158. $pay_status_arr = Config::get('global.pay_status_arr');
  1159. $this->assign('pay_status_arr',$pay_status_arr);
  1160. // 支付方式
  1161. $pay_method_arr = config('global.pay_method_arr');
  1162. $this->assign('pay_method_arr',$pay_method_arr);
  1163. return $this->fetch();
  1164. }
  1165. /**
  1166. * 删除充值记录
  1167. */
  1168. public function money_del()
  1169. {
  1170. if (IS_POST) {
  1171. $id_arr = input('del_id/a');
  1172. $id_arr = eyIntval($id_arr);
  1173. if(!empty($id_arr)){
  1174. $result = Db::name('users_money')->field('order_number')
  1175. ->where([
  1176. 'moneyid' => ['IN', $id_arr],
  1177. ])->select();
  1178. $order_number_list = get_arr_column($result, 'order_number');
  1179. $r = Db::name('users_money')->where([
  1180. 'moneyid' => ['IN', $id_arr],
  1181. ])
  1182. ->cache(true, null, "users_money")
  1183. ->delete();
  1184. if($r !== false){
  1185. adminLog('删除充值记录:'.implode(',', $order_number_list));
  1186. $this->success('删除成功');
  1187. }
  1188. }
  1189. $this->error('删除失败');
  1190. }
  1191. $this->error('非法访问');
  1192. }
  1193. // 标记订单逻辑
  1194. public function money_mark_order()
  1195. {
  1196. if (IS_POST) {
  1197. $moneyid = input('param.moneyid/d');
  1198. // 查询订单信息
  1199. $MoneyData = $this->users_money_db->where([
  1200. 'moneyid' => $moneyid,
  1201. ])->find();
  1202. // 处理订单逻辑
  1203. if (in_array($MoneyData['status'], [1,3])) {
  1204. $users_id = $MoneyData['users_id'];
  1205. $order_number = $MoneyData['order_number'];
  1206. $return = '';
  1207. if ('alipay' == $MoneyData['pay_method']) { // 支付宝查询订单
  1208. $return = $this->check_alipay_order($order_number);
  1209. } else if ('wechat' == $MoneyData['pay_method']) { // 微信查询订单
  1210. $return = $this->check_wechat_order($order_number);
  1211. } else if ('artificial' == $MoneyData['pay_method']) { // 手工充值订单
  1212. $return = '手工充值';
  1213. }
  1214. $result = [
  1215. 'users_id' => $users_id,
  1216. 'order_number'=> $order_number,
  1217. 'status' => '手动标记为已充值订单',
  1218. 'details' => '充值详情:'.$return,
  1219. 'pay_method' => 'artificial', //人为处理
  1220. 'money' => $MoneyData['money'],
  1221. 'users_money' => $MoneyData['users_money'],
  1222. ];
  1223. // 标记为未付款
  1224. if (3 == $MoneyData['status']) {
  1225. $result['status'] = '手动标记为未付款订单';
  1226. } else if (1 == $MoneyData['status']) {
  1227. $result['status'] = '手动标记为已充值订单';
  1228. }
  1229. // 修改会员充值明细表对应的订单数据,存入返回的数据,订单标记为已付款
  1230. $Where = [
  1231. 'moneyid' => $MoneyData['moneyid'],
  1232. 'users_id' => $users_id,
  1233. ];
  1234. $UpdateData = [
  1235. 'pay_details' => serialize($result),
  1236. 'update_time' => getTime(),
  1237. ];
  1238. // 标记为未付款时则状态更新为1
  1239. if (3 == $MoneyData['status']) {
  1240. $UpdateData['status'] = 1;
  1241. } else if (1 == $MoneyData['status']) {
  1242. $UpdateData['status'] = 3;
  1243. $UpdateData['pay_method'] = 'admin_pay';
  1244. $UpdateData['wechat_pay_type'] = '';
  1245. }
  1246. $IsMoney = $this->users_money_db->where($Where)->update($UpdateData);
  1247. if (!empty($IsMoney)) {
  1248. // 同步修改会员的金额
  1249. $UsersData = [
  1250. 'update_time' => getTime(),
  1251. ];
  1252. // 标记为未付款时则减去金额
  1253. if (3 == $MoneyData['status']) {
  1254. $UsersData = $this->users_db->field('users_money')->find($users_id);
  1255. if ($UsersData['users_money'] <= $MoneyData['money']) {
  1256. $UsersData['users_money'] = 0;
  1257. }else{
  1258. $UsersData['users_money'] = Db::raw('users_money-'.$MoneyData['money']);
  1259. }
  1260. } else if (1 == $MoneyData['status']) {
  1261. $UsersData['users_money'] = Db::raw('users_money+'.$MoneyData['money']);
  1262. }
  1263. $IsUsers = $this->users_db->where('users_id',$users_id)->update($UsersData);
  1264. if (!empty($IsUsers)) {
  1265. $this->success('操作成功');
  1266. }
  1267. }
  1268. }
  1269. $this->error('操作失败');
  1270. }
  1271. }
  1272. // 查询订单付款状态(微信)
  1273. private function check_wechat_order($order_number)
  1274. {
  1275. if (!empty($order_number)) {
  1276. // 引入文件
  1277. vendor('wechatpay.lib.WxPayApi');
  1278. vendor('wechatpay.lib.WxPayConfig');
  1279. // 实例化加载订单号
  1280. $input = new \WxPayOrderQuery;
  1281. $input->SetOut_trade_no($order_number);
  1282. // 处理微信配置数据
  1283. $pay_wechat_config = !empty($this->userConfig['pay_wechat_config']) ? $this->userConfig['pay_wechat_config'] : '';
  1284. $pay_wechat_config = unserialize($pay_wechat_config);
  1285. $config_data['app_id'] = $pay_wechat_config['appid'];
  1286. $config_data['mch_id'] = $pay_wechat_config['mchid'];
  1287. $config_data['key'] = $pay_wechat_config['key'];
  1288. // 实例化微信配置
  1289. $config = new \WxPayConfig($config_data);
  1290. $wxpayapi = new \WxPayApi;
  1291. // 返回结果
  1292. $result = $wxpayapi->orderQuery($config, $input);
  1293. // 判断结果
  1294. if ('ORDERNOTEXIST' == $result['err_code'] && 'FAIL' == $result['result_code']) {
  1295. return '订单在微信中不存在!';
  1296. }else if ('NOTPAY' == $result['trade_state'] && 'SUCCESS' == $result['result_code']) {
  1297. return '订单在微信中生成,但并未支付完成!';
  1298. }else if ('SUCCESS' == $result['trade_state'] && 'SUCCESS' == $result['result_code']) {
  1299. return '订单已使用'.$result['attach'].'完成!';
  1300. }
  1301. }else{
  1302. return false;
  1303. }
  1304. }
  1305. // 查询订单付款状态(支付宝)
  1306. private function check_alipay_order($order_number,$admin_pay='',$alipay='')
  1307. {
  1308. if (!empty($order_number)) {
  1309. // 引入文件
  1310. vendor('alipay.pagepay.service.AlipayTradeService');
  1311. vendor('alipay.pagepay.buildermodel.AlipayTradeQueryContentBuilder');
  1312. // 实例化加载订单号
  1313. $RequestBuilder = new \AlipayTradeQueryContentBuilder;
  1314. $out_trade_no = trim($order_number);
  1315. $RequestBuilder->setOutTradeNo($out_trade_no);
  1316. // 处理支付宝配置数据
  1317. if (empty($alipay)) {
  1318. $pay_alipay_config = !empty($this->userConfig['pay_alipay_config']) ? $this->userConfig['pay_alipay_config'] : '';
  1319. if (empty($pay_alipay_config)) {
  1320. return false;
  1321. }
  1322. $alipay = unserialize($pay_alipay_config);
  1323. }
  1324. $config['app_id'] = $alipay['app_id'];
  1325. $config['merchant_private_key'] = $alipay['merchant_private_key'];
  1326. $config['charset'] = 'UTF-8';
  1327. $config['sign_type'] = 'RSA2';
  1328. $config['gatewayUrl'] = 'https://openapi.alipay.com/gateway.do';
  1329. $config['alipay_public_key'] = $alipay['alipay_public_key'];
  1330. // 实例化支付宝配置
  1331. $aop = new \AlipayTradeService($config);
  1332. // 返回结果
  1333. if (!empty($admin_pay)) {
  1334. $result = $aop->IsQuery($RequestBuilder,$admin_pay);
  1335. }else{
  1336. $result = $aop->Query($RequestBuilder);
  1337. }
  1338. $result = json_decode(json_encode($result),true);
  1339. // 判断结果
  1340. if ('40004' == $result['code'] && 'Business Failed' == $result['msg']) {
  1341. // 用于支付宝支付配置验证
  1342. if (!empty($admin_pay)) { return 'ok'; }
  1343. // 用于订单查询
  1344. return '订单在支付宝中不存在!';
  1345. }else if ('10000' == $result['code'] && 'WAIT_BUYER_PAY' == $result['trade_status']) {
  1346. return '订单在支付宝中生成,但并未支付完成!';
  1347. }else if ('10000' == $result['code'] && 'TRADE_SUCCESS' == $result['trade_status']) {
  1348. return '订单已使用支付宝支付完成!';
  1349. }
  1350. // 用于支付宝支付配置验证
  1351. if (!empty($admin_pay) && !empty($result)) {
  1352. if ('40001' == $result['code'] && 'Missing Required Arguments' == $result['msg']) {
  1353. return '商户私钥错误!';
  1354. }
  1355. if (!is_array($result)) {
  1356. return $result;
  1357. }
  1358. }
  1359. }
  1360. }
  1361. /**
  1362. * 版本检测更新弹窗
  1363. */
  1364. public function ajax_check_upgrade_version()
  1365. {
  1366. $memberLogic = new MemberLogic;
  1367. $upgradeMsg = $memberLogic->checkVersion(); // 升级包消息
  1368. $this->success('检测成功', null, $upgradeMsg);
  1369. }
  1370. /**
  1371. * 一键升级
  1372. */
  1373. public function OneKeyUpgrade(){
  1374. header('Content-Type:application/json; charset=utf-8');
  1375. function_exists('set_time_limit') && set_time_limit(0);
  1376. /*权限控制 by 小虎哥*/
  1377. $auth_role_info = session('admin_info.auth_role_info');
  1378. if(0 < intval(session('admin_info.role_id')) && ! empty($auth_role_info) && intval($auth_role_info['online_update']) <= 0){
  1379. $this->error('您没有操作权限,请联系超级管理员分配权限');
  1380. }
  1381. /*--end*/
  1382. $memberLogic = new MemberLogic;
  1383. $data = $memberLogic->OneKeyUpgrade(); //升级包消息
  1384. if (1 <= intval($data['code'])) {
  1385. $this->success($data['msg'], null, ['code'=>$data['code']]);
  1386. } else {
  1387. $msg = '模板升级异常,请排查问题!';
  1388. if (is_array($data)) {
  1389. $msg = $data['msg'];
  1390. }
  1391. $this->error($msg);
  1392. }
  1393. }
  1394. /**
  1395. * 检测目录权限
  1396. */
  1397. public function check_authority()
  1398. {
  1399. $filelist = input('param.filelist/s');
  1400. $memberLogic = new MemberLogic;
  1401. $data = $memberLogic->checkAuthority($filelist); //检测目录权限
  1402. if (is_array($data)) {
  1403. if (1 == $data['code']) {
  1404. $this->success($data['msg']);
  1405. } else {
  1406. $this->error($data['msg'], null, $data['data']);
  1407. }
  1408. } else {
  1409. $this->error('检测模板失败', null, ['code'=>1]);
  1410. }
  1411. }
  1412. // 前台会员左侧菜单
  1413. public function ajax_menu_index()
  1414. {
  1415. $list = array();
  1416. $condition = array();
  1417. $usersTplVersion = getUsersTplVersion();
  1418. if ('v2' == $usersTplVersion) {
  1419. $condition['a.version'] = array('EQ', $usersTplVersion);
  1420. } else {
  1421. $condition['a.version'] = array('IN', ['weapp', $usersTplVersion]);
  1422. }
  1423. /**
  1424. * 数据查询
  1425. */
  1426. $count = Db::name('users_menu')->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  1427. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  1428. $row = Db::name('users_menu')->field('a.*')
  1429. ->alias('a')
  1430. ->where($condition)
  1431. ->order('a.sort_order asc, a.id asc')
  1432. ->limit($Page->firstRow.','.$Page->listRows)
  1433. ->select();
  1434. $list = [];
  1435. foreach ($row as $key => $val) {
  1436. $list[] = $val;
  1437. }
  1438. $show = $Page->show();// 分页显示输出
  1439. $this->assign('page',$show);// 赋值分页输出
  1440. $this->assign('list',$list);// 赋值数据集
  1441. $this->assign('pager',$Page);// 赋值分页集
  1442. return $this->fetch();
  1443. }
  1444. // 前台会员手机端底部菜单
  1445. public function ajax_bottom_menu_index()
  1446. {
  1447. $list = array();
  1448. $condition = array();
  1449. $condition['a.lang'] = $this->main_lang;
  1450. /**
  1451. * 数据查询
  1452. */
  1453. $count = Db::name('users_bottom_menu')->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  1454. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  1455. $list = Db::name('users_bottom_menu')->field('a.*')
  1456. ->alias('a')
  1457. ->where($condition)
  1458. ->order('a.sort_order asc, a.id asc')
  1459. ->limit($Page->firstRow.','.$Page->listRows)
  1460. ->select();
  1461. // 手机端会员中心底部菜单配置选项
  1462. $mobile_user_bottom_menu_config = Config::get('global.mobile_user_bottom_menu_config');
  1463. if ($mobile_user_bottom_menu_config) {
  1464. foreach ($mobile_user_bottom_menu_config as $key=>$v) {
  1465. switch ($v['mca']) {
  1466. case 'user/Level/level_centre':
  1467. $is_open = getUsersConfigData('level.level_member_upgrade');
  1468. if (!$is_open || $is_open != 1) unset($mobile_user_bottom_menu_config[$key]);
  1469. break;
  1470. case 'user/Pay/pay_account_recharge':
  1471. $is_open = getUsersConfigData('level.level_member_upgrade');
  1472. if (!$is_open || $is_open != 1) unset($mobile_user_bottom_menu_config[$key]);
  1473. break;
  1474. case 'user/Shop/shop_centre':
  1475. $is_open = getUsersConfigData('shop.shop_open');
  1476. if (!$is_open || $is_open != 1) unset($mobile_user_bottom_menu_config[$key]);
  1477. break;
  1478. case 'user/Shop/shop_cart_list':
  1479. $is_open = getUsersConfigData('shop.shop_open');
  1480. if (!$is_open || $is_open != 1) unset($mobile_user_bottom_menu_config[$key]);
  1481. break;
  1482. case 'user/UsersRelease/article_add':
  1483. $is_open = getUsersConfigData('users.users_open_release');
  1484. if (!$is_open || $is_open != 1) unset($mobile_user_bottom_menu_config[$key]);
  1485. break;
  1486. case 'user/UsersRelease/release_centre':
  1487. $is_open = getUsersConfigData('users.users_open_release');
  1488. if (!$is_open || $is_open != 1) unset($mobile_user_bottom_menu_config[$key]);
  1489. break;
  1490. case 'user/Download/index':
  1491. $is_open = Db::name("channeltype")->where(['nid'=>'download','status'=>1])->value("id");
  1492. if (!$is_open) unset($mobile_user_bottom_menu_config[$key]);
  1493. break;
  1494. }
  1495. }
  1496. }
  1497. $this->assign('mobile_user_bottom_menu_config',$mobile_user_bottom_menu_config);
  1498. $show = $Page->show();// 分页显示输出
  1499. $this->assign('page',$show);// 赋值分页输出
  1500. $this->assign('list',$list);// 赋值数据集
  1501. $this->assign('pager',$Page);// 赋值分页集
  1502. return $this->fetch();
  1503. }
  1504. /**
  1505. * 登录会员面板
  1506. */
  1507. public function syn_users_login($users_id = 0, $mca = '', $vars = [])
  1508. {
  1509. if (!empty($users_id)) {
  1510. $users = Db::name('users')->field('a.*,b.level_name,b.level_value,b.discount as level_discount')
  1511. ->alias('a')
  1512. ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
  1513. ->where([
  1514. 'a.users_id' => $users_id,
  1515. 'a.is_del' => 0,
  1516. ])->find();
  1517. if (!empty($users)) {
  1518. session('users_id',$users_id);
  1519. session('users_login_expire', getTime()); // 登录有效期
  1520. $url = get_homeurl($mca, $vars);
  1521. $this->redirect($url);
  1522. } else {
  1523. $this->error('该用户不存在!');
  1524. }
  1525. }
  1526. }
  1527. // --------------------------视频订单------------------------------ //
  1528. // 视频订单列表页
  1529. public function media_index()
  1530. {
  1531. // 定义数组
  1532. $condition = [];
  1533. // 订单状态搜索
  1534. $order_status = input('param.order_status/d', 0);
  1535. if (!empty($order_status)) $condition['a.order_status'] = intval($order_status) === 1 ? intval($order_status) : 0;
  1536. // 订单号或用户名搜索
  1537. $keywords = input('keywords/s', '');
  1538. if (!empty($keywords)) $condition['a.order_code|b.username'] = ['LIKE', "%{$keywords}%"];
  1539. // 支付方式查询
  1540. $pay_name = input('pay_name/s', '');
  1541. if (!empty($pay_name)) $condition['a.pay_name'] = $pay_name;
  1542. // 时间检索条件
  1543. $begin = strtotime(input('param.add_time_begin/s'));
  1544. $end = input('param.add_time_end/s');
  1545. !empty($end) && $end .= ' 23:59:59';
  1546. $end = strtotime($end);
  1547. // 时间检索
  1548. if ($begin > 0 && $end > 0) {
  1549. $condition['a.add_time'] = array('between', "$begin, $end");
  1550. } else if ($begin > 0) {
  1551. $condition['a.add_time'] = array('egt', $begin);
  1552. } else if ($end > 0) {
  1553. $condition['a.add_time'] = array('elt', $end);
  1554. }
  1555. // 分页查询
  1556. $count = Db::name('media_order')->alias('a')->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')->where($condition)->count();
  1557. $Page = new Page($count, config('paginate.list_rows'));
  1558. // 数据查询
  1559. $list = Db::name('media_order')->where($condition)
  1560. ->field('a.*, b.head_pic, b.username, b.nickname')
  1561. ->alias('a')
  1562. ->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')
  1563. ->order('a.order_id desc')
  1564. ->limit($Page->firstRow.','.$Page->listRows)
  1565. ->select();
  1566. foreach ($list as $key => $value) {
  1567. $value['username'] = !empty($value['nickname']) ? $value['nickname'] : $value['username'];
  1568. $value['head_pic'] = get_head_pic($value['head_pic']);
  1569. $list[$key] = $value;
  1570. }
  1571. $show = $Page->show();
  1572. $this->assign('list', $list);
  1573. $this->assign('page', $show);
  1574. $this->assign('pager', $Page);
  1575. // 是否开启文章付费
  1576. $channelRow = Db::name('channeltype')->where('nid', 'in',['article','download'])->getAllWithIndex('nid');
  1577. foreach ($channelRow as &$val){
  1578. if (!empty($val['data'])) $val['data'] = json_decode($val['data'], true);
  1579. }
  1580. $this->assign('channelRow', $channelRow);
  1581. return $this->fetch();
  1582. }
  1583. // 视频订单详情页
  1584. public function media_order_details()
  1585. {
  1586. $order_id = input('param.order_id/d');
  1587. if (!empty($order_id)) {
  1588. // 查询订单信息
  1589. $OrderData = Db::name('media_order')->field('*, product_id as aid')->find($order_id);
  1590. // 查询会员数据
  1591. $UsersData = $this->users_db->find($OrderData['users_id']);
  1592. // 用于点击视频文档跳转到前台
  1593. $array_new = get_archives_data([$OrderData], 'product_id');
  1594. // 内页地址
  1595. $OrderData['arcurl'] = get_arcurl($array_new[$OrderData['product_id']]);
  1596. // 支持子目录
  1597. $OrderData['product_litpic'] = get_default_pic($OrderData['product_litpic']);
  1598. // 加载数据
  1599. $this->assign('OrderData', $OrderData);
  1600. $this->assign('UsersData', $UsersData);
  1601. return $this->fetch();
  1602. } else {
  1603. $this->error('非法访问!');
  1604. }
  1605. }
  1606. // 视频订单批量删除
  1607. public function media_order_del()
  1608. {
  1609. $order_id = input('del_id/a');
  1610. $order_id = eyIntval($order_id);
  1611. if (IS_AJAX_POST && !empty($order_id)) {
  1612. // 条件数组
  1613. $Where = [
  1614. 'order_id' => ['IN', $order_id],
  1615. ];
  1616. $result = Db::name('media_order')->field('order_code')->where($Where)->select();
  1617. $order_code_list = get_arr_column($result, 'order_code');
  1618. // 删除订单列表数据
  1619. $return = Db::name('media_order')->where($Where)->delete();
  1620. if ($return) {
  1621. adminLog('删除订单:'.implode(',', $order_code_list));
  1622. $this->success('删除成功');
  1623. } else {
  1624. $this->error('删除失败');
  1625. }
  1626. }
  1627. $this->error('参数有误');
  1628. }
  1629. // --------------------------视频订单------------------------------ //
  1630. // 文章订单列表页
  1631. public function article_index()
  1632. {
  1633. // 定义数组
  1634. $condition = [];
  1635. // 订单状态搜索
  1636. $order_status = input('param.order_status/d', 0);
  1637. if (!empty($order_status)) $condition['a.order_status'] = intval($order_status) === 1 ? intval($order_status) : 0;
  1638. // 订单号或用户名搜索
  1639. $keywords = input('keywords/s', '');
  1640. if (!empty($keywords)) $condition['a.order_code|b.username'] = ['LIKE', "%{$keywords}%"];
  1641. // 支付方式查询
  1642. $pay_name = input('pay_name/s', '');
  1643. if (!empty($pay_name)) $condition['a.pay_name'] = $pay_name;
  1644. // 时间检索条件
  1645. $begin = strtotime(input('param.add_time_begin/s'));
  1646. $end = input('param.add_time_end/s');
  1647. !empty($end) && $end .= ' 23:59:59';
  1648. $end = strtotime($end);
  1649. // 时间检索
  1650. if ($begin > 0 && $end > 0) {
  1651. $condition['a.add_time'] = array('between', "$begin, $end");
  1652. } else if ($begin > 0) {
  1653. $condition['a.add_time'] = array('egt', $begin);
  1654. } else if ($end > 0) {
  1655. $condition['a.add_time'] = array('elt', $end);
  1656. }
  1657. // 分页查询
  1658. $count = Db::name('article_order')->alias('a')->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')->where($condition)->count();
  1659. $Page = new Page($count, config('paginate.list_rows'));
  1660. // 数据查询
  1661. $list = Db::name('article_order')->where($condition)
  1662. ->field('a.*, b.head_pic, b.username, b.nickname')
  1663. ->alias('a')
  1664. ->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')
  1665. ->order('a.order_id desc')
  1666. ->limit($Page->firstRow.','.$Page->listRows)
  1667. ->select();
  1668. foreach ($list as $key => $value) {
  1669. $value['username'] = !empty($value['nickname']) ? $value['nickname'] : $value['username'];
  1670. $value['head_pic'] = get_head_pic($value['head_pic']);
  1671. $list[$key] = $value;
  1672. }
  1673. $show = $Page->show();
  1674. $this->assign('list', $list);
  1675. $this->assign('page', $show);
  1676. $this->assign('pager', $Page);
  1677. // 是否开启文章付费
  1678. $channelRow = Db::name('channeltype')->where('nid', 'in',['article','download'])->getAllWithIndex('nid');
  1679. foreach ($channelRow as &$val){
  1680. if (!empty($val['data'])) $val['data'] = json_decode($val['data'], true);
  1681. }
  1682. $this->assign('channelRow', $channelRow);
  1683. return $this->fetch();
  1684. }
  1685. // 文章订单详情页
  1686. public function article_order_details()
  1687. {
  1688. $order_id = input('param.order_id/d');
  1689. if (!empty($order_id)) {
  1690. $OrderData = Db::name('article_order')->field('*, product_id as aid')->find($order_id);
  1691. $UsersData = $this->users_db->find($OrderData['users_id']);
  1692. // 用于点击视频文档跳转到前台
  1693. $array_new = get_archives_data([$OrderData], 'product_id');
  1694. // 内页地址
  1695. $OrderData['arcurl'] = get_arcurl($array_new[$OrderData['product_id']]);
  1696. // 支持子目录
  1697. $OrderData['product_litpic'] = get_default_pic($OrderData['product_litpic']);
  1698. $this->assign('OrderData', $OrderData);
  1699. $this->assign('UsersData', $UsersData);
  1700. return $this->fetch();
  1701. } else {
  1702. $this->error('非法访问!');
  1703. }
  1704. }
  1705. // 文章订单批量删除
  1706. public function article_order_del()
  1707. {
  1708. $order_id = input('del_id/a');
  1709. $order_id = eyIntval($order_id);
  1710. if (IS_AJAX_POST && !empty($order_id)) {
  1711. $Where = [
  1712. 'order_id' => ['IN', $order_id],
  1713. ];
  1714. $result = Db::name('article_order')->field('order_code')->where($Where)->select();
  1715. $order_code_list = get_arr_column($result, 'order_code');
  1716. // 删除订单列表数据
  1717. $return = Db::name('article_order')->where($Where)->delete();
  1718. if ($return) {
  1719. adminLog('删除文章订单:'.implode(',', $order_code_list));
  1720. $this->success('删除成功');
  1721. } else {
  1722. $this->error('删除失败');
  1723. }
  1724. }
  1725. $this->error('参数有误');
  1726. }
  1727. //积分明细
  1728. public function users_score_detail()
  1729. {
  1730. $condition = [];
  1731. $users_id = input('param.users_id/d');
  1732. $condition['a.users_id'] = $users_id;
  1733. $pagesize = 10;
  1734. $count = Db::name('users_score')->alias('a')->where($condition)->count();
  1735. $Page = new Page($count, $pagesize);
  1736. $list = Db::name('users_score')
  1737. ->alias('a')
  1738. ->field('a.*,b.user_name,c.nickname')
  1739. ->where($condition)
  1740. ->join('admin b','a.admin_id = b.admin_id','left')
  1741. ->join('users c','c.users_id = a.users_id','left')
  1742. ->order('a.id desc')
  1743. ->limit($Page->firstRow.','.$Page->listRows)
  1744. ->select();
  1745. $show = $Page->show();
  1746. $this->assign('page',$show);
  1747. $this->assign('list',$list);
  1748. $this->assign('pager',$Page);
  1749. return $this->fetch('member/edit/users_score_detail');
  1750. }
  1751. //余额明细
  1752. public function users_money_detail()
  1753. {
  1754. $users_id = input('param.users_id/d');
  1755. $condition = [
  1756. 'a.users_id' => $users_id,
  1757. 'a.status' => ['IN', [2, 3]],
  1758. ];
  1759. $count = Db::name('users_money')->alias('a')->where($condition)->count();
  1760. $Page = new Page($count, 10);
  1761. $list = Db::name('users_money')
  1762. ->alias('a')
  1763. ->field('a.*,b.user_name,c.nickname')
  1764. ->where($condition)
  1765. ->join('admin b','a.admin_id = b.admin_id','left')
  1766. ->join('users c','c.users_id = a.users_id','left')
  1767. ->order('a.update_time desc, a.moneyid desc')
  1768. ->limit($Page->firstRow.','.$Page->listRows)
  1769. ->select();
  1770. foreach ($list as $k => $v) {
  1771. $v['money'] = floatval($v['money']);
  1772. $v['users_money'] = floatval($v['users_money']);
  1773. if (isset($v['cause_type']) && 0 == $v['cause_type']) $v['cause'] = unserialize($v['cause']);
  1774. $list[$k] = $v;
  1775. }
  1776. $show = $Page->show();
  1777. $this->assign('page', $show);
  1778. $this->assign('list', $list);
  1779. $this->assign('pager', $Page);
  1780. $this->assign('increase_type', [0, 3, 5, 6]);
  1781. $this->assign('pay_cause_type_arr', Config::get('global.pay_cause_type_arr'));
  1782. return $this->fetch('member/edit/users_money_detail');
  1783. }
  1784. // 余额充值
  1785. public function users_edit_money()
  1786. {
  1787. $post = input('param.');
  1788. $users_id = $post['users_id'] = intval($post['users_id']);
  1789. $users = $this->users_db->where('users_id', $users_id)->find();
  1790. if (IS_POST) {
  1791. if (empty($post['type'])){
  1792. $this->error('请选择变化!');
  1793. }
  1794. if (empty($post['money']) && in_array($post['type'], [1,2])){
  1795. $this->error('变动数值不能为空或0');
  1796. } else if (!empty($post['money']) && !preg_match('/^([0-9\.]+)$/i', $post['money'])) {
  1797. $this->error('变动数值格式不正确!');
  1798. }
  1799. // 处理数据验证
  1800. $error = handleEyouDataValidate('users_id', '__token_users_edit_money__', $post);
  1801. if (!empty($error)) $this->error($error);
  1802. $times = getTime();
  1803. // 添加会员余额记录
  1804. $insert = [
  1805. 'users_id' => $users_id,
  1806. 'money' => floatval($post['money']),
  1807. 'users_money' => floatval($users['users_money']) + floatval($post['money']),
  1808. ];
  1809. // 更新会员主表余额
  1810. $update = [
  1811. 'update_time' => $times,
  1812. ];
  1813. // 4-管理员添加 5-管理员减少
  1814. $cause_type = 4;
  1815. if (1 === intval($post['type'])) {
  1816. //增加
  1817. $update['users_money'] = Db::raw('users_money+'.floatval($post['money']));
  1818. } else if (2 === intval($post['type'])) {
  1819. //减少
  1820. $cause_type = 5;
  1821. $update['users_money'] = Db::raw('users_money-'.floatval($post['money']));
  1822. $insert['users_money'] = floatval($users['users_money']) - floatval($post['money']);
  1823. } else if (3 === intval($post['type'])) {
  1824. $insert['users_money'] = floatval($post['money']);
  1825. $update['users_money'] = floatval($post['money']);
  1826. // 变化余额 大于 会员余额则执行
  1827. if (floatval($post['money']) > floatval($users['users_money'])) {
  1828. $cause_type = 4;
  1829. $insert['money'] = floatval($post['money']) - floatval($users['users_money']);
  1830. }
  1831. // 变化余额 小于 会员余额则执行
  1832. else {
  1833. $cause_type = 5;
  1834. $insert['money'] = floatval($users['users_money']) - floatval($post['money']);
  1835. }
  1836. }
  1837. // 更新会员主表余额
  1838. $where = [
  1839. 'users_id' => $users_id,
  1840. ];
  1841. $r = $this->users_db->where($where)->update($update);
  1842. if ($r !== false) {
  1843. // 添加会员余额记录
  1844. $insert['admin_id'] = session('admin_id');
  1845. $insert['cause'] = !empty($post['cause']) ? $post['cause'] : '';
  1846. $insert['cause_type'] = $cause_type;
  1847. $insert['status'] = 3;
  1848. $insert['add_time'] = $times;
  1849. $insert['update_time'] = $times;
  1850. $this->users_money_db->insert($insert);
  1851. adminLog('编辑 '.$users['nickname'].' 的会员余额');
  1852. $this->success('操作成功');
  1853. }
  1854. $this->error('操作失败');
  1855. }
  1856. $this->assign('users', $users);
  1857. return $this->fetch('member/edit/users_edit_money');
  1858. }
  1859. // 积分充值
  1860. public function users_edit_score()
  1861. {
  1862. $post = input('param.');
  1863. $post['users_id'] = intval($post['users_id']);
  1864. $users_id = $post['users_id'];
  1865. $users = Db::name('users')->where('users_id',$users_id)->find();
  1866. if (IS_POST){
  1867. if (empty($post['type'])){
  1868. $this->error('请选择变化!');
  1869. }
  1870. if (empty($post['money']) && in_array($post['type'], [1,2])){
  1871. $this->error('变动数值不能为空或0');
  1872. } else if (!empty($post['money']) && !preg_match('/^([0-9\.]+)$/i', $post['money'])) {
  1873. $this->error('变动数值格式不正确!');
  1874. }
  1875. // 处理数据验证
  1876. $error = handleEyouDataValidate('users_id', '__token_users_edit_score__', $post);
  1877. if (!empty($error)) $this->error($error);
  1878. $insert['type'] = 6;
  1879. $insert['users_id'] = $users_id;
  1880. $insert['current_score'] = $users['scores'];
  1881. $insert['lang'] = $this->admin_lang;
  1882. $insert['devote'] = $insert['current_devote'] = 0;
  1883. $insert['add_time'] = $insert['update_time'] = $update['update_time'] = getTime();
  1884. // 增加
  1885. if (1 == $post['type']) {
  1886. $update['scores'] = Db::raw('scores + '.$post['money']);
  1887. $insert['score'] = '+' . $post['money'];
  1888. $insert['current_score'] += $post['money'];
  1889. }
  1890. // 减少
  1891. else if (2 == $post['type']) {
  1892. $update['scores'] = Db::raw('scores - '.$post['money']);
  1893. $insert['score'] = '-' . $post['money'];
  1894. $insert['current_score'] -= $post['money'];
  1895. }
  1896. // 根据变动数据计算是增加还是减少
  1897. else if (3 == $post['type']) {
  1898. // 增加
  1899. if ($post['money'] > $users['scores']) {
  1900. $insert['score'] = '+' . ($post['money'] - $users['scores']);
  1901. }
  1902. // 减少
  1903. else {
  1904. $insert['score'] = '-' . ($users['scores'] - $post['money']);
  1905. }
  1906. $update['scores'] = $post['money'];
  1907. $insert['current_score'] = $post['money'];
  1908. }
  1909. // 更新会员积分
  1910. $where = [
  1911. 'users_id' => $users_id,
  1912. ];
  1913. $result = $this->users_db->where($where)->update($update);
  1914. if (!empty($result)) {
  1915. // 增加会员积分变动记录
  1916. if (!empty($post['remark'])) $insert['remark'] = $post['remark'];
  1917. $insert['admin_id'] = session('admin_id');
  1918. Db::name('users_score')->insert($insert);
  1919. \think\Cache::clear('users_list');
  1920. adminLog('编辑会员'.$users_id.'积分');
  1921. $this->success('操作成功');
  1922. }else{
  1923. $this->error('操作失败');
  1924. }
  1925. $this->success('操作成功');
  1926. }
  1927. $this->assign('users',$users);
  1928. return $this->fetch('member/edit/users_edit_score');
  1929. }
  1930. // 下载订单列表页
  1931. public function download_index()
  1932. {
  1933. // 定义数组
  1934. $condition = [];
  1935. // 订单状态搜索
  1936. $order_status = input('param.order_status/d', 0);
  1937. if (!empty($order_status)) $condition['a.order_status'] = intval($order_status) === 1 ? intval($order_status) : 0;
  1938. // 订单号或用户名搜索
  1939. $keywords = input('keywords/s', '');
  1940. if (!empty($keywords)) $condition['a.order_code|b.username'] = ['LIKE', "%{$keywords}%"];
  1941. // 支付方式查询
  1942. $pay_name = input('pay_name/s', '');
  1943. if (!empty($pay_name)) $condition['a.pay_name'] = $pay_name;
  1944. // 时间检索条件
  1945. $begin = strtotime(input('param.add_time_begin/s'));
  1946. $end = input('param.add_time_end/s');
  1947. !empty($end) && $end .= ' 23:59:59';
  1948. $end = strtotime($end);
  1949. // 时间检索
  1950. if ($begin > 0 && $end > 0) {
  1951. $condition['a.add_time'] = array('between', "$begin, $end");
  1952. } else if ($begin > 0) {
  1953. $condition['a.add_time'] = array('egt', $begin);
  1954. } else if ($end > 0) {
  1955. $condition['a.add_time'] = array('elt', $end);
  1956. }
  1957. // 分页查询
  1958. $count = Db::name('download_order')->alias('a')->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')->where($condition)->count();
  1959. $Page = new Page($count, config('paginate.list_rows'));
  1960. // 数据查询
  1961. $list = Db::name('download_order')->where($condition)
  1962. ->field('a.*, b.head_pic, b.username, b.nickname')
  1963. ->alias('a')
  1964. ->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')
  1965. ->order('a.order_id desc')
  1966. ->limit($Page->firstRow.','.$Page->listRows)
  1967. ->select();
  1968. foreach ($list as $key => $value) {
  1969. $value['username'] = !empty($value['nickname']) ? $value['nickname'] : $value['username'];
  1970. $value['head_pic'] = get_head_pic($value['head_pic']);
  1971. $list[$key] = $value;
  1972. }
  1973. $show = $Page->show();
  1974. $this->assign('list', $list);
  1975. $this->assign('page', $show);
  1976. $this->assign('pager', $Page);
  1977. // 是否开启文章付费
  1978. $channelRow = Db::name('channeltype')->where('nid', 'in',['article','download'])->getAllWithIndex('nid');
  1979. foreach ($channelRow as &$val){
  1980. if (!empty($val['data'])) $val['data'] = json_decode($val['data'], true);
  1981. }
  1982. $this->assign('channelRow', $channelRow);
  1983. return $this->fetch();
  1984. }
  1985. // 文章订单详情页
  1986. public function download_order_details()
  1987. {
  1988. $order_id = input('param.order_id/d');
  1989. if (!empty($order_id)) {
  1990. $OrderData = Db::name('download_order')->field('*, product_id as aid')->find($order_id);
  1991. $UsersData = $this->users_db->find($OrderData['users_id']);
  1992. // 用于点击视频文档跳转到前台
  1993. $array_new = get_archives_data([$OrderData], 'product_id');
  1994. // 内页地址
  1995. $OrderData['arcurl'] = get_arcurl($array_new[$OrderData['product_id']]);
  1996. // 支持子目录
  1997. $OrderData['product_litpic'] = get_default_pic($OrderData['product_litpic']);
  1998. $this->assign('OrderData', $OrderData);
  1999. $this->assign('UsersData', $UsersData);
  2000. return $this->fetch('article_order_details');
  2001. } else {
  2002. $this->error('非法访问!');
  2003. }
  2004. }
  2005. // 文章订单批量删除
  2006. public function download_order_del()
  2007. {
  2008. $order_id = input('del_id/a');
  2009. $order_id = eyIntval($order_id);
  2010. if (IS_AJAX_POST && !empty($order_id)) {
  2011. $Where = [
  2012. 'order_id' => ['IN', $order_id],
  2013. ];
  2014. $result = Db::name('download_order')->field('order_code')->where($Where)->select();
  2015. $order_code_list = get_arr_column($result, 'order_code');
  2016. // 删除订单列表数据
  2017. $return = Db::name('download_order')->where($Where)->delete();
  2018. if ($return) {
  2019. adminLog('删除下载订单:'.implode(',', $order_code_list));
  2020. $this->success('删除成功');
  2021. } else {
  2022. $this->error('删除失败');
  2023. }
  2024. }
  2025. $this->error('参数有误');
  2026. }
  2027. // AJAX导出搜索关键词Excel文档
  2028. public function ajax_excel_export()
  2029. {
  2030. // 设置最大内存
  2031. ini_set("memory_limit", "-1");
  2032. // 防止php超时
  2033. function_exists('set_time_limit') && set_time_limit(0);
  2034. if (file_exists('./vendor/PHPExcel.zip') && !is_dir('./vendor/PHPExcel/')) {
  2035. $zip = new \ZipArchive();//新建一个ZipArchive的对象
  2036. if ($zip->open(ROOT_PATH.'vendor'.DS.'PHPExcel.zip') === true) {
  2037. $zip->extractTo(ROOT_PATH.'vendor'.DS.'PHPExcel'.DS);
  2038. $zip->close();//关闭处理的zip文件
  2039. if (is_dir('./vendor/PHPExcel/')) {
  2040. @unlink('./vendor/PHPExcel.zip');
  2041. }
  2042. }
  2043. }
  2044. // 执行操作
  2045. if (IS_AJAX_POST) {
  2046. $condition['is_del'] = 0;
  2047. $orderby = "users_id desc";
  2048. $list = $this->users_db->field('*')->where($condition)->order($orderby)->select();
  2049. if (empty($list)) $this->error('没有导出的数据');
  2050. $level = Db::name('users_level')->field('level_id, level_name')->cache(true, EYOUCMS_CACHE_TIME, "users_level")->getAllWithIndex('level_id');
  2051. //成交订单数
  2052. $order_count = Db::name('shop_order')->where('order_status',3)
  2053. ->field('count(*) as count,sum(order_amount) as sum,users_id')
  2054. ->group('users_id')->getAllWithIndex('users_id');
  2055. // 处理订单导出数据
  2056. $ExcelData = [];
  2057. foreach ($list as $key => $value) {
  2058. // 拼装追加数据
  2059. $PushData = [
  2060. // 订单信息
  2061. 'users_id' => $value['users_id'],
  2062. 'username' => $value['username'],
  2063. 'nickname' => $value['nickname'],
  2064. 'mobile' => $value['mobile'],
  2065. 'email' => $value['email'],
  2066. 'level' => $level[$value['level']]['level_name'],
  2067. 'level_maturity_days' => $value['level_maturity_days'],
  2068. 'scores' => $value['scores'],
  2069. 'users_money' => $value['users_money'],
  2070. 'order_count' => !empty($order_count[$value['users_id']]['count']) ? $order_count[$value['users_id']]['count'] : 0,
  2071. 'order_money_count' => !empty($order_count[$value['users_id']]['sum']) ? $order_count[$value['users_id']]['sum'] : 0,
  2072. 'is_lock' => !empty($value['is_lock']) ? '是' : '否',
  2073. 'reg_time' => date('Y-m-d H:i:s', $value['reg_time']),
  2074. 'last_login' => !empty($value['last_login']) ? date('Y-m-d H:i:s', $value['last_login']) : '',
  2075. ];
  2076. // 追加数据,用于导出
  2077. array_push($ExcelData, $PushData);
  2078. }
  2079. // 导出字段设置
  2080. $ExcelField = ['users_id', 'username', 'nickname', 'mobile', 'email', 'level','level_maturity_days', 'scores', 'users_money', 'order_count', 'order_money_count', 'is_lock', 'reg_time', 'last_login'];
  2081. // 导出标题设置
  2082. $ExcelTitle = ['会员ID', '用户名', '会员昵称', '手机号', '电子邮箱', '会员等级','会员天数', '积分', '余额', '成交订单数', '成交金额', '黑名单', '注册时间', '最后登录'];
  2083. $ResultUrl = $this->PerformExport($ExcelData, $ExcelField, $ExcelTitle);
  2084. }
  2085. if (!empty($ResultUrl)) {
  2086. $this->success('正在下载', $ResultUrl);
  2087. } else {
  2088. $this->error('导出失败');
  2089. }
  2090. }
  2091. private function PerformExport($ExcelData = [], $ExcelField = [], $ExcelTitle = [])
  2092. {
  2093. // 引入SDK
  2094. vendor("PHPExcel.Classes.PHPExcel");
  2095. // Excel表格坐标
  2096. $cell_arr = ['A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
  2097. // 执行导出
  2098. $objPHPExcel = new \PHPExcel();
  2099. $objPHPExcel->getDefaultStyle()->getFont()->setName('Arial')->setSize(12);
  2100. // 设置表格标题栏长度
  2101. $objActSheet = $objPHPExcel->getActiveSheet();
  2102. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(8);
  2103. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
  2104. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  2105. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
  2106. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
  2107. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(12);
  2108. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
  2109. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(12);
  2110. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(12);
  2111. $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(12);
  2112. $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(12);
  2113. $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(8);
  2114. $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(18);
  2115. $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(18);
  2116. // 设置导出表格名称
  2117. $FileName = 'users-'.date("YmdHis");
  2118. // 循环设置表格标题栏数据
  2119. $startRow = 1;
  2120. if(!empty($ExcelTitle) || count($ExcelTitle) > 0) {
  2121. foreach($ExcelTitle as $k => $v) {
  2122. $objActSheet->setCellValue($cell_arr[$k] . $startRow, $v);
  2123. }
  2124. $startRow = 2;
  2125. }
  2126. // 循环设置表格字段内容数据
  2127. foreach($ExcelData as $v) {
  2128. foreach($ExcelField as $key => $value) {
  2129. $objActSheet->setCellValue($cell_arr[$key] . $startRow, $v[$value]."\t");
  2130. }
  2131. $startRow++;
  2132. }
  2133. $objPHPExcel->setActiveSheetIndex(0);
  2134. header('Content-Type: application/vnd.ms-excel');
  2135. header('Content-Disposition: attachment;filename="' . $FileName . '.xlsx"');
  2136. header('Cache-Control: max-age=0');
  2137. header('Cache-Control: max-age=1');
  2138. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  2139. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  2140. header('Cache-Control: cache, must-revalidate');
  2141. header('Pragma: public');
  2142. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  2143. // 文件目录
  2144. $ExcelPath = UPLOAD_PATH . 'excel/';
  2145. // 保存前清空删除原先的excel
  2146. delFile(UPLOAD_PATH . 'excel/', true);
  2147. // 创建文件夹
  2148. @mkdir($ExcelPath, 0777, true);
  2149. // excel文件路径
  2150. $filePath = $ExcelPath . $FileName . '.xlsx';
  2151. // 保存excel文件
  2152. $objWriter->save($filePath);
  2153. // 返回excel文件路径到AJAX下载
  2154. return request()->domain() . ROOT_DIR . '/' . $filePath;
  2155. }
  2156. // 充值套餐列表
  2157. public function recharge_pack_list()
  2158. {
  2159. // 搜索套餐名称
  2160. $where = [];
  2161. $packNames = input('param.pack_names/s', '');
  2162. $this->assign('packNames', $packNames);
  2163. if (!empty($packNames)) $where['pack_names'] = ['LIKE', "%{$packNames}%"];
  2164. // 查询分页数据
  2165. $count = Db::name('users_recharge_pack')->where($where)->count();
  2166. $Page = new Page($count, config('paginate.list_rows'));
  2167. $list = Db::name('users_recharge_pack')->where($where)->limit($Page->firstRow.','.$Page->listRows)->order('add_time desc, pack_id desc')->select();
  2168. // 数据虚拟排序处理
  2169. $count = intval($Page->nowPage) > 1 ? intval(++$count) - intval($Page->listRows) : intval(++$count);
  2170. foreach ($list as $key => $value) {
  2171. // 数据虚拟排序字段
  2172. $list[$key]['virtual_id'] = --$count;
  2173. }
  2174. $show = $Page->show();
  2175. $this->assign('list', $list);
  2176. $this->assign('page', $show);
  2177. $this->assign('pager', $Page);
  2178. return $this->fetch();
  2179. }
  2180. // 充值套餐添加
  2181. public function recharge_pack_add()
  2182. {
  2183. if (IS_AJAX_POST) {
  2184. $post = input('post.');
  2185. // 添加限制
  2186. if (empty($post['pack_names'])) $this->error('请输入套餐名称');
  2187. if (empty($post['pack_face_value'])) $this->error('请输入实际入账余额');
  2188. if (empty($post['pack_pay_prices'])) $this->error('请输入实际支付价格');
  2189. // 添加数据
  2190. $times = getTime();
  2191. $insert = [
  2192. 'pack_names' => strval($post['pack_names']),
  2193. 'pack_face_value' => unifyPriceHandle($post['pack_face_value']),
  2194. 'pack_pay_prices' => unifyPriceHandle($post['pack_pay_prices']),
  2195. 'add_time' => $times,
  2196. 'update_time' => $times,
  2197. ];
  2198. $insertID = Db::name('users_recharge_pack')->insertGetId($insert);
  2199. // 返回结束
  2200. if (!empty($insertID)) $this->success('添加成功');
  2201. $this->error('添加失败');
  2202. }
  2203. return $this->fetch();
  2204. }
  2205. // 充值套餐编辑
  2206. public function recharge_pack_edit()
  2207. {
  2208. if (IS_AJAX_POST) {
  2209. $post = input('post.');
  2210. // 编辑限制
  2211. if (empty($post['pack_id'])) $this->error('请选择要编辑套餐');
  2212. if (empty($post['pack_names'])) $this->error('请输入套餐名称');
  2213. if (empty($post['pack_face_value'])) $this->error('请输入实际入账余额');
  2214. if (empty($post['pack_pay_prices'])) $this->error('请输入实际支付价格');
  2215. // 编辑数据
  2216. $times = getTime();
  2217. $update = [
  2218. 'pack_id' => intval($post['pack_id']),
  2219. 'pack_names' => strval($post['pack_names']),
  2220. 'pack_face_value' => unifyPriceHandle($post['pack_face_value']),
  2221. 'pack_pay_prices' => unifyPriceHandle($post['pack_pay_prices']),
  2222. 'update_time' => $times,
  2223. ];
  2224. $insertID = Db::name('users_recharge_pack')->update($update);
  2225. // 返回结束
  2226. if (!empty($insertID)) $this->success('编辑成功');
  2227. $this->error('编辑失败');
  2228. }
  2229. $pack_id = input('param.pack_id/d', 0);
  2230. $where = [
  2231. 'pack_id' => intval($pack_id)
  2232. ];
  2233. $pack = Db::name('users_recharge_pack')->where($where)->find();
  2234. $this->assign('pack', $pack);
  2235. return $this->fetch();
  2236. }
  2237. // 充值套餐删除
  2238. public function recharge_pack_del()
  2239. {
  2240. if (IS_AJAX_POST) {
  2241. $pack_ids = input('del_id/a');
  2242. $pack_ids = eyIntval($pack_ids);
  2243. $where = [
  2244. 'pack_id' => ['IN', $pack_ids]
  2245. ];
  2246. $result = Db::name('users_recharge_pack')->where($where)->delete(true);
  2247. if (!empty($result)) $this->success('删除成功');
  2248. }
  2249. $this->error('删除失败');
  2250. }
  2251. // 充值套餐领取记录
  2252. public function recharge_pack_log()
  2253. {
  2254. // 搜索套餐名称
  2255. $where = [
  2256. 'a.order_status' => ['IN', [2, 3]]
  2257. ];
  2258. $keywords = input('param.keywords/s', '');
  2259. $this->assign('keywords', $keywords);
  2260. if (!empty($keywords)) $where['b.username|b.nickname'] = ['LIKE', "%{$keywords}%"];
  2261. // 时间检索条件
  2262. $begin = strtotime(input('param.add_time_begin/s'));
  2263. $end = input('param.add_time_end/s');
  2264. !empty($end) && $end .= ' 23:59:59';
  2265. $end = strtotime($end);
  2266. // 时间检索
  2267. if ($begin > 0 && $end > 0) {
  2268. $where['a.order_pay_time'] = array('between', "$begin, $end");
  2269. } else if ($begin > 0) {
  2270. $where['a.order_pay_time'] = array('egt', $begin);
  2271. } else if ($end > 0) {
  2272. $where['a.order_pay_time'] = array('elt', $end);
  2273. }
  2274. // 查询分页数据
  2275. $count = Db::name('users_recharge_pack_order')->alias('a')->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')->where($where)->count();
  2276. $Page = new Page($count, config('paginate.list_rows'));
  2277. $field = 'a.*, b.username, b.nickname, b.head_pic';
  2278. $list = Db::name('users_recharge_pack_order')->alias('a')
  2279. ->field($field)
  2280. ->where($where)
  2281. ->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')
  2282. ->limit($Page->firstRow.','.$Page->listRows)
  2283. ->order('add_time desc, order_id desc')
  2284. ->select();
  2285. // 数据虚拟排序处理
  2286. $count = intval($Page->nowPage) > 1 ? intval(++$count) - intval($Page->listRows) : intval(++$count);
  2287. foreach ($list as $key => $value) {
  2288. // 数据虚拟排序字段
  2289. $list[$key]['virtual_id'] = --$count;
  2290. $list[$key]['head_pic'] = get_head_pic($value['head_pic']);
  2291. $list[$key]['nickname'] = !empty($value['nickname']) ? $value['nickname'] : $value['username'];
  2292. }
  2293. // dump($list);exit;
  2294. $show = $Page->show();
  2295. $this->assign('list', $list);
  2296. $this->assign('page', $show);
  2297. $this->assign('pager', $Page);
  2298. return $this->fetch();
  2299. }
  2300. //会员注销列表
  2301. public function log_off_index()
  2302. {
  2303. $count = Db::name('users_log_off')->count('id');
  2304. $pageObj = new Page($count, 10);
  2305. $list = Db::name('users_log_off')
  2306. ->order('id desc')
  2307. ->limit($pageObj->firstRow . ',' . $pageObj->listRows)
  2308. ->select();
  2309. $pageStr = $pageObj->show();
  2310. $this->assign('list', $list);
  2311. $this->assign('pageStr', $pageStr);
  2312. $this->assign('pageObj', $pageObj);
  2313. $cur_key = $pageObj->totalRows - ($pageObj->nowPage - 1) * ($pageObj->listRows);
  2314. $this->assign('cur_key', $cur_key);
  2315. return $this->fetch('member/log_off/log_off_index');
  2316. }
  2317. //会员注销配置
  2318. public function log_off_set()
  2319. {
  2320. if (IS_AJAX_POST) {
  2321. $post = input('post.');
  2322. getUsersConfigData('users', ['users_open_log_off' => $post['data']['users_open_log_off']], 'cn'); // 开启注销
  2323. getUsersConfigData('users', ['users_log_off_check' => $post['data']['users_log_off_check']], 'cn'); // 注销审核
  2324. $this->success('保存成功');
  2325. }
  2326. $data = getUsersConfigData('users', '', 'cn');
  2327. $this->assign('data', $data);
  2328. return $this->fetch('member/log_off/log_off_set');
  2329. }
  2330. //会员注销列表详情查看
  2331. public function log_off_see()
  2332. {
  2333. $id = input('param.id/d');
  2334. if (empty($id)) $this->error('缺少必要参数');
  2335. $info = Db::name('users_log_off')
  2336. ->alias('a')
  2337. ->field('a.*,b.user_name')
  2338. ->join('admin b', 'a.admin_id = b.admin_id', 'left')
  2339. ->where('a.id', $id)
  2340. ->find();
  2341. $this->assign('info', $info);
  2342. return $this->fetch('member/log_off/log_off_see');
  2343. }
  2344. //会员注销审核
  2345. public function handle_log_off()
  2346. {
  2347. $param = input('param.');
  2348. $admin_id = session('admin_id');
  2349. if (empty($admin_id)) $this->error('操作失败');
  2350. $users_id = Db::name('users_log_off')->where('id', $param['id'])->value('users_id');
  2351. if (1 == $param['status']) {
  2352. $data = getUsersConfigData('users', '', 'cn');
  2353. if (empty($data['users_open_log_off'])) $this->error('未开启会员注销');
  2354. $users = Db::name('users')->where('users_id', $users_id)->find();
  2355. if (empty($users)) $this->error('会员不存在');
  2356. $update = [
  2357. 'status' => 1,
  2358. 'admin_id' => $admin_id,
  2359. 'handle_time' => getTime(),
  2360. 'update_time' => getTime(),
  2361. ];
  2362. $r = Db::name('users_log_off')->where('id', $param['id'])->update($update);
  2363. if (false !== $r) {
  2364. //直接删除
  2365. Db::name('users')->where('users_id', $users_id)->delete();
  2366. model('Member')->afterDel([$users_id]);
  2367. $this->success('注销成功');
  2368. }
  2369. } elseif (2 == $param['status']) {
  2370. //拒绝注销
  2371. $update = [
  2372. 'status' => 2,
  2373. 'admin_id' => $admin_id,
  2374. 'refuse_reason' => $param['refuse_reason'],
  2375. 'handle_time' => getTime(),
  2376. 'update_time' => getTime(),
  2377. ];
  2378. $r = Db::name('users_log_off')->where('id', $param['id'])->update($update);
  2379. if (false !== $r) {
  2380. $this->success('拒绝注销成功');
  2381. }
  2382. }
  2383. $this->error('操作失败');
  2384. }
  2385. }