User.php 27 KB

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