NewsService.php 58 KB

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