Member.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Db;
  5. use think\facade\Lang;
  6. /**
  7. *
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 控制器
  12. */
  13. class Member extends AdminControl
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/member.lang.php');
  19. }
  20. public function member()
  21. {
  22. $member_model = model('member');
  23. //会员级别
  24. $member_grade = $member_model->getMemberGradeArr();
  25. $search_field_value = input('search_field_value');
  26. $search_field_name = input('search_field_name');
  27. $condition = array();
  28. if ($search_field_value != '') {
  29. switch ($search_field_name) {
  30. case 'member_name':
  31. $condition[] = array('member_name', 'like', '%' . trim($search_field_value) . '%');
  32. break;
  33. case 'member_email':
  34. $condition[] = array('member_email', 'like', '%' . trim($search_field_value) . '%');
  35. break;
  36. case 'member_mobile':
  37. $condition[] = array('member_mobile', 'like', '%' . trim($search_field_value) . '%');
  38. break;
  39. case 'member_truename':
  40. $condition[] = array('member_truename', 'like', '%' . trim($search_field_value) . '%');
  41. break;
  42. }
  43. }
  44. $search_state = input('search_state');
  45. switch ($search_state) {
  46. case 'no_informallow':
  47. $condition[] = array('inform_allow', '=', '2');
  48. break;
  49. case 'no_isbuy':
  50. $condition[] = array('is_buylimit', '=', '0');
  51. break;
  52. case 'no_isallowtalk':
  53. $condition[] = array('is_allowtalk', '=', '0');
  54. break;
  55. case 'no_memberstate':
  56. $condition[] = array('member_state', '=', '0');
  57. break;
  58. }
  59. //会员等级
  60. $search_grade = intval(input('get.search_grade'));
  61. if ($search_grade > 0 && $member_grade) {
  62. if (isset($member_grade[$search_grade + 1]['exppoints'])) {
  63. $condition[] = array('member_exppoints', 'between', array($member_grade[$search_grade]['exppoints'], $member_grade[$search_grade + 1]['exppoints']));
  64. } else {
  65. $condition[] = array('member_exppoints', '>=', $member_grade[$search_grade]['exppoints']);
  66. }
  67. }
  68. //排序
  69. $order = trim(input('get.search_sort'));
  70. if (!in_array($order, array('member_logintime desc', 'member_loginnum desc'))) {
  71. $order = 'member_id desc';
  72. }
  73. $member_list = $member_model->getMemberList($condition, '*', 10, $order);
  74. //整理会员信息
  75. if (is_array($member_list) && !empty($member_list)) {
  76. foreach ($member_list as $k => $v) {
  77. $member_list[$k]['member_addtime'] = $v['member_addtime'] ? date('Y-m-d H:i:s', $v['member_addtime']) : '';
  78. $member_list[$k]['member_logintime'] = $v['member_logintime'] ? date('Y-m-d H:i:s', $v['member_logintime']) : '';
  79. $member_list[$k]['member_grade'] = ($t = $member_model->getOneMemberGrade($v['member_exppoints'], false, $member_grade)) ? $t['level_name'] : '';
  80. }
  81. }
  82. View::assign('member_grade', $member_grade);
  83. View::assign('search_sort', $order);
  84. View::assign('search_field_name', trim($search_field_name));
  85. View::assign('search_field_value', trim($search_field_value));
  86. View::assign('member_list', $member_list);
  87. View::assign('show_page', $member_model->page_info->render());
  88. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  89. $this->setAdminCurItem('member');
  90. return View::fetch();
  91. }
  92. public function add()
  93. {
  94. if (!request()->isPost()) {
  95. return View::fetch();
  96. } else {
  97. //需要完善地方 1.对录入数据进行判断 2.对判断用户名是否存在
  98. $member_model = model('member');
  99. $data = array(
  100. 'member_name' => trim(input('post.member_name')),
  101. 'member_password' => input('post.member_password'),
  102. 'member_email' => input('post.member_email'),
  103. 'member_truename' => input('post.member_truename'),
  104. 'member_sex' => input('post.member_sex'),
  105. 'member_qq' => input('post.member_qq'),
  106. 'member_ww' => input('post.member_ww'),
  107. 'member_addtime' => TIMESTAMP,
  108. 'member_loginnum' => 0,
  109. 'inform_allow' => 1, //默认允许举报商品
  110. );
  111. $member_validate = ds_validate('member');
  112. if (!$member_validate->scene('add')->check($data)) {
  113. $this->error($member_validate->getError());
  114. }
  115. $result = $member_model->addMember($data);
  116. if ($result) {
  117. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  118. } else {
  119. $this->error(lang('member_add_fail'));
  120. }
  121. }
  122. }
  123. public function edit()
  124. {
  125. //注:pathinfo地址参数不能通过get方法获取,查看“获取PARAM变量”
  126. $member_id = intval(input('param.member_id'));
  127. if (empty($member_id)) {
  128. $this->error(lang('param_error'));
  129. }
  130. $member_model = model('member');
  131. $condition = array();
  132. $condition[] = array('member_id', '=', $member_id);
  133. $member_array = $member_model->getMemberInfo($condition);
  134. if (!request()->isPost()) {
  135. View::assign('member_array', $member_array);
  136. return View::fetch();
  137. } else {
  138. $member_mobile = input('post.member_mobile');
  139. if ($member_mobile == encrypt_show($member_array['member_mobile'], 4, 4)) {
  140. $member_mobile = $member_array['member_mobile'];
  141. }
  142. $data = array(
  143. 'member_email' => input('post.member_email'),
  144. 'member_truename' => input('post.member_truename'),
  145. 'member_sex' => input('post.member_sex'),
  146. 'member_qq' => input('post.member_qq'),
  147. 'member_ww' => input('post.member_ww'),
  148. 'inform_allow' => input('post.inform_allow'),
  149. 'is_buylimit' => input('post.isbuy'),
  150. 'is_allowtalk' => input('post.allowtalk'),
  151. 'member_state' => input('post.member_state'),
  152. 'member_cityid' => input('post.city_id'),
  153. 'member_provinceid' => input('post.province_id'),
  154. 'member_areainfo' => input('post.region'),
  155. 'member_areaid' => input('post.area_id'),
  156. 'member_mobile' => $member_mobile,
  157. 'member_emailbind' => input('post.member_emailbind'),
  158. 'member_mobilebind' => input('post.member_mobilebind'),
  159. 'member_auth_state' => input('post.member_auth_state'),
  160. );
  161. if (input('post.member_password')) {
  162. $data['member_password'] = md5(input('post.member_password'));
  163. }
  164. if (input('post.member_paypwd')) {
  165. $data['member_paypwd'] = md5(input('post.member_paypwd'));
  166. }
  167. $member_validate = ds_validate('member');
  168. if (!$member_validate->scene('edit')->check($data)) {
  169. $this->error($member_validate->getError());
  170. }
  171. $result = $member_model->editMember(array('member_id' => $member_id), $data, $member_id);
  172. if ($result >= 0) {
  173. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  174. } else {
  175. $this->error(lang('ds_common_op_fail'));
  176. }
  177. }
  178. }
  179. /**
  180. * ajax操作
  181. */
  182. public function ajax()
  183. {
  184. $branch = input('param.branch');
  185. $condition = array();
  186. switch ($branch) {
  187. /**
  188. * 验证会员是否重复
  189. */
  190. case 'check_user_name':
  191. $member_model = model('member');
  192. $condition[] = array('member_name', '=', input('param.member_name'));
  193. $condition[] = array('member_id', '<>', intval(input('get.member_id')));
  194. $list = $member_model->getMemberInfo($condition);
  195. if (empty($list)) {
  196. echo 'true';
  197. exit;
  198. } else {
  199. echo 'false';
  200. exit;
  201. }
  202. break;
  203. /**
  204. * 验证邮件是否重复
  205. */
  206. case 'check_email':
  207. $member_model = model('member');
  208. $condition[] = array('member_email', '=', input('param.member_email'));
  209. $condition[] = array('member_id', '<>', intval(input('param.member_id')));
  210. $list = $member_model->getMemberInfo($condition);
  211. if (empty($list)) {
  212. echo 'true';
  213. exit;
  214. } else {
  215. echo 'false';
  216. exit;
  217. }
  218. break;
  219. }
  220. }
  221. /**
  222. * 设置会员状态
  223. */
  224. public function memberstate()
  225. {
  226. $member_id = input('param.member_id');
  227. $member_id_array = ds_delete_param($member_id);
  228. if ($member_id_array == FALSE) {
  229. ds_json_encode('10001', lang('param_error'));
  230. }
  231. $data['member_state'] = input('param.member_state') ? input('param.member_state') : 0;
  232. $condition = array();
  233. $condition[] = array('member_id', 'in', $member_id_array);
  234. $result = Db::name('member')->where($condition)->update($data);
  235. if ($result >= 0) {
  236. foreach ($member_id_array as $key => $member_id) {
  237. dcache($member_id, 'member');
  238. }
  239. $this->log(lang('ds_edit') . '[ID:' . implode(',', $member_id_array) . ']', 1);
  240. ds_json_encode('10000', lang('ds_common_op_succ'));
  241. } else {
  242. ds_json_encode('10001', lang('ds_common_op_fail'));
  243. }
  244. }
  245. /**
  246. * 获取卖家栏目列表,针对控制器下的栏目
  247. */
  248. protected function getAdminItemList()
  249. {
  250. $menu_array = array(
  251. array(
  252. 'name' => 'member',
  253. 'text' => lang('ds_manage'),
  254. 'url' => (string)url('Member/member')
  255. ),
  256. );
  257. if (request()->action() == 'add' || request()->action() == 'member') {
  258. $menu_array[] = array(
  259. 'name' => 'add',
  260. 'text' => lang('ds_add'),
  261. 'url' => "javascript:dsLayerOpen('" . (string)url('Member/add') . "','" . lang('ds_add') . "')"
  262. );
  263. }
  264. return $menu_array;
  265. }
  266. }