NewsService.php 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885
  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. $job['experience'] = $data['experience']?? null;
  1118. }
  1119. $jobId = JobRecruiting::insertGetId($job);
  1120. if (empty($jobId)) {
  1121. Db::rollBack();
  1122. return Result::error("添加失败");
  1123. }
  1124. // 添加公司信息
  1125. $company['user_id'] = $data['user_id']?? null;
  1126. $company['job_id'] = $jobId;
  1127. $company['user_type'] = $user['type_id']?? null;
  1128. $company['website_id'] = $data['website_id']?? null;
  1129. if($user['type_id'] == 10000){
  1130. // 管理员添加企业信息
  1131. // return Result::success($company);
  1132. $companyId = JobCompany::insertGetId($company);
  1133. if (empty($companyId)) {
  1134. Db::rollBack();
  1135. return Result::error("添加失败");
  1136. }
  1137. }else{
  1138. // 企业会员添加企业信息
  1139. $company = [
  1140. 'user_id' => $data['user_id']?? null,
  1141. 'business_name' => $user['business_name']?? null,
  1142. 'company_hy_id' => $user['company_hy_id']?? null,
  1143. 'company_size' => $user['company_size']?? null,
  1144. 'company_nature' => $user['company_nature']?? null,
  1145. 'introduction' => $user['introduction']?? null,
  1146. 'real_name' => $user['real_name']?? null,
  1147. 'mobile' => $user['mobile']?? null,
  1148. 'company_url' => $user['company_url']?? null,
  1149. 'address_arr_id' => $user['address_arr_id']?? null,
  1150. 'address' => $user['address']?? null,
  1151. 'email' => $user['email']?? null,
  1152. 'website_id' => $data['website_id']?? null,
  1153. 'user_type' => $user['type_id']?? null,
  1154. 'job_id' => $jobId,
  1155. ];
  1156. $companyId = JobCompany::insertGetId($company);
  1157. if (empty($companyId)) {
  1158. Db::rollBack();
  1159. return Result::error("添加失败");
  1160. }
  1161. // return Result::success($company);
  1162. }
  1163. Db::commit();
  1164. } catch (\Exception $e) {
  1165. Db::rollBack();
  1166. return Result::error($e->getMessage(), 0);
  1167. }
  1168. $result = [
  1169. 'job_id' => $jobId,
  1170. 'company_id' => $companyId,
  1171. ];
  1172. if (empty($result)) {
  1173. return Result::error("添加失败", 0);
  1174. }
  1175. return Result::success($result);
  1176. }
  1177. /*
  1178. * 获取招聘信息详情
  1179. * */
  1180. public function getJobRecruitingInfo(array $data): array
  1181. {
  1182. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  1183. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  1184. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  1185. ->select('job_recruiting.*', 'website.website_name as website_name',
  1186. 'job_company.business_name',
  1187. 'job_company.company_hy_id',
  1188. 'job_company.company_size',
  1189. 'job_company.company_nature',
  1190. 'job_company.introduction',
  1191. 'job_company.real_name',
  1192. 'job_company.mobile',
  1193. 'job_company.company_url',
  1194. 'job_company.address_arr_id',
  1195. 'job_company.address',
  1196. 'job_company.email'
  1197. )
  1198. ->first();
  1199. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  1200. if(!empty($cityId)){
  1201. if(isset($cityId[1]) && $cityId[1] != null){
  1202. $city = District::where('id', $cityId[1])->first(['name']);
  1203. }else{
  1204. $city = District::where('id', $cityId[0])->first(['name']);
  1205. }
  1206. $result['city'] = $city['name'] ?? '';
  1207. }
  1208. $addressId = json_decode($result['address_arr_id'], true)?? [];
  1209. if(is_array($addressId) && !empty($addressId)){
  1210. $address = District::whereIn('id', $addressId)
  1211. ->orderBy('level', 'asc')
  1212. ->get(['name'])
  1213. ->pluck('name')
  1214. ->implode('');
  1215. // $job->address_name = $address ?? '';
  1216. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  1217. }
  1218. if(empty($result)){
  1219. return Result::error("招聘信息不存在", 0);
  1220. }
  1221. // return Result::success($job);
  1222. return Result::success($result);
  1223. }
  1224. /*
  1225. * 修改招聘信息
  1226. * */
  1227. public function upJobRecruiting(array $data): array
  1228. {
  1229. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  1230. // return Result::success($job);
  1231. if(empty($job)){
  1232. return Result::error("招聘信息不存在", 0);
  1233. }
  1234. $user = User::where('id', $data['user_id'])->first();
  1235. // return Result::success($user);
  1236. if(empty($user) || $user['type_id']!= $data['user_type']){
  1237. return Result::error("用户不存在", 0);
  1238. }
  1239. if($user['type_id']==3 && $job['user_id']!= $user['id']){
  1240. return Result::error("用户暂无权限修改此招聘信息!", 0);
  1241. }
  1242. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  1243. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  1244. $data['cat_arr_id'] = isset($data['cat_arr_id'])? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  1245. $data['city_arr_id'] = isset($data['city_arr_id'])? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  1246. // 公司地址 管理员必填
  1247. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  1248. $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  1249. // 管理员-企业相关信息
  1250. $company = [
  1251. 'business_name' => $data['business_name']?? null,
  1252. 'company_hy_id' => $data['hy_id']?? null,
  1253. 'company_size' => $data['company_size']?? null,
  1254. 'company_nature' => $data['company_nature']?? null,
  1255. 'introduction' => $data['introduction']?? null,
  1256. 'real_name' => $data['real_name']?? null,
  1257. 'mobile' => $data['mobile']?? null,
  1258. 'company_url' => $data['company_url']?? null,
  1259. 'address_arr_id' => $data['address_arr_id']?? null,
  1260. 'address' => $data['address']?? null,
  1261. 'email' => $data['email']?? null,
  1262. ];
  1263. //去掉相关企业信息
  1264. $data = array_diff_key($data, array_flip(array_keys($company)));
  1265. $jobId = $data['id'];
  1266. $web = $data['website_id'];
  1267. $data['action_id'] = $data['user_id'];
  1268. unset($data['user_id']);
  1269. unset($data['user_type']);
  1270. unset($data['id']);
  1271. unset($data['website_id']);
  1272. // return Result::success($data);
  1273. Db::beginTransaction();
  1274. try {
  1275. // 管理员修改招聘信息
  1276. if($user['type_id'] == 10000){
  1277. $data['website_id'] = $web;
  1278. $company['website_id'] = $data['website_id'];
  1279. $data['status'] = 1;
  1280. }else{
  1281. $data['status'] = 0;
  1282. }
  1283. // Db::rollBack();
  1284. // return Result::success($company);
  1285. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  1286. if (empty($result['job'])) {
  1287. Db::rollBack();
  1288. return Result::error("修改招聘信息失败");
  1289. }
  1290. // 管理员修改企业相关信息
  1291. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  1292. if (empty($result['company'])) {
  1293. Db::rollBack();
  1294. return Result::error("修改企业相关信息失败");
  1295. }
  1296. Db::commit();
  1297. // return Result::success($result);
  1298. } catch (\Exception $e) {
  1299. Db::rollBack();
  1300. return Result::error($e->getMessage(), 0);
  1301. }
  1302. return Result::success($result);
  1303. }
  1304. /*
  1305. * 招聘信息删除
  1306. * */
  1307. public function delJobRecruiting(array $data): array
  1308. {
  1309. $user = User::where('id', $data['user_id'])->first();
  1310. if(empty($user)){
  1311. return Result::error("用户不存在", 0);
  1312. }
  1313. $job = JobRecruiting::where('id', $data['id'])->first();
  1314. if(empty($job)){
  1315. return Result::error("招聘信息不存在", 0);
  1316. }
  1317. if($user['type_id']==3 && $job['user_id']!= $user['id']){
  1318. return Result::error("用户暂无权限修改此招聘信息!", 0);
  1319. }
  1320. Db::beginTransaction();
  1321. try {
  1322. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  1323. if (empty($result['job'])) {
  1324. Db::rollBack();
  1325. return Result::error("删除招聘信息失败");
  1326. }
  1327. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  1328. if (empty($result['company'])) {
  1329. Db::rollBack();
  1330. return Result::error("删除企业相关信息失败");
  1331. }
  1332. Db::commit();
  1333. } catch (\Exception $e) {
  1334. Db::rollBack();
  1335. return Result::error($e->getMessage(), 0);
  1336. }
  1337. return Result::success($result);
  1338. }
  1339. /*
  1340. * 获取公司信息
  1341. * */
  1342. public function getJobCompany(array $data): array
  1343. {
  1344. $user = User::where('user.id', $data['user_id'])
  1345. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  1346. ->select('user.user_name','user.mobile','user.email','user.type_id','user_info.*')
  1347. ->first();
  1348. // return Result::success($user);
  1349. if(empty($user)){
  1350. return Result::error("用户不存在", 0);
  1351. }
  1352. if($user['type_id'] == 3){
  1353. $result = [
  1354. // 'id' => 0,
  1355. 'user_id' => $data['user_id'],
  1356. 'website_id' => $data['website_id'],
  1357. 'business_name' => $user['business_name'], // 企业名称
  1358. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  1359. 'company_nature' => $user['company_nature'], // 公司性质
  1360. 'company_size' => $user['company_size'], // 公司规模
  1361. 'introduction' => $user['introduction'], // 公司简介
  1362. 'real_name' => $user['real_name'], // 企业联系人
  1363. 'mobile' => $user['mobile'], // 企业联系电话
  1364. 'company_url' => $user['company_url'], // 企业网址
  1365. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  1366. 'address' => $user['address'], // 企业地址
  1367. 'email' => $user['email'], // 企业邮箱
  1368. ];
  1369. }else{
  1370. return Result::error("用户类型错误", 0);
  1371. }
  1372. if(empty($result)){
  1373. return Result::error("公司信息不存在", 0);
  1374. }
  1375. return Result::success($result);
  1376. }
  1377. /*
  1378. * 修改公司信息
  1379. * */
  1380. public function upJobCompany(array $data): array
  1381. {
  1382. // return Result::success($data);
  1383. $user = User::where('user.id', $data['user_id'])
  1384. ->where('user.status',1)
  1385. ->select('user.user_name','user.type_id')
  1386. ->first();
  1387. if(empty($user)){
  1388. return Result::error("用户不存在", 0);
  1389. }
  1390. $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  1391. $company = [
  1392. 'business_name' => $data['business_name'], // 企业名称
  1393. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  1394. 'company_nature' => $data['company_nature'], // 公司性质
  1395. 'company_size' => $data['company_size'], // 公司规模
  1396. 'introduction' => $data['introduction'], // 公司简介
  1397. // 'real_name' => $data['real_name'], // 企业联系人
  1398. 'company_url' => $data['company_url'], // 企业网址
  1399. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  1400. 'address' => $data['address'], // 企业详细地址
  1401. ];
  1402. if($user['type_id'] == 3){
  1403. Db::beginTransaction();
  1404. try {
  1405. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  1406. 'business_name' => $data['business_name'], // 企业名称
  1407. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  1408. 'company_nature' => $data['company_nature'], // 公司性质
  1409. 'company_size' => $data['company_size'], // 公司规模
  1410. 'introduction' => $data['introduction'], // 公司简介
  1411. // 'real_name' => $data['real_name'], // 企业联系人
  1412. 'company_url' => $data['company_url'], // 企业网址
  1413. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  1414. 'address' => $data['address'], // 企业详细地址
  1415. ]);
  1416. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  1417. Db::commit();
  1418. } catch (\Exception $e) {
  1419. Db::rollBack();
  1420. return Result::error($e->getMessage(), 0);
  1421. }
  1422. }else{
  1423. return Result::error("用户类型错误", 0);
  1424. }
  1425. if(empty($result)){
  1426. return Result::error("修改失败", 0);
  1427. }
  1428. return Result::success($result);
  1429. }
  1430. /*
  1431. * 获取省-市
  1432. * */
  1433. public function getJobRecruitingArea(array $data): array
  1434. {
  1435. if(isset($data['pid']) && $data['pid']!=null){
  1436. $result = District::where('pid',$data['pid'])->get()->all();
  1437. }else{
  1438. $result = District::where('level',1)->get()->all();
  1439. }
  1440. if (empty($result)) {
  1441. return Result::error("暂无此省市", 0);
  1442. }
  1443. return Result::success($result);
  1444. }
  1445. /*
  1446. * 获取行业分类
  1447. * */
  1448. public function getIndustry(array $data): array
  1449. {
  1450. $result = JobIndustry::get()->all();
  1451. if (empty($result)) {
  1452. return Result::error("暂无行业分类", 0);
  1453. }
  1454. return Result::success($result);
  1455. }
  1456. /*
  1457. * 获取职位
  1458. * */
  1459. public function getPositionList(array $data): array
  1460. {
  1461. if(isset($data['zwpid']) && $data['zwpid']!=null){
  1462. $result = JobPosition::where('zwpid',$data['zwpid'])->get()->all();
  1463. }else{
  1464. $result = JobPosition::where('zwpid',0)->get()->all();
  1465. }
  1466. if (empty($result)) {
  1467. return Result::error("暂无此职位", 0);
  1468. }
  1469. return Result::success($result);
  1470. }
  1471. /*
  1472. * 获取工作性质-菜单
  1473. * */
  1474. public function getJobNature(array $data): array
  1475. {
  1476. $result = JobEnum::where('egroup','nature')->get()->all();
  1477. if (empty($result)) {
  1478. return Result::error("暂无工作性质", 0);
  1479. }
  1480. return Result::success($result);
  1481. }
  1482. /*
  1483. * 获取工作经验-菜单
  1484. * */
  1485. public function getExperience(array $data): array
  1486. {
  1487. $result = JobEnum::where('egroup','years')->get()->all();
  1488. if (empty($result)) {
  1489. return Result::error("暂无工作经验", 0);
  1490. }
  1491. return Result::success($result);
  1492. }
  1493. /*
  1494. * 获取学历-菜单
  1495. * */
  1496. public function getEducation(array $data): array
  1497. {
  1498. $result = JobEnum::where('egroup','education')->get()->all();
  1499. if (empty($result)) {
  1500. return Result::error("暂无学历", 0);
  1501. }
  1502. return Result::success($result);
  1503. }
  1504. /*
  1505. * 获取薪资-菜单
  1506. * */
  1507. public function getSalary(array $data): array
  1508. {
  1509. $result = JobEnum::where('egroup','income')->get()->all();
  1510. if (empty($result)) {
  1511. return Result::error("暂无薪资", 0);
  1512. }
  1513. return Result::success($result);
  1514. }
  1515. /*
  1516. * 获取语言-菜单
  1517. * */
  1518. public function getLanguage(array $data): array
  1519. {
  1520. $result = JobEnum::where('egroup','language')->get()->all();
  1521. if (empty($result)) {
  1522. return Result::error("暂无语言", 0);
  1523. }
  1524. return Result::success($result);
  1525. }
  1526. /*
  1527. * 获取掌握程度-菜单
  1528. * */
  1529. public function getLevel(array $data): array
  1530. {
  1531. $result = JobEnum::where('egroup','languagetype')->get()->all();
  1532. if (empty($result)) {
  1533. return Result::error("暂无工作性质", 0);
  1534. }
  1535. return Result::success($result);
  1536. }
  1537. // 公司信息
  1538. /*
  1539. * 获取公司性质-菜单
  1540. * */
  1541. public function getCompanyNature(array $data): array
  1542. {
  1543. $result = JobNature::get()->all();
  1544. if (empty($result)) {
  1545. return Result::error("暂无公司性质", 0);
  1546. }
  1547. return Result::success($result);
  1548. }
  1549. /*
  1550. * 获取公司规模-菜单
  1551. * */
  1552. public function getCompanySize(array $data): array
  1553. {
  1554. $result = JobEnum::where('egroup','cosize')->get()->all();
  1555. if (empty($result)) {
  1556. return Result::error("暂无公司规模", 0);
  1557. }
  1558. return Result::success($result);
  1559. }
  1560. /*
  1561. * 招聘信息审核
  1562. * */
  1563. public function checkJobRecruiting(array $data): array
  1564. {
  1565. $user = User::where('id', $data['user_id'])->first();
  1566. if(empty($user)){
  1567. return Result::error("用户不存在", 0);
  1568. }
  1569. $job = JobRecruiting::where('id', $data['id'])->first();
  1570. if(empty($job)){
  1571. return Result::error("招聘信息不存在", 0);
  1572. }
  1573. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  1574. if($user['type_id'] != 10000){
  1575. return Result::error("用户暂无权限审核此招聘信息!", 0);
  1576. }
  1577. // 驳回原因
  1578. if($data['status'] == 2){
  1579. $data['refuse_reason'] = $data['refuse_reason']?? null;
  1580. }
  1581. $data['action_id'] = $data['user_id'];
  1582. unset($data['user_id']);
  1583. $result = JobRecruiting::where('id', $data['id'])->update($data);
  1584. if(empty($result)){
  1585. return Result::error("审核失败", 0);
  1586. }
  1587. return Result::success($result);
  1588. }
  1589. /*
  1590. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  1591. * */
  1592. public function getRecruitingList(array $data): array
  1593. {
  1594. $user = User::where('id', $data['user_id'])->first();
  1595. if(empty($user) || ($user['type_id']!= 10000 && $user['type_id']!= 1)){
  1596. return Result::error("用户不存在", 0);
  1597. }
  1598. // 1:个人会员 职场机会
  1599. if($user['type_id'] == 1){
  1600. $where['user_id'] = $user['id'];
  1601. }
  1602. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  1603. $query->where('recruit_id', $user['id']);
  1604. })
  1605. ->pluck('recruit_id');
  1606. $where = [];
  1607. if(isset($data['salary']) && $data['salary']!=null){
  1608. $where['job_recruiting.salary'] = $data['salary'];
  1609. }
  1610. if(isset($data['experience']) && $data['experience']!=null){
  1611. $where['job_recruiting.experience'] = $data['experience'];
  1612. }
  1613. if(isset($data['business_name']) && $data['business_name']!=null){
  1614. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  1615. }
  1616. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  1617. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  1618. ->where($where);
  1619. // ->count();
  1620. $count = $query->count();
  1621. $query = clone $query;
  1622. $job = $query
  1623. ->leftJoin('job_enum as income_enum', function ($join) {
  1624. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  1625. ->where('income_enum.egroup', 'income');
  1626. })
  1627. ->leftJoin('job_enum as years_enum', function ($join) {
  1628. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  1629. ->where('years_enum.egroup', 'years');
  1630. })
  1631. // ->where($where)
  1632. ->orderBy('job_recruiting.updated_at', 'desc')
  1633. ->select('job_recruiting.id','job_recruiting.title', 'job_company.business_name',
  1634. 'income_enum.evalue as salary_evalue', 'income_enum.ename as salary_ename',
  1635. 'years_enum.evalue as experience_evalue', 'years_enum.ename as experience_ename'
  1636. ,'job_recruiting.updated_at')
  1637. ->offset(($data['page'] - 1) * $data['pageSize'])
  1638. ->limit($data['pageSize'])
  1639. ->get()
  1640. ->all();
  1641. if (empty($job)) {
  1642. return Result::error("暂无招聘信息", 0);
  1643. }
  1644. $result = [
  1645. 'row' => $job,
  1646. 'count' => $count,
  1647. ];
  1648. return Result::success($result);
  1649. }
  1650. /*
  1651. * 获取企业会员-招聘信息列表
  1652. * */
  1653. public function getRecruitingInfo(array $data): array
  1654. {
  1655. $user = User::where('id', $data['user_id'])->first();
  1656. if(empty($user) || ($user['type_id']!= 10000 && $user['type_id']!= 1)){
  1657. return Result::error("用户不存在", 0);
  1658. }
  1659. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  1660. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  1661. ->select('job_recruiting.*', 'job_company.business_name','job_company.company_hy_id',
  1662. 'job_company.company_size','job_company.company_nature','job_company.introduction','job_company.real_name',
  1663. 'job_company.mobile','job_company.company_url','job_company.address_arr_id','job_company.address','job_company.email')
  1664. ->get();
  1665. if (empty($recruiting)) {
  1666. return Result::error("暂无招聘信息", 0);
  1667. }
  1668. return Result::success($recruiting);
  1669. }
  1670. /*
  1671. * 获取企业会员-我的沟通
  1672. * */
  1673. public function getJobResumeList(array $data): array
  1674. {
  1675. $user = User::where('id', $data['user_id'])->first();
  1676. if(empty($user) || ($user['type_id']!= 10000 && $user['type_id']!= 3)){
  1677. return Result::error("用户不存在", 0);
  1678. }
  1679. $where = [];
  1680. if(isset($data['salary']) && $data['salary']!=null){
  1681. $where['job_hunting.salary'] = $data['salary'];
  1682. }
  1683. if(isset($data['user_name']) && $data['user_name']!=null){
  1684. array_push($where, ['user.user_name', 'like', '%'. $data['user_name']. '%']);
  1685. }
  1686. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  1687. $query->where('job_resume.user_id', $user['id']);
  1688. })
  1689. ->when(!empty($where), function ($query) use ($where) {
  1690. $query->where($where);
  1691. })
  1692. ->leftJoin('job_hunting','job_hunting.id','job_resume.hunt_id')
  1693. ->leftJoin('job_recruiting','job_recruiting.id','job_resume.recruit_id')
  1694. ->leftJoin('user','user.id','job_resume.receiver_id')
  1695. ->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');
  1696. $count = $job->count();
  1697. if($count == 0){
  1698. return Result::error("暂无沟通记录", 0);
  1699. }
  1700. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  1701. ->offset(($data['page'] - 1) * $data['pageSize'])
  1702. ->limit($data['pageSize'])
  1703. ->get();
  1704. if (empty($jobs)) {
  1705. return Result::error("暂无沟通记录", 0);
  1706. }
  1707. $result['row'] = $this->processJob($jobs, '');
  1708. $result['count'] = $count;
  1709. return Result::success($result);
  1710. }
  1711. // 20250306 招聘
  1712. // 封装处理由问题
  1713. function processJob($job, $data)
  1714. {
  1715. return $job->map(function ($job) use ($data) {
  1716. $category = $job->cat_arr_id ?? '';
  1717. $cityid = $job->city_arr_id ?? '';
  1718. $city = json_decode($cityid, true);
  1719. $pinyin = '';
  1720. $level = json_decode($category, true);
  1721. // 路由
  1722. if (!empty($level) && is_array($level)) {
  1723. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1724. ->where('website_id', $data['website_id']) // 添加网站ID条件
  1725. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1726. ->get(['aLIas_pinyin'])
  1727. ->pluck('aLIas_pinyin')
  1728. ->implode('/');
  1729. if (empty($pinyin)) {
  1730. $pinyin = $pinyin->aLIas_pinyin ?? '';
  1731. }
  1732. $job->pinyin = $pinyin;
  1733. }
  1734. // 取职位城市-市??省
  1735. if (!empty($city) && is_array($city)) {
  1736. if (isset($city[1]) && !empty($city[1])) {
  1737. $city = District::where('id', $city[1])->first(['name']);
  1738. $job->city_name = $city->name ?? '';
  1739. } else if (isset($city[0]) && !empty($city[0])) {
  1740. $city = District::where('id', $city[0])->first(['name']);
  1741. $job->city_name = $city->name ?? '';
  1742. } else {
  1743. $job->city_name = '全国';
  1744. }
  1745. }
  1746. // 取公司详细地址拼接
  1747. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  1748. $address_id = json_decode($job->address_arr_id, true) ?? [];
  1749. if (is_array($address_id) && !empty($address_id)) {
  1750. $address = District::whereIn('id', $address_id)
  1751. ->orderBy('level', 'asc')
  1752. ->get(['name'])
  1753. ->pluck('name')
  1754. ->implode('');
  1755. // $job->address_name = $address ?? '';
  1756. $job->address_name = ($address ?? '') . ($job->address ?? '');
  1757. }
  1758. }
  1759. // 获取简历地址最后一级
  1760. if(isset($job->city_id) &&!empty($job->city_id)){
  1761. $city_name = District::where('id', $job->city_id)->first(['name']);
  1762. $job->hunt_cityname = $city_name->name?? '';
  1763. }
  1764. // 取行业
  1765. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id)) {
  1766. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  1767. if (!empty($job->industry)) {
  1768. $query->where('hyid', $job->industry);
  1769. } else if (!empty($job->hy_id)) {
  1770. $query->where('hyid', $job->hy_id);
  1771. } else {
  1772. $query->where('hyid', $job->company_hy_id);
  1773. }
  1774. })->first(['hyname']);
  1775. $job->hy_name = $hy_name->hyname ?? '';
  1776. }
  1777. // 取职位
  1778. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job))) {
  1779. $zwid = $job->job ?? $job->zw_id;
  1780. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  1781. $job->zw_name = $zw_name->zwname ?? '';
  1782. }
  1783. // 取具体职位
  1784. if ((isset($job->jtzw_id) && !empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get))) {
  1785. $jtzwid = $job->job_name_get ?? $job->jtzw_id;
  1786. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  1787. $job->jtzw_name = $jtzw_name->zwname ?? '';
  1788. }
  1789. // 取工作经验
  1790. if (isset($job->experience) && !empty($job->experience)) {
  1791. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  1792. $job->experience_name = $experience->ename ?? '';
  1793. }
  1794. // 取学历
  1795. if (isset($job->educational) && !empty($job->educational)) {
  1796. $education = JobEnum::where('egroup', 'education')->where('evalue', $job->educational)->first(['ename']);
  1797. $job->education_name = $education->ename ?? '';
  1798. }
  1799. // 语言
  1800. if (isset($job->language) && !empty($job->language)) {
  1801. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  1802. $job->language_name = $language->ename ?? '';
  1803. }
  1804. // 薪资
  1805. if (isset($job->salary) && !empty($job->salary)) {
  1806. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  1807. $job->salary_name = $salary->ename ?? '';
  1808. }
  1809. // 职位性质
  1810. if (isset($job->nature_id) && !empty($job->nature_id)) {
  1811. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  1812. $job->job_nature_name = $job_nature->ename ?? '';
  1813. }
  1814. // 公司规模
  1815. if (isset($job->company_size) && !empty($job->company_size)) {
  1816. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  1817. $job->company_size_name = $company_size->ename ?? '';
  1818. }
  1819. // 公司性质
  1820. if (isset($job->company_nature) && !empty($job->company_nature)) {
  1821. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  1822. $job->company_nature_name = $company_nature->nature_name ?? '';
  1823. }
  1824. // $job->pinyin = $pinyin;
  1825. return $job;
  1826. });
  1827. }
  1828. }