NewsService.php 58 KB

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