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