NewsService.php 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884
  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->orderBy('job_hunting.updated_at', 'desc')
  1700. ->offset(($data['page'] - 1) * $data['pageSize'])
  1701. ->limit($data['pageSize'])
  1702. ->get();
  1703. if (empty($jobs)) {
  1704. return Result::error("暂无沟通记录", 0);
  1705. }
  1706. $result['row'] = $this->processJob($jobs, '');
  1707. $result['count'] = $count;
  1708. return Result::success($result);
  1709. }
  1710. // 20250306 招聘
  1711. // 封装处理由问题
  1712. function processJob($job, $data)
  1713. {
  1714. return $job->map(function ($job) use ($data) {
  1715. $category = $job->cat_arr_id ?? '';
  1716. $cityid = $job->city_arr_id ?? '';
  1717. $city = json_decode($cityid, true);
  1718. $pinyin = '';
  1719. $level = json_decode($category, true);
  1720. // 路由
  1721. if (!empty($level) && is_array($level)) {
  1722. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1723. ->where('website_id', $data['website_id']) // 添加网站ID条件
  1724. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1725. ->get(['aLIas_pinyin'])
  1726. ->pluck('aLIas_pinyin')
  1727. ->implode('/');
  1728. if (empty($pinyin)) {
  1729. $pinyin = $pinyin->aLIas_pinyin ?? '';
  1730. }
  1731. $job->pinyin = $pinyin;
  1732. }
  1733. // 取职位城市-市??省
  1734. if (!empty($city) && is_array($city)) {
  1735. if (isset($city[1]) && !empty($city[1])) {
  1736. $city = District::where('id', $city[1])->first(['name']);
  1737. $job->city_name = $city->name ?? '';
  1738. } else if (isset($city[0]) && !empty($city[0])) {
  1739. $city = District::where('id', $city[0])->first(['name']);
  1740. $job->city_name = $city->name ?? '';
  1741. } else {
  1742. $job->city_name = '全国';
  1743. }
  1744. }
  1745. // 取公司详细地址拼接
  1746. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  1747. $address_id = json_decode($job->address_arr_id, true) ?? [];
  1748. if (is_array($address_id) && !empty($address_id)) {
  1749. $address = District::whereIn('id', $address_id)
  1750. ->orderBy('level', 'asc')
  1751. ->get(['name'])
  1752. ->pluck('name')
  1753. ->implode('');
  1754. // $job->address_name = $address ?? '';
  1755. $job->address_name = ($address ?? '') . ($job->address ?? '');
  1756. }
  1757. }
  1758. // 获取简历地址最后一级
  1759. if(isset($job->city_id) &&!empty($job->city_id)){
  1760. $city_name = District::where('id', $job->city_id)->first(['name']);
  1761. $job->hunt_cityname = $city_name->name?? '';
  1762. }
  1763. // 取行业
  1764. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id)) {
  1765. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  1766. if (!empty($job->industry)) {
  1767. $query->where('hyid', $job->industry);
  1768. } else if (!empty($job->hy_id)) {
  1769. $query->where('hyid', $job->hy_id);
  1770. } else {
  1771. $query->where('hyid', $job->company_hy_id);
  1772. }
  1773. })->first(['hyname']);
  1774. $job->hy_name = $hy_name->hyname ?? '';
  1775. }
  1776. // 取职位
  1777. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job))) {
  1778. $zwid = $job->job ?? $job->zw_id;
  1779. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  1780. $job->zw_name = $zw_name->zwname ?? '';
  1781. }
  1782. // 取具体职位
  1783. if ((isset($job->jtzw_id) && !empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get))) {
  1784. $jtzwid = $job->job_name_get ?? $job->jtzw_id;
  1785. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  1786. $job->jtzw_name = $jtzw_name->zwname ?? '';
  1787. }
  1788. // 取工作经验
  1789. if (isset($job->experience) && !empty($job->experience)) {
  1790. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  1791. $job->experience_name = $experience->ename ?? '';
  1792. }
  1793. // 取学历
  1794. if (isset($job->educational) && !empty($job->educational)) {
  1795. $education = JobEnum::where('egroup', 'education')->where('evalue', $job->educational)->first(['ename']);
  1796. $job->education_name = $education->ename ?? '';
  1797. }
  1798. // 语言
  1799. if (isset($job->language) && !empty($job->language)) {
  1800. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  1801. $job->language_name = $language->ename ?? '';
  1802. }
  1803. // 薪资
  1804. if (isset($job->salary) && !empty($job->salary)) {
  1805. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  1806. $job->salary_name = $salary->ename ?? '';
  1807. }
  1808. // 职位性质
  1809. if (isset($job->nature_id) && !empty($job->nature_id)) {
  1810. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  1811. $job->job_nature_name = $job_nature->ename ?? '';
  1812. }
  1813. // 公司规模
  1814. if (isset($job->company_size) && !empty($job->company_size)) {
  1815. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  1816. $job->company_size_name = $company_size->ename ?? '';
  1817. }
  1818. // 公司性质
  1819. if (isset($job->company_nature) && !empty($job->company_nature)) {
  1820. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  1821. $job->company_nature_name = $company_nature->nature_name ?? '';
  1822. }
  1823. // $job->pinyin = $pinyin;
  1824. return $job;
  1825. });
  1826. }
  1827. }