NewsService.php 61 KB

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