Memberinformation.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. * ============================================================================
  8. * DSMall多用户商城
  9. * ============================================================================
  10. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  11. * 网站地址: http://www.csdeshang.com
  12. * ----------------------------------------------------------------------------
  13. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  14. * 不允许对程序代码以任何形式任何目的的再发布。
  15. * ============================================================================
  16. * 控制器
  17. */
  18. class Memberinformation extends BaseMember {
  19. public function initialize() {
  20. parent::initialize(); // TODO: Change the autogenerated stub
  21. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberhome.lang.php');
  22. }
  23. /**
  24. * 我的资料【用户中心】
  25. *
  26. * @param
  27. * @return
  28. */
  29. public function index() {
  30. $member_model = model('member');
  31. if (request()->isPost()) {
  32. $member_array = array();
  33. $member_array['member_nickname'] = input('post.member_nickname');
  34. $member_array['member_sex'] = input('post.member_sex');
  35. $member_array['member_qq'] = input('post.member_qq');
  36. $member_array['member_ww'] = input('post.member_ww');
  37. $member_array['member_areaid'] = input('post.area_id');
  38. $member_array['member_cityid'] = input('post.city_id');
  39. $member_array['member_provinceid'] = input('post.province_id');
  40. $member_array['member_areainfo'] = input('post.area_info');
  41. if (strlen(input('post.birthday')) == 10) {
  42. $member_array['member_birthday'] = strtotime(input('post.birthday'));
  43. }
  44. $member_array['member_privacy'] = serialize(input('post.privacy/a'));
  45. $update = $member_model->editMember(array('member_id' => session('member_id')), $member_array, session('member_id'));
  46. $message = $update ? lang('ds_common_save_succ') : lang('ds_common_save_fail');
  47. if ($update) {
  48. ds_json_encode(10000, $message);
  49. } else {
  50. ds_json_encode(10001, $message);
  51. }
  52. }
  53. if ($this->member_info['member_privacy'] != '') {
  54. $this->member_info['member_privacy'] = unserialize($this->member_info['member_privacy']);
  55. } else {
  56. $this->member_info['member_privacy'] = array();
  57. }
  58. View::assign('member_info', $this->member_info);
  59. /* 设置买家当前菜单 */
  60. $this->setMemberCurMenu('member_information');
  61. /* 设置买家当前栏目 */
  62. $this->setMemberCurItem('member');
  63. View::assign('menu_sign', 'profile');
  64. View::assign('menu_sign_url', (string) url('Memberinformation/index'));
  65. View::assign('menu_sign1', 'baseinfo');
  66. return View::fetch($this->template_dir . 'index');
  67. }
  68. /**
  69. * 我的资料【更多个人资料】
  70. *
  71. * @param
  72. * @return
  73. */
  74. public function more() {
  75. if (request()->isPost()) {
  76. Db::name('snsmtagmember')->where(array('member_id' => session('member_id')))->delete();
  77. $mid_array = input('post.mid/a');
  78. if (!empty($mid_array)) {
  79. $insert_array = array();
  80. foreach ($mid_array as $val) {
  81. $insert_array[] = array(
  82. 'mtag_id' => intval($val),
  83. 'member_id' => session('member_id')
  84. );
  85. }
  86. Db::name('snsmtagmember')->insertAll($insert_array);
  87. }
  88. ds_json_encode(10000, lang('ds_common_op_succ'));
  89. }
  90. // 用户标签列表
  91. $mtag_array = Db::name('snsmembertag')->order('mtag_sort asc')->select()->toArray();
  92. // 用户已添加标签列表。
  93. $mtm_array = Db::name('snsmtagmember')->where(array('member_id' => session('member_id')))->select()->toArray();
  94. $mtag_list = array();
  95. $mtm_list = array();
  96. if (!empty($mtm_array) && is_array($mtm_array)) {
  97. // 整理
  98. $elect_array = array();
  99. foreach ($mtm_array as $val) {
  100. $elect_array[] = $val['mtag_id'];
  101. }
  102. foreach ((array) $mtag_array as $val) {
  103. if (in_array($val['mtag_id'], $elect_array)) {
  104. $mtm_list[] = $val;
  105. } else {
  106. $mtag_list[] = $val;
  107. }
  108. }
  109. } else {
  110. $mtag_list = $mtag_array;
  111. }
  112. View::assign('mtag_list', $mtag_list);
  113. View::assign('mtm_list', $mtm_list);
  114. /* 设置买家当前菜单 */
  115. $this->setMemberCurMenu('member_information');
  116. /* 设置买家当前栏目 */
  117. $this->setMemberCurItem('more');
  118. View::assign('menu_sign', 'profile');
  119. View::assign('menu_sign_url', (string) url('Memberinformation/index'));
  120. View::assign('menu_sign1', 'baseinfo');
  121. return View::fetch($this->template_dir . 'more');
  122. }
  123. public function upload() {
  124. if (!request()->isPost()) {
  125. $this->redirect('memberinformation/avatar');
  126. }
  127. $member_id = session('member_id');
  128. //上传图片
  129. if (!empty($_FILES['pic']['tmp_name'])) {
  130. $file_name = "avatar_" . session('member_id') . ".jpg";
  131. $res = ds_upload_pic(ATTACH_AVATAR, 'pic', $file_name);
  132. if ($res['code']) {
  133. $file_name = $res['data']['file_name'];
  134. model('member')->editMember(array('member_id' => session('member_id')), array('member_avatar' => $file_name), session('member_id'));
  135. session('avatar', $file_name);
  136. /* 设置买家当前菜单 */
  137. $this->setMemberCurMenu('member_information');
  138. /* 设置买家当前栏目 */
  139. $this->setMemberCurItem('avatar');
  140. View::assign('menu_sign', 'profile');
  141. View::assign('menu_sign_url', "{:(string)url('Memberinformation/index')}");
  142. View::assign('menu_sign1', 'avatar');
  143. return View::fetch($this->template_dir . 'avatar');
  144. } else {
  145. $this->error($res['msg']);
  146. }
  147. } else {
  148. $this->error(lang('upload_failed_replace_pictures'));
  149. }
  150. }
  151. /**
  152. * 更换头像
  153. *
  154. * @param
  155. * @return
  156. */
  157. public function avatar() {
  158. $member_info = model('member')->getMemberInfoByID(session('member_id'));
  159. View::assign('member_avatar', $member_info['member_avatar']);
  160. /* 设置买家当前菜单 */
  161. $this->setMemberCurMenu('member_information');
  162. /* 设置买家当前栏目 */
  163. $this->setMemberCurItem('avatar');
  164. View::assign('menu_sign', 'profile');
  165. View::assign('menu_sign_url', (string) url('Memberinformation/index'));
  166. View::assign('menu_sign1', 'avatar');
  167. View::assign('newfile', '');
  168. return View::fetch($this->template_dir . 'avatar');
  169. }
  170. /**
  171. * 用户中心右边,小导航
  172. *
  173. * @param string $menu_type 导航类型
  174. * @param string $menu_key 当前导航的menu_key
  175. * @return
  176. */
  177. public function getMemberItemList() {
  178. $menu_array = array(
  179. array(
  180. 'name' => 'member',
  181. 'text' => lang('home_member_base_infomation'),
  182. 'url' => (string) url('Memberinformation/index')
  183. ),
  184. array(
  185. 'name' => 'more',
  186. 'text' => lang('home_member_more'),
  187. 'url' => (string) url('Memberinformation/more')
  188. ),
  189. array(
  190. 'name' => 'avatar',
  191. 'text' => lang('home_member_modify_avatar'),
  192. 'url' => (string) url('Memberinformation/avatar')
  193. )
  194. );
  195. return $menu_array;
  196. }
  197. }