NewsService.php 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\WebsiteCategory;
  7. use App\Model\ArticleSurvey;
  8. use App\Model\District;
  9. use App\Model\Good;
  10. use App\Model\JobCompany;
  11. use App\Model\Website;
  12. use App\Model\JobRecruiting;
  13. use App\Model\JobIndustry;
  14. use App\Model\JobPosition;
  15. use App\Model\JobNature;
  16. use App\Model\JobEnum;
  17. use App\Model\User;
  18. use App\Model\UserRole;
  19. use App\Model\News;
  20. use App\Model\UserInfo;
  21. use App\Model\WebsiteGroup;
  22. ;
  23. use Hyperf\DbConnection\Db;
  24. use Hyperf\RpcServer\Annotation\RpcService;
  25. use App\Tools\Result;
  26. use Directory;
  27. use Ramsey\Uuid\Uuid;
  28. use Hyperf\Utils\Random;
  29. use function Hyperf\Support\retry;
  30. use App\Model\JobResume;
  31. use App\Model\JobHunting;
  32. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  33. class NewsService implements NewsServiceInterface
  34. {
  35. /**
  36. * 获取导航池列表
  37. * @param array $data
  38. * @return array
  39. */
  40. public function getCategoryList(array $data): array
  41. {
  42. $where = [];
  43. if (isset($data['name']) && $data['name']) {
  44. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  45. }
  46. if (isset($data['department_id']) && $data['department_id']) {
  47. array_push($where, ['category.department_id', '=', $data['department_id']]);
  48. }
  49. $city_id = '';
  50. if (isset($data['city_id']) && $data['city_id']) {
  51. $city_id = intval($data['city_id']);
  52. }
  53. $rep = Category::where($where)
  54. ->when($city_id, function ($query) use ($city_id) {
  55. if (isset($city_id) && $city_id) {
  56. $query->whereJsonContains("category.city_arr_id", $city_id);
  57. }
  58. })
  59. ->leftJoin('district', 'category.city_id', 'district.id')
  60. ->leftJoin('department', 'category.department_id', 'department.id')
  61. ->select("category.*", "district.name as city_name", "department.name as department_name")
  62. ->limit($data['pageSize'])->orderByDesc('category.updated_at')->offset(($data['page'] - 1) * $data['pageSize'])->get();
  63. $count = Category::where($where)->when($city_id, function ($query) use ($city_id) {
  64. if (isset($city_id) && $city_id) {
  65. $query->whereJsonContains("category.city_arr_id", $city_id);
  66. }
  67. })->count();
  68. $data = [
  69. 'rows' => $rep->toArray(),
  70. 'count' => $count,
  71. ];
  72. if (empty($rep->toArray())) {
  73. return Result::error("没有导航池数据");
  74. }
  75. return Result::success($data);
  76. }
  77. public function myCategoryList(array $data): array
  78. {
  79. $sszq = $data['sszq'] ?? '';
  80. unset($data['sszq']);
  81. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  82. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  83. $where[] = [
  84. 'pid', '=', $data['pid'],
  85. ];
  86. if (isset($data['name'])) {
  87. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  88. }
  89. var_dump($where);
  90. //根据分类id,从category表中取出分类信息
  91. $result = Category::where($where)
  92. ->whereIn('category.id', $catorytids)
  93. ->select('category.*', 'category.id as category_id')->get();
  94. if (empty($result)) {
  95. return Result::error("没有栏目数据");
  96. }
  97. return Result::success($result);
  98. }
  99. /**
  100. * @param array $data
  101. * @return array
  102. */
  103. public function categoryList(array $data): array
  104. {
  105. $where[] = [
  106. 'pid', '=', $data['pid'],
  107. ];
  108. if (isset($data['name'])) {
  109. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  110. }
  111. var_dump($where);
  112. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  113. if (empty($result)) {
  114. return Result::error("没有栏目数据");
  115. }
  116. return Result::success($result);
  117. }
  118. /**
  119. * @param array $data
  120. * @return array
  121. */
  122. public function addCategory(array $data): array
  123. {
  124. $id = Category::insertGetId($data);
  125. if (empty($id)) {
  126. return Result::error("添加失败");
  127. }
  128. return Result::success(['id' => $id]);
  129. }
  130. /**
  131. * @param array $data
  132. * @return array
  133. */
  134. public function delCategory(array $data): array
  135. {
  136. $categoryList = Category::where(['pid' => $data['id']])->get();
  137. var_dump("分类列表:", $data, $categoryList);
  138. if ($categoryList->toArray()) {
  139. return Result::error("分类下面有子分类不能删除");
  140. }
  141. $articleList = Article::where(['catid' => $data['id']])->get();
  142. var_dump("文章列表:", $articleList);
  143. if ($articleList->toArray()) {
  144. return Result::error("分类下面有资讯不能删除");
  145. }
  146. $result = Category::where($data)->delete();
  147. if (!$result) {
  148. return Result::error("删除失败");
  149. }
  150. return Result::success($result);
  151. }
  152. /**
  153. * @param array $data
  154. * @return array
  155. */
  156. public function updateCategory(array $data): array
  157. {
  158. $where = [
  159. 'id' => $data['id'],
  160. ];
  161. $result = Category::where($where)->update($data);
  162. if ($result) {
  163. return Result::success($result);
  164. } else {
  165. return Result::error("更新失败");
  166. }
  167. }
  168. /**
  169. * 获取导航池信息
  170. * @param array $data
  171. * @return array
  172. */
  173. public function getCategoryInfo(array $data): array
  174. {
  175. $where = [
  176. 'id' => $data['id'],
  177. ];
  178. $result = Category::where($where)->first();
  179. if ($result) {
  180. return Result::success($result);
  181. } else {
  182. return Result::error("更新失败");
  183. }
  184. }
  185. /**
  186. * @param array $data
  187. * @return array
  188. */
  189. public function getArticleList(array $data): array
  190. {
  191. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  192. $type_id = $data['type_id'];
  193. unset($data['type_id']);
  194. $user_id = $data['user_id'];
  195. unset($data['user_id']);
  196. $where = [];
  197. if (isset($data['title']) && $data['title']) {
  198. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  199. }
  200. if (isset($data['category_name']) && $data['category_name']) {
  201. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  202. }
  203. if (isset($data['author']) && $data['author']) {
  204. array_push($where, ['article.author', '=', $data['author']]);
  205. }
  206. if (isset($data['islink']) && $data['islink'] !== "") {
  207. array_push($where, ['article.islink', '=', $data['islink']]);
  208. }
  209. if (isset($data['status']) && $data['status'] !== "") {
  210. array_push($where, ['article.status', '=', $data['status']]);
  211. }
  212. //不是管理员展示个人数据;
  213. if ($type_id != 10000) {
  214. $where[] = ['article.admin_user_id', '=', $user_id];
  215. }
  216. $rep = Article::where($where)
  217. ->whereNotIn('article.status', [404])
  218. ->leftJoin('category', 'article.catid', 'category.id')
  219. ->select("article.*", "category.name as category_name")
  220. ->orderBy("article.id", "desc")
  221. ->limit($data['pageSize'])
  222. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  223. $count = Article::where($where)->whereNotIn('article.status', [404])
  224. ->leftJoin('category', 'article.catid', 'category.id')->count();
  225. $data = [
  226. 'rows' => $rep->toArray(),
  227. 'count' => $count,
  228. ];
  229. if (empty($rep)) {
  230. return Result::error("没有信息数据");
  231. }
  232. return Result::success($data);
  233. }
  234. /**
  235. * @param array $data
  236. * @return array
  237. */
  238. public function addArticle(array $data): array
  239. {
  240. var_dump($data, '----------12-----------1');
  241. unset($data['user_type']);
  242. // unset($data['web_site_id']);
  243. unset($data['nav_add_pool_id']);
  244. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  245. Db::beginTransaction();
  246. try {
  247. //处理投票
  248. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  249. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  250. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  251. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  252. unset($data['is_survey']);
  253. unset($data['survey_name']);
  254. unset($data['suvey_array']);
  255. unset($data['website_id']);
  256. $articleData = $data;
  257. unset($articleData['content']);
  258. $id = Article::insertGetId($articleData);
  259. $articleDataContent = [
  260. 'article_id' => $id,
  261. 'content' => $data['content'],
  262. ];
  263. ArticleData::insertGetId($articleDataContent);
  264. //处理投票
  265. if ($is_survey == 1) {
  266. //生成年月日时分秒+8位随机数
  267. $uuid = date('YmdHis') . rand(10000000, 99999999);
  268. var_dump($suvey_array, 'suvey_array________');
  269. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  270. var_dump($suveys_array, '---------------------1');
  271. var_dump($suvey_array, '---------------------2');
  272. $suvey_data = [];
  273. foreach ($suveys_array as $key => $value) {
  274. if ($value == '') {
  275. continue;
  276. }
  277. if (is_array($value)) {
  278. $suvey_data[] = [
  279. 'sur_id' => $uuid,
  280. 'art_id' => $id,
  281. 'website_id' => $website_id ?? 2,
  282. 'survey_name' => $survey_name,
  283. 'choice_name' => $value[1],
  284. 'is_other' => 1,
  285. 'other_id' => 0,
  286. 'results' => 0,
  287. ];
  288. } else {
  289. $suvey_data[] = [
  290. 'sur_id' => $uuid,
  291. 'art_id' => $id,
  292. 'website_id' => $website_id ?? 2,
  293. 'survey_name' => $survey_name,
  294. 'choice_name' => $value,
  295. 'is_other' => 0,
  296. 'other_id' => 0,
  297. 'results' => 0,
  298. ];
  299. }
  300. if (empty($suvey_data)) {
  301. throw new \Exception("投票数据为空");
  302. }
  303. }
  304. $result = ArticleSurvey::insert($suvey_data);
  305. if (!$result) {
  306. throw new \Exception("投票失败,ArticleSurvey插入失败");
  307. }
  308. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  309. if (!$result) {
  310. throw new \Exception("投票失败,更新主表失败");
  311. }
  312. }
  313. Db::commit();
  314. return Result::success(['id' => $id]);
  315. } catch (\Throwable $ex) {
  316. Db::rollBack();
  317. var_dump($ex->getMessage());
  318. return Result::error("创建失败", 0);
  319. }
  320. }
  321. /**
  322. * @param array $data
  323. * @return array
  324. */
  325. public function delArticle(array $data): array
  326. {
  327. $result = Article::where($data)->delete();
  328. //survey投票删除
  329. articleSurvey::where(['art_id' => $data['id']])->delete();
  330. if (!$result) {
  331. return Result::error("删除失败");
  332. }
  333. return Result::success($result);
  334. }
  335. /**
  336. * @param array $data
  337. * @return array
  338. */
  339. public function updateArticle(array $data): array
  340. {
  341. var_dump($data, '----------12-----------1');
  342. Db::beginTransaction();
  343. unset($data['user_type']);
  344. // unset($data['web_site_id']);
  345. unset($data['nav_add_pool_id']);
  346. try {
  347. //处理投票
  348. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  349. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  350. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  351. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  352. unset($data['is_survey']);
  353. unset($data['survey_name']);
  354. unset($data['suvey_array']);
  355. unset($data['website_id']);
  356. if ($data['hits'] == '') {
  357. $data['hits'] = 0;
  358. }
  359. if ($data['is_original'] == '') {
  360. $data['is_original'] = 0;
  361. }
  362. if ($data['status'] == '') {
  363. $data['status'] = 0;
  364. }
  365. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  366. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  367. $articleData = $data;
  368. unset($articleData['content']);
  369. unset($articleData['status_name']);
  370. unset($articleData['name']);
  371. unset($articleData['content']);
  372. unset($articleData['pid_arr']);
  373. unset($articleData['pid']);
  374. $id = Article::where(['id' => $data['id']])->update($articleData);
  375. $articleDataContent = [
  376. 'content' => $data['content'],
  377. ];
  378. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  379. //处理投票
  380. $id = $data['id'];
  381. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  382. var_dump($suvey_array, 'suvey_array________delete');
  383. //处理投票
  384. if ($is_survey == 1) {
  385. //生成年月日时分秒+8位随机数
  386. $uuid = date('YmdHis') . rand(10000000, 99999999);
  387. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  388. var_dump($suveys_array, '---------------------1');
  389. var_dump($suvey_array, '---------------------2');
  390. $suvey_data = [];
  391. if (is_array($suveys_array)) {
  392. foreach ($suveys_array as $key => $value) {
  393. if ($value == '') {
  394. continue;
  395. }
  396. if (is_array($value)) {
  397. $suvey_data[] = [
  398. 'sur_id' => $uuid,
  399. 'art_id' => $id,
  400. 'website_id' => $website_id ?? 2,
  401. 'survey_name' => $survey_name,
  402. 'choice_name' => $value[1],
  403. 'is_other' => 1,
  404. 'other_id' => 0,
  405. 'results' => 0,
  406. ];
  407. } else {
  408. $suvey_data[] = [
  409. 'sur_id' => $uuid,
  410. 'art_id' => $id,
  411. 'website_id' => $website_id ?? 2,
  412. 'survey_name' => $survey_name,
  413. 'choice_name' => $value,
  414. 'is_other' => 0,
  415. 'other_id' => 0,
  416. 'results' => 0,
  417. ];
  418. }
  419. if (empty($suvey_data)) {
  420. throw new \Exception("投票数据为空");
  421. }
  422. }
  423. }
  424. $result = ArticleSurvey::insert($suvey_data);
  425. if (!$result) {
  426. throw new \Exception("投票失败");
  427. }
  428. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  429. if (!$result) {
  430. throw new \Exception("投票失败");
  431. }
  432. } else {
  433. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  434. }
  435. Db::commit();
  436. return Result::success([]);
  437. } catch (\Throwable $ex) {
  438. Db::rollBack();
  439. var_dump($ex->getMessage());
  440. return Result::error("更新失败1" . $ex->getMessage(), 0);
  441. }
  442. }
  443. /**
  444. * 更新资讯状态
  445. * @param array $data
  446. * @return array
  447. */
  448. public function upArticleStatus(array $data): array
  449. {
  450. $result = Article::where(['id' => $data['id']])->update($data);
  451. if ($result) {
  452. return Result::success();
  453. } else {
  454. return Result::error("更新状态失败", 0);
  455. }
  456. }
  457. /**
  458. * @param array $data
  459. * @return array
  460. */
  461. public function getArticleInfo(array $data): array
  462. {
  463. $where = [
  464. 'article.id' => $data['id'],
  465. // 'article.status' => 1,
  466. ];
  467. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  468. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get()->all();
  469. var_dump($articleSurvey, 'articleSurvey');
  470. $info = $result;
  471. var_dump($info, 'info');
  472. // $info['survey_array'] = $articleSurvey == null ? [] : $info['survey_array'];
  473. if ($result) {
  474. return Result::success($info);
  475. } else {
  476. return Result::error("查询失败", 0);
  477. }
  478. }
  479. /**
  480. * 获取新闻
  481. * @param array $data
  482. * @return array
  483. */
  484. public function getWebsiteArticlett(array $data): array
  485. {
  486. $category = WebsiteCategory::where('website_id', $data['website_id'])->select('category_id')->get();
  487. $category = $category->toArray();
  488. $result = [];
  489. if ($category) {
  490. $category_ids = [];
  491. foreach ($category as $val) {
  492. array_push($category_ids, $val['category_id']);
  493. }
  494. if (isset($data['placeid'])) {
  495. $placeid = $data['placeid'] - 1;
  496. $result = Article::where('status', 1)->where('level', $data['level'])->whereIn("catid", $category_ids)->orderBy("updated_at", "desc")->offset($placeid)->limit($data['pageSize'])->get();
  497. } else {
  498. $result = Article::where('status', 1)->where('level', $data['level'])->whereIn("catid", $category_ids)->orderBy("updated_at", "desc")->offset(0)->limit($data['pageSize'])->get();
  499. }
  500. if (empty($result)) {
  501. return Result::error("暂无头条新闻", 0);
  502. }
  503. return Result::success($result);
  504. } else {
  505. return Result::error("本网站下暂无相关栏目", 0);
  506. }
  507. }
  508. /**
  509. * 获取模块新闻
  510. * @param array $data
  511. * @return array
  512. */
  513. public function getWebsiteModelArticles(array $data): array
  514. {
  515. $catid = $data['catid'];
  516. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  517. $category = $category->toArray();
  518. if (!empty($category)) {
  519. $where = [
  520. 'status' => 1,
  521. 'catid' => $catid,
  522. ];
  523. if ($data['level'] == 1) {
  524. $level = [
  525. 0 => '1',
  526. 1 => '4',
  527. 2 => '5',
  528. 3 => '0',
  529. ];
  530. $result = Article::where($where)->whereIn('level', $level)->orderBy("updated_at", "desc")->limit($data['pagesize'])->get();
  531. } elseif ($data['level'] == 2) {
  532. $level = '2';
  533. $result = Article::where($where)->where('level', $level)->orderBy("updated_at", "desc")->limit($data['pagesize'])->get();
  534. } else {
  535. $level = '3';
  536. $result = Article::where($where)->where('level', $level)->orderBy("updated_at", "desc")->limit($data['pagesize'])->get();
  537. }
  538. $result = $result->toArray();
  539. if (!empty($result) && isset($data['placeid']) && !empty($data['placeid'])) {
  540. $placeid = $data['placeid'] - 1;
  541. if ($level == 2 || $level == 3) {
  542. $where = [
  543. 'level' => $level,
  544. ];
  545. $result = Article::where($where)
  546. ->orderBy("updated_at", "desc")
  547. ->offset($placeid)
  548. ->limit($data['pagesize'])->get();
  549. } else {
  550. $result = Article::where($where)
  551. ->whereIn('level', $level)
  552. ->offset($placeid)
  553. ->orderBy("updated_at", "desc")
  554. ->limit($data['pagesize'])->get();
  555. }
  556. }
  557. if (empty($result)) {
  558. return Result::error("此栏目暂无相关新闻", 0);
  559. }
  560. } else {
  561. return Result::error("此网站暂无此栏目", 0);
  562. }
  563. return Result::success($result);
  564. }
  565. /**
  566. *获取新闻列表
  567. * @param array $data
  568. * @return array
  569. */
  570. public function getWebsiteArticleList(array $data): array
  571. {
  572. $where[] = ['status', '=', 1];
  573. if (isset($data['keyword']) && !empty($data['keyword'])) {
  574. array_push($where, ['article.title', 'like', '%' . $data['keyword'] . '%']);
  575. }
  576. if (isset($data['catid']) && !empty($data['catid'])) {
  577. if (is_array($data['catid'])) {
  578. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  579. array_push($where, ['catid', 'in', $data['catid']]);
  580. } else {
  581. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  582. array_push($where, ['catid', '=', $data['catid']]);
  583. }
  584. if (empty($category)) {
  585. return Result::error("此网站暂无此栏目", 0);
  586. }
  587. }
  588. // return Result::success($where);
  589. $rep = Article::where(function ($query) use ($where) {
  590. foreach ($where as $condition) {
  591. if ($condition[1] === 'in') {
  592. $query->whereIn($condition[0], $condition[2]);
  593. } else {
  594. $query->where($condition[0], $condition[1], $condition[2]);
  595. }
  596. }
  597. })
  598. ->orderBy("updated_at", "desc")
  599. ->limit($data['pageSize'])
  600. ->offset(($data['page'] - 1) * $data['pageSize'])
  601. ->get();
  602. $count = Article::where(function ($query) use ($where) {
  603. foreach ($where as $condition) {
  604. if ($condition[1] === 'in') {
  605. $query->whereIn($condition[0], $condition[2]);
  606. } else {
  607. $query->where($condition[0], $condition[1], $condition[2]);
  608. }
  609. }
  610. })->count();
  611. $data = [
  612. 'rows' => $rep->toArray(),
  613. 'count' => $count,
  614. ];
  615. if (empty($rep)) {
  616. return Result::error("没有信息数据");
  617. }
  618. return Result::success($data);
  619. }
  620. /**
  621. * 前端-获取新闻详情
  622. * @param array $data
  623. * @return array
  624. */
  625. public function selectWebsiteArticleInfo(array $data): array
  626. {
  627. $where = [
  628. 'article.id' => $data['id'],
  629. 'article.status' => 1,
  630. ];
  631. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  632. if (empty($result)) {
  633. return Result::error("查询失败", 0);
  634. }
  635. $category = WebsiteCategory::where('website_id', $data['website_id'])->where(['category_id' => $result['catid']])->first();
  636. if (empty($category)) {
  637. return Result::error("查询失败", 0);
  638. }
  639. $result['category_id'] = $category['category_id'];
  640. $result['cat_name'] = $category['alias'];
  641. return Result::success($result);
  642. }
  643. /**
  644. * 前端-获取网站调查问卷
  645. * @param array $data
  646. * @return array
  647. */
  648. public function getWebsiteSurvey(array $data): array
  649. {
  650. if (isset($data['website_id']) && !empty($data['website_id'])) {
  651. $website = Website::where('id', $data['website_id'])->first();
  652. if (empty($website)) {
  653. return Result::error("暂无此网站", 0);
  654. }
  655. }
  656. if (isset($data['art_id']) && !empty($data['art_id'])) {
  657. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  658. if (empty($article)) {
  659. return Result::error("暂无此文章", 0);
  660. }
  661. // return Result::error($data,0);
  662. $where['art_id'] = $data['art_id'];
  663. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  664. } else {
  665. $survey = ArticleSurvey::where('website_id', $data['website_id'])->orderBy('created_at')->first();
  666. if (empty($survey)) {
  667. return Result::error("暂无调查问卷", 0);
  668. }
  669. $where['sur_id'] = $survey['sur_id'];
  670. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  671. }
  672. $result['survey'] = ArticleSurvey::where($where)->where('is_other', 0)
  673. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  674. ->select('article_survey.*', 'article.survey_type')
  675. ->get()->all();
  676. $result['other'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  677. $result['others'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->first();
  678. if (empty($result)) {
  679. return Result::error("此文章暂无调查问卷", 0);
  680. }
  681. return Result::success($result);
  682. }
  683. /**
  684. * 前端-添加网站调查问卷选项
  685. * @param array $data
  686. * @return array
  687. */
  688. public function addWebsiteSurveyOption(array $data): array
  689. {
  690. if (isset($data['website_id']) && !empty($data['website_id'])) {
  691. $website = Website::where('id', $data['website_id'])->first();
  692. if (empty($website)) {
  693. return Result::error("暂无此网站", 0);
  694. }
  695. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  696. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  697. if (empty($survey)) {
  698. return Result::error("此调查问卷不可添加选项", 0);
  699. }
  700. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  701. $choice = [
  702. 'art_id' => $survey['art_id'],
  703. 'website_id' => $data['website_id'],
  704. 'survey_name' => $survey['survey_name'],
  705. 'choice_name' => $data['choice_name'],
  706. 'sur_id' => $survey['sur_id'],
  707. 'is_other' => 1,
  708. 'other_id' => $survey['id'],
  709. ];
  710. $result = ArticleSurvey::insertGetId($choice);
  711. if (empty($result)) {
  712. return Result::error("添加失败", 0);
  713. }
  714. return Result::success($result);
  715. }
  716. }
  717. return Result::error("添加失败", 0);
  718. }
  719. return Result::error("添加失败", 0);
  720. }
  721. /**
  722. * 前端-调查问卷投票
  723. * @param array $data
  724. * @return array
  725. */
  726. public function addWebsiteSurveyVote(array $data): array
  727. {
  728. if (isset($data['website_id']) && !empty($data['website_id'])) {
  729. $website = Website::where('id', $data['website_id'])->first();
  730. if (empty($website)) {
  731. return Result::error("暂无此网站", 0);
  732. }
  733. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  734. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->pluck('sur_id');
  735. if (empty($survey)) {
  736. return Result::error("此调查问卷不存在", 0);
  737. }
  738. // return Result::success($survey);
  739. // 调查问卷类型 0:单选 1:多选
  740. $type = Article::where('survey_id', $data['sur_id'])->pluck('survey_type');
  741. // return Result::success($type);
  742. if (empty($type) || ($type[0] != 1 && $type[0] != 0)) {
  743. return Result::error("此调查问卷不可投票", 0);
  744. }
  745. // return Result::success($type[0]);
  746. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  747. if ($type[0] == 0) {
  748. if (is_array($data['choice_id'])) {
  749. return Result::error("请选择一个选项!", 0);
  750. }
  751. $data['choice_id'] = [$data['choice_id']];
  752. } else {
  753. if (!is_array($data['choice_id'])) {
  754. return Result::error("请传递数组!", 0);
  755. }
  756. }
  757. // return Result::success($data['choice_id']);
  758. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  759. ->where('website_id', $data['website_id'])
  760. ->where('is_other', 1)
  761. ->where('other_id', 0)
  762. ->first();
  763. if (!empty($other)) {
  764. return Result::error("请选择已有的选项!", 0);
  765. }
  766. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  767. ->where('website_id', $data['website_id'])
  768. ->where('is_other', 1)
  769. ->where('other_id', '!=', 0)
  770. ->first();
  771. // return Result::success($data);
  772. if (!empty($choice['other'])) {
  773. array_push($data['choice_id'], $choice['other']['other_id']);
  774. // return Result::success($data['choice_id']);
  775. }
  776. // return Result::success($data);
  777. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  778. ->where('website_id', $data['website_id'])
  779. ->increment('results', 1);
  780. if (empty($choice)) {
  781. return Result::error("请选择已有的选项!", 0);
  782. }
  783. return Result::success($choice);
  784. }
  785. return Result::error("参数必填!");
  786. // if(isset($data['choice_id']) && !empty($data['choice_id'])){
  787. // $choice = ArticleSurvey::whereIn('id',$data['choice_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
  788. // }
  789. }
  790. return Result::error("此调查问卷不存在", 0);
  791. }
  792. return Result::error("参数必填!");
  793. }
  794. /**
  795. * 后端-获取网站调查问卷列表
  796. * @param array $data
  797. * @return array
  798. */
  799. public function getSurveyList(array $data): array
  800. {
  801. $where = [];
  802. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  803. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  804. }
  805. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  806. array_push($where, ['survey_type', '=', $data['survey_type']]);
  807. }
  808. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  809. array_push($where, ['is_survey', '=', $data['is_survey']]);
  810. }
  811. // return Result::success($where);
  812. if (!empty($where)) {
  813. $query = Article::where($where)->whereNotNull('survey_name');
  814. } else {
  815. $query = Article::whereNotNull('survey_name');
  816. }
  817. $count = $query->count();
  818. $survey = $query->orderByDesc('id')
  819. ->limit($data['pageSize'])
  820. ->offset(($data['page'] - 1) * $data['pageSize'])
  821. ->get();
  822. if (empty($survey->toArray())) {
  823. return Result::error("暂无调查问卷!", 0);
  824. }
  825. $result = [
  826. 'rows' => $survey,
  827. 'count' => $count,
  828. ];
  829. return Result::success($result);
  830. }
  831. /**
  832. * 后端-获取网站调查问卷详情
  833. * @param array $data
  834. * @return array
  835. */
  836. public function getSurveyInfo(array $data): array
  837. {
  838. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  839. $where = ['sur_id' => $data['sur_id']];
  840. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  841. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  842. ->select('article_survey.*', 'article.survey_type')
  843. ->get()->all();
  844. if (empty($choose)) {
  845. return Result::error("此调查问卷不存在", 0);
  846. }
  847. $resultsArray = array_column($choose, 'results');
  848. $total = array_sum($resultsArray);
  849. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  850. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  851. // $total = 0;
  852. if (!empty($other)) {
  853. $total = $total + $other['results'];
  854. $other['choice_name'] = $other['choice_name'] . '(其他)';
  855. if (!empty($others)) {
  856. $other['hasChildren'] = true;
  857. // array_push($other,['hasChildren','=',true]);
  858. $other['children'] = $others;
  859. $other_choices = [$other->toArray()];
  860. $mer_choice = array_merge($choose, $other_choices);
  861. $value_choice = array_values($mer_choice);
  862. } else {
  863. // return Result::error('1111');
  864. $other_choices = [$other->toArray()];
  865. $other_choices = array_merge($choose, $other_choices);
  866. $value_choice = array_values($other_choices);
  867. // return Result::success($result);
  868. }
  869. } else {
  870. $value_choice = $choose;
  871. }
  872. $result = [
  873. 'choose' => $value_choice,
  874. 'total' => $total,
  875. ];
  876. }
  877. return Result::success($result);
  878. }
  879. /**
  880. * 验证导航名称是否重复
  881. * @return void
  882. */
  883. public function checkCategoryName(array $data): array
  884. {
  885. $result = Category::when($data, function ($query) use ($data) {
  886. if (isset($data['name']) && $data['name']) {
  887. $query->where("name", $data['name']);
  888. }
  889. if (isset($data['id']) && $data['id']) {
  890. $query->where("id", "!=", $data['id']);
  891. }
  892. })->first();
  893. if ($result) {
  894. return Result::error("已存在");
  895. } else {
  896. return Result::success();
  897. }
  898. }
  899. //20250226 产品列表
  900. public function getGoodList(array $data): array
  901. {
  902. $where = [];
  903. //类型
  904. if (isset($data['type_id']) && $data['type_id']) {
  905. $where = [
  906. 'type_id' => $data['type_id'],
  907. ];
  908. }
  909. //名称
  910. if (isset($data['name']) && $data['name']) {
  911. $where = [
  912. 'good.name' => $data['name'],
  913. ];
  914. }
  915. $where1 = [];
  916. //website_id
  917. // if (isset($data['website_id']) && $data['website_id']) {
  918. // $where1 = [
  919. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  920. // ];
  921. // }
  922. // website_name
  923. if (isset($data['website_name']) && $data['website_name']) {
  924. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  925. }
  926. // catid
  927. if (isset($data['category_name']) && $data['category_name']) {
  928. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  929. }
  930. // $result = Good::where($where)
  931. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  932. $result = Good::where($where)
  933. ->when(!empty($where1), function ($query) use ($where1) {
  934. return $query->where($where1);
  935. })
  936. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  937. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  938. ->leftJoin('category', 'good.catid', '=', 'category.id')
  939. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  940. ->orderBy("id", "desc")
  941. ->limit($data['page_size'])
  942. ->offset(($data['page'] - 1) * $data['page_size'])
  943. ->get();
  944. $count = Good::where($where)
  945. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  946. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  947. ->leftJoin('category', 'good.catid', '=', 'category.id')
  948. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  949. ->orderBy("updated_at", "desc")->count();
  950. $data = [
  951. 'rows' => $result->toArray(),
  952. 'count' => $count,
  953. ];
  954. if (empty($result)) {
  955. return Result::error("此栏目暂无相关产品", 0);
  956. }
  957. return Result::success($data);
  958. }
  959. public function getGoodInfo(array $data): array
  960. {
  961. $result = Good::where('id', $data['id'])->first();
  962. if (empty($result)) {
  963. return Result::error("此产品不存在", 0);
  964. }
  965. return Result::success($result);
  966. }
  967. public function addGood(array $data): array
  968. {
  969. // unset($data['city_arr_id']);
  970. // unset($data['cat_arr_id']);
  971. $data['city_id'] = end($data['city_arr_id']);
  972. $data['catid'] = end($data['cat_arr_id']);
  973. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  974. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  975. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  976. unset($data['imgUrl']);
  977. $result = Good::insert($data);
  978. if (empty($result)) {
  979. return Result::error("添加失败", 0);
  980. }
  981. return Result::success($result);
  982. }
  983. public function updateGood(array $data): array
  984. {
  985. $data['city_id'] = end($data['city_arr_id']);
  986. $data['catid'] = end($data['cat_arr_id']);
  987. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  988. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  989. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  990. //设置东八区
  991. date_default_timezone_set('Asia/Shanghai');
  992. $data['updated_at'] = date('Y-m-d H:i:s');
  993. $result = Good::where('id', $data['id'])->update($data);
  994. if (empty($result)) {
  995. return Result::error("更新失败", 0);
  996. }
  997. return Result::success($result);
  998. }
  999. public function delGood(array $data): array
  1000. {
  1001. $result = Good::where('id', $data['id'])->delete();
  1002. if (empty($result)) {
  1003. return Result::error("删除失败", 0);
  1004. }
  1005. return Result::success($result);
  1006. }
  1007. //20250226 产品列表
  1008. // 20250306 -------招聘--------fr
  1009. /*
  1010. * 招聘列表
  1011. * */
  1012. public function getJobRecruitingList(array $data): array
  1013. {
  1014. $where = [];
  1015. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  1016. if($data['checkout'] == 0){
  1017. $job_status = [0, 2];
  1018. }else{
  1019. $job_status = [1];
  1020. }
  1021. if(isset($data['keyword']) && !empty($data['keyword'])){
  1022. array_push($where, ['job_recruiting.title', 'like', '%'. $data['keyword']. '%']);
  1023. }
  1024. $user = User::where('id', $data['user_id'])->first();
  1025. if(empty($user)){
  1026. return Result::error("用户不存在", 0);
  1027. }
  1028. // 3:企业会员
  1029. if($user['type_id'] == 3){
  1030. array_push($where,['job_recruiting.user_id', $data['user_id']]);
  1031. array_push($where,['job_recruiting.website_id', $data['website_id']]);
  1032. }
  1033. // 如果 $where 为空,则不添加 where 条件
  1034. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  1035. return $query->where($where);
  1036. })
  1037. ->whereIn('job_recruiting.status',$job_status)
  1038. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  1039. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  1040. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  1041. ->orderBy("updated_at", "desc")
  1042. ->offset(($data['page'] - 1) * $data['page_size'])
  1043. ->limit($data['page_size'])
  1044. ->get()
  1045. ->all();
  1046. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  1047. return $query->where($where);
  1048. })
  1049. ->whereIn('job_recruiting.status',$job_status)
  1050. ->count();
  1051. if (empty($result)) {
  1052. return Result::error("暂无招聘信息", 0);
  1053. }
  1054. return Result::success($result);
  1055. }
  1056. /*
  1057. * 招聘信息添加
  1058. * */
  1059. public function addJobRecruiting(array $data): array
  1060. {
  1061. // return Result::success($data);
  1062. $user = User::where('user.id', $data['user_id'])
  1063. ->where('user.status',1)
  1064. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  1065. ->select(
  1066. 'user.type_id', 'user.mobile','user.email',
  1067. 'user_info.business_name',
  1068. 'user_info.company_hy_id',
  1069. 'user_info.company_nature',
  1070. 'user_info.company_size',
  1071. 'user_info.introduction',
  1072. 'user_info.real_name',
  1073. 'user_info.company_url',
  1074. 'user_info.address_arr_id',
  1075. 'user_info.address'
  1076. )
  1077. ->first();
  1078. if(empty($user) || $user['type_id'] != $data['user_type']){
  1079. return Result::error("用户不存在", 0);
  1080. }
  1081. $web = Website::where('id', $data['website_id'])->first();
  1082. if(empty($web)){
  1083. return Result::error("网站不存在", 0);
  1084. }
  1085. // return Result::success($user);
  1086. $data['action_id'] = $data['user_id'];
  1087. $data['user_type'] = $user['type_id'];
  1088. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  1089. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  1090. $data['cat_arr_id'] = isset($data['cat_arr_id'])? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  1091. $data['city_arr_id'] = isset($data['city_arr_id'])? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  1092. // 公司地址 管理员必填
  1093. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  1094. $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  1095. // 管理员-企业相关信息
  1096. $company = [
  1097. // 'user_id' => $data['user_id']?? null,
  1098. 'business_name' => $data['business_name']?? null,
  1099. 'company_hy_id' => $data['company_hy_id']?? null,
  1100. 'company_size' => $data['company_size']?? null,
  1101. 'company_nature' => $data['company_nature']?? null,
  1102. 'introduction' => $data['introduction']?? null,
  1103. 'real_name' => $data['real_name']?? null,
  1104. 'mobile' => $data['mobile']?? null,
  1105. 'company_url' => $data['company_url']?? null,
  1106. 'address_arr_id' => $data['address_arr_id']?? null,
  1107. 'address' => $data['address']?? null,
  1108. 'email' => $data['email']?? null,
  1109. ];
  1110. //去掉相关企业信息
  1111. $job = array_diff_key($data, array_flip(array_keys($company)));
  1112. Db::beginTransaction();
  1113. try {
  1114. // 先添加职位相关信息
  1115. if($user['type_id'] == 10000){
  1116. $job['status'] = 1;
  1117. }
  1118. if(empty($data['experience']) || $data['experience'] == ''){
  1119. $job['experience'] = null;
  1120. }else{
  1121. $job['experience'] = $data['experience'];
  1122. }
  1123. $jobId = JobRecruiting::insertGetId($job);
  1124. if (empty($jobId)) {
  1125. Db::rollBack();
  1126. return Result::error("添加失败");
  1127. }
  1128. // 添加公司信息
  1129. $company['user_id'] = $data['user_id']?? null;
  1130. $company['job_id'] = $jobId;
  1131. $company['user_type'] = $user['type_id']?? null;
  1132. $company['website_id'] = $data['website_id']?? null;
  1133. if($user['type_id'] == 10000){
  1134. // 管理员添加企业信息
  1135. // return Result::success($company);
  1136. $companyId = JobCompany::insertGetId($company);
  1137. if (empty($companyId)) {
  1138. Db::rollBack();
  1139. return Result::error("添加失败");
  1140. }
  1141. }else{
  1142. // 企业会员添加企业信息
  1143. $company = [
  1144. 'user_id' => $data['user_id']?? null,
  1145. 'business_name' => $user['business_name']?? null,
  1146. 'company_hy_id' => $user['company_hy_id']?? null,
  1147. 'company_size' => $user['company_size']?? null,
  1148. 'company_nature' => $user['company_nature']?? null,
  1149. 'introduction' => $user['introduction']?? null,
  1150. 'real_name' => $user['real_name']?? null,
  1151. 'mobile' => $user['mobile']?? null,
  1152. 'company_url' => $user['company_url']?? null,
  1153. 'address_arr_id' => $user['address_arr_id']?? null,
  1154. 'address' => $user['address']?? null,
  1155. 'email' => $user['email']?? null,
  1156. 'website_id' => $data['website_id']?? null,
  1157. 'user_type' => $user['type_id']?? null,
  1158. 'job_id' => $jobId,
  1159. ];
  1160. $companyId = JobCompany::insertGetId($company);
  1161. if (empty($companyId)) {
  1162. Db::rollBack();
  1163. return Result::error("添加失败");
  1164. }
  1165. // return Result::success($company);
  1166. }
  1167. Db::commit();
  1168. } catch (\Exception $e) {
  1169. Db::rollBack();
  1170. return Result::error($e->getMessage(), 0);
  1171. }
  1172. $result = [
  1173. 'job_id' => $jobId,
  1174. 'company_id' => $companyId,
  1175. ];
  1176. if (empty($result)) {
  1177. return Result::error("添加失败", 0);
  1178. }
  1179. return Result::success($result);
  1180. }
  1181. /*
  1182. * 获取招聘信息详情
  1183. * */
  1184. public function getJobRecruitingInfo(array $data): array
  1185. {
  1186. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  1187. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  1188. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  1189. ->select('job_recruiting.*', 'website.website_name as website_name',
  1190. 'job_company.business_name',
  1191. 'job_company.company_hy_id',
  1192. 'job_company.company_size',
  1193. 'job_company.company_nature',
  1194. 'job_company.introduction',
  1195. 'job_company.real_name',
  1196. 'job_company.mobile',
  1197. 'job_company.company_url',
  1198. 'job_company.address_arr_id',
  1199. 'job_company.address',
  1200. 'job_company.email'
  1201. )
  1202. ->first();
  1203. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  1204. if(!empty($cityId)){
  1205. if(isset($cityId[1]) && $cityId[1] != null){
  1206. $city = District::where('id', $cityId[1])->first(['name']);
  1207. }else{
  1208. $city = District::where('id', $cityId[0])->first(['name']);
  1209. }
  1210. $result['city'] = $city['name'] ?? '';
  1211. }
  1212. $addressId = json_decode($result['address_arr_id'], true)?? [];
  1213. if(is_array($addressId) && !empty($addressId)){
  1214. $address = District::whereIn('id', $addressId)
  1215. ->orderBy('level', 'asc')
  1216. ->get(['name'])
  1217. ->pluck('name')
  1218. ->implode('');
  1219. // $job->address_name = $address ?? '';
  1220. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  1221. }
  1222. if(empty($result)){
  1223. return Result::error("招聘信息不存在", 0);
  1224. }
  1225. // return Result::success($job);
  1226. return Result::success($result);
  1227. }
  1228. /*
  1229. * 修改招聘信息
  1230. * */
  1231. public function upJobRecruiting(array $data): array
  1232. {
  1233. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  1234. // return Result::success($job);
  1235. if(empty($job)){
  1236. return Result::error("招聘信息不存在", 0);
  1237. }
  1238. $user = User::where('id', $data['user_id'])->first();
  1239. // return Result::success($user);
  1240. if(empty($user) || $user['type_id']!= $data['user_type']){
  1241. return Result::error("用户不存在", 0);
  1242. }
  1243. if($user['type_id']==3 && $job['user_id']!= $user['id']){
  1244. return Result::error("用户暂无权限修改此招聘信息!", 0);
  1245. }
  1246. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  1247. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  1248. $data['cat_arr_id'] = isset($data['cat_arr_id'])? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  1249. $data['city_arr_id'] = isset($data['city_arr_id'])? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  1250. // 公司地址 管理员必填
  1251. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  1252. $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  1253. // 管理员-企业相关信息
  1254. $company = [
  1255. 'business_name' => $data['business_name']?? null,
  1256. 'company_hy_id' => $data['hy_id']?? null,
  1257. 'company_size' => $data['company_size']?? null,
  1258. 'company_nature' => $data['company_nature']?? null,
  1259. 'introduction' => $data['introduction']?? null,
  1260. 'real_name' => $data['real_name']?? null,
  1261. 'mobile' => $data['mobile']?? null,
  1262. 'company_url' => $data['company_url']?? null,
  1263. 'address_arr_id' => $data['address_arr_id']?? null,
  1264. 'address' => $data['address']?? null,
  1265. 'email' => $data['email']?? null,
  1266. ];
  1267. //去掉相关企业信息
  1268. $data = array_diff_key($data, array_flip(array_keys($company)));
  1269. $jobId = $data['id'];
  1270. $web = $data['website_id'];
  1271. $data['action_id'] = $data['user_id'];
  1272. unset($data['user_id']);
  1273. unset($data['user_type']);
  1274. unset($data['id']);
  1275. unset($data['website_id']);
  1276. // return Result::success($data);
  1277. Db::beginTransaction();
  1278. try {
  1279. // 管理员修改招聘信息
  1280. if($user['type_id'] == 10000){
  1281. $data['website_id'] = $web;
  1282. $company['website_id'] = $data['website_id'];
  1283. $data['status'] = 1;
  1284. }else{
  1285. $data['status'] = 0;
  1286. }
  1287. if(empty($data['experience']) || $data['experience'] == ''){
  1288. $job['experience'] = null;
  1289. }else{
  1290. $job['experience'] = $data['experience'];
  1291. }
  1292. // Db::rollBack();
  1293. // return Result::success($company);
  1294. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  1295. if (empty($result['job'])) {
  1296. Db::rollBack();
  1297. return Result::error("修改招聘信息失败");
  1298. }
  1299. // 管理员修改企业相关信息
  1300. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  1301. if (empty($result['company'])) {
  1302. Db::rollBack();
  1303. return Result::error("修改企业相关信息失败");
  1304. }
  1305. Db::commit();
  1306. // return Result::success($result);
  1307. } catch (\Exception $e) {
  1308. Db::rollBack();
  1309. return Result::error($e->getMessage(), 0);
  1310. }
  1311. return Result::success($result);
  1312. }
  1313. /*
  1314. * 招聘信息删除
  1315. * */
  1316. public function delJobRecruiting(array $data): array
  1317. {
  1318. $user = User::where('id', $data['user_id'])->first();
  1319. if(empty($user)){
  1320. return Result::error("用户不存在", 0);
  1321. }
  1322. $job = JobRecruiting::where('id', $data['id'])->first();
  1323. if(empty($job)){
  1324. return Result::error("招聘信息不存在", 0);
  1325. }
  1326. if($user['type_id']==3 && $job['user_id']!= $user['id']){
  1327. return Result::error("用户暂无权限修改此招聘信息!", 0);
  1328. }
  1329. Db::beginTransaction();
  1330. try {
  1331. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  1332. if (empty($result['job'])) {
  1333. Db::rollBack();
  1334. return Result::error("删除招聘信息失败");
  1335. }
  1336. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  1337. if (empty($result['company'])) {
  1338. Db::rollBack();
  1339. return Result::error("删除企业相关信息失败");
  1340. }
  1341. Db::commit();
  1342. } catch (\Exception $e) {
  1343. Db::rollBack();
  1344. return Result::error($e->getMessage(), 0);
  1345. }
  1346. return Result::success($result);
  1347. }
  1348. /*
  1349. * 获取公司信息
  1350. * */
  1351. public function getJobCompany(array $data): array
  1352. {
  1353. $user = User::where('user.id', $data['user_id'])
  1354. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  1355. ->select('user.user_name','user.mobile','user.email','user.type_id','user_info.*')
  1356. ->first();
  1357. // return Result::success($user);
  1358. if(empty($user)){
  1359. return Result::error("用户不存在", 0);
  1360. }
  1361. if($user['type_id'] == 3){
  1362. $result = [
  1363. // 'id' => 0,
  1364. 'user_id' => $data['user_id'],
  1365. 'website_id' => $data['website_id'],
  1366. 'business_name' => $user['business_name'], // 企业名称
  1367. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  1368. 'company_nature' => $user['company_nature'], // 公司性质
  1369. 'company_size' => $user['company_size'], // 公司规模
  1370. 'introduction' => $user['introduction'], // 公司简介
  1371. 'real_name' => $user['real_name'], // 企业联系人
  1372. 'mobile' => $user['mobile'], // 企业联系电话
  1373. 'company_url' => $user['company_url'], // 企业网址
  1374. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  1375. 'address' => $user['address'], // 企业地址
  1376. 'email' => $user['email'], // 企业邮箱
  1377. ];
  1378. }else{
  1379. return Result::error("用户类型错误", 0);
  1380. }
  1381. if(empty($result)){
  1382. return Result::error("公司信息不存在", 0);
  1383. }
  1384. return Result::success($result);
  1385. }
  1386. /*
  1387. * 修改公司信息
  1388. * */
  1389. public function upJobCompany(array $data): array
  1390. {
  1391. // return Result::success($data);
  1392. $user = User::where('user.id', $data['user_id'])
  1393. ->where('user.status',1)
  1394. ->select('user.user_name','user.type_id')
  1395. ->first();
  1396. if(empty($user)){
  1397. return Result::error("用户不存在", 0);
  1398. }
  1399. $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  1400. $company = [
  1401. 'business_name' => $data['business_name'], // 企业名称
  1402. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  1403. 'company_nature' => $data['company_nature'], // 公司性质
  1404. 'company_size' => $data['company_size'], // 公司规模
  1405. 'introduction' => $data['introduction'], // 公司简介
  1406. // 'real_name' => $data['real_name'], // 企业联系人
  1407. 'company_url' => $data['company_url'], // 企业网址
  1408. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  1409. 'address' => $data['address'], // 企业详细地址
  1410. ];
  1411. if($user['type_id'] == 3){
  1412. Db::beginTransaction();
  1413. try {
  1414. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  1415. 'business_name' => $data['business_name'], // 企业名称
  1416. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  1417. 'company_nature' => $data['company_nature'], // 公司性质
  1418. 'company_size' => $data['company_size'], // 公司规模
  1419. 'introduction' => $data['introduction'], // 公司简介
  1420. // 'real_name' => $data['real_name'], // 企业联系人
  1421. 'company_url' => $data['company_url'], // 企业网址
  1422. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  1423. 'address' => $data['address'], // 企业详细地址
  1424. ]);
  1425. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  1426. Db::commit();
  1427. } catch (\Exception $e) {
  1428. Db::rollBack();
  1429. return Result::error($e->getMessage(), 0);
  1430. }
  1431. }else{
  1432. return Result::error("用户类型错误", 0);
  1433. }
  1434. if(empty($result)){
  1435. return Result::error("修改失败", 0);
  1436. }
  1437. return Result::success($result);
  1438. }
  1439. /*
  1440. * 获取省-市
  1441. * */
  1442. public function getJobRecruitingArea(array $data): array
  1443. {
  1444. if(isset($data['pid']) && $data['pid']!=null){
  1445. $result = District::where('pid',$data['pid'])->get()->all();
  1446. }else{
  1447. $result = District::where('level',1)->get()->all();
  1448. }
  1449. if (empty($result)) {
  1450. return Result::error("暂无此省市", 0);
  1451. }
  1452. return Result::success($result);
  1453. }
  1454. /*
  1455. * 获取行业分类
  1456. * */
  1457. public function getIndustry(array $data): array
  1458. {
  1459. $result = JobIndustry::get()->all();
  1460. if (empty($result)) {
  1461. return Result::error("暂无行业分类", 0);
  1462. }
  1463. return Result::success($result);
  1464. }
  1465. /*
  1466. * 获取职位
  1467. * */
  1468. public function getPositionList(array $data): array
  1469. {
  1470. if(isset($data['zwpid']) && $data['zwpid']!=null){
  1471. $result = JobPosition::where('zwpid',$data['zwpid'])->get()->all();
  1472. }else{
  1473. $result = JobPosition::where('zwpid',0)->get()->all();
  1474. }
  1475. if (empty($result)) {
  1476. return Result::error("暂无此职位", 0);
  1477. }
  1478. return Result::success($result);
  1479. }
  1480. /*
  1481. * 获取工作性质-菜单
  1482. * */
  1483. public function getJobNature(array $data): array
  1484. {
  1485. $result = JobEnum::where('egroup','nature')->get()->all();
  1486. if (empty($result)) {
  1487. return Result::error("暂无工作性质", 0);
  1488. }
  1489. return Result::success($result);
  1490. }
  1491. /*
  1492. * 获取工作经验-菜单
  1493. * */
  1494. public function getExperience(array $data): array
  1495. {
  1496. $result = JobEnum::where('egroup','years')->get()->all();
  1497. if (empty($result)) {
  1498. return Result::error("暂无工作经验", 0);
  1499. }
  1500. return Result::success($result);
  1501. }
  1502. /*
  1503. * 获取学历-菜单
  1504. * */
  1505. public function getEducation(array $data): array
  1506. {
  1507. $result = JobEnum::where('egroup','education')->get()->all();
  1508. if (empty($result)) {
  1509. return Result::error("暂无学历", 0);
  1510. }
  1511. return Result::success($result);
  1512. }
  1513. /*
  1514. * 获取薪资-菜单
  1515. * */
  1516. public function getSalary(array $data): array
  1517. {
  1518. $result = JobEnum::where('egroup','income')->get()->all();
  1519. if (empty($result)) {
  1520. return Result::error("暂无薪资", 0);
  1521. }
  1522. return Result::success($result);
  1523. }
  1524. /*
  1525. * 获取语言-菜单
  1526. * */
  1527. public function getLanguage(array $data): array
  1528. {
  1529. $result = JobEnum::where('egroup','language')->get()->all();
  1530. if (empty($result)) {
  1531. return Result::error("暂无语言", 0);
  1532. }
  1533. return Result::success($result);
  1534. }
  1535. /*
  1536. * 获取掌握程度-菜单
  1537. * */
  1538. public function getLevel(array $data): array
  1539. {
  1540. $result = JobEnum::where('egroup','languagetype')->get()->all();
  1541. if (empty($result)) {
  1542. return Result::error("暂无工作性质", 0);
  1543. }
  1544. return Result::success($result);
  1545. }
  1546. // 公司信息
  1547. /*
  1548. * 获取公司性质-菜单
  1549. * */
  1550. public function getCompanyNature(array $data): array
  1551. {
  1552. $result = JobNature::get()->all();
  1553. if (empty($result)) {
  1554. return Result::error("暂无公司性质", 0);
  1555. }
  1556. return Result::success($result);
  1557. }
  1558. /*
  1559. * 获取公司规模-菜单
  1560. * */
  1561. public function getCompanySize(array $data): array
  1562. {
  1563. $result = JobEnum::where('egroup','cosize')->get()->all();
  1564. if (empty($result)) {
  1565. return Result::error("暂无公司规模", 0);
  1566. }
  1567. return Result::success($result);
  1568. }
  1569. /*
  1570. * 招聘信息审核
  1571. * */
  1572. public function checkJobRecruiting(array $data): array
  1573. {
  1574. $user = User::where('id', $data['user_id'])->first();
  1575. if(empty($user)){
  1576. return Result::error("用户不存在", 0);
  1577. }
  1578. $job = JobRecruiting::where('id', $data['id'])->first();
  1579. if(empty($job)){
  1580. return Result::error("招聘信息不存在", 0);
  1581. }
  1582. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  1583. if($user['type_id'] != 10000){
  1584. return Result::error("用户暂无权限审核此招聘信息!", 0);
  1585. }
  1586. // 驳回原因
  1587. if($data['status'] == 2){
  1588. $data['refuse_reason'] = $data['refuse_reason']?? null;
  1589. }
  1590. $data['action_id'] = $data['user_id'];
  1591. unset($data['user_id']);
  1592. $result = JobRecruiting::where('id', $data['id'])->update($data);
  1593. if(empty($result)){
  1594. return Result::error("审核失败", 0);
  1595. }
  1596. return Result::success($result);
  1597. }
  1598. /*
  1599. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  1600. * */
  1601. public function getRecruitingList(array $data): array
  1602. {
  1603. $user = User::where('id', $data['user_id'])->first();
  1604. if(empty($user) || ($user['type_id']!= 10000 && $user['type_id']!= 1)){
  1605. return Result::error("用户不存在", 0);
  1606. }
  1607. // 1:个人会员 职场机会
  1608. if($user['type_id'] == 1){
  1609. $where['user_id'] = $user['id'];
  1610. }
  1611. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  1612. $query->where('recruit_id', $user['id']);
  1613. })
  1614. ->pluck('recruit_id');
  1615. $where = [];
  1616. if(isset($data['salary']) && $data['salary']!=null){
  1617. $where['job_recruiting.salary'] = $data['salary'];
  1618. }
  1619. if(isset($data['experience']) && $data['experience']!=null){
  1620. $where['job_recruiting.experience'] = $data['experience'];
  1621. }
  1622. if(isset($data['business_name']) && $data['business_name']!=null){
  1623. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  1624. }
  1625. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  1626. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  1627. ->where($where);
  1628. // ->count();
  1629. $count = $query->count();
  1630. $query = clone $query;
  1631. $job = $query
  1632. ->leftJoin('job_enum as income_enum', function ($join) {
  1633. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  1634. ->where('income_enum.egroup', 'income');
  1635. })
  1636. ->leftJoin('job_enum as years_enum', function ($join) {
  1637. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  1638. ->where('years_enum.egroup', 'years');
  1639. })
  1640. // ->where($where)
  1641. ->orderBy('job_recruiting.updated_at', 'desc')
  1642. ->select('job_recruiting.id','job_recruiting.title', 'job_company.business_name',
  1643. 'income_enum.evalue as salary_evalue', 'income_enum.ename as salary_ename',
  1644. 'years_enum.evalue as experience_evalue', 'years_enum.ename as experience_ename'
  1645. ,'job_recruiting.updated_at')
  1646. ->offset(($data['page'] - 1) * $data['pageSize'])
  1647. ->limit($data['pageSize'])
  1648. ->get()
  1649. ->all();
  1650. if (empty($job)) {
  1651. return Result::error("暂无招聘信息", 0);
  1652. }
  1653. $result = [
  1654. 'row' => $job,
  1655. 'count' => $count,
  1656. ];
  1657. return Result::success($result);
  1658. }
  1659. /*
  1660. * 获取企业会员-招聘信息列表
  1661. * */
  1662. public function getRecruitingInfo(array $data): array
  1663. {
  1664. $user = User::where('id', $data['user_id'])->first();
  1665. if(empty($user) || ($user['type_id']!= 10000 && $user['type_id']!= 1)){
  1666. return Result::error("用户不存在", 0);
  1667. }
  1668. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  1669. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  1670. ->select('job_recruiting.*', 'job_company.business_name','job_company.company_hy_id',
  1671. 'job_company.company_size','job_company.company_nature','job_company.introduction','job_company.real_name',
  1672. 'job_company.mobile','job_company.company_url','job_company.address_arr_id','job_company.address','job_company.email')
  1673. ->get();
  1674. if (empty($recruiting)) {
  1675. return Result::error("暂无招聘信息", 0);
  1676. }
  1677. return Result::success($recruiting);
  1678. }
  1679. /*
  1680. * 获取企业会员-我的沟通
  1681. * */
  1682. public function getJobResumeList(array $data): array
  1683. {
  1684. $user = User::where('id', $data['user_id'])->first();
  1685. if(empty($user) || ($user['type_id']!= 10000 && $user['type_id']!= 3)){
  1686. return Result::error("用户不存在", 0);
  1687. }
  1688. $where = [];
  1689. if(isset($data['salary']) && $data['salary']!=null){
  1690. $where['job_hunting.salary'] = $data['salary'];
  1691. }
  1692. if(isset($data['user_name']) && $data['user_name']!=null){
  1693. array_push($where, ['user.user_name', 'like', '%'. $data['user_name']. '%']);
  1694. }
  1695. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  1696. $query->where('job_resume.user_id', $user['id']);
  1697. })
  1698. ->when(!empty($where), function ($query) use ($where) {
  1699. $query->where($where);
  1700. })
  1701. ->leftJoin('job_hunting','job_hunting.id','job_resume.hunt_id')
  1702. ->leftJoin('job_recruiting','job_recruiting.id','job_resume.recruit_id')
  1703. ->leftJoin('user','user.id','job_resume.receiver_id')
  1704. ->select('job_resume.hunt_id','job_resume.recruit_id','job_hunting.id','job_hunting.salary','job_hunting.city_id','job_hunting.updated_at','job_recruiting.jtzw_id','user.user_name');
  1705. $count = $job->count();
  1706. if($count == 0){
  1707. return Result::error("暂无沟通记录", 0);
  1708. }
  1709. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  1710. ->offset(($data['page'] - 1) * $data['pageSize'])
  1711. ->limit($data['pageSize'])
  1712. ->get();
  1713. if (empty($jobs)) {
  1714. return Result::error("暂无沟通记录", 0);
  1715. }
  1716. $result['row'] = $this->processJob($jobs, '');
  1717. $result['count'] = $count;
  1718. return Result::success($result);
  1719. }
  1720. // 20250306 招聘
  1721. // 封装处理由问题
  1722. function processJob($job, $data)
  1723. {
  1724. return $job->map(function ($job) use ($data) {
  1725. $category = $job->cat_arr_id ?? '';
  1726. $cityid = $job->city_arr_id ?? '';
  1727. $city = json_decode($cityid, true);
  1728. $pinyin = '';
  1729. $level = json_decode($category, true);
  1730. // 路由
  1731. if (!empty($level) && is_array($level)) {
  1732. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1733. ->where('website_id', $data['website_id']) // 添加网站ID条件
  1734. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1735. ->get(['aLIas_pinyin'])
  1736. ->pluck('aLIas_pinyin')
  1737. ->implode('/');
  1738. if (empty($pinyin)) {
  1739. $pinyin = $pinyin->aLIas_pinyin ?? '';
  1740. }
  1741. $job->pinyin = $pinyin;
  1742. }
  1743. // 取职位城市-市??省
  1744. if (!empty($city) && is_array($city)) {
  1745. if (isset($city[1]) && !empty($city[1])) {
  1746. $city = District::where('id', $city[1])->first(['name']);
  1747. $job->city_name = $city->name ?? '';
  1748. } else if (isset($city[0]) && !empty($city[0])) {
  1749. $city = District::where('id', $city[0])->first(['name']);
  1750. $job->city_name = $city->name ?? '';
  1751. } else {
  1752. $job->city_name = '全国';
  1753. }
  1754. }
  1755. // 取公司详细地址拼接
  1756. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  1757. $address_id = json_decode($job->address_arr_id, true) ?? [];
  1758. if (is_array($address_id) && !empty($address_id)) {
  1759. $address = District::whereIn('id', $address_id)
  1760. ->orderBy('level', 'asc')
  1761. ->get(['name'])
  1762. ->pluck('name')
  1763. ->implode('');
  1764. // $job->address_name = $address ?? '';
  1765. $job->address_name = ($address ?? '') . ($job->address ?? '');
  1766. }
  1767. }
  1768. // 获取简历地址最后一级
  1769. if(isset($job->city_id) &&!empty($job->city_id)){
  1770. $city_name = District::where('id', $job->city_id)->first(['name']);
  1771. $job->hunt_cityname = $city_name->name?? '';
  1772. }
  1773. // 取行业
  1774. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id)) {
  1775. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  1776. if (!empty($job->industry)) {
  1777. $query->where('hyid', $job->industry);
  1778. } else if (!empty($job->hy_id)) {
  1779. $query->where('hyid', $job->hy_id);
  1780. } else {
  1781. $query->where('hyid', $job->company_hy_id);
  1782. }
  1783. })->first(['hyname']);
  1784. $job->hy_name = $hy_name->hyname ?? '';
  1785. }
  1786. // 取职位
  1787. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job))) {
  1788. $zwid = $job->job ?? $job->zw_id;
  1789. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  1790. $job->zw_name = $zw_name->zwname ?? '';
  1791. }
  1792. // 取具体职位
  1793. if ((isset($job->jtzw_id) && !empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get))) {
  1794. $jtzwid = $job->job_name_get ?? $job->jtzw_id;
  1795. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  1796. $job->jtzw_name = $jtzw_name->zwname ?? '';
  1797. }
  1798. // 取工作经验
  1799. if (isset($job->experience) && !empty($job->experience)) {
  1800. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  1801. $job->experience_name = $experience->ename ?? '';
  1802. }
  1803. // 取学历
  1804. if (isset($job->educational) && !empty($job->educational)) {
  1805. $education = JobEnum::where('egroup', 'education')->where('evalue', $job->educational)->first(['ename']);
  1806. $job->education_name = $education->ename ?? '';
  1807. }
  1808. // 语言
  1809. if (isset($job->language) && !empty($job->language)) {
  1810. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  1811. $job->language_name = $language->ename ?? '';
  1812. }
  1813. // 薪资
  1814. if (isset($job->salary) && !empty($job->salary)) {
  1815. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  1816. $job->salary_name = $salary->ename ?? '';
  1817. }
  1818. // 职位性质
  1819. if (isset($job->nature_id) && !empty($job->nature_id)) {
  1820. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  1821. $job->job_nature_name = $job_nature->ename ?? '';
  1822. }
  1823. // 公司规模
  1824. if (isset($job->company_size) && !empty($job->company_size)) {
  1825. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  1826. $job->company_size_name = $company_size->ename ?? '';
  1827. }
  1828. // 公司性质
  1829. if (isset($job->company_nature) && !empty($job->company_nature)) {
  1830. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  1831. $job->company_nature_name = $company_nature->nature_name ?? '';
  1832. }
  1833. // $job->pinyin = $pinyin;
  1834. return $job;
  1835. });
  1836. }
  1837. }