NewsService.php 87 KB

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