WebService.php 149 KB

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