Member.php 11 KB

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