NewsService.php 62 KB

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