NewsService.php 64 KB

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