Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Member.php 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 陈风任 <491085389@qq.com>
  11. * Date: 2019-2-20
  12. */
  13. namespace app\admin\model;
  14. use think\Db;
  15. use think\Model;
  16. /**
  17. * 会员
  18. */
  19. class Member extends Model
  20. {
  21. public $name = 'users';
  22. private $admin_lang = 'cn';
  23. //初始化
  24. protected function initialize()
  25. {
  26. // 需要调用`Model`的`initialize`方法
  27. parent::initialize();
  28. $this->admin_lang = get_admin_lang();
  29. }
  30. // 判断会员属性中必填项是否为空
  31. // 传入参数:
  32. // $post_users:会员属性信息数组
  33. // return 为空项
  34. public function isEmpty($post_users = [])
  35. {
  36. if (empty($post_users)) {
  37. return false;
  38. }
  39. // 会员属性
  40. $where = array(
  41. 'lang' => $this->admin_lang,
  42. 'is_hidden' => 0, // 是否隐藏属性,0为否
  43. 'is_required' => 1, // 是否必填属性,1为是
  44. );
  45. $para_data =Db::name('users_parameter')->where($where)->field('title,name')->select();
  46. // 判断提交的属性中必填项是否为空
  47. foreach ($para_data as $value) {
  48. if (isset($post_users[$value['name']])) {
  49. $attr_value = trim($post_users[$value['name']]);
  50. if (empty($attr_value)) {
  51. return $value['title'].'不能为空!';;
  52. }
  53. }
  54. }
  55. }
  56. // 判断邮箱和手机是否存在
  57. // 传入参数:
  58. // $post_users:会员属性信息数组
  59. // $users_id:会员ID,注册时不需要传入,修改时需要传入。
  60. // return 存在项
  61. public function isRequired($post_users = [],$users_id=0)
  62. {
  63. if (empty($post_users)) {
  64. return false;
  65. }
  66. // 匹配手机和邮箱数据
  67. $where_1 = [
  68. 'is_system'=> 1,
  69. 'lang' => $this->admin_lang,
  70. ];
  71. $where_1[] = Db::raw(" ( name LIKE 'email_%' OR name LIKE 'mobile_%' ) ");
  72. $users_parameter = Db::name('users_parameter')->where($where_1)->field('para_id,title,name')->getAllWithIndex('name');
  73. // 判断手机和邮箱格式是否正确
  74. foreach ($post_users as $key => $val) {
  75. if (preg_match('/^email_/i', $key)) {
  76. if (!empty($val) && !check_email($val)) {
  77. return $users_parameter[$key]['title'].'格式不正确!';
  78. }
  79. } else if (preg_match('/^mobile_/i', $key)) {
  80. if (!empty($val) && !check_mobile($val)) {
  81. return $users_parameter[$key]['title'].'格式不正确!';
  82. }
  83. }
  84. }
  85. // 判断手机和邮箱是否已存在
  86. foreach ($users_parameter as $key => $value) {
  87. if (isset($post_users[$value['name']])) {
  88. $where_2 = [
  89. 'para_id' => ['EQ', $value['para_id']],
  90. 'info' => trim($post_users[$value['name']]),
  91. 'users_id' => ['NEQ', $users_id],
  92. 'lang' => $this->admin_lang,
  93. ];
  94. // 若users_id为空,则清除条件中的users_id条件
  95. if (empty($users_id)) { unset($where_2['users_id']); }
  96. $users_list = Db::name('users_list')->where($where_2)->field('info')->find();
  97. if (!empty($users_list['info'])) {
  98. return $value['title'].'已存在!';
  99. }
  100. }
  101. }
  102. }
  103. // 查询会员属性信息表的邮箱和手机字段
  104. // 必须传入参数:
  105. // users_id 会员ID
  106. // field 查询字段,email仅邮箱,mobile仅手机号,*为两项都查询。
  107. // return Data
  108. public function getUsersListData($field,$users_id)
  109. {
  110. $Data = array();
  111. if ('email' == $field || '*' == $field) {
  112. // 查询邮箱
  113. $parawhere = [
  114. 'name' => ['LIKE', "email_%"],
  115. 'is_system' => 1,
  116. 'lang' => $this->admin_lang,
  117. ];
  118. $paraData = Db::name('users_parameter')->where($parawhere)->field('para_id')->find();
  119. $listwhere = [
  120. 'para_id' => $paraData['para_id'],
  121. 'users_id' => $users_id,
  122. 'lang' => $this->admin_lang,
  123. ];
  124. $listData = Db::name('users_list')->where($listwhere)->field('users_id,info')->find();
  125. $Data['email'] = !empty($listData['info']) ? $listData['info'] : '';
  126. $Data['is_email'] = !empty($Data['email']) ? 1 : 0;
  127. }
  128. if ('mobile' == $field || '*' == $field) {
  129. // 查询手机号
  130. $parawhere_1 = [
  131. 'name' => ['LIKE', "mobile_%"],
  132. 'is_system' => 1,
  133. 'lang' => $this->admin_lang,
  134. ];
  135. $paraData_1 = Db::name('users_parameter')->where($parawhere_1)->field('para_id')->find();
  136. $listwhere_1 = [
  137. 'para_id' => $paraData_1['para_id'],
  138. 'users_id' => $users_id,
  139. 'lang' => $this->admin_lang,
  140. ];
  141. $listData_1 = Db::name('users_list')->where($listwhere_1)->field('users_id,info')->find();
  142. $Data['mobile'] = !empty($listData_1['info']) ? $listData_1['info'] : '';
  143. $Data['is_mobile'] = !empty($Data['mobile']) ? 1 : 0;
  144. }
  145. return $Data;
  146. }
  147. /**
  148. * 查询解析数据表的数据用以构造from表单
  149. * @author 陈风任 by 2019-2-20
  150. */
  151. public function getDataPara()
  152. {
  153. // 字段及内容数据处理
  154. $where = array(
  155. 'lang' => $this->admin_lang,
  156. 'is_hidden' => 0, // 是否隐藏属性,0为否
  157. );
  158. $row =Db::name('users_parameter')->field('*')
  159. ->where($where)
  160. ->order('sort_order asc,para_id asc')
  161. ->select();
  162. // 根据所需数据格式,拆分成一维数组
  163. $addonRow = array();
  164. // 根据不同字段类型封装数据
  165. $list = $this->showViewFormData($row, 'users_', $addonRow);
  166. return $list;
  167. }
  168. /**
  169. * 查询解析数据表的数据用以构造from表单
  170. * @author 陈风任 by 2019-2-20
  171. */
  172. public function getDataParaList($users_id)
  173. {
  174. // 字段及内容数据处理
  175. $row = Db::name('users_parameter')->field('a.*,b.info,b.users_id')
  176. ->alias('a')
  177. ->join('__USERS_LIST__ b', "a.para_id = b.para_id AND b.users_id = {$users_id}", 'LEFT')
  178. ->where([
  179. 'a.lang' => $this->admin_lang,
  180. 'a.is_hidden' => 0, // 是否隐藏属性,0为否
  181. ])
  182. ->order('a.sort_order asc,a.para_id asc')
  183. ->select();
  184. // 根据所需数据格式,拆分成一维数组
  185. $addonRow = [];
  186. foreach ($row as $key => $val) {
  187. $addonRow[$val['name']] = $val['info'];
  188. }
  189. // 根据不同字段类型封装数据
  190. $list = $this->showViewFormData($row, 'users_', $addonRow);
  191. return $list;
  192. }
  193. /**
  194. * 处理页面显示字段的表单数据
  195. * @param array $list 字段列表
  196. * @param array $formFieldStr 表单元素名称的统一数组前缀
  197. * @param array $addonRow 字段的数据
  198. * @author 陈风任 by 2019-2-20
  199. */
  200. public function showViewFormData($list, $formFieldStr, $addonRow = array())
  201. {
  202. if (!empty($list)) {
  203. foreach ($list as $key => $val) {
  204. $val['fieldArr'] = $formFieldStr;
  205. switch ($val['dtype']) {
  206. case 'int':
  207. {
  208. if (isset($addonRow[$val['name']])) {
  209. $val['dfvalue'] = $addonRow[$val['name']];
  210. } else {
  211. if(preg_match("#[^0-9]#", $val['dfvalue']))
  212. {
  213. $val['dfvalue'] = "";
  214. }
  215. }
  216. break;
  217. }
  218. case 'float':
  219. case 'decimal':
  220. {
  221. if (isset($addonRow[$val['name']])) {
  222. $val['dfvalue'] = $addonRow[$val['name']];
  223. } else {
  224. if(preg_match("#[^0-9\.]#", $val['dfvalue']))
  225. {
  226. $val['dfvalue'] = "";
  227. }
  228. }
  229. break;
  230. }
  231. case 'select':
  232. {
  233. $dfvalue = $val['dfvalue'];
  234. $dfvalueArr = explode(',', $dfvalue);
  235. $val['dfvalue'] = $dfvalueArr;
  236. if (isset($addonRow[$val['name']])) {
  237. $val['trueValue'] = explode(',', $addonRow[$val['name']]);
  238. } else {
  239. $dfTrueValue = !empty($dfvalueArr[0]) ? $dfvalueArr[0] : '';
  240. $val['trueValue'] = array();
  241. }
  242. break;
  243. }
  244. case 'radio':
  245. {
  246. $dfvalue = $val['dfvalue'];
  247. $dfvalueArr = explode(',', $dfvalue);
  248. $val['dfvalue'] = $dfvalueArr;
  249. if (isset($addonRow[$val['name']])) {
  250. $val['trueValue'] = explode(',', $addonRow[$val['name']]);
  251. } else {
  252. $dfTrueValue = !empty($dfvalueArr[0]) ? $dfvalueArr[0] : '';
  253. $val['trueValue'] = array($dfTrueValue);
  254. }
  255. break;
  256. }
  257. case 'checkbox':
  258. {
  259. $dfvalue = $val['dfvalue'];
  260. $dfvalueArr = explode(',', $dfvalue);
  261. $val['dfvalue'] = $dfvalueArr;
  262. if (isset($addonRow[$val['name']])) {
  263. $val['trueValue'] = explode(',', $addonRow[$val['name']]);
  264. } else {
  265. $val['trueValue'] = array();
  266. }
  267. break;
  268. }
  269. case 'img':
  270. {
  271. $val['dfvalue'] = handle_subdir_pic($addonRow[$val['name']]);
  272. break;
  273. }
  274. case 'imgs':
  275. {
  276. $val[$val['name'].'_eyou_imgupload_list'] = array();
  277. if (isset($addonRow[$val['name']]) && !empty($addonRow[$val['name']])) {
  278. $eyou_imgupload_list = explode(',', $addonRow[$val['name']]);
  279. /*支持子目录*/
  280. foreach ($eyou_imgupload_list as $k1 => $v1) {
  281. $eyou_imgupload_list[$k1] = handle_subdir_pic($v1);
  282. }
  283. /*--end*/
  284. $val[$val['name'].'_eyou_imgupload_list'] = $eyou_imgupload_list;
  285. }
  286. break;
  287. }
  288. case 'datetime':
  289. {
  290. if (!empty($addonRow[$val['name']])) {
  291. if (is_numeric($addonRow[$val['name']])) {
  292. $val['dfvalue'] = date('Y-m-d H:i:s', $addonRow[$val['name']]);
  293. } else {
  294. $val['dfvalue'] = $addonRow[$val['name']];
  295. }
  296. } else {
  297. $val['dfvalue'] = date('Y-m-d H:i:s');
  298. }
  299. break;
  300. }
  301. case 'htmltext':
  302. {
  303. $val['dfvalue'] = isset($addonRow[$val['name']]) ? $addonRow[$val['name']] : $val['dfvalue'];
  304. /*支持子目录*/
  305. $val['dfvalue'] = handle_subdir_pic($val['dfvalue'], 'html');
  306. /*--end*/
  307. break;
  308. }
  309. case 'file':
  310. {
  311. $ext = tpCache('basic.file_type');
  312. $val['ext'] = !empty($ext) ? $ext : "zip|gz|rar|iso|doc|xls|ppt|wps";
  313. $val['filesize'] = upload_max_filesize();
  314. break;
  315. }
  316. default:
  317. {
  318. $val['dfvalue'] = isset($addonRow[$val['name']]) ? $addonRow[$val['name']] : $val['dfvalue'];
  319. /*支持子目录*/
  320. if (is_string($val['dfvalue'])) {
  321. $val['dfvalue'] = handle_subdir_pic($val['dfvalue'], 'html');
  322. $val['dfvalue'] = handle_subdir_pic($val['dfvalue']);
  323. }
  324. /*--end*/
  325. break;
  326. }
  327. }
  328. $list[$key] = $val;
  329. }
  330. }
  331. return $list;
  332. }
  333. /**
  334. * 后置操作方法
  335. * 自定义的一个函数 用于数据删除之后做的相应处理操作, 使用时手动调用
  336. */
  337. public function afterDel($users_ids = [])
  338. {
  339. if (!empty($users_ids)) {
  340. eyou_statistics_data(4, count($users_ids), '', 'dec');//统计新增会员数
  341. try {
  342. /*同步删除会员投稿数据*/
  343. Db::name('archives')->where("users_id",'IN',$users_ids)->delete();
  344. /*同步删除文章订单表数据*/
  345. Db::name('article_order')->where("users_id",'IN',$users_ids)->delete();
  346. /*同步删除内置问答表数据*/
  347. Db::name('ask')->where("users_id",'IN',$users_ids)->delete();
  348. /*同步删除内置问答表数据*/
  349. Db::name('ask_answer')->where("users_id",'IN',$users_ids)->delete();
  350. /*同步删除问答点赞表数据*/
  351. Db::name('ask_answer_like')->where("users_id",'IN',$users_ids)->delete();
  352. /*同步删除下载记录表数据*/
  353. Db::name('download_log')->where("users_id",'IN',$users_ids)->delete();
  354. /*同步删除下载订单表数据*/
  355. Db::name('download_order')->where("users_id",'IN',$users_ids)->delete();
  356. /*同步删除留言表数据*/
  357. Db::name('guestbook')->where("users_id",'IN',$users_ids)->delete();
  358. /*同步删除视频播放记录表数据*/
  359. Db::name('media_log')->where("users_id",'IN',$users_ids)->delete();
  360. /*同步删除视频订单表数据*/
  361. Db::name('media_order')->where("users_id",'IN',$users_ids)->delete();
  362. /*同步删除视频播放时长表数据*/
  363. Db::name('media_play_record')->where("users_id",'IN',$users_ids)->delete();
  364. /*同步删除礼品兑换记录表数据*/
  365. Db::name('memgiftget')->where("users_id",'IN',$users_ids)->delete();
  366. /*同步删除搜索锁定表数据*/
  367. Db::name('search_locking')->where("users_id",'IN',$users_ids)->delete();
  368. /*同步删除搜索关键词表数据*/
  369. Db::name('search_word')->where("users_id",'IN',$users_ids)->delete();
  370. /*同步删除商城收货地址表数据*/
  371. Db::name('shop_address')->where("users_id",'IN',$users_ids)->delete();
  372. /*同步删除购物车表数据*/
  373. Db::name('shop_cart')->where("users_id",'IN',$users_ids)->delete();
  374. /*同步删除优惠券领券记录表数据*/
  375. Db::name('shop_coupon_use')->where("users_id",'IN',$users_ids)->delete();
  376. /*同步删除商城订单表数据*/
  377. Db::name('shop_order')->where("users_id",'IN',$users_ids)->delete();
  378. /*同步删除商城订单评论表数据*/
  379. Db::name('shop_order_comment')->where("users_id",'IN',$users_ids)->delete();
  380. /*同步删除商城订单详情表数据*/
  381. Db::name('shop_order_details')->where("users_id",'IN',$users_ids)->delete();
  382. /*同步删除商城订单日志表数据*/
  383. Db::name('shop_order_log')->where("users_id",'IN',$users_ids)->delete();
  384. /*同步删除商城订单售后表数据*/
  385. Db::name('shop_order_service')->where("users_id",'IN',$users_ids)->delete();
  386. /*同步删除商城订单售后日志表数据*/
  387. Db::name('shop_order_service_log')->where("users_id",'IN',$users_ids)->delete();
  388. /*同步删除商城订单统一支付表数据*/
  389. Db::name('shop_order_unified_pay')->where("users_id",'IN',$users_ids)->delete();
  390. /*同步删除邮件发送记录表数据*/
  391. Db::name('smtp_record')->where("users_id",'IN',$users_ids)->delete();
  392. /*同步删除我的收藏表数据*/
  393. Db::name('users_collection')->where("users_id",'IN',$users_ids)->delete();
  394. /*同步删除我的足迹数据*/
  395. Db::name('users_footprint')->where("users_id",'IN',$users_ids)->delete();
  396. /*同步删除转发记录表数据*/
  397. Db::name('users_forward')->where("users_id",'IN',$users_ids)->delete();
  398. /*同步删除我喜欢的表数据*/
  399. Db::name('users_like')->where("users_id",'IN',$users_ids)->delete();
  400. /*同步删除会员属性表数据*/
  401. Db::name('users_list')->where("users_id",'IN',$users_ids)->delete();
  402. /*同步删除会员登录日志表数据*/
  403. Db::name('users_login_log')->where("users_id",'IN',$users_ids)->delete();
  404. /*同步删除金额明细表数据*/
  405. Db::name('users_money')->where("users_id",'IN',$users_ids)->delete();
  406. /*同步删除站内通知表数据*/
  407. Db::name('users_notice')->where("users_id",'IN',$users_ids)->delete();
  408. /*同步删除用户已读站内通知表数据*/
  409. Db::name('users_notice_read')->where("users_id",'IN',$users_ids)->delete();
  410. /*同步删除站内信发送接收记录表数据*/
  411. Db::name('users_notice_tpl_content')->where("users_id",'IN',$users_ids)->delete();
  412. /*同步删除积分详情表数据*/
  413. Db::name('users_score')->where("users_id",'IN',$users_ids)->delete();
  414. /*同步删除用户签到表数据*/
  415. Db::name('users_signin')->where("users_id",'IN',$users_ids)->delete();
  416. /*同步删除微信小程序用户表数据*/
  417. Db::name('wx_users')->where("users_id",'IN',$users_ids)->delete();
  418. // 同步删除插件数据
  419. $Prefix = config('database.prefix');
  420. if (is_dir('./weapp/Ask/')) {
  421. $isTable = Db::query('SHOW TABLES LIKE \''.$Prefix.'weapp_ask\'');
  422. if (!empty($isTable)) {
  423. /*同步删除内置问答表数据*/
  424. Db::name('weapp_ask')->where("users_id",'IN',$users_ids)->delete();
  425. /*同步删除内置问答表数据*/
  426. Db::name('weapp_ask_answer')->where("users_id",'IN',$users_ids)->delete();
  427. /*同步删除问答点赞表数据*/
  428. Db::name('weapp_ask_answer_like')->where("users_id",'IN',$users_ids)->delete();
  429. }
  430. }
  431. if (is_dir('./weapp/Comment/')) {
  432. $isTable = Db::query('SHOW TABLES LIKE \''.$Prefix.'weapp_comment\'');
  433. if (!empty($isTable)) {
  434. /*同步删除插件评论表数据*/
  435. Db::name('weapp_comment')->where(['users_id'=>['IN', $users_ids]])->delete();
  436. /*同步删除插件评论点赞表数据*/
  437. Db::name('weapp_comment_like')->where("users_id",'IN',$users_ids)->delete();
  438. }
  439. }
  440. } catch (\Exception $e) {
  441. }
  442. }
  443. }
  444. /**
  445. * 批量更新会员过期等级
  446. * @return [type] [description]
  447. */
  448. public function batch_update_userslevel()
  449. {
  450. $redata = [
  451. 'code' => 1,
  452. 'msg' => '没开启会员中心,不需要执行',
  453. ];
  454. $web_users_switch = tpCache('web.web_users_switch');
  455. if (!empty($web_users_switch)) {
  456. /*查询系统初始的默认级别*/
  457. $level_id = Db::name('users_level')->where([
  458. 'level_id' => 1,
  459. 'is_system' => 1,
  460. ])->value('level_id');
  461. $level_id = empty($level_id) ? 1 : intval($level_id);
  462. /* END */
  463. $time = getTime();
  464. $where_str = "`level` <> {$level_id} AND (`level_maturity_days` < 36600 AND (`open_level_time` <> 0 OR `level_maturity_days` <> 0)) AND ((`open_level_time` + (`level_maturity_days` * 86400) - {$time}) <= 0)";
  465. $r = Db::name('users')->where($where_str)->update([
  466. 'level' => $level_id,
  467. 'open_level_time' => 0,
  468. 'level_maturity_days' => 0,
  469. 'update_time' => $time,
  470. ]);
  471. if ($r !== false) {
  472. $redata = [
  473. 'code' => 1,
  474. 'msg' => '会员过期更新成功',
  475. ];
  476. } else {
  477. $redata = [
  478. 'code' => 1,
  479. 'msg' => '会员过期更新失败',
  480. ];
  481. }
  482. }
  483. return $redata;
  484. }
  485. }