NewsService.php 62 KB

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