User.php 29 KB

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