WebService.php 155 KB

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