NewsService.php 65 KB

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