NewsService.php 68 KB

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