WebService.php 157 KB

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