NewsService.php 60 KB

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