Memberinformation.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 控制器
  12. */
  13. class Memberinformation extends BaseMember
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize(); // TODO: Change the autogenerated stub
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberhome.lang.php');
  19. }
  20. /**
  21. * 我的资料【用户中心】
  22. *
  23. * @param
  24. * @return
  25. */
  26. public function index()
  27. {
  28. $member_model = model('member');
  29. if (request()->isPost()) {
  30. $member_array = array();
  31. $member_array['member_nickname'] = input('post.member_nickname');
  32. $member_array['member_sex'] = input('post.member_sex');
  33. $member_array['member_qq'] = input('post.member_qq');
  34. $member_array['member_ww'] = input('post.member_ww');
  35. $member_array['member_areaid'] = input('post.area_id');
  36. $member_array['member_cityid'] = input('post.city_id');
  37. $member_array['member_provinceid'] = input('post.province_id');
  38. $member_array['member_areainfo'] = input('post.area_info');
  39. if (strlen(input('post.birthday')) == 10) {
  40. $member_array['member_birthday'] = strtotime(input('post.birthday'));
  41. }
  42. $member_array['member_privacy'] = serialize(input('post.privacy/a'));
  43. $update = $member_model->editMember(array('member_id' => session('member_id')), $member_array, session('member_id'));
  44. $message = $update ? lang('ds_common_save_succ') : lang('ds_common_save_fail');
  45. if ($update) {
  46. ds_json_encode(10000, $message);
  47. } else {
  48. ds_json_encode(10001, $message);
  49. }
  50. }
  51. if ($this->member_info['member_privacy'] != '') {
  52. $this->member_info['member_privacy'] = unserialize($this->member_info['member_privacy']);
  53. } else {
  54. $this->member_info['member_privacy'] = array();
  55. }
  56. View::assign('member_info', $this->member_info);
  57. /* 设置买家当前菜单 */
  58. $this->setMemberCurMenu('member_information');
  59. /* 设置买家当前栏目 */
  60. $this->setMemberCurItem('member');
  61. View::assign('menu_sign', 'profile');
  62. View::assign('menu_sign_url', (string) url('Memberinformation/index'));
  63. View::assign('menu_sign1', 'baseinfo');
  64. return View::fetch($this->template_dir . 'index');
  65. }
  66. /**
  67. * 我的资料【更多个人资料】
  68. *
  69. * @param
  70. * @return
  71. */
  72. public function more()
  73. {
  74. if (request()->isPost()) {
  75. Db::name('snsmtagmember')->where(array('member_id' => session('member_id')))->delete();
  76. $mid_array = input('post.mid/a');
  77. if (!empty($mid_array)) {
  78. $insert_array = array();
  79. foreach ($mid_array as $val) {
  80. $insert_array[] = array(
  81. 'mtag_id' => intval($val),
  82. 'member_id' => session('member_id')
  83. );
  84. }
  85. Db::name('snsmtagmember')->insertAll($insert_array);
  86. }
  87. ds_json_encode(10000, lang('ds_common_op_succ'));
  88. }
  89. // 用户标签列表
  90. $mtag_array = Db::name('snsmembertag')->order('mtag_sort asc')->select()->toArray();
  91. // 用户已添加标签列表。
  92. $mtm_array = Db::name('snsmtagmember')->where(array('member_id' => session('member_id')))->select()->toArray();
  93. $mtag_list = array();
  94. $mtm_list = array();
  95. if (!empty($mtm_array) && is_array($mtm_array)) {
  96. // 整理
  97. $elect_array = array();
  98. foreach ($mtm_array as $val) {
  99. $elect_array[] = $val['mtag_id'];
  100. }
  101. foreach ((array) $mtag_array as $val) {
  102. if (in_array($val['mtag_id'], $elect_array)) {
  103. $mtm_list[] = $val;
  104. } else {
  105. $mtag_list[] = $val;
  106. }
  107. }
  108. } else {
  109. $mtag_list = $mtag_array;
  110. }
  111. View::assign('mtag_list', $mtag_list);
  112. View::assign('mtm_list', $mtm_list);
  113. /* 设置买家当前菜单 */
  114. $this->setMemberCurMenu('member_information');
  115. /* 设置买家当前栏目 */
  116. $this->setMemberCurItem('more');
  117. View::assign('menu_sign', 'profile');
  118. View::assign('menu_sign_url', (string) url('Memberinformation/index'));
  119. View::assign('menu_sign1', 'baseinfo');
  120. return View::fetch($this->template_dir . 'more');
  121. }
  122. public function upload()
  123. {
  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. {
  159. $member_info = model('member')->getMemberInfoByID(session('member_id'));
  160. View::assign('member_avatar', $member_info['member_avatar']);
  161. /* 设置买家当前菜单 */
  162. $this->setMemberCurMenu('member_information');
  163. /* 设置买家当前栏目 */
  164. $this->setMemberCurItem('avatar');
  165. View::assign('menu_sign', 'profile');
  166. View::assign('menu_sign_url', (string) url('Memberinformation/index'));
  167. View::assign('menu_sign1', 'avatar');
  168. View::assign('newfile', '');
  169. return View::fetch($this->template_dir . 'avatar');
  170. }
  171. /**
  172. * 用户中心右边,小导航
  173. *
  174. * @param string $menu_type 导航类型
  175. * @param string $menu_key 当前导航的menu_key
  176. * @return
  177. */
  178. public function getMemberItemList()
  179. {
  180. $menu_array = array(
  181. array(
  182. 'name' => 'member',
  183. 'text' => lang('home_member_base_infomation'),
  184. 'url' => (string) url('Memberinformation/index')
  185. ),
  186. array(
  187. 'name' => 'more',
  188. 'text' => lang('home_member_more'),
  189. 'url' => (string) url('Memberinformation/more')
  190. ),
  191. array(
  192. 'name' => 'avatar',
  193. 'text' => lang('home_member_modify_avatar'),
  194. 'url' => (string) url('Memberinformation/avatar')
  195. )
  196. );
  197. return $menu_array;
  198. }
  199. }