User.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. $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. Log::info('搜索条件:' . json_encode($where, JSON_UNESCAPED_UNICODE));
  334. $dataModel = $this
  335. ->alias("u")
  336. ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit")
  337. ->leftJoin("info_audit a", "u.uid=a.uid")
  338. ->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")//默认模板
  339. ->where($where)->where('ut.show_template_id',7);
  340. if (!empty($post["service_area"]) && is_array($post["service_area"])) {
  341. $dataModel->where(function ($query) use ($post, $cityModel) {
  342. foreach ($post["service_area"] as $v) {
  343. $stc = str_replace(['省', '市', '区', '县'], ['', '', '', ''], $v);
  344. $str = str_replace(['辖'], ['市辖'], $stc);
  345. $arr = explode(",", $str);
  346. $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[1] . "," . $arr[2])->value('id');
  347. if (!$city_id) $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[0] . "," . $arr[1])->value('id');
  348. $query->whereOr('find_in_set(' . $city_id . ',a.service_area)');
  349. }
  350. });
  351. }
  352. $data = $dataModel->order("u.show_temp_seq", "desc")
  353. ->order("u.uid", "desc")
  354. ->page($post["page"], $post["pageSize"])
  355. ->select();
  356. Log::info('搜索语句:' . json_encode($this->getLastSql(), JSON_UNESCAPED_UNICODE));
  357. if (!empty($data)) {
  358. $data = $data->toArray();
  359. }
  360. $infoAuditDb = new InfoAudit();
  361. foreach ($data as $k => $v) {
  362. $item = [
  363. "name" => "",
  364. "avatar" => "",
  365. "age" => "",
  366. "service_project_ar" => [],
  367. "user_work_type_title" => "",
  368. "service_area_all" => [],
  369. "birthday" => ""
  370. ];
  371. $infoData = $infoAuditDb->getItem(["status" => 1, "uid" => $v["uid"]]);
  372. if (!empty($infoData)) {
  373. foreach ($item as $k2 => $v2) {
  374. $item[$k2] = $infoData[$k2];
  375. }
  376. }
  377. $data[$k] = array_merge($v, $item);
  378. }
  379. }
  380. // $datatwo = [];
  381. // foreach($data as $v){
  382. // if($v['is_show'] == 1){
  383. // $datatwo[] = $v;
  384. // }
  385. // }
  386. $data = empty($data) ? [] : $data;
  387. return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
  388. }
  389. /**
  390. * 获取小程序在职展示列表
  391. * @return type
  392. */
  393. public function getNewApiWorkerList($post)
  394. {
  395. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  396. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  397. $where = [];
  398. $where[] = ["u.work_type_id", ">", 0];
  399. $where[] = ["u.status", "=", 1];
  400. if (!empty($post['work_type_id'])) {
  401. $where[] = ["u.work_type_id", "=", $post['work_type_id']];
  402. }
  403. if ($post['servicePrice'] > 0) {
  404. $where[] = ["a.service_min_price", "<=", $post['servicePrice']];
  405. }
  406. if (!empty($post['timetype'])) {
  407. $where[] = ["a.service_type", "=", $post['timetype']];
  408. }
  409. if ($post['is_china'] != '') {
  410. $where[] = ["a.is_china", '=', $post['is_china']];
  411. }
  412. $cityModel = new CityModel();
  413. $totalModel = $this->alias("u")->leftJoin("info_audit a", "u.uid=a.uid")->where($where);
  414. if (!empty($post["service_area"]) && is_array($post["service_area"])) {
  415. $totalModel->where(function ($query) use ($post, $cityModel) {
  416. foreach ($post["service_area"] as $v) {
  417. $stc = str_replace(['省', '市', '区', '县'], ['', '', '', ''], $v);
  418. $str = str_replace(['辖'], ['市辖'], $stc);
  419. $arr = explode(",", $str);
  420. $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[1] . "," . $arr[2])->value('id');
  421. if (!$city_id) $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[0] . "," . $arr[1])->value('id');
  422. $query->whereOr('find_in_set(' . $city_id . ',a.service_area)');
  423. }
  424. });
  425. }
  426. $totalCount = $totalModel->count();
  427. $data = null;
  428. if ($totalCount > 0) {
  429. $dataModel = $this
  430. ->alias("u")
  431. ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit")
  432. ->leftJoin("info_audit a", "u.uid=a.uid")
  433. ->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")//默认模板
  434. ->where($where);
  435. if (!empty($post["service_area"]) && is_array($post["service_area"])) {
  436. $dataModel->where(function ($query) use ($post, $cityModel) {
  437. foreach ($post["service_area"] as $v) {
  438. $stc = str_replace(['省', '市', '区', '县'], ['', '', '', ''], $v);
  439. $str = str_replace(['辖'], ['市辖'], $stc);
  440. $arr = explode(",", $str);
  441. $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[1] . "," . $arr[2])->value('id');
  442. if (!$city_id) $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[0] . "," . $arr[1])->value('id');
  443. $query->whereOr('find_in_set(' . $city_id . ',a.service_area)');
  444. }
  445. });
  446. }
  447. $data = $dataModel->order("u.uid", "desc")
  448. ->page($post["page"], $post["pageSize"])
  449. ->select();
  450. if (!empty($data)) {
  451. $data = $data->toArray();
  452. }
  453. $infoAuditDb = new InfoAudit();
  454. foreach ($data as $k => $v) {
  455. $item = [
  456. "name" => "",
  457. "avatar" => "",
  458. "age" => "",
  459. "service_project_ar" => [],
  460. "user_work_type_title" => "",
  461. "service_area_all" => [],
  462. "birthday" => ""
  463. ];
  464. $infoData = $infoAuditDb->getItem(["status" => 1, "uid" => $v["uid"]]);
  465. if (!empty($infoData)) {
  466. foreach ($item as $k2 => $v2) {
  467. $item[$k2] = $infoData[$k2];
  468. }
  469. }
  470. $data[$k] = array_merge($v, $item);
  471. }
  472. }
  473. // $datatwo = [];
  474. // foreach($data as $v){
  475. // if($v['is_show'] == 1){
  476. // $datatwo[] = $v;
  477. // }
  478. // }
  479. $data = empty($data) ? [] : $data;
  480. return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
  481. }
  482. /**
  483. * 获取从业人员列表
  484. * @param type $post
  485. * @param type $field
  486. * @param type $is_admin
  487. */
  488. public function getWorkerList($post, $field = "*", $is_admin = 0)
  489. {
  490. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  491. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  492. $where = [];
  493. $where[] = ["u.work_type_id", ">", 0];
  494. //用户uid
  495. if (!empty($post['uid'])) {
  496. $where[] = ["u.uid", "=", $post['uid']];
  497. }
  498. if (!empty($post['work_type_id'])) {
  499. $where[] = ["u.work_type_id", "=", $post['work_type_id']];
  500. }
  501. //手机号码
  502. if (!empty($post["mobile"])) {
  503. $where[] = ["u.mobile", "=", $post["mobile"]];
  504. }
  505. //状态
  506. if (isset($post["status"]) && in_array((string)$post["status"], ["0", "1", "-1"])) {
  507. $where[] = ["u.status", "=", (int)$post["status"]];
  508. }
  509. //父级uid
  510. if (!empty($post["parent_uid"])) {
  511. $where[] = ["u.parent_uid", "=", $post["parent_uid"]];
  512. }
  513. //
  514. if ($is_admin == 1) {
  515. $field = "u.*"
  516. . ",ut.show_template_id"
  517. . ",(select is_show from table_info_audit where uid = u.uid and status = 1 limit 1 ) as is_show"
  518. . ",p.nickname as p_nickname,p.mobile as p_mobile"
  519. . ",wt.title as work_type_title"
  520. . ",(select count(*) from table_user_show_template where uid = u.uid) as showTempCount"
  521. . ",(select count(*) from table_info_audit where uid = u.uid and status = 1) as is_info_audit"
  522. . ",(select count(*) from table_type_audit where uid = u.uid and status = 1) as is_type_audit"
  523. . ",(select count(*) from table_user where parent_uid = u.uid) as branchCount";
  524. }
  525. $totalCount = $this->alias("u")->where($where)->count();
  526. $data = null;
  527. if ($totalCount > 0) {
  528. $data = $this
  529. ->alias("u")
  530. ->field($field)
  531. ->leftJoin("user p", "p.uid = u.parent_uid")
  532. ->leftJoin("user_work_type wt", "wt.id = u.work_type_id")//职称
  533. ->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")//职称
  534. ->where($where)
  535. ->order("u.show_temp_seq", "desc")
  536. ->order("u.uid", "desc")
  537. ->page($post["page"], $post["pageSize"])
  538. ->select();
  539. // var_dump($this->getLastSql());
  540. if (!empty($data)) {
  541. $data = $data->toArray();
  542. }
  543. }
  544. $data = empty($data) ? [] : $data;
  545. $ShowTemplateDb = new ShowTemplate();
  546. foreach ($data as $k => $v) {
  547. if (!empty($v["regtime"])) {
  548. $data[$k]["regtime"] = date("Y-m-d H:i:s", $v["regtime"]);
  549. }
  550. if (!empty($v["parent_time"])) {
  551. $data[$k]["parent_time"] = date("Y-m-d H:i:s", $v["parent_time"]);
  552. }
  553. }
  554. // $datatwo = [];
  555. // foreach($data as $v){
  556. // if($v['is_show'] == 1){
  557. // $datatwo[] = $v;
  558. // }
  559. // }
  560. return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
  561. }
  562. /**
  563. * 前端获取用户列表
  564. * @param type $post
  565. * @param type $field
  566. * @return type
  567. */
  568. public function getDataList($post, $field = "*", $is_admin = 0)
  569. {
  570. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  571. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  572. $where = [];
  573. //用户uid
  574. if (!empty($post['uid'])) {
  575. $where[] = ["u.uid", "=", $post['uid']];
  576. }
  577. //状态
  578. if (isset($post["status"]) && in_array((string)$post["status"], ["0", "1", "-1"])) {
  579. $where[] = ["u.status", "=", (int)$post["status"]];
  580. }
  581. //昵称
  582. if (!empty($post["nickname"])) {
  583. $where[] = ["u.nickname", "like", "%{$post["nickname"]}%"];
  584. }
  585. //手机号码
  586. if (!empty($post["mobile"])) {
  587. $where[] = ["u.mobile", "=", $post["mobile"]];
  588. }
  589. //父级uid
  590. if (!empty($post["parent_uid"])) {
  591. $where[] = ["u.parent_uid", "=", $post["parent_uid"]];
  592. }
  593. //注册时间
  594. if (!empty($post['time']) && !empty($post['time'][0]) && !empty($post['time'][1])) {
  595. $startTime = strtotime($post['time'][0]);
  596. $endTime = strtotime($post['time'][1]);
  597. $where[] = ["u.regtime", "between", "{$startTime},{$endTime}"];
  598. }
  599. if ($is_admin == 1) {
  600. $field = "u.*"
  601. . ",p.nickname as p_nickname,p.mobile as p_mobile"
  602. . ",wt.title as work_type_title"
  603. . ",(select count(*) from table_user_show_template where uid = u.uid) as showTempCount"
  604. . ",(select count(*) from table_info_audit where uid = u.uid and status = 1) as is_info_audit"
  605. . ",(select count(*) from table_type_audit where uid = u.uid and status = 1) as is_type_audit"
  606. . ",(select count(*) from table_user where parent_uid = u.uid) as branchCount";
  607. }
  608. $totalCount = $this->alias("u")->where($where)->count();
  609. $data = null;
  610. if ($totalCount > 0) {
  611. $data = $this
  612. ->alias("u")
  613. ->field($field)
  614. ->leftJoin("user p", "p.uid = u.parent_uid")
  615. ->leftJoin("user_work_type wt", "wt.id = u.work_type_id")//职称
  616. ->where($where)
  617. ->order("u.uid", "desc")
  618. ->page($post["page"], $post["pageSize"])
  619. ->select();
  620. if (!empty($data)) {
  621. $data = $data->toArray();
  622. }
  623. }
  624. $data = empty($data) ? [] : $data;
  625. foreach ($data as $k => $v) {
  626. if (!empty($v["regtime"])) {
  627. $data[$k]["regtime"] = date("Y-m-d H:i:s", $v["regtime"]);
  628. }
  629. if (!empty($v["parent_time"])) {
  630. $data[$k]["parent_time"] = date("Y-m-d H:i:s", $v["parent_time"]);
  631. }
  632. }
  633. return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
  634. }
  635. }