member.ctrl.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->model('mc');
  8. $dos = array('address', 'base_information', 'member_credits', 'credit_statistics', 'display','del', 'add', 'group', 'register_setting', 'credit_setting', 'save_credit_setting', 'save_tactics_setting');
  9. $do = in_array($do, $dos) ? $do : 'display';
  10. if ($do == 'save_tactics_setting') {
  11. $setting = $_GPC['setting'];
  12. if (empty($setting)) {
  13. iajax(1, '');
  14. }
  15. uni_setting_save('creditbehaviors', $setting);
  16. iajax(0, '');
  17. }
  18. if ($do == 'save_credit_setting') {
  19. $credit_setting = $_GPC['credit_setting'];
  20. if (empty($credit_setting)) {
  21. iajax(1, '');
  22. }
  23. uni_setting_save('creditnames', $credit_setting);
  24. iajax(0, '');
  25. }
  26. if ($do == 'register_setting') {
  27. $_W['page']['title'] = '注册设置';
  28. if (checksubmit('submit')) {
  29. $passport = $_GPC['passport'];
  30. if (!empty($passport)) {
  31. uni_setting_save('passport', $passport);
  32. itoast('设置成功', '', 'success');
  33. }
  34. }
  35. $setting = uni_setting_load('passport');
  36. $register_setting = !empty($setting['passport']) ? $setting['passport'] : array();
  37. template('mc/member');
  38. }
  39. if ($do == 'credit_setting') {
  40. $_W['page']['title'] = '积分设置';
  41. $credit_setting = uni_setting_load('creditnames');
  42. $credit_setting = $credit_setting['creditnames'];
  43. $credit_tactics = uni_setting_load('creditbehaviors');
  44. $credit_tactics = $credit_tactics['creditbehaviors'];
  45. $enable_credit = array();
  46. if (!empty($credit_setting)) {
  47. foreach ($credit_setting as $key => $credit) {
  48. if ($credit['enabled'] == 1) {
  49. $enable_credit[] = $key;
  50. }
  51. }
  52. unset($credit);
  53. }
  54. template('mc/member');
  55. }
  56. if($do == 'display') {
  57. $_W['page']['title'] = '会员列表';
  58. $groups = mc_groups();
  59. $search_mod = intval($_GPC['search_mod']) == 1 ? '1' : '2';
  60. $pindex = max(1, intval($_GPC['page']));
  61. $psize = 25;
  62. $condition = '';
  63. $params = array(':uniacid' => $_W['uniacid']);
  64. if (!empty($_GPC['username'])) {
  65. if ($search_mod == 1) {
  66. $condition .= " AND ((`uid` = :openid) OR (`realname` = :realname) OR (`nickname` = :nickname) OR (`mobile` = :mobile))";
  67. $params[':realname'] = $params[':nickname'] = $params[':mobile'] = trim($_GPC['username']);
  68. if (!is_numeric(trim($_GPC['username']))) {
  69. $uid = pdo_getcolumn('mc_mapping_fans', array('openid' => trim($_GPC['username'])), 'uid');
  70. $params[':openid'] = empty($uid) ? "" : $uid;
  71. } else {
  72. $params[':openid'] = trim($_GPC['username']);
  73. }
  74. } else {
  75. $condition .= " AND ((`uid` = :openid) OR (`realname` LIKE :realname) OR (`nickname` LIKE :nickname) OR (`mobile` LIKE :mobile))";
  76. $params[':realname'] = $params[':nickname'] = $params[':mobile'] = '%' . trim($_GPC['username']) . '%';
  77. if (!is_numeric(trim($_GPC['username']))) {
  78. $uid = pdo_getcolumn('mc_mapping_fans', array('openid' => trim($_GPC['username'])), 'uid');
  79. $params[':openid'] = empty($uid) ? "" : $uid;
  80. } else {
  81. $params[':openid'] = $_GPC['username'];
  82. }
  83. }
  84. }
  85. if (!empty($_GPC['datelimit'])) {
  86. $starttime = strtotime($_GPC['datelimit']['start']);
  87. $endtime = strtotime($_GPC['datelimit']['end']) + 86399;
  88. $condition .= " AND createtime > :start AND createtime < :end";
  89. $params[':start'] = $starttime;
  90. $params[':end'] = $endtime;
  91. }
  92. if (intval($_GPC['groupid']) > 0) {
  93. $condition .= " AND `groupid` = :groupid";
  94. $params[':groupid'] = intval($_GPC['groupid']);
  95. }
  96. if(checksubmit('export_submit', true)) {
  97. $sql = "SELECT `uid`, `uniacid`, `groupid`, `realname`, `birthmonth`, `birthday`, `nickname`, `email`, `mobile`, `credit1`, `credit2`, `credit6`, `createtime` FROM". tablename('mc_members') . " WHERE uniacid = :uniacid " . $condition;
  98. $members = pdo_fetchall($sql, $params);
  99. $html = mc_member_export_parse($members);
  100. header("Content-type:text/csv");
  101. header("Content-Disposition:attachment; filename=会员数据.csv");
  102. echo $html;
  103. exit();
  104. }
  105. $sql = "SELECT uid, uniacid, groupid, realname, nickname, email, mobile, credit1, credit2, credit6, createtime FROM ".tablename('mc_members')." WHERE uniacid = :uniacid ".$condition." ORDER BY createtime DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize;
  106. $list = pdo_fetchall($sql, $params);
  107. if(!empty($list)) {
  108. foreach($list as &$li) {
  109. if(empty($li['email']) || (!empty($li['email']) && substr($li['email'], -6) == 'we7.cc' && strlen($li['email']) == 39)) {
  110. $li['email_effective'] = 0;
  111. } else {
  112. $li['email_effective'] = 1;
  113. }
  114. }
  115. }
  116. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('mc_members')." WHERE uniacid = :uniacid ".$condition, $params);
  117. $pager = pagination($total, $pindex, $psize);
  118. $stat['total'] = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_members') . ' WHERE uniacid = :uniacid', array(':uniacid' => $_W['uniacid']));
  119. $stat['today'] = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_members') . ' WHERE uniacid = :uniacid AND createtime >= :starttime AND createtime <= :endtime', array(':uniacid' => $_W['uniacid'], ':starttime' => strtotime('today'), ':endtime' => strtotime('today') + 86399));
  120. $stat['yesterday'] = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_members') . ' WHERE uniacid = :uniacid AND createtime >= :starttime AND createtime <= :endtime', array(':uniacid' => $_W['uniacid'], ':starttime' => strtotime('today')-86399, ':endtime' => strtotime('today')));
  121. template('mc/member');
  122. }
  123. if($do == 'del') {
  124. if(!empty($_GPC['uid'])) {
  125. if (is_array($_GPC['uid'])) {
  126. $delete_uids = array();
  127. foreach ($_GPC['uid'] as $uid) {
  128. $uid = intval($uid);
  129. if (!empty($uid)) {
  130. $delete_uids[] = intval($uid);
  131. }
  132. }
  133. } else {
  134. $delete_uids = $_GPC['uid'];
  135. }
  136. if (!empty($delete_uids)) {
  137. $tables = array('mc_members', 'mc_card_members', 'mc_card_notices', 'mc_card_notices_unread', 'mc_card_record', 'mc_card_sign_record', 'mc_cash_record', 'mc_credits_recharge', 'mc_credits_record', 'mc_member_address', 'mc_mapping_ucenter');
  138. foreach ($tables as $key => $value) {
  139. pdo_delete($value, array('uniacid' => $_W['uniacid'], 'uid' => $delete_uids));
  140. }
  141. pdo_update('mc_mapping_fans', array('uid' => 0), array('uid' => $delete_uids, 'uniacid' => $_W['uniacid']));
  142. itoast('删除成功!', referer(), 'success');
  143. }
  144. itoast('请选择要删除的项目!', referer(), 'error');
  145. }
  146. }
  147. if($do == 'add') {
  148. if($_W['isajax']) {
  149. $type = trim($_GPC['type']);
  150. $type_list = array('mobile', 'email');
  151. $data = trim($_GPC['data']);
  152. if(empty($data) || empty($type) || !in_array($type, $type_list)) {
  153. exit(json_encode(array('valid' => false)));
  154. }
  155. $user = pdo_get('mc_members', array('uniacid' => $_W['uniacid'], $type => $data));
  156. if(empty($user)) {
  157. exit(json_encode(array('valid' => true)));
  158. } else {
  159. exit(json_encode(array('valid' => false)));
  160. }
  161. }
  162. if(checksubmit('form')) {
  163. $realname = trim($_GPC['realname']) ? trim($_GPC['realname']) : itoast('姓名不能为空', '', '');
  164. $mobile = trim($_GPC['mobile']) ? trim($_GPC['mobile']) : itoast('手机不能为空', '', '');
  165. $user = pdo_get('mc_members', array('uniacid' => $_W['uniacid'], 'mobile' => $mobile));
  166. if(!empty($user)) {
  167. itoast('手机号被占用', '', '');
  168. }
  169. $email = trim($_GPC['email']);
  170. if(!empty($email)) {
  171. $user = pdo_get('mc_members', array('uniacid' => $_W['uniacid'], 'email' => $email));
  172. if(!empty($user)) {
  173. itoast('邮箱被占用', '', '');
  174. }
  175. }
  176. $salt = random(8);
  177. $data = array(
  178. 'uniacid' => $_W['uniacid'],
  179. 'realname' => $realname,
  180. 'mobile' => $mobile,
  181. 'email' => $email,
  182. 'salt' => $salt,
  183. 'password' => md5(trim($_GPC['password']) . $salt . $_W['config']['setting']['authkey']),
  184. 'credit1' => intval($_GPC['credit1']),
  185. 'credit2' => intval($_GPC['credit2']),
  186. 'groupid' => intval($_GPC['groupid']),
  187. 'createtime' => TIMESTAMP,
  188. );
  189. pdo_insert('mc_members', $data);
  190. $uid = pdo_insertid();
  191. itoast('添加会员成功,将进入编辑页面', url('mc/member/post', array('uid' => $uid)), 'success');
  192. }
  193. template('mc/member-add');
  194. }
  195. if($do == 'group') {
  196. if($_W['isajax']) {
  197. $id = intval($_GPC['id']);
  198. $group = $_W['account']['groups'][$id];
  199. if(empty($group)) {
  200. exit('会员组信息不存在');
  201. }
  202. $uid = intval($_GPC['uid']);
  203. $member = mc_fetch($uid);
  204. if(empty($member)) {
  205. exit('会员信息不存在');
  206. }
  207. $credit = intval($group['credit']);
  208. $credit6 = $credit - $member['credit1'];
  209. $status_update_groupid = mc_update($uid, array('groupid' => $id));
  210. $status_update_credit6 = mc_credit_update($uid, 'credit6', $credit6);
  211. if($status_update_groupid && !is_error($status_update_credit6)) {
  212. $openid = pdo_fetchcolumn('SELECT openid FROM ' . tablename('mc_mapping_fans') . ' WHERE acid = :acid AND uid = :uid', array(':acid' => $_W['acid'], ':uid' => $uid));
  213. if(!empty($openid)) {
  214. mc_notice_group($openid, $_W['account']['groups'][$member['groupid']]['title'], $_W['account']['groups'][$id]['title']);
  215. }
  216. exit('success');
  217. } else {
  218. exit('更新会员信息出错');
  219. }
  220. }
  221. exit('error');
  222. }
  223. if ($do == 'credit_statistics') {
  224. $_W['page']['title'] = '积分日志-会员管理';
  225. $uid = intval($_GPC['uid']);
  226. $credits = array(
  227. 'credit1' => '积分',
  228. 'credit2' => '余额'
  229. );
  230. $type = intval($_GPC['type']);
  231. $starttime = strtotime('-7 day');
  232. $endtime = strtotime('7 day');
  233. if($type == 1) {
  234. $starttime = strtotime(date('Y-m-d'));
  235. $endtime = TIMESTAMP;
  236. } elseif($type == -1) {
  237. $starttime = strtotime('-1 day');
  238. $endtime = strtotime(date('Y-m-d'));
  239. } else{
  240. $starttime = strtotime($_GPC['datelimit']['start']);
  241. $endtime = strtotime($_GPC['datelimit']['end']) + 86399;
  242. }
  243. if(!empty($credits)) {
  244. $data = array();
  245. foreach($credits as $key => $li) {
  246. $data[$key]['add'] = round(pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('mc_credits_record') . ' WHERE uniacid = :id AND uid = :uid AND createtime > :start AND createtime < :end AND credittype = :type AND num > 0', array(':id' => $_W['uniacid'], ':uid' => $uid, ':start' => $starttime, ':end' => $endtime, ':type' => $key)),2);
  247. $data[$key]['del'] = abs(round(pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('mc_credits_record') . ' WHERE uniacid = :id AND uid = :uid AND createtime > :start AND createtime < :end AND credittype = :type AND num < 0', array(':id' => $_W['uniacid'], ':uid' => $uid, ':start' => $starttime, ':end' => $endtime, ':type' => $key)),2));
  248. $data[$key]['end'] = $data[$key]['add'] - $data[$key]['del'];
  249. }
  250. }
  251. template('mc/member-information');
  252. }
  253. if($do == 'member_credits') {
  254. $_W['page']['title'] = '编辑会员资料 - 会员 - 会员中心';
  255. $uid = intval($_GPC['uid']);
  256. $credits = mc_credit_fetch($uid, array('credit1', 'credit2'));
  257. $type = trim($_GPC['type']) ? trim($_GPC['type']) : 'credit1';
  258. $pindex = max(1, intval($_GPC['page']));
  259. $psize = 50;
  260. $member_table = table('member');
  261. $member_table->searchCreditsRecordUid($uid);
  262. $member_table->searchCreditsRecordType($type);
  263. $member_table->searchWithPage($pindex, $psize);
  264. $records = $member_table->creditsRecordList();
  265. $total = $member_table->getLastQueryTotal();
  266. $pager = pagination($total, $pindex, $psize);
  267. template('mc/member-information');
  268. }
  269. if ($do == 'base_information') {
  270. $uid = intval($_GPC['uid']);
  271. $profile = mc_fetch($uid);
  272. $profile = mc_parse_profile($profile);
  273. $member_table = table('member');
  274. $uniacid_fields = $member_table->mcFieldsList($_W['uniacid']);
  275. $all_fields = mc_fields();
  276. $custom_fields = array();
  277. $base_fields = cache_load('userbasefields');
  278. $base_fields = array_keys($base_fields);
  279. foreach ($all_fields as $field => $title) {
  280. if (!in_array($field, $base_fields)) {
  281. $custom_fields[] = $field;
  282. }
  283. }
  284. $groups = mc_groups($_W['uniacid']);
  285. $addresses = pdo_getall('mc_member_address', array('uid' => $uid, 'uniacid' => $_W['uniacid']));
  286. if ($_W['ispost'] && $_W['isajax']) {
  287. if(!empty($_GPC['type'])) {
  288. $type = trim($_GPC['type']);
  289. }else {
  290. iajax(-1, '参数错误!', '');
  291. }
  292. switch ($type) {
  293. case 'avatar':
  294. $data = array('avatar' => $_GPC['imgsrc']);
  295. break;
  296. case 'groupid':
  297. case 'gender':
  298. case 'education':
  299. case 'constellation':
  300. case 'zodiac':
  301. case 'bloodtype':
  302. $data = array($type => $_GPC['request_data']);
  303. break;
  304. case 'nickname':
  305. case 'realname':
  306. case 'address':
  307. case 'qq':
  308. case 'mobile':
  309. case 'email':
  310. case 'telephone':
  311. case 'msn':
  312. case 'taobao':
  313. case 'alipay':
  314. case 'graduateschool':
  315. case 'grade':
  316. case 'studentid':
  317. case 'revenue':
  318. case 'position':
  319. case 'occupation':
  320. case 'company':
  321. case 'nationality':
  322. case 'height':
  323. case 'weight':
  324. case 'idcard':
  325. case 'zipcode':
  326. case 'site':
  327. case 'affectivestatus':
  328. case 'lookingfor':
  329. case 'bio':
  330. case 'interest':
  331. $data = array($type => trim($_GPC['request_data']));
  332. break;
  333. case 'births':
  334. $data = array(
  335. 'birthyear' => $_GPC['birthyear'],
  336. 'birthmonth' => $_GPC['birthmonth'],
  337. 'birthday' => $_GPC['birthday']
  338. );
  339. break;
  340. case 'resides':
  341. $data = array(
  342. 'resideprovince' => $_GPC['resideprovince'],
  343. 'residecity' => $_GPC['residecity'],
  344. 'residedist' => $_GPC['residedist']
  345. );
  346. break;
  347. case 'password':
  348. $password = trim($_GPC['password']);
  349. $sql = 'SELECT `uid`, `salt` FROM ' . tablename('mc_members') . " WHERE `uniacid`=:uniacid AND `uid` = :uid";
  350. $user = pdo_fetch($sql, array(':uniacid' => $_W['uniacid'], ':uid' => $uid));
  351. $data = array();
  352. if(!empty($user) && $user['uid'] == $uid) {
  353. if (empty($user['salt'])) {
  354. $user['salt'] = $salt = random(8);
  355. pdo_update('mc_members', array('salt' => $salt), array('uid' => $uid, 'uniacid' => $_W['uniacid']));
  356. }
  357. $password = md5($password . $user['salt'] . $_W['config']['setting']['authkey']);
  358. $data = array('password' => $password);
  359. }
  360. break;
  361. default:
  362. $data = array($type => trim($_GPC['request_data']));
  363. break;
  364. }
  365. $result = mc_update($uid, $data);
  366. if($result) {
  367. iajax(0, '修改成功!', '');
  368. }else {
  369. iajax(1, '修改失败!', '');
  370. }
  371. }
  372. template('mc/member-information');
  373. };
  374. if ($do == 'address') {
  375. $uid = intval($_GPC['uid']);
  376. if ($_W['ispost'] && $_W['isajax']) {
  377. if ($_GPC['op'] == 'addaddress' || $_GPC['op'] == 'editaddress') {
  378. $post = array(
  379. 'uniacid' => $_W['uniacid'],
  380. 'province' => trim($_GPC['province']),
  381. 'city' => trim($_GPC['city']),
  382. 'district' => trim($_GPC['district']),
  383. 'address' => trim($_GPC['detail']),
  384. 'uid' => intval($_GPC['uid']),
  385. 'username' => trim($_GPC['name']),
  386. 'mobile' => trim($_GPC['phone']),
  387. 'zipcode' => trim($_GPC['code'])
  388. );
  389. if ($_GPC['op'] == 'addaddress') {
  390. $exist_address = pdo_getcolumn('mc_member_address', array('uniacid' => $post['uniacid'], 'uid' => $uid), 'COUNT(*)');
  391. if (!$exist_address) {
  392. $post['isdefault'] = 1;
  393. }
  394. if(pdo_insert('mc_member_address', $post)){
  395. $post['id'] = pdo_insertid();
  396. iajax(0, $post, '');
  397. } else {
  398. iajax(1, "收货地址添加失败", '');
  399. };
  400. } else {
  401. $post['id'] = intval($_GPC['id']);
  402. $result = pdo_update('mc_member_address', $post, array('id' => intval($_GPC['id']), 'uniacid' => $_W['uniacid']));
  403. if($result){
  404. iajax(0, $post, '');
  405. } else {
  406. iajax(1, "收货地址修改失败", '');
  407. };
  408. }
  409. }
  410. if ($_GPC['op'] == 'deladdress') {
  411. $id = intval($_GPC['id']);
  412. if (pdo_delete('mc_member_address', array('id' => $id, 'uniacid' => $_W['uniacid']))) {
  413. iajax(0, '删除成功', '');
  414. }else{
  415. iajax(1, '删除失败', '');
  416. }
  417. }
  418. if ($_GPC['op'] == 'isdefault') {
  419. $id = intval($_GPC['id']);
  420. $uid = intval($_GPC['uid']);
  421. pdo_update('mc_member_address', array('isdefault' => 0), array('uid' => $uid, 'uniacid' => $_W['uniacid']));
  422. pdo_update('mc_member_address', array('isdefault' => 1), array('id' => $id, 'uniacid' => $_W['uniacid']));
  423. iajax(0, '设置成功', '');
  424. }
  425. }
  426. }