NewsService.php 53 KB

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