NewsService.php 157 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778
  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\Book;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\jobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  46. class NewsService implements NewsServiceInterface
  47. {
  48. /**
  49. * 获取导航池列表
  50. * @param array $data
  51. * @return array
  52. */
  53. public function getCategoryList(array $data): array
  54. {
  55. $search = $data['name'] ?? '';
  56. $page = (int)($data['page'] ?? 1);
  57. $perPage = (int)($data['pageSize'] ?? 10);
  58. // 1. 查出所有匹配的分类id
  59. if ($search) {
  60. $matchedIds = Category::where('name', 'like', "%{$search}%")->pluck('id')->toArray();
  61. if (empty($matchedIds)) {
  62. return Result::success(['rows' => [], 'total' => 0]);
  63. }
  64. // 2. 递归查所有父级,直到一级分类
  65. $idsStr = implode(',', $matchedIds);
  66. $sql = "
  67. WITH RECURSIVE parents AS (
  68. SELECT * FROM category WHERE id IN ($idsStr)
  69. UNION ALL
  70. SELECT c.* FROM category c
  71. INNER JOIN parents p ON c.id = p.pid
  72. )
  73. SELECT * FROM parents
  74. ";
  75. $parents = Db::select($sql);
  76. $parentIds = [];
  77. foreach ($parents as $row) {
  78. if ($row->pid == 0) {
  79. $parentIds[] = $row->id;
  80. }
  81. }
  82. $parentIds = array_unique($parentIds);
  83. } else {
  84. // 没有搜索,一级分类就是根
  85. $parentIds = Category::where('pid', 0)->pluck('id')->toArray();
  86. }
  87. // 3. 一级分类分页
  88. $total = count($parentIds);
  89. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  90. if (empty($parentIds)) {
  91. return Result::success(['rows' => [], 'total' => $total]);
  92. }
  93. // 4. 递归查所有子孙
  94. $idsStr = implode(',', $parentIds);
  95. $sql = "
  96. WITH RECURSIVE subcategories AS (
  97. SELECT * FROM category WHERE id IN ($idsStr)
  98. UNION ALL
  99. SELECT c.* FROM category c
  100. INNER JOIN subcategories s ON c.pid = s.id
  101. )
  102. SELECT * FROM subcategories ORDER BY updated_at DESC
  103. ";
  104. $allCategories = Db::select($sql);
  105. // 5. 组装树结构
  106. $categoryMap = [];
  107. foreach ($allCategories as $cat) {
  108. $cat = (array)$cat;
  109. $cat['children'] = [];
  110. $categoryMap[$cat['id']] = $cat;
  111. }
  112. foreach ($categoryMap as $id => &$cat) {
  113. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  114. $categoryMap[$cat['pid']]['children'][] = &$cat;
  115. }
  116. }
  117. unset($cat);
  118. $categoryTree = [];
  119. foreach ($parentIds as $id) {
  120. if (isset($categoryMap[$id])) {
  121. $categoryTree[] = $categoryMap[$id];
  122. }
  123. }
  124. return Result::success([
  125. 'rows' => $categoryTree,
  126. 'total' => $total,
  127. ]);
  128. }
  129. private function findMatchedCategories($search)
  130. {
  131. if ($search) {
  132. return Category::where('name', 'like', "%{$search}%")
  133. ->orderBy('updated_at', 'desc')
  134. ->get();
  135. }
  136. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  137. ->get();
  138. }
  139. private function findAllParents($categories)
  140. {
  141. $allCategories = [];
  142. foreach ($categories as $category) {
  143. $parentId = $category->pid;
  144. while ($parentId > 0) {
  145. $parent = Category::find($parentId);
  146. if ($parent) {
  147. $allCategories[$parent->id] = $parent;
  148. $parentId = $parent->pid;
  149. } else {
  150. break;
  151. }
  152. }
  153. $allCategories[$category->id] = $category;
  154. }
  155. return array_values($allCategories);
  156. }
  157. private function buildCategoryTree($category, $allRequiredCategories)
  158. {
  159. $categoryData = $category->toArray();
  160. $children = [];
  161. foreach ($allRequiredCategories as $c) {
  162. if ($c->pid === $category->id) {
  163. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  164. }
  165. }
  166. if (!empty($children)) {
  167. $categoryData['children'] = $children;
  168. }
  169. return $categoryData;
  170. }
  171. public function myCategoryList(array $data): array
  172. {
  173. $sszq = $data['sszq'] ?? '';
  174. unset($data['sszq']);
  175. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  176. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  177. $where[] = [
  178. 'pid',
  179. '=',
  180. $data['pid'],
  181. ];
  182. if (isset($data['name'])) {
  183. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  184. }
  185. var_dump($where);
  186. //根据分类id,从category表中取出分类信息
  187. $result = Category::where($where)
  188. ->whereIn('category.id', $catorytids)
  189. ->select('category.*', 'category.id as category_id')->get();
  190. if (empty($result)) {
  191. return Result::error("没有栏目数据");
  192. }
  193. return Result::success($result);
  194. }
  195. /**
  196. * @param array $data
  197. * @return array
  198. */
  199. public function categoryList(array $data): array
  200. {
  201. $where[] = [
  202. 'pid',
  203. '=',
  204. $data['pid'],
  205. ];
  206. if (isset($data['name'])) {
  207. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  208. }
  209. var_dump($where);
  210. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  211. if (empty($result)) {
  212. return Result::error("没有栏目数据");
  213. }
  214. return Result::success($result);
  215. }
  216. /**
  217. * @param array $data
  218. * @return array
  219. */
  220. public function addCategory(array $data): array
  221. {
  222. if (isset($data['id'])) {
  223. unset($data['id']);
  224. }
  225. $id = Category::insertGetId($data);
  226. if (empty($id)) {
  227. return Result::error("添加失败");
  228. }
  229. return Result::success(['id' => $id]);
  230. }
  231. /**
  232. * @param array $data
  233. * @return array
  234. */
  235. public function delCategory(array $data): array
  236. {
  237. Db::beginTransaction();
  238. try {
  239. $categoryList = Category::where(['pid' => $data['id']])->get();
  240. if ($categoryList->toArray()) {
  241. Db::rollBack();
  242. return Result::error("分类下面有子分类不能删除");
  243. }
  244. $articleList = Article::where(['catid' => $data['id']])->get();
  245. if ($articleList->toArray()) {
  246. Db::rollBack();
  247. return Result::error("分类下面有资讯不能删除");
  248. }
  249. $result = Category::where($data)->delete();
  250. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  251. if (!$result) {
  252. return Result::error("删除失败");
  253. }
  254. return Result::success($result);
  255. Db::commit();
  256. } catch (\Exception $e) {
  257. Db::rollBack();
  258. return Result::error("删除失败");
  259. }
  260. }
  261. /**
  262. * @param array $data
  263. * @return array
  264. */
  265. public function updateCategory(array $data): array
  266. {
  267. $where = [
  268. 'id' => $data['id'],
  269. ];
  270. $result = Category::where($where)->update($data);
  271. if ($result) {
  272. return Result::success($result);
  273. } else {
  274. return Result::error("更新失败");
  275. }
  276. }
  277. /**
  278. * 获取导航池信息
  279. * @param array $data
  280. * @return array
  281. */
  282. public function getCategoryInfo(array $data): array
  283. {
  284. $where = [
  285. 'id' => $data['id'],
  286. ];
  287. $result = Category::where($where)->first();
  288. if ($result) {
  289. return Result::success($result);
  290. } else {
  291. return Result::error("更新失败");
  292. }
  293. }
  294. /**
  295. * @param array $data
  296. * @return array
  297. */
  298. public function getArticleList(array $data): array
  299. {
  300. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  301. $type_id = $data['type_id'];
  302. unset($data['type_id']);
  303. $user_id = $data['user_id'];
  304. unset($data['user_id']);
  305. $where = [];
  306. $status1 = [];
  307. if (isset($data['id']) && $data['id']) {
  308. array_push($where, ['article.id', '=', $data['id']]);
  309. }
  310. if (isset($data['title']) && $data['title']) {
  311. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  312. }
  313. if (isset($data['category_name']) && $data['category_name']) {
  314. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  315. }
  316. if (isset($data['author']) && $data['author']) {
  317. array_push($where, ['article.author', '=', $data['author']]);
  318. }
  319. if (isset($data['islink']) && $data['islink'] !== "") {
  320. array_push($where, ['article.islink', '=', $data['islink']]);
  321. }
  322. if (isset($data['status']) && $data['status'] !== "") {
  323. array_push($where, ['article.status', '=', $data['status']]);
  324. }
  325. if (isset($data['status1'])) {
  326. $status1 = json_decode(($data['status1']));
  327. }
  328. //不是管理员展示个人数据;
  329. if ($type_id != 10000) {
  330. $where[] = ['article.admin_user_id', '=', $user_id];
  331. }
  332. $rep = Article::where($where)
  333. ->whereNotIn('article.status', [404])
  334. ->when($status1, function ($query) use ($status1) {
  335. if (isset($status1) && $status1) {
  336. $query->whereIn('article.status', $status1);
  337. }
  338. })
  339. ->leftJoin('category', 'article.catid', 'category.id')
  340. ->leftJoin('website_category', function ($join) {
  341. $join->on('article.web_site_id', '=', 'website_category.website_id')
  342. ->on('article.catid', '=', 'website_category.category_id');
  343. })
  344. ->select("article.*", "category.name as category_name", "website_category.alias")
  345. ->orderBy("article.updated_at", "desc")
  346. ->limit($data['pageSize'])
  347. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  348. $count = Article::where($where)->whereNotIn('article.status', [404])
  349. ->when($status1, function ($query) use ($status1) {
  350. if (isset($status1) && $status1) {
  351. $query->whereIn('article.status', $status1);
  352. }
  353. })
  354. ->leftJoin('category', 'article.catid', 'category.id')->count();
  355. $data = [
  356. 'rows' => $rep->toArray(),
  357. 'count' => $count,
  358. ];
  359. if (empty($rep)) {
  360. return Result::error("没有信息数据");
  361. }
  362. return Result::success($data);
  363. }
  364. /**
  365. * @param array $data
  366. * @return array
  367. */
  368. public function addArticle(array $data): array
  369. {
  370. var_dump($data, '----------12-----------1');
  371. unset($data['user_type']);
  372. unset($data['nav_add_pool_id']);
  373. // unset($data['commend_id']);
  374. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  375. Db::beginTransaction();
  376. try {
  377. //处理投票
  378. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  379. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  380. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  381. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  382. unset($data['is_survey']);
  383. unset($data['survey_name']);
  384. unset($data['suvey_array']);
  385. // unset($data['website_id']);
  386. // unset($data['web_site_id']);
  387. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  388. if ($data['hits'] == '') {
  389. $data['hits'] = 0;
  390. }
  391. if ($data['is_original'] == '') {
  392. $data['is_original'] = 0;
  393. }
  394. if ($data['status'] == '') {
  395. $data['status'] = 0;
  396. }
  397. $articleData = $data;
  398. unset($articleData['content']);
  399. //自动处理缩略图、关键字、描述
  400. if ($articleData['imgurl'] == '') {
  401. //如果没有图,设置level=0
  402. $levelArr = json_decode($articleData['level'], true);
  403. var_dump($levelArr, '----------levelArr-----------1');
  404. //content中提取图片第一个图,正则提取
  405. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  406. preg_match_all($reg, $data['content'], $matches);
  407. if (isset($matches[1][0])) {
  408. //截取varchar240
  409. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  410. //如果有图,设置level=3
  411. if (!in_array(3, $levelArr)) {
  412. $levelArr[] = 3;
  413. }
  414. $articleData['level'] = json_encode($levelArr);
  415. } else {
  416. if (!in_array(0, $levelArr)) {
  417. $levelArr[] = 0;
  418. }
  419. $articleData['level'] = json_encode($levelArr);
  420. }
  421. }
  422. var_dump($articleData['level'], '----------$articleData[level]----------1');
  423. if ($articleData['keyword'] == '') {
  424. //提取标题+内容中的关键词
  425. $articleData['keyword'] = $data['title'];
  426. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  427. Jieba::init(); // 初始化 jieba-php
  428. Finalseg::init();
  429. $segList = Jieba::cut($articleData['keyword']);
  430. $segList1 = array_slice($segList, 0, 8);
  431. $articleData['keyword'] = implode(',', $segList1);
  432. }
  433. if ($articleData['introduce'] == '') {
  434. //提取内容中的描述
  435. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  436. }
  437. $id = Article::insertGetId($articleData);
  438. $articleDataContent = [
  439. 'article_id' => $id,
  440. 'content' => $data['content'],
  441. ];
  442. ArticleData::insertGetId($articleDataContent);
  443. //处理投票
  444. if ($is_survey == 1) {
  445. //生成年月日时分秒+8位随机数
  446. $uuid = date('YmdHis') . rand(10000000, 99999999);
  447. var_dump($suvey_array, 'suvey_array________');
  448. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  449. var_dump($suveys_array, '---------------------1');
  450. var_dump($suvey_array, '---------------------2');
  451. $suvey_data = [];
  452. foreach ($suveys_array as $key => $value) {
  453. if ($value == '') {
  454. continue;
  455. }
  456. if (is_array($value)) {
  457. $suvey_data[] = [
  458. 'sur_id' => $uuid,
  459. 'art_id' => $id,
  460. 'website_id' => $website_id ?? 2,
  461. 'survey_name' => $survey_name,
  462. 'choice_name' => $value[1],
  463. 'is_other' => 1,
  464. 'other_id' => 0,
  465. 'results' => 0,
  466. ];
  467. } else {
  468. $suvey_data[] = [
  469. 'sur_id' => $uuid,
  470. 'art_id' => $id,
  471. 'website_id' => $website_id ?? 2,
  472. 'survey_name' => $survey_name,
  473. 'choice_name' => $value,
  474. 'is_other' => 0,
  475. 'other_id' => 0,
  476. 'results' => 0,
  477. ];
  478. }
  479. if (empty($suvey_data)) {
  480. throw new \Exception("投票数据为空");
  481. }
  482. }
  483. $result = ArticleSurvey::insert($suvey_data);
  484. if (!$result) {
  485. throw new \Exception("投票失败,ArticleSurvey插入失败");
  486. }
  487. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  488. if (!$result) {
  489. throw new \Exception("投票失败,更新主表失败");
  490. }
  491. }
  492. Db::commit();
  493. return Result::success(['id' => $id]);
  494. } catch (\Throwable $ex) {
  495. Db::rollBack();
  496. var_dump($ex->getMessage());
  497. return Result::error("创建失败", 0);
  498. }
  499. }
  500. /**
  501. * @param array $data
  502. * @return array
  503. */
  504. public function delArticle(array $data): array
  505. {
  506. $result = Article::where($data)->delete();
  507. //survey投票删除
  508. articleSurvey::where(['art_id' => $data['id']])->delete();
  509. if (!$result) {
  510. return Result::error("删除失败");
  511. }
  512. return Result::success($result);
  513. }
  514. /**
  515. * @param array $data
  516. * @return array
  517. */
  518. public function updateArticle(array $data): array
  519. {
  520. var_dump($data, '----------12-----------1');
  521. Db::beginTransaction();
  522. unset($data['user_type']);
  523. // unset($data['web_site_id']);
  524. unset($data['nav_add_pool_id']);
  525. try {
  526. //处理投票
  527. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  528. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  529. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  530. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  531. unset($data['is_survey']);
  532. unset($data['survey_name']);
  533. unset($data['suvey_array']);
  534. unset($data['website_id']);
  535. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  536. if ($data['hits'] == '') {
  537. $data['hits'] = 0;
  538. }
  539. if ($data['is_original'] == '') {
  540. $data['is_original'] = 0;
  541. }
  542. if ($data['status'] == '') {
  543. $data['status'] = 0;
  544. }
  545. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  546. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  547. $articleData = $data;
  548. unset($articleData['content']);
  549. unset($articleData['status_name']);
  550. unset($articleData['name']);
  551. unset($articleData['content']);
  552. unset($articleData['pid_arr']);
  553. unset($articleData['pid']);
  554. //自动处理缩略图、关键字、描述
  555. if ($articleData['imgurl'] == '') {
  556. //如果没有图,设置level=0
  557. $levelArr = json_decode($articleData['level'], true);
  558. var_dump($levelArr, '----------levelArr-----------1');
  559. //content中提取图片第一个图,正则提取
  560. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  561. preg_match_all($reg, $data['content'], $matches);
  562. if (isset($matches[1][0])) {
  563. //截取varchar240
  564. // 截取到第一个<
  565. $articleData['imgurl'] = $matches[1][0];
  566. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  567. $pos = strpos($articleData['imgurl'], '"');
  568. if ($pos !== false) {
  569. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  570. }
  571. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  572. //如果有图,设置level=3
  573. if (!in_array(3, $levelArr)) {
  574. $levelArr[] = 3;
  575. }
  576. $articleData['level'] = json_encode($levelArr);
  577. } else {
  578. if (!in_array(0, $levelArr)) {
  579. $levelArr[] = 0;
  580. }
  581. $articleData['level'] = json_encode($levelArr);
  582. }
  583. }
  584. var_dump($articleData['level'], '----------$articleData[level]----------1');
  585. if ($articleData['keyword'] == '') {
  586. //提取标题+内容中的关键词
  587. $articleData['keyword'] = $data['title'];
  588. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  589. Jieba::init(); // 初始化 jieba-php
  590. Finalseg::init();
  591. $segList = Jieba::cut($articleData['keyword']);
  592. $segList1 = array_slice($segList, 0, 8);
  593. $articleData['keyword'] = implode(',', $segList1);
  594. }
  595. if ($articleData['introduce'] == '') {
  596. //提取内容中的描述
  597. $articleData['introduce'] = substr(preg_replace('/\s+/', '', strip_tags($data['content'])), 0, 100);
  598. // substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  599. }
  600. $id = Article::where(['id' => $data['id']])->update($articleData);
  601. $articleDataContent = [
  602. 'content' => $data['content'],
  603. ];
  604. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  605. //处理投票
  606. $id = $data['id'];
  607. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  608. var_dump($suvey_array, 'suvey_array________delete');
  609. //处理投票
  610. if ($is_survey == 1) {
  611. //生成年月日时分秒+8位随机数
  612. $uuid = date('YmdHis') . rand(10000000, 99999999);
  613. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  614. var_dump($suveys_array, '---------------------1');
  615. $suvey_data = [];
  616. if (is_array($suveys_array)) {
  617. foreach ($suveys_array as $key => $value) {
  618. if ($value == '') {
  619. continue;
  620. }
  621. if (is_array($value)) {
  622. $suvey_data[] = [
  623. 'sur_id' => $uuid,
  624. 'art_id' => $id,
  625. 'website_id' => $website_id ?? 2,
  626. 'survey_name' => $survey_name,
  627. 'choice_name' => $value[1],
  628. 'is_other' => 1,
  629. 'other_id' => 0,
  630. 'results' => 0,
  631. ];
  632. } else {
  633. $suvey_data[] = [
  634. 'sur_id' => $uuid,
  635. 'art_id' => $id,
  636. 'website_id' => $website_id ?? 2,
  637. 'survey_name' => $survey_name,
  638. 'choice_name' => $value,
  639. 'is_other' => 0,
  640. 'other_id' => 0,
  641. 'results' => 0,
  642. ];
  643. }
  644. if (empty($suvey_data)) {
  645. throw new \Exception("投票数据为空");
  646. }
  647. }
  648. }
  649. $result = ArticleSurvey::insert($suvey_data);
  650. if (!$result) {
  651. throw new \Exception("投票失败");
  652. }
  653. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  654. if (!$result) {
  655. throw new \Exception("投票失败");
  656. }
  657. } else {
  658. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  659. }
  660. Db::commit();
  661. return Result::success([]);
  662. } catch (\Throwable $ex) {
  663. Db::rollBack();
  664. var_dump($ex->getMessage());
  665. return Result::error("更新失败" . $ex->getMessage(), 0);
  666. }
  667. }
  668. /**
  669. * 更新资讯状态
  670. * @param array $data
  671. * @return array
  672. */
  673. public function upArticleStatus(array $data): array
  674. {
  675. $result = Article::where(['id' => $data['id']])->update($data);
  676. if ($result) {
  677. return Result::success();
  678. } else {
  679. return Result::error("更新状态失败", 0);
  680. }
  681. }
  682. /**
  683. * @param array $data
  684. * @return array
  685. */
  686. public function getArticleInfo(array $data): array
  687. {
  688. $where = [
  689. 'article.id' => $data['id'],
  690. // 'article.status' => 1,
  691. ];
  692. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  693. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  694. $info = $result;
  695. // var_dump($info, 'info');
  696. $info['survey_array'] = $articleSurvey;
  697. if ($result) {
  698. return Result::success($info);
  699. } else {
  700. return Result::error("查询失败", 0);
  701. }
  702. }
  703. /**
  704. * 获取新闻
  705. * @param array $data
  706. * @return array
  707. */
  708. public function getWebsiteArticlett(array $data): array
  709. {
  710. // return Result::success($data['website_id']);
  711. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  712. $category = array_values(array_unique($category->toArray()));
  713. if ($category) {
  714. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  715. $where = [
  716. 'status' => 1,
  717. ];
  718. var_dump($data, 'data-----------------');
  719. // level=7 根据文章key来匹配文章
  720. if (isset($data['level']) && $data['level'] == 7) {
  721. // 根据文章id获取key
  722. // $data['id'] = 50142;
  723. if (isset($data['id']) && !empty($data['id'])) {
  724. $keyword = Article::where('id', $data['id'])->value('keyword');
  725. $keywordArray = explode(',', $keyword);
  726. $whereL7 = [];
  727. foreach ($keywordArray as $k => $v) {
  728. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  729. }
  730. // 原始查询
  731. $result['level7'] = Article::where($whereL7)
  732. ->when(!empty($data['imgnum']), function ($query) use ($data) {
  733. $query->where('article.imgurl', '!=', '')
  734. ->select('article.*')
  735. ->offset($data['placeid'])
  736. ->limit($data['imgnum']);
  737. })
  738. ->when(!empty($data['textnum']), function ($query) use ($data) {
  739. $query->select('article.*')
  740. ->offset($data['placeid'])
  741. ->limit($data['textnum']);
  742. })
  743. ->orderBy('updated_at', 'desc')
  744. ->get()
  745. ->map(function ($article) use ($data) {
  746. $catid = $article->catid;
  747. $pinyin = '';
  748. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  749. if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
  750. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  751. if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
  752. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  753. }
  754. } else {
  755. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  756. }
  757. $article->pinyin = $pinyin;
  758. return $article;
  759. });
  760. if (empty($result)) {
  761. return Result::success();
  762. }
  763. return Result::success($result);
  764. } else {
  765. return Result::error("参数错误level=7,id不能为空", 0);
  766. }
  767. }
  768. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  769. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  770. var_dump($where, 'where-----------------');
  771. // 初始化基础查询
  772. $query = Article::where($where)
  773. ->whereIn("catid", $category)
  774. ->where(function ($query) use ($data) {
  775. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  776. ->orWhereNull("ignore_ids");
  777. });
  778. // 处理 level 相关查询条件
  779. $query->when($data['level'] == 5, function ($query) {
  780. $query->inRandomOrder()
  781. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  782. })->when($data['level'] == 4, function ($query) {
  783. $query->orderBy("article.updated_at", "desc");
  784. })->when(!empty($data['level']), function ($query) use ($data) {
  785. if ($data['level'] != 4 && $data['level'] != 5) {
  786. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  787. ->orderBy("article.updated_at", "desc");
  788. }
  789. });
  790. // 初始化结果数组
  791. $result = [];
  792. // $input = $data['website_id'];
  793. // 处理图片新闻查询
  794. if (!empty($data['imgnum'])) {
  795. // 原错误提示表明 cleanBindings 方法需要传入数组类型的参数,而实际传入了 null。
  796. // 这里克隆查询构建器,确保绑定参数为数组,避免该错误。
  797. $imgQuery = clone $query;
  798. if ($imgQuery->getBindings() === null) {
  799. $imgQuery->setBindings([]);
  800. }
  801. $result['img'] = $imgQuery->where('article.imgurl', '!=', '')
  802. ->select(
  803. 'article.id',
  804. 'article.title',
  805. 'article.imgurl',
  806. 'article.author',
  807. 'article.updated_at',
  808. 'article.introduce',
  809. 'article.islink',
  810. 'article.linkurl',
  811. 'article.copyfrom',
  812. 'article.catid'
  813. )
  814. ->offset($data['placeid'])
  815. ->limit($data['imgnum'])
  816. ->get()
  817. ->map(function ($article) use ($data) {
  818. $catid = $article->catid;
  819. $pinyin = '';
  820. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  821. if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
  822. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  823. if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
  824. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  825. }
  826. } else {
  827. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  828. }
  829. $article->pinyin = $pinyin;
  830. return $article;
  831. });
  832. // $result['img'] = $this->processArticles($img_article, $input);
  833. }
  834. // 处理文字新闻查询
  835. if (!empty($data['textnum'])) {
  836. $textQuery = clone $query;
  837. $result['text'] = $textQuery
  838. ->select(
  839. 'article.id',
  840. 'article.title',
  841. 'article.imgurl',
  842. 'article.author',
  843. 'article.updated_at',
  844. 'article.introduce',
  845. 'article.islink',
  846. 'article.linkurl',
  847. 'article.copyfrom',
  848. 'article.catid'
  849. )
  850. ->offset($data['placeid'])
  851. ->limit($data['textnum'])
  852. ->get()
  853. ->map(function ($article) use ($data) {
  854. $catid = $article->catid;
  855. $pinyin = '';
  856. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  857. if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
  858. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  859. if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
  860. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  861. }
  862. } else {
  863. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  864. }
  865. $article->pinyin = $pinyin;
  866. return $article;
  867. });
  868. // $result['text'] = $this->processArticles($text_article, $input);
  869. }
  870. if (empty($result) || count($result) == 0) {
  871. return Result::error("暂无头条新闻");
  872. }
  873. return Result::success($result);
  874. } else {
  875. return Result::error("本网站下暂无相关栏目", 0);
  876. }
  877. }
  878. /**
  879. * 获取模块新闻
  880. * @param array $data
  881. * @return array
  882. */
  883. public function getWebsiteModelArticles(array $data): array
  884. {
  885. $catid = $data['catid'];
  886. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  887. $category = $category->toArray();
  888. if (!empty($category)) {
  889. $where = [
  890. 'status' => 1,
  891. 'catid' => $catid,
  892. ];
  893. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  894. // 1:文字新闻;2:轮播图;3:图文;
  895. // 级别:0:未分类
  896. // 3:推荐图片
  897. if ($data['level'] == 1) {
  898. $data['level'] = 0;
  899. }
  900. $result = Article::where($where)
  901. ->where(function ($query) use ($data) {
  902. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  903. ->orWhereNull("level")
  904. ->orWhereRaw("level = '[]'");
  905. })
  906. ->where(function ($query) use ($data) {
  907. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  908. ->orWhereNull("ignore_ids");
  909. })
  910. ->orderBy("updated_at", "desc")
  911. ->offset($placeid)
  912. ->limit($data['pagesize'])
  913. ->get();
  914. if (empty($result)) {
  915. return Result::error("此栏目暂无相关新闻", 0);
  916. }
  917. } else {
  918. return Result::error("此网站暂无此栏目", 0);
  919. }
  920. return Result::success($result);
  921. }
  922. /**
  923. *获取新闻列表
  924. * @param array $data
  925. * @return array
  926. */
  927. public function getWebsiteArticleList(array $data): array
  928. {
  929. // return Result::success($data);
  930. $where[] = ['status', '=', 1];
  931. if (isset($data['catid']) && !empty($data['catid'])) {
  932. if (is_array($data['catid'])) {
  933. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  934. array_push($where, ['catid', 'in', $data['catid']]);
  935. } else {
  936. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  937. array_push($where, ['catid', '=', $data['catid']]);
  938. }
  939. if (empty($category)) {
  940. return Result::error("此网站暂无此栏目", 0);
  941. }
  942. }
  943. // return Result::success($where);
  944. $rep = Article::where(function ($query) use ($where) {
  945. foreach ($where as $condition) {
  946. if ($condition[1] === 'in') {
  947. $query->whereIn($condition[0], $condition[2]);
  948. } else {
  949. $query->where($condition[0], $condition[1], $condition[2]);
  950. }
  951. }
  952. })
  953. ->where(function ($query) use ($data) {
  954. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  955. ->orWhereNull("ignore_ids");
  956. })
  957. ->select(
  958. 'article.id',
  959. 'article.title',
  960. 'article.imgurl',
  961. 'article.author',
  962. 'article.updated_at',
  963. 'article.introduce',
  964. 'article.islink',
  965. 'article.linkurl',
  966. 'article.copyfrom',
  967. 'article.catid'
  968. )
  969. ->orderBy("updated_at", "desc")
  970. ->offset(($data['page'] - 1) * $data['pageSize'])
  971. ->limit($data['pageSize'])
  972. ->get()
  973. ->map(function ($article) use ($data) {
  974. $catid = $article->catid ?? 0;
  975. $pinyin = '';
  976. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  977. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  978. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  979. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  980. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  981. }
  982. $article->pinyin = $pinyin;
  983. return $article;
  984. });
  985. $count = Article::where(function ($query) use ($where) {
  986. foreach ($where as $condition) {
  987. if ($condition[1] === 'in') {
  988. $query->whereIn($condition[0], $condition[2]);
  989. } else {
  990. $query->where($condition[0], $condition[1], $condition[2]);
  991. }
  992. }
  993. })->count();
  994. $data = [
  995. 'rows' => $rep->toArray(),
  996. 'count' => $count,
  997. ];
  998. if (empty($rep)) {
  999. return Result::error("没有信息数据");
  1000. }
  1001. return Result::success($data);
  1002. }
  1003. /**
  1004. * 前端-获取新闻详情
  1005. * @param array $data
  1006. * @return array
  1007. */
  1008. public function selectWebsiteArticleInfo(array $data): array
  1009. {
  1010. $where = [
  1011. 'article.id' => $data['id'],
  1012. 'article.status' => 1,
  1013. ];
  1014. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
  1015. ->where(function ($query) use ($data) {
  1016. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1017. ->orWhereNull("ignore_ids");
  1018. })
  1019. ->first();
  1020. if (empty($result)) {
  1021. return Result::error("暂无此新闻!", 0);
  1022. }
  1023. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1024. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1025. ->where('website_category.website_id', $data['website_id'])
  1026. ->where(['website_category.category_id' => $result['catid']])
  1027. ->first();
  1028. if (empty($category)) {
  1029. return Result::error("查询失败", 0);
  1030. }
  1031. //手动推荐文章
  1032. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1033. $commendArticle = Article::whereIn('id', $commend_ids)
  1034. ->where('status', 1)
  1035. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  1036. ->orderBy('updated_at', 'desc')
  1037. ->limit(5)
  1038. ->get();
  1039. $result['category_id'] = $category['category_id'];
  1040. $result['cat_name'] = $category['alias'];
  1041. $result['website_name'] = $category['website_name'] ?? "";
  1042. $result['suffix'] = $category['suffix'] ?? "";
  1043. $result['commendArticle'] = $commendArticle;
  1044. return Result::success($result);
  1045. }
  1046. /**
  1047. * 前端-获取网站调查问卷
  1048. * @param array $data
  1049. * @return array
  1050. */
  1051. public function getWebsiteSurvey(array $data): array
  1052. {
  1053. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1054. $website = Website::where('id', $data['website_id'])->first();
  1055. if (empty($website)) {
  1056. return Result::error("暂无此网站", 0);
  1057. }
  1058. }
  1059. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1060. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1061. if (empty($article)) {
  1062. return Result::error("暂无此文章", 0);
  1063. }
  1064. // return Result::error($data,0);
  1065. $where['art_id'] = $data['art_id'];
  1066. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1067. } else {
  1068. $survey = Article::where(function ($query) {
  1069. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1070. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1071. })
  1072. ->where('status', 1)
  1073. ->where('is_survey', 1)
  1074. ->select('survey_id')
  1075. ->orderBy('updated_at', 'desc')
  1076. ->first();
  1077. if (empty($survey)) {
  1078. return Result::error("暂无调查问卷", 0);
  1079. }
  1080. $where['sur_id'] = $survey['survey_id'];
  1081. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1082. }
  1083. // return Result::success($where);
  1084. $result = ArticleSurvey::where($where)
  1085. ->where(function ($query) {
  1086. $query->where('is_other', 0)
  1087. ->orWhere(function ($subQuery) {
  1088. $subQuery->where('is_other', 1)
  1089. ->where('other_id', 0);
  1090. });
  1091. })
  1092. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1093. ->select('article_survey.*', 'article.survey_type')
  1094. ->get()->all();
  1095. if (empty($result)) {
  1096. return Result::error("此文章暂无调查问卷", 0);
  1097. }
  1098. return Result::success($result);
  1099. }
  1100. /**
  1101. * 前端-添加网站调查问卷选项
  1102. * @param array $data
  1103. * @return array
  1104. */
  1105. public function addWebsiteSurveyOption(array $data): array
  1106. {
  1107. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1108. $website = Website::where('id', $data['website_id'])->first();
  1109. if (empty($website)) {
  1110. return Result::error("暂无此网站", 0);
  1111. }
  1112. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1113. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1114. if (empty($survey)) {
  1115. return Result::error("此调查问卷不可添加选项", 0);
  1116. }
  1117. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1118. $choice = [
  1119. 'art_id' => $survey['art_id'],
  1120. 'website_id' => $data['website_id'],
  1121. 'survey_name' => $survey['survey_name'],
  1122. 'choice_name' => $data['choice_name'],
  1123. 'sur_id' => $survey['sur_id'],
  1124. 'is_other' => 1,
  1125. 'other_id' => $survey['id'],
  1126. ];
  1127. $result = ArticleSurvey::insertGetId($choice);
  1128. if (empty($result)) {
  1129. return Result::error("添加失败", 0);
  1130. }
  1131. return Result::success($result);
  1132. }
  1133. }
  1134. return Result::error("添加失败", 0);
  1135. }
  1136. return Result::error("添加失败", 0);
  1137. }
  1138. /**
  1139. * 前端-调查问卷投票
  1140. * @param array $data
  1141. * @return array
  1142. */
  1143. public function addWebsiteSurveyVote(array $data): array
  1144. {
  1145. // return Result::success($data);
  1146. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1147. $website = Website::where('id', $data['website_id'])->first();
  1148. if (empty($website)) {
  1149. return Result::error("暂无此网站", 0);
  1150. }
  1151. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1152. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1153. // return Result::success($survey);
  1154. if (empty($is_survey)) {
  1155. return Result::error("此调查问卷不存在", 0);
  1156. }
  1157. // return Result::success($survey);
  1158. // 调查问卷类型
  1159. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1160. //多选 若是json型则转化成数组类型
  1161. if (strpos($data['choice_id'], '[') === 0) {
  1162. $data['choice_id'] = json_decode($data['choice_id'], true);
  1163. } else {
  1164. // 单选 也转换成数组
  1165. $data['choice_id'] = [$data['choice_id']];
  1166. }
  1167. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1168. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1169. // ->where('website_id',$data['website_id'])
  1170. ->where('is_other', 1)
  1171. ->where('other_id', 0)
  1172. ->first();
  1173. if (!empty($other)) {
  1174. return Result::error("请选择已有的选项!", 0);
  1175. }
  1176. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1177. // ->where('website_id',$data['website_id'])
  1178. ->where('is_other', 1)
  1179. ->where('other_id', '!=', 0)
  1180. ->first();
  1181. // return Result::success($choice['other']);
  1182. $choice_id = $data['choice_id'];
  1183. if (!empty($choice['other'])) {
  1184. // array_push($data['choice_id'],$choice['other']['other_id']);
  1185. if (!empty($choice_id)) {
  1186. $key = array_search($choice['other']['id'], $choice_id);
  1187. if ($key !== false) {
  1188. unset($choice_id[$key]);
  1189. $choice_id = array_values($choice_id);
  1190. }
  1191. array_push($choice_id, $choice['other']['other_id']);
  1192. } else {
  1193. $choice_id[0] = $choice['other']['other_id'];
  1194. }
  1195. array_push($data['choice_id'], $choice['other']['other_id']);
  1196. }
  1197. // return Result::success($data);
  1198. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1199. // ->where('website_id',$data['website_id'])
  1200. ->increment('results', 1);
  1201. if (empty($choice)) {
  1202. return Result::error("请选择已有的选项!", 0);
  1203. }
  1204. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1205. // ->where('website_id',$data['website_id'])
  1206. ->where('other_id', 0)
  1207. ->get();
  1208. $survey['choice'] = $choice_id;
  1209. return Result::success($survey);
  1210. }
  1211. return Result::error("参数必填!");
  1212. }
  1213. return Result::error("此调查问卷不存在", 0);
  1214. }
  1215. return Result::error("参数必填!");
  1216. }
  1217. /**
  1218. * 后端-获取网站调查问卷列表
  1219. * @param array $data
  1220. * @return array
  1221. */
  1222. public function getSurveyList(array $data): array
  1223. {
  1224. $where = [];
  1225. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1226. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1227. }
  1228. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1229. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1230. }
  1231. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1232. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1233. }
  1234. // return Result::success($where);
  1235. if (!empty($where)) {
  1236. $query = Article::where($where)->where(function ($q) {
  1237. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1238. });
  1239. } else {
  1240. $query = Article::where(function ($q) {
  1241. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1242. });
  1243. }
  1244. $count = $query->count();
  1245. $survey = $query->orderByDesc('id')
  1246. ->limit($data['pageSize'])
  1247. ->offset(($data['page'] - 1) * $data['pageSize'])
  1248. ->get();
  1249. if (empty($survey->toArray())) {
  1250. return Result::error("暂无调查问卷!", 0);
  1251. }
  1252. $result = [
  1253. 'rows' => $survey,
  1254. 'count' => $count,
  1255. ];
  1256. return Result::success($result);
  1257. }
  1258. /**
  1259. * 后端-获取网站调查问卷详情
  1260. * @param array $data
  1261. * @return array
  1262. */
  1263. public function getSurveyInfo(array $data): array
  1264. {
  1265. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1266. $where = ['sur_id' => $data['sur_id']];
  1267. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1268. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1269. ->select('article_survey.*', 'article.survey_type')
  1270. ->get()->all();
  1271. if (empty($choose)) {
  1272. return Result::error("此调查问卷不存在", 0);
  1273. }
  1274. $resultsArray = array_column($choose, 'results');
  1275. $total = array_sum($resultsArray);
  1276. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1277. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1278. // $total = 0;
  1279. if (!empty($other)) {
  1280. $total = $total + $other['results'];
  1281. $other['choice_name'] = '(其他)';
  1282. if (!empty($others)) {
  1283. $other['hasChildren'] = true;
  1284. // array_push($other,['hasChildren','=',true]);
  1285. $other['children'] = $others;
  1286. $other_choices = [$other->toArray()];
  1287. $mer_choice = array_merge($choose, $other_choices);
  1288. $value_choice = array_values($mer_choice);
  1289. } else {
  1290. // return Result::error('1111');
  1291. $other_choices = [$other->toArray()];
  1292. $other_choices = array_merge($choose, $other_choices);
  1293. $value_choice = array_values($other_choices);
  1294. // return Result::success($result);
  1295. }
  1296. } else {
  1297. $value_choice = $choose;
  1298. }
  1299. $result = [
  1300. 'choose' => $value_choice,
  1301. 'total' => $total,
  1302. ];
  1303. }
  1304. return Result::success($result);
  1305. }
  1306. /**
  1307. * 前端-搜索新闻列表
  1308. * @param array $data
  1309. * @return array
  1310. */
  1311. public function selectWebsiteArticle(array $data): array
  1312. {
  1313. $where = [];
  1314. // 初始化查询构造器
  1315. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1316. $query = Article::where('status', 1)
  1317. ->whereIn('catid', $category)
  1318. ->where(function ($query) use ($data) {
  1319. $query->where(function ($subQuery) use ($data) {
  1320. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1321. })->orWhereNull("ignore_ids");
  1322. });
  1323. // return Result::success($all_articles);
  1324. // 检查是否存在 cityid 参数
  1325. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1326. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1327. }
  1328. // 检查是否存在 department_id 参数
  1329. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1330. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1331. }
  1332. // 检查是否存在 keyword 参数
  1333. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1334. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1335. }
  1336. // 计算总数
  1337. $count = $query->count();
  1338. // 分页查询
  1339. $articles = $query
  1340. ->select(
  1341. 'article.id',
  1342. 'article.title',
  1343. 'article.imgurl',
  1344. 'article.author',
  1345. 'article.updated_at',
  1346. 'article.introduce',
  1347. 'article.islink',
  1348. 'article.linkurl',
  1349. 'article.copyfrom',
  1350. 'article.catid',
  1351. 'article.department_arr_id',
  1352. 'article.city_arr_id',
  1353. )
  1354. ->orderBy("updated_at", "desc")
  1355. ->offset(($data['page'] - 1) * $data['pageSize'])
  1356. ->limit($data['pageSize'])
  1357. ->get()
  1358. ->map(function ($article) use ($data) {
  1359. $catid = $article->catid ?? 0;
  1360. $pinyin = '';
  1361. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  1362. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1363. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  1364. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  1365. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  1366. }
  1367. $article->pinyin = $pinyin;
  1368. return $article;
  1369. });
  1370. if (empty($articles)) {
  1371. return Result::error("没有符合条件的资讯数据");
  1372. }
  1373. $data = [
  1374. 'rows' => $articles,
  1375. 'count' => $count,
  1376. ];
  1377. return Result::success($data);
  1378. }
  1379. /**
  1380. * 模块新闻加强版
  1381. * @param array $data
  1382. * @return array
  1383. */
  1384. public function getWebsiteCatidArticle(array $data): array
  1385. {
  1386. // return Result::success($data);
  1387. $where = [
  1388. // 'category.status' => 1,
  1389. 'website_category.category_id' => $data['catid'],
  1390. 'website_category.website_id' => $data['website_id'],
  1391. // 'article.status' => 1,
  1392. ];
  1393. // $category = WebsiteCategory::where($where);
  1394. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1395. $child_catnum = $data['child_catnum'] ?? 1;
  1396. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1397. $childCategoryIds = array_column($category['child'], 'category_id');
  1398. if (empty($childCategoryIds)) {
  1399. return Result::error("暂无子栏目", 0);
  1400. }
  1401. $imgArticles = [];
  1402. $textArticles = [];
  1403. // return Result::success($childCategoryIds);
  1404. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1405. // 初始化子分类图片新闻和文字新闻数组
  1406. // 查询所有子级栏目的图文新闻
  1407. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1408. ->where(function ($query) use ($data) {
  1409. $query->where(function ($subQuery) use ($data) {
  1410. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1411. })->orWhereNull("ignore_ids");
  1412. })
  1413. ->where('status', 1)
  1414. ->where('imgurl', '!=', '')
  1415. ->select('*')
  1416. ->orderBy('updated_at', 'desc')
  1417. ->limit($data['child_imgnum'])
  1418. ->get();
  1419. }
  1420. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1421. // 查询所有子级栏目的文字新闻
  1422. $textArticles = Article::where('catid', $childCategoryIds[0])
  1423. ->where('status', 1)
  1424. ->where(function ($query) use ($data) {
  1425. $query->where(function ($subQuery) use ($data) {
  1426. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1427. })->orWhereNull("ignore_ids");
  1428. })
  1429. // ->where(function ($query) {
  1430. // $query->whereNull('imgurl')
  1431. // ->orWhere('imgurl', '');
  1432. // })
  1433. ->select('*')
  1434. ->orderBy('updated_at', 'desc')
  1435. ->limit($data['child_textnum'])
  1436. ->get();
  1437. }
  1438. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1439. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1440. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1441. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1442. return $child;
  1443. }, $category['child']);
  1444. }
  1445. // }
  1446. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1447. $category['img'] = WebsiteCategory::where($where)
  1448. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1449. ->where('article.status', 1)
  1450. ->where('article.imgurl', '!=', '')
  1451. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1452. ->orderBy('article.updated_at', 'desc')
  1453. ->limit($data['img_num'])
  1454. ->get();
  1455. }
  1456. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1457. $category['text'] = WebsiteCategory::where($where)
  1458. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1459. ->where('article.status', 1)
  1460. // ->where(function ($query) {
  1461. // $query->whereNull('article.imgurl')
  1462. // ->orWhere('article.imgurl', '');
  1463. // })
  1464. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1465. ->orderBy('article.updated_at', 'desc')
  1466. ->limit($data['text_num'])
  1467. ->get();
  1468. }
  1469. // $category = $category->get();
  1470. if (empty($category)) {
  1471. return Result::error("查询失败", 0);
  1472. }
  1473. return Result::success($category);
  1474. }
  1475. /**
  1476. * 模块新闻加强plus版
  1477. * @param array $data
  1478. * @return array
  1479. */
  1480. public function getWebsiteAllArticle(array $data): array
  1481. {
  1482. // 修正传入的字符串,将单引号替换为双引号
  1483. $input['id'] = $data['id'];
  1484. $input['website_id'] = $data['website_id'];
  1485. // 将 JSON 字符串转换为 PHP 数组
  1486. $data = json_decode($input['id'], true);
  1487. // 使用 array_map 处理每个元素
  1488. $result = array_map(function ($item) use ($input) {
  1489. // 检查parent元素是否存在且不是undefined
  1490. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  1491. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1492. $website = [
  1493. 'website_id' => $input['website_id'],
  1494. ];
  1495. // 查询栏目名称
  1496. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1497. if (empty($category)) {
  1498. $parent_alias = '';
  1499. $parent_pinyin = null;
  1500. $imgArticles = [];
  1501. $textArticles = [];
  1502. } else {
  1503. $parent_alias = $category->alias ?? '';
  1504. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1505. // 查找子分类ID数组
  1506. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1507. array_push($childCategoryIds, $parentCatId);
  1508. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  1509. if ($parentImgNum != 0) {
  1510. // 查询图片新闻
  1511. $imgArticles = Article::where('article.status', 1)
  1512. ->where(function ($query) use ($parentCatId) {
  1513. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1514. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1515. })
  1516. ->where(function ($query) use ($website) {
  1517. $query->where(function ($subQuery) use ($website) {
  1518. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0")
  1519. ->orWhereNull("ignore_ids");
  1520. });
  1521. })
  1522. ->where('imgurl', '!=', '')
  1523. ->leftJoin('website_category', function ($join) use ($website) {
  1524. $join->on('article.catid', '=', 'website_category.category_id')
  1525. ->where('website_category.website_id', '=', $website['website_id']);
  1526. })
  1527. ->select(
  1528. 'article.id',
  1529. 'article.title',
  1530. 'article.imgurl',
  1531. 'article.author',
  1532. 'article.updated_at',
  1533. 'article.introduce',
  1534. 'article.islink',
  1535. 'article.linkurl',
  1536. 'article.copyfrom',
  1537. 'article.catid',
  1538. 'website_category.alias as category_name',
  1539. DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin'
  1540. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  1541. )
  1542. ->orderBy('updated_at', 'desc')
  1543. ->limit($parentImgNum)
  1544. ->get()->all();
  1545. // 查询文字新闻
  1546. }
  1547. if ($parentTextNum != 0) {
  1548. $textArticles = [];
  1549. $textArticles = Article::where('article.status', 1)
  1550. ->where(function ($query) use ($parentCatId) {
  1551. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1552. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1553. })
  1554. ->where(function ($query) use ($website) {
  1555. $query->where(function ($subQuery) use ($website) {
  1556. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0")
  1557. ->orWhereNull("ignore_ids");
  1558. });
  1559. })
  1560. ->leftJoin('website_category', function ($join) use ($website) {
  1561. $join->on('article.catid', '=', 'website_category.category_id')
  1562. ->where('website_category.website_id', '=', $website['website_id']);
  1563. })
  1564. ->select(
  1565. 'article.id',
  1566. 'article.title',
  1567. 'article.imgurl',
  1568. 'article.author',
  1569. 'article.updated_at',
  1570. 'article.introduce',
  1571. 'article.islink',
  1572. 'article.linkurl',
  1573. 'article.copyfrom',
  1574. 'article.catid',
  1575. 'website_category.alias as category_name',
  1576. DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin'
  1577. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  1578. )
  1579. ->orderBy('updated_at', 'desc')
  1580. ->limit($parentTextNum)
  1581. ->get()->all();
  1582. }
  1583. }
  1584. }
  1585. $resultItem = [
  1586. 'alias' => $parent_alias ?? '',
  1587. 'category_id' => $parentCatId ?? 0,
  1588. 'pinyin' => $parent_pinyin ?? null,
  1589. 'imgnum' => $imgArticles ?? [],
  1590. 'textnum' => $textArticles ?? [],
  1591. ];
  1592. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  1593. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  1594. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1595. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1596. ->get()->all();
  1597. if (!empty($childCategory)) {
  1598. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1599. // 查询子栏目名称
  1600. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1601. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1602. ->first();
  1603. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  1604. $childImgArticles = [];
  1605. $childTextArticles = [];
  1606. $resultItem['child'] = [];
  1607. } else {
  1608. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  1609. // 查询子栏目图片新闻
  1610. $childImgArticles = Article::where('catid', $childCatId)
  1611. ->where('status', 1)
  1612. ->where(function ($query) use ($website) {
  1613. $query->where(function ($subQuery) use ($website) {
  1614. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1615. })->orWhereNull("ignore_ids");
  1616. })
  1617. ->select(
  1618. 'article.id',
  1619. 'article.title',
  1620. 'article.imgurl',
  1621. 'article.author',
  1622. 'article.updated_at',
  1623. 'article.introduce',
  1624. 'article.islink',
  1625. 'article.linkurl',
  1626. 'article.copyfrom',
  1627. DB::raw("'$child_pinyin' as pinyin")
  1628. )
  1629. ->where('imgurl', '!=', '')
  1630. ->orderBy('updated_at', 'desc')
  1631. ->limit($childImgNum)
  1632. ->get()->all();
  1633. // 查询子栏目文字新闻
  1634. $childTextArticles = Article::where('catid', $childCatId)
  1635. ->where('status', 1)
  1636. ->where(function ($query) use ($website) {
  1637. $query->where(function ($subQuery) use ($website) {
  1638. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1639. })->orWhereNull("ignore_ids");
  1640. })
  1641. ->select(
  1642. 'article.id',
  1643. 'article.title',
  1644. 'article.author',
  1645. 'article.updated_at',
  1646. 'article.introduce',
  1647. 'article.islink',
  1648. 'article.linkurl',
  1649. 'article.copyfrom',
  1650. DB::raw("'$child_pinyin' as pinyin")
  1651. )
  1652. ->orderBy('updated_at', 'desc')
  1653. ->limit($childTextNum)
  1654. ->get()->all();
  1655. $resultItem['child'] = [
  1656. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1657. 'category_id' => $childCatId,
  1658. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1659. 'all_childcat' => $childCategory,
  1660. 'imgnum' => $childImgArticles,
  1661. 'textnum' => $childTextArticles,
  1662. ];
  1663. }
  1664. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1665. }
  1666. } else {
  1667. $resultItem['child'] = [];
  1668. }
  1669. return $resultItem;
  1670. }, $data);
  1671. return Result::success($result);
  1672. // return Result::success($data);
  1673. }
  1674. /**
  1675. * 乡村网-获取特殊新闻模块
  1676. * @param array $data
  1677. * @return array
  1678. */
  1679. public function getWebsiteArticles(array $data): array
  1680. {
  1681. $input['id'] = $data['id'];
  1682. $input['website_id'] = $data['website_id'];
  1683. $data = json_decode($input['id'], true);
  1684. // 使用 array_map 处理每个元素
  1685. $result = array_map(function ($item) use ($input) {
  1686. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1687. $website = [
  1688. 'website_id' => $input['website_id']
  1689. ];
  1690. // 查询栏目名称
  1691. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1692. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1693. if (empty($category)) {
  1694. $imgArticles = [];
  1695. $textArticles = [];
  1696. // return Result::error("暂无此栏目",0);
  1697. } else {
  1698. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1699. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1700. // return Result::success($website);
  1701. // 查询图片新闻
  1702. // 合并查询条件
  1703. $baseQuery = Article::where(function ($query) use ($website) {
  1704. $query->where(function ($subQuery) use ($website) {
  1705. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1706. })->orWhereNull("ignore_ids");
  1707. })
  1708. ->where('article.status', 1)
  1709. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1710. ->where('website_category.website_id', $website['website_id']);
  1711. // 查询文字新闻
  1712. $textArticles = clone $baseQuery;
  1713. $textArticles = $textArticles->whereIn('catid', $child_category)
  1714. ->select(
  1715. 'article.id',
  1716. 'article.title',
  1717. // 'article.imgurl',
  1718. 'article.author',
  1719. 'article.updated_at',
  1720. 'article.introduce',
  1721. 'article.islink',
  1722. 'article.linkurl',
  1723. 'article.copyfrom',
  1724. 'website_category.category_id',
  1725. 'website_category.alias',
  1726. 'website_category.aLIas_pinyin'
  1727. )
  1728. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1729. ->orderBy('article.updated_at', 'desc')
  1730. ->limit($parentTextNum)
  1731. ->get()
  1732. ->all();
  1733. if (empty($textArticles)) {
  1734. $textArticles = clone $baseQuery;
  1735. $textArticles = $textArticles->where('catid', $parentCatId)
  1736. ->select(
  1737. 'article.id',
  1738. 'article.title',
  1739. // 'article.imgurl',
  1740. 'article.author',
  1741. 'article.updated_at',
  1742. 'article.introduce',
  1743. 'article.islink',
  1744. 'article.linkurl',
  1745. 'article.copyfrom',
  1746. 'website_category.category_id',
  1747. 'website_category.alias',
  1748. 'website_category.aLIas_pinyin'
  1749. )
  1750. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1751. ->orderBy('article.updated_at', 'desc')
  1752. ->limit($parentTextNum)
  1753. ->get()
  1754. ->all();
  1755. }
  1756. // 查询图片新闻
  1757. $imgArticles = clone $baseQuery;
  1758. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid', $child_category)
  1759. ->select(
  1760. 'article.id',
  1761. 'article.title',
  1762. 'article.imgurl',
  1763. 'article.author',
  1764. 'article.updated_at',
  1765. 'article.introduce',
  1766. 'article.islink',
  1767. 'article.linkurl',
  1768. 'article.copyfrom',
  1769. 'website_category.category_id',
  1770. 'website_category.alias',
  1771. 'website_category.aLIas_pinyin'
  1772. )
  1773. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1774. ->orderBy('article.updated_at', 'desc')
  1775. ->limit($parentImgNum)
  1776. ->get()
  1777. ->all();
  1778. if (empty($imgArticles)) {
  1779. $imgArticles = clone $baseQuery;
  1780. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid', $parentCatId)
  1781. ->select(
  1782. 'article.id',
  1783. 'article.title',
  1784. 'article.imgurl',
  1785. 'article.author',
  1786. 'article.updated_at',
  1787. 'article.introduce',
  1788. 'article.islink',
  1789. 'article.linkurl',
  1790. 'article.copyfrom',
  1791. 'website_category.category_id',
  1792. 'website_category.alias',
  1793. 'website_category.aLIas_pinyin'
  1794. )
  1795. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1796. ->orderBy('article.updated_at', 'desc')
  1797. ->limit($parentImgNum)
  1798. ->get()
  1799. ->all();
  1800. }
  1801. }
  1802. $resultItem = [
  1803. 'alias' => $category ? $category->alias : null,
  1804. 'category_id' => $parentCatId,
  1805. 'pinyin' => $pinyin ? $pinyin : null,
  1806. 'imgnum' => $imgArticles ?? [],
  1807. 'textnum' => $textArticles ?? [],
  1808. ];
  1809. return $resultItem;
  1810. }, $data);
  1811. return Result::success($result);
  1812. }
  1813. // 封装处理商品的路由问题
  1814. function processGoods($goods, $data)
  1815. {
  1816. return $goods->map(function ($good) use ($data) {
  1817. $catid = $good->catid ?? 0;
  1818. $pinyin = '';
  1819. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1820. if (!empty($category->pid) && $category->pid != 0) {
  1821. $level = json_decode($category->category_arr_id);
  1822. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1823. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1824. ->get(['aLIas_pinyin'])
  1825. ->pluck('aLIas_pinyin')
  1826. ->implode('/');
  1827. } else {
  1828. $pinyin = $category->aLIas_pinyin ?? '';
  1829. }
  1830. if (isset($good->city_id) && !empty($good->city_id)) {
  1831. $city = District::where('id', $good->city_id)->first(['name']);
  1832. $good->city_name = $city->name ?? '';
  1833. }
  1834. // 解析imgurl JSON并取第一条数据
  1835. $imgUrls = json_decode($good->imgurl, true);
  1836. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1837. $good->pinyin = $pinyin;
  1838. return $good;
  1839. });
  1840. }
  1841. /**
  1842. * 获取商品模块
  1843. * @param array $data
  1844. * @return array
  1845. * */
  1846. public function getWebsiteshop(array $data): array
  1847. {
  1848. $input['id'] = $data['id'];
  1849. $input['website_id'] = $data['website_id'];
  1850. // return Result::success($input);
  1851. $data = json_decode($input['id'] ?? '', true) ?? [];
  1852. $result = array_map(function ($item) use ($input) {
  1853. // 检查parent元素是否存在且不是undefined
  1854. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1855. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1856. $website = $input['website_id'];
  1857. $query = Good::where('good.status', 2)
  1858. ->where('good.website_id', $website);
  1859. switch ($Levelid) {
  1860. case 1:
  1861. case 2:
  1862. case 3:
  1863. $goods = $query->where(function ($q) use ($Levelid) {
  1864. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 0")
  1865. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 0");
  1866. });
  1867. break;
  1868. case 4:
  1869. $goods = $query;
  1870. break;
  1871. case 5:
  1872. $goods = $query->where('type_id', 1);
  1873. break;
  1874. case 6:
  1875. $goods = $query->where('type_id', 2);
  1876. break;
  1877. default:
  1878. return [];
  1879. }
  1880. $all_goods = $goods
  1881. ->select(
  1882. 'good.id',
  1883. 'good.name',
  1884. 'good.imgurl',
  1885. 'good.description',
  1886. 'good.updated_at',
  1887. 'good.catid',
  1888. 'good.type_id',
  1889. 'good.price',
  1890. 'good.level',
  1891. 'good.website_id'
  1892. )
  1893. ->orderBy('updated_at', 'desc')
  1894. ->offset($goodStart)
  1895. ->limit($goodNum)
  1896. ->get();
  1897. $all_goods = $this->processGoods($all_goods, $input);
  1898. }
  1899. return $all_goods;
  1900. }, $data);
  1901. return Result::success($result);
  1902. }
  1903. /**
  1904. * 获取商品分类
  1905. * @param array $data
  1906. * @return array
  1907. * */
  1908. public function getWebsiteshopCat(array $data): array
  1909. {
  1910. $category = WebsiteCategory::where('website_id', $data['website_id'])
  1911. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  1912. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  1913. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id')
  1914. ->orderBy('sort')
  1915. ->get()
  1916. ->map(function ($item) use ($data) {
  1917. $pinyin = [];
  1918. $level = json_decode($item->category_arr_id);
  1919. // 递归获取所有父级栏目的拼音
  1920. if ($item->pid != 0) {
  1921. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  1922. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1923. ->get(['aLIas_pinyin'])
  1924. ->pluck('aLIas_pinyin')
  1925. ->implode('/');
  1926. } else {
  1927. $pinyin = $item->aLIas_pinyin;
  1928. }
  1929. $item->aLIas_pinyin = $pinyin;
  1930. return $item;
  1931. });
  1932. $goods = Good::where('website_id', $data['website_id'])
  1933. ->where('status', 2)
  1934. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  1935. ->latest('updated_at')
  1936. ->offset(($data['page'] - 1) * $data['pageSize'])
  1937. ->limit($data['pageSize'])
  1938. ->get();
  1939. $goods = $this->processGoods($goods, $data);
  1940. if (empty($category)) {
  1941. return Result::error("栏目查询失败", 0);
  1942. }
  1943. if (empty($goods)) {
  1944. return Result::error("商品查询失败", 0);
  1945. }
  1946. // 调用Tool中的buildMenuTree方法构建菜单树
  1947. $cat_tree = Result::buildMenuTree($category);
  1948. $result = [
  1949. 'category' => $cat_tree,
  1950. 'goods' => $goods,
  1951. ];
  1952. // $resul['goods'] = $goods;
  1953. if (empty($result)) {
  1954. return Result::error("查询失败", 0);
  1955. }
  1956. return Result::success($result);
  1957. }
  1958. /*
  1959. * 获取商品列表
  1960. * @param array $data
  1961. * @return array
  1962. * */
  1963. public function getWebsiteshopList(array $data): array
  1964. {
  1965. // return Result::success($data);
  1966. $where = [
  1967. 'status' => 2,
  1968. 'website_id' => $data['website_id'],
  1969. ];
  1970. if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  1971. return Result::error("查询失败", 0);
  1972. }
  1973. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1974. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  1975. $data['catid'] = $category->category_id ?? 0;
  1976. }
  1977. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1978. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  1979. }
  1980. if (isset($data['type_id']) && !empty($data['type_id'])) {
  1981. array_push($where, ['type_id', $data['type_id']]);
  1982. }
  1983. $query = Good::where($where)
  1984. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  1985. $query->where(function ($q) use ($data) {
  1986. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  1987. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  1988. });
  1989. })
  1990. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  1991. $query->where(function ($q) use ($data) {
  1992. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  1993. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  1994. });
  1995. })
  1996. ->select(
  1997. 'good.id',
  1998. 'good.name',
  1999. 'good.imgurl',
  2000. 'good.description',
  2001. 'good.updated_at',
  2002. 'good.catid',
  2003. 'good.type_id',
  2004. 'good.website_id',
  2005. 'good.cat_arr_id',
  2006. 'good.created_at',
  2007. 'good.city_id'
  2008. )
  2009. ->latest('updated_at');
  2010. // 获取 type_id 为 1 的数据
  2011. $result['type1'] = $this->processGoods(
  2012. $query->clone()
  2013. ->where('type_id', 1)
  2014. ->offset(($data['page'] - 1) * $data['pageSize'])
  2015. ->limit($data['pageSize'])
  2016. ->get(),
  2017. $data
  2018. );
  2019. // 获取 type_id 为 2 的数据
  2020. $result['type2'] = $this->processGoods(
  2021. $query->clone()
  2022. ->where('type_id', 2)
  2023. ->offset(($data['page'] - 1) * $data['pageSize'])
  2024. ->limit($data['pageSize'])
  2025. ->get(),
  2026. $data
  2027. );
  2028. if (empty($result)) {
  2029. return Result::error("查询失败", 0);
  2030. }
  2031. return Result::success($result);
  2032. }
  2033. /**
  2034. * 获取商品详情
  2035. * @param array $data
  2036. * @return array
  2037. * */
  2038. public function getWebsiteshopInfo(array $data): array
  2039. {
  2040. $where = [
  2041. 'good.status' => 2,
  2042. 'good.website_id' => $data['website_id'],
  2043. ];
  2044. $goods = Good::where($where)
  2045. ->where('good.id', $data['id'])
  2046. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2047. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2048. ->first();
  2049. if (empty($goods)) {
  2050. return Result::error("查询失败", 0);
  2051. }
  2052. $goods->imgurl = json_decode($goods->imgurl, true);
  2053. return Result::success($goods);
  2054. }
  2055. /**
  2056. * 封装处理文章的路由问题
  2057. * */
  2058. function processArticles($articles, $data)
  2059. {
  2060. if (!is_array($data)) {
  2061. // 可以根据实际情况进行日志记录或抛出异常
  2062. // 这里简单输出错误信息
  2063. echo "Error: \$data is not an array in processArticles. It is of type " . gettype($data) . PHP_EOL;
  2064. return $articles;
  2065. }
  2066. return $articles->map(function ($article) use ($data) {
  2067. $catid = $article->cat_arr_id ?? '';
  2068. $level = json_decode($catid, true);
  2069. $pinyin = '';
  2070. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2071. if (!empty($category->pid) && $category->pid != 0) {
  2072. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2073. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2074. ->get(['aLIas_pinyin'])
  2075. ->pluck('aLIas_pinyin')
  2076. ->implode('/');
  2077. } else {
  2078. $pinyin = $category->aLIas_pinyin ?? '';
  2079. }
  2080. $article->pinyin = $pinyin;
  2081. return $article;
  2082. });
  2083. }
  2084. /**
  2085. * 验证导航名称是否重复
  2086. * @return void
  2087. */
  2088. public function checkCategoryName(array $data): array
  2089. {
  2090. $result = Category::when($data, function ($query) use ($data) {
  2091. if (isset($data['name']) && $data['name']) {
  2092. $query->where("name", $data['name']);
  2093. }
  2094. if (isset($data['id']) && $data['id']) {
  2095. $query->where("id", "!=", $data['id']);
  2096. }
  2097. })->first();
  2098. if ($result) {
  2099. return Result::error("已存在");
  2100. } else {
  2101. return Result::success();
  2102. }
  2103. }
  2104. //20250226 产品列表
  2105. public function getGoodList(array $data): array
  2106. {
  2107. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  2108. unset($data['type_id']);
  2109. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  2110. $where = [];
  2111. if ($type_id != '10000') {
  2112. $where = [
  2113. 'good.user_id' => $user_id,
  2114. ];
  2115. }
  2116. //类型
  2117. if (isset($data['type_id']) && $data['type_id']) {
  2118. $where = [
  2119. 'type_id' => $data['type_id'],
  2120. ];
  2121. }
  2122. //名称
  2123. if (isset($data['name']) && $data['name']) {
  2124. $where = [
  2125. 'good.name' => $data['name'],
  2126. ];
  2127. }
  2128. //status
  2129. if (isset($data['status']) && $data['status'] != '') {
  2130. $where = [
  2131. 'good.status' => $data['status'],
  2132. ];
  2133. }
  2134. //status1
  2135. // if (isset($data['status1']) && $data['status1'] == 1) {
  2136. // $status1 = 1;
  2137. // }
  2138. $where1 = [];
  2139. //website_id
  2140. // if (isset($data['website_id']) && $data['website_id']) {
  2141. // $where1 = [
  2142. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  2143. // ];
  2144. // }
  2145. // website_name
  2146. if (isset($data['website_name']) && $data['website_name']) {
  2147. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  2148. }
  2149. // catid
  2150. if (isset($data['category_name']) && $data['category_name']) {
  2151. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  2152. }
  2153. // $result = Good::where($where)
  2154. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  2155. $result = Good::where($where)
  2156. ->when(!empty($where1), function ($query) use ($where1) {
  2157. return $query->where($where1);
  2158. })
  2159. //status 1待审核2已审核3已拒绝
  2160. ->when(isset($data['status1']), function ($query) {
  2161. return $query->whereIn('good.status', [1, 3]);
  2162. })
  2163. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  2164. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  2165. ->leftJoin('category', 'good.catid', '=', 'category.id')
  2166. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  2167. ->orderBy("updated_at", "desc")
  2168. ->limit($data['page_size'])
  2169. ->offset(($data['page'] - 1) * $data['page_size'])
  2170. ->get();
  2171. $count = Good::where($where)
  2172. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  2173. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  2174. ->leftJoin('category', 'good.catid', '=', 'category.id')
  2175. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  2176. ->orderBy("updated_at", "desc")->count();
  2177. $data = [
  2178. 'rows' => $result->toArray(),
  2179. 'count' => $count,
  2180. ];
  2181. if (empty($result)) {
  2182. return Result::error("此栏目暂无相关产品", 0);
  2183. }
  2184. return Result::success($data);
  2185. }
  2186. public function getGoodInfo(array $data): array
  2187. {
  2188. $result = Good::where('id', $data['id'])->first();
  2189. if (empty($result)) {
  2190. return Result::error("此产品不存在", 0);
  2191. }
  2192. return Result::success($result);
  2193. }
  2194. public function addGood(array $data): array
  2195. {
  2196. // unset($data['city_arr_id']);
  2197. // unset($data['cat_arr_id']);
  2198. $data['city_id'] = end($data['city_arr_id']);
  2199. $data['catid'] = end($data['cat_arr_id']);
  2200. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  2201. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  2202. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  2203. unset($data['imgUrl']);
  2204. if (isset($data['price']) && $data['price'] == '') {
  2205. $data['price'] = 0;
  2206. }
  2207. $result = Good::insert($data);
  2208. if (empty($result)) {
  2209. return Result::error("添加失败", 0);
  2210. }
  2211. return Result::success($result);
  2212. }
  2213. public function updateGood(array $data): array
  2214. {
  2215. $data['city_id'] = end($data['city_arr_id']);
  2216. $data['catid'] = end($data['cat_arr_id']);
  2217. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  2218. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  2219. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  2220. //设置东八区
  2221. date_default_timezone_set('Asia/Shanghai');
  2222. $data['updated_at'] = date('Y-m-d H:i:s');
  2223. if (isset($data['price']) && $data['price'] == '') {
  2224. $data['price'] = 0;
  2225. }
  2226. $result = Good::where('id', $data['id'])->update($data);
  2227. if (empty($result)) {
  2228. return Result::error("更新失败", 0);
  2229. }
  2230. return Result::success($result);
  2231. }
  2232. public function delGood(array $data): array
  2233. {
  2234. $result = Good::where('id', $data['id'])->delete();
  2235. if (empty($result)) {
  2236. return Result::error("删除失败", 0);
  2237. }
  2238. return Result::success($result);
  2239. }
  2240. //20250226 产品列表
  2241. //20250306 求职信息
  2242. public function getJobHuntingList(array $data): array
  2243. {
  2244. $where = [];
  2245. if (isset($data['username']) && !empty($data['username'])) {
  2246. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  2247. }
  2248. //status 1待审核2已审核3已拒绝
  2249. if (isset($data['status']) && $data['status'] != '') {
  2250. $where = [
  2251. 'job_hunting.status' => $data['status'],
  2252. ];
  2253. }
  2254. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  2255. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  2256. unset($data['type_id']);
  2257. if ($type_id != '10000') {
  2258. $where[] = ['job_hunting.user_id', '=', $user_id];
  2259. }
  2260. $result = JobHunting::where($where)
  2261. ->when(!empty($data['status1']), function ($query) use ($data) {
  2262. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  2263. })
  2264. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2265. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  2266. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  2267. ->orderBy("updated_at", "desc")
  2268. ->limit($data['page_size'])
  2269. ->offset(($data['page'] - 1) * $data['page_size'])
  2270. ->get();
  2271. if (empty($result)) {
  2272. return Result::error("查询失败", 0);
  2273. }
  2274. $count = JobHunting::where($where)
  2275. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2276. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  2277. ->count();
  2278. $data = [
  2279. 'rows' => $result->toArray(),
  2280. 'count' => $count,
  2281. ];
  2282. return Result::success($data);
  2283. }
  2284. public function getJobHuntingApply(array $data): array
  2285. {
  2286. $where = [];
  2287. if (isset($data['username']) && !empty($data['username'])) {
  2288. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  2289. }
  2290. if (isset($data['salary']) && !empty($data['salary'])) {
  2291. $where = [
  2292. 'job_hunting.salary' => $data['salary'],
  2293. ];
  2294. }
  2295. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  2296. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  2297. unset($data['type_id']);
  2298. if ($type_id != '10000') {
  2299. $where[] = ['job_resume.user_id', '=', $user_id];
  2300. }
  2301. $result = jobResume::where($where)
  2302. // ->when(!empty($data['status1']), function ($query) use ($data) {
  2303. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  2304. // })
  2305. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  2306. ->where('job_enum.egroup', '=', 'income')
  2307. ->where('job_hunting.status', 2) //已审核
  2308. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_resume.hunt_id')
  2309. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  2310. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  2311. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  2312. ->select('job_resume.*', 'job_hunting.job_name_get as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username')
  2313. ->orderBy("job_hunting.updated_at", "desc")
  2314. ->limit($data['page_size'])
  2315. ->offset(($data['page'] - 1) * $data['page_size'])
  2316. ->get();
  2317. if (empty($result)) {
  2318. return Result::error("查询失败", 0);
  2319. }
  2320. $count = jobResume::where($where)
  2321. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_resume.hunt_id')
  2322. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  2323. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  2324. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  2325. ->select('job_resume.*', 'job_hunting.job_name_get as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username')
  2326. ->count();
  2327. $data = [
  2328. 'rows' => $result->toArray(),
  2329. 'count' => $count,
  2330. ];
  2331. return Result::success($data);
  2332. }
  2333. public function addJobHunting(array $data): array
  2334. {
  2335. date_default_timezone_set('Asia/Shanghai');
  2336. unset($data['company_name']);
  2337. unset($data['job_industry']);
  2338. unset($data['job_name']);
  2339. unset($data['department']);
  2340. unset($data['job_timeList']);
  2341. unset($data['job_content']);
  2342. $data['created_at'] = date('Y-m-d H:i:s');
  2343. $data['updated_at'] = date('Y-m-d H:i:s');
  2344. var_dump($data, '-----------------test---------');
  2345. $result = JobHunting::create($data);
  2346. if (empty($result)) {
  2347. return Result::error("添加失败", 0);
  2348. }
  2349. return Result::success($result);
  2350. }
  2351. public function delJobHunting(array $data): array
  2352. {
  2353. $result = JobHunting::where('id', $data['id'])->delete();
  2354. if (empty($result)) {
  2355. return Result::error("删除失败", 0);
  2356. }
  2357. return Result::success($result);
  2358. }
  2359. public function updateJobHunting(array $data): array
  2360. {
  2361. //设置东八区
  2362. date_default_timezone_set('Asia/Shanghai');
  2363. unset($data['company_name']);
  2364. unset($data['job_industry']);
  2365. unset($data['job_name']);
  2366. unset($data['department']);
  2367. unset($data['job_timeList']);
  2368. unset($data['job_content']);
  2369. $data['created_at'] = date('Y-m-d H:i:s');
  2370. $data['updated_at'] = date('Y-m-d H:i:s');
  2371. $result = JobHunting::where('id', $data['id'])->update($data);
  2372. if (empty($result)) {
  2373. return Result::error("更新失败", 0);
  2374. }
  2375. return Result::success($result);
  2376. }
  2377. public function getJobHuntingInfo(array $data): array
  2378. {
  2379. $result = JobHunting::where('id', $data['id'])->first();
  2380. if (empty($result)) {
  2381. return Result::error("查询失败", 0);
  2382. }
  2383. return Result::success($result);
  2384. }
  2385. public function getJobHuntingData(array $data): array
  2386. {
  2387. $jobEnum = JobEnum::get();
  2388. $jobIndustry = JobIndustry::get();
  2389. $jobNature = JobNature::get();
  2390. $jobPosition = JobPosition::get();
  2391. $data = [
  2392. 'jobEnum' => $jobEnum,
  2393. 'jobIndustry' => $jobIndustry,
  2394. 'jobNature' => $jobNature,
  2395. 'jobPosition' => $jobPosition,
  2396. ];
  2397. return Result::success($data);
  2398. }
  2399. public function delJobHuntingInfo(array $data): array
  2400. {
  2401. $result = JobHunting::where('id', $data['id'])->delete();
  2402. return Result::success();
  2403. }
  2404. //20250324 通知,公告,消息
  2405. public function delNotice(array $data): array
  2406. {
  2407. $result = Notice::where('id', $data['id'])->delete();
  2408. if ($result) {
  2409. return Result::success();
  2410. } else {
  2411. return Result::error("删除失败", 0);
  2412. }
  2413. }
  2414. public function getNoticeInfo(array $data): array
  2415. {
  2416. $result = Notice::where('id', $data['id'])->first();
  2417. if (empty($result)) {
  2418. return Result::error("查询失败", 0);
  2419. }
  2420. return Result::success($result);
  2421. }
  2422. public function addNotice(array $data): array
  2423. {
  2424. date_default_timezone_set('Asia/Shanghai');
  2425. $data['created_at'] = date('Y-m-d H:i:s');
  2426. $data['updated_at'] = date('Y-m-d H:i:s');
  2427. $user_id = UserInfo::
  2428. //city_id不是null
  2429. whereNotNull('city_id')
  2430. ->whereNotNull('department_id')
  2431. ->where(function ($query) use ($data) {
  2432. $query->where(function ($subQuery) use ($data) {
  2433. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2434. });
  2435. })
  2436. ->where(function ($query) use ($data) {
  2437. $query->where(function ($subQuery) use ($data) {
  2438. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  2439. });
  2440. })
  2441. ->pluck('user_id')->toArray();
  2442. $user_id = array_unique($user_id);
  2443. $chat_ids = $user_id;
  2444. $user_id = json_encode($user_id);
  2445. $data['re_user_ids'] = $user_id;
  2446. $result = Notice::insertGetId($data);
  2447. if ($result && $data['is_group'] == 1) {
  2448. //chat_group
  2449. $group_id = PublicData::uuid();
  2450. $groupData = [
  2451. 'id' => $group_id,
  2452. 'creator_id' => $data['user_id'],
  2453. 'group_name' => $data['group_name'] ?? '',
  2454. 'profile' => $data['profile'] ?? 0,
  2455. ];
  2456. $groupResult = ChatGroups::insertGetId($groupData);
  2457. var_dump($groupResult, '-----------------groupid-------');
  2458. $groupMemberData = [
  2459. 'id' => PublicData::uuid(),
  2460. 'user_id' => $data['user_id'],
  2461. 'group_id' => $group_id,
  2462. 'leader' => 2,
  2463. ];
  2464. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  2465. //$chat_ids 去除掉$data['user_id']
  2466. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  2467. //插入群成员表
  2468. $groupMemberDataUser = [];
  2469. foreach ($chat_ids as $key => $value) {
  2470. $groupMemberDataUser[] = [
  2471. 'id' => PublicData::uuid(),
  2472. 'user_id' => $value,
  2473. 'group_id' => $group_id,
  2474. 'leader' => 1,
  2475. ];
  2476. }
  2477. ChatGroupsMember::insert($groupMemberDataUser);
  2478. //更新result的 group_id
  2479. $data['group_id'] = $group_id;
  2480. Notice::where(['id' => $result])->update($data);
  2481. }
  2482. if (empty($result)) {
  2483. return Result::error("添加失败", 0);
  2484. }
  2485. return Result::success($result);
  2486. }
  2487. public function updateNotice(array $data): array
  2488. {
  2489. date_default_timezone_set('Asia/Shanghai');
  2490. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  2491. $user_id = UserInfo::
  2492. //city_id不是null
  2493. whereNotNull('city_id')
  2494. ->whereNotNull('department_id')
  2495. ->where(function ($query) use ($data) {
  2496. $query->where(function ($subQuery) use ($data) {
  2497. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2498. });
  2499. })
  2500. ->where(function ($query) use ($data) {
  2501. $query->where(function ($subQuery) use ($data) {
  2502. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  2503. });
  2504. })
  2505. ->pluck('user_id')->toArray();
  2506. $user_id = array_unique($user_id);
  2507. $user_id = json_encode($user_id);
  2508. $data['re_user_ids'] = $user_id;
  2509. $data['updated_at'] = date('Y-m-d H:i:s');
  2510. $result = Notice::where('id', $data['id'])->update($data);
  2511. return Result::success($result);
  2512. }
  2513. public function getNoticeList(array $data): array
  2514. {
  2515. $where = [];
  2516. //title
  2517. if (isset($data['title']) && !empty($data['title'])) {
  2518. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  2519. }
  2520. //level
  2521. if (isset($data['level']) && !empty($data['level'])) {
  2522. $where[] = ['notice.level', '=', $data['level']];
  2523. }
  2524. //status
  2525. if (isset($data['status']) && !empty($data['status'])) {
  2526. $where[] = ['notice.status', '=', $data['status']];
  2527. }
  2528. var_dump($data['type_id'], '-----------------test---------');
  2529. if ($data['type_id'] == 10000) {
  2530. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  2531. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  2532. })
  2533. ->where($where)
  2534. ->orderBy('updated_at', 'desc')
  2535. ->limit($data['page_size'])
  2536. ->offset(($data['page'] - 1) * $data['page_size'])
  2537. ->get();
  2538. } else {
  2539. $result = Notice::where('status', 1)
  2540. ->where($where)
  2541. ->where('user_id', $data['user_id'])
  2542. ->orWhere(function ($query) use ($data) {
  2543. $query->where('re_user_ids', 'like', '%' . $data['user_id'] . '%');
  2544. })
  2545. ->orderBy('updated_at', 'desc')
  2546. ->limit($data['page_size'])
  2547. ->offset(($data['page'] - 1) * $data['page_size'])
  2548. ->get();
  2549. }
  2550. if (empty($result)) {
  2551. return Result::error("查询失败", 0);
  2552. }
  2553. $count = Notice::where('status', 1)->count();
  2554. $data = [
  2555. 'rows' => $result,
  2556. 'count' => $count,
  2557. ];
  2558. return Result::success($data);
  2559. }
  2560. public function getNoticeDetail(array $data): array
  2561. {
  2562. $result = Notice::where('id', $data['id'])->first();
  2563. if (empty($result)) {
  2564. return Result::error("查询失败", 0);
  2565. }
  2566. return Result::success($result);
  2567. }
  2568. public function deleteNotice(array $data): array
  2569. {
  2570. $notice = Notice::where('id', $data['id'])->first();
  2571. if (empty($notice)) {
  2572. return Result::error("删除失败", 0);
  2573. }
  2574. $chat_group_id = $notice->group_id;
  2575. if ($chat_group_id) {
  2576. //删除群聊
  2577. ChatGroups::where('id', $chat_group_id)->delete();
  2578. //删除群成员
  2579. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  2580. //删除群聊记录
  2581. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  2582. }
  2583. $result = Notice::where('id', $data['id'])->delete();
  2584. return Result::success($result);
  2585. }
  2586. public function getMSG(array $data): array
  2587. {
  2588. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  2589. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2590. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  2591. $result = [];
  2592. if ($type_id == 1) {
  2593. //最近的5篇已审的文章
  2594. $apply_articale = Article::where('status', 1)
  2595. ->where('admin_user_id', $user_id)
  2596. ->orderBy('updated_at', 'desc')
  2597. ->limit(5)->get();
  2598. //获取5条单聊未读聊天消息
  2599. $chat = ChatRecords::where('is_read', 0)
  2600. ->where('user_id', $user_id)
  2601. ->where('talk_type', 1)
  2602. ->orderBy('created_at', 'desc')
  2603. ->limit(5)->get();
  2604. //获取5条未读群聊信息
  2605. $chat_group = ChatRecords::where('is_read', 0)
  2606. ->where('user_id', $user_id)
  2607. ->where('talk_type', 2)
  2608. ->orderBy('created_at', 'desc')
  2609. ->limit(5)->get();
  2610. //获取5条用户的已审核商品
  2611. $good = Good::where('status', 2)
  2612. ->where('user_id', $user_id)
  2613. ->orderBy('updated_at', 'desc')
  2614. ->limit(5)->get();
  2615. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  2616. $result = [
  2617. 'apply_articale' => $apply_articale,
  2618. 'chat' => $chat,
  2619. 'chat_group' => $chat_group,
  2620. 'good' => $good,
  2621. 'count' => $count,
  2622. ];
  2623. } elseif ($type_id == 2) {
  2624. //最近的5篇已审的文章
  2625. $apply_articale = Article::where('status', 1)
  2626. ->where('admin_user_id', $user_id)
  2627. ->limit(5)->get();
  2628. //获取5条单聊未读聊天消息
  2629. $chat = ChatRecords::where('is_read', 0)
  2630. ->where('user_id', $user_id)
  2631. ->where('talk_type', 1)
  2632. ->orderBy('created_at', 'desc')
  2633. ->limit(5)->get();
  2634. //获取5条未读群聊信息
  2635. $chat_group = ChatRecords::where('is_read', 0)
  2636. ->where('user_id', $user_id)
  2637. ->where('talk_type', 2)
  2638. ->orderBy('created_at', 'desc')
  2639. ->limit(5)->get();
  2640. //获取5条用户的已审核商品
  2641. $good = Good::where('status', 2)
  2642. ->where('user_id', $user_id)
  2643. ->orderBy('updated_at', 'desc')
  2644. ->limit(5)->get();
  2645. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  2646. $result = [
  2647. 'apply_articale' => $apply_articale,
  2648. 'chat' => $chat,
  2649. 'chat_group' => $chat_group,
  2650. 'good' => $good,
  2651. 'count' => $count,
  2652. ];
  2653. } elseif ($type_id == 3) {
  2654. //最近的5篇已审的文章
  2655. $apply_articale = Article::where('status', 1)
  2656. ->where('admin_user_id', $user_id)
  2657. ->limit(5)->get();
  2658. //获取5条单聊未读聊天消息
  2659. $chat = ChatRecords::where('is_read', 0)
  2660. ->where('user_id', $user_id)
  2661. ->where('talk_type', 1)
  2662. ->orderBy('created_at', 'desc')
  2663. ->limit(5)->get();
  2664. //获取5条未读群聊信息
  2665. $chat_group = ChatRecords::where('is_read', 0)
  2666. ->where('user_id', $user_id)
  2667. ->where('talk_type', 2)
  2668. ->orderBy('created_at', 'desc')
  2669. ->limit(5)->get();
  2670. //获取5条用户的已审核商品
  2671. $good = Good::where('status', 2)
  2672. ->where('user_id', $user_id)
  2673. ->orderBy('updated_at', 'desc')
  2674. ->limit(5)->get();
  2675. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  2676. $result = [
  2677. 'apply_articale' => $apply_articale,
  2678. 'chat' => $chat,
  2679. 'chat_group' => $chat_group,
  2680. 'good' => $good,
  2681. 'count' => $count,
  2682. ];
  2683. } elseif ($type_id == 4) {
  2684. //最近的5篇已审的文章
  2685. $apply_articale = Article::where('status', 1)
  2686. ->where('admin_user_id', $user_id)
  2687. ->limit(5)->get();
  2688. //获取5条用户的已审核商品
  2689. $good = Good::where('status', 2)
  2690. ->where('user_id', $user_id)
  2691. ->orderBy('updated_at', 'desc')
  2692. ->limit(5)->get();
  2693. $count = count($apply_articale) + count($good);
  2694. $result = [
  2695. 'apply_articale' => $apply_articale,
  2696. 'chat' => '',
  2697. 'chat_group' => '',
  2698. 'good' => $good,
  2699. 'count' => $count,
  2700. ];
  2701. } elseif ($type_id == 10000) {
  2702. //获取未审核的5篇文章
  2703. $apply_articale = Article::where('status', 0)
  2704. ->orderBy('updated_at', 'desc')
  2705. ->limit(5)->get();
  2706. //获取5条单聊未读聊天消息
  2707. $chat = ChatRecords::where('is_read', 0)
  2708. ->where('user_id', $user_id)
  2709. ->where('talk_type', 1)
  2710. ->orderBy('created_at', 'desc')
  2711. ->limit(5)->get();
  2712. //获取5条未读群聊信息
  2713. $chat_group = ChatRecords::where('is_read', 0)
  2714. ->where('user_id', $user_id)
  2715. ->where('talk_type', 2)
  2716. ->orderBy('created_at', 'desc')
  2717. ->limit(5)->get();
  2718. //获取5条用户的已审核商品
  2719. $good = Good::where('status', 1)
  2720. // ->where('user_id', $user_id)
  2721. ->orderBy('updated_at', 'desc')
  2722. ->limit(5)->get();
  2723. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  2724. $result = [
  2725. 'apply_articale' => $apply_articale,
  2726. 'chat' => $chat,
  2727. 'chat_group' => $chat_group,
  2728. 'good' => $good,
  2729. 'count' => $count,
  2730. ];
  2731. } elseif ($type_id == 20000) {
  2732. }
  2733. var_dump($type_id, '-----------------test---------');
  2734. return Result::success($result);
  2735. }
  2736. public function getComplaintList(array $data): array
  2737. {
  2738. var_dump($data, '00000001000000000000');
  2739. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  2740. unset($data['type_id']);
  2741. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  2742. $where = [];
  2743. if ($type_id != 10000) {
  2744. $where['complaint.user_id'] = $user_id;
  2745. }
  2746. if (!empty($data['title'])) {
  2747. $where['complaint.title'] = ['like', '%' . $data['title'] . '%'];
  2748. }
  2749. if (!empty($data['deal'])) {
  2750. $where['complaint.deal'] = $data['deal'];
  2751. }
  2752. if (!empty($data['status'])) {
  2753. $where['complaint.status'] = $data['status'];
  2754. }
  2755. var_dump(!empty($data['deal_user']), '----------1');
  2756. $result = Complaint::where($where)
  2757. ->when(!empty($data['status1']), function ($query) use ($data) {
  2758. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  2759. })
  2760. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  2761. //json re_user_ids data[user_id]是不是在里面
  2762. $query->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')');
  2763. })
  2764. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  2765. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  2766. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  2767. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  2768. ->orderBy('updated_at', 'desc')
  2769. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  2770. //sql输出
  2771. if (empty($result)) {
  2772. return Result::error("暂无投诉信息", 0);
  2773. }
  2774. // 取出数据
  2775. $rows = $result->items();
  2776. $count = $result->total();
  2777. $responseData = [
  2778. 'rows' => $rows,
  2779. 'count' => $count,
  2780. ];
  2781. return Result::success($responseData);
  2782. }
  2783. public function getComplaintInfo(array $data): array
  2784. {
  2785. $result = Complaint::where('id', $data['id'])->first();
  2786. if (empty($result)) {
  2787. return Result::error("查询失败", 0);
  2788. }
  2789. return Result::success($result);
  2790. }
  2791. public function addComplaint(array $data): array
  2792. {
  2793. date_default_timezone_set('Asia/Shanghai');
  2794. $data['created_at'] = date('Y-m-d H:i:s');
  2795. $data['updated_at'] = date('Y-m-d H:i:s');
  2796. $result = Complaint::create($data);
  2797. return Result::success($result);
  2798. }
  2799. public function updateComplaint(array $data): array
  2800. {
  2801. date_default_timezone_set('Asia/Shanghai');
  2802. $data['updated_at'] = date('Y-m-d H:i:s');
  2803. $user_id = $data['user_id'] ?? 0;
  2804. $type_id = $data['type_id'] ?? 0;
  2805. unset($data['user_id']);
  2806. unset($data['type_id']);
  2807. $result = Complaint::where('id', $data['id'])->update($data);
  2808. return Result::success($result);
  2809. }
  2810. public function deleteComplaint(array $data): array
  2811. {
  2812. $result = Complaint::where('id', $data['id'])->delete();
  2813. return Result::success($result);
  2814. }
  2815. public function getComplainInfo(array $data): array
  2816. {
  2817. $result = Complaint::where('id', $data['id'])->first();
  2818. if (empty($result)) {
  2819. return Result::error("查询失败", 0);
  2820. }
  2821. return Result::success($result);
  2822. }
  2823. public function updateComplaintStatus(array $data): array
  2824. {
  2825. date_default_timezone_set('Asia/Shanghai');
  2826. $data['updated_at'] = date('Y-m-d H:i:s');
  2827. $user_id = $data['user_id'] ?? 0;
  2828. $type_id = $data['type_id'] ?? 0;
  2829. unset($data['user_id']);
  2830. unset($data['type_id']);
  2831. //处理, 写入处理人
  2832. if (isset($data['deal']) && ($data['deal'] == 1 || $data['deal'] == 4)) {
  2833. $data['real_deal_user'] = $user_id;
  2834. }
  2835. //如果是deal 23,则判断是不是处理人
  2836. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 3) && $type_id != 10000) {
  2837. $complaintInof = Complaint::where('id', $data['id'])
  2838. ->where('real_deal_user', $user_id)
  2839. ->first();
  2840. if (empty($complaintInof)) {
  2841. return Result::error("处理人错误", 0);
  2842. }
  2843. }
  2844. $result = complaint::where('id', $data['id'])->update($data);
  2845. return Result::success($result);
  2846. }
  2847. public function updateGoodStatus(array $data): array
  2848. {
  2849. $user_id = $data['user_id'] ?? 0;
  2850. $type_id = $data['type_id'] ?? 0;
  2851. unset($data['user_id']);
  2852. unset($data['type_id']);
  2853. $result = Good::where('id', $data['id'])->update($data);
  2854. return Result::success($result);
  2855. }
  2856. public function updateJobHuntingStatus(array $data): array
  2857. {
  2858. $user_id = $data['user_id'] ?? 0;
  2859. $type_id = $data['type_id'] ?? 0;
  2860. unset($data['user_id']);
  2861. unset($data['type_id']);
  2862. $result = JobHunting::where('id', $data['id'])->update($data);
  2863. return Result::success($result);
  2864. }
  2865. public function updateNoticeStatus(array $data): array
  2866. {
  2867. $user_id = $data['user_id'] ?? 0;
  2868. $type_id = $data['type_id'] ?? 0;
  2869. unset($data['user_id']);
  2870. unset($data['type_id']);
  2871. $result = Notice::where('id', $data['id'])->update($data);
  2872. return Result::success($result);
  2873. }
  2874. public function getDUser(array $data): array
  2875. {
  2876. if (!empty($data['ids'])) {
  2877. $user = User::whereIn('id', $data['ids'])->getall();
  2878. if (empty($user)) {
  2879. return Result::error('无数据', 0);
  2880. }
  2881. return Result::success($user);
  2882. }
  2883. $where = [];
  2884. if (!empty($data['department_id'])) {
  2885. $where['department_id'] = $data['department_id'];
  2886. }
  2887. if (!empty($data['city_id'])) {
  2888. $where['city_id'] = $data['city_id'];
  2889. }
  2890. $result = User::where('type_id', 2)
  2891. ->where('status', 1)
  2892. ->where($where)
  2893. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  2894. ->get();
  2895. if (empty($result)) {
  2896. return Result::error("查询失败", 0);
  2897. }
  2898. return Result::success($result);
  2899. }
  2900. //20250324 通知,公告,消息
  2901. // 20250306 -------招聘--------fr
  2902. /*
  2903. * 招聘列表
  2904. * */
  2905. public function getJobRecruitingList(array $data): array
  2906. {
  2907. $where = [];
  2908. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  2909. if ($data['checkout'] == 0) {
  2910. $job_status = [0, 2];
  2911. } else {
  2912. $job_status = [1];
  2913. }
  2914. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2915. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  2916. }
  2917. $user = User::where('id', $data['user_id'])->first();
  2918. if (empty($user)) {
  2919. return Result::error("用户不存在", 0);
  2920. }
  2921. // 3:企业会员
  2922. if ($user['type_id'] == 3) {
  2923. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  2924. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  2925. }
  2926. // 如果 $where 为空,则不添加 where 条件
  2927. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2928. return $query->where($where);
  2929. })
  2930. ->whereIn('job_recruiting.status', $job_status)
  2931. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  2932. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  2933. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  2934. ->orderBy("updated_at", "desc")
  2935. ->offset(($data['page'] - 1) * $data['page_size'])
  2936. ->limit($data['page_size'])
  2937. ->get()
  2938. ->all();
  2939. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2940. return $query->where($where);
  2941. })
  2942. ->whereIn('job_recruiting.status', $job_status)
  2943. ->count();
  2944. if (empty($result)) {
  2945. return Result::error("暂无招聘信息", 0);
  2946. }
  2947. return Result::success($result);
  2948. }
  2949. /*
  2950. * 招聘信息添加
  2951. * */
  2952. public function addJobRecruiting(array $data): array
  2953. {
  2954. // return Result::success($data);
  2955. $user = User::where('user.id', $data['user_id'])
  2956. ->where('user.status', 1)
  2957. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2958. ->select(
  2959. 'user.type_id',
  2960. 'user.mobile',
  2961. 'user.email',
  2962. 'user_info.business_name',
  2963. 'user_info.company_hy_id',
  2964. 'user_info.company_nature',
  2965. 'user_info.company_size',
  2966. 'user_info.introduction',
  2967. 'user_info.real_name',
  2968. 'user_info.company_url',
  2969. 'user_info.address_arr_id',
  2970. 'user_info.address'
  2971. )
  2972. ->first();
  2973. if (empty($user) || $user['type_id'] != $data['user_type']) {
  2974. return Result::error("用户不存在", 0);
  2975. }
  2976. $web = Website::where('id', $data['website_id'])->first();
  2977. if (empty($web)) {
  2978. return Result::error("网站不存在", 0);
  2979. }
  2980. // return Result::success($user);
  2981. $data['action_id'] = $data['user_id'];
  2982. $data['user_type'] = $user['type_id'];
  2983. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  2984. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  2985. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  2986. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  2987. // 公司地址 管理员必填
  2988. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  2989. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2990. // 管理员-企业相关信息
  2991. $company = [
  2992. // 'user_id' => $data['user_id']?? null,
  2993. 'business_name' => $data['business_name'] ?? null,
  2994. 'company_hy_id' => $data['company_hy_id'] ?? null,
  2995. 'company_size' => $data['company_size'] ?? null,
  2996. 'company_nature' => $data['company_nature'] ?? null,
  2997. 'introduction' => $data['introduction'] ?? null,
  2998. 'real_name' => $data['real_name'] ?? null,
  2999. 'mobile' => $data['mobile'] ?? null,
  3000. 'company_url' => $data['company_url'] ?? null,
  3001. 'address_arr_id' => $data['address_arr_id'] ?? null,
  3002. 'address' => $data['address'] ?? null,
  3003. 'email' => $data['email'] ?? null,
  3004. ];
  3005. //去掉相关企业信息
  3006. $job = array_diff_key($data, array_flip(array_keys($company)));
  3007. Db::beginTransaction();
  3008. try {
  3009. // 先添加职位相关信息
  3010. if ($user['type_id'] == 10000) {
  3011. $job['status'] = 1;
  3012. }
  3013. $jobId = JobRecruiting::insertGetId($job);
  3014. if (empty($jobId)) {
  3015. Db::rollBack();
  3016. return Result::error("添加失败");
  3017. }
  3018. // 添加公司信息
  3019. $company['user_id'] = $data['user_id'] ?? null;
  3020. $company['job_id'] = $jobId;
  3021. $company['user_type'] = $user['type_id'] ?? null;
  3022. $company['website_id'] = $data['website_id'] ?? null;
  3023. if ($user['type_id'] == 10000) {
  3024. // 管理员添加企业信息
  3025. // return Result::success($company);
  3026. $companyId = JobCompany::insertGetId($company);
  3027. if (empty($companyId)) {
  3028. Db::rollBack();
  3029. return Result::error("添加失败");
  3030. }
  3031. } else {
  3032. // 企业会员添加企业信息
  3033. $company = [
  3034. 'user_id' => $data['user_id'] ?? null,
  3035. 'business_name' => $user['business_name'] ?? null,
  3036. 'company_hy_id' => $user['company_hy_id'] ?? null,
  3037. 'company_size' => $user['company_size'] ?? null,
  3038. 'company_nature' => $user['company_nature'] ?? null,
  3039. 'introduction' => $user['introduction'] ?? null,
  3040. 'real_name' => $user['real_name'] ?? null,
  3041. 'mobile' => $user['mobile'] ?? null,
  3042. 'company_url' => $user['company_url'] ?? null,
  3043. 'address_arr_id' => $user['address_arr_id'] ?? null,
  3044. 'address' => $user['address'] ?? null,
  3045. 'email' => $user['email'] ?? null,
  3046. 'website_id' => $data['website_id'] ?? null,
  3047. 'user_type' => $user['type_id'] ?? null,
  3048. 'job_id' => $jobId,
  3049. ];
  3050. $companyId = JobCompany::insertGetId($company);
  3051. if (empty($companyId)) {
  3052. Db::rollBack();
  3053. return Result::error("添加失败");
  3054. }
  3055. // return Result::success($company);
  3056. }
  3057. Db::commit();
  3058. } catch (\Exception $e) {
  3059. Db::rollBack();
  3060. return Result::error($e->getMessage(), 0);
  3061. }
  3062. $result = [
  3063. 'job_id' => $jobId,
  3064. 'company_id' => $companyId,
  3065. ];
  3066. if (empty($result)) {
  3067. return Result::error("添加失败", 0);
  3068. }
  3069. return Result::success($result);
  3070. }
  3071. /*
  3072. * 获取招聘信息详情
  3073. * */
  3074. public function getJobRecruitingInfo(array $data): array
  3075. {
  3076. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  3077. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3078. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3079. ->select(
  3080. 'job_recruiting.*',
  3081. 'website.website_name as website_name',
  3082. 'job_company.business_name',
  3083. 'job_company.company_hy_id',
  3084. 'job_company.company_size',
  3085. 'job_company.company_nature',
  3086. 'job_company.introduction',
  3087. 'job_company.real_name',
  3088. 'job_company.mobile',
  3089. 'job_company.company_url',
  3090. 'job_company.address_arr_id',
  3091. 'job_company.address',
  3092. 'job_company.email'
  3093. )
  3094. ->first();
  3095. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  3096. if(!empty($cityId)){
  3097. if(isset($cityId[1]) && $cityId[1] != null){
  3098. $city = District::where('id', $cityId[1])->first(['name']);
  3099. }else{
  3100. $city = District::where('id', $cityId[0])->first(['name']);
  3101. }
  3102. $result['city'] = $city['name'] ?? '';
  3103. }
  3104. if(empty($result)){
  3105. return Result::error("招聘信息不存在", 0);
  3106. }
  3107. // return Result::success($job);
  3108. return Result::success($result);
  3109. }
  3110. /*
  3111. * 修改招聘信息
  3112. * */
  3113. public function upJobRecruiting(array $data): array
  3114. {
  3115. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  3116. // return Result::success($job);
  3117. if (empty($job)) {
  3118. return Result::error("招聘信息不存在", 0);
  3119. }
  3120. $user = User::where('id', $data['user_id'])->first();
  3121. // return Result::success($user);
  3122. if (empty($user) || $user['type_id'] != $data['user_type']) {
  3123. return Result::error("用户不存在", 0);
  3124. }
  3125. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  3126. return Result::error("用户暂无权限修改此招聘信息!", 0);
  3127. }
  3128. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  3129. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  3130. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  3131. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  3132. // 公司地址 管理员必填
  3133. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  3134. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  3135. // 管理员-企业相关信息
  3136. $company = [
  3137. 'business_name' => $data['business_name'] ?? null,
  3138. 'company_hy_id' => $data['hy_id'] ?? null,
  3139. 'company_size' => $data['company_size'] ?? null,
  3140. 'company_nature' => $data['company_nature'] ?? null,
  3141. 'introduction' => $data['introduction'] ?? null,
  3142. 'real_name' => $data['real_name'] ?? null,
  3143. 'mobile' => $data['mobile'] ?? null,
  3144. 'company_url' => $data['company_url'] ?? null,
  3145. 'address_arr_id' => $data['address_arr_id'] ?? null,
  3146. 'address' => $data['address'] ?? null,
  3147. 'email' => $data['email'] ?? null,
  3148. ];
  3149. //去掉相关企业信息
  3150. $data = array_diff_key($data, array_flip(array_keys($company)));
  3151. $jobId = $data['id'];
  3152. $web = $data['website_id'];
  3153. $data['action_id'] = $data['user_id'];
  3154. unset($data['user_id']);
  3155. unset($data['user_type']);
  3156. unset($data['id']);
  3157. unset($data['website_id']);
  3158. // return Result::success($data);
  3159. Db::beginTransaction();
  3160. try {
  3161. // 管理员修改招聘信息
  3162. if ($user['type_id'] == 10000) {
  3163. $data['website_id'] = $web;
  3164. $company['website_id'] = $data['website_id'];
  3165. $data['status'] = 1;
  3166. } else {
  3167. $data['status'] = 0;
  3168. }
  3169. // Db::rollBack();
  3170. // return Result::success($company);
  3171. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  3172. if (empty($result['job'])) {
  3173. Db::rollBack();
  3174. return Result::error("修改招聘信息失败");
  3175. }
  3176. // 管理员修改企业相关信息
  3177. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  3178. if (empty($result['company'])) {
  3179. Db::rollBack();
  3180. return Result::error("修改企业相关信息失败");
  3181. }
  3182. Db::commit();
  3183. // return Result::success($result);
  3184. } catch (\Exception $e) {
  3185. Db::rollBack();
  3186. return Result::error($e->getMessage(), 0);
  3187. }
  3188. return Result::success($result);
  3189. }
  3190. /*
  3191. * 招聘信息删除
  3192. * */
  3193. public function delJobRecruiting(array $data): array
  3194. {
  3195. $user = User::where('id', $data['user_id'])->first();
  3196. if (empty($user)) {
  3197. return Result::error("用户不存在", 0);
  3198. }
  3199. $job = JobRecruiting::where('id', $data['id'])->first();
  3200. if (empty($job)) {
  3201. return Result::error("招聘信息不存在", 0);
  3202. }
  3203. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  3204. return Result::error("用户暂无权限修改此招聘信息!", 0);
  3205. }
  3206. Db::beginTransaction();
  3207. try {
  3208. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  3209. if (empty($result['job'])) {
  3210. Db::rollBack();
  3211. return Result::error("删除招聘信息失败");
  3212. }
  3213. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  3214. if (empty($result['company'])) {
  3215. Db::rollBack();
  3216. return Result::error("删除企业相关信息失败");
  3217. }
  3218. Db::commit();
  3219. } catch (\Exception $e) {
  3220. Db::rollBack();
  3221. return Result::error($e->getMessage(), 0);
  3222. }
  3223. return Result::success($result);
  3224. }
  3225. /*
  3226. * 获取公司信息
  3227. * */
  3228. public function getJobCompany(array $data): array
  3229. {
  3230. $user = User::where('user.id', $data['user_id'])
  3231. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  3232. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  3233. ->first();
  3234. // return Result::success($user);
  3235. if (empty($user)) {
  3236. return Result::error("用户不存在", 0);
  3237. }
  3238. if ($user['type_id'] == 3) {
  3239. $result = [
  3240. // 'id' => 0,
  3241. 'user_id' => $data['user_id'],
  3242. 'website_id' => $data['website_id'],
  3243. 'business_name' => $user['business_name'], // 企业名称
  3244. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  3245. 'company_nature' => $user['company_nature'], // 公司性质
  3246. 'company_size' => $user['company_size'], // 公司规模
  3247. 'introduction' => $user['introduction'], // 公司简介
  3248. 'real_name' => $user['real_name'], // 企业联系人
  3249. 'mobile' => $user['mobile'], // 企业联系电话
  3250. 'company_url' => $user['company_url'], // 企业网址
  3251. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  3252. 'address' => $user['address'], // 企业地址
  3253. 'email' => $user['email'], // 企业邮箱
  3254. ];
  3255. } else {
  3256. return Result::error("用户类型错误", 0);
  3257. }
  3258. if (empty($result)) {
  3259. return Result::error("公司信息不存在", 0);
  3260. }
  3261. return Result::success($result);
  3262. }
  3263. /*
  3264. * 修改公司信息
  3265. * */
  3266. public function upJobCompany(array $data): array
  3267. {
  3268. // return Result::success($data);
  3269. $user = User::where('user.id', $data['user_id'])
  3270. ->where('user.status', 1)
  3271. ->select('user.user_name', 'user.type_id')
  3272. ->first();
  3273. if (empty($user)) {
  3274. return Result::error("用户不存在", 0);
  3275. }
  3276. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  3277. $company = [
  3278. 'business_name' => $data['business_name'], // 企业名称
  3279. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  3280. 'company_nature' => $data['company_nature'], // 公司性质
  3281. 'company_size' => $data['company_size'], // 公司规模
  3282. 'introduction' => $data['introduction'], // 公司简介
  3283. // 'real_name' => $data['real_name'], // 企业联系人
  3284. 'company_url' => $data['company_url'], // 企业网址
  3285. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  3286. 'address' => $data['address'], // 企业详细地址
  3287. ];
  3288. if ($user['type_id'] == 3) {
  3289. Db::beginTransaction();
  3290. try {
  3291. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  3292. 'business_name' => $data['business_name'], // 企业名称
  3293. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  3294. 'company_nature' => $data['company_nature'], // 公司性质
  3295. 'company_size' => $data['company_size'], // 公司规模
  3296. 'introduction' => $data['introduction'], // 公司简介
  3297. // 'real_name' => $data['real_name'], // 企业联系人
  3298. 'company_url' => $data['company_url'], // 企业网址
  3299. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  3300. 'address' => $data['address'], // 企业详细地址
  3301. ]);
  3302. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  3303. Db::commit();
  3304. } catch (\Exception $e) {
  3305. Db::rollBack();
  3306. return Result::error($e->getMessage(), 0);
  3307. }
  3308. } else {
  3309. return Result::error("用户类型错误", 0);
  3310. }
  3311. if (empty($result)) {
  3312. return Result::error("修改失败", 0);
  3313. }
  3314. return Result::success($result);
  3315. }
  3316. /*
  3317. * 获取省-市
  3318. * */
  3319. public function getJobRecruitingArea(array $data): array
  3320. {
  3321. if(isset($data['pid']) && $data['pid']!=null){
  3322. $result = District::where('pid',$data['pid'])->get()->all();
  3323. }else{
  3324. $result = District::where('level',1)->get()->all();
  3325. }
  3326. if (empty($result)) {
  3327. return Result::error("暂无此省市", 0);
  3328. }
  3329. return Result::success($result);
  3330. }
  3331. /*
  3332. * 获取行业分类
  3333. * */
  3334. public function getIndustry(array $data): array
  3335. {
  3336. $result = JobIndustry::get()->all();
  3337. if (empty($result)) {
  3338. return Result::error("暂无行业分类", 0);
  3339. }
  3340. return Result::success($result);
  3341. }
  3342. /*
  3343. * 获取职位
  3344. * */
  3345. public function getPositionList(array $data): array
  3346. {
  3347. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  3348. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  3349. } else {
  3350. $result = JobPosition::where('zwpid', 0)->get()->all();
  3351. }
  3352. if (empty($result)) {
  3353. return Result::error("暂无此职位", 0);
  3354. }
  3355. return Result::success($result);
  3356. }
  3357. /*
  3358. * 获取工作性质-菜单
  3359. * */
  3360. public function getJobNature(array $data): array
  3361. {
  3362. $result = JobEnum::where('egroup', 'nature')->get()->all();
  3363. if (empty($result)) {
  3364. return Result::error("暂无工作性质", 0);
  3365. }
  3366. return Result::success($result);
  3367. }
  3368. /*
  3369. * 获取工作经验-菜单
  3370. * */
  3371. public function getExperience(array $data): array
  3372. {
  3373. $result = JobEnum::where('egroup', 'years')->get()->all();
  3374. if (empty($result)) {
  3375. return Result::error("暂无工作经验", 0);
  3376. }
  3377. return Result::success($result);
  3378. }
  3379. /*
  3380. * 获取学历-菜单
  3381. * */
  3382. public function getEducation(array $data): array
  3383. {
  3384. $result = JobEnum::where('egroup', 'education')->get()->all();
  3385. if (empty($result)) {
  3386. return Result::error("暂无学历", 0);
  3387. }
  3388. return Result::success($result);
  3389. }
  3390. /*
  3391. * 获取薪资-菜单
  3392. * */
  3393. public function getSalary(array $data): array
  3394. {
  3395. $result = JobEnum::where('egroup', 'income')->get()->all();
  3396. if (empty($result)) {
  3397. return Result::error("暂无薪资", 0);
  3398. }
  3399. return Result::success($result);
  3400. }
  3401. /*
  3402. * 获取语言-菜单
  3403. * */
  3404. public function getLanguage(array $data): array
  3405. {
  3406. $result = JobEnum::where('egroup', 'language')->get()->all();
  3407. if (empty($result)) {
  3408. return Result::error("暂无语言", 0);
  3409. }
  3410. return Result::success($result);
  3411. }
  3412. /*
  3413. * 获取掌握程度-菜单
  3414. * */
  3415. public function getLevel(array $data): array
  3416. {
  3417. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  3418. if (empty($result)) {
  3419. return Result::error("暂无工作性质", 0);
  3420. }
  3421. return Result::success($result);
  3422. }
  3423. // 公司信息
  3424. /*
  3425. * 获取公司性质-菜单
  3426. * */
  3427. public function getCompanyNature(array $data): array
  3428. {
  3429. $result = JobNature::get()->all();
  3430. if (empty($result)) {
  3431. return Result::error("暂无公司性质", 0);
  3432. }
  3433. return Result::success($result);
  3434. }
  3435. /*
  3436. * 获取公司规模-菜单
  3437. * */
  3438. public function getCompanySize(array $data): array
  3439. {
  3440. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  3441. if (empty($result)) {
  3442. return Result::error("暂无公司规模", 0);
  3443. }
  3444. return Result::success($result);
  3445. }
  3446. /*
  3447. * 招聘信息审核
  3448. * */
  3449. public function checkJobRecruiting(array $data): array
  3450. {
  3451. $user = User::where('id', $data['user_id'])->first();
  3452. if (empty($user)) {
  3453. return Result::error("用户不存在", 0);
  3454. }
  3455. $job = JobRecruiting::where('id', $data['id'])->first();
  3456. if (empty($job)) {
  3457. return Result::error("招聘信息不存在", 0);
  3458. }
  3459. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  3460. if ($user['type_id'] != 10000) {
  3461. return Result::error("用户暂无权限审核此招聘信息!", 0);
  3462. }
  3463. // 驳回原因
  3464. if ($data['status'] == 2) {
  3465. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  3466. }
  3467. $data['action_id'] = $data['user_id'];
  3468. unset($data['user_id']);
  3469. $result = JobRecruiting::where('id', $data['id'])->update($data);
  3470. if (empty($result)) {
  3471. return Result::error("审核失败", 0);
  3472. }
  3473. return Result::success($result);
  3474. }
  3475. /*
  3476. * 获取招聘信息列表
  3477. * */
  3478. public function getRecruitingList(array $data): array
  3479. {
  3480. $user = User::where('id', $data['user_id'])->first();
  3481. if(empty($user) || ($user['type_id']!= 10000 && $user['type_id']!= 1)){
  3482. return Result::error("用户不存在", 0);
  3483. }
  3484. $recruitingId = JobApply::where('user_id', $data['user_id'])
  3485. ->pluck('recruit_id');
  3486. $where = [];
  3487. if(isset($data['salary']) && $data['salary']!=null){
  3488. $where['job_recruiting.salary'] = $data['salary'];
  3489. }
  3490. if(isset($data['experience']) && $data['experience']!=null){
  3491. $where['job_recruiting.experience'] = $data['experience'];
  3492. }
  3493. if(isset($data['business_name']) && $data['business_name']!=null){
  3494. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  3495. }
  3496. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  3497. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3498. ->where($where);
  3499. // ->count();
  3500. $count = $query->count();
  3501. $query = clone $query;
  3502. $job = $query
  3503. ->leftJoin('job_enum as income_enum', function ($join) {
  3504. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  3505. ->where('income_enum.egroup', 'income');
  3506. })
  3507. ->leftJoin('job_enum as years_enum', function ($join) {
  3508. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  3509. ->where('years_enum.egroup', 'years');
  3510. })
  3511. // ->where($where)
  3512. ->orderBy('job_recruiting.updated_at', 'desc')
  3513. ->select('job_recruiting.id','job_recruiting.title', 'job_company.business_name', 'income_enum.evalue as salary_evalue', 'income_enum.ename as salary_ename', 'years_enum.evalue as experience_evalue', 'years_enum.ename as experience_ename')
  3514. ->offset(($data['page'] - 1) * $data['pageSize'])
  3515. ->limit($data['pageSize'])
  3516. ->get()
  3517. ->all();
  3518. if (empty($job)) {
  3519. return Result::error("暂无招聘信息", 0);
  3520. }
  3521. $result = [
  3522. 'row' => $job,
  3523. 'count' => $count,
  3524. ];
  3525. return Result::success($result);
  3526. }
  3527. // 20250306 招聘
  3528. //20250422 书刊音像
  3529. public function addBook(array $data): array
  3530. {
  3531. $user_id = $data['user_id'] ?? 0;
  3532. $type_id = $data['type_id'] ?? 0;
  3533. $website_id = $data['website_id'] ?? 0;
  3534. // unset($data['user_id']);
  3535. unset($data['type_id']);
  3536. // unset($data['website_id']);
  3537. //处理数组
  3538. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  3539. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  3540. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  3541. if ($data['img_url'] == '') {
  3542. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3543. preg_match_all($reg, $data['detail'], $matches);
  3544. if (isset($matches[1][0])) {
  3545. //截取varchar240
  3546. $data['img_url'] = substr($matches[1][0], 0, 240);
  3547. }
  3548. }
  3549. if ($data['keyword'] == '') {
  3550. //提取标题+内容中的关键词
  3551. $data['keyword'] = $data['title'];
  3552. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3553. Jieba::init(); // 初始化 jieba-php
  3554. Finalseg::init();
  3555. $segList = Jieba::cut($data['keyword']);
  3556. $segList1 = array_slice($segList, 0, 8);
  3557. $data['keyword'] = implode(',', $segList1);
  3558. }
  3559. if ($data['description'] == '') {
  3560. //提取内容中的描述
  3561. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3562. }
  3563. $result = Book::insertGetId($data);
  3564. if (empty($result)) {
  3565. return Result::error("添加失败", 0);
  3566. }
  3567. return Result::success($result);
  3568. }
  3569. public function getBookList(array $data): array
  3570. {
  3571. $where = [];
  3572. if (!empty($data["title"])) {
  3573. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  3574. }
  3575. if (!empty($data['website_name'])) {
  3576. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3577. }
  3578. if (!empty($data['status'])) {
  3579. $where[] = ['book.status', '=', $data['status']];
  3580. }
  3581. $user_id = $data['user_id'];
  3582. $type_id = $data['type_id'];
  3583. // $type_id = 4;
  3584. var_dump($type_id, '------1--------');
  3585. if ($type_id != 10000) {
  3586. $where[] = ['book.user_id', '=', $user_id];
  3587. }
  3588. var_dump(!empty($data['status1']), '=-===1');
  3589. $result = Book::where($where)
  3590. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  3591. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  3592. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  3593. ->when(isset($data['status1']), function ($query) use ($data) {
  3594. $query->whereIn('book.status', [1, 3]);
  3595. })
  3596. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  3597. ->orderBy("updated_at", "desc")
  3598. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  3599. if (empty($result)) {
  3600. return Result::error("暂无数据", 0);
  3601. }
  3602. // 取出数据
  3603. $rows = $result->items();
  3604. $count = $result->total();
  3605. $responseData = [
  3606. 'rows' => $rows,
  3607. 'count' => $count,
  3608. ];
  3609. return Result::success($responseData);
  3610. }
  3611. public function deleteBook(array $data): array
  3612. {
  3613. $result = Book::where('id', $data['id'])->delete();
  3614. if (empty($result)) {
  3615. return Result::error("删除失败", 0);
  3616. }
  3617. return Result::success($result);
  3618. }
  3619. public function updateBook(array $data): array
  3620. {
  3621. $user_id = $data['user_id'] ?? 0;
  3622. $type_id = $data['type_id'] ?? 0;
  3623. $website_id = $data['website_id'] ?? 0;
  3624. unset($data['user_id']);
  3625. unset($data['type_id']);
  3626. // unset($data['website_id']);
  3627. //处理数组
  3628. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  3629. if ($data['img_url'] == '') {
  3630. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3631. preg_match_all($reg, $data['detail'], $matches);
  3632. if (isset($matches[1][0])) {
  3633. //截取varchar240
  3634. $data['img_url'] = substr($matches[1][0], 0, 240);
  3635. }
  3636. }
  3637. if ($data['keyword'] == '') {
  3638. //提取标题+内容中的关键词
  3639. $data['keyword'] = $data['title'];
  3640. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3641. Jieba::init(); // 初始化 jieba-php
  3642. Finalseg::init();
  3643. $segList = Jieba::cut($data['keyword']);
  3644. $segList1 = array_slice($segList, 0, 8);
  3645. $data['keyword'] = implode(',', $segList1);
  3646. }
  3647. if ($data['description'] == '') {
  3648. //提取内容中的描述
  3649. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3650. }
  3651. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  3652. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  3653. $result = Book::where("id", $data["id"])->update($data);
  3654. if (empty($result)) {
  3655. return Result::error("更新失败", 0);
  3656. }
  3657. return Result::success($result);
  3658. }
  3659. public function getBookInfo(array $data): array
  3660. {
  3661. $result = Book::where("id", $data["id"])->first();
  3662. if (empty($result)) {
  3663. return Result::error("获取失败", 0);
  3664. }
  3665. return Result::success($result);
  3666. }
  3667. public function updateBookStatus(array $data): array
  3668. {
  3669. $result = Book::where("id", $data["id"])->update($data);
  3670. if (empty($result)) {
  3671. return Result::error("更新失败", 0);
  3672. }
  3673. return Result::success($result);
  3674. }
  3675. //20250422 书刊音像
  3676. }