qiuqiubond.ctrl.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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('app');
  8. $dos = array('display', 'credits', 'address', 'card', 'mycard', 'record', 'mobile', 'email', 'barcode', 'qrcode', 'consume', 'card_qrcode', 'addressadd');
  9. $do = in_array($do, $dos) ? $do : 'display';
  10. load()->func('tpl');
  11. load()->model('user');
  12. if ($do == 'credits') {
  13. $where = '';
  14. $params = array(':uid' => $_W['member']['uid']);
  15. $pindex = max(1, intval($_GPC['page']));
  16. $psize = 15;
  17. if (empty($starttime) || empty($endtime)) {
  18. $starttime = strtotime('-1 month');
  19. $endtime = time();
  20. }
  21. if ($_GPC['time']) {
  22. $starttime = strtotime($_GPC['time']['start']);
  23. $endtime = strtotime($_GPC['time']['end']) + 86399;
  24. $where = ' AND `createtime` >= :starttime AND `createtime` < :endtime';
  25. $params[':starttime'] = $starttime;
  26. $params[':endtime'] = $endtime;
  27. }
  28. $sql = 'SELECT `realname`, `avatar` FROM ' . tablename('mc_members') . " WHERE `uid` = :uid";
  29. $user = pdo_fetch($sql, array(':uid' => $_W['member']['uid']));
  30. if ($_GPC['credittype']) {
  31. if ($_GPC['type'] == 'order') {
  32. $sql = 'SELECT * FROM ' . tablename('mc_credits_recharge') . " WHERE `uid` = :uid $where LIMIT " . ($pindex - 1) * $psize. ',' . $psize;
  33. $orders = pdo_fetchall($sql, $params);
  34. foreach ($orders as &$value) {
  35. $value['createtime'] = date('Y-m-d', $value['createtime']);
  36. $value['fee'] = number_format($value['fee'], 2);
  37. if ($value['status'] == 1) {
  38. $orderspay += $value['fee'];
  39. }
  40. unset($value);
  41. }
  42. $ordersql = 'SELECT COUNT(*) FROM ' .tablename('mc_credits_recharge') . "WHERE `uid` = :uid {$where}";
  43. $total = pdo_fetchcolumn($ordersql, $params);
  44. $orderpager = pagination($total, $pindex, $psize, '', array('before' => 0, 'after' => 0, 'ajaxcallback' => ''));
  45. template('mc/bond');
  46. exit();
  47. }
  48. $where .= " AND `credittype` = '{$_GPC['credittype']}'";
  49. }
  50. $sql = 'SELECT `num` FROM ' . tablename('mc_credits_record') . " WHERE `uid` = :uid $where";
  51. $nums = pdo_fetchall($sql, $params);
  52. $pay = $income = 0;
  53. foreach ($nums as $value) {
  54. if ($value['num'] > 0) {
  55. $income += $value['num'];
  56. } else {
  57. $pay += abs($value['num']);
  58. }
  59. }
  60. $pay = number_format($pay, 2);
  61. $income = number_format($income, 2);
  62. $sql = 'SELECT * FROM ' . tablename('mc_credits_record') . " WHERE `uid` = :uid {$where} ORDER BY `createtime` DESC LIMIT " . ($pindex - 1) * $psize.','. $psize;
  63. $data = pdo_fetchall($sql, $params);
  64. foreach ($data as $key=>$value) {
  65. $data[$key]['credittype'] = $creditnames[$data[$key]['credittype']]['title'];
  66. $data[$key]['createtime'] = date('Y-m-d H:i', $data[$key]['createtime']);
  67. $data[$key]['num'] = number_format($value['num'], 2);
  68. }
  69. $pagesql = 'SELECT COUNT(*) FROM ' .tablename('mc_credits_record') . "WHERE `uid` = :uid {$where}";
  70. $total = pdo_fetchcolumn($pagesql, $params);
  71. $pager = pagination($total, $pindex, $psize, '', array('before' => 0, 'after' => 0, 'ajaxcallback' => ''));
  72. }
  73. if ($do == 'address') {
  74. if ($_GPC['op'] == 'default') {
  75. pdo_update('mc_member_address', array('isdefault' => 0), array('uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid']));
  76. pdo_update('mc_member_address', array('isdefault' => 1), array('id' => $_GPC['id']));
  77. pdo_update('mc_members', array('address' => $_GPC['address']), array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  78. }
  79. if ($_GPC['op'] == 'delete') {
  80. pdo_delete('mc_member_address', array('id' => $_GPC['id']));
  81. }
  82. $where = ' WHERE 1';
  83. $params = array(':uniacid' => $_W['uniacid'], ':uid' => $_W['member']['uid']);
  84. if (!empty($_GPC['addid'])) {
  85. $where .= ' AND `id` = :id';
  86. $params[':id'] = intval($_GPC['addid']);
  87. }
  88. $where .= ' AND `uniacid` = :uniacid AND `uid` = :uid';
  89. $sql = 'SELECT * FROM ' . tablename('mc_member_address') . $where;
  90. if (empty($params[':id'])) {
  91. $psize = 10;
  92. $pindex = max(1, intval($_GPC['page']));
  93. $sql .= ' LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
  94. $addresses = pdo_fetchall($sql, $params);
  95. $sql = 'SELECT COUNT(*) FROM ' . tablename('mc_member_address') . $where;
  96. $total = pdo_fetchcolumn($sql, $params);
  97. $pager = pagination($total, $pindex, $psize);
  98. } else {
  99. $address = pdo_fetch($sql, $params);
  100. }
  101. }
  102. /*添加或编辑地址*/
  103. if ($do == 'addressadd') {
  104. if ($_W['ispost']) {
  105. $address = $_GPC['address'];
  106. if (empty($address['username'])) {
  107. message('请输入您的姓名', referer(), 'error');
  108. }
  109. if (empty($address['mobile'])) {
  110. message('请输入您的手机号', referer(), 'error');
  111. }
  112. if (empty($address['zipcode'])) {
  113. message('请输入您的邮政编码', referer(), 'error');
  114. }
  115. if (empty($address['province'])) {
  116. message('请输入您的所在省', referer(), 'error');
  117. }
  118. if (empty($address['city'])) {
  119. message('请输入您的所在市', referer(), 'error');
  120. }
  121. if (empty($address['district'])) {
  122. message('请输入您的所在区', referer(), 'error');
  123. }
  124. if (empty($address['address'])) {
  125. message('请输入您的详细地址', referer(), 'error');
  126. }
  127. $address['uniacid'] = $_W['uniacid'];
  128. $address['uid'] = $_W['member']['uid'];
  129. $address_data = pdo_get('mc_member_address', array('uniacid' => $_W['uniacid'], 'uid' => $address['uid']));
  130. if (empty($address_data)) {
  131. $address['isdefault'] = 1;
  132. }
  133. if (!empty($_GPC['addid'])) {
  134. if (pdo_update('mc_member_address', $address, array('id' => intval($_GPC['addid']), 'uid' => $address['uid']))) {
  135. message('修改收货地址成功', url('mc/bond/address'), 'success');
  136. } else {
  137. message('修改收货地址失败,请稍后重试', url('mc/bond/address'), 'error');
  138. }
  139. }
  140. if (pdo_insert('mc_member_address', $address)) {
  141. $adres = pdo_get('mc_member_address', array('uniacid' => $_W['uniacid'], 'uid' => $address['uid'], 'isdefault'=> 1));
  142. if (!empty($adres)) {
  143. $adres['address'] = $adres['province'].$adres['city'].$adres['district'].$adres['address'];
  144. pdo_update('mc_members', array('address' => $adres['address']), array('uid' => $address['uid']));
  145. }
  146. message('地址添加成功', url('mc/bond/address'), 'success');
  147. }
  148. }
  149. if (!empty($_GPC['addid'])) {
  150. $address = pdo_get('mc_member_address', array('id' => $_GPC['addid'], 'uniacid' => $_W['uniacid']));
  151. }
  152. }
  153. if ($do == 'card') {
  154. $mcard = pdo_fetch('SELECT * FROM ' . tablename('mc_card_members') . ' WHERE uniacid = :uniacid AND uid = :uid', array(':uniacid' => $_W['uniacid'], ':uid' => $_W['member']['uid']));
  155. if(!empty($mcard)) {
  156. header('Location:' . url('mc/bond/mycard'));
  157. }
  158. $sql = 'SELECT * FROM ' . tablename('mc_card') . "WHERE `uniacid` = :uniacid AND `status` = '1'";
  159. $setting = pdo_fetch($sql, array(':uniacid' => $_W['uniacid']));
  160. if (!empty($setting)) {
  161. $setting['color'] = iunserializer($setting['color']);
  162. $setting['background'] = iunserializer($setting['background']);
  163. $setting['fields'] = iunserializer($setting['fields']);
  164. $setting['grant'] = iunserializer($setting['grant']);
  165. if(is_array($setting['grant'])) {
  166. $coupon_id = intval($setting['grant']['coupon']);
  167. if($coupon_id > 0) {
  168. $coupon = pdo_fetch('SELECT couponid,title,type FROM ' . tablename('activity_coupon') . ' WHERE uniacid = :uniacid AND couponid = :couponid', array(':uniacid' => $_W['uniacid'], ':couponid' => $coupon_id));
  169. }
  170. }
  171. } else {
  172. message('公众号尚未开启会员卡功能', url('mc'), 'error');
  173. }
  174. if(!empty($setting['fields'])) {
  175. $fields = array('email');
  176. foreach($setting['fields'] as $li) {
  177. if($li['bind'] == 'birth') {
  178. $fields[] = 'birthyear';
  179. $fields[] = 'birthmonth';
  180. $fields[] = 'birthday';
  181. } elseif($li['bind'] == 'reside') {
  182. $fields[] = 'resideprovince';
  183. $fields[] = 'residecity';
  184. $fields[] = 'residedist';
  185. } else {
  186. $fields[] = $li['bind'];
  187. }
  188. }
  189. $member_info = mc_fetch($_W['member']['uid'], $fields);
  190. $reregister = 0;
  191. if(strlen($member_info['email']) == 39 && strexists($member_info['email'], '@we7.cc')) {
  192. $member_info['email'] = '';
  193. $reregister = 1;
  194. }
  195. }
  196. if (checksubmit('submit')) {
  197. $data = array();
  198. $realname = trim($_GPC['realname']);
  199. if(empty($realname)) {
  200. message('请输入姓名', referer(), 'info');
  201. }
  202. $data['realname'] = $realname;
  203. $mobile = trim($_GPC['mobile']);
  204. if(!preg_match(REGULAR_MOBILE, $mobile)) {
  205. message('手机号有误,请重新输入', referer(), 'info');
  206. }
  207. $data['mobile'] = $mobile;
  208. if (!empty($setting['fields'])) {
  209. foreach ($setting['fields'] as $row) {
  210. if($row['bind'] == 'mobile' && !preg_match(REGULAR_MOBILE, $_GPC['mobile'])) {
  211. message('手机号有误,请重新输入', referer(), 'info');
  212. } if (!empty($row['require']) && ($row['bind'] == 'birth' || $row['bind'] == 'birthyear')) {
  213. if (empty($_GPC['birth']['year']) || empty($_GPC['birth']['month']) || empty($_GPC['birth']['day'])) {
  214. message('请输入完整的出生日期!', referer(), 'info');
  215. }
  216. $row['bind'] = 'birth';
  217. } elseif (!empty($row['require']) && $row['bind'] == 'resideprovince') {
  218. if (empty($_GPC['reside']['province']) || empty($_GPC['reside']['city']) || empty($_GPC['reside']['district'])) {
  219. message('请输入完整的居住地!', referer(), 'info');
  220. }
  221. $row['bind'] = 'reside';
  222. } elseif (!empty($row['require']) && empty($_GPC[$row['bind']])) {
  223. message('请输入'.$row['title'].'!', referer(), 'info');
  224. }
  225. $data[$row['bind']] = $_GPC[$row['bind']];
  226. }
  227. }
  228. $check = mc_check($data);
  229. if(is_error($check)) {
  230. message($check['message'], referer(), 'error');
  231. }
  232. $sql = 'SELECT COUNT(*) FROM ' . tablename('mc_card_members') . " WHERE `uid` = :uid AND `cid` = :cid AND uniacid = :uniacid";
  233. $count = pdo_fetchcolumn($sql, array(':uid' => $_W['member']['uid'], ':cid' => $_GPC['cardid'], ':uniacid' => $_W['uniacid']));
  234. if ($count >= 1) {
  235. message('抱歉,您已经领取过该会员卡.', referer(), 'error');
  236. }
  237. $record = array(
  238. 'uniacid' => $_W['uniacid'],
  239. 'openid' => $_W['openid'],
  240. 'uid' => $_W['member']['uid'],
  241. 'cid' => $_GPC['cardid'],
  242. 'cardsn' => $data['mobile'],
  243. 'status' => '1',
  244. 'createtime' => TIMESTAMP,
  245. 'endtime' => TIMESTAMP
  246. );
  247. if(pdo_insert('mc_card_members', $record)) {
  248. if(!empty($data)){
  249. mc_update($_W['member']['uid'], $data);
  250. }
  251. $notice = '';
  252. if(is_array($setting['grant'])) {
  253. if($setting['grant']['credit1'] > 0) {
  254. $log = array(
  255. $_W['member']['uid'],
  256. "领取会员卡,赠送{$setting['grant']['credit1']}积分"
  257. );
  258. mc_credit_update($_W['member']['uid'], 'credit1', $setting['grant']['credit1'], $log);
  259. $notice .= "赠送【{$setting['grant']['credit1']}】积分";
  260. }
  261. if($setting['grant']['credit2'] > 0) {
  262. $log = array(
  263. $_W['member']['uid'],
  264. "领取会员卡,赠送{$setting['credit2']['credit1']}余额"
  265. );
  266. mc_credit_update($_W['member']['uid'], 'credit2', $setting['grant']['credit2'], $log);
  267. $notice .= ",赠送【{$setting['grant']['credit2']}】余额";
  268. }
  269. if($setting['grant']['coupon'] > 0 && !empty($coupon)) {
  270. if($coupon['type'] == 1) {
  271. $status = activity_coupon_grant($_W['member']['uid'], $coupon['couponid'], 'card', '领取会员卡,赠送优惠券');
  272. } else {
  273. $status = activity_token_grant($_W['member']['uid'], $coupon['couponid'], 'card', '领取会员卡,赠送优惠券');
  274. }
  275. if(!is_error($status)) {
  276. $notice .= ",赠送【{$coupon['title']}】优惠券";
  277. }
  278. }
  279. }
  280. $time = date('Y-m-d H:i');
  281. $url = murl('mc/bond/mycard/', array(), true, true);
  282. $title = "【{$_W['account']['name']}】- 领取会员卡通知\n";
  283. $info = "您在{$time}成功领取会员卡,{$notice}。\n\n";
  284. $info .= "<a href='{$url}'>点击查看详情</a>";
  285. $status = mc_notice_custom_text($_W['openid'], $title, $info);
  286. message("领取会员卡成功<br>{$notice}", url('mc/bond/mycard'), 'success');
  287. } else {
  288. message('领取会员卡失败.', referer(), 'error');
  289. }
  290. }
  291. }
  292. if ($do == 'mycard') {
  293. $mcard = pdo_fetch('SELECT * FROM ' . tablename('mc_card_members') . ' WHERE uniacid = :uniacid AND uid = :uid', array(':uniacid' => $_W['uniacid'], ':uid' => $_W['member']['uid']));
  294. if(empty($mcard)) {
  295. header('Location:' . url('mc/bond/card'));
  296. }
  297. if(empty($mcard['openid']) && !empty($_W['openid'])) {
  298. pdo_update('mc_card_members', array('openid' => $_W['openid']), array('uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid']));
  299. }
  300. if (!empty($mcard['status'])) {
  301. $setting = pdo_fetch('SELECT * FROM ' . tablename('mc_card') . ' WHERE uniacid = :uniacid', array(':uniacid' => $_W['uniacid']));
  302. if(!empty($setting)) {
  303. $setting['color'] = iunserializer($setting['color']);
  304. $setting['background'] = iunserializer($setting['background']);;
  305. }
  306. }
  307. load()->model('card');
  308. $notice_count = card_notice_stat();
  309. }
  310. if($do == 'consume') {
  311. load()->model('card');
  312. $setting = card_setting();
  313. $stores = pdo_fetchall('SELECT id,business_name FROM ' . tablename('activity_stores') . ' WHERE uniacid = :uniacid', array(':uniacid' => $_W['uniacid']), 'id');
  314. $card_params = json_decode($setting['params'], true);
  315. if (!empty($card_params)) {
  316. foreach ($card_params as $key => $value) {
  317. if ($value['id'] == 'cardActivity') {
  318. $grant_rate = $value['params']['grant_rate'];
  319. }
  320. }
  321. }
  322. $setting['grant_rate'] = $grant_rate;
  323. if(checksubmit()) {
  324. $credit = floatval($_GPC['credit']);
  325. $discount_credit = $credit;
  326. $store_id = intval($_GPC['store_id']);
  327. $store_str = (!$store_id || empty($stores[$store_id])) ? '未知' : $stores[$store_id]['business_name'];
  328. if(!$credit) {
  329. message('请输入消费金额', referer(), 'error');
  330. }
  331. if($setting['discount_type'] > 0 && !empty($setting['discount'])) {
  332. $discount = $setting['discount'][$_W['member']['groupid']];
  333. if(!empty($discount['discount']) && $credit >= $discount['condition']) {
  334. if($setting['discount_type'] == 1) {
  335. $discount_credit = $credit - $discount['discount'];
  336. $discount_str = ",该会员属于【{$_W['member']['groupname']}】,可享受【满{$discount['condition']}元减{$discount['discount']}元】,最终支付【{$discount_credit}】元";
  337. } else {
  338. $rate = $discount['discount'] * 10;
  339. $discount_credit = $credit * $discount['discount'];
  340. $discount_str = ",该会员属于【{$_W['member']['groupname']}】,可享受【满{$discount['condition']}元打{$rate}折】,最终支付【{$discount_credit}】元";
  341. }
  342. if($discount_credit < 0) {
  343. $discount_credit = 0;
  344. }
  345. }
  346. }
  347. if($_W['member']['credit2'] < $discount_credit) {
  348. message('余额不足', referer(), 'error');
  349. }
  350. if($setting['grant_rate'] > 0) {
  351. $credit1 = $discount_credit * $setting['grant_rate'];
  352. $log_credit1 = array(
  353. $_W['member']['uid'],
  354. "使用会员卡消费【{$discount_credit}】元,消费返积分比率:【1:{$setting['grant_rate']}】,共赠送积分{$credit1}"
  355. );
  356. mc_credit_update($_W['member']['uid'], 'credit1', $credit1, $log_credit1);
  357. $discount_str .= ",消费返积分比率:【1:{$setting['grant_rate']}】,共赠送积分{$credit1}";
  358. }
  359. $log_credit2 = array(
  360. $_W['member']['uid'],
  361. "使用会员卡消费【{$credit}】元 {$discount_str},消费门店:{$store_str}",
  362. 'card',
  363. 0,
  364. $store_id
  365. );
  366. mc_credit_update($_W['member']['uid'], 'credit2', -$discount_credit, $log_credit2);
  367. mc_notice_credit2($_W['openid'], $_W['member']['uid'], -$discount_credit, $credit1, $store_str);
  368. message("消费成功,共扣除余额{$discount_credit}元,赠送{$credit1}积分", url('mc/bond/mycard'), 'success');
  369. }
  370. if($setting['discount_type'] != 0 && !empty($setting['discount'])) {
  371. $discount = $setting['discount'];
  372. if(!empty($discount[$_W['member']['groupid']])) {
  373. $tips = "您当前会员组 {$_W['member']['groupname']} ,可享受满 {$discount[$_W['member']['groupid']]['condition']}元";
  374. if($setting['discount_type'] == 2) {
  375. $rate = $discount[$_W['member']['groupid']]['discount'] * 10;
  376. $tips .= "打{$rate}折";
  377. } else {
  378. $tips .= "减{$discount[$_W['member']['groupid']]['discount']}元";
  379. }
  380. $mine_discount = $discount[$_W['member']['groupid']];
  381. }
  382. }
  383. $url = $_W['siteroot'] . 'app' . ltrim(murl('clerk/card', array('uid' => $_W['member']['uid'])), '.');
  384. template('mc/consume');
  385. exit();
  386. }
  387. if($do == 'card_qrcode') {
  388. require_once('../framework/library/qrcode/phpqrcode.php');
  389. $errorCorrectionLevel = "L";
  390. $matrixPointSize = "8";
  391. $url = $_W['siteroot'] . 'app' . ltrim(murl('clerk/card', array('uid' => $_W['member']['uid'])), '.');
  392. QRcode::png($url, false, $errorCorrectionLevel, $matrixPointSize);
  393. exit();
  394. }
  395. if ($do == 'barcode') {
  396. $cardsn = $_W['member']['uid'];
  397. $barcode_path = '../framework/library/barcode/';
  398. require_once($barcode_path . 'class/BCGFontFile.php');
  399. require_once($barcode_path . 'class/BCGColor.php');
  400. require_once($barcode_path . 'class/BCGDrawing.php');
  401. require_once($barcode_path . 'class/BCGcode39.barcode.php');
  402. $color_black = new BCGColor(0, 0, 0);
  403. $color_white = new BCGColor(255, 255, 255);
  404. $drawException = null;
  405. try {
  406. $code = new BCGcode39();
  407. $code->setScale(2);
  408. $code->setThickness(30);
  409. $code->setForegroundColor($color_black);
  410. $code->setBackgroundColor($color_white);
  411. $code->setFont($font);
  412. $code->parse($cardsn);
  413. } catch(Exception $exception) {
  414. $drawException = $exception;
  415. }
  416. $drawing = new BCGDrawing('', $color_white);
  417. if($drawException) {
  418. $drawing->drawException($drawException);
  419. } else {
  420. $drawing->setBarcode($code);
  421. $drawing->draw();
  422. }
  423. header('Content-Type: image/png');
  424. header('Content-Disposition: inline; filename="barcode.png"');
  425. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
  426. }
  427. if ($do == 'qrcode') {
  428. require_once('../framework/library/qrcode/phpqrcode.php');
  429. $errorCorrectionLevel = "L";
  430. $matrixPointSize = "8";
  431. $cardsn = $_W['member']['uid'];
  432. QRcode::png($cardsn, false, $errorCorrectionLevel, $matrixPointSize);
  433. }
  434. if($do == 'record') {
  435. $setting = pdo_get('mc_card', array('uniacid' => $_W['uniacid']), array('nums_text', 'times_text'));
  436. $card = pdo_get('mc_card_members', array('uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid']));
  437. $type = trim($_GPC['type']);
  438. $where = ' WHERE uniacid = :uniacid AND uid = :uid AND type = :type';
  439. $params = array(
  440. ':uniacid' => $_W['uniacid'],
  441. ':uid' => $_W['member']['uid'],
  442. ':type' => $type,
  443. );
  444. $pindex = max(1, intval($_GPC['page']));
  445. $psize = 20;
  446. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_card_record') . $where, $params);
  447. $limit = ' ORDER BY id DESC LIMIT ' . ($pindex - 1) * $psize . ', ' . $psize;
  448. $data = pdo_fetchall('SELECT * FROM ' . tablename('mc_card_record') . $where . $limit, $params);
  449. $pager = pagination($total, $pindex, $psize, '', array('before' => 0, 'after' => 0, 'ajaxcallback' => ''));
  450. }
  451. if($do == 'mobile') {
  452. $profile = mc_fetch($_W['member']['uid'], array('mobile'));
  453. $mobile_exist = empty($profile['mobile']) ? 0 : 1;
  454. if(checksubmit('submit')) {
  455. if($mobile_exist == 1) {
  456. $oldmobile = trim($_GPC['oldmobile']) ? trim($_GPC['oldmobile']) : message('请填写原手机号');
  457. $password = trim($_GPC['password']) ? trim($_GPC['password']) : message('请填写密码');
  458. $mobile = trim($_GPC['mobile']) ? trim($_GPC['mobile']) : message('请填写新手机号');
  459. if(!preg_match(REGULAR_MOBILE, $mobile)) {
  460. message('新手机号格式有误', '', 'error');
  461. }
  462. $info = pdo_fetch('SELECT uid, password, salt FROM ' . tablename('mc_members') . ' WHERE uniacid = :uniacid AND mobile = :mobile AND uid = :uid', array(':uniacid' => $_W['uniacid'], ':mobile' => $oldmobile, ':uid' => $_W['member']['uid']));
  463. if(!empty($info)) {
  464. if($info['password'] == md5($password . $info['salt'] . $_W['config']['setting']['authkey'])) {
  465. pdo_update('mc_members', array('mobile' => $mobile), array('uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid']));
  466. message('修改手机号成功', url('mc/home'), 'success');
  467. } else {
  468. message('密码输入错误', '', 'error');
  469. }
  470. } else {
  471. message('原手机号输入错误', '', 'error');
  472. }
  473. } else {
  474. $mobile = trim($_GPC['mobile']) ? trim($_GPC['mobile']) : message('请填写手机号');
  475. if(!preg_match(REGULAR_MOBILE, $mobile)) {
  476. message('手机号格式有误', '', 'error');
  477. }
  478. $password = trim($_GPC['password']);
  479. if(empty($password) || strlen($password) < 6) {
  480. message('密码不能少于6位');
  481. }
  482. $repassword = trim($_GPC['repassword']);
  483. if($password != $repassword) {
  484. message('两次输入密码不一致');
  485. }
  486. $is_exist = pdo_fetch('SELECT uid FROM ' . tablename('mc_members') . ' WHERE uniacid = :uniacid AND mobile = :mobile AND uid != :uid', array(':uniacid' => $_W['uniacid'], ':mobile' => $mobile, ':uid' => $_W['member']['uid']));
  487. if(!empty($is_exist)) {
  488. message('该手机号已被绑定,换个手机号试试', '', 'error');
  489. }
  490. $salt = random(8);
  491. $password = md5($password . $salt . $_W['config']['setting']['authkey']);
  492. pdo_update('mc_members', array('mobile' => $mobile, 'salt' => $salt, 'password' => $password), array('uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid']));
  493. message('修改手机号成功', url('mc/home'), 'success');
  494. }
  495. }
  496. }
  497. if($do == 'email') {
  498. $username_type = empty($setting['passport']['item']) ? 'random' : $setting['passport']['item'];
  499. $profile = mc_fetch($_W['member']['uid'], array('uid', 'email', 'salt'));
  500. $reregister = false;
  501. if ($_W['member']['email'] == md5($_W['openid']).'@we7.cc') {
  502. $reregister = true;
  503. }
  504. if(checksubmit('submit')) {
  505. $type = intval($_GPC['type']);
  506. $data = array();
  507. if ($type == 1) {
  508. if ($reregister) {
  509. if (!empty($_GPC['email'])) {
  510. $username = trim($_GPC['email']);
  511. if (($username_type == 'email' || $username_type == 'random') && preg_match(REGULAR_EMAIL, $username)) {
  512. $data['email'] = $username;
  513. $emailexists = pdo_fetch("SELECT uid FROM ".tablename('mc_members')." WHERE email = :email AND uniacid = :uniacid AND uid != :uid ", array(':email' => $data['email'], ':uniacid' => $_W['uniacid'], ':uid' => $_W['member']['uid']));
  514. if (!empty($emailexists['uid'])) {
  515. message('抱歉,该E-Mail地址已经被注册,请更换。', '', 'error');
  516. }
  517. } elseif (($username_type == 'mobile' || $username_type == 'random') && preg_match(REGULAR_MOBILE, $username)) {
  518. $data['mobile'] = $username;
  519. $mobileexists = pdo_fetch("SELECT uid FROM ".tablename('mc_members')." WHERE mobile = :mobile AND uniacid = :uniacid AND uid != :uid ", array(':mobile' => $data['mobile'], ':uniacid' => $_W['uniacid'], ':uid' => $_W['member']['uid']));
  520. if (!empty($mobileexists['uid'])) {
  521. message('抱歉,该手机号已经被注册,请更换。', '', 'error');
  522. }
  523. //当用户已填写重要资料,把用户@we7.cc格式的邮箱重置为空,防止用户登陆反复提示重置资料
  524. $data['email'] = '';
  525. } else {
  526. if ($username_type == 'mobile') {
  527. message('手机号码格式有误', '', 'error');
  528. } elseif ($username_type == 'email') {
  529. message('E-Mail格式有误', '', 'error');
  530. } else {
  531. message('手机号码或E-Mail格式有误', '', 'error');
  532. }
  533. }
  534. }
  535. }
  536. if (empty($_GPC['password'])) {
  537. message('请输入您的密码', '', 'error');
  538. }
  539. $data['password'] = md5($_GPC['password'] . $profile['salt'] . $_W['config']['setting']['authkey']);
  540. pdo_update('mc_members', $data, array(
  541. 'uid' => $profile['uid']
  542. ));
  543. message('修改帐号密码成功!', url('mc/home'), 'success');
  544. } else {
  545. $data['username'] = $_GPC['username'];
  546. $data['password'] = $_GPC['oldpassword'];
  547. if (empty($data['username']) || empty($data['password'])) {
  548. message('抱歉,用户名或是密码没有填写。', '', 'error');
  549. }
  550. $pars_tmp[':uniacid'] = $_W['uniacid'];
  551. if(preg_match(REGULAR_MOBILE, $data['username'])) {
  552. $sql_tmp .= ' AND `mobile`=:mobile';
  553. $pars_tmp[':mobile'] = $data['username'];
  554. } else {
  555. $sql_tmp .= ' AND `email`=:email';
  556. $pars_tmp[':email'] = $data['username'];
  557. }
  558. $member = pdo_fetch("SELECT `uid`,`salt`,`password` FROM " . tablename('mc_members') . " WHERE `uniacid`=:uniacid " . $sql_tmp, $pars_tmp);
  559. if (empty($member)) {
  560. message('抱歉,用户不存或是已经被删除', '', 'error');
  561. }
  562. $hash = md5($data['password'] . $member['salt'] . $_W['config']['setting']['authkey']);
  563. if($member['password'] != $hash) {
  564. message('抱歉,您输入的密码有误', '', 'error');
  565. }
  566. pdo_update('mc_mapping_fans', array('uid' => $member['uid']), array(
  567. 'acid' => $_W['acid'],
  568. 'openid' => $_W['openid'],
  569. ));
  570. $member_old = mc_fetch($_W['member']['uid']);
  571. $member_new = mc_fetch($member['uid']);
  572. if(!empty($member_old) && !empty($member_new)) {
  573. $ignore = array('email', 'password', 'uid', 'uniacid', 'salt', 'credit1', 'credit2', 'credit3','credit4','credit5');
  574. $profile_update = array();
  575. foreach($member_old as $key => $value) {
  576. if(!in_array($key, $ignore)) {
  577. if(empty($member_new[$key]) && !empty($member_old[$key])) {
  578. $profile_update[$key] = $member_old[$key];
  579. }
  580. }
  581. }
  582. $profile_update['credit1'] = $member_old['credit1'] + $member_new['credit1'];
  583. $profile_update['credit2'] = $member_old['credit2'] + $member_new['credit2'];
  584. $profile_update['credit3'] = $member_old['credit3'] + $member_new['credit3'];
  585. $profile_update['credit4'] = $member_old['credit4'] + $member_new['credit4'];
  586. $profile_update['credit5'] = $member_old['credit5'] + $member_new['credit5'];
  587. pdo_update('mc_members', $profile_update, array('uid' => $member['uid'], 'uniacid' => $_W['uniacid']));
  588. pdo_delete('mc_members', array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  589. pdo_update('activity_coupon_record', array('uid' => $member['uid']), array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  590. pdo_update('activity_exchange_trades', array('uid' => $member['uid']), array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  591. pdo_update('activity_exchange_trades_shipping', array('uid' => $member['uid']), array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  592. pdo_update('mc_credits_record', array('uid' => $member['uid']), array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  593. pdo_update('mc_card_members', array('uid' => $member['uid']), array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  594. }
  595. message('重新绑定帐号成功!', url('mc/home'), 'success');
  596. }
  597. }
  598. }
  599. template('mc/bond');