人人商城

profile.ctrl.php 6.2KB

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