NewsService.php 157 KB

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