人人商城

bond.ctrl.php 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. load()->func('tpl');
  9. load()->model('user');
  10. $dos = array('display', 'credits', 'address', 'card', 'mycard', 'record',
  11. 'mobile', 'email', 'card_qrcode',
  12. 'addressadd', 'settings', 'password', 'aboutus', 'binding_account', 'pay_password');
  13. $do = in_array($do, $dos) ? $do : 'display';
  14. $profile = mc_fetch($_W['member']['uid']);
  15. if ($do == 'pay_password') {
  16. $user_info = mc_fetch($_W['member']['uid']);
  17. $pay_password = $user_info['pay_password'];
  18. if ($_W['isajax'] && $_W['ispost']) {
  19. $password = safe_gpc_string($_GPC['pay_password']);
  20. $repeat_password = safe_gpc_string($_GPC['repeat_pay_password']);
  21. if ($_GPC['pay_password_open'] == 'on') {
  22. if (empty($password) || empty($repeat_password)) {
  23. message('请输入支付密码', '', 'error');
  24. }
  25. if ($password != $repeat_password) {
  26. message('两次输入的密码不一致', '', 'error');
  27. }
  28. if (strlen($password) < 6) {
  29. message('密码最小长度为6位', '', 'error');
  30. }
  31. $password = md5($password . $user_info['salt']);
  32. mc_update($_W['member']['uid'], array('pay_password' => $password));
  33. message('设置成功', url('mc/bond/pay_password'));
  34. } else {
  35. mc_update($_W['member']['uid'], array('pay_password' => ''));
  36. message('已关闭支付密码', url('mc/bond/pay_password'));
  37. }
  38. }
  39. }
  40. if ($do == 'credits') {
  41. $where = '';
  42. $params = array(':uid' => $_W['member']['uid']);
  43. $pindex = max(1, intval($_GPC['page']));
  44. $psize = 15;
  45. $period = intval($_GPC['period']);
  46. if ($period == '1') {
  47. $starttime = date('Ym01',strtotime(0));
  48. $endtime = date('Ymd His', time());
  49. } elseif($period == '0') {
  50. $starttime = date('Ym01', strtotime(1*$period . "month"));
  51. $endtime = date('Ymd', strtotime("$starttime + 1 month - 1 day"));
  52. } else {
  53. $starttime = date('Ym01', strtotime(1*$period . "month"));
  54. $endtime = date('Ymd', strtotime("$starttime + 1 month - 1 day"));
  55. }
  56. $where = ' AND `createtime` >= :starttime AND `createtime` < :endtime';
  57. $params[':starttime'] = strtotime($starttime);
  58. $params[':endtime'] = strtotime($endtime);
  59. $sql = 'SELECT `realname`, `avatar` FROM ' . tablename('mc_members') . " WHERE `uid` = :uid";
  60. $user = pdo_fetch($sql, array(':uid' => $_W['member']['uid']));
  61. if ($_GPC['credittype']) {
  62. if ($_GPC['type'] == 'order') {
  63. $sql = 'SELECT * FROM ' . tablename('mc_credits_recharge') . " WHERE `uid` = :uid $where LIMIT " . ($pindex - 1) * $psize. ',' . $psize;
  64. $orders = pdo_fetchall($sql, $params);
  65. foreach ($orders as &$value) {
  66. $value['createtime'] = date('Y-m-d', $value['createtime']);
  67. $value['fee'] = number_format($value['fee'], 2);
  68. if ($value['status'] == 1) {
  69. $orderspay += $value['fee'];
  70. }
  71. unset($value);
  72. }
  73. $ordersql = 'SELECT COUNT(*) FROM ' .tablename('mc_credits_recharge') . "WHERE `uid` = :uid {$where}";
  74. $total = pdo_fetchcolumn($ordersql, $params);
  75. $orderpager = pagination($total, $pindex, $psize, '', array('before' => 0, 'after' => 0, 'ajaxcallback' => ''));
  76. template('mc/bond');
  77. exit();
  78. }
  79. $where .= " AND `credittype` = :credit_type";
  80. $params[':credit_type'] = safe_gpc_string($_GPC['credittype']);
  81. }
  82. $sql = 'SELECT `num` FROM ' . tablename('mc_credits_record') . " WHERE `uid` = :uid $where";
  83. $nums = pdo_fetchall($sql, $params);
  84. $pay = $income = 0;
  85. foreach ($nums as $value) {
  86. if ($value['num'] > 0) {
  87. $income += $value['num'];
  88. } else {
  89. $pay += abs($value['num']);
  90. }
  91. }
  92. if ($_GPC['credittype'] == 'credit2') {
  93. $pay = number_format($pay, 2);
  94. $income = number_format($income, 2);
  95. }
  96. $sql = 'SELECT * FROM ' . tablename('mc_credits_record') . " WHERE `uid` = :uid {$where} ORDER BY `createtime` DESC LIMIT " . ($pindex - 1) * $psize.','. $psize;
  97. $data = pdo_fetchall($sql, $params);
  98. foreach ($data as $key=>$value) {
  99. $data[$key]['credittype'] = $creditnames[$data[$key]['credittype']]['title'];
  100. $data[$key]['createtime'] = date('Y-m-d H:i', $data[$key]['createtime']);
  101. $data[$key]['num'] = number_format($value['num'], 2);
  102. if ($data[$key]['num'] < 0) {
  103. $data[$key]['color'] = "#000";
  104. } else {
  105. $data[$key]['color'] = "#04be02";
  106. $data[$key]['num'] = "+" . $data[$key]['num'];
  107. }
  108. $data[$key]['remark'] = str_replace('credit1', '积分', $data[$key]['remark']);
  109. $data[$key]['remark'] = str_replace('credit2', '余额', $data[$key]['remark']);
  110. $data[$key]['remark'] = empty($data[$key]['remark']) ? '未记录' : $data[$key]['remark'];
  111. }
  112. $pagesql = 'SELECT COUNT(*) FROM ' .tablename('mc_credits_record') . "WHERE `uid` = :uid {$where}";
  113. $total = pdo_fetchcolumn($pagesql, $params);
  114. $pager = pagination($total, $pindex, $psize, '', array('before' => 0, 'after' => 0, 'ajaxcallback' => ''));
  115. $pagenums = ceil($total / $psize);
  116. if($_W['isajax'] && $_W['ispost']) {
  117. if (!empty($data)){
  118. exit(json_encode($data));
  119. } else {
  120. exit(json_encode(array('state'=>'error')));
  121. }
  122. }
  123. $type = trim($_GPC['type']);
  124. if ($type == 'recorddetail') {
  125. $id = intval($_GPC['id']);
  126. $credittype = $_GPC['credittype'];
  127. $data = pdo_fetch("SELECT r.*, u.username FROM " . tablename('mc_credits_record') . ' AS r LEFT JOIN ' .tablename('users') . ' AS u ON r.operator = u.uid ' . ' WHERE r.id = :id AND r.uniacid = :uniacid AND r.credittype = :credittype ORDER BY id DESC LIMIT ' . ($pindex - 1) * $psize .',' . $psize, array(':uniacid' => $_W['uniacid'], ':id' => $id, ':credittype' => $credittype));
  128. if ($data['credittype'] == 'credit2') {
  129. $data['credittype'] = '余额';
  130. } elseif ($data['credittype'] == 'credit1') {
  131. $data['credittype'] = '积分';
  132. }
  133. $data['remark'] = str_replace('credit1', '积分', $data['remark']);
  134. $data['remark'] = str_replace('credit2', '余额', $data['remark']);
  135. $data['remark'] = empty($data['remark']) ? '暂无记录' : $data['remark'];
  136. }
  137. }
  138. if($do == 'record') {
  139. $setting = pdo_get('mc_card', array('uniacid' => $_W['uniacid']), array('nums_text', 'times_text'));
  140. $card = pdo_get('mc_card_members', array('uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid']));
  141. $type = trim($_GPC['type']);
  142. $where = ' WHERE uniacid = :uniacid AND uid = :uid AND type = :type';
  143. $params = array(
  144. ':uniacid' => $_W['uniacid'],
  145. ':uid' => $_W['member']['uid'],
  146. ':type' => $type,
  147. );
  148. $pindex = max(1, intval($_GPC['page']));
  149. $psize = 20;
  150. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_card_record') . $where, $params);
  151. $limit = ' ORDER BY id DESC LIMIT ' . ($pindex - 1) * $psize . ', ' . $psize;
  152. $data = pdo_fetchall('SELECT * FROM ' . tablename('mc_card_record') . $where . $limit, $params);
  153. $pager = pagination($total, $pindex, $psize, '', array('before' => 0, 'after' => 0, 'ajaxcallback' => ''));
  154. }
  155. if($do == 'mobile') {
  156. $reregister = false;
  157. if ($_W['member']['email'] == md5($_W['openid']).'@we7.cc') {
  158. $reregister = true;
  159. message('请先完善账号信息', url('mc/bond/binding_account', array('type' => '1')), 'error');
  160. }
  161. $op = trim($_GPC['op']) ? trim($_GPC['op']) : 'index';
  162. $mobile_exist = empty($profile['mobile']) ? 0 : 1;
  163. if($_W['ispost'] && $_W['isajax']) {
  164. $code = trim($_GPC['code']);
  165. $mobile = trim($_GPC['mobile']);
  166. $password = trim($_GPC['password']);
  167. $repassword = trim($_GPC['repassword']);
  168. load()->model('utility');
  169. if (!preg_match(REGULAR_MOBILE, $mobile)) {
  170. message(error(-1, '格式错误'), '', 'ajax');
  171. }
  172. if (!code_verify($_W['uniacid'], $mobile, $code)) {
  173. pdo_delete('uni_verifycode', array('receiver' => $username));
  174. message(error(-1, '验证码错误'), '', 'ajax');
  175. } else {
  176. }
  177. if (empty($mobile)) {
  178. message(error(-1, '请填写手机号'), '', 'ajax');
  179. }
  180. if (!empty($reregister)) {
  181. if (empty($password) || empty($repassword)) {
  182. message(error(-1, '请填写密码'), '', 'ajax');
  183. }
  184. if ($password !== $repassword) {
  185. message(error(-1, '密码不一致'), '', 'ajax');
  186. }
  187. }
  188. $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']));
  189. if(!empty($is_exist)) {
  190. message(error(-1, '手机号已被绑定'), '', 'ajax');
  191. } else {
  192. $salt = random(8);
  193. $password = md5($password . $salt . $_W['config']['setting']['authkey']);
  194. if (!empty($reregister)) {
  195. mc_update($_W['member']['uid'], array('mobile' => $mobile, 'email' => '', 'salt' => $salt, 'password' => $password));
  196. } else {
  197. mc_update($_W['member']['uid'], array('mobile' => $mobile));
  198. }
  199. message(error(0, '绑定成功'), url('mc/bond/mobile'), 'ajax');
  200. }
  201. }
  202. }
  203. if ($do == 'password') {
  204. $reregister = false;
  205. if ($_W['member']['email'] == md5($_W['openid']).'@we7.cc') {
  206. $reregister = true;
  207. message('请先完善账号信息', url('mc/bond/binding_account', array('type' => '1')), 'error');
  208. }
  209. if ($_W['isajax'] && $_W['ispost']) {
  210. if (empty($reregister) && !empty($profile['password'])) {
  211. $oldpassword = trim($_GPC['oldpassword']);
  212. $oldpassword = md5($oldpassword . $profile['salt'] . $_W['config']['setting']['authkey']);
  213. $correct = pdo_get('mc_members', array('uid' => $_W['member']['uid'], 'password' => $oldpassword), array('uid'));
  214. if (empty($correct)) {
  215. message('旧密码不正确', '', 'error');
  216. }
  217. }
  218. $password = trim($_GPC['password']);
  219. if(empty($password) || strlen($password) < 6) {
  220. message('密码不能少于6位', '', 'error');
  221. }
  222. $repassword = trim($_GPC['repassword']);
  223. if($password != $repassword) {
  224. message('两次输入密码不一致', '', 'error');
  225. }
  226. $salt = random(8);
  227. $password = md5($password . $salt . $_W['config']['setting']['authkey']);
  228. mc_update($_W['member']['uid'], array('salt' => $salt, 'password' => $password));
  229. message('设置密码成功', url('mc/bond/settings'), 'success');
  230. }
  231. }
  232. if ($do == 'email') {
  233. $reregister = false;
  234. if ($_W['member']['email'] == md5($_W['openid']).'@we7.cc') {
  235. $reregister = true;
  236. message('请先完善账号信息', url('mc/bond/binding_account', array('type' => '1')), 'error');
  237. }
  238. if ($_W['isajax'] && $_W['ispost']) {
  239. $data = array();
  240. if (empty($_GPC['email'])) {
  241. message('请输入您的邮箱', '', 'error');
  242. }
  243. $data['email'] = trim($_GPC['email']);
  244. $emailexists = pdo_get('mc_members', array('email' => $data['email'], 'uniacid' => $_W['uniacid'], 'uid <>' => $_W['member']['uid']), array('uid'));
  245. if (!empty($emailexists['uid'])) {
  246. message('抱歉,该E-Mail地址已经被注册,请更换。', '', 'error');
  247. }
  248. mc_update($profile['uid'], $data);
  249. message('邮箱绑定成功', url('mc/home'), 'success');
  250. }
  251. }
  252. if ($do == 'settings') {
  253. $reregister = false;
  254. if ($_W['member']['email'] == md5($_W['openid']).'@we7.cc') {
  255. $reregister = true;
  256. }
  257. $profile_hide = mc_card_settings_hide();
  258. $item = empty($setting['passport']['item']) ? 'random' : $setting['passport']['item'];
  259. $ltype = empty($setting['passport']['type']) ? 'hybird' : $setting['passport']['type'];
  260. }
  261. if ($do == 'binding_account') {
  262. $type = intval($_GPC['type']);
  263. $reregister = false;
  264. if ($_W['member']['email'] == md5($_W['openid']).'@we7.cc') {
  265. $reregister = true;
  266. }
  267. $item = empty($setting['passport']['item']) ? 'random' : $setting['passport']['item'];
  268. if ($_W['isajax'] && $_W['ispost']) {
  269. $username = trim($_GPC['username']);
  270. $password = $_GPC['password'];
  271. $data = array();
  272. if (empty($_GPC['username'])) {
  273. message('请输入您的账号', '', 'error');
  274. }
  275. if (empty($_GPC['password'])) {
  276. message('请输入您的密码', '', 'error');
  277. }
  278. if($item == 'email') {
  279. if (preg_match(REGULAR_EMAIL, $username)) {
  280. $data['email'] = $username;
  281. } else {
  282. message('邮箱格式不正确', referer(), 'error');
  283. }
  284. } elseif($item == 'mobile') {
  285. if (preg_match(REGULAR_MOBILE, $username)) {
  286. $data['mobile'] = $username;
  287. } else {
  288. message('手机号格式不正确', referer(), 'error');
  289. }
  290. } else {
  291. if (preg_match(REGULAR_MOBILE, $username)) {
  292. $data['mobile'] = $username;
  293. } elseif (preg_match(REGULAR_EMAIL, $username)) {
  294. $data['email'] = $username;
  295. } else {
  296. message('用户名格式错误', referer(), 'error');
  297. }
  298. }
  299. if ($type == '1') {
  300. if (!empty($data['email'])) {
  301. $userexists = pdo_get('mc_members', array('email' => $data['email'], 'uniacid' => $_W['uniacid'], 'uid <>' => $_W['member']['uid']), array('uid'));
  302. } elseif (!empty($data['mobile'])) {
  303. $userexists = pdo_get('mc_members', array('mobile' => $data['mobile'], 'uniacid' => $_W['uniacid'], 'uid <>' => $_W['member']['uid']), array('uid'));
  304. $data['email'] = '';
  305. }
  306. if (!empty($userexists['uid'])) {
  307. message('抱歉,该账号已经被注册,请更换。', '', 'error');
  308. }
  309. $hash = md5($password . $profile['salt'] . $_W['config']['setting']['authkey']);
  310. $data['salt'] = $profile['salt'];
  311. $data['password'] = $hash;
  312. mc_update($profile['uid'], $data);
  313. message('账号绑定成功', url('mc/home'), 'success');
  314. } else {
  315. if (!preg_match(REGULAR_EMAIL, $data['email'])) {
  316. message('邮箱格式不正确', referer(), 'error');
  317. }
  318. if (!empty($reregister)) {
  319. $member = pdo_get('mc_members', array('uniacid' => $_W['uniacid'], 'email' => $data['email']), array('uid', 'salt', 'password'));
  320. if (empty($member)) {
  321. message('绑定已有账号失败', '', 'error');
  322. }
  323. $hash = md5($_GPC['password'] . $member['salt'] . $_W['config']['setting']['authkey']);
  324. if ($member['password'] != $hash) {
  325. message('绑定已有账号失败', '', 'error');
  326. }
  327. pdo_update('mc_mapping_fans', array('uid' => $member['uid']), array(
  328. 'acid' => $_W['acid'],
  329. 'openid' => $_W['openid'],
  330. ));
  331. $member_old = mc_fetch($_W['member']['uid']);
  332. $member_new = mc_fetch($member['uid']);
  333. if (!empty($member_old) && !empty($member_new)) {
  334. $ignore = array('email', 'password', 'uid', 'uniacid', 'salt', 'credit1', 'credit2', 'credit3','credit4','credit5');
  335. $profile_update = array();
  336. foreach ($member_old as $key => $value) {
  337. if (!in_array($key, $ignore)) {
  338. if (empty($member_new[$key]) && !empty($member_old[$key])) {
  339. $profile_update[$key] = $member_old[$key];
  340. }
  341. }
  342. }
  343. $profile_update['credit1'] = $member_old['credit1'] + $member_new['credit1'];
  344. $profile_update['credit2'] = $member_old['credit2'] + $member_new['credit2'];
  345. $profile_update['credit3'] = $member_old['credit3'] + $member_new['credit3'];
  346. $profile_update['credit4'] = $member_old['credit4'] + $member_new['credit4'];
  347. $profile_update['credit5'] = $member_old['credit5'] + $member_new['credit5'];
  348. pdo_update('mc_members', $profile_update, array('uid' => $member['uid'], 'uniacid' => $_W['uniacid']));
  349. cache_build_memberinfo($member['uid']);
  350. pdo_delete('mc_members', array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  351. pdo_update('coupon_record', array('uid' => $member['uid']), array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  352. pdo_update('activity_exchange_trades', array('uid' => $member['uid']), array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  353. pdo_update('activity_exchange_trades_shipping', array('uid' => $member['uid']), array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  354. pdo_update('mc_credits_record', array('uid' => $member['uid']), array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  355. pdo_update('mc_card_members', array('uid' => $member['uid']), array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  356. }
  357. message('绑定已有账号成功', url('mc/home'), 'success');
  358. }
  359. }
  360. }
  361. }
  362. template('mc/bond');