NewsService.php 54 KB

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