NewsService.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  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\WebsiteCategory;
  7. use App\Model\ArticleSurvey;
  8. use App\Model\jobHunting;
  9. use App\Model\JobEnum;
  10. use App\Model\JobIndustry;
  11. use App\Model\JobPosition;
  12. use App\Model\JobRecruiting;
  13. use App\Model\Good;
  14. use App\Model\JobNature;
  15. use App\Model\Website;
  16. use Hyperf\DbConnection\Db;
  17. use Hyperf\RpcServer\Annotation\RpcService;
  18. use App\Tools\Result;
  19. use Ramsey\Uuid\Uuid;
  20. use Hyperf\Utils\Random;
  21. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  22. class NewsService implements NewsServiceInterface
  23. {
  24. /**
  25. * 获取导航池列表
  26. * @param array $data
  27. * @return array
  28. */
  29. public function getCategoryList(array $data): array
  30. {
  31. $where = [];
  32. if (isset($data['name']) && $data['name']) {
  33. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  34. }
  35. if (isset($data['department_id']) && $data['department_id']) {
  36. array_push($where, ['category.department_id', '=', $data['department_id']]);
  37. }
  38. $city_id = '';
  39. if (isset($data['city_id']) && $data['city_id']) {
  40. $city_id = intval($data['city_id']);
  41. }
  42. $rep = Category::where($where)
  43. ->when($city_id, function ($query) use ($city_id) {
  44. if (isset($city_id) && $city_id) {
  45. $query->whereJsonContains("category.city_arr_id", $city_id);
  46. }
  47. })
  48. ->leftJoin('district', 'category.city_id', 'district.id')
  49. ->leftJoin('department', 'category.department_id', 'department.id')
  50. ->leftJoin('category as c', 'category.pid', 'c.id')
  51. ->select("category.*", "district.name as city_name", "department.name as department_name", "c.name as parent_name")
  52. ->limit($data['pageSize'])->orderByDesc('category.updated_at')->offset(($data['page'] - 1) * $data['pageSize'])->get();
  53. $count = Category::where($where)->when($city_id, function ($query) use ($city_id) {
  54. if (isset($city_id) && $city_id) {
  55. $query->whereJsonContains("category.city_arr_id", $city_id);
  56. }
  57. })->count();
  58. $data = [
  59. 'rows' => $rep->toArray(),
  60. 'count' => $count,
  61. ];
  62. if (empty($rep->toArray())) {
  63. return Result::error("没有导航池数据");
  64. }
  65. return Result::success($data);
  66. }
  67. public function myCategoryList(array $data): array
  68. {
  69. $sszq = $data['sszq'] ?? '';
  70. unset($data['sszq']);
  71. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  72. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  73. $where[] = [
  74. 'pid', '=', $data['pid'],
  75. ];
  76. if (isset($data['name'])) {
  77. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  78. }
  79. var_dump($where);
  80. //根据分类id,从category表中取出分类信息
  81. $result = Category::where($where)
  82. ->whereIn('category.id', $catorytids)
  83. ->select('category.*', 'category.id as category_id')->get();
  84. if (empty($result)) {
  85. return Result::error("没有栏目数据");
  86. }
  87. return Result::success($result);
  88. }
  89. /**
  90. * @param array $data
  91. * @return array
  92. */
  93. public function categoryList(array $data): array
  94. {
  95. $where[] = [
  96. 'pid', '=', $data['pid'],
  97. ];
  98. if (isset($data['name'])) {
  99. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  100. }
  101. var_dump($where);
  102. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  103. if (empty($result)) {
  104. return Result::error("没有栏目数据");
  105. }
  106. return Result::success($result);
  107. }
  108. /**
  109. * @param array $data
  110. * @return array
  111. */
  112. public function addCategory(array $data): array
  113. {
  114. if (isset($data['id'])) {
  115. unset($data['id']);
  116. }
  117. $id = Category::insertGetId($data);
  118. if (empty($id)) {
  119. return Result::error("添加失败");
  120. }
  121. return Result::success(['id' => $id]);
  122. }
  123. /**
  124. * @param array $data
  125. * @return array
  126. */
  127. public function delCategory(array $data): array
  128. {
  129. $categoryList = Category::where(['pid' => $data['id']])->get();
  130. var_dump("分类列表:", $data, $categoryList);
  131. if ($categoryList->toArray()) {
  132. return Result::error("分类下面有子分类不能删除");
  133. }
  134. $articleList = Article::where(['catid' => $data['id']])->get();
  135. var_dump("文章列表:", $articleList);
  136. if ($articleList->toArray()) {
  137. return Result::error("分类下面有资讯不能删除");
  138. }
  139. $result = Category::where($data)->delete();
  140. if (!$result) {
  141. return Result::error("删除失败");
  142. }
  143. return Result::success($result);
  144. }
  145. /**
  146. * @param array $data
  147. * @return array
  148. */
  149. public function updateCategory(array $data): array
  150. {
  151. $where = [
  152. 'id' => $data['id'],
  153. ];
  154. $result = Category::where($where)->update($data);
  155. if ($result) {
  156. return Result::success($result);
  157. } else {
  158. return Result::error("更新失败");
  159. }
  160. }
  161. /**
  162. * 获取导航池信息
  163. * @param array $data
  164. * @return array
  165. */
  166. public function getCategoryInfo(array $data): array
  167. {
  168. $where = [
  169. 'id' => $data['id'],
  170. ];
  171. $result = Category::where($where)->first();
  172. if ($result) {
  173. return Result::success($result);
  174. } else {
  175. return Result::error("更新失败");
  176. }
  177. }
  178. /**
  179. * @param array $data
  180. * @return array
  181. */
  182. public function getArticleList(array $data): array
  183. {
  184. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  185. $type_id = $data['type_id'];
  186. unset($data['type_id']);
  187. $user_id = $data['user_id'];
  188. unset($data['user_id']);
  189. $where = [];
  190. $status1 = [];
  191. if (isset($data['title']) && $data['title']) {
  192. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  193. }
  194. if (isset($data['category_name']) && $data['category_name']) {
  195. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  196. }
  197. if (isset($data['author']) && $data['author']) {
  198. array_push($where, ['article.author', '=', $data['author']]);
  199. }
  200. if (isset($data['islink']) && $data['islink'] !== "") {
  201. array_push($where, ['article.islink', '=', $data['islink']]);
  202. }
  203. if (isset($data['status']) && $data['status'] !== "") {
  204. array_push($where, ['article.status', '=', $data['status']]);
  205. }
  206. if (isset($data['status1'])) {
  207. $status1 = json_decode(($data['status1']));
  208. }
  209. //不是管理员展示个人数据;
  210. if ($type_id != 10000) {
  211. $where[] = ['article.admin_user_id', '=', $user_id];
  212. }
  213. $rep = Article::where($where)
  214. ->whereNotIn('article.status', [404])
  215. ->when($status1, function ($query) use ($status1) {
  216. if (isset($status1) && $status1) {
  217. $query->whereIn('article.status', $status1);
  218. }
  219. })
  220. ->leftJoin('category', 'article.catid', 'category.id')
  221. ->select("article.*", "category.name as category_name")
  222. ->orderBy("article.updated_at", "desc")
  223. ->limit($data['pageSize'])
  224. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  225. $count = Article::where($where)->whereNotIn('article.status', [404])
  226. ->when($status1, function ($query) use ($status1) {
  227. if (isset($status1) && $status1) {
  228. $query->whereIn('article.status', $status1);
  229. }
  230. })
  231. ->leftJoin('category', 'article.catid', 'category.id')->count();
  232. $data = [
  233. 'rows' => $rep->toArray(),
  234. 'count' => $count,
  235. ];
  236. if (empty($rep)) {
  237. return Result::error("没有信息数据");
  238. }
  239. return Result::success($data);
  240. }
  241. /**
  242. * @param array $data
  243. * @return array
  244. */
  245. public function addArticle(array $data): array
  246. {
  247. var_dump($data, '----------12-----------1');
  248. unset($data['user_type']);
  249. unset($data['nav_add_pool_id']);
  250. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  251. Db::beginTransaction();
  252. try {
  253. //处理投票
  254. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  255. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  256. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  257. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  258. unset($data['is_survey']);
  259. unset($data['survey_name']);
  260. unset($data['suvey_array']);
  261. // unset($data['website_id']);
  262. // unset($data['web_site_id']);
  263. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  264. if ($data['hits'] == '') {
  265. $data['hits'] = 0;
  266. }
  267. if ($data['is_original'] == '') {
  268. $data['is_original'] = 0;
  269. }
  270. if ($data['status'] == '') {
  271. $data['status'] = 0;
  272. }
  273. $articleData = $data;
  274. unset($articleData['content']);
  275. //自动处理缩略图、关键字、描述
  276. if ($articleData['imgurl'] == '') {
  277. //如果没有图,设置level=0
  278. $articleData['level'] = '[0]';
  279. //content中提取图片第一个图,正则提取
  280. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  281. preg_match_all($reg, $data['content'], $matches);
  282. if (isset($matches[1][0])) {
  283. $articleData['imgurl'] = $matches[1][0];
  284. //如果有图,设置level=3
  285. $articleData['level'] = '[3]';
  286. }
  287. }
  288. if ($articleData['keyword'] == '') {
  289. //提取标题+内容中的关键词
  290. $articleData['keyword'] = $data['title'] . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  291. }
  292. if ($articleData['introduce'] == '') {
  293. //提取内容中的描述
  294. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  295. }
  296. $id = Article::insertGetId($articleData);
  297. $articleDataContent = [
  298. 'article_id' => $id,
  299. 'content' => $data['content'],
  300. ];
  301. ArticleData::insertGetId($articleDataContent);
  302. //处理投票
  303. if ($is_survey == 1) {
  304. //生成年月日时分秒+8位随机数
  305. $uuid = date('YmdHis') . rand(10000000, 99999999);
  306. var_dump($suvey_array, 'suvey_array________');
  307. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  308. var_dump($suveys_array, '---------------------1');
  309. var_dump($suvey_array, '---------------------2');
  310. $suvey_data = [];
  311. foreach ($suveys_array as $key => $value) {
  312. if ($value == '') {
  313. continue;
  314. }
  315. if (is_array($value)) {
  316. $suvey_data[] = [
  317. 'sur_id' => $uuid,
  318. 'art_id' => $id,
  319. 'website_id' => $website_id ?? 2,
  320. 'survey_name' => $survey_name,
  321. 'choice_name' => $value[1],
  322. 'is_other' => 1,
  323. 'other_id' => 0,
  324. 'results' => 0,
  325. ];
  326. } else {
  327. $suvey_data[] = [
  328. 'sur_id' => $uuid,
  329. 'art_id' => $id,
  330. 'website_id' => $website_id ?? 2,
  331. 'survey_name' => $survey_name,
  332. 'choice_name' => $value,
  333. 'is_other' => 0,
  334. 'other_id' => 0,
  335. 'results' => 0,
  336. ];
  337. }
  338. if (empty($suvey_data)) {
  339. throw new \Exception("投票数据为空");
  340. }
  341. }
  342. $result = ArticleSurvey::insert($suvey_data);
  343. if (!$result) {
  344. throw new \Exception("投票失败,ArticleSurvey插入失败");
  345. }
  346. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  347. if (!$result) {
  348. throw new \Exception("投票失败,更新主表失败");
  349. }
  350. }
  351. Db::commit();
  352. return Result::success(['id' => $id]);
  353. } catch (\Throwable $ex) {
  354. Db::rollBack();
  355. var_dump($ex->getMessage());
  356. return Result::error("创建失败", 0);
  357. }
  358. }
  359. /**
  360. * @param array $data
  361. * @return array
  362. */
  363. public function delArticle(array $data): array
  364. {
  365. $result = Article::where($data)->delete();
  366. //survey投票删除
  367. articleSurvey::where(['art_id' => $data['id']])->delete();
  368. if (!$result) {
  369. return Result::error("删除失败");
  370. }
  371. return Result::success($result);
  372. }
  373. /**
  374. * @param array $data
  375. * @return array
  376. */
  377. public function updateArticle(array $data): array
  378. {
  379. var_dump($data, '----------12-----------1');
  380. Db::beginTransaction();
  381. unset($data['user_type']);
  382. // unset($data['web_site_id']);
  383. unset($data['nav_add_pool_id']);
  384. try {
  385. //处理投票
  386. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  387. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  388. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  389. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  390. unset($data['is_survey']);
  391. unset($data['survey_name']);
  392. unset($data['suvey_array']);
  393. unset($data['website_id']);
  394. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  395. if ($data['hits'] == '') {
  396. $data['hits'] = 0;
  397. }
  398. if ($data['is_original'] == '') {
  399. $data['is_original'] = 0;
  400. }
  401. if ($data['status'] == '') {
  402. $data['status'] = 0;
  403. }
  404. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  405. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  406. $articleData = $data;
  407. unset($articleData['content']);
  408. unset($articleData['status_name']);
  409. unset($articleData['name']);
  410. unset($articleData['content']);
  411. unset($articleData['pid_arr']);
  412. unset($articleData['pid']);
  413. //自动处理缩略图、关键字、描述
  414. if ($articleData['imgurl'] == '') {
  415. //如果没有图,设置level=0
  416. $articleData['level'] = '[0]';
  417. //content中提取图片第一个图,正则提取
  418. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  419. preg_match_all($reg, $data['content'], $matches);
  420. if (isset($matches[1][0])) {
  421. $articleData['imgurl'] = $matches[1][0];
  422. //如果有图,设置level=3
  423. $articleData['level'] = '[3]';
  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. * @param array $data
  519. * @return array
  520. */
  521. public function getArticleInfo(array $data): array
  522. {
  523. $where = [
  524. 'article.id' => $data['id'],
  525. // 'article.status' => 1,
  526. ];
  527. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  528. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  529. $info = $result;
  530. // var_dump($info, 'info');
  531. $info['survey_array'] = $articleSurvey;
  532. if ($result) {
  533. return Result::success($info);
  534. } else {
  535. return Result::error("查询失败", 0);
  536. }
  537. }
  538. /**
  539. * 获取新闻
  540. * @param array $data
  541. * @return array
  542. */
  543. public function getWebsiteArticlett(array $data): array
  544. {
  545. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  546. $result = [];
  547. if ($category) {
  548. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  549. $where = [
  550. 'status' => 1,
  551. ];
  552. var_dump($data, 'data-----------------');
  553. //如果是4:热点资讯 5:资讯推荐;
  554. var_dump($where, 'where-----------------');
  555. $result = Article::where($where)
  556. ->whereIn("catid", $category)
  557. ->where(function ($query) use ($data) {
  558. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  559. ->orWhereNull("ignore_ids");
  560. })
  561. //$data['level'] == 4 || $data['level'] == 5 查询随机
  562. ->when($data['level'] == 5, function ($query) {
  563. $query->inRandomOrder()
  564. //updated_at最近三十天;
  565. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  566. })
  567. ->when($data['level'] != 5, function ($query) {
  568. $query->orderBy("updated_at", "desc");
  569. })
  570. ->when(!empty($data['level']), function ($query) use ($data) {
  571. if ($data['level'] != 4 && $data['level'] != 5) {
  572. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  573. ->orWhereNull("level");
  574. }
  575. })
  576. ->offset($placeid)
  577. ->limit($data['pageSize'])
  578. ->get();
  579. if (empty($result)) {
  580. return Result::error("暂无头条新闻", 0);
  581. }
  582. return Result::success($result);
  583. } else {
  584. return Result::error("本网站下暂无相关栏目", 0);
  585. }
  586. }
  587. /**
  588. * 获取模块新闻
  589. * @param array $data
  590. * @return array
  591. */
  592. public function getWebsiteModelArticles(array $data): array
  593. {
  594. $catid = $data['catid'];
  595. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  596. $category = $category->toArray();
  597. if (!empty($category)) {
  598. $where = [
  599. 'status' => 1,
  600. 'catid' => $catid,
  601. ];
  602. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  603. // 级别:0:未分类 1:头条 2:轮播图 3:推荐图 4:热点资讯 5:资讯推荐
  604. if ($data['level'] == 1) {
  605. $result = Article::where($where)
  606. ->where(function ($query) use ($data) {
  607. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  608. ->orWhereNull("level")
  609. ->orWhereRaw("level = '[]'");
  610. })
  611. ->where(function ($query) use ($data) {
  612. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  613. ->orWhereNull("ignore_ids");
  614. })
  615. ->orderBy("updated_at", "desc")
  616. ->offset($placeid)
  617. ->limit($data['pagesize'])
  618. ->get();
  619. } elseif ($data['level'] == 2) {
  620. $level = '2';
  621. $result = Article::where($where)
  622. ->where(function ($query) use ($data) {
  623. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  624. ->orWhereNull("level")
  625. ->orWhereRaw("level = '[]'");
  626. })
  627. ->where(function ($query) use ($data) {
  628. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  629. ->orWhereNull("ignore_ids");
  630. })
  631. ->orderBy("updated_at", "desc")
  632. ->offset($placeid)
  633. ->limit($data['pagesize'])
  634. ->get();
  635. } else {
  636. $level = '3';
  637. $result = Article::where($where)
  638. ->where(function ($query) use ($data) {
  639. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  640. ->orWhereNull("level")
  641. ->orWhereRaw("level = '[]'");
  642. })
  643. ->where(function ($query) use ($data) {
  644. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  645. ->orWhereNull("ignore_ids");
  646. })
  647. ->orderBy("updated_at", "desc")
  648. ->offset($placeid)
  649. ->limit($data['pagesize'])
  650. ->get();
  651. }
  652. if (empty($result)) {
  653. return Result::error("此栏目暂无相关新闻", 0);
  654. }
  655. } else {
  656. return Result::error("此网站暂无此栏目", 0);
  657. }
  658. return Result::success($result);
  659. }
  660. /**
  661. *获取新闻列表
  662. * @param array $data
  663. * @return array
  664. */
  665. public function getWebsiteArticleList(array $data): array
  666. {
  667. $where[] = ['status', '=', 1];
  668. if (isset($data['keyword']) && !empty($data['keyword'])) {
  669. array_push($where, ['article.title', 'like', '%' . $data['keyword'] . '%']);
  670. }
  671. if (isset($data['catid']) && !empty($data['catid'])) {
  672. if (is_array($data['catid'])) {
  673. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  674. array_push($where, ['catid', 'in', $data['catid']]);
  675. } else {
  676. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  677. array_push($where, ['catid', '=', $data['catid']]);
  678. }
  679. if (empty($category)) {
  680. return Result::error("此网站暂无此栏目", 0);
  681. }
  682. }
  683. // return Result::success($where);
  684. $rep = Article::where(function ($query) use ($where) {
  685. foreach ($where as $condition) {
  686. if ($condition[1] === 'in') {
  687. $query->whereIn($condition[0], $condition[2]);
  688. } else {
  689. $query->where($condition[0], $condition[1], $condition[2]);
  690. }
  691. }
  692. })
  693. ->where(function ($query) use ($data) {
  694. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  695. ->orWhereNull("ignore_ids");
  696. })
  697. ->orderBy("updated_at", "desc")
  698. ->limit($data['pageSize'])
  699. ->offset(($data['page'] - 1) * $data['pageSize'])
  700. ->get();
  701. $count = Article::where(function ($query) use ($where) {
  702. foreach ($where as $condition) {
  703. if ($condition[1] === 'in') {
  704. $query->whereIn($condition[0], $condition[2]);
  705. } else {
  706. $query->where($condition[0], $condition[1], $condition[2]);
  707. }
  708. }
  709. })->count();
  710. $data = [
  711. 'rows' => $rep->toArray(),
  712. 'count' => $count,
  713. ];
  714. if (empty($rep)) {
  715. return Result::error("没有信息数据");
  716. }
  717. return Result::success($data);
  718. }
  719. /**
  720. * 前端-获取新闻详情
  721. * @param array $data
  722. * @return array
  723. */
  724. public function selectWebsiteArticleInfo(array $data): array
  725. {
  726. $where = [
  727. 'article.id' => $data['id'],
  728. 'article.status' => 1,
  729. ];
  730. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
  731. ->where(function ($query) use ($data) {
  732. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  733. ->orWhereNull("ignore_ids");
  734. })
  735. ->first();
  736. if (empty($result)) {
  737. return Result::error("暂无此新闻!", 0);
  738. }
  739. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  740. ->select('website_category.*', 'website.website_name', 'website.suffix')
  741. ->where('website_category.website_id', $data['website_id'])
  742. ->where(['website_category.category_id' => $result['catid']])
  743. ->first();
  744. if (empty($category)) {
  745. return Result::error("查询失败", 0);
  746. }
  747. $result['category_id'] = $category['category_id'];
  748. $result['cat_name'] = $category['alias'];
  749. $result['website_name'] = $category['website_name'] ?? "";
  750. $result['suffix'] = $category['suffix'] ?? "";
  751. return Result::success($result);
  752. }
  753. /**
  754. * 前端-获取网站调查问卷
  755. * @param array $data
  756. * @return array
  757. */
  758. public function getWebsiteSurvey(array $data): array
  759. {
  760. if (isset($data['website_id']) && !empty($data['website_id'])) {
  761. $website = Website::where('id', $data['website_id'])->first();
  762. if (empty($website)) {
  763. return Result::error("暂无此网站", 0);
  764. }
  765. }
  766. if (isset($data['art_id']) && !empty($data['art_id'])) {
  767. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  768. if (empty($article)) {
  769. return Result::error("暂无此文章", 0);
  770. }
  771. // return Result::error($data,0);
  772. $where['art_id'] = $data['art_id'];
  773. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  774. } else {
  775. $survey = ArticleSurvey::where('website_id', $data['website_id'])->orderBy('created_at')->first();
  776. if (empty($survey)) {
  777. return Result::error("暂无调查问卷", 0);
  778. }
  779. $where['sur_id'] = $survey['sur_id'];
  780. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  781. }
  782. $result['survey'] = ArticleSurvey::where($where)->where('is_other', 0)
  783. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  784. ->select('article_survey.*', 'article.survey_type')
  785. ->get()->all();
  786. $result['other'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  787. $result['others'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->first();
  788. if (empty($result)) {
  789. return Result::error("此文章暂无调查问卷", 0);
  790. }
  791. return Result::success($result);
  792. }
  793. /**
  794. * 前端-添加网站调查问卷选项
  795. * @param array $data
  796. * @return array
  797. */
  798. public function addWebsiteSurveyOption(array $data): array
  799. {
  800. if (isset($data['website_id']) && !empty($data['website_id'])) {
  801. $website = Website::where('id', $data['website_id'])->first();
  802. if (empty($website)) {
  803. return Result::error("暂无此网站", 0);
  804. }
  805. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  806. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  807. if (empty($survey)) {
  808. return Result::error("此调查问卷不可添加选项", 0);
  809. }
  810. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  811. $choice = [
  812. 'art_id' => $survey['art_id'],
  813. 'website_id' => $data['website_id'],
  814. 'survey_name' => $survey['survey_name'],
  815. 'choice_name' => $data['choice_name'],
  816. 'sur_id' => $survey['sur_id'],
  817. 'is_other' => 1,
  818. 'other_id' => $survey['id'],
  819. ];
  820. $result = ArticleSurvey::insertGetId($choice);
  821. if (empty($result)) {
  822. return Result::error("添加失败", 0);
  823. }
  824. return Result::success($result);
  825. }
  826. }
  827. return Result::error("添加失败", 0);
  828. }
  829. return Result::error("添加失败", 0);
  830. }
  831. /**
  832. * 前端-调查问卷投票
  833. * @param array $data
  834. * @return array
  835. */
  836. public function addWebsiteSurveyVote(array $data): array
  837. {
  838. if (isset($data['website_id']) && !empty($data['website_id'])) {
  839. $website = Website::where('id', $data['website_id'])->first();
  840. if (empty($website)) {
  841. return Result::error("暂无此网站", 0);
  842. }
  843. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  844. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->pluck('sur_id');
  845. if (empty($survey)) {
  846. return Result::error("此调查问卷不存在", 0);
  847. }
  848. // return Result::success($survey);
  849. // 调查问卷类型 0:单选 1:多选
  850. $type = Article::where('survey_id', $data['sur_id'])->pluck('survey_type');
  851. // return Result::success($type);
  852. if (empty($type) || ($type[0] != 1 && $type[0] != 0)) {
  853. return Result::error("此调查问卷不可投票", 0);
  854. }
  855. // return Result::success($type[0]);
  856. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  857. if ($type[0] == 0) {
  858. if (is_array($data['choice_id'])) {
  859. return Result::error("请选择一个选项!", 0);
  860. }
  861. $data['choice_id'] = [$data['choice_id']];
  862. } else {
  863. if (!is_array($data['choice_id'])) {
  864. return Result::error("请传递数组!", 0);
  865. }
  866. }
  867. // return Result::success($data['choice_id']);
  868. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  869. ->where('website_id', $data['website_id'])
  870. ->where('is_other', 1)
  871. ->where('other_id', 0)
  872. ->first();
  873. if (!empty($other)) {
  874. return Result::error("请选择已有的选项!", 0);
  875. }
  876. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  877. ->where('website_id', $data['website_id'])
  878. ->where('is_other', 1)
  879. ->where('other_id', '!=', 0)
  880. ->first();
  881. // return Result::success($data);
  882. if (!empty($choice['other'])) {
  883. array_push($data['choice_id'], $choice['other']['other_id']);
  884. // return Result::success($data['choice_id']);
  885. }
  886. // return Result::success($data);
  887. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  888. ->where('website_id', $data['website_id'])
  889. ->increment('results', 1);
  890. if (empty($choice)) {
  891. return Result::error("请选择已有的选项!", 0);
  892. }
  893. $retult_survey = ArticleSurvey::where('website_id', $data['website_id'])
  894. ->where('sur_id', $data['sur_id'])
  895. ->get();
  896. return Result::success($retult_survey);
  897. }
  898. return Result::error("参数必填!");
  899. // if(isset($data['choice_id']) && !empty($data['choice_id'])){
  900. // $choice = ArticleSurvey::whereIn('id',$data['choice_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
  901. // }
  902. }
  903. return Result::error("此调查问卷不存在", 0);
  904. }
  905. return Result::error("参数必填!");
  906. }
  907. /**
  908. * 后端-获取网站调查问卷列表
  909. * @param array $data
  910. * @return array
  911. */
  912. public function getSurveyList(array $data): array
  913. {
  914. $where = [];
  915. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  916. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  917. }
  918. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  919. array_push($where, ['survey_type', '=', $data['survey_type']]);
  920. }
  921. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  922. array_push($where, ['is_survey', '=', $data['is_survey']]);
  923. }
  924. // return Result::success($where);
  925. if (!empty($where)) {
  926. $query = Article::where($where)->where(function ($q) {
  927. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  928. });
  929. } else {
  930. $query = Article::where(function ($q) {
  931. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  932. });
  933. }
  934. $count = $query->count();
  935. $survey = $query->orderByDesc('id')
  936. ->limit($data['pageSize'])
  937. ->offset(($data['page'] - 1) * $data['pageSize'])
  938. ->get();
  939. if (empty($survey->toArray())) {
  940. return Result::error("暂无调查问卷!", 0);
  941. }
  942. $result = [
  943. 'rows' => $survey,
  944. 'count' => $count,
  945. ];
  946. return Result::success($result);
  947. }
  948. /**
  949. * 后端-获取网站调查问卷详情
  950. * @param array $data
  951. * @return array
  952. */
  953. public function getSurveyInfo(array $data): array
  954. {
  955. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  956. $where = ['sur_id' => $data['sur_id']];
  957. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  958. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  959. ->select('article_survey.*', 'article.survey_type')
  960. ->get()->all();
  961. if (empty($choose)) {
  962. return Result::error("此调查问卷不存在", 0);
  963. }
  964. $resultsArray = array_column($choose, 'results');
  965. $total = array_sum($resultsArray);
  966. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  967. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  968. // $total = 0;
  969. if (!empty($other)) {
  970. $total = $total + $other['results'];
  971. $other['choice_name'] = $other['choice_name'] . '(其他)';
  972. if (!empty($others)) {
  973. $other['hasChildren'] = true;
  974. // array_push($other,['hasChildren','=',true]);
  975. $other['children'] = $others;
  976. $other_choices = [$other->toArray()];
  977. $mer_choice = array_merge($choose, $other_choices);
  978. $value_choice = array_values($mer_choice);
  979. } else {
  980. // return Result::error('1111');
  981. $other_choices = [$other->toArray()];
  982. $other_choices = array_merge($choose, $other_choices);
  983. $value_choice = array_values($other_choices);
  984. // return Result::success($result);
  985. }
  986. } else {
  987. $value_choice = $choose;
  988. }
  989. $result = [
  990. 'choose' => $value_choice,
  991. 'total' => $total,
  992. ];
  993. }
  994. return Result::success($result);
  995. }
  996. /**
  997. * 前端-搜索新闻列表
  998. * @param array $data
  999. * @return array
  1000. */
  1001. public function selectWebsiteArticle(array $data): array
  1002. {
  1003. $where = [];
  1004. // 初始化查询构造器
  1005. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1006. $query = Article::where('status', 1)
  1007. ->whereIn('catid', $category)
  1008. ->where(function ($query) use ($data) {
  1009. $query->where(function ($subQuery) use ($data) {
  1010. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1011. })->orWhereNull("ignore_ids");
  1012. });
  1013. // return Result::success($all_articles);
  1014. // 检查是否存在 cityid 参数
  1015. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1016. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1017. }
  1018. // 检查是否存在 department_id 参数
  1019. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1020. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1021. }
  1022. // 检查是否存在 keyword 参数
  1023. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1024. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1025. }
  1026. // 计算总数
  1027. $count = $query->count();
  1028. // 分页查询
  1029. $articles = $query->orderBy("updated_at", "desc")
  1030. ->limit($data['pageSize'])
  1031. ->offset(($data['page'] - 1) * $data['pageSize'])
  1032. ->get()->all();
  1033. if (empty($articles)) {
  1034. return Result::error("没有符合条件的资讯数据");
  1035. }
  1036. $data = [
  1037. 'rows' => $articles,
  1038. 'count' => $count,
  1039. ];
  1040. return Result::success($data);
  1041. }
  1042. /**
  1043. * 验证导航名称是否重复
  1044. * @return void
  1045. */
  1046. public function checkCategoryName(array $data): array
  1047. {
  1048. $result = Category::when($data, function ($query) use ($data) {
  1049. if (isset($data['name']) && $data['name']) {
  1050. $query->where("name", $data['name']);
  1051. }
  1052. if (isset($data['id']) && $data['id']) {
  1053. $query->where("id", "!=", $data['id']);
  1054. }
  1055. })->first();
  1056. if ($result) {
  1057. return Result::error("已存在");
  1058. } else {
  1059. return Result::success();
  1060. }
  1061. }
  1062. //20250226 产品列表
  1063. public function getGoodList(array $data): array
  1064. {
  1065. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1066. unset($data['type_id']);
  1067. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1068. $where = [];
  1069. if ($type_id != '10000') {
  1070. $where = [
  1071. 'good.user_id' => $user_id,
  1072. ];
  1073. }
  1074. //类型
  1075. if (isset($data['type_id']) && $data['type_id']) {
  1076. $where = [
  1077. 'type_id' => $data['type_id'],
  1078. ];
  1079. }
  1080. //名称
  1081. if (isset($data['name']) && $data['name']) {
  1082. $where = [
  1083. 'good.name' => $data['name'],
  1084. ];
  1085. }
  1086. $where1 = [];
  1087. //website_id
  1088. // if (isset($data['website_id']) && $data['website_id']) {
  1089. // $where1 = [
  1090. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1091. // ];
  1092. // }
  1093. // website_name
  1094. if (isset($data['website_name']) && $data['website_name']) {
  1095. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1096. }
  1097. // catid
  1098. if (isset($data['category_name']) && $data['category_name']) {
  1099. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1100. }
  1101. // $result = Good::where($where)
  1102. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1103. $result = Good::where($where)
  1104. ->when(!empty($where1), function ($query) use ($where1) {
  1105. return $query->where($where1);
  1106. })
  1107. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1108. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1109. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1110. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1111. ->orderBy("id", "desc")
  1112. ->limit($data['page_size'])
  1113. ->offset(($data['page'] - 1) * $data['page_size'])
  1114. ->get();
  1115. $count = Good::where($where)
  1116. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1117. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1118. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1119. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1120. ->orderBy("updated_at", "desc")->count();
  1121. $data = [
  1122. 'rows' => $result->toArray(),
  1123. 'count' => $count,
  1124. ];
  1125. if (empty($result)) {
  1126. return Result::error("此栏目暂无相关产品", 0);
  1127. }
  1128. return Result::success($data);
  1129. }
  1130. public function getGoodInfo(array $data): array
  1131. {
  1132. $result = Good::where('id', $data['id'])->first();
  1133. if (empty($result)) {
  1134. return Result::error("此产品不存在", 0);
  1135. }
  1136. return Result::success($result);
  1137. }
  1138. public function addGood(array $data): array
  1139. {
  1140. // unset($data['city_arr_id']);
  1141. // unset($data['cat_arr_id']);
  1142. $data['city_id'] = end($data['city_arr_id']);
  1143. $data['catid'] = end($data['cat_arr_id']);
  1144. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1145. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1146. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1147. unset($data['imgUrl']);
  1148. $result = Good::insert($data);
  1149. if (empty($result)) {
  1150. return Result::error("添加失败", 0);
  1151. }
  1152. return Result::success($result);
  1153. }
  1154. public function updateGood(array $data): array
  1155. {
  1156. $data['city_id'] = end($data['city_arr_id']);
  1157. $data['catid'] = end($data['cat_arr_id']);
  1158. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1159. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1160. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1161. //设置东八区
  1162. date_default_timezone_set('Asia/Shanghai');
  1163. $data['updated_at'] = date('Y-m-d H:i:s');
  1164. $result = Good::where('id', $data['id'])->update($data);
  1165. if (empty($result)) {
  1166. return Result::error("更新失败", 0);
  1167. }
  1168. return Result::success($result);
  1169. }
  1170. public function delGood(array $data): array
  1171. {
  1172. $result = Good::where('id', $data['id'])->delete();
  1173. if (empty($result)) {
  1174. return Result::error("删除失败", 0);
  1175. }
  1176. return Result::success($result);
  1177. }
  1178. //20250226 产品列表
  1179. //20250306 求职信息
  1180. public function getJobHuntingList(array $data): array
  1181. {
  1182. $where = [];
  1183. if (isset($data['username']) && !empty($data['username'])) {
  1184. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1185. }
  1186. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1187. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1188. unset($data['type_id']);
  1189. if ($type_id != '10000') {
  1190. $where[] = ['job_hunting.user_id', '=', $user_id];
  1191. }
  1192. $result = JobHunting::where($where)
  1193. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1194. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1195. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1196. ->orderBy("id", "desc")
  1197. ->limit($data['page_size'])
  1198. ->offset(($data['page'] - 1) * $data['page_size'])
  1199. ->get();
  1200. if (empty($result)) {
  1201. return Result::error("查询失败", 0);
  1202. }
  1203. $count = JobHunting::where($where)
  1204. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1205. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1206. ->count();
  1207. $data = [
  1208. 'rows' => $result->toArray(),
  1209. 'count' => $count,
  1210. ];
  1211. return Result::success($data);
  1212. }
  1213. public function addJobHunting(array $data): array
  1214. {
  1215. date_default_timezone_set('Asia/Shanghai');
  1216. unset($data['company_name']);
  1217. unset($data['job_industry']);
  1218. unset($data['job_name']);
  1219. unset($data['department']);
  1220. unset($data['job_timeList']);
  1221. unset($data['job_content']);
  1222. $data['created_at'] = date('Y-m-d H:i:s');
  1223. $data['updated_at'] = date('Y-m-d H:i:s');
  1224. var_dump($data, '-----------------test---------');
  1225. $result = JobHunting::create($data);
  1226. if (empty($result)) {
  1227. return Result::error("添加失败", 0);
  1228. }
  1229. return Result::success($result);
  1230. }
  1231. public function delJobHunting(array $data): array
  1232. {
  1233. $result = JobHunting::where('id', $data['id'])->delete();
  1234. if (empty($result)) {
  1235. return Result::error("删除失败", 0);
  1236. }
  1237. return Result::success($result);
  1238. }
  1239. public function updateJobHunting(array $data): array
  1240. {
  1241. //设置东八区
  1242. date_default_timezone_set('Asia/Shanghai');
  1243. unset($data['company_name']);
  1244. unset($data['job_industry']);
  1245. unset($data['job_name']);
  1246. unset($data['department']);
  1247. unset($data['job_timeList']);
  1248. unset($data['job_content']);
  1249. $data['created_at'] = date('Y-m-d H:i:s');
  1250. $data['updated_at'] = date('Y-m-d H:i:s');
  1251. $result = JobHunting::where('id', $data['id'])->update($data);
  1252. if (empty($result)) {
  1253. return Result::error("更新失败", 0);
  1254. }
  1255. return Result::success($result);
  1256. }
  1257. public function getJobHuntingInfo(array $data): array
  1258. {
  1259. $result = JobHunting::where('id', $data['id'])->first();
  1260. if (empty($result)) {
  1261. return Result::error("查询失败", 0);
  1262. }
  1263. return Result::success($result);
  1264. }
  1265. public function getJobHuntingData(array $data): array
  1266. {
  1267. $jobEnum = JobEnum::get();
  1268. $jobIndustry = JobIndustry::get();
  1269. $jobNature = JobNature::get();
  1270. $jobPosition = JobPosition::get();
  1271. $data = [
  1272. 'jobEnum' => $jobEnum,
  1273. 'jobIndustry' => $jobIndustry,
  1274. 'jobNature' => $jobNature,
  1275. 'jobPosition' => $jobPosition,
  1276. ];
  1277. return Result::success($data);
  1278. }
  1279. public function delJobHuntingInfo(array $data): array
  1280. {
  1281. $result = JobHunting::where('id', $data['id'])->delete();
  1282. return Result::success();
  1283. }
  1284. }