NewsService.php 53 KB

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