NewsService.php 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  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.updated_at", "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::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  684. ->select('website_category.*', 'website.website_name', 'website.suffix')
  685. ->where('website_category.website_id', $data['website_id'])
  686. ->where(['website_category.category_id' => $result['catid']])
  687. ->first();
  688. if (empty($category)) {
  689. return Result::error("查询失败", 0);
  690. }
  691. $result['category_id'] = $category['category_id'];
  692. $result['cat_name'] = $category['alias'];
  693. $result['website_name'] = $category['website_name']??"";
  694. $result['suffix'] = $category['suffix']??"";
  695. return Result::success($result);
  696. }
  697. /**
  698. * 前端-获取网站调查问卷
  699. * @param array $data
  700. * @return array
  701. */
  702. public function getWebsiteSurvey(array $data): array
  703. {
  704. if (isset($data['website_id']) && !empty($data['website_id'])) {
  705. $website = Website::where('id', $data['website_id'])->first();
  706. if (empty($website)) {
  707. return Result::error("暂无此网站", 0);
  708. }
  709. }
  710. if (isset($data['art_id']) && !empty($data['art_id'])) {
  711. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  712. if (empty($article)) {
  713. return Result::error("暂无此文章", 0);
  714. }
  715. // return Result::error($data,0);
  716. $where['art_id'] = $data['art_id'];
  717. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  718. } else {
  719. $survey = ArticleSurvey::where('website_id', $data['website_id'])->orderBy('created_at')->first();
  720. if (empty($survey)) {
  721. return Result::error("暂无调查问卷", 0);
  722. }
  723. $where['sur_id'] = $survey['sur_id'];
  724. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  725. }
  726. $result['survey'] = ArticleSurvey::where($where)->where('is_other', 0)
  727. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  728. ->select('article_survey.*', 'article.survey_type')
  729. ->get()->all();
  730. $result['other'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  731. $result['others'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->first();
  732. if (empty($result)) {
  733. return Result::error("此文章暂无调查问卷", 0);
  734. }
  735. return Result::success($result);
  736. }
  737. /**
  738. * 前端-添加网站调查问卷选项
  739. * @param array $data
  740. * @return array
  741. */
  742. public function addWebsiteSurveyOption(array $data): array
  743. {
  744. if (isset($data['website_id']) && !empty($data['website_id'])) {
  745. $website = Website::where('id', $data['website_id'])->first();
  746. if (empty($website)) {
  747. return Result::error("暂无此网站", 0);
  748. }
  749. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  750. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  751. if (empty($survey)) {
  752. return Result::error("此调查问卷不可添加选项", 0);
  753. }
  754. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  755. $choice = [
  756. 'art_id' => $survey['art_id'],
  757. 'website_id' => $data['website_id'],
  758. 'survey_name' => $survey['survey_name'],
  759. 'choice_name' => $data['choice_name'],
  760. 'sur_id' => $survey['sur_id'],
  761. 'is_other' => 1,
  762. 'other_id' => $survey['id'],
  763. ];
  764. $result = ArticleSurvey::insertGetId($choice);
  765. if (empty($result)) {
  766. return Result::error("添加失败", 0);
  767. }
  768. return Result::success($result);
  769. }
  770. }
  771. return Result::error("添加失败", 0);
  772. }
  773. return Result::error("添加失败", 0);
  774. }
  775. /**
  776. * 前端-调查问卷投票
  777. * @param array $data
  778. * @return array
  779. */
  780. public function addWebsiteSurveyVote(array $data): array
  781. {
  782. if (isset($data['website_id']) && !empty($data['website_id'])) {
  783. $website = Website::where('id', $data['website_id'])->first();
  784. if (empty($website)) {
  785. return Result::error("暂无此网站", 0);
  786. }
  787. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  788. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->pluck('sur_id');
  789. if (empty($survey)) {
  790. return Result::error("此调查问卷不存在", 0);
  791. }
  792. // return Result::success($survey);
  793. // 调查问卷类型 0:单选 1:多选
  794. $type = Article::where('survey_id', $data['sur_id'])->pluck('survey_type');
  795. // return Result::success($type);
  796. if (empty($type) || ($type[0] != 1 && $type[0] != 0)) {
  797. return Result::error("此调查问卷不可投票", 0);
  798. }
  799. // return Result::success($type[0]);
  800. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  801. if ($type[0] == 0) {
  802. if (is_array($data['choice_id'])) {
  803. return Result::error("请选择一个选项!", 0);
  804. }
  805. $data['choice_id'] = [$data['choice_id']];
  806. } else {
  807. if (!is_array($data['choice_id'])) {
  808. return Result::error("请传递数组!", 0);
  809. }
  810. }
  811. // return Result::success($data['choice_id']);
  812. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  813. ->where('website_id', $data['website_id'])
  814. ->where('is_other', 1)
  815. ->where('other_id', 0)
  816. ->first();
  817. if (!empty($other)) {
  818. return Result::error("请选择已有的选项!", 0);
  819. }
  820. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  821. ->where('website_id', $data['website_id'])
  822. ->where('is_other', 1)
  823. ->where('other_id', '!=', 0)
  824. ->first();
  825. // return Result::success($data);
  826. if (!empty($choice['other'])) {
  827. array_push($data['choice_id'], $choice['other']['other_id']);
  828. // return Result::success($data['choice_id']);
  829. }
  830. // return Result::success($data);
  831. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  832. ->where('website_id', $data['website_id'])
  833. ->increment('results', 1);
  834. if (empty($choice)) {
  835. return Result::error("请选择已有的选项!", 0);
  836. }
  837. return Result::success($choice);
  838. }
  839. return Result::error("参数必填!");
  840. // if(isset($data['choice_id']) && !empty($data['choice_id'])){
  841. // $choice = ArticleSurvey::whereIn('id',$data['choice_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
  842. // }
  843. }
  844. return Result::error("此调查问卷不存在", 0);
  845. }
  846. return Result::error("参数必填!");
  847. }
  848. /**
  849. * 后端-获取网站调查问卷列表
  850. * @param array $data
  851. * @return array
  852. */
  853. public function getSurveyList(array $data): array
  854. {
  855. $where = [];
  856. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  857. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  858. }
  859. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  860. array_push($where, ['survey_type', '=', $data['survey_type']]);
  861. }
  862. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  863. array_push($where, ['is_survey', '=', $data['is_survey']]);
  864. }
  865. // return Result::success($where);
  866. if (!empty($where)) {
  867. $query = Article::where($where)->where(function ($q) {
  868. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  869. });
  870. } else {
  871. $query = Article::where(function ($q) {
  872. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  873. });
  874. }
  875. $count = $query->count();
  876. $survey = $query->orderByDesc('id')
  877. ->limit($data['pageSize'])
  878. ->offset(($data['page'] - 1) * $data['pageSize'])
  879. ->get();
  880. if (empty($survey->toArray())) {
  881. return Result::error("暂无调查问卷!", 0);
  882. }
  883. $result = [
  884. 'rows' => $survey,
  885. 'count' => $count,
  886. ];
  887. return Result::success($result);
  888. }
  889. /**
  890. * 后端-获取网站调查问卷详情
  891. * @param array $data
  892. * @return array
  893. */
  894. public function getSurveyInfo(array $data): array
  895. {
  896. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  897. $where = ['sur_id' => $data['sur_id']];
  898. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  899. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  900. ->select('article_survey.*', 'article.survey_type')
  901. ->get()->all();
  902. if (empty($choose)) {
  903. return Result::error("此调查问卷不存在", 0);
  904. }
  905. $resultsArray = array_column($choose, 'results');
  906. $total = array_sum($resultsArray);
  907. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  908. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  909. // $total = 0;
  910. if (!empty($other)) {
  911. $total = $total + $other['results'];
  912. $other['choice_name'] = $other['choice_name'] . '(其他)';
  913. if (!empty($others)) {
  914. $other['hasChildren'] = true;
  915. // array_push($other,['hasChildren','=',true]);
  916. $other['children'] = $others;
  917. $other_choices = [$other->toArray()];
  918. $mer_choice = array_merge($choose, $other_choices);
  919. $value_choice = array_values($mer_choice);
  920. } else {
  921. // return Result::error('1111');
  922. $other_choices = [$other->toArray()];
  923. $other_choices = array_merge($choose, $other_choices);
  924. $value_choice = array_values($other_choices);
  925. // return Result::success($result);
  926. }
  927. } else {
  928. $value_choice = $choose;
  929. }
  930. $result = [
  931. 'choose' => $value_choice,
  932. 'total' => $total,
  933. ];
  934. }
  935. return Result::success($result);
  936. }
  937. /**
  938. * 前端-搜索新闻列表
  939. * @param array $data
  940. * @return array
  941. */
  942. public function selectWebsiteArticle(array $data): array
  943. {
  944. $where = [];
  945. // 初始化查询构造器
  946. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  947. $query = Article::where('status', 1)
  948. ->whereIn('catid', $category)
  949. ->where(function ($query) use ($data) {
  950. $query->where(function ($subQuery) use ($data) {
  951. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  952. })->orWhereNull("ignore_ids");
  953. });
  954. // return Result::success($all_articles);
  955. // 检查是否存在 cityid 参数
  956. if (isset($data['cityid']) && !empty($data['cityid'])) {
  957. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  958. }
  959. // 检查是否存在 department_id 参数
  960. if (isset($data['department_id']) && !empty($data['department_id'])) {
  961. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  962. }
  963. // 检查是否存在 keyword 参数
  964. if (isset($data['keyword']) && !empty($data['keyword'])) {
  965. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  966. }
  967. // 计算总数
  968. $count = $query->count();
  969. // 分页查询
  970. $articles = $query->orderBy("updated_at", "desc")
  971. ->limit($data['pageSize'])
  972. ->offset(($data['page'] - 1) * $data['pageSize'])
  973. ->get()->all();
  974. if (empty($articles)) {
  975. return Result::error("没有符合条件的资讯数据");
  976. }
  977. $data = [
  978. 'rows' => $articles,
  979. 'count' => $count,
  980. ];
  981. return Result::success($data);
  982. }
  983. /**
  984. * 验证导航名称是否重复
  985. * @return void
  986. */
  987. public function checkCategoryName(array $data): array
  988. {
  989. $result = Category::when($data, function ($query) use ($data) {
  990. if (isset($data['name']) && $data['name']) {
  991. $query->where("name", $data['name']);
  992. }
  993. if (isset($data['id']) && $data['id']) {
  994. $query->where("id", "!=", $data['id']);
  995. }
  996. })->first();
  997. if ($result) {
  998. return Result::error("已存在");
  999. } else {
  1000. return Result::success();
  1001. }
  1002. }
  1003. //20250226 产品列表
  1004. public function getGoodList(array $data): array
  1005. {
  1006. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1007. unset($data['type_id']);
  1008. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1009. $where = [];
  1010. if ($type_id != '10000') {
  1011. $where = [
  1012. 'good.user_id' => $user_id,
  1013. ];
  1014. }
  1015. //类型
  1016. if (isset($data['type_id']) && $data['type_id']) {
  1017. $where = [
  1018. 'type_id' => $data['type_id'],
  1019. ];
  1020. }
  1021. //名称
  1022. if (isset($data['name']) && $data['name']) {
  1023. $where = [
  1024. 'good.name' => $data['name'],
  1025. ];
  1026. }
  1027. $where1 = [];
  1028. //website_id
  1029. // if (isset($data['website_id']) && $data['website_id']) {
  1030. // $where1 = [
  1031. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1032. // ];
  1033. // }
  1034. // website_name
  1035. if (isset($data['website_name']) && $data['website_name']) {
  1036. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1037. }
  1038. // catid
  1039. if (isset($data['category_name']) && $data['category_name']) {
  1040. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1041. }
  1042. // $result = Good::where($where)
  1043. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1044. $result = Good::where($where)
  1045. ->when(!empty($where1), function ($query) use ($where1) {
  1046. return $query->where($where1);
  1047. })
  1048. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1049. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1050. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1051. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1052. ->orderBy("id", "desc")
  1053. ->limit($data['page_size'])
  1054. ->offset(($data['page'] - 1) * $data['page_size'])
  1055. ->get();
  1056. $count = Good::where($where)
  1057. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1058. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1059. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1060. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1061. ->orderBy("updated_at", "desc")->count();
  1062. $data = [
  1063. 'rows' => $result->toArray(),
  1064. 'count' => $count,
  1065. ];
  1066. if (empty($result)) {
  1067. return Result::error("此栏目暂无相关产品", 0);
  1068. }
  1069. return Result::success($data);
  1070. }
  1071. public function getGoodInfo(array $data): array
  1072. {
  1073. $result = Good::where('id', $data['id'])->first();
  1074. if (empty($result)) {
  1075. return Result::error("此产品不存在", 0);
  1076. }
  1077. return Result::success($result);
  1078. }
  1079. public function addGood(array $data): array
  1080. {
  1081. // unset($data['city_arr_id']);
  1082. // unset($data['cat_arr_id']);
  1083. $data['city_id'] = end($data['city_arr_id']);
  1084. $data['catid'] = end($data['cat_arr_id']);
  1085. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1086. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1087. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1088. unset($data['imgUrl']);
  1089. $result = Good::insert($data);
  1090. if (empty($result)) {
  1091. return Result::error("添加失败", 0);
  1092. }
  1093. return Result::success($result);
  1094. }
  1095. public function updateGood(array $data): array
  1096. {
  1097. $data['city_id'] = end($data['city_arr_id']);
  1098. $data['catid'] = end($data['cat_arr_id']);
  1099. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1100. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1101. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1102. //设置东八区
  1103. date_default_timezone_set('Asia/Shanghai');
  1104. $data['updated_at'] = date('Y-m-d H:i:s');
  1105. $result = Good::where('id', $data['id'])->update($data);
  1106. if (empty($result)) {
  1107. return Result::error("更新失败", 0);
  1108. }
  1109. return Result::success($result);
  1110. }
  1111. public function delGood(array $data): array
  1112. {
  1113. $result = Good::where('id', $data['id'])->delete();
  1114. if (empty($result)) {
  1115. return Result::error("删除失败", 0);
  1116. }
  1117. return Result::success($result);
  1118. }
  1119. //20250226 产品列表
  1120. //20250306 求职信息
  1121. public function getJobHuntingList(array $data): array
  1122. {
  1123. $where = [];
  1124. if (isset($data['username']) && !empty($data['username'])) {
  1125. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1126. }
  1127. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1128. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1129. unset($data['type_id']);
  1130. if ($type_id != '10000') {
  1131. $where[] = ['job_hunting.user_id', '=', $user_id];
  1132. }
  1133. $result = JobHunting::where($where)
  1134. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1135. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1136. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1137. ->orderBy("id", "desc")
  1138. ->limit($data['page_size'])
  1139. ->offset(($data['page'] - 1) * $data['page_size'])
  1140. ->get();
  1141. if (empty($result)) {
  1142. return Result::error("查询失败", 0);
  1143. }
  1144. $count = JobHunting::where($where)
  1145. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1146. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1147. ->count();
  1148. $data = [
  1149. 'rows' => $result->toArray(),
  1150. 'count' => $count,
  1151. ];
  1152. return Result::success($data);
  1153. }
  1154. // 20250306 招聘
  1155. /*
  1156. * 招聘列表
  1157. * */
  1158. public function getJobRecruitingList(array $data): array
  1159. {
  1160. $where = [];
  1161. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1162. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  1163. }
  1164. $user = User::where('id', $data['user_id'])->first();
  1165. if (empty($user)) {
  1166. return Result::error("用户不存在", 0);
  1167. }
  1168. // 3:企业会员
  1169. if ($user['type_id'] == 3) {
  1170. array_push($where, ['user_id', $data['user_id']]);
  1171. }
  1172. $result = JobRecruiting::where($where)
  1173. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  1174. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  1175. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  1176. ->orderBy("updated_at", "desc")
  1177. ->offset(($data['page'] - 1) * $data['page_size'])
  1178. ->limit($data['page_size'])
  1179. ->get()
  1180. ->all();
  1181. if (empty($result)) {
  1182. return Result::error("暂无招聘信息", 0);
  1183. }
  1184. return Result::success($result);
  1185. }
  1186. /*
  1187. * 招聘信息详情
  1188. * */
  1189. public function getJobRecruitingInfo(array $data): array
  1190. {
  1191. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  1192. ->leftJoin('user_info', 'job_recruiting.user_id', 'user_info.id')
  1193. ->leftJoin('user', 'job_recruiting.user_id', 'user.id')
  1194. ->select(
  1195. 'job_recruiting.*',
  1196. 'user_info.business_name', // 企业名称
  1197. 'user_info.hy_id', // 企业所属行业
  1198. 'user_info.company_size', // 公司规模
  1199. 'user_info.company_nature', // 公司性质
  1200. 'user_info.introduction', // 公司简介
  1201. 'user_info.real_name', // 企业联系人
  1202. 'user.mobile', // 企业联系电话
  1203. 'user_info.company_url', // 企业网址
  1204. 'user_info.address_arr_id', // 企业地址
  1205. 'user_info.address', // 企业地址
  1206. 'user.email', // 企业邮箱
  1207. )
  1208. ->orderBy("updated_at", "desc")
  1209. ->first();
  1210. if (empty($result)) {
  1211. return Result::error("暂无招聘信息", 0);
  1212. }
  1213. return Result::success($result);
  1214. }
  1215. /*
  1216. * 招聘信息添加
  1217. * */
  1218. public function addJobRecruiting(array $data): array
  1219. {
  1220. $user = User::where('id', $data['user_id'])->first();
  1221. if (empty($user)) {
  1222. return Result::error("用户不存在", 0);
  1223. }
  1224. // 3:企业会员
  1225. if ($user['type_id'] != 3) {
  1226. if ($data['website_id'] == 0) {
  1227. return Result::error("请选择所属网站", 0);
  1228. }
  1229. $website = Website::where('id', $data['website_id'])->first();
  1230. if (empty($website)) {
  1231. return Result::error("网站不存在", 0);
  1232. }
  1233. $data['website_id'] = $website['id'];
  1234. }
  1235. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  1236. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  1237. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1238. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1239. $result = JobRecruiting::insertGetId($data);
  1240. if (empty($result)) {
  1241. return Result::error("添加失败", 0);
  1242. }
  1243. return Result::success($result);
  1244. }
  1245. /*
  1246. * 招聘信息更新
  1247. * */
  1248. public function upJobRecruiting(array $data): array
  1249. {
  1250. $job = JobRecruiting::where('id', $data['id'])->first();
  1251. if (empty($job)) {
  1252. return Result::error("招聘信息不存在", 0);
  1253. }
  1254. $user = User::where('id', $data['user_id'])->first();
  1255. if (empty($user)) {
  1256. return Result::error("用户不存在", 0);
  1257. }
  1258. // 3:企业会员
  1259. if ($user['type_id'] != 3) {
  1260. if ($data['website_id'] == 0) {
  1261. return Result::error("请选择所属网站", 0);
  1262. }
  1263. $website = Website::where('id', $data['website_id'])->first();
  1264. if (empty($website)) {
  1265. return Result::error("网站不存在", 0);
  1266. }
  1267. $data['website_id'] = $website['id'];
  1268. }
  1269. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  1270. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  1271. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1272. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1273. $result = JobRecruiting::where('id', $data['id'])->update($data);
  1274. if (empty($result)) {
  1275. return Result::error("更新失败", 0);
  1276. }
  1277. return Result::success($data);
  1278. }
  1279. /*
  1280. * 招聘信息删除
  1281. * */
  1282. public function delJobRecruiting(array $data): array
  1283. {
  1284. $job = JobRecruiting::where('id', $data['id'])->first();
  1285. if (empty($job)) {
  1286. return Result::error("招聘信息不存在", 0);
  1287. }
  1288. $result = JobRecruiting::where('id', $data['id'])->delete();
  1289. if (empty($result)) {
  1290. return Result::error("删除失败", 0);
  1291. }
  1292. return Result::success($data);
  1293. }
  1294. /*
  1295. * 获取省-市
  1296. * */
  1297. public function getJobRecruitingArea(array $data): array
  1298. {
  1299. if (isset($data['province_id']) && $data['province_id'] != null) {
  1300. $result = District::where('pid', $data['pid'])->get()->all();
  1301. } else {
  1302. $result = District::where('level', 1)->get()->all();
  1303. }
  1304. if (empty($result)) {
  1305. return Result::error("暂无此省市", 0);
  1306. }
  1307. return Result::success($result);
  1308. }
  1309. /*
  1310. * 获取行业分类
  1311. * */
  1312. public function getIndustry(array $data): array
  1313. {
  1314. $result = JobIndustry::get()->all();
  1315. if (empty($result)) {
  1316. return Result::error("暂无行业分类", 0);
  1317. }
  1318. return Result::success($result);
  1319. }
  1320. /*
  1321. * 获取职位
  1322. * */
  1323. public function getPositionList(array $data): array
  1324. {
  1325. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  1326. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  1327. } else {
  1328. $result = JobPosition::where('zwpid', 0)->get()->all();
  1329. }
  1330. if (empty($result)) {
  1331. return Result::error("暂无此职位", 0);
  1332. }
  1333. return Result::success($result);
  1334. }
  1335. /*
  1336. * 获取工作性质-菜单
  1337. * */
  1338. public function getJobNature(array $data): array
  1339. {
  1340. $result = JobEnum::where('egroup', 'nature')->get()->all();
  1341. if (empty($result)) {
  1342. return Result::error("暂无工作性质", 0);
  1343. }
  1344. return Result::success($result);
  1345. }
  1346. /*
  1347. * 获取工作经验-菜单
  1348. * */
  1349. public function getExperience(array $data): array
  1350. {
  1351. $result = JobEnum::where('egroup', 'years')->get()->all();
  1352. if (empty($result)) {
  1353. return Result::error("暂无工作经验", 0);
  1354. }
  1355. return Result::success($result);
  1356. }
  1357. /*
  1358. * 获取学历-菜单
  1359. * */
  1360. public function getEducation(array $data): array
  1361. {
  1362. $result = JobEnum::where('egroup', 'education')->get()->all();
  1363. if (empty($result)) {
  1364. return Result::error("暂无学历", 0);
  1365. }
  1366. return Result::success($result);
  1367. }
  1368. /*
  1369. * 获取薪资-菜单
  1370. * */
  1371. public function getSalary(array $data): array
  1372. {
  1373. $result = JobEnum::where('egroup', 'income')->get()->all();
  1374. if (empty($result)) {
  1375. return Result::error("暂无薪资", 0);
  1376. }
  1377. return Result::success($result);
  1378. }
  1379. /*
  1380. * 获取语言-菜单
  1381. * */
  1382. public function getLanguage(array $data): array
  1383. {
  1384. $result = JobEnum::where('egroup', 'language')->get()->all();
  1385. if (empty($result)) {
  1386. return Result::error("暂无语言", 0);
  1387. }
  1388. return Result::success($result);
  1389. }
  1390. /*
  1391. * 获取掌握程度-菜单
  1392. * */
  1393. public function getLevel(array $data): array
  1394. {
  1395. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  1396. if (empty($result)) {
  1397. return Result::error("暂无工作性质", 0);
  1398. }
  1399. return Result::success($result);
  1400. }
  1401. // 公司信息
  1402. /*
  1403. * 获取公司性质-菜单
  1404. * */
  1405. public function getCompanyNature(array $data): array
  1406. {
  1407. $result = JobNature::get()->all();
  1408. if (empty($result)) {
  1409. return Result::error("暂无公司性质", 0);
  1410. }
  1411. return Result::success($result);
  1412. }
  1413. /*
  1414. * 获取公司规模-菜单
  1415. * */
  1416. public function getCompanySize(array $data): array
  1417. {
  1418. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  1419. if (empty($result)) {
  1420. return Result::error("暂无公司规模", 0);
  1421. }
  1422. return Result::success($result);
  1423. }
  1424. // 20250306 招聘
  1425. public function addJobHunting(array $data): array
  1426. {
  1427. date_default_timezone_set('Asia/Shanghai');
  1428. unset($data['company_name']);
  1429. unset($data['job_industry']);
  1430. unset($data['job_name']);
  1431. unset($data['department']);
  1432. unset($data['job_timeList']);
  1433. unset($data['job_content']);
  1434. $data['created_at'] = date('Y-m-d H:i:s');
  1435. $data['updated_at'] = date('Y-m-d H:i:s');
  1436. var_dump($data, '-----------------test---------');
  1437. $result = JobHunting::create($data);
  1438. if (empty($result)) {
  1439. return Result::error("添加失败", 0);
  1440. }
  1441. return Result::success($result);
  1442. }
  1443. public function delJobHunting(array $data): array
  1444. {
  1445. $result = JobHunting::where('id', $data['id'])->delete();
  1446. if (empty($result)) {
  1447. return Result::error("删除失败", 0);
  1448. }
  1449. return Result::success($result);
  1450. }
  1451. public function updateJobHunting(array $data): array
  1452. {
  1453. //设置东八区
  1454. date_default_timezone_set('Asia/Shanghai');
  1455. unset($data['company_name']);
  1456. unset($data['job_industry']);
  1457. unset($data['job_name']);
  1458. unset($data['department']);
  1459. unset($data['job_timeList']);
  1460. unset($data['job_content']);
  1461. $data['created_at'] = date('Y-m-d H:i:s');
  1462. $data['updated_at'] = date('Y-m-d H:i:s');
  1463. $result = JobHunting::where('id', $data['id'])->update($data);
  1464. if (empty($result)) {
  1465. return Result::error("更新失败", 0);
  1466. }
  1467. return Result::success($result);
  1468. }
  1469. public function getJobHuntingInfo(array $data): array
  1470. {
  1471. $result = JobHunting::where('id', $data['id'])->first();
  1472. if (empty($result)) {
  1473. return Result::error("查询失败", 0);
  1474. }
  1475. return Result::success($result);
  1476. }
  1477. public function getJobHuntingData(array $data): array
  1478. {
  1479. $jobEnum = JobEnum::get();
  1480. $jobIndustry = JobIndustry::get();
  1481. $jobNature = JobNature::get();
  1482. $jobPosition = JobPosition::get();
  1483. $data = [
  1484. 'jobEnum' => $jobEnum,
  1485. 'jobIndustry' => $jobIndustry,
  1486. 'jobNature' => $jobNature,
  1487. 'jobPosition' => $jobPosition,
  1488. ];
  1489. return Result::success($data);
  1490. }
  1491. public function delJobHuntingInfo(array $data): array
  1492. {
  1493. $result = JobHunting::where('id', $data['id'])->delete();
  1494. return Result::success();
  1495. }
  1496. }