NewsService.php 76 KB

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