NewsService.php 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  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. $result['category_id'] = $category['category_id'];
  745. $result['cat_name'] = $category['alias'];
  746. $result['website_name'] = $category['website_name'] ?? "";
  747. $result['suffix'] = $category['suffix'] ?? "";
  748. return Result::success($result);
  749. }
  750. /**
  751. * 前端-获取网站调查问卷
  752. * @param array $data
  753. * @return array
  754. */
  755. public function getWebsiteSurvey(array $data): array
  756. {
  757. if (isset($data['website_id']) && !empty($data['website_id'])) {
  758. $website = Website::where('id', $data['website_id'])->first();
  759. if (empty($website)) {
  760. return Result::error("暂无此网站", 0);
  761. }
  762. }
  763. if (isset($data['art_id']) && !empty($data['art_id'])) {
  764. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  765. if (empty($article)) {
  766. return Result::error("暂无此文章", 0);
  767. }
  768. // return Result::error($data,0);
  769. $where['art_id'] = $data['art_id'];
  770. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  771. } else {
  772. $survey = Article::where(function ($query) {
  773. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  774. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  775. })
  776. ->where('status', 1)
  777. ->where('is_survey', 1)
  778. ->select('survey_id')
  779. ->orderBy('updated_at', 'desc')
  780. ->first();
  781. if (empty($survey)) {
  782. return Result::error("暂无调查问卷", 0);
  783. }
  784. $where['sur_id'] = $survey['survey_id'];
  785. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  786. }
  787. // return Result::success($where);
  788. $result = ArticleSurvey::where($where)
  789. ->where(function ($query) {
  790. $query->where('is_other', 0)
  791. ->orWhere(function ($subQuery) {
  792. $subQuery->where('is_other', 1)
  793. ->where('other_id', 0);
  794. });
  795. })
  796. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  797. ->select('article_survey.*', 'article.survey_type')
  798. ->get()->all();
  799. if (empty($result)) {
  800. return Result::error("此文章暂无调查问卷", 0);
  801. }
  802. return Result::success($result);
  803. }
  804. /**
  805. * 前端-添加网站调查问卷选项
  806. * @param array $data
  807. * @return array
  808. */
  809. public function addWebsiteSurveyOption(array $data): array
  810. {
  811. if (isset($data['website_id']) && !empty($data['website_id'])) {
  812. $website = Website::where('id', $data['website_id'])->first();
  813. if (empty($website)) {
  814. return Result::error("暂无此网站", 0);
  815. }
  816. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  817. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  818. if (empty($survey)) {
  819. return Result::error("此调查问卷不可添加选项", 0);
  820. }
  821. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  822. $choice = [
  823. 'art_id' => $survey['art_id'],
  824. 'website_id' => $data['website_id'],
  825. 'survey_name' => $survey['survey_name'],
  826. 'choice_name' => $data['choice_name'],
  827. 'sur_id' => $survey['sur_id'],
  828. 'is_other' => 1,
  829. 'other_id' => $survey['id'],
  830. ];
  831. $result = ArticleSurvey::insertGetId($choice);
  832. if (empty($result)) {
  833. return Result::error("添加失败", 0);
  834. }
  835. return Result::success($result);
  836. }
  837. }
  838. return Result::error("添加失败", 0);
  839. }
  840. return Result::error("添加失败", 0);
  841. }
  842. /**
  843. * 前端-调查问卷投票
  844. * @param array $data
  845. * @return array
  846. */
  847. public function addWebsiteSurveyVote(array $data): array
  848. {
  849. // return Result::success($data);
  850. if (isset($data['website_id']) && !empty($data['website_id'])) {
  851. $website = Website::where('id', $data['website_id'])->first();
  852. if (empty($website)) {
  853. return Result::error("暂无此网站", 0);
  854. }
  855. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  856. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  857. // return Result::success($survey);
  858. if (empty($is_survey)) {
  859. return Result::error("此调查问卷不存在", 0);
  860. }
  861. // return Result::success($survey);
  862. // 调查问卷类型
  863. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  864. //多选 若是json型则转化成数组类型
  865. if (strpos($data['choice_id'], '[') === 0) {
  866. $data['choice_id'] = json_decode($data['choice_id'], true);
  867. } else {
  868. // 单选 也转换成数组
  869. $data['choice_id'] = [$data['choice_id']];
  870. }
  871. $data['choice_id'] = array_map('intval', $data['choice_id']);
  872. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  873. ->where('website_id', $data['website_id'])
  874. ->where('is_other', 1)
  875. ->where('other_id', 0)
  876. ->first();
  877. if (!empty($other)) {
  878. return Result::error("请选择已有的选项!", 0);
  879. }
  880. $choice['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. // return Result::success($choice['other']);
  886. $choice_id = $data['choice_id'];
  887. if (!empty($choice['other'])) {
  888. // array_push($data['choice_id'],$choice['other']['other_id']);
  889. if (!empty($choice_id)) {
  890. $key = array_search($choice['other']['id'], $choice_id);
  891. if ($key !== false) {
  892. unset($choice_id[$key]);
  893. $choice_id = array_values($choice_id);
  894. }
  895. array_push($choice_id, $choice['other']['other_id']);
  896. } else {
  897. $choice_id[0] = $choice['other']['other_id'];
  898. }
  899. // return Result::success($data['choice_id']);
  900. }
  901. // return Result::success($data);
  902. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  903. ->where('website_id', $data['website_id'])
  904. ->increment('results', 1);
  905. if (empty($choice)) {
  906. return Result::error("请选择已有的选项!", 0);
  907. }
  908. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  909. ->where('website_id', $data['website_id'])
  910. ->where('other_id', 0)
  911. ->get();
  912. $survey['choice'] = $choice_id;
  913. return Result::success($survey);
  914. }
  915. return Result::error("参数必填!");
  916. }
  917. return Result::error("此调查问卷不存在", 0);
  918. }
  919. return Result::error("参数必填!");
  920. }
  921. /**
  922. * 后端-获取网站调查问卷列表
  923. * @param array $data
  924. * @return array
  925. */
  926. public function getSurveyList(array $data): array
  927. {
  928. $where = [];
  929. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  930. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  931. }
  932. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  933. array_push($where, ['survey_type', '=', $data['survey_type']]);
  934. }
  935. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  936. array_push($where, ['is_survey', '=', $data['is_survey']]);
  937. }
  938. // return Result::success($where);
  939. if (!empty($where)) {
  940. $query = Article::where($where)->where(function ($q) {
  941. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  942. });
  943. } else {
  944. $query = Article::where(function ($q) {
  945. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  946. });
  947. }
  948. $count = $query->count();
  949. $survey = $query->orderByDesc('id')
  950. ->limit($data['pageSize'])
  951. ->offset(($data['page'] - 1) * $data['pageSize'])
  952. ->get();
  953. if (empty($survey->toArray())) {
  954. return Result::error("暂无调查问卷!", 0);
  955. }
  956. $result = [
  957. 'rows' => $survey,
  958. 'count' => $count,
  959. ];
  960. return Result::success($result);
  961. }
  962. /**
  963. * 后端-获取网站调查问卷详情
  964. * @param array $data
  965. * @return array
  966. */
  967. public function getSurveyInfo(array $data): array
  968. {
  969. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  970. $where = ['sur_id' => $data['sur_id']];
  971. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  972. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  973. ->select('article_survey.*', 'article.survey_type')
  974. ->get()->all();
  975. if (empty($choose)) {
  976. return Result::error("此调查问卷不存在", 0);
  977. }
  978. $resultsArray = array_column($choose, 'results');
  979. $total = array_sum($resultsArray);
  980. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  981. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  982. // $total = 0;
  983. if (!empty($other)) {
  984. $total = $total + $other['results'];
  985. $other['choice_name'] = $other['choice_name'] . '(其他)';
  986. if (!empty($others)) {
  987. $other['hasChildren'] = true;
  988. // array_push($other,['hasChildren','=',true]);
  989. $other['children'] = $others;
  990. $other_choices = [$other->toArray()];
  991. $mer_choice = array_merge($choose, $other_choices);
  992. $value_choice = array_values($mer_choice);
  993. } else {
  994. // return Result::error('1111');
  995. $other_choices = [$other->toArray()];
  996. $other_choices = array_merge($choose, $other_choices);
  997. $value_choice = array_values($other_choices);
  998. // return Result::success($result);
  999. }
  1000. } else {
  1001. $value_choice = $choose;
  1002. }
  1003. $result = [
  1004. 'choose' => $value_choice,
  1005. 'total' => $total,
  1006. ];
  1007. }
  1008. return Result::success($result);
  1009. }
  1010. /**
  1011. * 前端-搜索新闻列表
  1012. * @param array $data
  1013. * @return array
  1014. */
  1015. public function selectWebsiteArticle(array $data): array
  1016. {
  1017. $where = [];
  1018. // 初始化查询构造器
  1019. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1020. $query = Article::where('status', 1)
  1021. ->whereIn('catid', $category)
  1022. ->where(function ($query) use ($data) {
  1023. $query->where(function ($subQuery) use ($data) {
  1024. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1025. })->orWhereNull("ignore_ids");
  1026. });
  1027. // return Result::success($all_articles);
  1028. // 检查是否存在 cityid 参数
  1029. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1030. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1031. }
  1032. // 检查是否存在 department_id 参数
  1033. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1034. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1035. }
  1036. // 检查是否存在 keyword 参数
  1037. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1038. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1039. }
  1040. // 计算总数
  1041. $count = $query->count();
  1042. // 分页查询
  1043. $articles = $query->orderBy("updated_at", "desc")
  1044. ->limit($data['pageSize'])
  1045. ->offset(($data['page'] - 1) * $data['pageSize'])
  1046. ->get()->all();
  1047. if (empty($articles)) {
  1048. return Result::error("没有符合条件的资讯数据");
  1049. }
  1050. $data = [
  1051. 'rows' => $articles,
  1052. 'count' => $count,
  1053. ];
  1054. return Result::success($data);
  1055. }
  1056. /**
  1057. * 验证导航名称是否重复
  1058. * @return void
  1059. */
  1060. public function checkCategoryName(array $data): array
  1061. {
  1062. $result = Category::when($data, function ($query) use ($data) {
  1063. if (isset($data['name']) && $data['name']) {
  1064. $query->where("name", $data['name']);
  1065. }
  1066. if (isset($data['id']) && $data['id']) {
  1067. $query->where("id", "!=", $data['id']);
  1068. }
  1069. })->first();
  1070. if ($result) {
  1071. return Result::error("已存在");
  1072. } else {
  1073. return Result::success();
  1074. }
  1075. }
  1076. //20250226 产品列表
  1077. public function getGoodList(array $data): array
  1078. {
  1079. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1080. unset($data['type_id']);
  1081. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1082. $where = [];
  1083. if ($type_id != '10000') {
  1084. $where = [
  1085. 'good.user_id' => $user_id,
  1086. ];
  1087. }
  1088. //类型
  1089. if (isset($data['type_id']) && $data['type_id']) {
  1090. $where = [
  1091. 'type_id' => $data['type_id'],
  1092. ];
  1093. }
  1094. //名称
  1095. if (isset($data['name']) && $data['name']) {
  1096. $where = [
  1097. 'good.name' => $data['name'],
  1098. ];
  1099. }
  1100. $where1 = [];
  1101. //website_id
  1102. // if (isset($data['website_id']) && $data['website_id']) {
  1103. // $where1 = [
  1104. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1105. // ];
  1106. // }
  1107. // website_name
  1108. if (isset($data['website_name']) && $data['website_name']) {
  1109. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1110. }
  1111. // catid
  1112. if (isset($data['category_name']) && $data['category_name']) {
  1113. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1114. }
  1115. // $result = Good::where($where)
  1116. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1117. $result = Good::where($where)
  1118. ->when(!empty($where1), function ($query) use ($where1) {
  1119. return $query->where($where1);
  1120. })
  1121. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1122. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1123. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1124. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1125. ->orderBy("id", "desc")
  1126. ->limit($data['page_size'])
  1127. ->offset(($data['page'] - 1) * $data['page_size'])
  1128. ->get();
  1129. $count = Good::where($where)
  1130. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1131. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1132. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1133. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1134. ->orderBy("updated_at", "desc")->count();
  1135. $data = [
  1136. 'rows' => $result->toArray(),
  1137. 'count' => $count,
  1138. ];
  1139. if (empty($result)) {
  1140. return Result::error("此栏目暂无相关产品", 0);
  1141. }
  1142. return Result::success($data);
  1143. }
  1144. public function getGoodInfo(array $data): array
  1145. {
  1146. $result = Good::where('id', $data['id'])->first();
  1147. if (empty($result)) {
  1148. return Result::error("此产品不存在", 0);
  1149. }
  1150. return Result::success($result);
  1151. }
  1152. public function addGood(array $data): array
  1153. {
  1154. // unset($data['city_arr_id']);
  1155. // unset($data['cat_arr_id']);
  1156. $data['city_id'] = end($data['city_arr_id']);
  1157. $data['catid'] = end($data['cat_arr_id']);
  1158. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1159. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1160. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1161. unset($data['imgUrl']);
  1162. $result = Good::insert($data);
  1163. if (empty($result)) {
  1164. return Result::error("添加失败", 0);
  1165. }
  1166. return Result::success($result);
  1167. }
  1168. public function updateGood(array $data): array
  1169. {
  1170. $data['city_id'] = end($data['city_arr_id']);
  1171. $data['catid'] = end($data['cat_arr_id']);
  1172. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1173. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1174. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1175. //设置东八区
  1176. date_default_timezone_set('Asia/Shanghai');
  1177. $data['updated_at'] = date('Y-m-d H:i:s');
  1178. $result = Good::where('id', $data['id'])->update($data);
  1179. if (empty($result)) {
  1180. return Result::error("更新失败", 0);
  1181. }
  1182. return Result::success($result);
  1183. }
  1184. public function delGood(array $data): array
  1185. {
  1186. $result = Good::where('id', $data['id'])->delete();
  1187. if (empty($result)) {
  1188. return Result::error("删除失败", 0);
  1189. }
  1190. return Result::success($result);
  1191. }
  1192. //20250226 产品列表
  1193. //20250306 求职信息
  1194. public function getJobHuntingList(array $data): array
  1195. {
  1196. $where = [];
  1197. if (isset($data['username']) && !empty($data['username'])) {
  1198. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1199. }
  1200. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1201. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1202. unset($data['type_id']);
  1203. if ($type_id != '10000') {
  1204. $where[] = ['job_hunting.user_id', '=', $user_id];
  1205. }
  1206. $result = JobHunting::where($where)
  1207. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1208. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1209. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1210. ->orderBy("id", "desc")
  1211. ->limit($data['page_size'])
  1212. ->offset(($data['page'] - 1) * $data['page_size'])
  1213. ->get();
  1214. if (empty($result)) {
  1215. return Result::error("查询失败", 0);
  1216. }
  1217. $count = JobHunting::where($where)
  1218. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1219. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1220. ->count();
  1221. $data = [
  1222. 'rows' => $result->toArray(),
  1223. 'count' => $count,
  1224. ];
  1225. return Result::success($data);
  1226. }
  1227. public function addJobHunting(array $data): array
  1228. {
  1229. date_default_timezone_set('Asia/Shanghai');
  1230. unset($data['company_name']);
  1231. unset($data['job_industry']);
  1232. unset($data['job_name']);
  1233. unset($data['department']);
  1234. unset($data['job_timeList']);
  1235. unset($data['job_content']);
  1236. $data['created_at'] = date('Y-m-d H:i:s');
  1237. $data['updated_at'] = date('Y-m-d H:i:s');
  1238. var_dump($data, '-----------------test---------');
  1239. $result = JobHunting::create($data);
  1240. if (empty($result)) {
  1241. return Result::error("添加失败", 0);
  1242. }
  1243. return Result::success($result);
  1244. }
  1245. public function delJobHunting(array $data): array
  1246. {
  1247. $result = JobHunting::where('id', $data['id'])->delete();
  1248. if (empty($result)) {
  1249. return Result::error("删除失败", 0);
  1250. }
  1251. return Result::success($result);
  1252. }
  1253. public function updateJobHunting(array $data): array
  1254. {
  1255. //设置东八区
  1256. date_default_timezone_set('Asia/Shanghai');
  1257. unset($data['company_name']);
  1258. unset($data['job_industry']);
  1259. unset($data['job_name']);
  1260. unset($data['department']);
  1261. unset($data['job_timeList']);
  1262. unset($data['job_content']);
  1263. $data['created_at'] = date('Y-m-d H:i:s');
  1264. $data['updated_at'] = date('Y-m-d H:i:s');
  1265. $result = JobHunting::where('id', $data['id'])->update($data);
  1266. if (empty($result)) {
  1267. return Result::error("更新失败", 0);
  1268. }
  1269. return Result::success($result);
  1270. }
  1271. public function getJobHuntingInfo(array $data): array
  1272. {
  1273. $result = JobHunting::where('id', $data['id'])->first();
  1274. if (empty($result)) {
  1275. return Result::error("查询失败", 0);
  1276. }
  1277. return Result::success($result);
  1278. }
  1279. public function getJobHuntingData(array $data): array
  1280. {
  1281. $jobEnum = JobEnum::get();
  1282. $jobIndustry = JobIndustry::get();
  1283. $jobNature = JobNature::get();
  1284. $jobPosition = JobPosition::get();
  1285. $data = [
  1286. 'jobEnum' => $jobEnum,
  1287. 'jobIndustry' => $jobIndustry,
  1288. 'jobNature' => $jobNature,
  1289. 'jobPosition' => $jobPosition,
  1290. ];
  1291. return Result::success($data);
  1292. }
  1293. public function delJobHuntingInfo(array $data): array
  1294. {
  1295. $result = JobHunting::where('id', $data['id'])->delete();
  1296. return Result::success();
  1297. }
  1298. }