User.php 30 KB

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