NewsService.php 61 KB

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