WebService.php 160 KB

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