NewsService.php 59 KB

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