member_verify.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. /**
  3. * 管理员后台会员审核操作类
  4. */
  5. defined('IN_PHPCMS') or exit('No permission resources.');
  6. pc_base::load_app_class('admin', 'admin', 0);
  7. pc_base::load_sys_class('format', '', 0);
  8. class member_verify extends admin {
  9. private $db, $member_db;
  10. function __construct() {
  11. parent::__construct();
  12. $this->db = pc_base::load_model('member_verify_model');
  13. $this->_init_phpsso();
  14. }
  15. /**
  16. * defalut
  17. */
  18. function init() {
  19. include $this->admin_tpl('member_init');
  20. }
  21. /**
  22. * member list
  23. */
  24. function manage() {
  25. $status = !empty($_GET['s']) ? $_GET['s'] : 0;
  26. $where = array('status'=>$status);
  27. $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
  28. $memberlist = $this->db->listinfo($where, 'regdate DESC', $page, 10);
  29. $pages = $this->db->pages;
  30. $member_model = getcache('member_model', 'commons');
  31. include $this->admin_tpl('member_verify');
  32. }
  33. function modelinfo() {
  34. $userid = !empty($_GET['userid']) ? intval($_GET['userid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  35. $modelid = !empty($_GET['modelid']) ? intval($_GET['modelid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  36. $memberinfo = $this->db->get_one(array('userid'=>$userid));
  37. //模型字段名称
  38. $this->member_field_db = pc_base::load_model('sitemodel_field_model');
  39. $model_fieldinfo = $this->member_field_db->select(array('modelid'=>$modelid), "*", 100);
  40. //用户模型字段信息
  41. $member_fieldinfo = string2array($memberinfo['modelinfo']);
  42. //交换数组key值
  43. foreach($model_fieldinfo as $v) {
  44. if(array_key_exists($v['field'], $member_fieldinfo)) {
  45. $tmp = $member_fieldinfo[$v['field']];
  46. unset($member_fieldinfo[$v['field']]);
  47. $member_fieldinfo[$v['name']] = $tmp;
  48. unset($tmp);
  49. }
  50. }
  51. include $this->admin_tpl('member_verify_modelinfo');
  52. }
  53. /**
  54. * pass member
  55. */
  56. function pass() {
  57. if (isset($_POST['userid'])) {
  58. $this->member_db = pc_base::load_model('member_model');
  59. $uidarr = isset($_POST['userid']) ? $_POST['userid'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  60. $where = to_sqls($uidarr, '', 'userid');
  61. $userarr = $this->db->listinfo($where);
  62. $success_uids = $info = array();
  63. foreach($userarr as $v) {
  64. $status = $this->client->ps_member_register($v['username'], $v['password'], $v['email'], $v['regip'], $v['encrypt']);
  65. if ($status > 0) {
  66. $info['phpssouid'] = $status;
  67. $info['password'] = password($v['password'], $v['encrypt']);
  68. $info['regdate'] = $info['lastdate'] = $v['regdate'];
  69. $info['username'] = $v['username'];
  70. $info['nickname'] = $v['nickname'];
  71. $info['email'] = $v['email'];
  72. $info['regip'] = $v['regip'];
  73. $info['point'] = $v['point'];
  74. $info['groupid'] = $this->_get_usergroup_bypoint($v['point']);
  75. $info['amount'] = $v['amount'];
  76. $info['encrypt'] = $v['encrypt'];
  77. $info['modelid'] = $v['modelid'] ? $v['modelid'] : 10;
  78. if($v['mobile']) $info['mobile'] = $v['mobile'];
  79. $userid = $this->member_db->insert($info, 1);
  80. if($v['modelinfo']) { //如果数据模型不为空
  81. //插入会员模型数据
  82. $user_model_info = string2array($v['modelinfo']);
  83. $user_model_info['userid'] = $userid;
  84. $this->member_db->set_model($info['modelid']);
  85. $this->member_db->insert($user_model_info);
  86. }
  87. if($userid) {
  88. $success_uids[] = $v['userid'];
  89. }
  90. }
  91. }
  92. $where = to_sqls($success_uids, '', 'userid');
  93. $this->db->update(array('status'=>1, 'message'=>$_POST['message']), $where);
  94. //phpsso注册失败的用户状态直接置为审核期间phpsso已注册该会员
  95. $fail_uids = array_diff($uidarr, $success_uids);
  96. if (!empty($fail_uids)) {
  97. $where = to_sqls($fail_uids, '', 'userid');
  98. $this->db->update(array('status'=>5, 'message'=>$_POST['message']), $where);
  99. }
  100. //发送 email通知
  101. if($_POST['sendemail']) {
  102. $memberinfo = $this->db->select($where);
  103. pc_base::load_sys_func('mail');
  104. foreach ($memberinfo as $v) {
  105. sendmail($v['email'], L('reg_pass'), $_POST['message']);
  106. }
  107. }
  108. showmessage(L('pass').L('operation_success'), HTTP_REFERER);
  109. } else {
  110. showmessage(L('operation_failure'), HTTP_REFERER);
  111. }
  112. }
  113. /**
  114. * delete member
  115. */
  116. function delete() {
  117. if(isset($_POST['userid'])) {
  118. $uidarr = isset($_POST['userid']) ? $_POST['userid'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  119. $message = stripslashes($_POST['message']);
  120. $where = to_sqls($uidarr, '', 'userid');
  121. $this->db->delete($where);
  122. showmessage(L('delete').L('operation_success'), HTTP_REFERER);
  123. } else {
  124. showmessage(L('operation_failure'), HTTP_REFERER);
  125. }
  126. }
  127. /**
  128. * reject member
  129. */
  130. function reject() {
  131. if(isset($_POST['userid'])) {
  132. $uidarr = isset($_POST['userid']) ? $_POST['userid'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  133. $where = to_sqls($uidarr, '', 'userid');
  134. $res = $this->db->update(array('status'=>4, 'message'=>$_POST['message']), $where);
  135. //发送 email通知
  136. if($res) {
  137. if($_POST['sendemail']) {
  138. $memberinfo = $this->db->select($where);
  139. pc_base::load_sys_func('mail');
  140. foreach ($memberinfo as $v) {
  141. sendmail($v['email'], L('reg_reject'), $_POST['message']);
  142. }
  143. }
  144. }
  145. showmessage(L('reject').L('operation_success'), HTTP_REFERER);
  146. } else {
  147. showmessage(L('operation_failure'), HTTP_REFERER);
  148. }
  149. }
  150. /**
  151. * ignore member
  152. */
  153. function ignore() {
  154. if(isset($_POST['userid'])) {
  155. $uidarr = isset($_POST['userid']) ? $_POST['userid'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  156. $where = to_sqls($uidarr, '', 'userid');
  157. $res = $this->db->update(array('status'=>2, 'message'=>$_POST['message']), $where);
  158. //发送 email通知
  159. if($res) {
  160. if($_POST['sendemail']) {
  161. $memberinfo = $this->db->select($where);
  162. pc_base::load_sys_func('mail');
  163. foreach ($memberinfo as $v) {
  164. sendmail($v['email'], L('reg_ignore'), $_POST['message']);
  165. }
  166. }
  167. }
  168. showmessage(L('ignore').L('operation_success'), HTTP_REFERER);
  169. } else {
  170. showmessage(L('operation_failure'), HTTP_REFERER);
  171. }
  172. }
  173. /*
  174. * change password
  175. */
  176. function _edit_password($userid, $password){
  177. $userid = intval($userid);
  178. if($userid < 1) return false;
  179. if(!is_password($password))
  180. {
  181. showmessage(L('password_format_incorrect'));
  182. return false;
  183. }
  184. $passwordinfo = password($password);
  185. return $this->db->update($passwordinfo,array('userid'=>$userid));
  186. }
  187. private function _checkuserinfo($data, $is_edit=0) {
  188. if(!is_array($data)){
  189. showmessage(L('need_more_param'));return false;
  190. } elseif (!is_username($data['username']) && !$is_edit){
  191. showmessage(L('username_format_incorrect'));return false;
  192. } elseif (!isset($data['userid']) && $is_edit) {
  193. showmessage(L('username_format_incorrect'));return false;
  194. } elseif (empty($data['email']) || !is_email($data['email'])){
  195. showmessage(L('email_format_incorrect'));return false;
  196. }
  197. return $data;
  198. }
  199. private function _checkpasswd($password){
  200. if (!is_password($password)){
  201. return false;
  202. }
  203. return true;
  204. }
  205. private function _checkname($username) {
  206. $username = trim($username);
  207. if ($this->db->get_one(array('username'=>$username))){
  208. return false;
  209. }
  210. return true;
  211. }
  212. /**
  213. *根据积分算出用户组
  214. * @param $point int 积分数
  215. */
  216. private function _get_usergroup_bypoint($point=0) {
  217. $groupid = 2;
  218. if(empty($point)) {
  219. $member_setting = getcache('member_setting');
  220. $point = $member_setting['defualtpoint'] ? $member_setting['defualtpoint'] : 0;
  221. }
  222. $grouplist = getcache('grouplist');
  223. foreach ($grouplist as $k=>$v) {
  224. $grouppointlist[$k] = $v['point'];
  225. }
  226. arsort($grouppointlist);
  227. //如果超出用户组积分设置则为积分最高的用户组
  228. if($point > max($grouppointlist)) {
  229. $groupid = key($grouppointlist);
  230. } else {
  231. foreach ($grouppointlist as $k=>$v) {
  232. if($point >= $v) {
  233. $groupid = $tmp_k;
  234. break;
  235. }
  236. $tmp_k = $k;
  237. }
  238. }
  239. return $groupid;
  240. }
  241. /**
  242. * 初始化phpsso
  243. * about phpsso, include client and client configure
  244. * @return string phpsso_api_url phpsso地址
  245. */
  246. private function _init_phpsso() {
  247. pc_base::load_app_class('client', '', 0);
  248. define('APPID', pc_base::load_config('system', 'phpsso_appid'));
  249. $phpsso_api_url = pc_base::load_config('system', 'phpsso_api_url');
  250. $phpsso_auth_key = pc_base::load_config('system', 'phpsso_auth_key');
  251. $this->client = new client($phpsso_api_url, $phpsso_auth_key);
  252. return $phpsso_api_url;
  253. }
  254. /**
  255. * check uername status
  256. */
  257. public function checkname_ajax() {
  258. $username = isset($_GET['username']) && trim($_GET['username']) ? trim($_GET['username']) : exit(0);
  259. $username = iconv('utf-8', CHARSET, $username);
  260. $status = $this->client->ps_checkname($username);
  261. if($status == -4) { //deny_register
  262. exit('0');
  263. }
  264. $status = $this->client->ps_get_member_info($username, 2);
  265. if (is_array($status)) {
  266. exit('0');
  267. } else {
  268. exit('1');
  269. }
  270. }
  271. /**
  272. * check email status
  273. */
  274. public function checkemail_ajax() {
  275. $email = isset($_GET['email']) && trim($_GET['email']) ? trim($_GET['email']) : exit(0);
  276. $status = $this->client->ps_checkemail($email);
  277. if($status == -5) { //deny_register
  278. exit('0');
  279. }
  280. $status = $this->client->ps_get_member_info($email, 3);
  281. if(isset($_GET['phpssouid']) && isset($status['uid'])) {
  282. if ($status['uid'] == intval($_GET['phpssouid'])) {
  283. exit('1');
  284. }
  285. }
  286. if (is_array($status)) {
  287. exit('0');
  288. } else {
  289. exit('1');
  290. }
  291. }
  292. }
  293. ?>