WebService.php 160 KB

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