Member.php 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 陈风任 <491085389@qq.com>
  11. * Date: 2019-2-12
  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. // 会员列表
  48. public function users_index()
  49. {
  50. $list = array();
  51. $keywords = input('keywords/s');
  52. $condition = array();
  53. // 应用搜索条件
  54. if (!empty($keywords)) {
  55. $condition['a.username'] = array('LIKE', "%{$keywords}%");
  56. }
  57. $condition['a.is_del'] = 0;
  58. // 多语言
  59. $condition['a.lang'] = array('eq', $this->admin_lang);
  60. /**
  61. * 数据查询
  62. */
  63. $count = $this->users_db->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  64. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  65. $list = $this->users_db->field('a.*,b.level_name')
  66. ->alias('a')
  67. ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
  68. ->where($condition)
  69. ->order('a.users_id desc')
  70. ->limit($Page->firstRow.','.$Page->listRows)
  71. ->select();
  72. $show = $Page->show();// 分页显示输出
  73. $this->assign('page',$show);// 赋值分页输出
  74. $this->assign('list',$list);// 赋值数据集
  75. $this->assign('pager',$Page);// 赋值分页集
  76. /*纠正数据*/
  77. $web_is_authortoken = tpCache('web.web_is_authortoken');
  78. if (is_realdomain() && !empty($web_is_authortoken)) {
  79. getUsersConfigData('shop', ['shop_open'=>0]);
  80. }
  81. /*检测是否存在会员中心模板*/
  82. if ('v1.0.1' > getVersion('version_themeusers')) {
  83. $is_syn_theme_users = 1;
  84. } else {
  85. $is_syn_theme_users = 0;
  86. }
  87. $this->assign('is_syn_theme_users',$is_syn_theme_users);
  88. /*--end*/
  89. return $this->fetch();
  90. }
  91. // 检测并第一次从官方同步会员中心的前台模板
  92. public function ajax_syn_theme_users()
  93. {
  94. $msg = '下载会员中心模板包异常,请第一时间联系技术支持,排查问题!';
  95. $memberLogic = new MemberLogic;
  96. $data = $memberLogic->syn_theme_users();
  97. if (true !== $data) {
  98. if (1 <= intval($data['code'])) {
  99. $this->success('初始化成功!', url('Member/users_index'));
  100. } else {
  101. if (is_array($data)) {
  102. $msg = $data['msg'];
  103. }
  104. }
  105. }
  106. /*多语言*/
  107. if (is_language()) {
  108. $langRow = \think\Db::name('language')->order('id asc')
  109. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  110. ->select();
  111. foreach ($langRow as $key => $val) {
  112. tpCache('web', ['web_users_switch'=>0], $val['mark']);
  113. }
  114. } else { // 单语言
  115. tpCache('web', ['web_users_switch'=>0]);
  116. }
  117. /*--end*/
  118. $this->error($msg);
  119. }
  120. // 会员批量新增
  121. public function users_batch_add()
  122. {
  123. if (IS_POST) {
  124. $post = input('post.');
  125. $username = $post['username'];
  126. if (empty($username)) {
  127. $this->error('用户名不能为空!');
  128. }
  129. if (empty($post['password'])) {
  130. $this->error('登录密码不能为空!');
  131. }
  132. if (!empty($this->userConfig['level_member_upgrade']) && 1 == $this->userConfig['level_member_upgrade']) {
  133. if (1 != $post['level'] && !preg_match("/^([0-9]+)$/i", $post['level_maturity_days'])) {
  134. $this->error('请填写会员有效期天数!');
  135. }
  136. }
  137. $post['level_maturity_days'] = intval($post['level_maturity_days']);
  138. $password = func_encrypt($post['password']);
  139. $usernameArr = explode("\r\n", $username);
  140. $usernameArr = array_filter($usernameArr);//去除数组空值
  141. $usernameArr = array_unique($usernameArr); //去重
  142. $addData = [];
  143. $usernameList = $this->users_db->where([
  144. 'username' => ['IN', $usernameArr],
  145. 'lang' => $this->admin_lang,
  146. ])->column('username');
  147. foreach ($usernameArr as $key => $val) {
  148. if(trim($val) == '' || empty($val) || in_array($val, $usernameList) || !preg_match("/^[\x{4e00}-\x{9fa5}\w\-\_\@\#]{2,30}$/u", $val))
  149. {
  150. continue;
  151. }
  152. $addData[] = [
  153. 'username' => $val,
  154. 'nickname' => $val,
  155. 'password' => $password,
  156. 'level' => $post['level'],
  157. 'register_place' => 1,
  158. 'level_maturity_days' => $post['level_maturity_days'],
  159. 'open_level_time' => getTime(),
  160. 'reg_time' => getTime(),
  161. 'head_pic' => ROOT_DIR . '/public/static/common/images/dfboy.png',
  162. 'lang' => $this->admin_lang,
  163. 'add_time' => getTime(),
  164. ];
  165. }
  166. if (!empty($addData)) {
  167. $r = model('Member')->saveAll($addData);
  168. if (!empty($r)) {
  169. adminLog('批量新增会员:'.get_arr_column($addData, 'username'));
  170. $this->success('操作成功!', url('Member/users_index'));
  171. } else {
  172. $this->error('操作失败');
  173. }
  174. } else {
  175. $this->success('操作成功!', url('Member/users_index'));
  176. }
  177. }
  178. $user_level = $this->users_level_db->field('level_id,level_name')
  179. ->where(['lang'=>$this->admin_lang])
  180. ->order('level_value asc')
  181. ->select();
  182. $this->assign('user_level',$user_level);
  183. return $this->fetch();
  184. }
  185. // 会员新增
  186. // public function users_add()
  187. // {
  188. // if (IS_POST) {
  189. // $post = input('post.');
  190. // $count = $this->users_db->where([
  191. // 'username' => $post['username'],
  192. // 'lang' => $this->admin_lang,
  193. // ])->count();
  194. // if (!empty($count)) {
  195. // $this->error('用户名已存在!');
  196. // }
  197. // if (empty($post['password']) && empty($post['password2'])) {
  198. // $this->error('登录密码不能为空!');
  199. // } else {
  200. // if ($post['password'] != $post['password2']) {
  201. // $this->error('两次密码输入不一致!');
  202. // }
  203. // }
  204. // $ParaData = [];
  205. // if (is_array($post['users_'])) {
  206. // $ParaData = $post['users_'];
  207. // }
  208. // unset($post['users_']);
  209. // // 处理提交的会员属性中必填项是否为空
  210. // // 必须传入提交的会员属性数组
  211. // $EmptyData = model('Member')->isEmpty($ParaData);
  212. // if ($EmptyData) {
  213. // $this->error($EmptyData);
  214. // }
  215. // // 处理提交的会员属性中邮箱和手机是否已存在
  216. // // isRequired方法传入的参数有2个
  217. // // 第一个必须传入提交的会员属性数组
  218. // // 第二个users_id,注册时不需要传入,修改时需要传入。
  219. // $RequiredData = model('Member')->isRequired($ParaData);
  220. // if ($RequiredData) {
  221. // $this->error($RequiredData);
  222. // }
  223. // $post['password'] = func_encrypt($post['password']);// MD5加密
  224. // unset($post['password2']);
  225. // $post['register_place'] = 1; // 注册位置,后台注册不受注册验证影响,1为后台注册,2为前台注册。
  226. // $post['reg_time'] = getTime();
  227. // $post['lang'] = $this->admin_lang;
  228. // $users_id = $this->users_db->add($post);
  229. // // 判断会员添加是否成功
  230. // if (!empty($users_id)) {
  231. // // 批量添加会员属性到属性信息表
  232. // if (!empty($ParaData)) {
  233. // $betchData = [];
  234. // $usersparaRow = $this->users_parameter_db->where([
  235. // 'lang' => $this->admin_lang,
  236. // 'is_hidden' => 0,
  237. // ])->getAllWithIndex('name');
  238. // foreach ($ParaData as $key => $value) {
  239. // $para_id = intval($usersparaRow[$key]['para_id']);
  240. // $betchData[] = [
  241. // 'users_id' => $users_id,
  242. // 'para_id' => $para_id,
  243. // 'info' => $value,
  244. // 'lang' => $this->admin_lang,
  245. // 'add_time' => getTime(),
  246. // ];
  247. // }
  248. // $this->users_list_db->insertAll($betchData);
  249. // }
  250. // // 查询属性表的手机号码和邮箱地址,同步修改会员信息。
  251. // $UsersListData = model('Member')->getUsersListData('*',$users_id);
  252. // $UsersListData['update_time'] = getTime();
  253. // $this->users_db->where([
  254. // 'users_id' => $users_id,
  255. // 'lang' => $this->admin_lang,
  256. // ])->update($UsersListData);
  257. // adminLog('新增会员:'.$post['username']);
  258. // $this->success('操作成功!', url('Member/users_index'));
  259. // }else{
  260. // $this->error('操作失败');
  261. // }
  262. // }
  263. // $user_level = $this->users_level_db->field('level_id,level_name')
  264. // ->where(['lang'=>$this->admin_lang])
  265. // ->order('level_value asc')
  266. // ->select();
  267. // $this->assign('user_level',$user_level);
  268. // // 资料信息
  269. // $users_para = model('Member')->getDataPara();
  270. // $this->assign('users_para',$users_para);
  271. // return $this->fetch();
  272. // }
  273. // 会员编辑
  274. public function users_edit()
  275. {
  276. if (IS_POST) {
  277. $post = input('post.');
  278. if (!empty($this->userConfig['level_member_upgrade']) && 1 == $this->userConfig['level_member_upgrade']) {
  279. if (1 != $post['level'] && !preg_match("/^([0-9]+)$/i", $post['level_maturity_days_up'])) {
  280. $this->error('请填写会员有效期天数!');
  281. }
  282. /*会员级别到期天数*/
  283. $post['level_maturity_days_up'] = intval($post['level_maturity_days_up']);
  284. if (0 >= $post['level_maturity_days_up']) {
  285. $days_new = 0;
  286. }else{
  287. if ($post['level_maturity_days_new'] >= $post['level_maturity_days_up']) {
  288. $days_new = $post['level_maturity_days_new'] - $post['level_maturity_days_up'];
  289. $days_new = $post['level_maturity_days_old'] - $days_new;
  290. }else{
  291. $days_new = $post['level_maturity_days_up'] - $post['level_maturity_days_new'];
  292. $days_new = $post['level_maturity_days_old'] + $days_new;
  293. }
  294. }
  295. $days_new = (99999999 < $days_new) ? 99999999 : $days_new;
  296. $post['level_maturity_days'] = $days_new;
  297. }
  298. /*end*/
  299. if (isset($post['users_money'])) {
  300. $users_money = input('post.users_money/f');
  301. $post['users_money'] = (99999999 < $users_money) ? 99999999 : $users_money;
  302. }
  303. if (!empty($post['password'])) {
  304. $post['password'] = func_encrypt($post['password']); // MD5加密
  305. } else {
  306. unset($post['password']);
  307. }
  308. $users_id = $post['users_id'];
  309. $ParaData = [];
  310. if (is_array($post['users_'])) {
  311. $ParaData = $post['users_'];
  312. }
  313. unset($post['users_']);
  314. // 处理提交的会员属性中必填项是否为空
  315. // 必须传入提交的会员属性数组
  316. /*$EmptyData = model('Member')->isEmpty($ParaData);
  317. if ($EmptyData) {
  318. $this->error($EmptyData);
  319. }*/
  320. // 处理提交的会员属性中邮箱和手机是否已存在
  321. // isRequired方法传入的参数有2个
  322. // 第一个必须传入提交的会员属性数组
  323. // 第二个users_id,注册时不需要传入,修改时需要传入。
  324. $RequiredData = model('Member')->isRequired($ParaData,$users_id);
  325. if ($RequiredData) {
  326. $this->error($RequiredData);
  327. }
  328. $users_where = [
  329. 'users_id' => $users_id,
  330. 'lang' => $this->admin_lang,
  331. ];
  332. $userinfo = $this->users_db->where($users_where)->find();
  333. $post['update_time'] = getTime();
  334. /*会员级别到期天数*/
  335. if(isset($post['level_maturity_days']) && !empty($post['level_maturity_days'])){
  336. if (empty($userinfo['open_level_time'])) {
  337. $post['open_level_time'] = getTime();
  338. }
  339. }else if (empty($post['level_maturity_days'])) {
  340. $post['open_level_time'] = '';
  341. // $level_id = $this->users_level_db
  342. // ->where([
  343. // 'level_id' => 1,
  344. // 'is_system' => 1,
  345. // 'lang' => $this->admin_lang,
  346. // ])
  347. // ->getField('level_id');
  348. $level_id = 1;
  349. $post['level'] = $level_id;
  350. }
  351. /*end*/
  352. unset($post['username']);
  353. $r = $this->users_db->where($users_where)->update($post);
  354. if ($r) {
  355. $row2 = $this->users_parameter_db->field('para_id,name')->getAllWithIndex('name');
  356. foreach ($ParaData as $key => $value) {
  357. $data = [];
  358. $para_id = intval($row2[$key]['para_id']);
  359. $where = [
  360. 'users_id' => $post['users_id'],
  361. 'para_id' => $para_id,
  362. 'lang' => $this->admin_lang,
  363. ];
  364. $data['info'] = $value;
  365. $data['update_time'] = getTime();
  366. // 若信息表中无数据则添加
  367. $row = $this->users_list_db->where($where)->count();
  368. if (empty($row)) {
  369. $data['users_id'] = $post['users_id'];
  370. $data['para_id'] = $para_id;
  371. $data['lang'] = $this->admin_lang;
  372. $data['add_time'] = getTime();
  373. $this->users_list_db->add($data);
  374. } else {
  375. $this->users_list_db->where($where)->update($data);
  376. }
  377. }
  378. // 查询属性表的手机号码和邮箱地址,同步修改会员信息。
  379. $UsersListData = model('Member')->getUsersListData('*',$users_id);
  380. $UsersListData['update_time'] = getTime();
  381. $this->users_db->where($users_where)->update($UsersListData);
  382. adminLog('编辑会员:'.$userinfo['username']);
  383. $this->success('操作成功', url('Member/users_index'));
  384. }else{
  385. $this->error('操作失败');
  386. }
  387. }
  388. $users_id = input('param.id/d');
  389. // 会员信息
  390. $info = $this->users_db->where([
  391. 'users_id' => $users_id,
  392. 'lang' => $this->admin_lang,
  393. ])->find();
  394. // 计算剩余天数
  395. $days = $info['open_level_time'] + ($info['level_maturity_days'] * 86400);
  396. // 取整
  397. $days = ceil(($days - getTime()) / 86400);
  398. if (0 >= $days) {
  399. $info['level_maturity_days_new'] = '0';
  400. }else{
  401. $info['level_maturity_days_new'] = $days;
  402. }
  403. $this->assign('info',$info);
  404. // 等级信息
  405. $level = $this->users_level_db->field('level_id,level_name')
  406. ->where(['lang'=>$this->admin_lang])
  407. ->order('level_value asc')
  408. ->select();
  409. $this->assign('level',$level);
  410. // 属性信息
  411. $users_para = model('Member')->getDataParaList($users_id);
  412. $this->assign('users_para',$users_para);
  413. // 上一个页面来源
  414. $from = input('param.from/s');
  415. if ('money_index' == $from) {
  416. $backurl = url('Member/money_index');
  417. } else {
  418. $backurl = url('Member/users_index');
  419. }
  420. $this->assign('backurl', $backurl);
  421. return $this->fetch();
  422. }
  423. // 会员删除
  424. public function users_del()
  425. {
  426. $users_id = input('del_id/a');
  427. $users_id = eyIntval($users_id);
  428. if (IS_AJAX_POST && !empty($users_id)) {
  429. // 删除统一条件
  430. $Where = [
  431. 'users_id' => ['IN', $users_id],
  432. 'lang' => $this->admin_lang,
  433. ];
  434. $result = $this->users_db->field('username')->where($Where)->select();
  435. $username_list = get_arr_column($result, 'username');
  436. $return = $this->users_db->where($Where)->delete();
  437. if ($return) {
  438. /*删除会员中心关联数据表*/
  439. // 删除会员下的属性
  440. $this->users_list_db->where($Where)->delete();
  441. // 删除会员下的属性
  442. $this->users_money_db->where($Where)->delete();
  443. /*结束*/
  444. /*删除订单中心关联数据表*/
  445. // 删除会员下的购物车表
  446. $this->shop_cart_db->where($Where)->delete();
  447. // 删除会员下的收货地址表
  448. $this->shop_address_db->where($Where)->delete();
  449. // 删除会员下的订单主表
  450. $this->shop_order_db->where($Where)->delete();
  451. // 删除会员下的订单副表
  452. $this->shop_order_log_db->where($Where)->delete();
  453. // 删除会员下的订单操作记录表
  454. $this->shop_order_details_db->where($Where)->delete();
  455. /*结束*/
  456. adminLog('删除会员:'.implode(',', $username_list));
  457. $this->success('删除成功');
  458. }else{
  459. $this->error('删除失败');
  460. }
  461. }
  462. $this->error('参数有误');
  463. }
  464. // 级别列表
  465. public function level_index()
  466. {
  467. $list = array();
  468. $keywords = input('keywords/s');
  469. $condition = array();
  470. // 应用搜索条件
  471. if (!empty($keywords)) {
  472. $condition['a.level_name'] = array('LIKE', "%{$keywords}%");
  473. }
  474. // 多语言
  475. $condition['a.lang'] = array('eq', $this->admin_lang);
  476. /**
  477. * 数据查询
  478. */
  479. $count = $this->users_level_db->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  480. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  481. $list = $this->users_level_db->field('a.*')
  482. ->alias('a')
  483. ->where($condition)
  484. ->order('a.level_value asc, a.level_id asc')
  485. ->limit($Page->firstRow.','.$Page->listRows)
  486. ->select();
  487. $show = $Page->show();// 分页显示输出
  488. $this->assign('page',$show);// 赋值分页输出
  489. $this->assign('list',$list);// 赋值数据集
  490. $this->assign('pager',$Page);// 赋值分页集
  491. // 用于判断是否可以删除会员级别,当会员级别下存在会员时,不可删除。
  492. $levelgroup = $this->users_db->field('level')
  493. ->where(['lang'=>$this->admin_lang])
  494. ->group('level')
  495. ->getAllWithIndex('level');
  496. $this->assign('levelgroup',$levelgroup);
  497. return $this->fetch();
  498. }
  499. // 级别 - 新增
  500. public function level_add()
  501. {
  502. if (IS_POST) {
  503. $post = input('post.');
  504. // 级别名称不可重复
  505. $PostLevelName = array_unique($post['level_name']);
  506. if (count($PostLevelName) != count($post['level_name'])) {
  507. $this->error('级别名称不可重复!');
  508. }
  509. // 会员等级值不可重复
  510. $PostLevelValue = array_unique($post['level_value']);
  511. if (count($PostLevelValue) != count($post['level_value'])) {
  512. $this->error('会员等级值不可重复!');
  513. }
  514. // 数据拼装
  515. $AddUsersLevelData = $where = [];
  516. foreach ($post['level_name'] as $key => $value) {
  517. $level_id = $post['level_id'][$key];
  518. $level_name = trim($value);
  519. $level_value = intval(trim($post['level_value'][$key]));
  520. $discount = $post['discount'][$key];
  521. if (empty($discount)) $discount = 100;
  522. if (empty($level_name)) $this->error('级别名称不可为空!');
  523. if (empty($level_value)) $this->error('会员等级值不可为空!');
  524. $AddUsersLevelData[$key] = [
  525. 'level_id' => $level_id,
  526. 'level_name' => $level_name,
  527. 'level_value' => $level_value,
  528. 'discount' => $discount,
  529. 'update_time' => getTime(),
  530. ];
  531. if (empty($level_id)) {
  532. $AddUsersLevelData[$key]['lang'] = $this->admin_lang;
  533. $AddUsersLevelData[$key]['add_time'] = getTime();
  534. unset($AddUsersLevelData[$key]['level_id']);
  535. }
  536. }
  537. $ReturnId = model('UsersLevel')->saveAll($AddUsersLevelData);
  538. if ($ReturnId) {
  539. adminLog('新增会员级别:'.implode(',', $post['level_name']));
  540. $this->success('操作成功', url('Member/level_index'));
  541. } else {
  542. $this->error('操作失败');
  543. }
  544. }
  545. return $this->fetch();
  546. }
  547. // 级别 - 编辑
  548. public function level_edit()
  549. {
  550. if (IS_POST) {
  551. $post = input('post.');
  552. $post['level_name'] = trim($post['level_name']);
  553. $post['level_value'] = intval(trim($post['level_value']));
  554. $levelRow = $this->users_level_db->field('level_name,level_value')
  555. ->where([
  556. 'level_id' => ['NEQ', $post['level_id']],
  557. 'lang' => $this->admin_lang,
  558. ])
  559. ->select();
  560. foreach ($levelRow as $key => $val) {
  561. if ($val['level_name'] == $post['level_name']) {
  562. $this->error('级别名称已存在!');
  563. } else if (intval($val['level_value']) == $post['level_value']) {
  564. $this->error('会员等级值不能重复!');
  565. }
  566. }
  567. $newData = [
  568. 'level_value' => intval($post['level_value']),
  569. 'update_time' => getTime(),
  570. ];
  571. $data = array_merge($post, $newData);
  572. $r = $this->users_level_db->where([
  573. 'level_id' => $post['level_id'],
  574. 'lang' => $this->admin_lang,
  575. ])->update($data);
  576. if ($r) {
  577. adminLog('编辑会员级别:'.$data['level_name']);
  578. $this->success('操作成功', url('Member/level_index'));
  579. } else {
  580. $this->error('操作失败');
  581. }
  582. }
  583. $id = input('get.id/d');
  584. $info = $this->users_level_db->where([
  585. 'level_id' => $id,
  586. 'lang' => $this->admin_lang,
  587. ])->find();
  588. $this->assign('info',$info);
  589. return $this->fetch();
  590. }
  591. // 级别 - 删除
  592. public function level_del()
  593. {
  594. $level_id = input('del_id/a');
  595. $level_id = eyIntval($level_id);
  596. if (IS_AJAX_POST && !empty($level_id)) {
  597. // 查询条件
  598. $where = [
  599. 'lang' => $this->admin_lang,
  600. 'level_id' => ['IN', $level_id],
  601. ];
  602. // 查询会员级别
  603. $result = $this->users_level_db->field('level_name,is_system,level_value')->where($where)->select();
  604. $level_name_list = get_arr_column($result, 'level_name');
  605. // 系统内置级别不可删除
  606. foreach ($result as $val) {
  607. if (1 == intval($val['is_system'])) {
  608. $this->error('系统内置,不可删除!');
  609. }
  610. }
  611. // 有使用的会员不可删除
  612. $info = $this->users_db->where([
  613. 'level' => ['IN', $level_id],
  614. 'lang' => $this->admin_lang,
  615. ])->count();
  616. if (!empty($info)) {
  617. $this->error('选中的级别存在会员,不可删除!');
  618. }
  619. // 删除指定级别
  620. $return = $this->users_level_db->where($where)->delete();
  621. if ($return) {
  622. // 查询指定会员级别
  623. $where1 = [
  624. 'lang' => $this->admin_lang,
  625. 'level_value' => ['>', $result[0]['level_value']],
  626. ];
  627. $result_1 = $this->users_level_db->where($where1)->order('level_value asc')->field('level_id')->find();
  628. if (empty($result_1)) {
  629. $where1 = [
  630. 'lang' => $this->admin_lang,
  631. 'level_value' => ['<', $result[0]['level_value']],
  632. ];
  633. $result_1 = $this->users_level_db->where($where1)->order('level_value asc')->field('level_id')->find();
  634. }
  635. // 拼装更新条件
  636. $UpData = [
  637. 'level_id' => $result_1['level_id'],
  638. 'update_time' => getTime(),
  639. ];
  640. // 更新会员升级表数据
  641. Db::name('users_type_manage')->where($where)->update($UpData);
  642. adminLog('删除会员级别:'.implode(',', $level_name_list));
  643. $this->success('删除成功');
  644. }else{
  645. $this->error('删除失败');
  646. }
  647. }
  648. $this->error('参数有误');
  649. }
  650. // 属性列表
  651. public function attr_index()
  652. {
  653. //属性数据
  654. $info = $this->users_parameter_db->field('a.*,a.title,b.title as dtypetitle')
  655. ->alias('a')
  656. ->join('__FIELD_TYPE__ b', 'a.dtype = b.name', 'LEFT')
  657. ->order('a.is_system desc,a.sort_order asc,a.para_id desc')
  658. ->where('a.lang',$this->admin_lang)
  659. ->select();
  660. foreach ($info as $key => $value) {
  661. if ('email' == $value['dtype']) {
  662. $info[$key]['dtypetitle'] = '邮箱地址';
  663. } else if ('mobile' == $value['dtype']) {
  664. $info[$key]['dtypetitle'] = '手机号码';
  665. }
  666. }
  667. $this->assign('info',$info);
  668. return $this->fetch();
  669. }
  670. // 属性添加
  671. public function attr_add()
  672. {
  673. if (IS_POST) {
  674. $post = input('post.');
  675. $post['title'] = trim($post['title']);
  676. if (empty($post['title'])) {
  677. $this->error('属性标题不能为空!');
  678. }
  679. if (empty($post['dtype'])) {
  680. $this->error('请选择属性类型!');
  681. }
  682. $count = $this->users_parameter_db->where([
  683. 'title'=>$post['title']
  684. ])->count();
  685. if (!empty($count)) {
  686. $this->error('属性标题已存在!');
  687. }
  688. $post['dfvalue'] = str_replace(',', ',', $post['dfvalue']);
  689. $post['dfvalue'] = trim($post['dfvalue'], ',');
  690. /*判断默认值是否含有重复值*/
  691. if (in_array($post['dtype'], ['radio','checkbox','select'])) {
  692. if (!empty($post['dfvalue'])){
  693. $dfvalue_arr = [];
  694. $dfvalue_arr = explode(',', $post['dfvalue']);
  695. foreach ($dfvalue_arr as &$v) {
  696. $v = trim($v);
  697. }
  698. if (count($dfvalue_arr) != count(array_unique($dfvalue_arr))) {
  699. $this->error('默认值不能含有相同的值!');
  700. }
  701. }
  702. }
  703. /*end*/
  704. $post['add_time'] = getTime();
  705. $post['lang'] = $this->admin_lang;
  706. $post['sort_order'] = '100';
  707. $para_id = $this->users_parameter_db->insertGetId($post);
  708. if (!empty($para_id)) {
  709. $name = 'para_'.$para_id;
  710. $return = $this->users_parameter_db->where('para_id',$para_id)
  711. ->update([
  712. 'name' => $name,
  713. 'update_time' => getTime(),
  714. ]);
  715. if ($return) {
  716. adminLog('新增会员属性:'.$post['title']);
  717. $this->success('操作成功',url('Member/attr_index'));
  718. }
  719. }
  720. $this->error('操作失败');
  721. }
  722. $field = $this->field_type_db->field('name,title,ifoption')
  723. ->where([
  724. 'name' => ['IN', ['text','checkbox','multitext','radio','select','img','file']]
  725. ])
  726. ->select();
  727. $this->assign('field',$field);
  728. return $this->fetch();
  729. }
  730. // 属性修改
  731. public function attr_edit()
  732. {
  733. $para_id = input('param.id/d');
  734. if (IS_POST && !empty($para_id)) {
  735. $post = input('post.');
  736. $post['title'] = trim($post['title']);
  737. if (empty($post['title'])) {
  738. $this->error('属性标题不能为空!');
  739. }
  740. if (empty($post['dtype'])) {
  741. $this->error('请选择属性类型!');
  742. }
  743. $count = $this->users_parameter_db->where([
  744. 'title' => $post['title'],
  745. 'para_id' => ['NEQ', $post['para_id']],
  746. ])->count();
  747. if ($count) {
  748. $this->error('属性标题已存在!');
  749. }
  750. $post['dfvalue'] = str_replace(',', ',', $post['dfvalue']);
  751. $post['dfvalue'] = trim($post['dfvalue'], ',');
  752. /*判断默认值是否含有重复值*/
  753. if (in_array($post['dtype'], ['radio','checkbox','select'])) {
  754. if (!empty($post['dfvalue'])){
  755. $dfvalue_arr = [];
  756. $dfvalue_arr = explode(',', $post['dfvalue']);
  757. foreach ($dfvalue_arr as &$v) {
  758. $v = trim($v);
  759. }
  760. if (count($dfvalue_arr) != count(array_unique($dfvalue_arr))) {
  761. $this->error('默认值不能含有相同的值!');
  762. }
  763. }
  764. }
  765. /*end*/
  766. $post['update_time'] = getTime();
  767. $return = $this->users_parameter_db->where([
  768. 'para_id' => $para_id,
  769. 'lang' => $this->admin_lang,
  770. ])->update($post);
  771. if ($return) {
  772. adminLog('编辑会员属性:'.$post['title']);
  773. $this->success('操作成功',url('Member/attr_index'));
  774. }else{
  775. $this->error('操作失败');
  776. }
  777. }
  778. $info = $this->users_parameter_db->where([
  779. 'para_id' => $para_id,
  780. 'lang' => $this->admin_lang,
  781. ])->find();
  782. $this->assign('info',$info);
  783. $field = $this->field_type_db->field('name,title,ifoption')
  784. ->where([
  785. 'name' => ['IN', ['text','checkbox','multitext','radio','select','img','file']]
  786. ])
  787. ->select();
  788. $this->assign('field',$field);
  789. return $this->fetch();
  790. }
  791. // 属性删除
  792. public function attr_del()
  793. {
  794. $para_id = input('del_id/a');
  795. $para_id = eyIntval($para_id);
  796. if (IS_AJAX_POST && !empty($para_id)) {
  797. $result = $this->users_parameter_db->field('title')
  798. ->where([
  799. 'para_id' => ['IN', $para_id],
  800. 'lang' => $this->admin_lang,
  801. ])
  802. ->select();
  803. $title_list = get_arr_column($result, 'title');
  804. // 删除会员属性表数据
  805. $return = $this->users_parameter_db->where([
  806. 'para_id' => ['IN', $para_id],
  807. 'lang' => $this->admin_lang,
  808. ])->delete();
  809. if ($return) {
  810. // 删除会员属性信息表数据
  811. $this->users_list_db->where([
  812. 'para_id' => ['IN', $para_id],
  813. 'lang' => $this->admin_lang,
  814. ])->delete();
  815. adminLog('删除会员属性:'.implode(',', $title_list));
  816. $this->success('删除成功');
  817. }else{
  818. $this->error('删除失败');
  819. }
  820. }
  821. $this->error('参数有误');
  822. }
  823. // 功能设置
  824. public function users_config()
  825. {
  826. if (IS_POST) {
  827. $post = input('post.');
  828. /*商城入口*/
  829. $shop_open = $post['shop']['shop_open'];
  830. $shop_open_old = !empty($this->userConfig['shop_open']) ? $this->userConfig['shop_open'] : 0;
  831. /*--end*/
  832. // 邮件验证的检测
  833. if (2 == $post['users']['users_verification']) {
  834. $users_config_email = $this->users_config_email();
  835. if (!empty($users_config_email)) {
  836. $this->error($users_config_email);
  837. }
  838. }
  839. // 第三方登录
  840. if (1 == $post['oauth']['oauth_open']) {
  841. empty($post['oauth']['oauth_qq']) && $post['oauth']['oauth_qq'] = 0;
  842. empty($post['oauth']['oauth_weixin']) && $post['oauth']['oauth_weixin'] = 0;
  843. empty($post['oauth']['oauth_weibo']) && $post['oauth']['oauth_weibo'] = 0;
  844. }
  845. foreach ($post as $key => $val) {
  846. getUsersConfigData($key, $val);
  847. }
  848. $this->success('操作成功');
  849. }
  850. // 获取会员配置信息
  851. $this->assign('info',$this->userConfig);
  852. /*检测是否存在订单中心模板*/
  853. if ('v1.0.1' > getVersion('version_themeshop') && !empty($this->userConfig['shop_open'])) {
  854. $is_syn_theme_shop = 1;
  855. } else {
  856. $is_syn_theme_shop = 0;
  857. }
  858. $this->assign('is_syn_theme_shop',$is_syn_theme_shop);
  859. /*--end*/
  860. return $this->fetch();
  861. }
  862. // 第三方登录配置
  863. public function ajax_set_oauth_config()
  864. {
  865. $oauth = input('param.oauth/s', 'qq');
  866. return $this->fetch();
  867. }
  868. // 邮件验证的检测
  869. public function ajax_users_config_email()
  870. {
  871. if (IS_AJAX) {
  872. // 邮件验证的检测
  873. $users_config_email = $this->users_config_email();
  874. if (!empty($users_config_email)) $this->error($users_config_email);
  875. $this->success('检验通过');
  876. }
  877. $this->error('参数有误');
  878. }
  879. private function users_config_email(){
  880. // 会员属性信息
  881. $where = array(
  882. 'name' => ['LIKE', "email_%"],
  883. 'lang' => $this->admin_lang,
  884. 'is_system' => 1,
  885. );
  886. // 是否要为必填项
  887. $param = $this->users_parameter_db->where($where)->field('title,is_hidden')->find();
  888. if (empty($param) || 1 == $param['is_hidden']) {
  889. return "请先把会员属性的<font color='red'>{$param['title']}</font>设置为显示,且为必填项!";
  890. }
  891. $param = $this->users_parameter_db->where($where)->field('title,is_required')->find();
  892. if (empty($param) || 0 == $param['is_required']) {
  893. return "请先把会员属性的<font color='red'>{$param['title']}</font>设置为必填项!";
  894. }
  895. // 是否开启邮箱发送扩展
  896. $openssl_funcs = get_extension_funcs('openssl');
  897. if (!$openssl_funcs) {
  898. return "请联系空间商,开启php的 <font color='red'>openssl</font> 扩展!";
  899. }
  900. $send_email_scene = config('send_email_scene');
  901. $scene = $send_email_scene[2]['scene'];
  902. // 自动启用注册邮件模板
  903. Db::name('smtp_tpl')->where([
  904. 'send_scene' => $scene,
  905. 'lang' => $this->admin_lang,
  906. ])->update([
  907. 'is_open' => 1,
  908. 'update_time' => getTime(),
  909. ]);
  910. // 是否填写邮件配置
  911. $smtp_config = tpCache('smtp');
  912. if (empty($smtp_config['smtp_user']) || empty($smtp_config['smtp_pwd'])) {
  913. return "请先完善<font color='red'>(邮件配置)</font>,具体步骤【基本信息】->【接口配置】->【邮件配置】";
  914. }
  915. return false;
  916. }
  917. // 手机验证的检测
  918. public function ajax_users_config_mobile()
  919. {
  920. if (IS_AJAX) {
  921. // 邮件验证的检测
  922. $users_config_mobile = $this->users_config_mobile();
  923. if (!empty($users_config_mobile)) $this->error($users_config_mobile);
  924. $this->success('检验通过');
  925. }
  926. $this->error('参数有误');
  927. }
  928. private function users_config_mobile(){
  929. // 会员属性信息
  930. $where = array(
  931. 'name' => ['LIKE', "mobile_%"],
  932. 'lang' => $this->admin_lang,
  933. 'is_system' => 1
  934. );
  935. // 是否要为必填项
  936. $param = $this->users_parameter_db->where($where)->field('title, is_hidden')->find();
  937. if (empty($param) || 1 == $param['is_hidden']) {
  938. return "请先把会员属性的<font color='red'>{$param['title']}</font>设置为显示,且为必填项!";
  939. }
  940. $param = $this->users_parameter_db->where($where)->field('title, is_required')->find();
  941. if (empty($param) || 0 == $param['is_required']) {
  942. return "请先把会员属性的<font color='red'>{$param['title']}</font>设置为必填项!";
  943. }
  944. // 自动启用注册手机模板
  945. Db::name('sms_template')->where([
  946. 'send_scene' => 0,
  947. 'lang' => $this->admin_lang,
  948. ])->update([
  949. 'is_open' => 1,
  950. 'update_time' => getTime()
  951. ]);
  952. // 是否填写手机短信配置
  953. $sms_config = tpCache('sms');
  954. foreach ($sms_config as $key => $val) {
  955. if (!in_array($key, ['sms_shop_order_pay', 'sms_shop_order_send'])) {
  956. if (preg_match('/^sms_/i', $key) && empty($val)) {
  957. return "请先完善<font color='red'>(短信配置)</font>,具体步骤【基本信息】->【接口配置】->【短信配置】";
  958. }
  959. }
  960. }
  961. return false;
  962. }
  963. // 支付方式配置
  964. public function pay_set(){
  965. $payConfig = $this->userConfig;
  966. /*微信支付配置*/
  967. $wechat = !empty($payConfig['pay_wechat_config']) ? $payConfig['pay_wechat_config'] : [];
  968. $this->assign('wechat',unserialize($wechat));
  969. /*--end*/
  970. /*支付宝支付配置*/
  971. $alipay = !empty($payConfig['pay_alipay_config']) ? $payConfig['pay_alipay_config'] : [];
  972. $this->assign('alipay',unserialize($alipay));
  973. if (version_compare(PHP_VERSION,'5.5.0','<')) {
  974. $php_version = 1; // PHP5.4.0或更低版本,可使用旧版支付方式
  975. }else{
  976. $php_version = 0;// PHP5.5.0或更高版本,可使用新版支付方式,兼容旧版支付方式
  977. }
  978. $this->assign('php_version',$php_version);
  979. /*--end*/
  980. return $this->fetch();
  981. }
  982. // 微信配信信息
  983. public function wechat_set(){
  984. if (IS_POST) {
  985. $post = input('post.');
  986. if (empty($post['wechat']['appid'])) {
  987. $this->error('微信AppId不能为空!');
  988. }
  989. if (empty($post['wechat']['mchid'])) {
  990. $this->error('微信商户号不能为空!');
  991. }
  992. if (empty($post['wechat']['key'])) {
  993. $this->error('微信KEY值不能为空!');
  994. }
  995. $data = model('Pay')->payForQrcode($post['wechat']);
  996. if ($data['return_code'] == 'FAIL') {
  997. if ('签名错误' == $data['return_msg']) {
  998. $this->error('微信KEY值错误!');
  999. }else if (stristr($data['return_msg'], 'appid')) {
  1000. $this->error('微信AppId错误!');
  1001. }else if (stristr($data['return_msg'], 'mch_id')) {
  1002. $this->error('微信商户号错误!');
  1003. } else {
  1004. $this->error($data['return_msg']);
  1005. }
  1006. }
  1007. foreach ($post as $key => $val) {
  1008. getUsersConfigData('pay', ['pay_wechat_config'=>serialize($val)]);
  1009. }
  1010. $this->success('操作成功');
  1011. }
  1012. }
  1013. // 支付宝配信信息
  1014. public function alipay_set(){
  1015. if (IS_POST) {
  1016. $post = input('post.');
  1017. $php_version = $post['alipay']['version'];
  1018. if (0 == $php_version) {
  1019. if (empty($post['alipay']['app_id'])) {
  1020. $this->error('支付APPID不能为空!');
  1021. }
  1022. if (empty($post['alipay']['merchant_private_key'])) {
  1023. $this->error('商户私钥不能为空!');
  1024. }
  1025. if (empty($post['alipay']['alipay_public_key'])) {
  1026. $this->error('支付宝公钥不能为空!');
  1027. }
  1028. $order_number = getTime();
  1029. $return = $this->check_alipay_order($order_number,'admin_pay',$post['alipay']);
  1030. if ('ok' != $return) {
  1031. $this->error($return);
  1032. }
  1033. }else if (1 == $php_version) {
  1034. if (empty($post['alipay']['account'])) {
  1035. $this->error('支付宝账号不能为空!');
  1036. }
  1037. if (empty($post['alipay']['code'])) {
  1038. $this->error('交易安全校验码不能为空!');
  1039. }
  1040. if (empty($post['alipay']['id'])) {
  1041. $this->error('合作者身份ID不能为空!');
  1042. }
  1043. }
  1044. // 处理数据中的空格和换行
  1045. $post['alipay']['app_id'] = preg_replace('/\r|\n/', '', $post['alipay']['app_id']);
  1046. $post['alipay']['merchant_private_key'] = preg_replace('/\r|\n/', '', $post['alipay']['merchant_private_key']);
  1047. $post['alipay']['alipay_public_key'] = preg_replace('/\r|\n/', '', $post['alipay']['alipay_public_key']);
  1048. foreach ($post as $key => $val) {
  1049. getUsersConfigData('pay', ['pay_alipay_config'=>serialize($val)]);
  1050. }
  1051. $this->success('操作成功');
  1052. }
  1053. }
  1054. // 充值记录列表
  1055. public function money_index()
  1056. {
  1057. $list = array();
  1058. $keywords = input('keywords/s');
  1059. $condition = array();
  1060. // 应用搜索条件
  1061. if (!empty($keywords)) {
  1062. $condition['a.order_number'] = array('LIKE', "%{$keywords}%");
  1063. }
  1064. // 多语言
  1065. $condition['a.lang'] = array('eq', $this->admin_lang);
  1066. /**
  1067. * 数据查询
  1068. */
  1069. $count = $this->users_money_db->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  1070. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  1071. $list = $this->users_money_db->field('a.*,b.username')
  1072. ->alias('a')
  1073. ->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')
  1074. ->where($condition)
  1075. ->order('a.moneyid desc')
  1076. ->limit($Page->firstRow.','.$Page->listRows)
  1077. ->select();
  1078. $show = $Page->show();// 分页显示输出
  1079. $this->assign('page',$show);// 赋值分页输出
  1080. $this->assign('list',$list);// 赋值数据集
  1081. $this->assign('pager',$Page);// 赋值分页集
  1082. // 订单类型
  1083. $pay_cause_type_arr = config('global.pay_cause_type_arr');
  1084. $this->assign('pay_cause_type_arr',$pay_cause_type_arr);
  1085. // 充值状态
  1086. $pay_status_arr = config('global.pay_status_arr');
  1087. $this->assign('pay_status_arr',$pay_status_arr);
  1088. // 支付方式
  1089. $pay_method_arr = config('global.pay_method_arr');
  1090. $this->assign('pay_method_arr',$pay_method_arr);
  1091. return $this->fetch();
  1092. }
  1093. // 充值记录编辑
  1094. public function money_edit()
  1095. {
  1096. $param = input('param.');
  1097. $MoneyData = $this->users_money_db->find($param['moneyid']);
  1098. $this->assign('MoneyData',$MoneyData);
  1099. $UsersData = $this->users_db->find($MoneyData['users_id']);
  1100. $this->assign('UsersData',$UsersData);
  1101. // 支付宝查询订单
  1102. if ('alipay' == $MoneyData['pay_method']) {
  1103. $return = $this->check_alipay_order($MoneyData['order_number']);
  1104. $this->assign('return',$return);
  1105. }
  1106. // 微信查询订单
  1107. if ('wechat' == $MoneyData['pay_method']) {
  1108. $return = $this->check_wechat_order($MoneyData['order_number']);
  1109. $this->assign('return',$return);
  1110. }
  1111. // 人为处理订单
  1112. if ('artificial' == $MoneyData['pay_method']) {
  1113. $return = '人为处理';
  1114. $this->assign('return',$return);
  1115. }
  1116. // 获取订单状态
  1117. $pay_status_arr = Config::get('global.pay_status_arr');
  1118. $this->assign('pay_status_arr',$pay_status_arr);
  1119. // 支付方式
  1120. $pay_method_arr = config('global.pay_method_arr');
  1121. $this->assign('pay_method_arr',$pay_method_arr);
  1122. return $this->fetch();
  1123. }
  1124. /**
  1125. * 删除充值记录
  1126. */
  1127. public function money_del()
  1128. {
  1129. if (IS_POST) {
  1130. $id_arr = input('del_id/a');
  1131. $id_arr = eyIntval($id_arr);
  1132. if(!empty($id_arr)){
  1133. $result = Db::name('users_money')->field('order_number')
  1134. ->where([
  1135. 'moneyid' => ['IN', $id_arr],
  1136. 'lang' => $this->admin_lang,
  1137. ])->select();
  1138. $order_number_list = get_arr_column($result, 'order_number');
  1139. $r = Db::name('users_money')->where([
  1140. 'moneyid' => ['IN', $id_arr],
  1141. 'lang' => $this->admin_lang,
  1142. ])
  1143. ->cache(true, null, "users_money")
  1144. ->delete();
  1145. if($r !== false){
  1146. adminLog('删除充值记录:'.implode(',', $order_number_list));
  1147. $this->success('删除成功');
  1148. }
  1149. }
  1150. $this->error('删除失败');
  1151. }
  1152. $this->error('非法访问');
  1153. }
  1154. // 标记订单逻辑
  1155. public function money_mark_order()
  1156. {
  1157. if (IS_POST) {
  1158. $moneyid = input('param.moneyid/d');
  1159. // 查询订单信息
  1160. $MoneyData = $this->users_money_db->where([
  1161. 'moneyid' => $moneyid,
  1162. 'lang' => $this->admin_lang,
  1163. ])->find();
  1164. // 处理订单逻辑
  1165. if (in_array($MoneyData['status'], [1,3])) {
  1166. $users_id = $MoneyData['users_id'];
  1167. $order_number = $MoneyData['order_number'];
  1168. $return = '';
  1169. if ('alipay' == $MoneyData['pay_method']) { // 支付宝查询订单
  1170. $return = $this->check_alipay_order($order_number);
  1171. } else if ('wechat' == $MoneyData['pay_method']) { // 微信查询订单
  1172. $return = $this->check_wechat_order($order_number);
  1173. } else if ('artificial' == $MoneyData['pay_method']) { // 手工充值订单
  1174. $return = '手工充值';
  1175. }
  1176. $result = [
  1177. 'users_id' => $users_id,
  1178. 'order_number'=> $order_number,
  1179. 'status' => '手动标记为已充值订单',
  1180. 'details' => '充值详情:'.$return,
  1181. 'pay_method' => 'artificial', //人为处理
  1182. 'money' => $MoneyData['money'],
  1183. 'users_money' => $MoneyData['users_money'],
  1184. ];
  1185. // 标记为未付款
  1186. if (3 == $MoneyData['status']) {
  1187. $result['status'] = '手动标记为未付款订单';
  1188. } else if (1 == $MoneyData['status']) {
  1189. $result['status'] = '手动标记为已充值订单';
  1190. }
  1191. // 修改会员充值明细表对应的订单数据,存入返回的数据,订单标记为已付款
  1192. $Where = [
  1193. 'moneyid' => $MoneyData['moneyid'],
  1194. 'users_id' => $users_id,
  1195. ];
  1196. $UpdateData = [
  1197. 'pay_details' => serialize($result),
  1198. 'update_time' => getTime(),
  1199. ];
  1200. // 标记为未付款时则状态更新为1
  1201. if (3 == $MoneyData['status']) {
  1202. $UpdateData['status'] = 1;
  1203. } else if (1 == $MoneyData['status']) {
  1204. $UpdateData['status'] = 3;
  1205. }
  1206. $IsMoney = $this->users_money_db->where($Where)->update($UpdateData);
  1207. if (!empty($IsMoney)) {
  1208. // 同步修改会员的金额
  1209. $UsersData = [
  1210. 'update_time' => getTime(),
  1211. ];
  1212. // 标记为未付款时则减去金额
  1213. if (3 == $MoneyData['status']) {
  1214. $UsersData = $this->users_db->field('users_money')->find($users_id);
  1215. if ($UsersData['users_money'] <= $MoneyData['money']) {
  1216. $UsersData['users_money'] = 0;
  1217. }else{
  1218. $UsersData['users_money'] = Db::raw('users_money-'.$MoneyData['money']);
  1219. }
  1220. } else if (1 == $MoneyData['status']) {
  1221. $UsersData['users_money'] = Db::raw('users_money+'.$MoneyData['money']);
  1222. }
  1223. $IsUsers = $this->users_db->where('users_id',$users_id)->update($UsersData);
  1224. if (!empty($IsUsers)) {
  1225. $this->success('操作成功');
  1226. }
  1227. }
  1228. }
  1229. $this->error('操作失败');
  1230. }
  1231. }
  1232. // 查询订单付款状态(微信)
  1233. private function check_wechat_order($order_number)
  1234. {
  1235. if (!empty($order_number)) {
  1236. // 引入文件
  1237. vendor('wechatpay.lib.WxPayApi');
  1238. vendor('wechatpay.lib.WxPayConfig');
  1239. // 实例化加载订单号
  1240. $input = new \WxPayOrderQuery;
  1241. $input->SetOut_trade_no($order_number);
  1242. // 处理微信配置数据
  1243. $pay_wechat_config = !empty($this->userConfig['pay_wechat_config']) ? $this->userConfig['pay_wechat_config'] : '';
  1244. $pay_wechat_config = unserialize($pay_wechat_config);
  1245. $config_data['app_id'] = $pay_wechat_config['appid'];
  1246. $config_data['mch_id'] = $pay_wechat_config['mchid'];
  1247. $config_data['key'] = $pay_wechat_config['key'];
  1248. // 实例化微信配置
  1249. $config = new \WxPayConfig($config_data);
  1250. $wxpayapi = new \WxPayApi;
  1251. // 返回结果
  1252. $result = $wxpayapi->orderQuery($config, $input);
  1253. // 判断结果
  1254. if ('ORDERNOTEXIST' == $result['err_code'] && 'FAIL' == $result['result_code']) {
  1255. return '订单在微信中不存在!';
  1256. }else if ('NOTPAY' == $result['trade_state'] && 'SUCCESS' == $result['result_code']) {
  1257. return '订单在微信中生成,但并未支付完成!';
  1258. }else if ('SUCCESS' == $result['trade_state'] && 'SUCCESS' == $result['result_code']) {
  1259. return '订单已使用'.$result['attach'].'完成!';
  1260. }
  1261. }else{
  1262. return false;
  1263. }
  1264. }
  1265. // 查询订单付款状态(支付宝)
  1266. private function check_alipay_order($order_number,$admin_pay='',$alipay='')
  1267. {
  1268. if (!empty($order_number)) {
  1269. // 引入文件
  1270. vendor('alipay.pagepay.service.AlipayTradeService');
  1271. vendor('alipay.pagepay.buildermodel.AlipayTradeQueryContentBuilder');
  1272. // 实例化加载订单号
  1273. $RequestBuilder = new \AlipayTradeQueryContentBuilder;
  1274. $out_trade_no = trim($order_number);
  1275. $RequestBuilder->setOutTradeNo($out_trade_no);
  1276. // 处理支付宝配置数据
  1277. if (empty($alipay)) {
  1278. $pay_alipay_config = !empty($this->userConfig['pay_alipay_config']) ? $this->userConfig['pay_alipay_config'] : '';
  1279. if (empty($pay_alipay_config)) {
  1280. return false;
  1281. }
  1282. $alipay = unserialize($pay_alipay_config);
  1283. }
  1284. $config['app_id'] = $alipay['app_id'];
  1285. $config['merchant_private_key'] = $alipay['merchant_private_key'];
  1286. $config['charset'] = 'UTF-8';
  1287. $config['sign_type'] = 'RSA2';
  1288. $config['gatewayUrl'] = 'https://openapi.alipay.com/gateway.do';
  1289. $config['alipay_public_key'] = $alipay['alipay_public_key'];
  1290. // 实例化支付宝配置
  1291. $aop = new \AlipayTradeService($config);
  1292. // 返回结果
  1293. if (!empty($admin_pay)) {
  1294. $result = $aop->IsQuery($RequestBuilder,$admin_pay);
  1295. }else{
  1296. $result = $aop->Query($RequestBuilder);
  1297. }
  1298. $result = json_decode(json_encode($result),true);
  1299. // 判断结果
  1300. if ('40004' == $result['code'] && 'Business Failed' == $result['msg']) {
  1301. // 用于支付宝支付配置验证
  1302. if (!empty($admin_pay)) { return 'ok'; }
  1303. // 用于订单查询
  1304. return '订单在支付宝中不存在!';
  1305. }else if ('10000' == $result['code'] && 'WAIT_BUYER_PAY' == $result['trade_status']) {
  1306. return '订单在支付宝中生成,但并未支付完成!';
  1307. }else if ('10000' == $result['code'] && 'TRADE_SUCCESS' == $result['trade_status']) {
  1308. return '订单已使用支付宝支付完成!';
  1309. }
  1310. // 用于支付宝支付配置验证
  1311. if (!empty($admin_pay) && !empty($result)) {
  1312. if ('40001' == $result['code'] && 'Missing Required Arguments' == $result['msg']) {
  1313. return '商户私钥错误!';
  1314. }
  1315. if (!is_array($result)) {
  1316. return $result;
  1317. }
  1318. }
  1319. }
  1320. }
  1321. /**
  1322. * 版本检测更新弹窗
  1323. */
  1324. public function ajax_check_upgrade_version()
  1325. {
  1326. $memberLogic = new MemberLogic;
  1327. $upgradeMsg = $memberLogic->checkVersion(); // 升级包消息
  1328. $this->success('检测成功', null, $upgradeMsg);
  1329. }
  1330. /**
  1331. * 一键升级
  1332. */
  1333. public function OneKeyUpgrade(){
  1334. header('Content-Type:application/json; charset=utf-8');
  1335. function_exists('set_time_limit') && set_time_limit(0);
  1336. /*权限控制 by 小虎哥*/
  1337. $auth_role_info = session('admin_info.auth_role_info');
  1338. if(0 < intval(session('admin_info.role_id')) && ! empty($auth_role_info) && intval($auth_role_info['online_update']) <= 0){
  1339. $this->error('您没有操作权限,请联系超级管理员分配权限');
  1340. }
  1341. /*--end*/
  1342. $memberLogic = new MemberLogic;
  1343. $data = $memberLogic->OneKeyUpgrade(); //升级包消息
  1344. if (1 <= intval($data['code'])) {
  1345. $this->success($data['msg'], null, ['code'=>$data['code']]);
  1346. } else {
  1347. $msg = '模板升级异常,请第一时间联系技术支持,排查问题!';
  1348. if (is_array($data)) {
  1349. $msg = $data['msg'];
  1350. }
  1351. $this->error($msg);
  1352. }
  1353. }
  1354. /**
  1355. * 检测目录权限
  1356. */
  1357. public function check_authority()
  1358. {
  1359. $filelist = input('param.filelist/s');
  1360. $memberLogic = new MemberLogic;
  1361. $data = $memberLogic->checkAuthority($filelist); //检测目录权限
  1362. if (is_array($data)) {
  1363. if (1 == $data['code']) {
  1364. $this->success($data['msg']);
  1365. } else {
  1366. $this->error($data['msg'], null, $data['data']);
  1367. }
  1368. } else {
  1369. $this->error('检测模板失败', null, ['code'=>1]);
  1370. }
  1371. }
  1372. // 前台会员左侧菜单
  1373. public function ajax_menu_index()
  1374. {
  1375. $list = array();
  1376. $condition = array();
  1377. // 多语言
  1378. $condition['a.lang'] = array('eq', $this->admin_lang);
  1379. /**
  1380. * 数据查询
  1381. */
  1382. $count = Db::name('users_menu')->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  1383. $Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  1384. $row = Db::name('users_menu')->field('a.*')
  1385. ->alias('a')
  1386. ->where($condition)
  1387. ->order('a.sort_order asc, a.id asc')
  1388. ->limit($Page->firstRow.','.$Page->listRows)
  1389. ->select();
  1390. $list = [];
  1391. foreach ($row as $key => $val) {
  1392. $list[] = $val;
  1393. }
  1394. $show = $Page->show();// 分页显示输出
  1395. $this->assign('page',$show);// 赋值分页输出
  1396. $this->assign('list',$list);// 赋值数据集
  1397. $this->assign('pager',$Page);// 赋值分页集
  1398. return $this->fetch();
  1399. }
  1400. }