NewsService.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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\Good;
  9. use App\Model\JobHunting;
  10. use Hyperf\DbConnection\Db;
  11. use Hyperf\RpcServer\Annotation\RpcService;
  12. use App\Tools\Result;
  13. use Ramsey\Uuid\Uuid;
  14. use Hyperf\Utils\Random;
  15. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  16. class NewsService implements NewsServiceInterface
  17. {
  18. /**
  19. * 获取导航池列表
  20. * @param array $data
  21. * @return array
  22. */
  23. public function getCategoryList(array $data): array
  24. {
  25. $where = [];
  26. if (isset($data['name']) && $data['name']) {
  27. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  28. }
  29. if (isset($data['department_id']) && $data['department_id']) {
  30. array_push($where, ['category.department_id', '=', $data['department_id']]);
  31. }
  32. $city_id = '';
  33. if (isset($data['city_id']) && $data['city_id']) {
  34. $city_id = intval($data['city_id']);
  35. }
  36. $rep = Category::where($where)
  37. ->when($city_id, function ($query) use ($city_id) {
  38. if (isset($city_id) && $city_id) {
  39. $query->whereJsonContains("category.city_arr_id", $city_id);
  40. }
  41. })
  42. ->leftJoin('district', 'category.city_id', 'district.id')
  43. ->leftJoin('department', 'category.department_id', 'department.id')
  44. ->select("category.*", "district.name as city_name", "department.name as department_name")
  45. ->limit($data['pageSize'])->orderByDesc('category.updated_at')->offset(($data['page'] - 1) * $data['pageSize'])->get();
  46. $count = Category::where($where)->when($city_id, function ($query) use ($city_id) {
  47. if (isset($city_id) && $city_id) {
  48. $query->whereJsonContains("category.city_arr_id", $city_id);
  49. }
  50. })->count();
  51. $data = [
  52. 'rows' => $rep->toArray(),
  53. 'count' => $count,
  54. ];
  55. if (empty($rep->toArray())) {
  56. return Result::error("没有导航池数据");
  57. }
  58. return Result::success($data);
  59. }
  60. public function myCategoryList(array $data): array
  61. {
  62. $sszq = $data['sszq'] ?? '';
  63. unset($data['sszq']);
  64. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  65. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  66. $where[] = [
  67. 'pid', '=', $data['pid'],
  68. ];
  69. if (isset($data['name'])) {
  70. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  71. }
  72. var_dump($where);
  73. //根据分类id,从category表中取出分类信息
  74. $result = Category::where($where)
  75. ->whereIn('category.id', $catorytids)
  76. ->select('category.*', 'category.id as category_id')->get();
  77. if (empty($result)) {
  78. return Result::error("没有栏目数据");
  79. }
  80. return Result::success($result);
  81. }
  82. /**
  83. * @param array $data
  84. * @return array
  85. */
  86. public function categoryList(array $data): array
  87. {
  88. $where[] = [
  89. 'pid', '=', $data['pid'],
  90. ];
  91. if (isset($data['name'])) {
  92. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  93. }
  94. var_dump($where);
  95. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  96. if (empty($result)) {
  97. return Result::error("没有栏目数据");
  98. }
  99. return Result::success($result);
  100. }
  101. /**
  102. * @param array $data
  103. * @return array
  104. */
  105. public function addCategory(array $data): array
  106. {
  107. $id = Category::insertGetId($data);
  108. if (empty($id)) {
  109. return Result::error("添加失败");
  110. }
  111. return Result::success(['id' => $id]);
  112. }
  113. /**
  114. * @param array $data
  115. * @return array
  116. */
  117. public function delCategory(array $data): array
  118. {
  119. $categoryList = Category::where(['pid' => $data['id']])->get();
  120. var_dump("分类列表:", $data, $categoryList);
  121. if ($categoryList->toArray()) {
  122. return Result::error("分类下面有子分类不能删除");
  123. }
  124. $articleList = Article::where(['catid' => $data['id']])->get();
  125. var_dump("文章列表:", $articleList);
  126. if ($articleList->toArray()) {
  127. return Result::error("分类下面有资讯不能删除");
  128. }
  129. $result = Category::where($data)->delete();
  130. if (!$result) {
  131. return Result::error("删除失败");
  132. }
  133. return Result::success($result);
  134. }
  135. /**
  136. * @param array $data
  137. * @return array
  138. */
  139. public function updateCategory(array $data): array
  140. {
  141. $where = [
  142. 'id' => $data['id'],
  143. ];
  144. $result = Category::where($where)->update($data);
  145. if ($result) {
  146. return Result::success($result);
  147. } else {
  148. return Result::error("更新失败");
  149. }
  150. }
  151. /**
  152. * 获取导航池信息
  153. * @param array $data
  154. * @return array
  155. */
  156. public function getCategoryInfo(array $data): array
  157. {
  158. $where = [
  159. 'id' => $data['id'],
  160. ];
  161. $result = Category::where($where)->first();
  162. if ($result) {
  163. return Result::success($result);
  164. } else {
  165. return Result::error("更新失败");
  166. }
  167. }
  168. /**
  169. * @param array $data
  170. * @return array
  171. */
  172. public function getArticleList(array $data): array
  173. {
  174. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  175. $type_id = $data['type_id'];
  176. unset($data['type_id']);
  177. $user_id = $data['user_id'];
  178. unset($data['user_id']);
  179. $where = [];
  180. if (isset($data['title']) && $data['title']) {
  181. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  182. }
  183. if (isset($data['category_name']) && $data['category_name']) {
  184. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  185. }
  186. if (isset($data['author']) && $data['author']) {
  187. array_push($where, ['article.author', '=', $data['author']]);
  188. }
  189. if (isset($data['islink']) && $data['islink'] !== "") {
  190. array_push($where, ['article.islink', '=', $data['islink']]);
  191. }
  192. if (isset($data['status']) && $data['status'] !== "") {
  193. array_push($where, ['article.status', '=', $data['status']]);
  194. }
  195. //不是管理员展示个人数据;
  196. if ($type_id != 10000) {
  197. $where[] = ['article.admin_user_id', '=', $user_id];
  198. }
  199. $rep = Article::where($where)
  200. ->whereNotIn('article.status', [404])
  201. ->leftJoin('category', 'article.catid', 'category.id')
  202. ->select("article.*", "category.name as category_name")
  203. ->orderBy("article.id", "desc")
  204. ->limit($data['pageSize'])
  205. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  206. $count = Article::where($where)->whereNotIn('article.status', [404])
  207. ->leftJoin('category', 'article.catid', 'category.id')->count();
  208. $data = [
  209. 'rows' => $rep->toArray(),
  210. 'count' => $count,
  211. ];
  212. if (empty($rep)) {
  213. return Result::error("没有信息数据");
  214. }
  215. return Result::success($data);
  216. }
  217. /**
  218. * @param array $data
  219. * @return array
  220. */
  221. public function addArticle(array $data): array
  222. {
  223. var_dump($data, '----------12-----------1');
  224. var_dump($data, '----------12-----------1');
  225. unset($data['user_type']);
  226. // unset($data['web_site_id']);
  227. unset($data['nav_add_pool_id']);
  228. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  229. Db::beginTransaction();
  230. try {
  231. //处理投票
  232. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  233. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  234. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  235. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  236. unset($data['is_survey']);
  237. unset($data['survey_name']);
  238. unset($data['suvey_array']);
  239. unset($data['website_id']);
  240. if ($data['hits'] == '') {
  241. $data['hits'] = 0;
  242. }
  243. if ($data['is_original'] == '') {
  244. $data['is_original'] = 0;
  245. }
  246. if ($data['status'] == '') {
  247. $data['status'] = 0;
  248. }
  249. $articleData = $data;
  250. unset($articleData['content']);
  251. $id = Article::insertGetId($articleData);
  252. $articleDataContent = [
  253. 'article_id' => $id,
  254. 'content' => $data['content'],
  255. ];
  256. ArticleData::insertGetId($articleDataContent);
  257. //处理投票
  258. if ($is_survey == 1) {
  259. //生成年月日时分秒+8位随机数
  260. $uuid = date('YmdHis') . rand(10000000, 99999999);
  261. var_dump($suvey_array, 'suvey_array________');
  262. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  263. var_dump($suveys_array, '---------------------1');
  264. var_dump($suvey_array, '---------------------2');
  265. $suvey_data = [];
  266. foreach ($suveys_array as $key => $value) {
  267. if ($value == '') {
  268. continue;
  269. }
  270. if (is_array($value)) {
  271. $suvey_data[] = [
  272. 'sur_id' => $uuid,
  273. 'art_id' => $id,
  274. 'website_id' => $website_id ?? 2,
  275. 'survey_name' => $survey_name,
  276. 'choice_name' => $value[1],
  277. 'is_other' => 1,
  278. 'other_id' => 0,
  279. 'results' => 0,
  280. ];
  281. } else {
  282. $suvey_data[] = [
  283. 'sur_id' => $uuid,
  284. 'art_id' => $id,
  285. 'website_id' => $website_id ?? 2,
  286. 'survey_name' => $survey_name,
  287. 'choice_name' => $value,
  288. 'is_other' => 0,
  289. 'other_id' => 0,
  290. 'results' => 0,
  291. ];
  292. }
  293. if (empty($suvey_data)) {
  294. throw new \Exception("投票数据为空");
  295. }
  296. }
  297. $result = ArticleSurvey::insert($suvey_data);
  298. if (!$result) {
  299. throw new \Exception("投票失败,ArticleSurvey插入失败");
  300. }
  301. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  302. if (!$result) {
  303. throw new \Exception("投票失败,更新主表失败");
  304. }
  305. }
  306. Db::commit();
  307. return Result::success(['id' => $id]);
  308. } catch (\Throwable $ex) {
  309. Db::rollBack();
  310. var_dump($ex->getMessage());
  311. return Result::error("创建失败", 0);
  312. }
  313. }
  314. /**
  315. * @param array $data
  316. * @return array
  317. */
  318. public function delArticle(array $data): array
  319. {
  320. $result = Article::where($data)->delete();
  321. //survey投票删除
  322. articleSurvey::where(['art_id' => $data['id']])->delete();
  323. if (!$result) {
  324. return Result::error("删除失败");
  325. }
  326. return Result::success($result);
  327. }
  328. /**
  329. * @param array $data
  330. * @return array
  331. */
  332. public function updateArticle(array $data): array
  333. {
  334. var_dump($data, '----------12-----------1');
  335. Db::beginTransaction();
  336. unset($data['user_type']);
  337. // unset($data['web_site_id']);
  338. unset($data['nav_add_pool_id']);
  339. try {
  340. //处理投票
  341. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  342. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  343. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  344. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  345. unset($data['is_survey']);
  346. unset($data['survey_name']);
  347. unset($data['suvey_array']);
  348. unset($data['website_id']);
  349. if ($data['hits'] == '') {
  350. $data['hits'] = 0;
  351. }
  352. if ($data['is_original'] == '') {
  353. $data['is_original'] = 0;
  354. }
  355. if ($data['status'] == '') {
  356. $data['status'] = 0;
  357. }
  358. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  359. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  360. $articleData = $data;
  361. unset($articleData['content']);
  362. unset($articleData['status_name']);
  363. unset($articleData['name']);
  364. unset($articleData['content']);
  365. unset($articleData['pid_arr']);
  366. unset($articleData['pid']);
  367. $id = Article::where(['id' => $data['id']])->update($articleData);
  368. $articleDataContent = [
  369. 'content' => $data['content'],
  370. ];
  371. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  372. //处理投票
  373. $id = $data['id'];
  374. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  375. var_dump($suvey_array, 'suvey_array________delete');
  376. //处理投票
  377. if ($is_survey == 1) {
  378. //生成年月日时分秒+8位随机数
  379. $uuid = date('YmdHis') . rand(10000000, 99999999);
  380. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  381. var_dump($suveys_array, '---------------------1');
  382. var_dump($suvey_array, '---------------------2');
  383. $suvey_data = [];
  384. if (is_array($suveys_array)) {
  385. foreach ($suveys_array as $key => $value) {
  386. if ($value == '') {
  387. continue;
  388. }
  389. if (is_array($value)) {
  390. $suvey_data[] = [
  391. 'sur_id' => $uuid,
  392. 'art_id' => $id,
  393. 'website_id' => $website_id ?? 2,
  394. 'survey_name' => $survey_name,
  395. 'choice_name' => $value[1],
  396. 'is_other' => 1,
  397. 'other_id' => 0,
  398. 'results' => 0,
  399. ];
  400. } else {
  401. $suvey_data[] = [
  402. 'sur_id' => $uuid,
  403. 'art_id' => $id,
  404. 'website_id' => $website_id ?? 2,
  405. 'survey_name' => $survey_name,
  406. 'choice_name' => $value,
  407. 'is_other' => 0,
  408. 'other_id' => 0,
  409. 'results' => 0,
  410. ];
  411. }
  412. if (empty($suvey_data)) {
  413. throw new \Exception("投票数据为空");
  414. }
  415. }
  416. }
  417. $result = ArticleSurvey::insert($suvey_data);
  418. if (!$result) {
  419. throw new \Exception("投票失败");
  420. }
  421. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  422. if (!$result) {
  423. throw new \Exception("投票失败");
  424. }
  425. } else {
  426. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  427. }
  428. Db::commit();
  429. return Result::success([]);
  430. } catch (\Throwable $ex) {
  431. Db::rollBack();
  432. var_dump($ex->getMessage());
  433. return Result::error("更新失败" . $ex->getMessage(), 0);
  434. }
  435. }
  436. /**
  437. * 更新资讯状态
  438. * @param array $data
  439. * @return array
  440. */
  441. public function upArticleStatus(array $data): array
  442. {
  443. $result = Article::where(['id' => $data['id']])->update($data);
  444. if ($result) {
  445. return Result::success();
  446. } else {
  447. return Result::error("更新状态失败", 0);
  448. }
  449. }
  450. /**
  451. * @param array $data
  452. * @return array
  453. */
  454. public function getArticleInfo(array $data): array
  455. {
  456. $where = [
  457. 'article.id' => $data['id'],
  458. // 'article.status' => 1,
  459. ];
  460. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  461. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get()->all();
  462. var_dump($articleSurvey, 'articleSurvey');
  463. $info = $result;
  464. var_dump($info, 'info');
  465. // $info['survey_array'] = $articleSurvey == null ? [] : $info['survey_array'];
  466. if ($result) {
  467. return Result::success($info);
  468. } else {
  469. return Result::error("查询失败", 0);
  470. }
  471. }
  472. /**
  473. * 获取新闻
  474. * @param array $data
  475. * @return array
  476. */
  477. public function getWebsiteArticlett(array $data): array
  478. {
  479. $category = WebsiteCategory::where('website_id', $data['website_id'])->select('category_id')->get();
  480. $category = $category->toArray();
  481. $result = [];
  482. if ($category) {
  483. $category_ids = [];
  484. foreach ($category as $val) {
  485. array_push($category_ids, $val['category_id']);
  486. }
  487. if (isset($data['placeid'])) {
  488. $placeid = $data['placeid'] - 1;
  489. $result = Article::where('status', 1)->where('level', $data['level'])->whereIn("catid", $category_ids)->orderBy("created_at", "desc")->offset($placeid)->limit($data['pageSize'])->get();
  490. } else {
  491. $result = Article::where('status', 1)->where('level', $data['level'])->whereIn("catid", $category_ids)->orderBy("created_at", "desc")->offset(0)->limit($data['pageSize'])->get();
  492. }
  493. if (empty($result)) {
  494. return Result::error("暂无头条新闻", 0);
  495. }
  496. return Result::success($result);
  497. } else {
  498. return Result::error("本网站下暂无相关栏目", 0);
  499. }
  500. }
  501. /**
  502. * 获取模块新闻
  503. * @param array $data
  504. * @return array
  505. */
  506. public function getWebsiteModelArticles(array $data): array
  507. {
  508. $catid = $data['catid'];
  509. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  510. $category = $category->toArray();
  511. if (!empty($category)) {
  512. $where = [
  513. 'status' => 1,
  514. 'catid' => $catid,
  515. ];
  516. if ($data['level'] == 1) {
  517. $level = [
  518. 0 => '1',
  519. 1 => '4',
  520. 2 => '5',
  521. ];
  522. $result = Article::where($where)->whereIn('level', $level)->orderBy("created_at", "desc")->limit($data['pagesize'])->get();
  523. } elseif ($data['level'] == 2) {
  524. $level = '2';
  525. $result = Article::where($where)->where('level', $level)->orderBy("created_at", "desc")->limit($data['pagesize'])->get();
  526. } else {
  527. $level = '3';
  528. $result = Article::where($where)->where('level', $level)->orderBy("created_at", "desc")->limit($data['pagesize'])->get();
  529. }
  530. $result = $result->toArray();
  531. if (!empty($result) && isset($data['placeid']) && !empty($data['placeid'])) {
  532. $placeid = $data['placeid'] - 1;
  533. if ($level == 2 || $level == 3) {
  534. $where = [
  535. 'level' => $level,
  536. ];
  537. $result = Article::where($where)
  538. ->orderBy("created_at", "desc")
  539. ->offset($placeid)
  540. ->limit($data['pagesize'])->get();
  541. } else {
  542. $result = Article::where($where)
  543. ->whereIn('level', $level)
  544. ->offset($placeid)
  545. ->orderBy("created_at", "desc")
  546. ->limit($data['pagesize'])->get();
  547. }
  548. }
  549. if (empty($result)) {
  550. return Result::error("此栏目暂无相关新闻", 0);
  551. }
  552. } else {
  553. return Result::error("此网站暂无此栏目", 0);
  554. }
  555. return Result::success($result);
  556. }
  557. //20250226 产品列表
  558. public function getGoodList(array $data): array
  559. {
  560. $where = [];
  561. //类型
  562. if (isset($data['type_id']) && $data['type_id']) {
  563. $where = [
  564. 'type_id' => $data['type_id'],
  565. ];
  566. }
  567. //名称
  568. if (isset($data['name']) && $data['name']) {
  569. $where = [
  570. 'good.name' => $data['name'],
  571. ];
  572. }
  573. $where1 = [];
  574. //website_id
  575. // if (isset($data['website_id']) && $data['website_id']) {
  576. // $where1 = [
  577. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  578. // ];
  579. // }
  580. // website_name
  581. if (isset($data['website_name']) && $data['website_name']) {
  582. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  583. }
  584. // catid
  585. if (isset($data['category_name']) && $data['category_name']) {
  586. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  587. }
  588. // $result = Good::where($where)
  589. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  590. $result = Good::where($where)
  591. ->when(!empty($where1), function ($query) use ($where1) {
  592. return $query->where($where1);
  593. })
  594. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  595. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  596. ->leftJoin('category', 'good.catid', '=', 'category.id')
  597. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  598. ->orderBy("id", "desc")
  599. ->limit($data['page_size'])
  600. ->offset(($data['page'] - 1) * $data['page_size'])
  601. ->get();
  602. $count = Good::where($where)
  603. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  604. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  605. ->leftJoin('category', 'good.catid', '=', 'category.id')
  606. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  607. ->orderBy("updated_at", "desc")->count();
  608. $data = [
  609. 'rows' => $result->toArray(),
  610. 'count' => $count,
  611. ];
  612. if (empty($result)) {
  613. return Result::error("此栏目暂无相关产品", 0);
  614. }
  615. return Result::success($data);
  616. }
  617. public function getGoodInfo(array $data): array
  618. {
  619. $result = Good::where('id', $data['id'])->first();
  620. if (empty($result)) {
  621. return Result::error("此产品不存在", 0);
  622. }
  623. return Result::success($result);
  624. }
  625. public function addGood(array $data): array
  626. {
  627. // unset($data['city_arr_id']);
  628. // unset($data['cat_arr_id']);
  629. $data['city_id'] = end($data['city_arr_id']);
  630. $data['catid'] = end($data['cat_arr_id']);
  631. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  632. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  633. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  634. unset($data['imgUrl']);
  635. $result = Good::insert($data);
  636. if (empty($result)) {
  637. return Result::error("添加失败", 0);
  638. }
  639. return Result::success($result);
  640. }
  641. public function updateGood(array $data): array
  642. {
  643. $data['city_id'] = end($data['city_arr_id']);
  644. $data['catid'] = end($data['cat_arr_id']);
  645. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  646. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  647. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  648. //设置东八区
  649. date_default_timezone_set('Asia/Shanghai');
  650. $data['updated_at'] = date('Y-m-d H:i:s');
  651. $result = Good::where('id', $data['id'])->update($data);
  652. if (empty($result)) {
  653. return Result::error("更新失败", 0);
  654. }
  655. return Result::success($result);
  656. }
  657. public function delGood(array $data): array
  658. {
  659. $result = Good::where('id', $data['id'])->delete();
  660. if (empty($result)) {
  661. return Result::error("删除失败", 0);
  662. }
  663. return Result::success($result);
  664. }
  665. //20250226 产品列表
  666. //20250306 求职信息
  667. public function getJobHuntingList(array $data): array
  668. {
  669. $where = [];
  670. if (isset($data['title']) && !empty($data['title'])) {
  671. $where[] = ['title', 'like', '%' . $data['title'] . '%'];
  672. }
  673. $result = JobHunting::where($where)->paginate($data['limit'], ['*'], 'page', $data['page'])->toArray();
  674. if (empty($result)) {
  675. return Result::error("查询失败", 0);
  676. }
  677. return Result::success($result);
  678. }
  679. public function addJobHunting(array $data): array
  680. {
  681. $data['created_at'] = date('Y-m-d H:i:s');
  682. $data['updated_at'] = date('Y-m-d H:i:s');
  683. $result = JobHunting::create($data);
  684. if (empty($result)) {
  685. return Result::error("添加失败", 0);
  686. }
  687. return Result::success($result);
  688. }
  689. public function delJobHunting(array $data): array
  690. {
  691. $result = JobHunting::where('id', $data['id'])->delete();
  692. if (empty($result)) {
  693. return Result::error("删除失败", 0);
  694. }
  695. return Result::success($result);
  696. }
  697. public function updateJobHunting(array $data): array
  698. {
  699. $result = JobHunting::where('id', $data['id'])->update($data);
  700. if (empty($result)) {
  701. return Result::error("更新失败", 0);
  702. }
  703. return Result::success($result);
  704. }
  705. public function getJobHuntingInfo(array $data): array
  706. {
  707. $result = JobHunting::where('id', $data['id'])->first();
  708. if (empty($result)) {
  709. return Result::error("查询失败", 0);
  710. }
  711. return Result::success($result);
  712. }
  713. }