NewsService.php 56 KB

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