NewsService.php 61 KB

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