人人商城

profile.ctrl.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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('user');
  8. load()->func('file');
  9. load()->classs('oauth2/oauth2client');
  10. load()->model('message');
  11. load()->model('setting');
  12. $dos = array('base', 'post', 'bind', 'validate_mobile', 'bind_mobile', 'unbind');
  13. $do = in_array($do, $dos) ? $do : 'base';
  14. $_W['page']['title'] = '账号信息 - 我的账户 - 用户管理';
  15. if ($do == 'post' && $_W['isajax'] && $_W['ispost']) {
  16. $type = trim($_GPC['type']);
  17. if ($_W['isfounder']) {
  18. $uid = is_array($_GPC['uid']) ? 0 : intval($_GPC['uid']);
  19. } else {
  20. $uid = $_W['uid'];
  21. }
  22. if (empty($uid) || empty($type)) {
  23. iajax(40035, '参数错误,请刷新后重试!', '');
  24. }
  25. $user = user_single($uid);
  26. if (empty($user)) {
  27. iajax(-1, '用户不存在或已经被删除!', '');
  28. }
  29. if ($user['status'] == USER_STATUS_CHECK || $user['status'] == USER_STATUS_BAN) {
  30. iajax(-1, '访问错误,该用户未审核或者已被禁用,请先修改用户状态!', '');
  31. }
  32. $users_profile_exist = pdo_get('users_profile', array('uid' => $uid));
  33. if ($type == 'birth') {
  34. if ($users_profile_exist['year'] == $_GPC['year'] && $users_profile_exist['month'] == $_GPC['month'] && $users_profile_exist['day'] == $_GPC['day']) iajax(0, '未作修改!', '');
  35. } elseif ($type == 'reside') {
  36. if ($users_profile_exist['province'] == $_GPC['province'] && $users_profile_exist['city'] == $_GPC['city'] && $users_profile_exist['district'] == $_GPC['district']) iajax(0, '未作修改!', '');
  37. } else {
  38. if (in_array($type, array('username', 'password'))) {
  39. if ($user[$type] == $_GPC[$type] && $type != 'password') iajax(0, '未做修改!', '');
  40. } else {
  41. if ($users_profile_exist[$type] == $_GPC[$type]) iajax(0, '未作修改!', '');
  42. }
  43. }
  44. switch ($type) {
  45. case 'avatar':
  46. case 'realname':
  47. case 'address':
  48. case 'qq':
  49. case 'mobile':
  50. if ($type == 'mobile') {
  51. $match = preg_match(REGULAR_MOBILE, trim($_GPC[$type]));
  52. if (empty($match)) {
  53. iajax(-1, '手机号不正确', '');
  54. }
  55. $users_mobile = pdo_get('users_profile', array('mobile' => trim($_GPC[$type]), 'uid <>' => $uid));
  56. $bind_mobile = pdo_get('users_bind', array('bind_sign' => trim($_GPC[$type]), 'uid<>' => $uid));
  57. if (!empty($users_mobile) || !empty($bind_mobile)) {
  58. iajax(-1, '手机号已存在,请联系管理员', '');
  59. }
  60. }
  61. if ($users_profile_exist) {
  62. $result = pdo_update('users_profile', array($type => trim($_GPC[$type])), array('uid' => $uid));
  63. } else {
  64. $data = array(
  65. 'uid' => $uid,
  66. 'createtime' => TIMESTAMP,
  67. $type => trim($_GPC[$type])
  68. );
  69. $result = pdo_insert('users_profile', $data);
  70. }
  71. $data = array(
  72. 'uid' => $uid,
  73. 'bind_sign' => trim($_GPC[$type]),
  74. 'third_nickname' => trim($_GPC[$type]),
  75. 'third_type' => USER_REGISTER_TYPE_MOBILE,
  76. );
  77. $users_bind_exist = pdo_get('users_bind', array('uid' => $uid, 'third_type' => USER_REGISTER_TYPE_MOBILE));
  78. if ($users_bind_exist) {
  79. $result_bind = pdo_update('users_bind', $data, array('uid' => $uid, 'third_type' => USER_REGISTER_TYPE_MOBILE));
  80. } else {
  81. $result_bind = pdo_insert('users_bind', $data);
  82. }
  83. if (!$result_bind) {
  84. iajax(-1, '绑定手机号失败,请联系管理员解决!', '');
  85. }
  86. break;
  87. case 'username':
  88. $founders = explode(',', $_W['config']['setting']['founder']);
  89. if (!in_array($_W['uid'], $founders) && $_W['uid'] != $user['owner_uid']) {
  90. iajax(1, '无权限修改,请联系网站创始人!');
  91. }
  92. $username = trim($_GPC['username']);
  93. $name_exist = pdo_get('users', array('username' => $username));
  94. if (!empty($name_exist)) {
  95. iajax(2, '用户名已存在,请更换其他用户名!', '');
  96. }
  97. $result = pdo_update('users', array('username' => $username), array('uid' => $uid));
  98. break;
  99. case 'vice_founder_name':
  100. $userinfo = user_single(array('username' => $_GPC['vice_founder_name']));
  101. if (empty($userinfo) || $userinfo['founder_groupid'] != ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  102. iajax(1, '用户不存在或该用户不是副创始人', '');
  103. }
  104. $result = pdo_update('users', array('owner_uid' => $userinfo['uid']), array('uid' => $uid));
  105. break;
  106. case 'remark':
  107. $result = pdo_update('users', array('remark' => trim($_GPC['remark'])), array('uid' => $uid));
  108. break;
  109. case 'welcome_link':
  110. $welcome_link = intval($_GPC['welcome_link']);
  111. $result = pdo_update('users', array('welcome_link' => $welcome_link), array('uid' => $uid));
  112. break;
  113. case 'password':
  114. if ($_GPC['newpwd'] !== $_GPC['renewpwd']) iajax(2, '两次密码不一致!', '');
  115. $check_safe = safe_check_password($_GPC['newpwd']);
  116. if (is_error($check_safe)) {
  117. iajax(4, $check_safe['message']);
  118. }
  119. if (!$_W['isfounder'] && empty($user['register_type'])) {
  120. $pwd = user_hash($_GPC['oldpwd'], $user['salt']);
  121. if ($pwd != $user['password']) iajax(3, '原密码不正确!', '');
  122. }
  123. $newpwd = user_hash($_GPC['newpwd'], $user['salt']);
  124. if ($newpwd == $user['password']) {
  125. iajax(0, '未作修改!', '');
  126. }
  127. $result = pdo_update('users', array('password' => $newpwd), array('uid' => $uid));
  128. break;
  129. case 'endtime' :
  130. if ($_GPC['endtype'] == 1) {
  131. $endtime = 0;
  132. } else {
  133. $endtime = strtotime($_GPC['endtime']);
  134. }
  135. if (user_is_vice_founder() && !empty($_W['user']['endtime']) && ($endtime > $_W['user']['endtime'] || empty($endtime))) {
  136. iajax(-1, '副创始人给用户设置的时间不能超过自己的到期时间');
  137. }
  138. $result = pdo_update('users', array('endtime' => $endtime), array('uid' => $uid));
  139. pdo_update('users_profile', array('send_expire_status' => 0), array('uid' => $uid));
  140. $uni_account_user = pdo_getall('uni_account_users', array('uid' => $uid, 'role' => 'owner'));
  141. if (!empty($uni_account_user)) {
  142. foreach ($uni_account_user as $account) {
  143. cache_delete(cache_system_key('uniaccount', array('uniacid' => $account['uniacid'])));
  144. }
  145. }
  146. break;
  147. case 'birth':
  148. if ($users_profile_exist) {
  149. $result = pdo_update('users_profile', array('birthyear' => intval($_GPC['year']), 'birthmonth' => intval($_GPC['month']), 'birthday' => intval($_GPC['day'])), array('uid' => $uid));
  150. } else {
  151. $data = array(
  152. 'uid' => $uid,
  153. 'createtime' => TIMESTAMP,
  154. 'birthyear' => intval($_GPC['year']),
  155. 'birthmonth' => intval($_GPC['month']),
  156. 'birthday' => intval($_GPC['day'])
  157. );
  158. $result = pdo_insert('users_profile', $data);
  159. }
  160. break;
  161. case 'reside':
  162. if ($users_profile_exist) {
  163. $result = pdo_update('users_profile', array('resideprovince' => $_GPC['province'], 'residecity' => $_GPC['city'], 'residedist' => $_GPC['district']), array('uid' => $uid));
  164. } else {
  165. $data = array(
  166. 'uid' => $uid,
  167. 'createtime' => TIMESTAMP,
  168. 'resideprovince' => $_GPC['province'],
  169. 'residecity' => $_GPC['city'],
  170. 'residedist' => $_GPC['district']
  171. );
  172. $result = pdo_insert('users_profile', $data);
  173. }
  174. break;
  175. }
  176. if ($result) {
  177. pdo_update('users_profile', array('edittime' => TIMESTAMP), array('uid' => $uid));
  178. iajax(0, '修改成功!', '');
  179. } else {
  180. iajax(1, '修改失败,请稍候重试!', '');
  181. }
  182. }
  183. if ($do == 'base') {
  184. $account_num = permission_user_account_num($_W['uid']);
  185. $message_id = intval($_GPC['message_id']);
  186. message_notice_read($message_id);
  187. $user_type = !empty($_GPC['user_type']) ? trim($_GPC['user_type']) : PERSONAL_BASE_TYPE;
  188. $user = user_single($_W['uid']);
  189. if (empty($user)) {
  190. itoast('抱歉,用户不存在或是已经被删除!', url('user/profile'), 'error');
  191. }
  192. $user['last_visit'] = date('Y-m-d H:i:s', $user['lastvisit']);
  193. $user['joindate'] = date('Y-m-d H:i:s', $user['joindate']);
  194. $user['url'] = user_invite_register_url($_W['uid']);
  195. $profile = pdo_get('users_profile', array('uid' => $_W['uid']));
  196. $profile = user_detail_formate($profile);
  197. if (!$_W['isfounder'] || user_is_vice_founder()) {
  198. if ($_W['user']['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  199. $groups = user_founder_group();
  200. $group_info = user_founder_group_detail_info($user['groupid']);
  201. } else {
  202. $groups = user_group();
  203. $group_info = user_group_detail_info($user['groupid']);
  204. }
  205. $account_detail = user_account_detail_info($_W['uid']);
  206. }
  207. $table = table('core_profile_fields');
  208. $extra_fields = $table->getExtraFields();
  209. template('user/profile');
  210. }
  211. if ($do == 'bind') {
  212. $setting_sms_sign = setting_load('site_sms_sign');
  213. $bind_sign = !empty($setting_sms_sign['site_sms_sign']['register']) ? $setting_sms_sign['site_sms_sign']['register'] : '';
  214. $user_table = table('users');
  215. $user = $user_table->usersInfo($_W['uid']);
  216. $user_profile = $user_table->userProfile($_W['uid']);
  217. $user_table->bindSearchWithUser($_W['uid']);
  218. $bind_info = $user_table->userBind();
  219. $signs = array_keys($bind_info);
  220. if (!empty($user['openid']) && !in_array($user['openid'], $signs)) {
  221. pdo_insert('users_bind', array('uid' => $user['uid'], 'bind_sign' => $user['openid'], 'third_type' => $user['register_type'], 'third_nickname' => $user_profile['nickname']));
  222. }
  223. if (!empty($user_profile['mobile']) && !in_array($user_profile['mobile'], $signs)) {
  224. pdo_insert('users_bind', array('uid' => $user_profile['uid'], 'bind_sign' => $user_profile['mobile'], 'third_type' => USER_REGISTER_TYPE_MOBILE, 'third_nickname' => $user_profile['mobile']));
  225. }
  226. $user_table->bindSearchWithUser($_W['uid']);
  227. $lists = $user_table->userBind();
  228. $bind_qq = array();
  229. $bind_wechat = array();
  230. $bind_mobile = array();
  231. if (!empty($lists)) {
  232. foreach($lists as $list) {
  233. switch($list['third_type']){
  234. case USER_REGISTER_TYPE_QQ:
  235. $bind_qq = $list;
  236. break;
  237. case USER_REGISTER_TYPE_WECHAT:
  238. $bind_wechat = $list;
  239. break;
  240. case USER_REGISTER_TYPE_MOBILE:
  241. $bind_mobile = $list;
  242. break;
  243. }
  244. }
  245. }
  246. $support_login_urls = user_support_urls();
  247. template('user/bind');
  248. }
  249. if (in_array($do, array('validate_mobile', 'bind_mobile')) || $_GPC['bind_type'] == USER_REGISTER_TYPE_MOBILE && $do == 'unbind') {
  250. $user_table = table('users');
  251. $user_profile = $user_table->userProfile($_W['uid']);
  252. $mobile = trim($_GPC['mobile']);
  253. $type = trim($_GPC['type']);
  254. $user_table = table('users');
  255. $mobile_exists = $user_table->userProfileMobile($mobile);
  256. if (empty($mobile)) {
  257. iajax(-1, '手机号不能为空');
  258. }
  259. if (!preg_match(REGULAR_MOBILE, $mobile)) {
  260. iajax(-1, '手机号格式不正确');
  261. }
  262. if (!empty($type) && $mobile != $user_profile['mobile']) {
  263. iajax(-1, '请输入已绑定的手机号');
  264. }
  265. if (empty($type) && !empty($mobile_exists)) {
  266. iajax(-1, '手机号已存在');
  267. }
  268. }
  269. if ($do == 'validate_mobile') {
  270. $user = array('username' => trim($_GPC['mobile']));
  271. $mobile_exists = user_check($user);
  272. if ($mobile_exists) {
  273. iajax(-1, '手机号已经存在');
  274. }
  275. iajax(0, '本地校验成功');
  276. }
  277. if ($do == 'bind_mobile') {
  278. if ($_W['isajax'] && $_W['ispost']) {
  279. $bind_info = OAuth2Client::create('mobile')->bind();
  280. $user = array('username' => trim($_GPC['mobile']));
  281. $mobile_exists = user_check($user);
  282. if ($mobile_exists) {
  283. iajax(-1, '手机号已经存在');
  284. }
  285. if (is_error($bind_info)) {
  286. iajax(-1, $bind_info['message']);
  287. }
  288. iajax(0, '绑定成功', url('user/profile/bind'));
  289. } else {
  290. iajax(-1, '非法请求');
  291. }
  292. }
  293. if ($do == 'unbind') {
  294. $types = array(1 => 'qq', 2 => 'wechat', 3 => 'mobile');
  295. if (!in_array($_GPC['bind_type'], array(USER_REGISTER_TYPE_QQ, USER_REGISTER_TYPE_WECHAT, USER_REGISTER_TYPE_MOBILE))) {
  296. iajax(-1, '类型错误');
  297. }
  298. $bind_type = $types[$_GPC['bind_type']];
  299. if ($_W['isajax'] && $_W['ispost']) {
  300. $unbind_info = OAuth2Client::create($bind_type, $_W['setting']['thirdlogin'][$bind_type]['appid'], $_W['setting']['thirdlogin'][$bind_type]['appsecret'])->unbind();
  301. if (is_error($unbind_info)) {
  302. iajax(-1, $unbind_info['message']);
  303. }
  304. iajax(0, '解绑成功', url('user/profile/bind'));
  305. }
  306. iajax(-1, '非法请求');
  307. }