NewsService.php 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\WebsiteCategory;
  7. use App\Model\ArticleSurvey;
  8. use App\Model\jobHunting;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\JobPosition;
  16. use App\Model\JobNature;
  17. use App\Model\JobEnum;
  18. use App\Model\User;
  19. use App\Model\UserRole;
  20. use App\Model\News;
  21. use App\Model\UserInfo;
  22. use App\Model\WebsiteGroup;
  23. ;
  24. use Hyperf\DbConnection\Db;
  25. use Hyperf\RpcServer\Annotation\RpcService;
  26. use App\Tools\Result;
  27. use Directory;
  28. use Ramsey\Uuid\Uuid;
  29. use Hyperf\Utils\Random;
  30. use Fukuball\Jieba\Jieba;
  31. use Fukuball\Jieba\Finalseg;
  32. use App\Model\ChatRecords;
  33. use Hyperf\Utils\Collection;
  34. use function Hyperf\Support\retry;
  35. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  36. class NewsService implements NewsServiceInterface
  37. {
  38. /**
  39. * 获取导航池列表
  40. * @param array $data
  41. * @return array
  42. */
  43. public function getCategoryList(array $data): array
  44. {
  45. $page = (int) $data['page'] ?? 1;
  46. $perPage = (int) $data['pageSize'] ?? 10;
  47. $search = $data['name'] ?? '';
  48. // 查找所有匹配的分类
  49. $matchedCategories = $this->findMatchedCategories($search);
  50. // 查找所有匹配分类的父级分类
  51. $allRequiredCategories = $this->findAllParents($matchedCategories);
  52. // 提取一级分类
  53. $topLevelCategories = [];
  54. foreach ($allRequiredCategories as $category) {
  55. if ($category->pid === 0) {
  56. $topLevelCategories[] = $category;
  57. }
  58. }
  59. // 分页处理
  60. $offset = ($page - 1) * $perPage;
  61. $paginatedTopLevelCategories = array_slice($topLevelCategories, $offset, $perPage);
  62. $categoryTree = [];
  63. foreach ($paginatedTopLevelCategories as $category) {
  64. $categoryTree[] = $this->buildCategoryTree($category, $allRequiredCategories);
  65. }
  66. $return = [
  67. 'rows' => $categoryTree,
  68. 'total' => count($topLevelCategories),
  69. ];
  70. return Result::success($return);
  71. }
  72. private function findMatchedCategories($search)
  73. {
  74. if ($search) {
  75. return Category::where('name', 'like', "%{$search}%")
  76. ->orderBy('updated_at', 'desc')
  77. ->get();
  78. }
  79. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  80. ->get();
  81. }
  82. private function findAllParents($categories)
  83. {
  84. $allCategories = [];
  85. foreach ($categories as $category) {
  86. $parentId = $category->pid;
  87. while ($parentId > 0) {
  88. $parent = Category::find($parentId);
  89. if ($parent) {
  90. $allCategories[$parent->id] = $parent;
  91. $parentId = $parent->pid;
  92. } else {
  93. break;
  94. }
  95. }
  96. $allCategories[$category->id] = $category;
  97. }
  98. return array_values($allCategories);
  99. }
  100. private function buildCategoryTree($category, $allRequiredCategories)
  101. {
  102. $categoryData = $category->toArray();
  103. $children = [];
  104. foreach ($allRequiredCategories as $c) {
  105. if ($c->pid === $category->id) {
  106. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  107. }
  108. }
  109. if (!empty($children)) {
  110. $categoryData['children'] = $children;
  111. }
  112. return $categoryData;
  113. }
  114. public function myCategoryList(array $data): array
  115. {
  116. $sszq = $data['sszq'] ?? '';
  117. unset($data['sszq']);
  118. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  119. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  120. $where[] = [
  121. 'pid', '=', $data['pid'],
  122. ];
  123. if (isset($data['name'])) {
  124. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  125. }
  126. var_dump($where);
  127. //根据分类id,从category表中取出分类信息
  128. $result = Category::where($where)
  129. ->whereIn('category.id', $catorytids)
  130. ->select('category.*', 'category.id as category_id')->get();
  131. if (empty($result)) {
  132. return Result::error("没有栏目数据");
  133. }
  134. return Result::success($result);
  135. }
  136. /**
  137. * @param array $data
  138. * @return array
  139. */
  140. public function categoryList(array $data): array
  141. {
  142. $where[] = [
  143. 'pid', '=', $data['pid'],
  144. ];
  145. if (isset($data['name'])) {
  146. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  147. }
  148. var_dump($where);
  149. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  150. if (empty($result)) {
  151. return Result::error("没有栏目数据");
  152. }
  153. return Result::success($result);
  154. }
  155. /**
  156. * @param array $data
  157. * @return array
  158. */
  159. public function addCategory(array $data): array
  160. {
  161. if (isset($data['id'])) {
  162. unset($data['id']);
  163. }
  164. $id = Category::insertGetId($data);
  165. if (empty($id)) {
  166. return Result::error("添加失败");
  167. }
  168. return Result::success(['id' => $id]);
  169. }
  170. /**
  171. * @param array $data
  172. * @return array
  173. */
  174. public function delCategory(array $data): array
  175. {
  176. Db::beginTransaction();
  177. try {
  178. $categoryList = Category::where(['pid' => $data['id']])->get();
  179. if ($categoryList->toArray()) {
  180. Db::rollBack();
  181. return Result::error("分类下面有子分类不能删除");
  182. }
  183. $articleList = Article::where(['catid' => $data['id']])->get();
  184. if ($articleList->toArray()) {
  185. Db::rollBack();
  186. return Result::error("分类下面有资讯不能删除");
  187. }
  188. $result = Category::where($data)->delete();
  189. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  190. if (!$result) {
  191. return Result::error("删除失败");
  192. }
  193. return Result::success($result);
  194. Db::commit();
  195. } catch (\Exception $e) {
  196. Db::rollBack();
  197. return Result::error("删除失败");
  198. }
  199. }
  200. /**
  201. * @param array $data
  202. * @return array
  203. */
  204. public function updateCategory(array $data): array
  205. {
  206. $where = [
  207. 'id' => $data['id'],
  208. ];
  209. $result = Category::where($where)->update($data);
  210. if ($result) {
  211. return Result::success($result);
  212. } else {
  213. return Result::error("更新失败");
  214. }
  215. }
  216. /**
  217. * 获取导航池信息
  218. * @param array $data
  219. * @return array
  220. */
  221. public function getCategoryInfo(array $data): array
  222. {
  223. $where = [
  224. 'id' => $data['id'],
  225. ];
  226. $result = Category::where($where)->first();
  227. if ($result) {
  228. return Result::success($result);
  229. } else {
  230. return Result::error("更新失败");
  231. }
  232. }
  233. /**
  234. * @param array $data
  235. * @return array
  236. */
  237. public function getArticleList(array $data): array
  238. {
  239. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  240. $type_id = $data['type_id'];
  241. unset($data['type_id']);
  242. $user_id = $data['user_id'];
  243. unset($data['user_id']);
  244. $where = [];
  245. $status1 = [];
  246. if (isset($data['id']) && $data['id']) {
  247. array_push($where, ['article.id', '=', $data['id']]);
  248. }
  249. if (isset($data['title']) && $data['title']) {
  250. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  251. }
  252. if (isset($data['category_name']) && $data['category_name']) {
  253. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  254. }
  255. if (isset($data['author']) && $data['author']) {
  256. array_push($where, ['article.author', '=', $data['author']]);
  257. }
  258. if (isset($data['islink']) && $data['islink'] !== "") {
  259. array_push($where, ['article.islink', '=', $data['islink']]);
  260. }
  261. if (isset($data['status']) && $data['status'] !== "") {
  262. array_push($where, ['article.status', '=', $data['status']]);
  263. }
  264. if (isset($data['status1'])) {
  265. $status1 = json_decode(($data['status1']));
  266. }
  267. //不是管理员展示个人数据;
  268. if ($type_id != 10000) {
  269. $where[] = ['article.admin_user_id', '=', $user_id];
  270. }
  271. $rep = Article::where($where)
  272. ->whereNotIn('article.status', [404])
  273. ->when($status1, function ($query) use ($status1) {
  274. if (isset($status1) && $status1) {
  275. $query->whereIn('article.status', $status1);
  276. }
  277. })
  278. ->leftJoin('category', 'article.catid', 'category.id')
  279. ->select("article.*", "category.name as category_name")
  280. ->orderBy("article.updated_at", "desc")
  281. ->limit($data['pageSize'])
  282. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  283. $count = Article::where($where)->whereNotIn('article.status', [404])
  284. ->when($status1, function ($query) use ($status1) {
  285. if (isset($status1) && $status1) {
  286. $query->whereIn('article.status', $status1);
  287. }
  288. })
  289. ->leftJoin('category', 'article.catid', 'category.id')->count();
  290. $data = [
  291. 'rows' => $rep->toArray(),
  292. 'count' => $count,
  293. ];
  294. if (empty($rep)) {
  295. return Result::error("没有信息数据");
  296. }
  297. return Result::success($data);
  298. }
  299. /**
  300. * @param array $data
  301. * @return array
  302. */
  303. public function addArticle(array $data): array
  304. {
  305. var_dump($data, '----------12-----------1');
  306. unset($data['user_type']);
  307. unset($data['nav_add_pool_id']);
  308. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  309. Db::beginTransaction();
  310. try {
  311. //处理投票
  312. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  313. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  314. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  315. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  316. unset($data['is_survey']);
  317. unset($data['survey_name']);
  318. unset($data['suvey_array']);
  319. // unset($data['website_id']);
  320. // unset($data['web_site_id']);
  321. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  322. if ($data['hits'] == '') {
  323. $data['hits'] = 0;
  324. }
  325. if ($data['is_original'] == '') {
  326. $data['is_original'] = 0;
  327. }
  328. if ($data['status'] == '') {
  329. $data['status'] = 0;
  330. }
  331. $articleData = $data;
  332. unset($articleData['content']);
  333. //自动处理缩略图、关键字、描述
  334. if ($articleData['imgurl'] == '') {
  335. //如果没有图,设置level=0
  336. $levelArr = json_decode($articleData['level'], true);
  337. var_dump($levelArr, '----------levelArr-----------1');
  338. //content中提取图片第一个图,正则提取
  339. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  340. preg_match_all($reg, $data['content'], $matches);
  341. if (isset($matches[1][0])) {
  342. //截取varchar240
  343. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  344. //如果有图,设置level=3
  345. if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
  346. $articleData['level'] = json_encode($levelArr);
  347. } else {
  348. if (!in_array(0, $levelArr)) {
  349. $levelArr[] = 0;
  350. }
  351. $articleData['level'] = json_encode($levelArr);
  352. }
  353. }
  354. var_dump($articleData['level'], '----------$articleData[level]----------1');
  355. if ($articleData['keyword'] == '') {
  356. //提取标题+内容中的关键词
  357. $articleData['keyword'] = $data['title'];
  358. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  359. Jieba::init(); // 初始化 jieba-php
  360. Finalseg::init();
  361. $segList = Jieba::cut($articleData['keyword']);
  362. $segList1 = array_slice($segList, 0, 8);
  363. $articleData['keyword'] = implode(',', $segList1);
  364. }
  365. if ($articleData['introduce'] == '') {
  366. //提取内容中的描述
  367. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  368. }
  369. $id = Article::insertGetId($articleData);
  370. $articleDataContent = [
  371. 'article_id' => $id,
  372. 'content' => $data['content'],
  373. ];
  374. ArticleData::insertGetId($articleDataContent);
  375. //处理投票
  376. if ($is_survey == 1) {
  377. //生成年月日时分秒+8位随机数
  378. $uuid = date('YmdHis') . rand(10000000, 99999999);
  379. var_dump($suvey_array, 'suvey_array________');
  380. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  381. var_dump($suveys_array, '---------------------1');
  382. var_dump($suvey_array, '---------------------2');
  383. $suvey_data = [];
  384. foreach ($suveys_array as $key => $value) {
  385. if ($value == '') {
  386. continue;
  387. }
  388. if (is_array($value)) {
  389. $suvey_data[] = [
  390. 'sur_id' => $uuid,
  391. 'art_id' => $id,
  392. 'website_id' => $website_id ?? 2,
  393. 'survey_name' => $survey_name,
  394. 'choice_name' => $value[1],
  395. 'is_other' => 1,
  396. 'other_id' => 0,
  397. 'results' => 0,
  398. ];
  399. } else {
  400. $suvey_data[] = [
  401. 'sur_id' => $uuid,
  402. 'art_id' => $id,
  403. 'website_id' => $website_id ?? 2,
  404. 'survey_name' => $survey_name,
  405. 'choice_name' => $value,
  406. 'is_other' => 0,
  407. 'other_id' => 0,
  408. 'results' => 0,
  409. ];
  410. }
  411. if (empty($suvey_data)) {
  412. throw new \Exception("投票数据为空");
  413. }
  414. }
  415. $result = ArticleSurvey::insert($suvey_data);
  416. if (!$result) {
  417. throw new \Exception("投票失败,ArticleSurvey插入失败");
  418. }
  419. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  420. if (!$result) {
  421. throw new \Exception("投票失败,更新主表失败");
  422. }
  423. }
  424. Db::commit();
  425. return Result::success(['id' => $id]);
  426. } catch (\Throwable $ex) {
  427. Db::rollBack();
  428. var_dump($ex->getMessage());
  429. return Result::error("创建失败", 0);
  430. }
  431. }
  432. /**
  433. * @param array $data
  434. * @return array
  435. */
  436. public function delArticle(array $data): array
  437. {
  438. $result = Article::where($data)->delete();
  439. //survey投票删除
  440. articleSurvey::where(['art_id' => $data['id']])->delete();
  441. if (!$result) {
  442. return Result::error("删除失败");
  443. }
  444. return Result::success($result);
  445. }
  446. /**
  447. * @param array $data
  448. * @return array
  449. */
  450. public function updateArticle(array $data): array
  451. {
  452. var_dump($data, '----------12-----------1');
  453. Db::beginTransaction();
  454. unset($data['user_type']);
  455. // unset($data['web_site_id']);
  456. unset($data['nav_add_pool_id']);
  457. try {
  458. //处理投票
  459. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  460. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  461. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  462. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  463. unset($data['is_survey']);
  464. unset($data['survey_name']);
  465. unset($data['suvey_array']);
  466. unset($data['website_id']);
  467. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  468. if ($data['hits'] == '') {
  469. $data['hits'] = 0;
  470. }
  471. if ($data['is_original'] == '') {
  472. $data['is_original'] = 0;
  473. }
  474. if ($data['status'] == '') {
  475. $data['status'] = 0;
  476. }
  477. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  478. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  479. $articleData = $data;
  480. unset($articleData['content']);
  481. unset($articleData['status_name']);
  482. unset($articleData['name']);
  483. unset($articleData['content']);
  484. unset($articleData['pid_arr']);
  485. unset($articleData['pid']);
  486. //自动处理缩略图、关键字、描述
  487. if ($articleData['imgurl'] == '') {
  488. //如果没有图,设置level=0
  489. $levelArr = json_decode($articleData['level'], true);
  490. var_dump($levelArr, '----------levelArr-----------1');
  491. //content中提取图片第一个图,正则提取
  492. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  493. preg_match_all($reg, $data['content'], $matches);
  494. if (isset($matches[1][0])) {
  495. //截取varchar240
  496. // 截取到第一个<
  497. $articleData['imgurl'] = $matches[1][0];
  498. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  499. $pos = strpos($articleData['imgurl'], '"');
  500. if ($pos !== false) {
  501. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  502. }
  503. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  504. //如果有图,设置level=3
  505. if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
  506. $articleData['level'] = json_encode($levelArr);
  507. } else {
  508. if (!in_array(0, $levelArr)) {
  509. $levelArr[] = 0;
  510. }
  511. $articleData['level'] = json_encode($levelArr);
  512. }
  513. }
  514. var_dump($articleData['level'], '----------$articleData[level]----------1');
  515. if ($articleData['keyword'] == '') {
  516. //提取标题+内容中的关键词
  517. $articleData['keyword'] = $data['title'];
  518. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  519. Jieba::init(); // 初始化 jieba-php
  520. Finalseg::init();
  521. $segList = Jieba::cut($articleData['keyword']);
  522. $segList1 = array_slice($segList, 0, 8);
  523. $articleData['keyword'] = implode(',', $segList1);
  524. }
  525. if ($articleData['introduce'] == '') {
  526. //提取内容中的描述
  527. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  528. }
  529. $id = Article::where(['id' => $data['id']])->update($articleData);
  530. $articleDataContent = [
  531. 'content' => $data['content'],
  532. ];
  533. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  534. //处理投票
  535. $id = $data['id'];
  536. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  537. var_dump($suvey_array, 'suvey_array________delete');
  538. //处理投票
  539. if ($is_survey == 1) {
  540. //生成年月日时分秒+8位随机数
  541. $uuid = date('YmdHis') . rand(10000000, 99999999);
  542. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  543. var_dump($suveys_array, '---------------------1');
  544. $suvey_data = [];
  545. if (is_array($suveys_array)) {
  546. foreach ($suveys_array as $key => $value) {
  547. if ($value == '') {
  548. continue;
  549. }
  550. if (is_array($value)) {
  551. $suvey_data[] = [
  552. 'sur_id' => $uuid,
  553. 'art_id' => $id,
  554. 'website_id' => $website_id ?? 2,
  555. 'survey_name' => $survey_name,
  556. 'choice_name' => $value[1],
  557. 'is_other' => 1,
  558. 'other_id' => 0,
  559. 'results' => 0,
  560. ];
  561. } else {
  562. $suvey_data[] = [
  563. 'sur_id' => $uuid,
  564. 'art_id' => $id,
  565. 'website_id' => $website_id ?? 2,
  566. 'survey_name' => $survey_name,
  567. 'choice_name' => $value,
  568. 'is_other' => 0,
  569. 'other_id' => 0,
  570. 'results' => 0,
  571. ];
  572. }
  573. if (empty($suvey_data)) {
  574. throw new \Exception("投票数据为空");
  575. }
  576. }
  577. }
  578. $result = ArticleSurvey::insert($suvey_data);
  579. if (!$result) {
  580. throw new \Exception("投票失败");
  581. }
  582. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  583. if (!$result) {
  584. throw new \Exception("投票失败");
  585. }
  586. } else {
  587. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  588. }
  589. Db::commit();
  590. return Result::success([]);
  591. } catch (\Throwable $ex) {
  592. Db::rollBack();
  593. var_dump($ex->getMessage());
  594. return Result::error("更新失败" . $ex->getMessage(), 0);
  595. }
  596. }
  597. /**
  598. * 更新资讯状态
  599. * @param array $data
  600. * @return array
  601. */
  602. public function upArticleStatus(array $data): array
  603. {
  604. $result = Article::where(['id' => $data['id']])->update($data);
  605. if ($result) {
  606. return Result::success();
  607. } else {
  608. return Result::error("更新状态失败", 0);
  609. }
  610. }
  611. /**
  612. * @param array $data
  613. * @return array
  614. */
  615. public function getArticleInfo(array $data): array
  616. {
  617. $where = [
  618. 'article.id' => $data['id'],
  619. // 'article.status' => 1,
  620. ];
  621. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  622. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  623. $info = $result;
  624. // var_dump($info, 'info');
  625. $info['survey_array'] = $articleSurvey;
  626. if ($result) {
  627. return Result::success($info);
  628. } else {
  629. return Result::error("查询失败", 0);
  630. }
  631. }
  632. /**
  633. * 获取新闻
  634. * @param array $data
  635. * @return array
  636. */
  637. public function getWebsiteArticlett(array $data): array
  638. {
  639. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  640. $category = array_values(array_unique($category->toArray()));
  641. $result = [];
  642. if ($category) {
  643. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  644. $where = [
  645. 'status' => 1,
  646. ];
  647. var_dump($data, 'data-----------------');
  648. // level=7 根据文章key来匹配文章
  649. if (isset($data['level']) && $data['level'] == 7) {
  650. // 根据文章id获取key
  651. // $data['id'] = 50142;
  652. if (isset($data['id']) && !empty($data['id'])) {
  653. $keyword = Article::where('id', $data['id'])->value('keyword');
  654. $keywordArray = explode(',', $keyword);
  655. $whereL7 = [];
  656. foreach ($keywordArray as $k => $v) {
  657. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  658. }
  659. // 原始查询
  660. $result = Article::where($whereL7)
  661. ->offset($placeid)
  662. ->limit($data['pageSize'])
  663. ->orderBy('updated_at', 'desc')
  664. ->get()
  665. ->map(function ($article ) use ($data) {
  666. $catid = $article->catid;
  667. $pinyin = '';
  668. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  669. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  670. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  671. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  672. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
  673. }
  674. $article->pinyin = $pinyin;
  675. return $article;
  676. });
  677. if (empty($result)) {
  678. return Result::success([]);
  679. }
  680. return Result::success($result);
  681. } else {
  682. return Result::error("参数错误level=7,id不能为空", 0);
  683. }
  684. }
  685. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  686. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  687. var_dump($where, 'where-----------------');
  688. $result = Article::where($where)
  689. ->whereIn("catid", $category)
  690. // ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  691. // ->where('website_category.website_id', $data['website_id'])
  692. ->where(function ($query) use ($data) {
  693. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  694. ->orWhereNull("ignore_ids");
  695. })
  696. //$data['level'] == 4 || $data['level'] == 5 查询随机
  697. ->when($data['level'] == 5, function ($query) {
  698. $query->inRandomOrder()
  699. //updated_at最近三十天;
  700. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  701. })
  702. ->when($data['level'] == 4, function ($query) {
  703. $query->orderBy("article.updated_at", "desc");
  704. })
  705. ->when(!empty($data['level']), function ($query) use ($data) {
  706. if ($data['level'] != 4 && $data['level'] != 5) {
  707. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  708. ->orderBy("article.updated_at", "desc");
  709. }
  710. })
  711. ->select('article.*')
  712. ->offset($placeid)
  713. ->limit($data['pageSize'])
  714. ->get()
  715. ->map(function ($article ) use ($data) {
  716. $catid = $article->catid;
  717. $pinyin = '';
  718. // $category = WebsiteCategory::whereIn('category_id', $catArrId)->where('website_category.website_id', $data['website_id'])->get()->all();
  719. // if ($catArrId) {
  720. // foreach ($catArrId as $categoryId) {
  721. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  722. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  723. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  724. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  725. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
  726. }
  727. // }
  728. // }
  729. $article->pinyin = $pinyin;
  730. return $article;
  731. });
  732. if (empty($result)) {
  733. return Result::error("暂无头条新闻", 0);
  734. }
  735. return Result::success($result);
  736. } else {
  737. return Result::error("本网站下暂无相关栏目", 0);
  738. }
  739. }
  740. /**
  741. * 获取模块新闻
  742. * @param array $data
  743. * @return array
  744. */
  745. public function getWebsiteModelArticles(array $data): array
  746. {
  747. $catid = $data['catid'];
  748. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  749. $category = $category->toArray();
  750. if (!empty($category)) {
  751. $where = [
  752. 'status' => 1,
  753. 'catid' => $catid,
  754. ];
  755. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  756. // 1:文字新闻;2:轮播图;3:图文;
  757. // 级别:0:未分类
  758. // 3:推荐图片
  759. if ($data['level'] == 1) {
  760. $data['level'] = 0;
  761. }
  762. $result = Article::where($where)
  763. ->where(function ($query) use ($data) {
  764. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  765. ->orWhereNull("level")
  766. ->orWhereRaw("level = '[]'");
  767. })
  768. ->where(function ($query) use ($data) {
  769. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  770. ->orWhereNull("ignore_ids");
  771. })
  772. ->orderBy("updated_at", "desc")
  773. ->offset($placeid)
  774. ->limit($data['pagesize'])
  775. ->get();
  776. if (empty($result)) {
  777. return Result::error("此栏目暂无相关新闻", 0);
  778. }
  779. } else {
  780. return Result::error("此网站暂无此栏目", 0);
  781. }
  782. return Result::success($result);
  783. }
  784. /**
  785. *获取新闻列表
  786. * @param array $data
  787. * @return array
  788. */
  789. public function getWebsiteArticleList(array $data): array
  790. {
  791. // return Result::success($data);
  792. $where[] = ['status', '=', 1];
  793. if (isset($data['catid']) && !empty($data['catid'])) {
  794. if (is_array($data['catid'])) {
  795. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  796. array_push($where, ['catid', 'in', $data['catid']]);
  797. } else {
  798. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  799. array_push($where, ['catid', '=', $data['catid']]);
  800. }
  801. if (empty($category)) {
  802. return Result::error("此网站暂无此栏目", 0);
  803. }
  804. }
  805. // return Result::success($where);
  806. $rep = Article::where(function ($query) use ($where) {
  807. foreach ($where as $condition) {
  808. if ($condition[1] === 'in') {
  809. $query->whereIn($condition[0], $condition[2]);
  810. } else {
  811. $query->where($condition[0], $condition[1], $condition[2]);
  812. }
  813. }
  814. })
  815. ->where(function ($query) use ($data) {
  816. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  817. ->orWhereNull("ignore_ids");
  818. })
  819. ->select(
  820. 'article.id',
  821. 'article.title',
  822. 'article.imgurl',
  823. 'article.author',
  824. 'article.updated_at',
  825. 'article.introduce',
  826. 'article.islink',
  827. 'article.linkurl',
  828. 'article.copyfrom',
  829. 'article.catid')
  830. ->orderBy("updated_at", "desc")
  831. ->limit($data['pageSize'])
  832. ->offset(($data['page'] - 1) * $data['pageSize'])
  833. ->get()
  834. ->map(function ($article ) use ($data) {
  835. $catid = $article->catid ?? 0;
  836. $pinyin = '';
  837. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  838. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  839. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  840. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  841. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
  842. }
  843. $article->pinyin = $pinyin;
  844. return $article;
  845. });
  846. $count = Article::where(function ($query) use ($where) {
  847. foreach ($where as $condition) {
  848. if ($condition[1] === 'in') {
  849. $query->whereIn($condition[0], $condition[2]);
  850. } else {
  851. $query->where($condition[0], $condition[1], $condition[2]);
  852. }
  853. }
  854. })->count();
  855. $data = [
  856. 'rows' => $rep->toArray(),
  857. 'count' => $count,
  858. ];
  859. if (empty($rep)) {
  860. return Result::error("没有信息数据");
  861. }
  862. return Result::success($data);
  863. }
  864. /**
  865. * 前端-获取新闻详情
  866. * @param array $data
  867. * @return array
  868. */
  869. public function selectWebsiteArticleInfo(array $data): array
  870. {
  871. $where = [
  872. 'article.id' => $data['id'],
  873. 'article.status' => 1,
  874. ];
  875. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
  876. ->where(function ($query) use ($data) {
  877. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  878. ->orWhereNull("ignore_ids");
  879. })
  880. ->first();
  881. if (empty($result)) {
  882. return Result::error("暂无此新闻!", 0);
  883. }
  884. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  885. ->select('website_category.*', 'website.website_name', 'website.suffix')
  886. ->where('website_category.website_id', $data['website_id'])
  887. ->where(['website_category.category_id' => $result['catid']])
  888. ->first();
  889. if (empty($category)) {
  890. return Result::error("查询失败", 0);
  891. }
  892. //手动推荐文章
  893. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  894. $commendArticle = Article::whereIn('id', $commend_ids)
  895. ->where('status', 1)
  896. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  897. ->orderBy('updated_at', 'desc')
  898. ->limit(5)
  899. ->get();
  900. $result['category_id'] = $category['category_id'];
  901. $result['cat_name'] = $category['alias'];
  902. $result['website_name'] = $category['website_name'] ?? "";
  903. $result['suffix'] = $category['suffix'] ?? "";
  904. $result['commendArticle'] = $commendArticle;
  905. return Result::success($result);
  906. }
  907. /**
  908. * 前端-获取网站调查问卷
  909. * @param array $data
  910. * @return array
  911. */
  912. public function getWebsiteSurvey(array $data): array
  913. {
  914. if (isset($data['website_id']) && !empty($data['website_id'])) {
  915. $website = Website::where('id', $data['website_id'])->first();
  916. if (empty($website)) {
  917. return Result::error("暂无此网站", 0);
  918. }
  919. }
  920. if (isset($data['art_id']) && !empty($data['art_id'])) {
  921. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  922. if (empty($article)) {
  923. return Result::error("暂无此文章", 0);
  924. }
  925. // return Result::error($data,0);
  926. $where['art_id'] = $data['art_id'];
  927. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  928. } else {
  929. $survey = Article::where(function ($query) {
  930. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  931. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  932. })
  933. ->where('status', 1)
  934. ->where('is_survey', 1)
  935. ->select('survey_id')
  936. ->orderBy('updated_at', 'desc')
  937. ->first();
  938. if (empty($survey)) {
  939. return Result::error("暂无调查问卷", 0);
  940. }
  941. $where['sur_id'] = $survey['survey_id'];
  942. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  943. }
  944. // return Result::success($where);
  945. $result = ArticleSurvey::where($where)
  946. ->where(function ($query) {
  947. $query->where('is_other', 0)
  948. ->orWhere(function ($subQuery) {
  949. $subQuery->where('is_other', 1)
  950. ->where('other_id', 0);
  951. });
  952. })
  953. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  954. ->select('article_survey.*', 'article.survey_type')
  955. ->get()->all();
  956. if (empty($result)) {
  957. return Result::error("此文章暂无调查问卷", 0);
  958. }
  959. return Result::success($result);
  960. }
  961. /**
  962. * 前端-添加网站调查问卷选项
  963. * @param array $data
  964. * @return array
  965. */
  966. public function addWebsiteSurveyOption(array $data): array
  967. {
  968. if (isset($data['website_id']) && !empty($data['website_id'])) {
  969. $website = Website::where('id', $data['website_id'])->first();
  970. if (empty($website)) {
  971. return Result::error("暂无此网站", 0);
  972. }
  973. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  974. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  975. if (empty($survey)) {
  976. return Result::error("此调查问卷不可添加选项", 0);
  977. }
  978. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  979. $choice = [
  980. 'art_id' => $survey['art_id'],
  981. 'website_id' => $data['website_id'],
  982. 'survey_name' => $survey['survey_name'],
  983. 'choice_name' => $data['choice_name'],
  984. 'sur_id' => $survey['sur_id'],
  985. 'is_other' => 1,
  986. 'other_id' => $survey['id'],
  987. ];
  988. $result = ArticleSurvey::insertGetId($choice);
  989. if (empty($result)) {
  990. return Result::error("添加失败", 0);
  991. }
  992. return Result::success($result);
  993. }
  994. }
  995. return Result::error("添加失败", 0);
  996. }
  997. return Result::error("添加失败", 0);
  998. }
  999. /**
  1000. * 前端-调查问卷投票
  1001. * @param array $data
  1002. * @return array
  1003. */
  1004. public function addWebsiteSurveyVote(array $data): array
  1005. {
  1006. // return Result::success($data);
  1007. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1008. $website = Website::where('id', $data['website_id'])->first();
  1009. if (empty($website)) {
  1010. return Result::error("暂无此网站", 0);
  1011. }
  1012. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1013. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1014. // return Result::success($survey);
  1015. if (empty($is_survey)) {
  1016. return Result::error("此调查问卷不存在", 0);
  1017. }
  1018. // return Result::success($survey);
  1019. // 调查问卷类型
  1020. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1021. //多选 若是json型则转化成数组类型
  1022. if (strpos($data['choice_id'], '[') === 0) {
  1023. $data['choice_id'] = json_decode($data['choice_id'], true);
  1024. } else {
  1025. // 单选 也转换成数组
  1026. $data['choice_id'] = [$data['choice_id']];
  1027. }
  1028. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1029. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1030. ->where('website_id', $data['website_id'])
  1031. ->where('is_other', 1)
  1032. ->where('other_id', 0)
  1033. ->first();
  1034. if (!empty($other)) {
  1035. return Result::error("请选择已有的选项!", 0);
  1036. }
  1037. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1038. ->where('website_id', $data['website_id'])
  1039. ->where('is_other', 1)
  1040. ->where('other_id', '!=', 0)
  1041. ->first();
  1042. // return Result::success($choice['other']);
  1043. $choice_id = $data['choice_id'];
  1044. if (!empty($choice['other'])) {
  1045. // array_push($data['choice_id'],$choice['other']['other_id']);
  1046. if (!empty($choice_id)) {
  1047. $key = array_search($choice['other']['id'], $choice_id);
  1048. if ($key !== false) {
  1049. unset($choice_id[$key]);
  1050. $choice_id = array_values($choice_id);
  1051. }
  1052. array_push($choice_id, $choice['other']['other_id']);
  1053. } else {
  1054. $choice_id[0] = $choice['other']['other_id'];
  1055. }
  1056. array_push($data['choice_id'], $choice['other']['other_id']);
  1057. }
  1058. // return Result::success($data);
  1059. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1060. ->where('website_id', $data['website_id'])
  1061. ->increment('results', 1);
  1062. if (empty($choice)) {
  1063. return Result::error("请选择已有的选项!", 0);
  1064. }
  1065. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1066. ->where('website_id', $data['website_id'])
  1067. ->where('other_id', 0)
  1068. ->get();
  1069. $survey['choice'] = $choice_id;
  1070. return Result::success($survey);
  1071. }
  1072. return Result::error("参数必填!");
  1073. }
  1074. return Result::error("此调查问卷不存在", 0);
  1075. }
  1076. return Result::error("参数必填!");
  1077. }
  1078. /**
  1079. * 后端-获取网站调查问卷列表
  1080. * @param array $data
  1081. * @return array
  1082. */
  1083. public function getSurveyList(array $data): array
  1084. {
  1085. $where = [];
  1086. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1087. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1088. }
  1089. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1090. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1091. }
  1092. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1093. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1094. }
  1095. // return Result::success($where);
  1096. if (!empty($where)) {
  1097. $query = Article::where($where)->where(function ($q) {
  1098. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1099. });
  1100. } else {
  1101. $query = Article::where(function ($q) {
  1102. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1103. });
  1104. }
  1105. $count = $query->count();
  1106. $survey = $query->orderByDesc('id')
  1107. ->limit($data['pageSize'])
  1108. ->offset(($data['page'] - 1) * $data['pageSize'])
  1109. ->get();
  1110. if (empty($survey->toArray())) {
  1111. return Result::error("暂无调查问卷!", 0);
  1112. }
  1113. $result = [
  1114. 'rows' => $survey,
  1115. 'count' => $count,
  1116. ];
  1117. return Result::success($result);
  1118. }
  1119. /**
  1120. * 后端-获取网站调查问卷详情
  1121. * @param array $data
  1122. * @return array
  1123. */
  1124. public function getSurveyInfo(array $data): array
  1125. {
  1126. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1127. $where = ['sur_id' => $data['sur_id']];
  1128. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1129. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1130. ->select('article_survey.*', 'article.survey_type')
  1131. ->get()->all();
  1132. if (empty($choose)) {
  1133. return Result::error("此调查问卷不存在", 0);
  1134. }
  1135. $resultsArray = array_column($choose, 'results');
  1136. $total = array_sum($resultsArray);
  1137. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1138. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1139. // $total = 0;
  1140. if (!empty($other)) {
  1141. $total = $total + $other['results'];
  1142. $other['choice_name'] = '(其他)';
  1143. if (!empty($others)) {
  1144. $other['hasChildren'] = true;
  1145. // array_push($other,['hasChildren','=',true]);
  1146. $other['children'] = $others;
  1147. $other_choices = [$other->toArray()];
  1148. $mer_choice = array_merge($choose, $other_choices);
  1149. $value_choice = array_values($mer_choice);
  1150. } else {
  1151. // return Result::error('1111');
  1152. $other_choices = [$other->toArray()];
  1153. $other_choices = array_merge($choose, $other_choices);
  1154. $value_choice = array_values($other_choices);
  1155. // return Result::success($result);
  1156. }
  1157. } else {
  1158. $value_choice = $choose;
  1159. }
  1160. $result = [
  1161. 'choose' => $value_choice,
  1162. 'total' => $total,
  1163. ];
  1164. }
  1165. return Result::success($result);
  1166. }
  1167. /**
  1168. * 前端-搜索新闻列表
  1169. * @param array $data
  1170. * @return array
  1171. */
  1172. public function selectWebsiteArticle(array $data): array
  1173. {
  1174. $where = [];
  1175. // 初始化查询构造器
  1176. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1177. $query = Article::where('status', 1)
  1178. ->whereIn('catid', $category)
  1179. ->where(function ($query) use ($data) {
  1180. $query->where(function ($subQuery) use ($data) {
  1181. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1182. })->orWhereNull("ignore_ids");
  1183. });
  1184. // return Result::success($all_articles);
  1185. // 检查是否存在 cityid 参数
  1186. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1187. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1188. }
  1189. // 检查是否存在 department_id 参数
  1190. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1191. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1192. }
  1193. // 检查是否存在 keyword 参数
  1194. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1195. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1196. }
  1197. // 计算总数
  1198. $count = $query->count();
  1199. // 分页查询
  1200. $articles = $query
  1201. ->select(
  1202. 'article.id',
  1203. 'article.title',
  1204. 'article.imgurl',
  1205. 'article.author',
  1206. 'article.updated_at',
  1207. 'article.introduce',
  1208. 'article.islink',
  1209. 'article.linkurl',
  1210. 'article.copyfrom',
  1211. 'article.catid',
  1212. 'article.department_arr_id',
  1213. 'article.city_arr_id',)
  1214. ->orderBy("updated_at", "desc")
  1215. ->offset(($data['page'] - 1) * $data['pageSize'])
  1216. ->limit($data['pageSize'])
  1217. ->get()
  1218. ->map(function ($article ) use ($data) {
  1219. $catid = $article->catid ?? 0;
  1220. $pinyin = '';
  1221. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  1222. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1223. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  1224. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  1225. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
  1226. }
  1227. $article->pinyin = $pinyin;
  1228. return $article;
  1229. });
  1230. if (empty($articles)) {
  1231. return Result::error("没有符合条件的资讯数据");
  1232. }
  1233. $data = [
  1234. 'rows' => $articles,
  1235. 'count' => $count,
  1236. ];
  1237. return Result::success($data);
  1238. }
  1239. /**
  1240. * 模块新闻加强版
  1241. * @param array $data
  1242. * @return array
  1243. */
  1244. public function getWebsiteCatidArticle(array $data): array
  1245. {
  1246. // return Result::success($data);
  1247. $where = [
  1248. // 'category.status' => 1,
  1249. 'website_category.category_id' => $data['catid'],
  1250. 'website_category.website_id' => $data['website_id'],
  1251. // 'article.status' => 1,
  1252. ];
  1253. // $category = WebsiteCategory::where($where);
  1254. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1255. $child_catnum = $data['child_catnum'] ?? 1;
  1256. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1257. $childCategoryIds = array_column($category['child'], 'category_id');
  1258. if (empty($childCategoryIds)) {
  1259. return Result::error("暂无子栏目", 0);
  1260. }
  1261. $imgArticles = [];
  1262. $textArticles = [];
  1263. // return Result::success($childCategoryIds);
  1264. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1265. // 初始化子分类图片新闻和文字新闻数组
  1266. // 查询所有子级栏目的图文新闻
  1267. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1268. ->where(function ($query) use ($data) {
  1269. $query->where(function ($subQuery) use ($data) {
  1270. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1271. })->orWhereNull("ignore_ids");
  1272. })
  1273. ->where('status', 1)
  1274. ->where('imgurl', '!=', '')
  1275. ->select('*')
  1276. ->orderBy('updated_at', 'desc')
  1277. ->limit($data['child_imgnum'])
  1278. ->get();
  1279. }
  1280. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1281. // 查询所有子级栏目的文字新闻
  1282. $textArticles = Article::where('catid', $childCategoryIds[0])
  1283. ->where('status', 1)
  1284. ->where(function ($query) use ($data) {
  1285. $query->where(function ($subQuery) use ($data) {
  1286. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1287. })->orWhereNull("ignore_ids");
  1288. })
  1289. // ->where(function ($query) {
  1290. // $query->whereNull('imgurl')
  1291. // ->orWhere('imgurl', '');
  1292. // })
  1293. ->select('*')
  1294. ->orderBy('updated_at', 'desc')
  1295. ->limit($data['child_textnum'])
  1296. ->get();
  1297. }
  1298. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1299. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1300. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1301. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1302. return $child;
  1303. }, $category['child']);
  1304. }
  1305. // }
  1306. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1307. $category['img'] = WebsiteCategory::where($where)
  1308. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1309. ->where('article.status', 1)
  1310. ->where('article.imgurl', '!=', '')
  1311. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1312. ->orderBy('article.updated_at', 'desc')
  1313. ->limit($data['img_num'])
  1314. ->get();
  1315. }
  1316. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1317. $category['text'] = WebsiteCategory::where($where)
  1318. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1319. ->where('article.status', 1)
  1320. // ->where(function ($query) {
  1321. // $query->whereNull('article.imgurl')
  1322. // ->orWhere('article.imgurl', '');
  1323. // })
  1324. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1325. ->orderBy('article.updated_at', 'desc')
  1326. ->limit($data['text_num'])
  1327. ->get();
  1328. }
  1329. // $category = $category->get();
  1330. if (empty($category)) {
  1331. return Result::error("查询失败", 0);
  1332. }
  1333. return Result::success($category);
  1334. }
  1335. /**
  1336. * 模块新闻加强plus版
  1337. * @param array $data
  1338. * @return array
  1339. */
  1340. public function getWebsiteAllArticle(array $data): array
  1341. {
  1342. // 修正传入的字符串,将单引号替换为双引号
  1343. $input['id'] = $data['id'];
  1344. $input['website_id'] = $data['website_id'];
  1345. // 将 JSON 字符串转换为 PHP 数组
  1346. $data = json_decode($input['id'], true);
  1347. // 使用 array_map 处理每个元素
  1348. $result = array_map(function ($item) use ($input) {
  1349. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1350. $website = [
  1351. 'website_id' => $input['website_id'],
  1352. ];
  1353. // 查询栏目名称
  1354. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1355. if (empty($category)) {
  1356. $imgArticles = [];
  1357. $textArticles = [];
  1358. // return Result::error("暂无此栏目",0);
  1359. }else{
  1360. $parent_alias = $category->alias ?? '';
  1361. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1362. // 查询图片新闻
  1363. $imgArticles = Article::where('catid', $parentCatId)
  1364. ->where('status', 1)
  1365. ->where(function ($query) use ($website) {
  1366. $query->where(function ($subQuery) use ($website) {
  1367. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1368. })->orWhereNull("ignore_ids");
  1369. })
  1370. ->where('imgurl', '!=', '')
  1371. ->select(
  1372. 'article.id',
  1373. 'article.title',
  1374. 'article.imgurl',
  1375. 'article.author',
  1376. 'article.updated_at',
  1377. 'article.introduce',
  1378. 'article.islink',
  1379. 'article.linkurl',
  1380. 'article.copyfrom',
  1381. DB::raw("'$parent_pinyin' as pinyin") // 添加 pinyin 字段
  1382. )
  1383. ->orderBy('updated_at', 'desc')
  1384. ->limit($parentImgNum)
  1385. ->get()->all();
  1386. // 查询文字新闻
  1387. $textArticles = Article::where('catid', $parentCatId)
  1388. ->where('status', 1)
  1389. ->where(function ($query) use ($website) {
  1390. $query->where(function ($subQuery) use ($website) {
  1391. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1392. })->orWhereNull("ignore_ids");
  1393. })
  1394. ->select(
  1395. 'article.id',
  1396. 'article.title',
  1397. 'article.author',
  1398. 'article.updated_at',
  1399. 'article.introduce',
  1400. 'article.islink',
  1401. 'article.linkurl',
  1402. 'article.copyfrom',
  1403. DB::raw("'$parent_pinyin' as pinyin"))
  1404. ->orderBy('updated_at', 'desc')
  1405. ->limit($parentTextNum)
  1406. ->get()->all();
  1407. }
  1408. $resultItem = [
  1409. 'alias' => $parent_alias,
  1410. 'category_id' => $parentCatId,
  1411. 'pinyin' => $parent_pinyin,
  1412. 'imgnum' => $imgArticles,
  1413. 'textnum' => $textArticles,
  1414. ];
  1415. if (!empty($item['child']) && $item['child'] != "") {
  1416. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin.'/' : '';
  1417. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1418. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1419. ->get()->all();
  1420. if ($childCategory) {
  1421. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1422. // 查询子栏目名称
  1423. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1424. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1425. ->first();
  1426. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  1427. if(empty($childCategoryInfo)){
  1428. $childImgArticles = [];
  1429. $childTextArticles = [];
  1430. } else {
  1431. // 查询子栏目图片新闻
  1432. $childImgArticles = Article::where('catid', $childCatId)
  1433. ->where('status', 1)
  1434. ->where(function ($query) use ($website) {
  1435. $query->where(function ($subQuery) use ($website) {
  1436. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1437. })->orWhereNull("ignore_ids");
  1438. })
  1439. ->select(
  1440. 'article.id',
  1441. 'article.title',
  1442. 'article.imgurl',
  1443. 'article.author',
  1444. 'article.updated_at',
  1445. 'article.introduce',
  1446. 'article.islink',
  1447. 'article.linkurl',
  1448. 'article.copyfrom',
  1449. DB::raw("'$child_pinyin' as pinyin"))
  1450. ->where('imgurl', '!=', '')
  1451. ->orderBy('updated_at', 'desc')
  1452. ->limit($childImgNum)
  1453. ->get()->all();
  1454. // 查询子栏目文字新闻
  1455. $childTextArticles = Article::where('catid', $childCatId)
  1456. ->where('status', 1)
  1457. ->where(function ($query) use ($website) {
  1458. $query->where(function ($subQuery) use ($website) {
  1459. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1460. })->orWhereNull("ignore_ids");
  1461. })
  1462. ->select(
  1463. 'article.id',
  1464. 'article.title',
  1465. 'article.author',
  1466. 'article.updated_at',
  1467. 'article.introduce',
  1468. 'article.islink',
  1469. 'article.linkurl',
  1470. 'article.copyfrom',
  1471. DB::raw("'$child_pinyin' as pinyin"))
  1472. ->orderBy('updated_at', 'desc')
  1473. ->limit($childTextNum)
  1474. ->get()->all();
  1475. }
  1476. $resultItem['child'] = [
  1477. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1478. 'category_id' => $childCatId,
  1479. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1480. 'all_childcat' => $childCategory,
  1481. 'imgnum' => $childImgArticles,
  1482. 'textnum' => $childTextArticles,
  1483. ];
  1484. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1485. }
  1486. }
  1487. return $resultItem;
  1488. }, $data);
  1489. return Result::success($result);
  1490. // return Result::success($data);
  1491. }
  1492. /**
  1493. * 乡村网-获取特殊新闻模块
  1494. * @param array $data
  1495. * @return array
  1496. */
  1497. public function getWebsiteArticles(array $data): array
  1498. {
  1499. $input['id'] = $data['id'];
  1500. $input['website_id'] = $data['website_id'];
  1501. $data = json_decode($input['id'], true);
  1502. // 使用 array_map 处理每个元素
  1503. $result = array_map(function ($item) use ($input) {
  1504. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1505. $website = [
  1506. 'website_id' => $input['website_id']
  1507. ];
  1508. // 查询栏目名称
  1509. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1510. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1511. if(empty($category)){
  1512. $imgArticles = [];
  1513. $textArticles = [];
  1514. // return Result::error("暂无此栏目",0);
  1515. }else{
  1516. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin.'/' : null;
  1517. // return Result::success($website);
  1518. // 查询图片新闻
  1519. // 合并查询条件
  1520. $baseQuery = Article::where(function ($query) use ($website) {
  1521. $query->where(function ($subQuery) use ($website) {
  1522. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1523. })->orWhereNull("ignore_ids");
  1524. })
  1525. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
  1526. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1527. ->where('website_category.website_id', $website['website_id'])
  1528. ->where('article.status', 1);
  1529. // 查询文字新闻
  1530. $textArticles = clone $baseQuery;
  1531. $textArticles = $textArticles
  1532. ->select(
  1533. 'article.id',
  1534. 'article.title',
  1535. // 'article.imgurl',
  1536. 'article.author',
  1537. 'article.updated_at',
  1538. 'article.introduce',
  1539. 'article.islink',
  1540. 'article.linkurl',
  1541. 'article.copyfrom',
  1542. 'website_category.category_id',
  1543. 'website_category.alias',
  1544. 'website_category.aLIas_pinyin'
  1545. )
  1546. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1547. ->orderBy('article.updated_at', 'desc')
  1548. ->limit($parentTextNum)
  1549. ->get()
  1550. ->all();
  1551. // 查询图片新闻
  1552. $imgArticles = clone $baseQuery;
  1553. $imgArticles = $imgArticles
  1554. ->select(
  1555. 'article.id',
  1556. 'article.title',
  1557. 'article.imgurl',
  1558. 'article.author',
  1559. 'article.updated_at',
  1560. 'article.introduce',
  1561. 'article.islink',
  1562. 'article.linkurl',
  1563. 'article.copyfrom',
  1564. 'website_category.category_id',
  1565. 'website_category.alias',
  1566. 'website_category.aLIas_pinyin'
  1567. )
  1568. ->selectRaw("CONCAT(?, aLIas_pinyin ) as aLIas_pinyin", [$parent_alias])
  1569. ->orderBy('article.updated_at', 'desc')
  1570. ->where('imgurl', '!=', '')
  1571. ->limit($parentImgNum)
  1572. ->get()
  1573. ->all();
  1574. }
  1575. $resultItem = [
  1576. 'alias' => $category ? $category->alias : null,
  1577. 'category_id' => $parentCatId,
  1578. 'pinyin' => $pinyin ? $pinyin : null,
  1579. 'imgnum' => $imgArticles ?? [],
  1580. 'textnum' => $textArticles ?? [],
  1581. ];
  1582. return $resultItem;
  1583. }, $data);
  1584. return Result::success($result);
  1585. }
  1586. /**
  1587. *获取头条类新闻模块-合集
  1588. * @param array $data
  1589. * @return array
  1590. */
  1591. public function getWebsiteAllArticlett(array $data): array
  1592. {
  1593. $input['id'] = $data['id'];
  1594. $input['website_id'] = $data['website_id'];
  1595. $data = json_decode($input['id'], true);
  1596. // 使用 array_map 处理每个元素
  1597. $result = array_map(function ($item) use ($input) {
  1598. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1599. $website = [
  1600. 'website_id' => $input['website_id']
  1601. ];
  1602. $category = WebsiteCategory::where('website_id', $input['website_id'])->pluck('category_id');
  1603. $category = array_values(array_unique($category->toArray()));
  1604. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1605. $where = [
  1606. 'status' => 1,
  1607. ];
  1608. return $category;
  1609. }, $data); // 添加第二个参数 $data,确保 array_map 函数有两个参数
  1610. return Result::success($result);
  1611. }
  1612. /**
  1613. * 验证导航名称是否重复
  1614. * @return void
  1615. */
  1616. public function checkCategoryName(array $data): array
  1617. {
  1618. $result = Category::when($data, function ($query) use ($data) {
  1619. if (isset($data['name']) && $data['name']) {
  1620. $query->where("name", $data['name']);
  1621. }
  1622. if (isset($data['id']) && $data['id']) {
  1623. $query->where("id", "!=", $data['id']);
  1624. }
  1625. })->first();
  1626. if ($result) {
  1627. return Result::error("已存在");
  1628. } else {
  1629. return Result::success();
  1630. }
  1631. }
  1632. //20250226 产品列表
  1633. public function getGoodList(array $data): array
  1634. {
  1635. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1636. unset($data['type_id']);
  1637. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1638. $where = [];
  1639. if ($type_id != '10000') {
  1640. $where = [
  1641. 'good.user_id' => $user_id,
  1642. ];
  1643. }
  1644. //类型
  1645. if (isset($data['type_id']) && $data['type_id']) {
  1646. $where = [
  1647. 'type_id' => $data['type_id'],
  1648. ];
  1649. }
  1650. //名称
  1651. if (isset($data['name']) && $data['name']) {
  1652. $where = [
  1653. 'good.name' => $data['name'],
  1654. ];
  1655. }
  1656. $where1 = [];
  1657. //website_id
  1658. // if (isset($data['website_id']) && $data['website_id']) {
  1659. // $where1 = [
  1660. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1661. // ];
  1662. // }
  1663. // website_name
  1664. if (isset($data['website_name']) && $data['website_name']) {
  1665. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1666. }
  1667. // catid
  1668. if (isset($data['category_name']) && $data['category_name']) {
  1669. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1670. }
  1671. // $result = Good::where($where)
  1672. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1673. $result = Good::where($where)
  1674. ->when(!empty($where1), function ($query) use ($where1) {
  1675. return $query->where($where1);
  1676. })
  1677. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1678. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1679. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1680. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1681. ->orderBy("id", "desc")
  1682. ->limit($data['page_size'])
  1683. ->offset(($data['page'] - 1) * $data['page_size'])
  1684. ->get();
  1685. $count = Good::where($where)
  1686. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1687. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1688. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1689. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1690. ->orderBy("updated_at", "desc")->count();
  1691. $data = [
  1692. 'rows' => $result->toArray(),
  1693. 'count' => $count,
  1694. ];
  1695. if (empty($result)) {
  1696. return Result::error("此栏目暂无相关产品", 0);
  1697. }
  1698. return Result::success($data);
  1699. }
  1700. public function getGoodInfo(array $data): array
  1701. {
  1702. $result = Good::where('id', $data['id'])->first();
  1703. if (empty($result)) {
  1704. return Result::error("此产品不存在", 0);
  1705. }
  1706. return Result::success($result);
  1707. }
  1708. public function addGood(array $data): array
  1709. {
  1710. // unset($data['city_arr_id']);
  1711. // unset($data['cat_arr_id']);
  1712. $data['city_id'] = end($data['city_arr_id']);
  1713. $data['catid'] = end($data['cat_arr_id']);
  1714. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1715. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1716. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1717. unset($data['imgUrl']);
  1718. $result = Good::insert($data);
  1719. if (empty($result)) {
  1720. return Result::error("添加失败", 0);
  1721. }
  1722. return Result::success($result);
  1723. }
  1724. public function updateGood(array $data): array
  1725. {
  1726. $data['city_id'] = end($data['city_arr_id']);
  1727. $data['catid'] = end($data['cat_arr_id']);
  1728. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1729. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1730. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1731. //设置东八区
  1732. date_default_timezone_set('Asia/Shanghai');
  1733. $data['updated_at'] = date('Y-m-d H:i:s');
  1734. $result = Good::where('id', $data['id'])->update($data);
  1735. if (empty($result)) {
  1736. return Result::error("更新失败", 0);
  1737. }
  1738. return Result::success($result);
  1739. }
  1740. public function delGood(array $data): array
  1741. {
  1742. $result = Good::where('id', $data['id'])->delete();
  1743. if (empty($result)) {
  1744. return Result::error("删除失败", 0);
  1745. }
  1746. return Result::success($result);
  1747. }
  1748. //20250226 产品列表
  1749. //20250306 求职信息
  1750. public function getJobHuntingList(array $data): array
  1751. {
  1752. $where = [];
  1753. if (isset($data['username']) && !empty($data['username'])) {
  1754. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1755. }
  1756. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1757. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1758. unset($data['type_id']);
  1759. if ($type_id != '10000') {
  1760. $where[] = ['job_hunting.user_id', '=', $user_id];
  1761. }
  1762. $result = JobHunting::where($where)
  1763. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1764. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1765. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1766. ->orderBy("id", "desc")
  1767. ->limit($data['page_size'])
  1768. ->offset(($data['page'] - 1) * $data['page_size'])
  1769. ->get();
  1770. if (empty($result)) {
  1771. return Result::error("查询失败", 0);
  1772. }
  1773. $count = JobHunting::where($where)
  1774. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1775. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1776. ->count();
  1777. $data = [
  1778. 'rows' => $result->toArray(),
  1779. 'count' => $count,
  1780. ];
  1781. return Result::success($data);
  1782. }
  1783. public function addJobHunting(array $data): array
  1784. {
  1785. date_default_timezone_set('Asia/Shanghai');
  1786. unset($data['company_name']);
  1787. unset($data['job_industry']);
  1788. unset($data['job_name']);
  1789. unset($data['department']);
  1790. unset($data['job_timeList']);
  1791. unset($data['job_content']);
  1792. $data['created_at'] = date('Y-m-d H:i:s');
  1793. $data['updated_at'] = date('Y-m-d H:i:s');
  1794. var_dump($data, '-----------------test---------');
  1795. $result = JobHunting::create($data);
  1796. if (empty($result)) {
  1797. return Result::error("添加失败", 0);
  1798. }
  1799. return Result::success($result);
  1800. }
  1801. public function delJobHunting(array $data): array
  1802. {
  1803. $result = JobHunting::where('id', $data['id'])->delete();
  1804. if (empty($result)) {
  1805. return Result::error("删除失败", 0);
  1806. }
  1807. return Result::success($result);
  1808. }
  1809. public function updateJobHunting(array $data): array
  1810. {
  1811. //设置东八区
  1812. date_default_timezone_set('Asia/Shanghai');
  1813. unset($data['company_name']);
  1814. unset($data['job_industry']);
  1815. unset($data['job_name']);
  1816. unset($data['department']);
  1817. unset($data['job_timeList']);
  1818. unset($data['job_content']);
  1819. $data['created_at'] = date('Y-m-d H:i:s');
  1820. $data['updated_at'] = date('Y-m-d H:i:s');
  1821. $result = JobHunting::where('id', $data['id'])->update($data);
  1822. if (empty($result)) {
  1823. return Result::error("更新失败", 0);
  1824. }
  1825. return Result::success($result);
  1826. }
  1827. public function getJobHuntingInfo(array $data): array
  1828. {
  1829. $result = JobHunting::where('id', $data['id'])->first();
  1830. if (empty($result)) {
  1831. return Result::error("查询失败", 0);
  1832. }
  1833. return Result::success($result);
  1834. }
  1835. public function getJobHuntingData(array $data): array
  1836. {
  1837. $jobEnum = JobEnum::get();
  1838. $jobIndustry = JobIndustry::get();
  1839. $jobNature = JobNature::get();
  1840. $jobPosition = JobPosition::get();
  1841. $data = [
  1842. 'jobEnum' => $jobEnum,
  1843. 'jobIndustry' => $jobIndustry,
  1844. 'jobNature' => $jobNature,
  1845. 'jobPosition' => $jobPosition,
  1846. ];
  1847. return Result::success($data);
  1848. }
  1849. public function delJobHuntingInfo(array $data): array
  1850. {
  1851. $result = JobHunting::where('id', $data['id'])->delete();
  1852. return Result::success();
  1853. }
  1854. //20250324 通知,公告,消息
  1855. public function delNotice(array $data): array
  1856. {
  1857. return Result::success();
  1858. }
  1859. public function getNoticeInfo(array $data): array
  1860. {
  1861. $result = Notice::where('id', $data['id'])->first();
  1862. if (empty($result)) {
  1863. return Result::error("查询失败", 0);
  1864. }
  1865. return Result::success($result);
  1866. }
  1867. public function addNotice(array $data): array
  1868. {
  1869. $result = Notice::create($data);
  1870. return Result::success($result);
  1871. }
  1872. public function updateNotice(array $data): array
  1873. {
  1874. $result = Notice::where('id', $data['id'])->update($data);
  1875. return Result::success($result);
  1876. }
  1877. public function getNoticeList(array $data): array
  1878. {
  1879. $result = Notice::where('status', 1)->get();
  1880. return Result::success($result);
  1881. }
  1882. public function getNoticeDetail(array $data): array
  1883. {
  1884. $result = Notice::where('id', $data['id'])->first();
  1885. if (empty($result)) {
  1886. return Result::error("查询失败", 0);
  1887. }
  1888. return Result::success($result);
  1889. }
  1890. public function deleteNotice(array $data): array
  1891. {
  1892. $result = Notice::where('id', $data['id'])->delete();
  1893. return Result::success($result);
  1894. }
  1895. public function getMSG(array $data): array
  1896. {
  1897. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  1898. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  1899. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  1900. $result = [];
  1901. if ($type_id == 1) {
  1902. //最近的5篇已审的文章
  1903. $apply_articale = Article::where('status', 1)
  1904. ->where('admin_user_id', $user_id)
  1905. ->orderBy('updated_at', 'desc')
  1906. ->limit(5)->get();
  1907. //获取5条单聊未读聊天消息
  1908. $chat = ChatRecords::where('is_read', 0)
  1909. ->where('user_id', $user_id)
  1910. ->where('talk_type', 1)
  1911. ->orderBy('created_at', 'desc')
  1912. ->limit(5)->get();
  1913. //获取5条未读群聊信息
  1914. $chat_group = ChatRecords::where('is_read', 0)
  1915. ->where('user_id', $user_id)
  1916. ->where('talk_type', 2)
  1917. ->orderBy('created_at', 'desc')
  1918. ->limit(5)->get();
  1919. $count = count($chat) + count($chat_group) + count($apply_articale);
  1920. $result = [
  1921. 'apply_articale' => $apply_articale,
  1922. 'chat' => $chat,
  1923. 'chat_group' => $chat_group,
  1924. 'count' => $count,
  1925. ];
  1926. } elseif ($type_id == 2) {
  1927. //最近的5篇已审的文章
  1928. $apply_articale = Article::where('status', 1)
  1929. ->where('admin_user_id', $user_id)
  1930. ->limit(5)->get();
  1931. //获取5条单聊未读聊天消息
  1932. $chat = ChatRecords::where('is_read', 0)
  1933. ->where('user_id', $user_id)
  1934. ->where('talk_type', 1)
  1935. ->orderBy('created_at', 'desc')
  1936. ->limit(5)->get();
  1937. //获取5条未读群聊信息
  1938. $chat_group = ChatRecords::where('is_read', 0)
  1939. ->where('user_id', $user_id)
  1940. ->where('talk_type', 2)
  1941. ->orderBy('created_at', 'desc')
  1942. ->limit(5)->get();
  1943. $count = count($chat) + count($chat_group) + count($apply_articale);
  1944. $result = [
  1945. 'apply_articale' => $apply_articale,
  1946. 'chat' => $chat,
  1947. 'chat_group' => $chat_group,
  1948. 'count' => $count,
  1949. ];
  1950. } elseif ($type_id == 3) {
  1951. //最近的5篇已审的文章
  1952. $apply_articale = Article::where('status', 1)
  1953. ->where('admin_user_id', $user_id)
  1954. ->limit(5)->get();
  1955. //获取5条单聊未读聊天消息
  1956. $chat = ChatRecords::where('is_read', 0)
  1957. ->where('user_id', $user_id)
  1958. ->where('talk_type', 1)
  1959. ->orderBy('created_at', 'desc')
  1960. ->limit(5)->get();
  1961. //获取5条未读群聊信息
  1962. $chat_group = ChatRecords::where('is_read', 0)
  1963. ->where('user_id', $user_id)
  1964. ->where('talk_type', 2)
  1965. ->orderBy('created_at', 'desc')
  1966. ->limit(5)->get();
  1967. $count = count($chat) + count($chat_group) + count($apply_articale);
  1968. $result = [
  1969. 'apply_articale' => $apply_articale,
  1970. 'chat' => $chat,
  1971. 'chat_group' => $chat_group,
  1972. 'count' => $count,
  1973. ];
  1974. } elseif ($type_id == 4) {
  1975. //最近的5篇已审的文章
  1976. $apply_articale = Article::where('status', 1)
  1977. ->where('admin_user_id', $user_id)
  1978. ->limit(5)->get();
  1979. $count = count($apply_articale);
  1980. $result = [
  1981. 'apply_articale' => $apply_articale,
  1982. 'count' => $count,
  1983. ];
  1984. } elseif ($type_id == 10000) {
  1985. //获取未审核的5篇文章
  1986. $apply_articale = Article::where('status', 0)
  1987. ->orderBy('updated_at', 'desc')
  1988. ->limit(5)->get();
  1989. //获取5条单聊未读聊天消息
  1990. $chat = ChatRecords::where('is_read', 0)
  1991. ->where('user_id', $user_id)
  1992. ->where('talk_type', 1)
  1993. ->orderBy('created_at', 'desc')
  1994. ->limit(5)->get();
  1995. //获取5条未读群聊信息
  1996. $chat_group = ChatRecords::where('is_read', 0)
  1997. ->where('user_id', $user_id)
  1998. ->where('talk_type', 2)
  1999. ->orderBy('created_at', 'desc')
  2000. ->limit(5)->get();
  2001. $count = count($chat) + count($chat_group) + count($apply_articale);
  2002. $result = [
  2003. 'apply_articale' => $apply_articale,
  2004. 'chat' => $chat,
  2005. 'chat_group' => $chat_group,
  2006. 'count' => $count,
  2007. ];
  2008. } elseif ($type_id == 20000) {
  2009. }
  2010. var_dump($type_id, '-----------------test---------');
  2011. return Result::success($result);
  2012. }
  2013. public function getComplaintList(array $data): array
  2014. {
  2015. $result = Notice::where('status', 1)->get();
  2016. return Result::success($result);
  2017. }
  2018. public function getComplaintInfo(array $data): array
  2019. {
  2020. $result = Notice::where('id', $data['id'])->first();
  2021. if (empty($result)) {
  2022. return Result::error("查询失败", 0);
  2023. }
  2024. return Result::success($result);
  2025. }
  2026. public function addComplaint(array $data): array
  2027. {
  2028. $result = Notice::create($data);
  2029. return Result::success($result);
  2030. }
  2031. public function updateComplaint(array $data): array
  2032. {
  2033. $result = Notice::where('id', $data['id'])->update($data);
  2034. return Result::success($result);
  2035. }
  2036. public function deleteComplaint(array $data): array
  2037. {
  2038. $result = Notice::where('id', $data['id'])->delete();
  2039. return Result::success($result);
  2040. }
  2041. public function getComplainInfo(array $data): array
  2042. {
  2043. $result = Notice::where('id', $data['id'])->first();
  2044. if (empty($result)) {
  2045. return Result::error("查询失败", 0);
  2046. }
  2047. return Result::success($result);
  2048. }
  2049. //20250324 通知,公告,消息
  2050. // 20250306 -------招聘--------fr
  2051. /*
  2052. * 招聘列表
  2053. * */
  2054. public function getJobRecruitingList(array $data): array
  2055. {
  2056. $where = [];
  2057. if(isset($data['keyword']) && !empty($data['keyword'])){
  2058. array_push($where, ['job_recruiting.title', 'like', '%'. $data['keyword']. '%']);
  2059. }
  2060. $user = User::where('id', $data['user_id'])->first();
  2061. if(empty($user)){
  2062. return Result::error("用户不存在", 0);
  2063. }
  2064. // 3:企业会员
  2065. if($user['type_id'] == 3){
  2066. array_push($where,['job_recruiting.user_id', $data['user_id']]);
  2067. array_push($where,['job_recruiting.website_id', $data['website_id']]);
  2068. }
  2069. // 如果 $where 为空,则不添加 where 条件
  2070. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2071. return $query->where($where);
  2072. })
  2073. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  2074. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  2075. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  2076. ->orderBy("updated_at", "desc")
  2077. ->offset(($data['page'] - 1) * $data['page_size'])
  2078. ->limit($data['page_size'])
  2079. ->get()
  2080. ->all();
  2081. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2082. return $query->where($where);
  2083. })
  2084. ->count();
  2085. if (empty($result)) {
  2086. return Result::error("暂无招聘信息", 0);
  2087. }
  2088. return Result::success($result);
  2089. }
  2090. /*
  2091. * 招聘信息添加
  2092. * */
  2093. public function addJobRecruiting(array $data): array
  2094. {
  2095. // return Result::success($data);
  2096. $user = User::where('user.id', $data['user_id'])
  2097. ->where('user.status',1)
  2098. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2099. ->select(
  2100. 'user.type_id', 'user.mobile','user.email',
  2101. 'user_info.business_name',
  2102. 'user_info.hy_id',
  2103. 'user_info.company_nature',
  2104. 'user_info.company_size',
  2105. 'user_info.introduction',
  2106. 'user_info.real_name',
  2107. 'user_info.company_url',
  2108. 'user_info.address_arr_id',
  2109. 'user_info.address'
  2110. )
  2111. ->first();
  2112. if(empty($user) || $user['type_id'] != $data['user_type']){
  2113. return Result::error("用户不存在", 0);
  2114. }
  2115. $web = Website::where('id', $data['website_id'])->first();
  2116. if(empty($web)){
  2117. return Result::error("网站不存在", 0);
  2118. }
  2119. // return Result::success($user);
  2120. $data['action_id'] = $data['user_id'];
  2121. $data['user_type'] = $user['type_id'];
  2122. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  2123. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  2124. $data['cat_arr_id'] = isset($data['cat_arr_id'])? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  2125. $data['city_arr_id'] = isset($data['city_arr_id'])? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  2126. // 公司地址 管理员必填
  2127. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  2128. $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2129. // 管理员-企业相关信息
  2130. $company = [
  2131. // 'user_id' => $data['user_id']?? null,
  2132. 'business_name' => $data['business_name']?? null,
  2133. 'company_hy_id' => $data['company_hy_id']?? null,
  2134. 'company_size' => $data['company_size']?? null,
  2135. 'company_nature' => $data['company_nature']?? null,
  2136. 'introduction' => $data['introduction']?? null,
  2137. 'real_name' => $data['real_name']?? null,
  2138. 'mobile' => $data['mobile']?? null,
  2139. 'company_url' => $data['company_url']?? null,
  2140. 'address_arr_id' => $data['address_arr_id']?? null,
  2141. 'address' => $data['address']?? null,
  2142. 'email' => $data['email']?? null,
  2143. ];
  2144. //去掉相关企业信息
  2145. $job = array_diff_key($data, array_flip(array_keys($company)));
  2146. Db::beginTransaction();
  2147. try {
  2148. // 先添加职位相关信息
  2149. $jobId = JobRecruiting::insertGetId($job);
  2150. if (empty($jobId)) {
  2151. Db::rollBack();
  2152. return Result::error("添加失败");
  2153. }
  2154. // 添加公司信息
  2155. $company['user_id'] = $data['user_id']?? null;
  2156. $company['job_id'] = $jobId;
  2157. $company['user_type'] = $user['type_id']?? null;
  2158. $company['website_id'] = $data['website_id']?? null;
  2159. if($user['type_id'] == 10000){
  2160. // 管理员添加企业信息
  2161. // return Result::success($company);
  2162. $companyId = JobCompany::insertGetId($company);
  2163. if (empty($companyId)) {
  2164. Db::rollBack();
  2165. return Result::error("添加失败");
  2166. }
  2167. }else{
  2168. // 企业会员添加企业信息
  2169. $company = [
  2170. 'user_id' => $data['user_id']?? null,
  2171. 'business_name' => $user['business_name']?? null,
  2172. 'company_hy_id' => $user['hy_id']?? null,
  2173. 'company_size' => $user['company_size']?? null,
  2174. 'company_nature' => $user['company_nature']?? null,
  2175. 'introduction' => $user['introduction']?? null,
  2176. 'real_name' => $user['real_name']?? null,
  2177. 'mobile' => $user['mobile']?? null,
  2178. 'company_url' => $user['company_url']?? null,
  2179. 'address_arr_id' => $user['address_arr_id']?? null,
  2180. 'address' => $user['address']?? null,
  2181. 'email' => $user['email']?? null,
  2182. 'website_id' => $data['website_id']?? null,
  2183. 'user_type' => $user['type_id']?? null,
  2184. 'job_id' => $jobId,
  2185. ];
  2186. $companyId = JobCompany::insertGetId($company);
  2187. if (empty($companyId)) {
  2188. Db::rollBack();
  2189. return Result::error("添加失败");
  2190. }
  2191. // return Result::success($company);
  2192. }
  2193. Db::commit();
  2194. } catch (\Exception $e) {
  2195. Db::rollBack();
  2196. return Result::error($e->getMessage(), 0);
  2197. }
  2198. $result = [
  2199. 'job_id' => $jobId,
  2200. 'company_id' => $companyId,
  2201. ];
  2202. if (empty($result)) {
  2203. return Result::error("添加失败", 0);
  2204. }
  2205. return Result::success($result);
  2206. }
  2207. /*
  2208. * 获取招聘信息详情
  2209. * */
  2210. public function getJobRecruitingInfo(array $data): array
  2211. {
  2212. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  2213. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  2214. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2215. ->select('job_recruiting.*', 'website.website_name as website_name',
  2216. 'job_company.business_name',
  2217. 'job_company.company_hy_id',
  2218. 'job_company.company_size',
  2219. 'job_company.company_nature',
  2220. 'job_company.introduction',
  2221. 'job_company.real_name',
  2222. 'job_company.mobile',
  2223. 'job_company.company_url',
  2224. 'job_company.address_arr_id',
  2225. 'job_company.address',
  2226. 'job_company.email'
  2227. )
  2228. ->first();
  2229. if(empty($result)){
  2230. return Result::error("招聘信息不存在", 0);
  2231. }
  2232. // return Result::success($job);
  2233. return Result::success($result);
  2234. }
  2235. /*
  2236. * 修改招聘信息
  2237. * */
  2238. public function upJobRecruiting(array $data): array
  2239. {
  2240. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  2241. // return Result::success($job);
  2242. if(empty($job)){
  2243. return Result::error("招聘信息不存在", 0);
  2244. }
  2245. $user = User::where('id', $data['user_id'])->first();
  2246. // return Result::success($user);
  2247. if(empty($user) || $user['type_id']!= $data['user_type']){
  2248. return Result::error("用户不存在", 0);
  2249. }
  2250. if($user['type_id']==3 && $job['user_id']!= $user['id']){
  2251. return Result::error("用户暂无权限修改此招聘信息!", 0);
  2252. }
  2253. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  2254. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  2255. $data['cat_arr_id'] = isset($data['cat_arr_id'])? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  2256. $data['city_arr_id'] = isset($data['city_arr_id'])? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  2257. // 公司地址 管理员必填
  2258. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  2259. $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2260. // 管理员-企业相关信息
  2261. $company = [
  2262. 'business_name' => $data['business_name']?? null,
  2263. 'company_hy_id' => $data['hy_id']?? null,
  2264. 'company_size' => $data['company_size']?? null,
  2265. 'company_nature' => $data['company_nature']?? null,
  2266. 'introduction' => $data['introduction']?? null,
  2267. 'real_name' => $data['real_name']?? null,
  2268. 'mobile' => $data['mobile']?? null,
  2269. 'company_url' => $data['company_url']?? null,
  2270. 'address_arr_id' => $data['address_arr_id']?? null,
  2271. 'address' => $data['address']?? null,
  2272. 'email' => $data['email']?? null,
  2273. ];
  2274. //去掉相关企业信息
  2275. $data = array_diff_key($data, array_flip(array_keys($company)));
  2276. $jobId = $data['id'];
  2277. $web = $data['website_id'];
  2278. $data['action_id'] = $data['user_id'];
  2279. unset($data['user_id']);
  2280. unset($data['user_type']);
  2281. unset($data['id']);
  2282. unset($data['website_id']);
  2283. // return Result::success($data);
  2284. Db::beginTransaction();
  2285. try {
  2286. // 管理员修改招聘信息
  2287. if($user['type_id'] == 10000){
  2288. $data['website_id'] = $web;
  2289. $company['website_id'] = $data['website_id'];
  2290. }
  2291. // Db::rollBack();
  2292. // return Result::success($company);
  2293. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  2294. if (empty($result['job'])) {
  2295. Db::rollBack();
  2296. return Result::error("修改招聘信息失败");
  2297. }
  2298. // 管理员修改企业相关信息
  2299. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  2300. if (empty($result['company'])) {
  2301. Db::rollBack();
  2302. return Result::error("修改企业相关信息失败");
  2303. }
  2304. Db::commit();
  2305. // return Result::success($result);
  2306. } catch (\Exception $e) {
  2307. Db::rollBack();
  2308. return Result::error($e->getMessage(), 0);
  2309. }
  2310. return Result::success($result);
  2311. }
  2312. /*
  2313. * 招聘信息删除
  2314. * */
  2315. public function delJobRecruiting(array $data): array
  2316. {
  2317. $user = User::where('id', $data['user_id'])->first();
  2318. if(empty($user)){
  2319. return Result::error("用户不存在", 0);
  2320. }
  2321. $job = JobRecruiting::where('id', $data['id'])->first();
  2322. if(empty($job)){
  2323. return Result::error("招聘信息不存在", 0);
  2324. }
  2325. if($user['type_id']==3 && $job['user_id']!= $user['id']){
  2326. return Result::error("用户暂无权限修改此招聘信息!", 0);
  2327. }
  2328. Db::beginTransaction();
  2329. try {
  2330. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  2331. if (empty($result['job'])) {
  2332. Db::rollBack();
  2333. return Result::error("删除招聘信息失败");
  2334. }
  2335. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  2336. if (empty($result['company'])) {
  2337. Db::rollBack();
  2338. return Result::error("删除企业相关信息失败");
  2339. }
  2340. Db::commit();
  2341. } catch (\Exception $e) {
  2342. Db::rollBack();
  2343. return Result::error($e->getMessage(), 0);
  2344. }
  2345. return Result::success($result);
  2346. }
  2347. /*
  2348. * 获取公司信息
  2349. * */
  2350. public function getJobCompany(array $data): array
  2351. {
  2352. $user = User::where('user.id', $data['user_id'])
  2353. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2354. ->select('user.user_name','user.mobile','user.email','user.type_id', 'user_info.*')
  2355. ->first();
  2356. // return Result::success($user);
  2357. if(empty($user)){
  2358. return Result::error("用户不存在", 0);
  2359. }
  2360. if($user['type_id'] == 3){
  2361. $result = [
  2362. // 'id' => 0,
  2363. 'user_id' => $data['user_id'],
  2364. 'website_id' => $data['website_id'],
  2365. 'business_name' => $user['business_name'], // 企业名称
  2366. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  2367. 'company_nature' => $user['company_nature'], // 公司性质
  2368. 'company_size' => $user['company_size'], // 公司规模
  2369. 'introduction' => $user['introduction'], // 公司简介
  2370. 'real_name' => $user['real_name'], // 企业联系人
  2371. 'mobile' => $user['mobile'], // 企业联系电话
  2372. 'company_url' => $user['company_url'], // 企业网址
  2373. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  2374. 'address' => $user['address'], // 企业地址
  2375. 'email' => $user['email'], // 企业邮箱
  2376. ];
  2377. }else{
  2378. return Result::error("用户类型错误", 0);
  2379. }
  2380. if(empty($result)){
  2381. return Result::error("公司信息不存在", 0);
  2382. }
  2383. return Result::success($result);
  2384. }
  2385. /*
  2386. * 修改公司信息
  2387. * */
  2388. public function upJobCompany(array $data): array
  2389. {
  2390. // return Result::success($data);
  2391. $user = User::where('user.id', $data['user_id'])
  2392. ->where('user.status',1)
  2393. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2394. ->select('user.user_name','user.type_id', 'user_info.*')
  2395. ->first();
  2396. if(empty($user)){
  2397. return Result::error("用户不存在", 0);
  2398. }
  2399. $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2400. $company = [
  2401. 'business_name' => $data['business_name'], // 企业名称
  2402. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  2403. 'company_nature' => $data['company_nature'], // 公司性质
  2404. 'company_size' => $data['company_size'], // 公司规模
  2405. 'introduction' => $data['introduction'], // 公司简介
  2406. 'real_name' => $data['real_name'], // 企业联系人
  2407. 'company_url' => $data['company_url'], // 企业网址
  2408. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  2409. 'address' => $data['address'], // 企业详细地址
  2410. ];
  2411. if($user['type_id'] == 3){
  2412. $result['user'] = User::where('user.id', $data['user_id'])->update([
  2413. 'mobile' => $data['mobile'], // 企业联系电话
  2414. 'email' => $data['email'], // 企业邮箱
  2415. ]);
  2416. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  2417. 'business_name' => $data['business_name'], // 企业名称
  2418. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  2419. 'company_nature' => $data['company_nature'], // 公司性质
  2420. 'company_size' => $data['company_size'], // 公司规模
  2421. 'introduction' => $data['introduction'], // 公司简介
  2422. 'real_name' => $data['real_name'], // 企业联系人
  2423. 'company_url' => $data['company_url'], // 企业网址
  2424. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  2425. 'address' => $data['address'], // 企业详细地址
  2426. ]);
  2427. $result = JobCompany::where('user_id', $data['user_id'])->update($company);
  2428. }else{
  2429. return Result::error("用户类型错误", 0);
  2430. }
  2431. if(empty($result)){
  2432. return Result::error("修改失败", 0);
  2433. }
  2434. return Result::success($result);
  2435. }
  2436. /*
  2437. * 获取省-市
  2438. * */
  2439. public function getJobRecruitingArea(array $data): array
  2440. {
  2441. if(isset($data['province_id']) && $data['province_id']!=null){
  2442. $result = District::where('pid',$data['pid'])->get()->all();
  2443. }else{
  2444. $result = District::where('level',1)->get()->all();
  2445. }
  2446. if (empty($result)) {
  2447. return Result::error("暂无此省市", 0);
  2448. }
  2449. return Result::success($result);
  2450. }
  2451. /*
  2452. * 获取行业分类
  2453. * */
  2454. public function getIndustry(array $data): array
  2455. {
  2456. $result = JobIndustry::get()->all();
  2457. if (empty($result)) {
  2458. return Result::error("暂无行业分类", 0);
  2459. }
  2460. return Result::success($result);
  2461. }
  2462. /*
  2463. * 获取职位
  2464. * */
  2465. public function getPositionList(array $data): array
  2466. {
  2467. if(isset($data['zwpid']) && $data['zwpid']!=null){
  2468. $result = JobPosition::where('zwpid',$data['zwpid'])->get()->all();
  2469. }else{
  2470. $result = JobPosition::where('zwpid',0)->get()->all();
  2471. }
  2472. if (empty($result)) {
  2473. return Result::error("暂无此职位", 0);
  2474. }
  2475. return Result::success($result);
  2476. }
  2477. /*
  2478. * 获取工作性质-菜单
  2479. * */
  2480. public function getJobNature(array $data): array
  2481. {
  2482. $result = JobEnum::where('egroup','nature')->get()->all();
  2483. if (empty($result)) {
  2484. return Result::error("暂无工作性质", 0);
  2485. }
  2486. return Result::success($result);
  2487. }
  2488. /*
  2489. * 获取工作经验-菜单
  2490. * */
  2491. public function getExperience(array $data): array
  2492. {
  2493. $result = JobEnum::where('egroup','years')->get()->all();
  2494. if (empty($result)) {
  2495. return Result::error("暂无工作经验", 0);
  2496. }
  2497. return Result::success($result);
  2498. }
  2499. /*
  2500. * 获取学历-菜单
  2501. * */
  2502. public function getEducation(array $data): array
  2503. {
  2504. $result = JobEnum::where('egroup','education')->get()->all();
  2505. if (empty($result)) {
  2506. return Result::error("暂无学历", 0);
  2507. }
  2508. return Result::success($result);
  2509. }
  2510. /*
  2511. * 获取薪资-菜单
  2512. * */
  2513. public function getSalary(array $data): array
  2514. {
  2515. $result = JobEnum::where('egroup','income')->get()->all();
  2516. if (empty($result)) {
  2517. return Result::error("暂无薪资", 0);
  2518. }
  2519. return Result::success($result);
  2520. }
  2521. /*
  2522. * 获取语言-菜单
  2523. * */
  2524. public function getLanguage(array $data): array
  2525. {
  2526. $result = JobEnum::where('egroup','language')->get()->all();
  2527. if (empty($result)) {
  2528. return Result::error("暂无语言", 0);
  2529. }
  2530. return Result::success($result);
  2531. }
  2532. /*
  2533. * 获取掌握程度-菜单
  2534. * */
  2535. public function getLevel(array $data): array
  2536. {
  2537. $result = JobEnum::where('egroup','languagetype')->get()->all();
  2538. if (empty($result)) {
  2539. return Result::error("暂无工作性质", 0);
  2540. }
  2541. return Result::success($result);
  2542. }
  2543. // 公司信息
  2544. /*
  2545. * 获取公司性质-菜单
  2546. * */
  2547. public function getCompanyNature(array $data): array
  2548. {
  2549. $result = JobNature::get()->all();
  2550. if (empty($result)) {
  2551. return Result::error("暂无公司性质", 0);
  2552. }
  2553. return Result::success($result);
  2554. }
  2555. /*
  2556. * 获取公司规模-菜单
  2557. * */
  2558. public function getCompanySize(array $data): array
  2559. {
  2560. $result = JobEnum::where('egroup','cosize')->get()->all();
  2561. if (empty($result)) {
  2562. return Result::error("暂无公司规模", 0);
  2563. }
  2564. return Result::success($result);
  2565. }
  2566. // 20250306 招聘
  2567. }