NewsService.php 56 KB

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