NewsService.php 62 KB

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