profile.ctrl.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. $title = $_W['account']['name'] . '微站';
  10. $dos = array('index', 'editprofile', 'personal_info', 'contact_method', 'education_info', 'jobedit', 'avatar', 'address', 'addressadd');
  11. $do = in_array($do, $dos) ? $do : 'index';
  12. $navs = app_navs('profile');
  13. if (empty($_W['member']['uid'])) {
  14. message('请先登录!', url('auth/login', array('i' => $_W['uniacid'])), 'error');
  15. }
  16. $profile = mc_fetch($_W['member']['uid']);
  17. if(!empty($profile)) {
  18. if(empty($profile['email']) || (!empty($profile['email']) && substr($profile['email'], -6) == 'we7.cc' && strlen($profile['email']) == 39)) {
  19. $profile['email'] = '';
  20. $profile['email_effective'] = 1;
  21. }
  22. }
  23. if(!empty($_W['openid'])) {
  24. $map_fans = pdo_getcolumn('mc_mapping_fans', array('uniacid' => $_W['uniacid'], 'openid' => $_W['openid']), 'tag');
  25. if(!empty($map_fans)) {
  26. if (is_base64($map_fans)){
  27. $map_fans = base64_decode($map_fans);
  28. }
  29. if (is_serialized($map_fans)) {
  30. $map_fans = iunserializer($map_fans);
  31. }
  32. if(!empty($map_fans) && is_array($map_fans)) {
  33. empty($profile['nickname']) ? ($data['nickname'] = strip_emoji($map_fans['nickname'])) : '';
  34. empty($profile['gender']) ? ($data['gender'] = $map_fans['sex']) : '';
  35. empty($profile['residecity']) ? ($data['residecity'] = ($map_fans['city']) ? $map_fans['city'] . '市' : '') : '';
  36. empty($profile['resideprovince']) ? ($data['resideprovince'] = ($map_fans['province']) ? $map_fans['province'] . '省' : '') : '';
  37. empty($profile['nationality']) ? ($data['nationality'] = $map_fans['country']) : '';
  38. empty($profile['avatar']) ? ($data['avatar'] = $map_fans['headimgurl']) : '';
  39. if(!empty($data)) {
  40. mc_update($_W['member']['uid'], $data);
  41. }
  42. }
  43. }
  44. }
  45. $sql = 'SELECT `mf`.*, `pf`.`field` FROM ' . tablename('mc_member_fields') . ' AS `mf` JOIN ' . tablename('profile_fields') . " AS `pf`
  46. ON `mf`.`fieldid` = `pf`.`id` WHERE `mf`.`uniacid` = :uniacid AND `mf`.`available` = :available";
  47. $params = array(':uniacid' => $_W['uniacid'], ':available' => '1');
  48. $mcFields = pdo_fetchall($sql, $params, 'field');
  49. $personal_info_hide = mc_card_settings_hide('personal_info');
  50. $contact_method_hide = mc_card_settings_hide('contact_method');
  51. $education_info_hide = mc_card_settings_hide('education_info');
  52. $jobedit_hide = mc_card_settings_hide('jobedit');
  53. if ($do == 'editprofile'){
  54. if ($_W['isajax'] && $_W['ispost']) {
  55. $data = array(
  56. 'nickname' => safe_gpc_string($_GPC['nickname']),
  57. 'realname' => safe_gpc_string($_GPC['realname']),
  58. 'birth' => array(
  59. 'year' => intval($_GPC['birth']['year']),
  60. 'month' => intval($_GPC['birth']['month']),
  61. 'day' => intval($_GPC['birth']['day'])
  62. ),
  63. 'gender' => intval($_GPC['gender']),
  64. );
  65. $result = mc_update($_W['member']['uid'], $data);
  66. if ($result) {
  67. message('更新资料成功!', referer(), 'success');
  68. } else {
  69. message('更新资料失败!', referer(), 'error');
  70. }
  71. }
  72. }
  73. if ($do == 'avatar') {
  74. $avatar = array('avatar' => safe_gpc_string($_GPC['avatar']));
  75. if (mc_update($_W['member']['uid'], $avatar)) {
  76. message('头像设置成功!', referer(), 'success');
  77. }
  78. }
  79. if ($do == 'address') {
  80. $address_id = intval($_GPC['id']);
  81. if ($_GPC['op'] == 'default') {
  82. pdo_update('mc_member_address', array('isdefault' => 0), array('uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid']));
  83. pdo_update('mc_member_address', array('isdefault' => 1), array('id' => $address_id, 'uniacid' => $_W['uniacid']));
  84. mc_update($_W['member']['uid'], array('address' => safe_gpc_string($_GPC['address'])));
  85. }
  86. if ($_GPC['op'] == 'delete') {
  87. if (!empty($profile) && !empty($_W['openid'])) {
  88. pdo_delete('mc_member_address', array('id' => $address_id, 'uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid']));
  89. }
  90. }
  91. $where = ' WHERE 1';
  92. $params = array(':uniacid' => $_W['uniacid'], ':uid' => $_W['member']['uid']);
  93. if (!empty($_GPC['addid'])) {
  94. $where .= ' AND `id` = :id';
  95. $params[':id'] = intval($_GPC['addid']);
  96. }
  97. $where .= ' AND `uniacid` = :uniacid AND `uid` = :uid';
  98. $sql = 'SELECT * FROM ' . tablename('mc_member_address') . $where;
  99. if (empty($params[':id'])) {
  100. $psize = 10;
  101. $pindex = max(1, intval($_GPC['page']));
  102. $sql .= ' LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
  103. $addresses = pdo_fetchall($sql, $params);
  104. $sql = 'SELECT COUNT(*) FROM ' . tablename('mc_member_address') . $where;
  105. $total = pdo_fetchcolumn($sql, $params);
  106. $pager = pagination($total, $pindex, $psize);
  107. } else {
  108. $address = pdo_fetch($sql, $params);
  109. }
  110. }
  111. if ($do == 'addressadd') {
  112. $addid = intval($_GPC['addid']);
  113. if ($_W['isajax'] && $_W['ispost']) {
  114. $post = safe_gpc_array($_GPC['address']);
  115. if (empty($post['username'])) {
  116. message('请输入您的姓名', referer(), 'error');
  117. }
  118. if (empty($post['mobile'])) {
  119. message('请输入您的手机号', referer(), 'error');
  120. }
  121. if (empty($post['zipcode'])) {
  122. message('请输入您的邮政编码', referer(), 'error');
  123. }
  124. if (empty($post['province'])) {
  125. message('请输入您的所在省', referer(), 'error');
  126. }
  127. if (empty($post['city'])) {
  128. message('请输入您的所在市', referer(), 'error');
  129. }
  130. if (empty($post['address'])) {
  131. message('请输入您的详细地址', referer(), 'error');
  132. }
  133. $address = array(
  134. 'username' => $post['username'],
  135. 'mobile' => $post['mobile'],
  136. 'zipcode' => $post['zipcode'],
  137. 'province' => $post['province'],
  138. 'city' => $post['city'],
  139. 'district' => empty($post['district']) ? '' : $post['district'],
  140. 'address' => $post['address'],
  141. );
  142. $address_data = pdo_get('mc_member_address', array('uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid']));
  143. if (empty($address_data)) {
  144. $address['isdefault'] = 1;
  145. }
  146. if (!empty($addid)) {
  147. if (pdo_update('mc_member_address', $address, array('id' => $addid, 'uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid']))) {
  148. message('修改收货地址成功', url('mc/profile/address'), 'success');
  149. } else {
  150. message('修改收货地址失败,请稍后重试', url('mc/profile/address'), 'error');
  151. }
  152. } else {
  153. $address['uniacid'] = $_W['uniacid'];
  154. $address['uid'] = $_W['member']['uid'];
  155. if (pdo_insert('mc_member_address', $address)) {
  156. $adres = pdo_get('mc_member_address', array('uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid'], 'isdefault'=> 1));
  157. if (!empty($adres)) {
  158. $adres['address'] = $adres['province'].$adres['city'].$adres['district'].$adres['address'];
  159. mc_update($_W['member']['uid'], array('address' => $adres['address']));
  160. }
  161. message('地址添加成功', url('mc/profile/address'), 'success');
  162. }
  163. }
  164. }
  165. if (!empty($addid)) {
  166. $address = pdo_get('mc_member_address', array('id' => $addid, 'uniacid' => $_W['uniacid']));
  167. }
  168. }
  169. template('mc/profile');