NewsService.php 63 KB

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