WebService.php 153 KB

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