NewsService.php 52 KB

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