NewsService.php 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  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']) : $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. $suvey_data = [];
  450. if (is_array($suveys_array)) {
  451. foreach ($suveys_array as $key => $value) {
  452. if ($value == '') {
  453. continue;
  454. }
  455. if (is_array($value)) {
  456. $suvey_data[] = [
  457. 'sur_id' => $uuid,
  458. 'art_id' => $id,
  459. 'website_id' => $website_id ?? 2,
  460. 'survey_name' => $survey_name,
  461. 'choice_name' => $value[1],
  462. 'is_other' => 1,
  463. 'other_id' => 0,
  464. 'results' => 0,
  465. ];
  466. } else {
  467. $suvey_data[] = [
  468. 'sur_id' => $uuid,
  469. 'art_id' => $id,
  470. 'website_id' => $website_id ?? 2,
  471. 'survey_name' => $survey_name,
  472. 'choice_name' => $value,
  473. 'is_other' => 0,
  474. 'other_id' => 0,
  475. 'results' => 0,
  476. ];
  477. }
  478. if (empty($suvey_data)) {
  479. throw new \Exception("投票数据为空");
  480. }
  481. }
  482. }
  483. $result = ArticleSurvey::insert($suvey_data);
  484. if (!$result) {
  485. throw new \Exception("投票失败");
  486. }
  487. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  488. if (!$result) {
  489. throw new \Exception("投票失败");
  490. }
  491. } else {
  492. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  493. }
  494. Db::commit();
  495. return Result::success([]);
  496. } catch (\Throwable $ex) {
  497. Db::rollBack();
  498. var_dump($ex->getMessage());
  499. return Result::error("更新失败1" . $ex->getMessage(), 0);
  500. }
  501. }
  502. /**
  503. * 更新资讯状态
  504. * @param array $data
  505. * @return array
  506. */
  507. public function upArticleStatus(array $data): array
  508. {
  509. $result = Article::where(['id' => $data['id']])->update($data);
  510. if ($result) {
  511. return Result::success();
  512. } else {
  513. return Result::error("更新状态失败", 0);
  514. }
  515. }
  516. /**
  517. * @param array $data
  518. * @return array
  519. */
  520. public function getArticleInfo(array $data): array
  521. {
  522. $where = [
  523. 'article.id' => $data['id'],
  524. // 'article.status' => 1,
  525. ];
  526. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  527. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  528. $info = $result;
  529. // var_dump($info, 'info');
  530. $info['survey_array'] = $articleSurvey;
  531. if ($result) {
  532. return Result::success($info);
  533. } else {
  534. return Result::error("查询失败", 0);
  535. }
  536. }
  537. /**
  538. * 获取新闻
  539. * @param array $data
  540. * @return array
  541. */
  542. public function getWebsiteArticlett(array $data): array
  543. {
  544. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  545. $result = [];
  546. if ($category) {
  547. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  548. $where = [
  549. 'status' => 1,
  550. ];
  551. var_dump($data, 'data-----------------');
  552. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  553. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  554. var_dump($where, 'where-----------------');
  555. $result = Article::where($where)
  556. ->whereIn("catid", $category)
  557. ->where(function ($query) use ($data) {
  558. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  559. ->orWhereNull("ignore_ids");
  560. })
  561. //$data['level'] == 4 || $data['level'] == 5 查询随机
  562. ->when($data['level'] == 5, function ($query) {
  563. $query->inRandomOrder()
  564. //updated_at最近三十天;
  565. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  566. })
  567. ->when($data['level'] == 4, function ($query) {
  568. $query->orderBy("updated_at", "desc");
  569. })
  570. ->when(!empty($data['level']), function ($query) use ($data) {
  571. if ($data['level'] != 4 && $data['level'] != 5) {
  572. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  573. ->orderBy("updated_at", "desc");
  574. }
  575. })
  576. ->offset($placeid)
  577. ->limit($data['pageSize'])
  578. ->get();
  579. if (empty($result)) {
  580. return Result::error("暂无头条新闻", 0);
  581. }
  582. return Result::success($result);
  583. } else {
  584. return Result::error("本网站下暂无相关栏目", 0);
  585. }
  586. }
  587. /**
  588. * 获取模块新闻
  589. * @param array $data
  590. * @return array
  591. */
  592. public function getWebsiteModelArticles(array $data): array
  593. {
  594. $catid = $data['catid'];
  595. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  596. $category = $category->toArray();
  597. if (!empty($category)) {
  598. $where = [
  599. 'status' => 1,
  600. 'catid' => $catid,
  601. ];
  602. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  603. // 1:文字新闻;2:轮播图;3:图文;
  604. // 级别:0:未分类
  605. // 3:推荐图片
  606. if ($data['level'] == 1) {
  607. $data['level'] = 0;
  608. }
  609. $result = Article::where($where)
  610. ->where(function ($query) use ($data) {
  611. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  612. ->orWhereNull("level")
  613. ->orWhereRaw("level = '[]'");
  614. })
  615. ->where(function ($query) use ($data) {
  616. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  617. ->orWhereNull("ignore_ids");
  618. })
  619. ->orderBy("updated_at", "desc")
  620. ->offset($placeid)
  621. ->limit($data['pagesize'])
  622. ->get();
  623. if (empty($result)) {
  624. return Result::error("此栏目暂无相关新闻", 0);
  625. }
  626. } else {
  627. return Result::error("此网站暂无此栏目", 0);
  628. }
  629. return Result::success($result);
  630. }
  631. /**
  632. *获取新闻列表
  633. * @param array $data
  634. * @return array
  635. */
  636. public function getWebsiteArticleList(array $data): array
  637. {
  638. $where[] = ['status', '=', 1];
  639. if (isset($data['keyword']) && !empty($data['keyword'])) {
  640. array_push($where, ['article.title', 'like', '%' . $data['keyword'] . '%']);
  641. }
  642. if (isset($data['catid']) && !empty($data['catid'])) {
  643. if (is_array($data['catid'])) {
  644. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  645. array_push($where, ['catid', 'in', $data['catid']]);
  646. } else {
  647. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  648. array_push($where, ['catid', '=', $data['catid']]);
  649. }
  650. if (empty($category)) {
  651. return Result::error("此网站暂无此栏目", 0);
  652. }
  653. }
  654. // return Result::success($where);
  655. $rep = Article::where(function ($query) use ($where) {
  656. foreach ($where as $condition) {
  657. if ($condition[1] === 'in') {
  658. $query->whereIn($condition[0], $condition[2]);
  659. } else {
  660. $query->where($condition[0], $condition[1], $condition[2]);
  661. }
  662. }
  663. })
  664. ->where(function ($query) use ($data) {
  665. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  666. ->orWhereNull("ignore_ids");
  667. })
  668. ->orderBy("updated_at", "desc")
  669. ->limit($data['pageSize'])
  670. ->offset(($data['page'] - 1) * $data['pageSize'])
  671. ->get();
  672. $count = Article::where(function ($query) use ($where) {
  673. foreach ($where as $condition) {
  674. if ($condition[1] === 'in') {
  675. $query->whereIn($condition[0], $condition[2]);
  676. } else {
  677. $query->where($condition[0], $condition[1], $condition[2]);
  678. }
  679. }
  680. })->count();
  681. $data = [
  682. 'rows' => $rep->toArray(),
  683. 'count' => $count,
  684. ];
  685. if (empty($rep)) {
  686. return Result::error("没有信息数据");
  687. }
  688. return Result::success($data);
  689. }
  690. /**
  691. * 前端-获取新闻详情
  692. * @param array $data
  693. * @return array
  694. */
  695. public function selectWebsiteArticleInfo(array $data): array
  696. {
  697. $where = [
  698. 'article.id' => $data['id'],
  699. 'article.status' => 1,
  700. ];
  701. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
  702. ->where(function ($query) use ($data) {
  703. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  704. ->orWhereNull("ignore_ids");
  705. })
  706. ->first();
  707. if (empty($result)) {
  708. return Result::error("暂无此新闻!", 0);
  709. }
  710. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  711. ->select('website_category.*', 'website.website_name', 'website.suffix')
  712. ->where('website_category.website_id', $data['website_id'])
  713. ->where(['website_category.category_id' => $result['catid']])
  714. ->first();
  715. if (empty($category)) {
  716. return Result::error("查询失败", 0);
  717. }
  718. $result['category_id'] = $category['category_id'];
  719. $result['cat_name'] = $category['alias'];
  720. $result['website_name'] = $category['website_name'] ?? "";
  721. $result['suffix'] = $category['suffix'] ?? "";
  722. return Result::success($result);
  723. }
  724. /**
  725. * 前端-获取网站调查问卷
  726. * @param array $data
  727. * @return array
  728. */
  729. public function getWebsiteSurvey(array $data): array
  730. {
  731. if (isset($data['website_id']) && !empty($data['website_id'])) {
  732. $website = Website::where('id', $data['website_id'])->first();
  733. if (empty($website)) {
  734. return Result::error("暂无此网站", 0);
  735. }
  736. }
  737. if (isset($data['art_id']) && !empty($data['art_id'])) {
  738. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  739. if (empty($article)) {
  740. return Result::error("暂无此文章", 0);
  741. }
  742. // return Result::error($data,0);
  743. $where['art_id'] = $data['art_id'];
  744. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  745. } else {
  746. $survey = Article::where(function ($query) {
  747. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  748. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  749. })
  750. ->where('status', 1)
  751. ->where('is_survey', 1)
  752. ->select('survey_id')
  753. ->orderBy('updated_at', 'desc')
  754. ->first();
  755. if (empty($survey)) {
  756. return Result::error("暂无调查问卷", 0);
  757. }
  758. $where['sur_id'] = $survey['survey_id'];
  759. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  760. }
  761. // return Result::success($where);
  762. $result = ArticleSurvey::where($where)
  763. ->where(function ($query) {
  764. $query->where('is_other', 0)
  765. ->orWhere(function ($subQuery) {
  766. $subQuery->where('is_other', 1)
  767. ->where('other_id', 0);
  768. });
  769. })
  770. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  771. ->select('article_survey.*', 'article.survey_type')
  772. ->get()->all();
  773. if (empty($result)) {
  774. return Result::error("此文章暂无调查问卷", 0);
  775. }
  776. return Result::success($result);
  777. }
  778. /**
  779. * 前端-添加网站调查问卷选项
  780. * @param array $data
  781. * @return array
  782. */
  783. public function addWebsiteSurveyOption(array $data): array
  784. {
  785. if (isset($data['website_id']) && !empty($data['website_id'])) {
  786. $website = Website::where('id', $data['website_id'])->first();
  787. if (empty($website)) {
  788. return Result::error("暂无此网站", 0);
  789. }
  790. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  791. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  792. if (empty($survey)) {
  793. return Result::error("此调查问卷不可添加选项", 0);
  794. }
  795. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  796. $choice = [
  797. 'art_id' => $survey['art_id'],
  798. 'website_id' => $data['website_id'],
  799. 'survey_name' => $survey['survey_name'],
  800. 'choice_name' => $data['choice_name'],
  801. 'sur_id' => $survey['sur_id'],
  802. 'is_other' => 1,
  803. 'other_id' => $survey['id'],
  804. ];
  805. $result = ArticleSurvey::insertGetId($choice);
  806. if (empty($result)) {
  807. return Result::error("添加失败", 0);
  808. }
  809. return Result::success($result);
  810. }
  811. }
  812. return Result::error("添加失败", 0);
  813. }
  814. return Result::error("添加失败", 0);
  815. }
  816. /**
  817. * 前端-调查问卷投票
  818. * @param array $data
  819. * @return array
  820. */
  821. public function addWebsiteSurveyVote(array $data): array
  822. {
  823. // return Result::success($data);
  824. if (isset($data['website_id']) && !empty($data['website_id'])) {
  825. $website = Website::where('id', $data['website_id'])->first();
  826. if (empty($website)) {
  827. return Result::error("暂无此网站", 0);
  828. }
  829. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  830. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  831. // return Result::success($survey);
  832. if (empty($is_survey)) {
  833. return Result::error("此调查问卷不存在", 0);
  834. }
  835. // return Result::success($survey);
  836. // 调查问卷类型
  837. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  838. //多选 若是json型则转化成数组类型
  839. if (strpos($data['choice_id'], '[') === 0) {
  840. $data['choice_id'] = json_decode($data['choice_id'], true);
  841. } else {
  842. // 单选 也转换成数组
  843. $data['choice_id'] = [$data['choice_id']];
  844. }
  845. $data['choice_id'] = array_map('intval', $data['choice_id']);
  846. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  847. ->where('website_id', $data['website_id'])
  848. ->where('is_other', 1)
  849. ->where('other_id', 0)
  850. ->first();
  851. if (!empty($other)) {
  852. return Result::error("请选择已有的选项!", 0);
  853. }
  854. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  855. ->where('website_id', $data['website_id'])
  856. ->where('is_other', 1)
  857. ->where('other_id', '!=', 0)
  858. ->first();
  859. // return Result::success($choice['other']);
  860. $choice_id = $data['choice_id'];
  861. if (!empty($choice['other'])) {
  862. // array_push($data['choice_id'],$choice['other']['other_id']);
  863. if (!empty($choice_id)) {
  864. $key = array_search($choice['other']['id'], $choice_id);
  865. if ($key !== false) {
  866. unset($choice_id[$key]);
  867. $choice_id = array_values($choice_id);
  868. }
  869. array_push($choice_id, $choice['other']['other_id']);
  870. } else {
  871. $choice_id[0] = $choice['other']['other_id'];
  872. }
  873. // return Result::success($data['choice_id']);
  874. }
  875. // return Result::success($data);
  876. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  877. ->where('website_id', $data['website_id'])
  878. ->increment('results', 1);
  879. if (empty($choice)) {
  880. return Result::error("请选择已有的选项!", 0);
  881. }
  882. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  883. ->where('website_id', $data['website_id'])
  884. ->where('other_id', 0)
  885. ->get();
  886. $survey['choice'] = $choice_id;
  887. return Result::success($survey);
  888. }
  889. return Result::error("参数必填!");
  890. }
  891. return Result::error("此调查问卷不存在", 0);
  892. }
  893. return Result::error("参数必填!");
  894. }
  895. /**
  896. * 后端-获取网站调查问卷列表
  897. * @param array $data
  898. * @return array
  899. */
  900. public function getSurveyList(array $data): array
  901. {
  902. $where = [];
  903. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  904. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  905. }
  906. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  907. array_push($where, ['survey_type', '=', $data['survey_type']]);
  908. }
  909. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  910. array_push($where, ['is_survey', '=', $data['is_survey']]);
  911. }
  912. // return Result::success($where);
  913. if (!empty($where)) {
  914. $query = Article::where($where)->where(function ($q) {
  915. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  916. });
  917. } else {
  918. $query = Article::where(function ($q) {
  919. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  920. });
  921. }
  922. $count = $query->count();
  923. $survey = $query->orderByDesc('id')
  924. ->limit($data['pageSize'])
  925. ->offset(($data['page'] - 1) * $data['pageSize'])
  926. ->get();
  927. if (empty($survey->toArray())) {
  928. return Result::error("暂无调查问卷!", 0);
  929. }
  930. $result = [
  931. 'rows' => $survey,
  932. 'count' => $count,
  933. ];
  934. return Result::success($result);
  935. }
  936. /**
  937. * 后端-获取网站调查问卷详情
  938. * @param array $data
  939. * @return array
  940. */
  941. public function getSurveyInfo(array $data): array
  942. {
  943. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  944. $where = ['sur_id' => $data['sur_id']];
  945. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  946. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  947. ->select('article_survey.*', 'article.survey_type')
  948. ->get()->all();
  949. if (empty($choose)) {
  950. return Result::error("此调查问卷不存在", 0);
  951. }
  952. $resultsArray = array_column($choose, 'results');
  953. $total = array_sum($resultsArray);
  954. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  955. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  956. // $total = 0;
  957. if (!empty($other)) {
  958. $total = $total + $other['results'];
  959. $other['choice_name'] = $other['choice_name'] . '(其他)';
  960. if (!empty($others)) {
  961. $other['hasChildren'] = true;
  962. // array_push($other,['hasChildren','=',true]);
  963. $other['children'] = $others;
  964. $other_choices = [$other->toArray()];
  965. $mer_choice = array_merge($choose, $other_choices);
  966. $value_choice = array_values($mer_choice);
  967. } else {
  968. // return Result::error('1111');
  969. $other_choices = [$other->toArray()];
  970. $other_choices = array_merge($choose, $other_choices);
  971. $value_choice = array_values($other_choices);
  972. // return Result::success($result);
  973. }
  974. } else {
  975. $value_choice = $choose;
  976. }
  977. $result = [
  978. 'choose' => $value_choice,
  979. 'total' => $total,
  980. ];
  981. }
  982. return Result::success($result);
  983. }
  984. /**
  985. * 前端-搜索新闻列表
  986. * @param array $data
  987. * @return array
  988. */
  989. public function selectWebsiteArticle(array $data): array
  990. {
  991. $where = [];
  992. // 初始化查询构造器
  993. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  994. $query = Article::where('status', 1)
  995. ->whereIn('catid', $category)
  996. ->where(function ($query) use ($data) {
  997. $query->where(function ($subQuery) use ($data) {
  998. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  999. })->orWhereNull("ignore_ids");
  1000. });
  1001. // return Result::success($all_articles);
  1002. // 检查是否存在 cityid 参数
  1003. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1004. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1005. }
  1006. // 检查是否存在 department_id 参数
  1007. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1008. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1009. }
  1010. // 检查是否存在 keyword 参数
  1011. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1012. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1013. }
  1014. // 计算总数
  1015. $count = $query->count();
  1016. // 分页查询
  1017. $articles = $query->orderBy("updated_at", "desc")
  1018. ->limit($data['pageSize'])
  1019. ->offset(($data['page'] - 1) * $data['pageSize'])
  1020. ->get()->all();
  1021. if (empty($articles)) {
  1022. return Result::error("没有符合条件的资讯数据");
  1023. }
  1024. $data = [
  1025. 'rows' => $articles,
  1026. 'count' => $count,
  1027. ];
  1028. return Result::success($data);
  1029. }
  1030. /**
  1031. * 验证导航名称是否重复
  1032. * @return void
  1033. */
  1034. public function checkCategoryName(array $data): array
  1035. {
  1036. $result = Category::when($data, function ($query) use ($data) {
  1037. if (isset($data['name']) && $data['name']) {
  1038. $query->where("name", $data['name']);
  1039. }
  1040. if (isset($data['id']) && $data['id']) {
  1041. $query->where("id", "!=", $data['id']);
  1042. }
  1043. })->first();
  1044. if ($result) {
  1045. return Result::error("已存在");
  1046. } else {
  1047. return Result::success();
  1048. }
  1049. }
  1050. //20250226 产品列表
  1051. public function getGoodList(array $data): array
  1052. {
  1053. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1054. unset($data['type_id']);
  1055. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1056. $where = [];
  1057. if ($type_id != '10000') {
  1058. $where = [
  1059. 'good.user_id' => $user_id,
  1060. ];
  1061. }
  1062. //类型
  1063. if (isset($data['type_id']) && $data['type_id']) {
  1064. $where = [
  1065. 'type_id' => $data['type_id'],
  1066. ];
  1067. }
  1068. //名称
  1069. if (isset($data['name']) && $data['name']) {
  1070. $where = [
  1071. 'good.name' => $data['name'],
  1072. ];
  1073. }
  1074. $where1 = [];
  1075. //website_id
  1076. // if (isset($data['website_id']) && $data['website_id']) {
  1077. // $where1 = [
  1078. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1079. // ];
  1080. // }
  1081. // website_name
  1082. if (isset($data['website_name']) && $data['website_name']) {
  1083. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1084. }
  1085. // catid
  1086. if (isset($data['category_name']) && $data['category_name']) {
  1087. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1088. }
  1089. // $result = Good::where($where)
  1090. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1091. $result = Good::where($where)
  1092. ->when(!empty($where1), function ($query) use ($where1) {
  1093. return $query->where($where1);
  1094. })
  1095. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1096. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1097. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1098. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1099. ->orderBy("id", "desc")
  1100. ->limit($data['page_size'])
  1101. ->offset(($data['page'] - 1) * $data['page_size'])
  1102. ->get();
  1103. $count = Good::where($where)
  1104. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1105. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1106. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1107. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1108. ->orderBy("updated_at", "desc")->count();
  1109. $data = [
  1110. 'rows' => $result->toArray(),
  1111. 'count' => $count,
  1112. ];
  1113. if (empty($result)) {
  1114. return Result::error("此栏目暂无相关产品", 0);
  1115. }
  1116. return Result::success($data);
  1117. }
  1118. public function getGoodInfo(array $data): array
  1119. {
  1120. $result = Good::where('id', $data['id'])->first();
  1121. if (empty($result)) {
  1122. return Result::error("此产品不存在", 0);
  1123. }
  1124. return Result::success($result);
  1125. }
  1126. public function addGood(array $data): array
  1127. {
  1128. // unset($data['city_arr_id']);
  1129. // unset($data['cat_arr_id']);
  1130. $data['city_id'] = end($data['city_arr_id']);
  1131. $data['catid'] = end($data['cat_arr_id']);
  1132. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1133. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1134. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1135. unset($data['imgUrl']);
  1136. $result = Good::insert($data);
  1137. if (empty($result)) {
  1138. return Result::error("添加失败", 0);
  1139. }
  1140. return Result::success($result);
  1141. }
  1142. public function updateGood(array $data): array
  1143. {
  1144. $data['city_id'] = end($data['city_arr_id']);
  1145. $data['catid'] = end($data['cat_arr_id']);
  1146. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1147. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1148. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1149. //设置东八区
  1150. date_default_timezone_set('Asia/Shanghai');
  1151. $data['updated_at'] = date('Y-m-d H:i:s');
  1152. $result = Good::where('id', $data['id'])->update($data);
  1153. if (empty($result)) {
  1154. return Result::error("更新失败", 0);
  1155. }
  1156. return Result::success($result);
  1157. }
  1158. public function delGood(array $data): array
  1159. {
  1160. $result = Good::where('id', $data['id'])->delete();
  1161. if (empty($result)) {
  1162. return Result::error("删除失败", 0);
  1163. }
  1164. return Result::success($result);
  1165. }
  1166. //20250226 产品列表
  1167. //20250306 求职信息
  1168. public function getJobHuntingList(array $data): array
  1169. {
  1170. $where = [];
  1171. if (isset($data['username']) && !empty($data['username'])) {
  1172. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1173. }
  1174. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1175. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1176. unset($data['type_id']);
  1177. if ($type_id != '10000') {
  1178. $where[] = ['job_hunting.user_id', '=', $user_id];
  1179. }
  1180. $result = JobHunting::where($where)
  1181. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1182. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1183. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1184. ->orderBy("id", "desc")
  1185. ->limit($data['page_size'])
  1186. ->offset(($data['page'] - 1) * $data['page_size'])
  1187. ->get();
  1188. if (empty($result)) {
  1189. return Result::error("查询失败", 0);
  1190. }
  1191. $count = JobHunting::where($where)
  1192. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1193. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1194. ->count();
  1195. $data = [
  1196. 'rows' => $result->toArray(),
  1197. 'count' => $count,
  1198. ];
  1199. return Result::success($data);
  1200. }
  1201. public function addJobHunting(array $data): array
  1202. {
  1203. date_default_timezone_set('Asia/Shanghai');
  1204. unset($data['company_name']);
  1205. unset($data['job_industry']);
  1206. unset($data['job_name']);
  1207. unset($data['department']);
  1208. unset($data['job_timeList']);
  1209. unset($data['job_content']);
  1210. $data['created_at'] = date('Y-m-d H:i:s');
  1211. $data['updated_at'] = date('Y-m-d H:i:s');
  1212. var_dump($data, '-----------------test---------');
  1213. $result = JobHunting::create($data);
  1214. if (empty($result)) {
  1215. return Result::error("添加失败", 0);
  1216. }
  1217. return Result::success($result);
  1218. }
  1219. public function delJobHunting(array $data): array
  1220. {
  1221. $result = JobHunting::where('id', $data['id'])->delete();
  1222. if (empty($result)) {
  1223. return Result::error("删除失败", 0);
  1224. }
  1225. return Result::success($result);
  1226. }
  1227. public function updateJobHunting(array $data): array
  1228. {
  1229. //设置东八区
  1230. date_default_timezone_set('Asia/Shanghai');
  1231. unset($data['company_name']);
  1232. unset($data['job_industry']);
  1233. unset($data['job_name']);
  1234. unset($data['department']);
  1235. unset($data['job_timeList']);
  1236. unset($data['job_content']);
  1237. $data['created_at'] = date('Y-m-d H:i:s');
  1238. $data['updated_at'] = date('Y-m-d H:i:s');
  1239. $result = JobHunting::where('id', $data['id'])->update($data);
  1240. if (empty($result)) {
  1241. return Result::error("更新失败", 0);
  1242. }
  1243. return Result::success($result);
  1244. }
  1245. public function getJobHuntingInfo(array $data): array
  1246. {
  1247. $result = JobHunting::where('id', $data['id'])->first();
  1248. if (empty($result)) {
  1249. return Result::error("查询失败", 0);
  1250. }
  1251. return Result::success($result);
  1252. }
  1253. public function getJobHuntingData(array $data): array
  1254. {
  1255. $jobEnum = JobEnum::get();
  1256. $jobIndustry = JobIndustry::get();
  1257. $jobNature = JobNature::get();
  1258. $jobPosition = JobPosition::get();
  1259. $data = [
  1260. 'jobEnum' => $jobEnum,
  1261. 'jobIndustry' => $jobIndustry,
  1262. 'jobNature' => $jobNature,
  1263. 'jobPosition' => $jobPosition,
  1264. ];
  1265. return Result::success($data);
  1266. }
  1267. public function delJobHuntingInfo(array $data): array
  1268. {
  1269. $result = JobHunting::where('id', $data['id'])->delete();
  1270. return Result::success();
  1271. }
  1272. }