人人商城

member.ctrl.php 16KB

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