WebService.php 154 KB

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