User.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\model\api;
  4. use app\model\api\City as CityModel;
  5. use Closure;
  6. use library\basic\BaseModel;
  7. use think\db\exception\DbException;
  8. use app\model\api\ShowTemplate;
  9. use app\model\api\InfoAudit;
  10. use think\Model;
  11. use think\facade\Db;
  12. use think\Request;
  13. /**
  14. * @mixin \think\Model
  15. */
  16. class User extends BaseModel
  17. {
  18. //
  19. protected $pk = 'uid';
  20. /**
  21. * 获取列表数据
  22. * @param $page
  23. * @param $where
  24. * @param $pageCount
  25. * @param $desc
  26. */
  27. public function getList($page, $where = [], $pageCount = 20, $filed = '*', $desc = '')
  28. {
  29. $today = strtotime(date("Y-m-d"));
  30. $data = $this
  31. ->alias("m")
  32. ->field("m.*,u.nickname as i_nickname,u.uuid as i_uuid,t.name as i_tname,t.tuuid as i_tuuid,s.day_surplus_talk,s.day_surplus_video,s.time as surplus_time"
  33. . ",(select count(*) from table_user_friends as p where p.uid = m.uid) as friendsCount"//朋友数
  34. . ",(select count(*) from table_user_attention as a where a.uid = m.uid) as attentionCount"//关注数
  35. . ",(select count(*) from table_user_attention as f where f.i_uid = m.uid) as fasCount"//粉丝数
  36. . ",(select count(*) from table_user_visitors as v where v.uid = m.uid) as visitorsCount"//访客数
  37. . "")
  38. ->leftJoin("user u", "u.uid = m.i_uid")
  39. ->leftJoin("user_surplus s", "s.uid = m.uid and s.time = {$today}")
  40. ->leftJoin("tuser t", "t.tuid = m.i_tuid")
  41. ->when(!empty($where), function ($query) use ($where) {
  42. if (!empty($where['mobile'])) {
  43. $query->where('m.mobile', $where['mobile']);
  44. }
  45. if (!empty($where['nickname'])) {
  46. $query->whereLike('m.nickname', "%{$where['nickname']}%");
  47. }
  48. if (is_numeric($where['levelid']) && in_array(strval($where['levelid']), ['0', '1', '2'])) {
  49. $query->where('m.levelid', intval($where['levelid']));
  50. }
  51. if (is_numeric($where['is_certification']) && in_array(strval($where['is_certification']), ['0', '1', '2'])) {
  52. $query->where('m.is_certification', intval($where['is_certification']));
  53. }
  54. if (is_numeric($where['is_goddess']) && in_array(strval($where['is_goddess']), ['0', '1', '2'])) {
  55. $query->where('m.is_goddess', intval($where['is_goddess']));
  56. }
  57. if (!empty($where['address'])) {
  58. $query->whereLike('m.address', "%{$where['address']}%");
  59. }
  60. if (!empty($where['now_address'])) {
  61. $query->whereLike('m.now_address', "%{$where['now_address']}%");
  62. }
  63. if (!empty($where['i_uid'])) {
  64. $query->where('m.i_uid', $where['i_uid']);
  65. }
  66. if (!empty($where['i_tuid'])) {
  67. $query->where('m.i_tuid', $where['i_tuid']);
  68. }
  69. if (is_numeric($where["sex"]) && in_array(strval($where["sex"]), ["0", "1", "2"])) {
  70. $query->where('m.sex', $where["sex"]);
  71. }
  72. if (is_numeric($where["is_im"]) && in_array(strval($where["is_im"]), ["0", "1"])) {
  73. $query->where('m.is_im', $where["is_im"]);
  74. }
  75. if (is_numeric($where["is_online"]) && in_array(strval($where["is_online"]), ["0", "1"])) {
  76. $query->where('m.is_online', $where["is_online"]);
  77. }
  78. if (is_numeric($where["status"]) && in_array(strval($where["status"]), ["0", "1", "-1"])) {
  79. $query->where('m.status', $where["status"]);
  80. }
  81. if (!empty($where['uid'])) {
  82. $query->where('m.uid', $where['uid']);
  83. }
  84. if (!empty($where['uuid'])) {
  85. $query->where('m.uuid', $where['uuid']);
  86. }
  87. //注册时间
  88. $startTime = "";
  89. $endTime = "";
  90. if (!empty($where['time']) && !empty($where['time'][0]) && !empty($where['time'][1])) {
  91. $startTime = strtotime($where['time'][0]);
  92. $endTime = strtotime($where['time'][1]);
  93. }
  94. if (!empty($startTime) && !empty($endTime)) {
  95. $query->whereBetween("m.regtime", "{$startTime},{$endTime}");
  96. }
  97. })
  98. ->order($desc)
  99. ->paginate(['list_rows' => $pageCount, 'page' => $page])
  100. ->toArray();
  101. return [$data['total'], $data['data']];
  102. }
  103. /**
  104. * 保存数据
  105. * @param $data
  106. * @param $admin_id
  107. * @return array
  108. */
  109. public function saveUpdate($data, $admin_id)
  110. {
  111. try {
  112. self::beginTrans();
  113. if (!is_numeric($data["levelid"]) || !in_array(strval($data["levelid"]), ["0", "1", "2"])) {
  114. unset($data["levelid"]);
  115. }
  116. if (empty($data["mobile"])) {
  117. unset($data["mobile"]);
  118. } else {
  119. if (!isMobile($data["mobile"])) {
  120. return [0, '请输入正确的手机号码'];
  121. }
  122. }
  123. if (empty($data["nickname"])) {
  124. unset($data["nickname"]);
  125. }
  126. if (empty($data["address"])) {
  127. unset($data["address"]);
  128. }
  129. if (empty($data["now_address"])) {
  130. unset($data["now_address"]);
  131. }
  132. if (!is_numeric($data["status"]) || !in_array(strval($data["status"]), ["0", "1", "-1"])) {
  133. unset($data["status"]);
  134. }
  135. if (!is_numeric($data["is_shield"]) || !in_array(strval($data["is_shield"]), ["0", "1"])) {
  136. unset($data["is_shield"]);
  137. }
  138. //密码
  139. if (!empty($data['password'])) {
  140. $data['password'] = md5($data['password']);
  141. } else {
  142. unset($data["password"]);
  143. }
  144. if (empty($data["avatar"])) {
  145. unset($data["avatar"]);
  146. }
  147. if (!is_numeric($data["sex"]) || !in_array(strval($data["sex"]), ["0", "1", "2"])) {
  148. unset($data["sex"]);
  149. }
  150. //特殊设置
  151. if (empty($data["msg_price"]) || !is_numeric($data["msg_price"])) {
  152. unset($data["msg_price"]);
  153. }
  154. if (empty($data["video_price"]) || !is_numeric($data["video_price"])) {
  155. unset($data["video_price"]);
  156. }
  157. if (empty($data["audio_price"]) || !is_numeric($data["audio_price"])) {
  158. unset($data["audio_price"]);
  159. }
  160. if (empty($data["phone_price"]) || !is_numeric($data["phone_price"])) {
  161. unset($data["phone_price"]);
  162. }
  163. if (empty($data["wx_price"]) || !is_numeric($data["wx_price"])) {
  164. unset($data["wx_price"]);
  165. }
  166. if (empty($data["qq_price"]) || !is_numeric($data["qq_price"])) {
  167. unset($data["qq_price"]);
  168. }
  169. //开关设置
  170. if (!is_numeric($data["is_rank"]) || !in_array(strval($data["is_rank"]), ["0", "1"])) {
  171. unset($data["is_rank"]);
  172. }
  173. if (!is_numeric($data["is_gift"]) || !in_array(strval($data["is_gift"]), ["0", "1"])) {
  174. unset($data["is_gift"]);
  175. }
  176. if (!is_numeric($data["is_msg"]) || !in_array(strval($data["is_msg"]), ["0", "1"])) {
  177. unset($data["is_msg"]);
  178. }
  179. if (!is_numeric($data["is_video"]) || !in_array(strval($data["is_video"]), ["0", "1"])) {
  180. unset($data["is_video"]);
  181. }
  182. if (!is_numeric($data["is_audio"]) || !in_array(strval($data["is_audio"]), ["0", "1"])) {
  183. unset($data["is_audio"]);
  184. }
  185. //uid
  186. if (!empty($data['uid'])) {
  187. $uData = $this->where('uid', $data['uid'])->find()->toArray();
  188. if (empty($uData)) {
  189. return [0, '会员不存在'];
  190. }
  191. if (!empty($data["mobile"])) {
  192. //判断手机是否重复
  193. $count = $this
  194. ->where('mobile', $data['mobile'])
  195. ->where('uid', '<>', $data['uid'])
  196. ->count();
  197. if ($count > 0) {
  198. return [0, '手机号码已经存在'];
  199. }
  200. }
  201. } else {
  202. $data['regtime'] = time();
  203. }
  204. $this->saveModel($data);
  205. self::commitTrans();
  206. return [1, ''];
  207. } catch (DbException $db) {
  208. self::rollbackTrans();
  209. return [0, '操作失败1'];
  210. } catch (\Exception $e) {
  211. self::rollbackTrans();
  212. return [0, '操作失败2'];
  213. }
  214. return [0, '操作失败'];
  215. }
  216. /**
  217. * 获取列表数据
  218. * @param $page
  219. * @param $where
  220. * @param $pageCount
  221. * @param $desc
  222. */
  223. public function getItem($uid)
  224. {
  225. $data = $this
  226. ->field("m.*,(select mobile from table_user where uid = m.i_uid) as i_name")
  227. ->alias("m")
  228. ->where('uid', $uid)
  229. ->select();
  230. return $data;
  231. }
  232. /**
  233. * 获取小程序在职展示列表
  234. * @return type
  235. */
  236. public function getApiWorkerList($post)
  237. {
  238. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  239. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  240. $where = [];
  241. $where[] = ["u.work_type_id", ">", 0];
  242. $where[] = ["u.status", "=", 1];
  243. if (!empty($post['work_type_id'])) {
  244. $where[] = ["u.work_type_id", "=", $post['work_type_id']];
  245. }
  246. $totalCount = $this->alias("u")->where($where)->count();
  247. $data = null;
  248. if ($totalCount > 0) {
  249. @file_put_contents('quanju.txt', json_encode($where). "-搜索条件2\r\n", 8);
  250. $data = $this
  251. ->alias("u")
  252. ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit")
  253. ->leftJoin("info_audit a", "u.uid=a.uid")
  254. ->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")//默认模板
  255. ->where($where)
  256. ->order("u.show_temp_seq", "desc")
  257. ->order("u.uid", "desc")
  258. ->page($post["page"], $post["pageSize"])
  259. ->select();
  260. if (!empty($data)) {
  261. $data = $data->toArray();
  262. }
  263. $infoAuditDb = new InfoAudit();
  264. foreach ($data as $k => $v) {
  265. $item = [
  266. "name" => "",
  267. "avatar" => "",
  268. "age" => "",
  269. "service_project_ar" => [],
  270. "user_work_type_title" => "",
  271. "service_area_all" => [],
  272. "birthday" => ""
  273. ];
  274. $infoData = $infoAuditDb->getItem(["status" => 1, "uid" => $v["uid"]]);
  275. if (!empty($infoData)) {
  276. foreach ($item as $k2 => $v2) {
  277. $item[$k2] = $infoData[$k2];
  278. }
  279. }
  280. $data[$k] = array_merge($v, $item);
  281. }
  282. }
  283. // $datatwo = [];
  284. // foreach($data as $v){
  285. // if($v['is_show'] == 1){
  286. // $datatwo[] = $v;
  287. // }
  288. // }
  289. $data = empty($data) ? [] : $data;
  290. return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
  291. }
  292. /**
  293. * 获取小程序在职展示列表
  294. * @return type
  295. */
  296. public function getGoodApiWorkerList($post)
  297. {
  298. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  299. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  300. $where = [];
  301. $where[] = ["u.work_type_id", ">", 0];
  302. $where[] = ["u.show_temp_seq", ">", 0];
  303. $where[] = ["u.status", "=", 1];
  304. if (!empty($post['work_type_id'])) {
  305. $where[] = ["u.work_type_id", "=", $post['work_type_id']];
  306. }
  307. if ($post['servicePrice'] > 0) {
  308. $where[] = ["a.service_min_price", "<=", $post['servicePrice']];
  309. }
  310. if ($post['is_china'] != '') {
  311. $where[] = ["a.is_china", '=', $post['is_china']];
  312. }
  313. if (!empty($post['timetype'])) {
  314. $where[] = ["a.service_type", "=", $post['timetype']];
  315. }
  316. $cityModel = new CityModel();
  317. $totalModel = $this->alias("u")->leftJoin("info_audit a", "u.uid=a.uid")->where($where);
  318. if (!empty($post["service_area"]) && is_array($post["service_area"])) {
  319. $totalModel->where(function ($query) use ($post, $cityModel) {
  320. foreach ($post["service_area"] as $v) {
  321. $stc = str_replace(['省', '市', '区', '县'], ['', '', '', ''], $v);
  322. $str = str_replace(['辖'], ['市辖'], $stc);
  323. $arr = explode(",", $str);
  324. $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[1] . "," . $arr[2])->value('id');
  325. if (!$city_id) $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[0] . "," . $arr[1])->value('id');
  326. $query->whereOr('find_in_set(' . $city_id . ',a.service_area)');
  327. }
  328. });
  329. }
  330. $totalCount = $totalModel->count();
  331. $data = null;
  332. if ($totalCount > 0) {
  333. $dataModel = $this
  334. ->alias("u")
  335. ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit")
  336. ->leftJoin("info_audit a", "u.uid=a.uid")
  337. ->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")//默认模板
  338. ->where($where);
  339. if (!empty($post["service_area"]) && is_array($post["service_area"])) {
  340. $dataModel->where(function ($query) use ($post, $cityModel) {
  341. foreach ($post["service_area"] as $v) {
  342. $stc = str_replace(['省', '市', '区', '县'], ['', '', '', ''], $v);
  343. $str = str_replace(['辖'], ['市辖'], $stc);
  344. $arr = explode(",", $str);
  345. $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[1] . "," . $arr[2])->value('id');
  346. if (!$city_id) $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[0] . "," . $arr[1])->value('id');
  347. $query->whereOr('find_in_set(' . $city_id . ',a.service_area)');
  348. }
  349. });
  350. }
  351. $data = $dataModel->order("u.show_temp_seq", "desc")
  352. ->order("u.uid", "desc")
  353. ->page($post["page"], $post["pageSize"])
  354. ->select();
  355. if (!empty($data)) {
  356. $data = $data->toArray();
  357. }
  358. $infoAuditDb = new InfoAudit();
  359. foreach ($data as $k => $v) {
  360. $item = [
  361. "name" => "",
  362. "avatar" => "",
  363. "age" => "",
  364. "service_project_ar" => [],
  365. "user_work_type_title" => "",
  366. "service_area_all" => [],
  367. "birthday" => ""
  368. ];
  369. $infoData = $infoAuditDb->getItem(["status" => 1, "uid" => $v["uid"]]);
  370. if (!empty($infoData)) {
  371. foreach ($item as $k2 => $v2) {
  372. $item[$k2] = $infoData[$k2];
  373. }
  374. }
  375. $data[$k] = array_merge($v, $item);
  376. }
  377. }
  378. // $datatwo = [];
  379. // foreach($data as $v){
  380. // if($v['is_show'] == 1){
  381. // $datatwo[] = $v;
  382. // }
  383. // }
  384. $data = empty($data) ? [] : $data;
  385. return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
  386. }
  387. /**
  388. * 获取小程序在职展示列表
  389. * @return type
  390. */
  391. public function getNewApiWorkerList($post)
  392. {
  393. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  394. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  395. $where = [];
  396. $where[] = ["u.work_type_id", ">", 0];
  397. $where[] = ["u.status", "=", 1];
  398. if (!empty($post['work_type_id'])) {
  399. $where[] = ["u.work_type_id", "=", $post['work_type_id']];
  400. }
  401. if ($post['servicePrice'] > 0) {
  402. $where[] = ["a.service_min_price", "<=", $post['servicePrice']];
  403. }
  404. if (!empty($post['timetype'])) {
  405. $where[] = ["a.service_type", "=", $post['timetype']];
  406. }
  407. if ($post['is_china'] != '') {
  408. $where[] = ["a.is_china", '=', $post['is_china']];
  409. }
  410. $cityModel = new CityModel();
  411. $totalModel = $this->alias("u")->leftJoin("info_audit a", "u.uid=a.uid")->where($where);
  412. if (!empty($post["service_area"]) && is_array($post["service_area"])) {
  413. $totalModel->where(function ($query) use ($post, $cityModel) {
  414. foreach ($post["service_area"] as $v) {
  415. $stc = str_replace(['省', '市', '区', '县'], ['', '', '', ''], $v);
  416. $str = str_replace(['辖'], ['市辖'], $stc);
  417. $arr = explode(",", $str);
  418. $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[1] . "," . $arr[2])->value('id');
  419. if (!$city_id) $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[0] . "," . $arr[1])->value('id');
  420. $query->whereOr('find_in_set(' . $city_id . ',a.service_area)');
  421. }
  422. });
  423. }
  424. $totalCount = $totalModel->count();
  425. $data = null;
  426. if ($totalCount > 0) {
  427. $dataModel = $this
  428. ->alias("u")
  429. ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit")
  430. ->leftJoin("info_audit a", "u.uid=a.uid")
  431. ->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")//默认模板
  432. ->where($where);
  433. if (!empty($post["service_area"]) && is_array($post["service_area"])) {
  434. $dataModel->where(function ($query) use ($post, $cityModel) {
  435. foreach ($post["service_area"] as $v) {
  436. $stc = str_replace(['省', '市', '区', '县'], ['', '', '', ''], $v);
  437. $str = str_replace(['辖'], ['市辖'], $stc);
  438. $arr = explode(",", $str);
  439. $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[1] . "," . $arr[2])->value('id');
  440. if (!$city_id) $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[0] . "," . $arr[1])->value('id');
  441. $query->whereOr('find_in_set(' . $city_id . ',a.service_area)');
  442. }
  443. });
  444. }
  445. $data = $dataModel->order("u.uid", "desc")
  446. ->page($post["page"], $post["pageSize"])
  447. ->select();
  448. if (!empty($data)) {
  449. $data = $data->toArray();
  450. }
  451. $infoAuditDb = new InfoAudit();
  452. foreach ($data as $k => $v) {
  453. $item = [
  454. "name" => "",
  455. "avatar" => "",
  456. "age" => "",
  457. "service_project_ar" => [],
  458. "user_work_type_title" => "",
  459. "service_area_all" => [],
  460. "birthday" => ""
  461. ];
  462. $infoData = $infoAuditDb->getItem(["status" => 1, "uid" => $v["uid"]]);
  463. if (!empty($infoData)) {
  464. foreach ($item as $k2 => $v2) {
  465. $item[$k2] = $infoData[$k2];
  466. }
  467. }
  468. $data[$k] = array_merge($v, $item);
  469. }
  470. }
  471. // $datatwo = [];
  472. // foreach($data as $v){
  473. // if($v['is_show'] == 1){
  474. // $datatwo[] = $v;
  475. // }
  476. // }
  477. $data = empty($data) ? [] : $data;
  478. return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
  479. }
  480. /**
  481. * 获取从业人员列表
  482. * @param type $post
  483. * @param type $field
  484. * @param type $is_admin
  485. */
  486. public function getWorkerList($post, $field = "*", $is_admin = 0)
  487. {
  488. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  489. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  490. $where = [];
  491. $where[] = ["u.work_type_id", ">", 0];
  492. //用户uid
  493. if (!empty($post['uid'])) {
  494. $where[] = ["u.uid", "=", $post['uid']];
  495. }
  496. if (!empty($post['work_type_id'])) {
  497. $where[] = ["u.work_type_id", "=", $post['work_type_id']];
  498. }
  499. //手机号码
  500. if (!empty($post["mobile"])) {
  501. $where[] = ["u.mobile", "=", $post["mobile"]];
  502. }
  503. //状态
  504. if (isset($post["status"]) && in_array((string)$post["status"], ["0", "1", "-1"])) {
  505. $where[] = ["u.status", "=", (int)$post["status"]];
  506. }
  507. //父级uid
  508. if (!empty($post["parent_uid"])) {
  509. $where[] = ["u.parent_uid", "=", $post["parent_uid"]];
  510. }
  511. //
  512. if ($is_admin == 1) {
  513. $field = "u.*"
  514. . ",ut.show_template_id"
  515. . ",(select is_show from table_info_audit where uid = u.uid and status = 1 limit 1 ) as is_show"
  516. . ",p.nickname as p_nickname,p.mobile as p_mobile"
  517. . ",wt.title as work_type_title"
  518. . ",(select count(*) from table_user_show_template where uid = u.uid) as showTempCount"
  519. . ",(select count(*) from table_info_audit where uid = u.uid and status = 1) as is_info_audit"
  520. . ",(select count(*) from table_type_audit where uid = u.uid and status = 1) as is_type_audit"
  521. . ",(select count(*) from table_user where parent_uid = u.uid) as branchCount";
  522. }
  523. $totalCount = $this->alias("u")->where($where)->count();
  524. $data = null;
  525. if ($totalCount > 0) {
  526. $data = $this
  527. ->alias("u")
  528. ->field($field)
  529. ->leftJoin("user p", "p.uid = u.parent_uid")
  530. ->leftJoin("user_work_type wt", "wt.id = u.work_type_id")//职称
  531. ->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")//职称
  532. ->where($where)
  533. ->order("u.show_temp_seq", "desc")
  534. ->order("u.uid", "desc")
  535. ->page($post["page"], $post["pageSize"])
  536. ->select();
  537. // var_dump($this->getLastSql());
  538. if (!empty($data)) {
  539. $data = $data->toArray();
  540. }
  541. }
  542. $data = empty($data) ? [] : $data;
  543. $ShowTemplateDb = new ShowTemplate();
  544. foreach ($data as $k => $v) {
  545. if (!empty($v["regtime"])) {
  546. $data[$k]["regtime"] = date("Y-m-d H:i:s", $v["regtime"]);
  547. }
  548. if (!empty($v["parent_time"])) {
  549. $data[$k]["parent_time"] = date("Y-m-d H:i:s", $v["parent_time"]);
  550. }
  551. }
  552. // $datatwo = [];
  553. // foreach($data as $v){
  554. // if($v['is_show'] == 1){
  555. // $datatwo[] = $v;
  556. // }
  557. // }
  558. return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
  559. }
  560. /**
  561. * 前端获取用户列表
  562. * @param type $post
  563. * @param type $field
  564. * @return type
  565. */
  566. public function getDataList($post, $field = "*", $is_admin = 0)
  567. {
  568. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  569. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  570. $where = [];
  571. //用户uid
  572. if (!empty($post['uid'])) {
  573. $where[] = ["u.uid", "=", $post['uid']];
  574. }
  575. //状态
  576. if (isset($post["status"]) && in_array((string)$post["status"], ["0", "1", "-1"])) {
  577. $where[] = ["u.status", "=", (int)$post["status"]];
  578. }
  579. //昵称
  580. if (!empty($post["nickname"])) {
  581. $where[] = ["u.nickname", "like", "%{$post["nickname"]}%"];
  582. }
  583. //手机号码
  584. if (!empty($post["mobile"])) {
  585. $where[] = ["u.mobile", "=", $post["mobile"]];
  586. }
  587. //父级uid
  588. if (!empty($post["parent_uid"])) {
  589. $where[] = ["u.parent_uid", "=", $post["parent_uid"]];
  590. }
  591. //注册时间
  592. if (!empty($post['time']) && !empty($post['time'][0]) && !empty($post['time'][1])) {
  593. $startTime = strtotime($post['time'][0]);
  594. $endTime = strtotime($post['time'][1]);
  595. $where[] = ["u.regtime", "between", "{$startTime},{$endTime}"];
  596. }
  597. if ($is_admin == 1) {
  598. $field = "u.*"
  599. . ",p.nickname as p_nickname,p.mobile as p_mobile"
  600. . ",wt.title as work_type_title"
  601. . ",(select count(*) from table_user_show_template where uid = u.uid) as showTempCount"
  602. . ",(select count(*) from table_info_audit where uid = u.uid and status = 1) as is_info_audit"
  603. . ",(select count(*) from table_type_audit where uid = u.uid and status = 1) as is_type_audit"
  604. . ",(select count(*) from table_user where parent_uid = u.uid) as branchCount";
  605. }
  606. $totalCount = $this->alias("u")->where($where)->count();
  607. $data = null;
  608. if ($totalCount > 0) {
  609. $data = $this
  610. ->alias("u")
  611. ->field($field)
  612. ->leftJoin("user p", "p.uid = u.parent_uid")
  613. ->leftJoin("user_work_type wt", "wt.id = u.work_type_id")//职称
  614. ->where($where)
  615. ->order("u.uid", "desc")
  616. ->page($post["page"], $post["pageSize"])
  617. ->select();
  618. if (!empty($data)) {
  619. $data = $data->toArray();
  620. }
  621. }
  622. $data = empty($data) ? [] : $data;
  623. foreach ($data as $k => $v) {
  624. if (!empty($v["regtime"])) {
  625. $data[$k]["regtime"] = date("Y-m-d H:i:s", $v["regtime"]);
  626. }
  627. if (!empty($v["parent_time"])) {
  628. $data[$k]["parent_time"] = date("Y-m-d H:i:s", $v["parent_time"]);
  629. }
  630. }
  631. return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
  632. }
  633. }