NewsService.php 122 KB

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