User.php 27 KB

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