WebsiteService.php 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477
  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\TemplateClass;
  15. use App\Model\Template;
  16. use App\Model\User;
  17. use App\Model\UserInfo;
  18. use App\Model\WebsiteRole;
  19. use App\Model\WebsiteRoleUser;
  20. use App\Model\Website;
  21. use App\Model\WebsiteColumn;
  22. use App\Model\Good;
  23. use App\Model\Book;
  24. use App\Model\ChatRecords;
  25. use App\Model\ChatTopic;
  26. use App\Model\JobRecruiting;
  27. use App\Model\JobHunting;
  28. use App\Model\Notice;
  29. use App\Model\Complaint;
  30. use App\Model\Order;
  31. use App\Model\WebsiteImg;
  32. use App\Model\Company;
  33. use App\Model\Project;
  34. use App\Model\ChatTopicsReply;
  35. use Hyperf\HttpServer\Contract\RequestInterface;
  36. use Hyperf\DbConnection\Db;
  37. use Hyperf\RpcServer\Annotation\RpcService;
  38. use App\Tools\Result;
  39. use Carbon\Carbon;
  40. use App\Model\WebsiteCategory;
  41. use App\Model\WebsiteGroup;
  42. use App\Model\WebsiteTemplate;
  43. use App\Model\Sector;
  44. use PhpParser\Node\Stmt\Return_;
  45. use SimpleKafkaClient\Metadata\Topic;
  46. use function PHPUnit\Framework\isNull;
  47. use Overtrue\Pinyin\Pinyin;
  48. use App\Tools\buildTree;
  49. use App\Model\WhiteRouter;
  50. use App\Model\Size;
  51. use App\Tools\PinyinHelper;
  52. use Hyperf\HttpServer\Annotation\AutoController;
  53. use Hyperf\Utils\Parallel;
  54. use Hyperf\Coroutine\Concurrent;
  55. use function Hyperf\Coroutine\batch;
  56. use Swoole\Coroutine;
  57. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  58. class WebsiteService implements WebsiteServiceInterface
  59. {
  60. /**
  61. * 获取网站列表
  62. * @param string $keyword
  63. * @param int $page
  64. * @param int $pageSize
  65. * @return array
  66. */
  67. public function getWebsitetList(array $data): array
  68. {
  69. // 构建查询
  70. $query = Website::when($data, function ($query) use ($data) {
  71. if (isset($data['keyword']) && !empty($data['keyword'])) {
  72. $query->where('zxt_website.website_name', 'like', '%' . trim($data['keyword']) . '%');
  73. }
  74. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  75. $query->whereJsonContains("zxt_website.website_column_arr_id", intval($data['website_column_id']));
  76. }
  77. if (isset($data['web_type']) && !empty($data['web_type'])) {
  78. $query->where('zxt_website.web_type', intval($data['web_type']));
  79. }
  80. if (isset($data['is_core']) && !empty($data['is_core'])) {
  81. $query->where('zxt_website.is_core', intval($data['is_core']));
  82. }
  83. });
  84. $column_name = WebsiteColumn::pluck('column_name', 'id')->all();
  85. $queryWithJoins = $query->leftJoin("zxt_website_column", "zxt_website.website_column_id", "zxt_website_column.id");
  86. $count = $queryWithJoins->count();
  87. $result = $queryWithJoins->select("zxt_website.*", "zxt_website_column.column_name")
  88. ->limit($data['pageSize'])
  89. ->offset(($data['page'] - 1) * $data['pageSize'])
  90. ->orderBy("zxt_website.updated_at", "desc")
  91. ->get()
  92. ->all();
  93. foreach ($result as $key => $value) {
  94. $column_arr = json_decode($value['website_column_arr_id']);
  95. $result[$key]['website_url'] = json_decode($value['website_url']);
  96. $result[$key]['website_column_arr_id'] = $column_arr;
  97. $result[$key]['city_arr_id'] = json_decode($value['city_arr_id'] ?? '[]', true);
  98. if(count($column_arr) > 1){
  99. $result[$key]['column_name'] = implode('/', array_intersect_key($column_name, array_flip($column_arr)));
  100. }
  101. }
  102. if (empty($result)) {
  103. return Result::error("没有数据", 0);
  104. }
  105. $data = [
  106. 'rows' => $result,
  107. 'count' => $count,
  108. ];
  109. return Result::success($data);
  110. }
  111. /**
  112. * @param array $data
  113. */
  114. public function createWebsite(array $data): array
  115. {
  116. var_dump("网站数据:", $data);
  117. // $wzbs = $this->getWebsitetAdkey($data);
  118. // return Result::success($wzbs);
  119. $web = Website::where('ad_key', $data['ad_key'])->first();
  120. if (!empty($web)) {
  121. return Result::error("网站名称简写重复,请填写", 0);
  122. }
  123. $insertData = [
  124. 'website_name' => $data['website_name'],
  125. 'logo' => $data['logo'] ?? '',
  126. 'website_url' => $data['website_url'] ?? '',
  127. //'city_id'=>$data['city_id']??0,
  128. 'website_column_id' => $data['website_column_id'],
  129. 'title' => $data['title'] ?? '',
  130. 'keywords' => $data['keywords'] ?? '',
  131. 'description' => $data['description'] ?? '',
  132. 'status' => $data['status'] ?? 1,
  133. 'website_column_arr_id' => $data['website_column_arr_id'],
  134. //'city_arr_id'=>$data['city_arr_id']??[0],
  135. 'template_id' => $data['template_id'] ?? 0,
  136. 'suffix' => $data['suffix'] ?? "",
  137. 'ad_key' => $data['ad_key'] ?? "",
  138. 'index_img' => $data['index_img'] ?? '',
  139. 'qr_code' => $data['qr_code'] ?? '',
  140. 'web_type' => $data['web_type'] ?? 0,
  141. 'is_core' => $data['is_core'] ?? 0,
  142. ];
  143. $result = Website::insertGetId($insertData);
  144. if (empty($result)) {
  145. return Result::error("创建网站失败", 0);
  146. } else {
  147. return Result::success(["id" => $result]);
  148. }
  149. }
  150. /**
  151. * 修改网站头部基础信息
  152. * @param array $data
  153. */
  154. public function updateWebsite(int $id, array $data): array
  155. {
  156. $website = Website::where('id', $id)->first();
  157. if (empty($website)) {
  158. return Result::error("网站不存在", 0);
  159. }
  160. $insertData = [
  161. 'website_name' => $data['website_name'],
  162. 'logo' => $data['logo'] ?? '',
  163. 'website_url' => $data['website_url'] ?? '',
  164. // 'city_id'=>$data['city_id']??0,
  165. 'website_column_id' => $data['website_column_id'],
  166. 'title' => $data['title'] ?? '',
  167. 'keywords' => $data['keywords'] ?? '',
  168. 'description' => $data['description'] ?? '',
  169. // 'status' => $data['status'] ?? 0,
  170. 'website_column_arr_id' => $data['website_column_arr_id'],
  171. // 'city_arr_id'=>$data['city_arr_id']??[0],
  172. 'template_id' => $data['template_id'] ?? 0,
  173. 'suffix' => $data['suffix'] ?? "",
  174. 'ad_key' => $data['ad_key'] ?? "",
  175. 'index_img' => $data['index_img'] ?? '',
  176. 'qr_code' => $data['qr_code'] ?? '',
  177. 'web_type' => $data['web_type'] ?? 0,
  178. 'is_core' => $data['is_core'] ?? 0,
  179. ];
  180. // $web_templsate = WebsiteTemplateInfo::where('website_id', $data['id'])->first();
  181. // `status` tinyint(1) DEFAULT '0' COMMENT '0:未构建 1:未应用 2:已应用',
  182. // if (!empty($web_templsate) && $web_templsate['status'] == 2) {
  183. // return Result::error("此网站已应用,不可修改基本信息", 0);
  184. // }
  185. Db::beginTransaction();
  186. try {
  187. if ($data['ad_key'] != $website['ad_key']) {
  188. $web = Website::where(function ($query) use ($data) {
  189. $query->where('id', '!=', $data['id'])
  190. ->where('ad_key', $data['ad_key']);
  191. })->first();
  192. if (!empty($web)) {
  193. Db::rollBack();
  194. return Result::error("网站名称简写重复,请填写", 0);
  195. }
  196. $ad_place = AdPlace::where('website_id', $data['id'])->select('ad_tag', 'id')->get()->toArray();
  197. if (!empty($ad_place)) {
  198. foreach ($ad_place as $key => $val) {
  199. $ad_keys = explode('_', $val['ad_tag']);
  200. $ad_keys[0] = $data['ad_key'];
  201. $ad_place[$key]['ad_tag'] = implode('_', $ad_keys);
  202. // $up_adtags = AdPlace::where('id', $val['id'])->update(['ad_tag' => $ad_tags[$key]]);
  203. }
  204. $up_adtags = AdPlace::upsert($ad_place, ['id'], ['ad_tag']);
  205. if (empty($up_adtags)) {
  206. Db::rollBack();
  207. return Result::error('广告位标识同步失败', 0);
  208. }
  209. }
  210. $template = WebsiteTemplate::where('website_id', $data['id'])->first();
  211. if (!empty($template)) {
  212. // Eloquent 没有 replace 方法,推测你可能是想替换模板中的字符串,假设是更新 content 字段
  213. $uptemplate = WebsiteTemplate::where('website_id', $data['id'])->update([
  214. 'template_data' => DB::raw("REPLACE(template_data, '{$website['ad_key']}', '{$data['ad_key']}')")
  215. ]);
  216. if (empty($uptemplate)) {
  217. Db::rollBack();
  218. return Result::error("更新模板失败!", 0);
  219. }
  220. }
  221. }
  222. // return Result::success($UP_template);
  223. $result = Website::where('id', $data['id'])->update($insertData);
  224. if (empty($result)) {
  225. Db::rollBack();
  226. return Result::error("更新网站失败!", 0);
  227. }
  228. Db::commit();
  229. return Result::success("更新成功");
  230. } catch (\Exception $e) {
  231. Db::rollBack();
  232. return Result::error($e->getMessage(), 0);
  233. }
  234. }
  235. /**
  236. * @param int $id
  237. * @return array
  238. */
  239. public function delWebsite(int $id): array
  240. {
  241. $result = Website::where('id', $id)->delete();
  242. if (empty($result)) {
  243. return Result::error("删除失败", 0);
  244. } else {
  245. return Result::success();
  246. }
  247. }
  248. /**
  249. * @param int $id
  250. * @return array
  251. */
  252. public function getWebsiteInfo(int $id): array
  253. {
  254. $where = [
  255. ['zxt_website.id', '=', $id],
  256. ];
  257. $result = Website::where($where)
  258. ->leftJoin("template", "template.id", "zxt_website.template_id")
  259. ->select("zxt_website.*", "template.template_name", "template.template_img")
  260. ->first();
  261. if (empty($result)) {
  262. return Result::error("数据不存在", 0);
  263. } else {
  264. return Result::success($result->toArray());
  265. }
  266. }
  267. /**
  268. * 查询所有的站点栏目
  269. * @return array
  270. */
  271. public function getWebsiteColumn(array $data): array
  272. {
  273. $result = WebsiteColumn::where($data)->get();
  274. if (empty($result)) {
  275. return Result::error("数据不存在", 0);
  276. } else {
  277. return Result::success($result->toArray());
  278. }
  279. }
  280. /**
  281. * @param string $keyword
  282. * @param int $page
  283. * @param int $pageSize
  284. * @return array
  285. */
  286. public function getWebsiteColumnList(array $data): array
  287. {
  288. $where = [];
  289. if (isset($data['keyword']) && $data['keyword']) {
  290. array_push($where, ['zxt_website_column.column_name', 'like', '%' . $data['keyword'] . '%']);
  291. }
  292. $result = WebsiteColumn::where($where)
  293. ->leftJoin("zxt_website_column as wc", "zxt_website_column.pid", "wc.id")
  294. ->select("zxt_website_column.*", "wc.column_name as parent_column_name")
  295. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
  296. $count = WebsiteColumn::where($where)->count();
  297. if (empty($result)) {
  298. return Result::error("没有数据", 0);
  299. }
  300. $data = [
  301. 'rows' => $result->toArray(),
  302. 'count' => $count,
  303. ];
  304. return Result::success($data);
  305. }
  306. /**
  307. * @param array $data
  308. * @return array
  309. */
  310. public function createWebsiteColumn(array $data): array
  311. {
  312. $insertData = [
  313. 'column_name' => $data['column_name'],
  314. 'pid' => $data['pid'] ?? '',
  315. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  316. 'sort' => $data['sort'] ?? 0,
  317. 'remark' => $data['remark'] ?? '',
  318. ];
  319. $result = WebsiteColumn::insertGetId($insertData);
  320. if (empty($result)) {
  321. return Result::error("创建失败", 0);
  322. } else {
  323. return Result::success(["id" => $result]);
  324. }
  325. }
  326. /**
  327. * @param int $id
  328. * @param array $data
  329. * @return array
  330. */
  331. public function updateWebsiteColumn(int $id, array $data): array
  332. {
  333. $insertData = [
  334. 'column_name' => $data['column_name'],
  335. 'pid' => $data['pid'] ?? '',
  336. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  337. 'sort' => $data['sort'] ?? 0,
  338. 'remark' => $data['remark'] ?? '',
  339. ];
  340. $result = WebsiteColumn::where('id', $id)->update($insertData);
  341. if (empty($result)) {
  342. return Result::error("更新失败", 0);
  343. } else {
  344. return Result::success();
  345. }
  346. }
  347. /**
  348. * @param int $id
  349. * @return array
  350. */
  351. public function delWebsiteColumn(int $id): array
  352. {
  353. $list = WebsiteColumn::where(['pid' => $id])->get();
  354. if ($list) {
  355. return Result::error("存在子网系,不能删除,请先删除子网系", 0);
  356. }
  357. $result = WebsiteColumn::where('id', $id)->delete();
  358. if (empty($result)) {
  359. return Result::error("删除失败", 0);
  360. } else {
  361. return Result::success();
  362. }
  363. }
  364. /**
  365. * @param string $keyword
  366. * @param int $page
  367. * @param int $pageSize
  368. * @return array
  369. */
  370. public function getWebsiteRoleList(string $keyword, int $page, int $pageSize, int $websiteId): array
  371. {
  372. $where = [
  373. ['role.role_name', 'like', '%' . $keyword . '%'],
  374. ['website_role.website_id', '=', $websiteId],
  375. ];
  376. $result = WebsiteRole::where($where)
  377. ->leftJoin("role", "role.id", "website_role.role_id")
  378. ->select("role.*", "website_role.type", "website_role.role_id", "website_role.id as website_role_id", "website_role.website_id")
  379. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  380. $count = WebsiteRole::where($where)->leftJoin("role", "role.id", "website_role.role_id")->count();
  381. if (empty($result)) {
  382. return Result::error("没有数据", 0);
  383. }
  384. $data = [
  385. 'rows' => $result->toArray(),
  386. 'count' => $count,
  387. ];
  388. return Result::success($data);
  389. }
  390. /**
  391. * @param array $data
  392. * @return array
  393. */
  394. public function createWebsiteRole(array $data): array
  395. {
  396. $insertData = [
  397. 'website_id' => $data['website_id'],
  398. 'role_id' => $data['role_id'] ?? '',
  399. ];
  400. $info = WebsiteRole::where($insertData)->first();
  401. if ($info) {
  402. return Result::error("不能重复添加角色", 0);
  403. }
  404. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  405. $insertData['type'] = $data['type'] ?? '';
  406. $result = WebsiteRole::insertGetId($insertData);
  407. if (empty($result)) {
  408. return Result::error("创建失败", 0);
  409. } else {
  410. return Result::success(["id" => $result]);
  411. }
  412. }
  413. /**
  414. * 暂时用不上
  415. * @param int $id
  416. * @param array $data
  417. * @return array
  418. */
  419. public function updateWebsiteRole(int $id, array $data): array
  420. {
  421. $insertData = [
  422. 'website_id' => $data['website_id'],
  423. 'type' => $data['type'] ?? '',
  424. ];
  425. $result = WebsiteRole::where('id', $id)->update($insertData);
  426. if (empty($result)) {
  427. return Result::error("更新失败", 0);
  428. } else {
  429. return Result::success();
  430. }
  431. }
  432. /**
  433. * @param int $id
  434. * @return array
  435. */
  436. public function delWebsiteRole(int $id): array
  437. {
  438. $result = WebsiteRole::where('id', $id)->delete();
  439. if (empty($result)) {
  440. return Result::error("删除失败", 0);
  441. } else {
  442. return Result::success();
  443. }
  444. }
  445. /**
  446. * @param string $keyword
  447. * @param int $page
  448. * @param int $pageSize
  449. * @return array
  450. */
  451. public function getWebsiteRoleUserList(string $keyword, int $page, int $pageSize, int $websiteId, int $roleId): array
  452. {
  453. $where = [
  454. ['website_role_user.website_id', '=', $websiteId],
  455. ['website_role_user.role_id', '=', $roleId],
  456. ];
  457. $count = WebsiteRoleUser::where($where)->count();
  458. $where[] = ['u.user_name', 'like', '%' . $keyword . '%'];
  459. $result = WebsiteRoleUser::where($where)
  460. ->leftJoin("user as u", "website_role_user.user_id", "u.id")
  461. ->leftJoin("website as w", "website_role_user.website_id", "u.id")
  462. ->leftJoin("role as r", "website_role_user.role_id", "r.id")
  463. ->select("u.*", "u.user_name", 'w.website_name', 'r.role_name', 'website_role_user.id as website_role_user_id', 'website_role_user.updated_at as user_update_at')
  464. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  465. if (empty($result)) {
  466. return Result::error("没有数据", 0);
  467. }
  468. $data = [
  469. 'rows' => $result->toArray(),
  470. 'count' => $count,
  471. ];
  472. return Result::success($data);
  473. }
  474. /**
  475. * @param array $data
  476. * @return array
  477. */
  478. public function createWebsiteRoleUser(array $data): array
  479. {
  480. $insertData = [
  481. 'website_id' => $data['website_id'],
  482. 'user_id' => $data['user_id'] ?? '',
  483. ];
  484. $info = WebsiteRoleUser::where($insertData)->first();
  485. if ($info) {
  486. return Result::error("不能重复添加角色用户", 0);
  487. }
  488. $insertData['role_id'] = $data['role_id'] ?? '';
  489. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  490. $insertData['type'] = $data['type'] ?? '';
  491. $result = WebsiteRoleUser::insertGetId($insertData);
  492. if (empty($result)) {
  493. return Result::error("创建失败", 0);
  494. } else {
  495. return Result::success(["id" => $result]);
  496. }
  497. }
  498. /**
  499. * @param int $id
  500. * @param array $data
  501. * @return array
  502. */
  503. public function updateWebsiteRoleUser(int $id, array $data): array
  504. {
  505. $insertData = [
  506. 'website_id' => $data['website_id'],
  507. 'type' => $data['type'] ?? '',
  508. 'type_id' => $data['type_id'] ?? '',
  509. 'role_id' => $data['role_id'] ?? '',
  510. ];
  511. $result = WebsiteRoleUser::where('id', $id)->update($insertData);
  512. if (empty($result)) {
  513. return Result::error("更新失败", 0);
  514. } else {
  515. return Result::success();
  516. }
  517. }
  518. /**
  519. * @param int $id
  520. * @return array
  521. */
  522. public function delWebsiteRoleUser(int $id): array
  523. {
  524. $result = WebsiteRoleUser::where('id', $id)->delete();
  525. if (empty($result)) {
  526. return Result::error("删除失败", 0);
  527. } else {
  528. return Result::success();
  529. }
  530. }
  531. /**
  532. * 根据域名获取网站 站点id
  533. * @param array $data
  534. * @return array
  535. */
  536. public function getWebsiteId(array $data): array
  537. {
  538. $result = Website::whereJsonContains('website_url', $data['website_url'])->first();
  539. if (empty($result)) {
  540. return Result::error("查询站点失败", 0);
  541. } else {
  542. return Result::success($result);
  543. }
  544. }
  545. /**
  546. *各省市查询
  547. * @param array $data
  548. * @return array
  549. */
  550. public function selectWebsiteArea()
  551. {
  552. // return Result::success($data);
  553. $pid = $data['pid'] ?? 0;
  554. $result = District::leftJoin('district as district2', 'district.pid', '=', 'district2.id')
  555. ->where('district.pid', $pid)
  556. ->where('district.status', 1)
  557. ->select('district.*', 'district2.name as pid_name')
  558. ->orderBy('district.code')->get();
  559. if (empty($result)) {
  560. return Result::error("未查询到此地区", 0);
  561. } else {
  562. return Result::success($result);
  563. }
  564. }
  565. /**
  566. * 获取友情链接
  567. * @param array $data
  568. * @return array
  569. */
  570. public function selectWebsiteLinks(array $data): array
  571. {
  572. $where = [
  573. 'website_id' => $data['website_id'],
  574. 'status' => 1,
  575. 'type' => $data['type'],
  576. ];
  577. $num = $data['num'];
  578. $result = Link::where($where)->orderBy('sort')->limit($num)->get();
  579. if (!empty($result)) {
  580. return Result::success($result);
  581. } else {
  582. return Result::error("本网站暂无此类型友情链接", 0);
  583. }
  584. }
  585. /**
  586. *
  587. * @param array $data
  588. * @return array
  589. */
  590. /**网站行政职能搜索 */
  591. public function selectWebsiteDepartment(array $data): array
  592. {
  593. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->get();
  594. if (isset($data['keyword']) && !empty($data['keyword'])) {
  595. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  596. if (empty($departments)) {
  597. $result['message'] = "未查询到与此相关职能部门";
  598. } else {
  599. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  600. $m = [
  601. 'department' => $depart,
  602. 'type' => $departments,
  603. 'count' => $count,
  604. ];
  605. }
  606. $result['sele'] = $m;
  607. return Result::success($result['sele']);
  608. }
  609. $result = $depart;
  610. return Result::success($result);
  611. }
  612. /**
  613. * 网站首页数据统计, 管理员
  614. * @return void
  615. */
  616. public function getAdminIndex(array $data): array
  617. {
  618. var_dump("用户类型:", $data);
  619. switch ($data['type_id']) {
  620. case 10000:
  621. $res = [];
  622. //网站
  623. $res['website']['count'] = 0;
  624. $res['website']['growth_rate'] = 0;
  625. //资讯
  626. $res['article']['count'] = 0;
  627. $res['article']['growth_rate'] = 0;
  628. //导航池
  629. $res['category']['count'] = 0;
  630. $res['category']['growth_rate'] = 0;
  631. //商品
  632. $res['good']['count'] = 0;
  633. $res['book']['count'] = 0;
  634. $res['jobHunting']['count'] = 0;
  635. $res['jobRecruiting']['count'] = 0;
  636. //近一月数据
  637. $res['monthArticle'] = [];
  638. //用户类型
  639. $res['userType'] = [];
  640. $res['website']['count'] = Website::where([])->count();
  641. $res['article']['count'] = Article::whereIn('status', [1])->count();
  642. $res['category']['count'] = Category::where([])->count();
  643. $res['good']['count'] = Good::whereIn('status', [2])->count();
  644. $res['book']['count'] = Book::whereIn('status', [2])->count();
  645. $res['jobHunting']['count'] = JobHunting::whereIn('status', [2])->count();
  646. $res['jobRecruiting']['count'] = JobRecruiting::whereIn('status', [1])->count();
  647. $res['complaint']['count'] = Complaint::whereIn('status', [2])->count();
  648. $res['notice']['count'] = Notice::whereIn('status', [2])->count();
  649. //已审核数量
  650. $res['company']['count'] = Company::whereIn('status', [1])->count();
  651. $res['project']['count'] = Project::whereIn('status', [1])->count();
  652. // $res['monthArticle'] = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM article WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
  653. $res['monthArticle'] = Db::select(' SELECT DATE(article.created_at) AS date,COUNT(*) AS count ,user.type_id FROM article left JOIN user on article.admin_user_id = user.id WHERE
  654. article.status =1 and article.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(article.created_at),`user`.type_id ORDER BY date ASC');
  655. $res['monthGood'] = Db::select(' SELECT DATE(good.created_at) AS date,COUNT(*) AS count ,user.type_id FROM good left JOIN user on good.user_id = user.id WHERE
  656. good.status =2 and good.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(good.created_at),`user`.type_id ORDER BY date ASC');
  657. $res['monthBook'] = Db::select(' SELECT DATE(book.created_at) AS date,COUNT(*) AS count ,user.type_id FROM book left JOIN user on book.user_id = user.id WHERE book.status =2 and book.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(book.created_at),`user`.type_id ORDER BY date ASC');
  658. $res['monthJobHunting'] = Db::select(' SELECT DATE(job_hunting.created_at) AS date,COUNT(*) AS count ,user.type_id FROM job_hunting left JOIN user on job_hunting.user_id = user.id WHERE job_hunting.status =2 and job_hunting.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(job_hunting.created_at),`user`.type_id ORDER BY date ASC');
  659. $res['monthJobRecruiting'] = Db::select(' SELECT DATE(job_recruiting.created_at) AS date,COUNT(*) AS count ,user.type_id FROM job_recruiting left JOIN user on job_recruiting.user_id = user.id WHERE job_recruiting.status =1 and job_recruiting.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(job_recruiting.created_at),`user`.type_id ORDER BY date ASC');
  660. //company project 1 已审核
  661. $res['monthCompany'] = Db::select(' SELECT DATE(company.created_at) AS date,COUNT(*) AS count ,user.type_id FROM company left JOIN user on company.user_id = user.id WHERE company.status =1 and company.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(company.created_at),`user`.type_id ORDER BY date ASC');
  662. $res['monthProject'] = Db::select(' SELECT DATE(project.created_at) AS date,COUNT(*) AS count ,user.type_id FROM project left JOIN user on project.user_id = user.id WHERE project.status =1 and project.created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(project.created_at),`user`.type_id ORDER BY date ASC');
  663. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  664. //待审核数据
  665. $res['apply']['article'] = Article::where(['status' => 0])->count(); //
  666. $res['apply']['good'] = Good::where(['status' => 1])->count();
  667. $res['apply']['book'] = Book::where(['status' => 1])->count();
  668. $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->count();
  669. $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->count();
  670. $res['apply']['complaint'] = Complaint::where(['status' => 1])->count();
  671. $res['apply']['notice'] = Notice::where(['status' => 1])->count(); //订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束',
  672. $res['apply']['order'] = Order::where(['status' => 6])->count();
  673. $res['apply']['company'] = Company::where(['status' => 0])->count();
  674. $res['apply']['project'] = Project::where(['status' => 0])->count();
  675. return Result::success($res);
  676. case 1:
  677. case 2:
  678. case 3:
  679. case 4:
  680. $res = [];
  681. if ($data['type_id'] == 4) {
  682. $result = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM letter_of_complaint WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
  683. $res = [];
  684. //查询已审核文章
  685. $user_id = $data['user_id'];
  686. $article = Article::where('status', 1)
  687. ->where('admin_user_id', $user_id)
  688. ->orderBy('updated_at', 'desc')
  689. ->limit(10)
  690. ->get();
  691. $res['letterOfComplaintList'] = $result;
  692. $res['article'] = $article;
  693. }
  694. //查询已审核文章
  695. $user_id = $data['user_id'];
  696. $now = Carbon::now();
  697. // 系统提醒审核消息
  698. $sys_msg = [];
  699. $article = Article::where('status', 0)
  700. ->where('admin_user_id', $user_id)
  701. ->orderBy('updated_at', 'desc')
  702. ->limit(5)
  703. ->get(['id', 'title', 'updated_at'])
  704. ->map(function ($item) use ($now) {
  705. $item->class = '资讯';
  706. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  707. return $item;
  708. });
  709. var_dump($article, '---1--');
  710. $good = Good::where('status', 1)
  711. ->where('user_id', $user_id)
  712. ->orderBy('updated_at', 'desc')
  713. ->get(['id', 'name as title', 'updated_at'])
  714. ->map(function ($item) use ($now) {
  715. //去掉name的属性
  716. $item->class = '商品';
  717. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  718. return $item;
  719. });
  720. $book = Book::query()
  721. ->where('status', 1)
  722. ->where('user_id', $user_id)
  723. ->orderBy('updated_at', 'desc')
  724. ->get(['id', 'title', 'updated_at'])
  725. ->map(function ($item) use ($now) {
  726. //去掉name的属性
  727. $item->class = '书刊';
  728. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  729. return $item;
  730. });
  731. //招聘 求职
  732. $jobhunting = JobHunting::query()
  733. ->where('status', 1)
  734. ->where('user_id', $user_id)
  735. ->orderBy('updated_at', 'desc')
  736. ->get(['id', 'name as title', 'updated_at'])
  737. ->map(function ($item) use ($now) {
  738. //去掉name的属性
  739. $item->class = '求职';
  740. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  741. return $item;
  742. });
  743. $jobrecruiting = JobRecruiting::query()
  744. ->where('status', 0)
  745. ->where('user_id', $user_id)
  746. ->orderBy('updated_at', 'desc')
  747. ->get(['id', 'title', 'updated_at'])
  748. ->map(function ($item) use ($now) {
  749. //去掉name的属性
  750. $item->class = '招聘';
  751. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  752. return $item;
  753. });
  754. //通知 投诉
  755. $notice = Notice::query()
  756. ->where('status', 1)
  757. ->where('user_id', $user_id)
  758. ->orderBy('updated_at', 'desc')
  759. ->get(['id', 'title', 'updated_at'])
  760. ->map(function ($item) use ($now) {
  761. //去掉name的属性
  762. $item->class = $item->type == 1 ? "通知" : "公告";
  763. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  764. return $item;
  765. });
  766. $complaint = Complaint::query()
  767. ->where('status', 1)
  768. ->where('user_id', $user_id)
  769. ->orderBy('updated_at', 'desc')
  770. ->get(['id', 'title', 'updated_at'])
  771. ->map(function ($item) use ($now) {
  772. //去掉name的属性
  773. $item->class = "投诉";
  774. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  775. return $item;
  776. });
  777. //项目 公司 待审核 :0:未审核;1:已审核;2:已拒绝
  778. $project = Project::query()
  779. ->where('status', 0)
  780. ->where('user_id', $user_id)
  781. ->orderBy('updated_at', 'desc')
  782. ->get(['id', 'title', 'updated_at'])
  783. ->map(function ($item) use ($now) {
  784. //去掉name的属性
  785. $item->class = "项目";
  786. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  787. return $item;
  788. });
  789. $company = Company::query()
  790. ->where('status', 0)
  791. ->where('user_id', $user_id)
  792. ->orderBy('updated_at', 'desc')
  793. ->get(['id', 'title', 'updated_at'])
  794. ->map(function ($item) use ($now) {
  795. //去掉name的属性
  796. $item->class = "公司";
  797. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  798. return $item;
  799. });
  800. // var_dump($jobrecruiting, '-1--------------------11111111111111--');
  801. // var_dump($good, '-3--');
  802. // $s = $article->toArray();
  803. // var_dump($s, '=====31111111111111111');
  804. // 合并两个集合
  805. // 合并两个集合,并按 updated_at 倒序排序
  806. // $combined = $article->merge($good)->sortByDesc('updated_at');
  807. $combined = $article
  808. ->concat($good)
  809. ->concat($book)
  810. ->concat($jobhunting)
  811. ->concat($jobrecruiting)
  812. ->concat($notice)
  813. ->concat($complaint)
  814. ->concat($project)
  815. ->concat($company)
  816. ->sortByDesc(function ($item) {
  817. return Carbon::createFromFormat('Y-m-d H:i:s', $item->updated_at);
  818. });
  819. // ->sortBy('updated_at');
  820. // var_dump($combined, '--4--');
  821. // 转换为数组输出
  822. $res['sys_msg'] = $combined->values()->all();
  823. // 互动消息
  824. $chat_msg = [];
  825. // 通知投诉
  826. $notice_msg = [];
  827. // $res['sys_msg'] = $sys_msg;
  828. $chat_single_msg = ChatRecords::where('user_id', $user_id)
  829. ->where('is_read', 0)
  830. ->where('talk_type', 1)
  831. ->orderBy('updated_at', 'desc')
  832. ->limit(5)
  833. ->get(['id', 'content', 'updated_at'])
  834. ->map(function ($item) use ($now) {
  835. $item->class = "单聊";
  836. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  837. return $item;
  838. });
  839. $chat_group_msg = ChatRecords::where('user_id', $user_id)
  840. ->where('is_read', 0)
  841. ->where('talk_type', 2)
  842. ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  843. ->orderBy('updated_at', 'desc')
  844. ->limit(5)
  845. ->get(['chat_records.id', 'content as content1', 'chat_records.updated_at', 'chat_groups.group_name as content'])
  846. ->map(function ($item) use ($now) {
  847. $item->class = "群聊";
  848. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  849. return $item;
  850. });
  851. $topic_msg = ChatTopic::where('chat_topics.user_id', $user_id)
  852. ->whereNotNull('chat_topics_reply.updated_at')
  853. ->leftJoin('chat_topics_reply', 'chat_topics.id', '=', 'chat_topics_reply.topic_id')
  854. ->select('chat_topics.id', 'chat_topics.title as content', 'chat_topics_reply.updated_at as updated_at')
  855. ->orderBy('updated_at', 'desc')
  856. ->limit(5)
  857. ->get(['chat_topics.id', 'chat_topics.content', 'chat_topics.updated_at'])
  858. ->map(function ($item) use ($now) {
  859. $item->class = "话题";
  860. // $item->content = $item->content;
  861. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  862. return $item;
  863. });
  864. // 合并单聊和群聊消息
  865. $chat_msg = $chat_single_msg
  866. ->concat($chat_group_msg)
  867. ->concat($topic_msg)
  868. ->sortByDesc(function ($item) {
  869. return Carbon::createFromFormat('Y-m-d H:i:s', $item->updated_at);
  870. })->values()->all();
  871. $res['chat_msg'] = $chat_msg;
  872. //未读消息
  873. $notce_recieve_msg = Notice::where('status', 1)
  874. ->whereJsonContains('re_user_ids', $user_id)
  875. ->where(function ($query) use ($user_id) {
  876. $query->whereNull('read_id')
  877. ->orWhereRaw('NOT JSON_CONTAINS(`read_id`, ?)', [$user_id]);
  878. })
  879. ->orderBy('updated_at', 'desc')
  880. ->limit(5)
  881. ->get(['id', 'title', 'updated_at'])
  882. ->map(function ($item) use ($now) {
  883. $item->class = "通知";
  884. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  885. return $item;
  886. });
  887. $complaint_recieve_msg = Complaint::where('status', 1)
  888. ->whereJsonContains('re_user_ids', $user_id)
  889. ->where(function ($query) use ($user_id) {
  890. $query->whereNull('read_id')
  891. ->orWhereRaw('NOT JSON_CONTAINS(`read_id`, ?)', [$user_id]);
  892. })
  893. ->orderBy('updated_at', 'desc')
  894. ->limit(5)
  895. ->get(['id', 'title', 'updated_at'])
  896. ->map(function ($item) use ($now) {
  897. $item->class = "投诉";
  898. $item->formatted_updated_at = $this->timeAgo($item->updated_at, $now);
  899. return $item;
  900. });
  901. // 合并消息
  902. $notice_msg = $notce_recieve_msg
  903. ->concat($complaint_recieve_msg)
  904. ->sortByDesc(function ($item) {
  905. return Carbon::createFromFormat('Y-m-d H:i:s', $item->updated_at);
  906. })->values()->all();
  907. $res['notice_msg'] = $notice_msg;
  908. // $res['article'] = $article;
  909. $res['website']['count'] = Website::where([])->count();
  910. $res['article']['count'] = Article::whereIn('status', [1])->where('admin_user_id', $user_id)->count();
  911. $res['category']['count'] = Category::where([])->count();
  912. $res['good']['count'] = Good::whereIn('status', [2])
  913. ->where('user_id', $user_id)->count();
  914. $res['book']['count'] = Book::whereIn('status', [2])
  915. ->where('user_id', $user_id)->count();
  916. $res['jobHunting']['count'] = JobHunting::whereIn('status', [2])
  917. ->where('user_id', $user_id)->count();
  918. $res['jobRecruiting']['count'] = JobRecruiting::whereIn('status', [1])
  919. ->where('user_id', $user_id)->count();
  920. $res['complaint']['count'] = Complaint::whereIn('status', [2])
  921. ->where('user_id', $user_id)->count();
  922. $res['notice']['count'] = Notice::whereIn('status', [2])
  923. ->where('user_id', $user_id)->count();
  924. //company project 0 待审核 1 已审核
  925. $res['company']['count'] = Company::whereIn('status', [1])
  926. ->where('user_id', $user_id)->count();
  927. $res['project']['count'] = Project::whereIn('status', [1])
  928. ->where('user_id', $user_id)->count();
  929. //待处理的complaint
  930. $res['complaint_deal']['count'] = Complaint::where(['status' => 2])
  931. ->where('deal', 1)
  932. // ->where('user_id', $user_id)
  933. ->whereJsonContains('re_user_ids', $user_id)
  934. ->count();
  935. //待审核数据
  936. $res['apply']['article'] = Article::where(['status' => 0])->where('admin_user_id', $user_id)->count(); //
  937. $res['apply']['good'] = Good::where(['status' => 1])->where('user_id', $user_id)->count();
  938. $res['apply']['book'] = Book::where(['status' => 1])->where('user_id', $user_id)->count();
  939. $res['apply']['jobHunting'] = JobHunting::where(['status' => 1])->where('user_id', $user_id)->count();
  940. $res['apply']['jobRecruiting'] = JobRecruiting::where(['status' => 0])->where('user_id', $user_id)->count();
  941. $res['apply']['complaint'] = Complaint::where(['status' => 1])->where('user_id', $user_id)->count();
  942. $res['apply']['notice'] = Notice::where(['status' => 1])->where('user_id', $user_id)->count();
  943. //project company
  944. $res['apply']['project'] = Project::whereIn('status', [0])
  945. ->where('user_id', $user_id)->count();
  946. $res['apply']['company'] = Company::whereIn('status', [0])
  947. ->where('user_id', $user_id)->count();
  948. return Result::success($res);
  949. }
  950. return [];
  951. }
  952. private function timeAgo(string $date, Carbon $now): string
  953. {
  954. $diff = (new Carbon($date))->diffInMinutes($now);
  955. if ($diff < 1) {
  956. return '刚刚';
  957. } elseif ($diff < 60) {
  958. return "{$diff} 分钟前";
  959. } elseif ($diff < 1440) {
  960. return (int)($diff / 60) . " 小时前";
  961. } elseif ($diff < 2880) { // 两天内
  962. return "1 天前";
  963. } elseif ($diff < 7 * 1440) {
  964. return (int)($diff / 1440) . " 天前";
  965. } else {
  966. return (new Carbon($date))->format('Y-m-d');
  967. }
  968. }
  969. /**
  970. * 获取分类下的模板
  971. * @param array $data
  972. * @return array
  973. */
  974. public function getTemplate(array $data): array
  975. {
  976. $page = $data['page'];
  977. $pageSize = $data['pageSize'];
  978. $where = [];
  979. if (isset($data['template_class_id']) && $data['template_class_id']) {
  980. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  981. }
  982. $result = Template::where($where)
  983. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  984. $count = Template::where($where)->count();
  985. if (empty($result)) {
  986. return Result::error("没有数据", 0);
  987. }
  988. $data = [
  989. 'rows' => $result->toArray(),
  990. 'count' => $count,
  991. ];
  992. return Result::success($data);
  993. }
  994. /**
  995. * 创建模板
  996. * @param
  997. * @return void
  998. */
  999. public function addTemplate(array $data): array
  1000. {
  1001. $insertData = [
  1002. 'template_name' => $data['template_name'],
  1003. 'template_img' => json_encode($data['template_img']),
  1004. 'template_class_id' => $data['template_class_id'],
  1005. ];
  1006. $result = Template::insertGetId($insertData);
  1007. if (empty($result)) {
  1008. return Result::error("创建模板失败", 0);
  1009. } else {
  1010. return Result::success(["id" => $result]);
  1011. }
  1012. }
  1013. /**
  1014. * 更新模板
  1015. * @param array $data
  1016. * @return array
  1017. */
  1018. public function upTemplate(array $data): array
  1019. {
  1020. $where = [
  1021. 'id' => $data['id'],
  1022. ];
  1023. $insertData = [
  1024. 'template_name' => $data['template_name'],
  1025. 'template_img' => json_encode($data['template_img']),
  1026. 'template_class_id' => $data['template_class_id'],
  1027. ];
  1028. $result = Template::where($where)->update($insertData);
  1029. if (empty($result)) {
  1030. return Result::error("更新模板失败", 0);
  1031. } else {
  1032. return Result::success();
  1033. }
  1034. }
  1035. /**
  1036. * 删除模板
  1037. * @param array $data
  1038. * @return array
  1039. */
  1040. public function delTemplate(array $data): array
  1041. {
  1042. $where = [
  1043. 'id' => $data['id'],
  1044. ];
  1045. $result = Template::where($where)->delete();
  1046. if (empty($result)) {
  1047. return Result::error("删除模板失败", 0);
  1048. } else {
  1049. return Result::success();
  1050. }
  1051. }
  1052. /**
  1053. * 搜索网站
  1054. * @param array $data
  1055. * @return array
  1056. */
  1057. public function websiteList(array $data): array
  1058. {
  1059. $where = [];
  1060. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1061. array_push($where, ['zxt_website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1062. }
  1063. $result = Website::where($where)->get();
  1064. if (isset($data['website_column_id'])) {
  1065. $target = $data['website_column_id'];
  1066. $result = $result->filter(function ($item) use ($target) {
  1067. $arr = json_decode($item->website_column_arr_id, true);
  1068. return !in_array($target, $arr);
  1069. });
  1070. }
  1071. if ($result) {
  1072. return Result::success($result);
  1073. } else {
  1074. return Result::error("没有网站", 0);
  1075. }
  1076. }
  1077. public function addWebsiteCategory(array $data): array
  1078. {
  1079. $website_id = $data['website_id'];
  1080. $category_arr_id = $data['category_arr_id'];
  1081. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  1082. $categoryListIds = [];
  1083. if ($categoryList) {
  1084. foreach ($categoryList->toArray() as $val) {
  1085. array_push($categoryListIds, $val['id']);
  1086. }
  1087. }
  1088. $arr = [];
  1089. if ($categoryListIds) {
  1090. foreach ($categoryListIds as $v) {
  1091. $ids = $this->getUnderlingUIds(intval($v));
  1092. $ids_arr = explode(",", $ids);
  1093. array_push($arr, $ids_arr);
  1094. }
  1095. }
  1096. $mergedArray = [];
  1097. foreach ($arr as $subarray) {
  1098. $mergedArray = array_merge($mergedArray, $subarray);
  1099. }
  1100. var_dump("所有:", $arr, $mergedArray);
  1101. //查询出所有的分类进行分割插入 组装数据
  1102. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  1103. $categoryListData = $categoryListData->toArray();
  1104. $insertData = [];
  1105. if ($categoryListData) {
  1106. foreach ($categoryListData as $key => $value) {
  1107. $insertData[$key]['website_id'] = $website_id;
  1108. $insertData[$key]['name'] = $value['name'];
  1109. $insertData[$key]['sort'] = $value['sort'];
  1110. $insertData[$key]['pid'] = $value['pid'];
  1111. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  1112. $insertData[$key]['seo_title'] = $value['seo_title'];
  1113. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  1114. $insertData[$key]['seo_description'] = $value['seo_description'];
  1115. $insertData[$key]['alias'] = $value['name'];
  1116. $insertData[$key]['category_id'] = $value['id'];
  1117. }
  1118. }
  1119. $result = WebsiteCategory::insert($insertData);
  1120. var_dump("插入数据状态:", $result);
  1121. if ($result) {
  1122. return Result::success($result);
  1123. } else {
  1124. return Result::error("创建失败", 0);
  1125. }
  1126. }
  1127. /**
  1128. * 删除网站导航
  1129. * @param array $data
  1130. * @return array
  1131. */
  1132. public function delWebsiteCategory(array $data): array
  1133. {
  1134. $website_id = $data['website_id'] ?? 0;
  1135. $category_id = $data['category_id'] ?? 0;
  1136. $ids = $this->getUnderlingUIds(intval($category_id));
  1137. $ids_arr = explode(",", $ids);
  1138. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  1139. if ($result) {
  1140. return Result::success($result);
  1141. } else {
  1142. return Result::error("删除失败", 0);
  1143. }
  1144. }
  1145. /**
  1146. * 获取网站导航
  1147. * @param array $data
  1148. * @return array
  1149. */
  1150. public function getAdminWebsiteCategory(array $data): array
  1151. {
  1152. $where = [
  1153. 'website_id' => $data['website_id'],
  1154. ];
  1155. $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
  1156. $list = [];
  1157. if ($result) {
  1158. foreach ($result->toArray() as $val) {
  1159. array_push($list, json_decode($val['category_arr_id']));
  1160. }
  1161. }
  1162. if ($result) {
  1163. return Result::success($list);
  1164. } else {
  1165. return Result::error("查询失败", 0);
  1166. }
  1167. }
  1168. /**
  1169. * 更新网站导航
  1170. * @param array $data
  1171. * @return array
  1172. */
  1173. public function upWebsiteCategory(array $data): array
  1174. {
  1175. $pinyin = new Pinyin();
  1176. var_dump("更新数据:", $data);
  1177. Db::beginTransaction();
  1178. try {
  1179. if (!empty($data['category_arr_id'])) {
  1180. $websiteId = $data['website_id'];
  1181. // 1. 获取旧的 category_id 列表
  1182. $oldCategoryListIds = WebsiteCategory::where('website_id', $websiteId)->pluck('category_id')->toArray();
  1183. // 2. 获取新的 category_id 列表(去重)
  1184. $newCategoryListIds = [];
  1185. foreach ($data['category_arr_id'] as $arr) {
  1186. $lastId = end($arr);
  1187. $newCategoryListIds[] = $lastId;
  1188. }
  1189. $newCategoryListIds = array_unique($newCategoryListIds);
  1190. // 3. 需要删除的 category_id
  1191. $toDelete = array_diff($oldCategoryListIds, $newCategoryListIds);
  1192. if (!empty($toDelete)) {
  1193. WebsiteCategory::where('website_id', $websiteId)
  1194. ->whereIn('category_id', $toDelete)
  1195. ->delete();
  1196. }
  1197. // 4. 批量查出所有需要的 category 信息
  1198. $categories = Category::whereIn('id', $newCategoryListIds)->get()->keyBy('id');
  1199. // 5. 组装 upsertData,确保 category_id 不重复
  1200. $upsertData = [];
  1201. $handledCategoryIds = [];
  1202. foreach ($data['category_arr_id'] as $arr) {
  1203. $categoryId = end($arr);
  1204. if (!isset($categories[$categoryId]) || in_array($categoryId, $handledCategoryIds)) continue;
  1205. $info = $categories[$categoryId];
  1206. $aLIas_pinyin = $pinyin->permalink($info->name, '');
  1207. $upsertData[] = [
  1208. 'website_id' => $websiteId,
  1209. 'category_id' => $categoryId,
  1210. 'name' => $info->name ?? '',
  1211. 'alias' => $info->name ?? '',
  1212. 'aLIas_pinyin' => $aLIas_pinyin ?? '',
  1213. 'sort' => $info->sort ?? 0,
  1214. 'pid' => $info->pid ?? 0,
  1215. 'pid_arr' => $info->pid_arr ?? json_encode([]),
  1216. 'seo_title' => $info->seo_title ?? "",
  1217. 'seo_keywords' => $info->seo_keywords ?? "",
  1218. 'seo_description' => $info->seo_description ?? "",
  1219. 'is_url' => $info->is_url ?? 0,
  1220. 'web_url' => $info->web_url ?? '',
  1221. 'type' => $info->type ?? 1,
  1222. 'category_arr_id' => json_encode($arr)
  1223. ];
  1224. $handledCategoryIds[] = $categoryId;
  1225. }
  1226. // 6. upsert
  1227. if (!empty($upsertData)) {
  1228. WebsiteCategory::upsert(
  1229. $upsertData,
  1230. ['website_id', 'category_id'],
  1231. [
  1232. 'aLIas_pinyin',
  1233. 'pid',
  1234. 'pid_arr',
  1235. 'is_url',
  1236. 'web_url',
  1237. 'category_arr_id'
  1238. ]
  1239. );
  1240. }
  1241. }
  1242. //处理所有path
  1243. var_dump($data, '--------111----');
  1244. $website_id = $data['website_id'];
  1245. //获取所有数据
  1246. $result = WebsiteCategory::where(['website_id' => $websiteId, 'path' => NULL])->get()->toArray();
  1247. if (empty($result)) {
  1248. // return Result::error("没有数据", 0);
  1249. }
  1250. //处理path
  1251. foreach ($result as $key => $value) {
  1252. $array_category_arr_id = json_decode($value['category_arr_id'], true);
  1253. $result[$key]['path'] = WebsiteCategory::where('website_id', $websiteId)
  1254. ->orderByRaw('FIELD(category_id, ' . implode(',', $array_category_arr_id) . ')')
  1255. ->whereIn('category_id', $array_category_arr_id)
  1256. ->pluck('aLIas_pinyin')
  1257. ->implode('/');
  1258. }
  1259. //批量更新数据path
  1260. $updateData = [];
  1261. foreach ($result as $item) {
  1262. $updateData[] = [
  1263. 'id' => $item['id'],
  1264. 'path' => $item['path']
  1265. ];
  1266. }
  1267. //批量更新
  1268. DB::beginTransaction();
  1269. try {
  1270. foreach ($result as $item) {
  1271. WebsiteCategory::where('id', $item['id'])->update(['path' => $item['path']]);
  1272. }
  1273. DB::commit();
  1274. } catch (\Exception $e) {
  1275. DB::rollBack();
  1276. throw $e; // 或者返回错误信息
  1277. }
  1278. //更换级别操作 形成新的上下级;
  1279. $website_all = WebsiteCategory::where('website_id', $website_id)
  1280. ->where('pid', '>', 0)
  1281. ->get()->toArray();
  1282. foreach ($website_all as $key => $value) {
  1283. $category_arr_id = json_decode($value['category_arr_id'], true);
  1284. $validPids = [];
  1285. $pid = 0;
  1286. foreach ($category_arr_id as $pidid => $pid) {
  1287. $exists = WebsiteCategory::where('website_id', $website_id)
  1288. ->where('category_id', $pid)->exists();
  1289. if ($exists) {
  1290. $validPids[] = $pid;
  1291. }
  1292. }
  1293. $pid = $validPids[0];
  1294. if (count($validPids) != count($category_arr_id)) {
  1295. if (count($validPids) == 1) {
  1296. $pid = 0;
  1297. }
  1298. // $category_arr_id = array_push($validPids, $value['category_id']);
  1299. WebsiteCategory::where('id', $value['id'])->update([
  1300. 'real_category_arr_id' => json_encode($validPids),
  1301. 'real_pid' => $pid,
  1302. 'path' => WebsiteCategory::where('website_id', $website_id)
  1303. ->orderByRaw('FIELD(category_id, ' . implode(',', $validPids) . ')')
  1304. ->whereIn('category_id', $validPids)
  1305. ->pluck('aLIas_pinyin')
  1306. ->implode('/'),
  1307. ]);
  1308. } else {
  1309. WebsiteCategory::where('id', $value['id'])->update([
  1310. 'real_category_arr_id' => null,
  1311. 'real_pid' => null,
  1312. 'path' => WebsiteCategory::where('website_id', $website_id)
  1313. ->orderByRaw('FIELD(category_id, ' . implode(',', $validPids) . ')')
  1314. ->whereIn('category_id', $validPids)
  1315. ->pluck('aLIas_pinyin')
  1316. ->implode('/'),
  1317. ]);
  1318. }
  1319. }
  1320. Db::commit();
  1321. var_dump("更新数据1:", $data);
  1322. return Result::success();
  1323. } catch (\Throwable $ex) {
  1324. Db::rollBack();
  1325. return Result::error("修改失败" . $ex->getMessage(), 0);
  1326. }
  1327. }
  1328. /**
  1329. * 获取网站列表
  1330. * @param array $data
  1331. * @return array
  1332. */
  1333. public function getWebsiteCategoryList(array $data): array
  1334. {
  1335. $where = [];
  1336. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1337. array_push($where, ['zxt_website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1338. }
  1339. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1340. array_push($where, ['zxt_website.website_column_id', '=', $data['website_column_id']]);
  1341. }
  1342. $result = Website::where($where)
  1343. ->with(["websiteCategory" => function ($query) {
  1344. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1345. }])
  1346. ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  1347. ->get();
  1348. $count = Website::where($where)->count();
  1349. if (empty($result)) {
  1350. return Result::error("没有数据", 0);
  1351. }
  1352. $data = [
  1353. 'rows' => $result->toArray(),
  1354. 'count' => $count,
  1355. ];
  1356. if ($result) {
  1357. return Result::success($data);
  1358. } else {
  1359. return Result::error("查询失败", 0);
  1360. }
  1361. }
  1362. /**
  1363. * 删除网站下的所有导航
  1364. * @param array $data
  1365. * @return array
  1366. */
  1367. public function delWebsiteAllCategory(array $data): array
  1368. {
  1369. $website_id = $data['website_id'];
  1370. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1371. if ($result) {
  1372. return Result::success($result);
  1373. } else {
  1374. return Result::error("删除失败", 0);
  1375. }
  1376. }
  1377. /**
  1378. * 获取网站下的某一个导航
  1379. * @param array $data
  1380. * @return array
  1381. */
  1382. public function getWebsiteCategoryOnes(array $data): array
  1383. {
  1384. $website_id = $data['website_id'];
  1385. $category_id = $data['category_id'];
  1386. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1387. ->first();
  1388. if ($result) {
  1389. return Result::success($result);
  1390. } else {
  1391. return Result::error("查询失败", 0);
  1392. }
  1393. }
  1394. /**
  1395. * 更新网闸下的某一个导航
  1396. * @param array $data
  1397. * @return array
  1398. */
  1399. public function upWebsiteCategoryones(array $data): array
  1400. {
  1401. //处理所有数据
  1402. //获取所有数据
  1403. if (isset($data['all']) && $data['all'] == 'all') {
  1404. $result = WebsiteCategory::get();
  1405. $result = $result->toArray();
  1406. var_dump($result, '------------');
  1407. $pinyin = new Pinyin();
  1408. $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1409. for ($i = 0; $i < count($result); $i++) {
  1410. // $randss = substr(str_shuffle($letters), 0, 4);
  1411. $result[$i]['aLIas_pinyin'] = $pinyin->permalink($result[$i]['alias'], '');
  1412. WebsiteCategory::where(['id' => $result[$i]['id']])->update(['aLIas_pinyin' => $result[$i]['aLIas_pinyin']]);
  1413. }
  1414. var_dump($result, '--------222----');
  1415. if ($result) {
  1416. return Result::success($result);
  1417. } else {
  1418. return Result::error("更新失败", 0);
  1419. }
  1420. }
  1421. //处理所有path
  1422. if (isset($data['pathone']) && $data['pathone'] == 'pathone') {
  1423. var_dump($data, '--------111----');
  1424. $website_id = $data['website_id'];
  1425. //获取所有数据
  1426. $result = WebsiteCategory::where(['website_id' => $website_id, 'path' => NULL])->get()->toArray();
  1427. if (empty($result)) {
  1428. return Result::error("没有数据", 0);
  1429. }
  1430. //处理path
  1431. foreach ($result as $key => $value) {
  1432. $array_category_arr_id = json_decode($value['category_arr_id'], true);
  1433. $result[$key]['path'] = WebsiteCategory::where('website_id', $website_id)
  1434. ->orderByRaw('FIELD(category_id, ' . implode(',', $array_category_arr_id) . ')')
  1435. ->whereIn('category_id', $array_category_arr_id)
  1436. ->pluck('aLIas_pinyin')
  1437. ->implode('/');
  1438. }
  1439. //批量更新数据path
  1440. $updateData = [];
  1441. foreach ($result as $item) {
  1442. $updateData[] = [
  1443. 'id' => $item['id'],
  1444. 'path' => $item['path']
  1445. ];
  1446. }
  1447. //批量更新
  1448. DB::beginTransaction();
  1449. try {
  1450. foreach ($result as $item) {
  1451. WebsiteCategory::where('id', $item['id'])->update(['path' => $item['path']]);
  1452. }
  1453. DB::commit();
  1454. } catch (\Exception $e) {
  1455. DB::rollBack();
  1456. throw $e; // 或者返回错误信息
  1457. }
  1458. return Result::success($result);
  1459. }
  1460. if (isset($data['pathall']) && $data['pathall'] == 'pathall') {
  1461. //获取所有数据
  1462. $result = WebsiteCategory::where(['path' => NULL])->get()->toArray();
  1463. if (empty($result)) {
  1464. return Result::error("没有数据", 0);
  1465. }
  1466. //处理path
  1467. foreach ($result as $key => $value) {
  1468. if (empty($value['category_arr_id'])) continue;
  1469. if ($key >= 4) { // 改为 >= 4 如果你想处理最多4个元素
  1470. // break;
  1471. }
  1472. $array_category_arr_id = json_decode($value['category_arr_id'], true);
  1473. $result[$key]['path'] = WebsiteCategory::where('website_id', $value['website_id'])
  1474. ->orderByRaw('FIELD(category_id, ' . implode(',', $array_category_arr_id) . ')')
  1475. ->whereIn('category_id', $array_category_arr_id)
  1476. ->pluck('aLIas_pinyin')
  1477. ->implode('/');
  1478. }
  1479. //批量更新数据path
  1480. $updateData = [];
  1481. foreach ($result as $item) {
  1482. $updateData[] = [
  1483. 'id' => $item['id'],
  1484. 'category_arr_id' => $item['category_arr_id'],
  1485. 'path' => $item['path']
  1486. ];
  1487. }
  1488. // var_dump($updateData);
  1489. // return Result::success($updateData);
  1490. //批量更新
  1491. DB::beginTransaction();
  1492. try {
  1493. foreach ($result as $item) {
  1494. WebsiteCategory::where('id', $item['id'])->update(['path' => $item['path']]);
  1495. }
  1496. DB::commit();
  1497. } catch (\Exception $e) {
  1498. DB::rollBack();
  1499. throw $e; // 或者返回错误信息
  1500. }
  1501. return Result::success($result);
  1502. }
  1503. $where = [
  1504. 'website_id' => $data['website_id'],
  1505. 'category_id' => $data['category_id'],
  1506. ];
  1507. $alias = $data['alias'];
  1508. $pinyin = new Pinyin();
  1509. $aLIas_pinyin = $pinyin->permalink($alias, '');
  1510. //从WebsiteCategory取出alis ,并转成拼音存放到aLIas_pinyin
  1511. $result = WebsiteCategory::where($where)->first();
  1512. if (empty($result)) {
  1513. return Result::error("没有数据", 0);
  1514. }
  1515. $result = $result->toArray();
  1516. $oldAliasPinyin = $data['alias_pinyin']; // 修正键名大小写
  1517. var_dump($oldAliasPinyin, $result, '----old-new---');
  1518. //+四位随机字母
  1519. $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1520. // 打乱字符串顺序并截取前四位
  1521. // $randss = substr(str_shuffle($letters), 0, 4);
  1522. $data['aLIas_pinyin'] = $aLIas_pinyin;
  1523. //数据库先更新一下,再改path
  1524. WebsiteCategory::where($where)->update(['aLIas_pinyin' => $data['aLIas_pinyin']]);
  1525. //处理path
  1526. $category_arr_id = json_decode($result['category_arr_id'], true);
  1527. //取出来设置path
  1528. $path = WebsiteCategory::where('website_id', $data['website_id'])
  1529. ->orderByRaw('FIELD(category_id, ' . implode(',', $category_arr_id) . ')')
  1530. ->whereIn('category_id', $category_arr_id)
  1531. ->pluck('aLIas_pinyin')
  1532. ->implode('/');
  1533. $data['path'] = $path;
  1534. //处理包含此id的所有path
  1535. // 取出category_arr_id包含此id的所有数据
  1536. $all_other = WebsiteCategory::where('website_id', $data['website_id'])
  1537. ->whereJsonContains('category_arr_id', $data['category_id'])
  1538. ->get();
  1539. // var_dump($all_other, '------------');
  1540. // 遍历所有数据,更新path
  1541. $newAliasPinyin = $aLIas_pinyin; // 添加空值判断
  1542. // 收集需要更新的ID和路径
  1543. $updateData = [];
  1544. foreach ($all_other as $item) {
  1545. $newPath = str_replace($oldAliasPinyin, $newAliasPinyin, $item->path);
  1546. var_dump($newPath, '---------zz--', $item->path, $oldAliasPinyin, $newAliasPinyin);
  1547. if ($newPath !== $item->path) { // 仅在路径变化时更新
  1548. $updateData[] = [
  1549. 'id' => $item->id,
  1550. // 'category_id' => $item->category_id,
  1551. 'path' => $newPath
  1552. ];
  1553. }
  1554. }
  1555. var_dump($updateData, '-----------1-');
  1556. // 批量更新提高性能
  1557. if (!empty($updateData)) {
  1558. // 假设模型对应的数据表为 'table_name',请替换为实际表名
  1559. // WebsiteCategory::upsert($updateData, ['id'], ['path']);
  1560. foreach ($updateData as $datapath) {
  1561. WebsiteCategory::updateOrInsert(
  1562. ['id' => $datapath['id']], // 匹配条件
  1563. ['path' => $datapath['path']] // 更新字段
  1564. );
  1565. }
  1566. }
  1567. $result = WebsiteCategory::where($where)->update($data);
  1568. if ($result) {
  1569. return Result::success($result);
  1570. } else {
  1571. return Result::error("更新失败", 0);
  1572. }
  1573. }
  1574. /**
  1575. * 获取网站下的所有导航(包含子导航)
  1576. * @param array $data
  1577. * @return array
  1578. */
  1579. public function getWebsiteAllCategory(array $data): array
  1580. {
  1581. $where = [];
  1582. var_dump($data, '---1');
  1583. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1584. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1585. }
  1586. // if (isset($data['name']) && !empty($data['name'])) {
  1587. // array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1588. // }
  1589. // if (isset($data['alias']) && !empty($data['alias'])) {
  1590. // array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1591. // }
  1592. // if (isset($data['department_id']) && !empty($data['department_id'])) {
  1593. // array_push($where, ['category.department_id', '=', $data['department_id']]);
  1594. // }
  1595. // if (isset($data['city_id']) && !empty($data['city_id'])) {
  1596. // array_push($where, ['category.city_id', '=', $data['city_id']]);
  1597. // }
  1598. if (isset($data['is_show'])) {
  1599. array_push($where, ['website_category.is_show', '=', $data['is_show']]);
  1600. }
  1601. var_dump($where, '---2');
  1602. $result_real = WebsiteCategory::where($where)
  1603. // ->where('website_category.is_show', 1) //显示
  1604. ->whereNotNull('website_category.real_pid') //只显示顶级
  1605. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1606. ->select(
  1607. "website_category.*",
  1608. DB::raw('real_pid AS pid'),
  1609. DB::raw('real_category_arr_id AS category_arr_id'),
  1610. "category.name as name"
  1611. )
  1612. ->orderBy("sort", "asc")
  1613. ->orderBy("updated_at", "desc")
  1614. ->get()->toArray();
  1615. $result = WebsiteCategory::where($where)
  1616. // ->where('website_category.is_show', 1) //显示
  1617. ->whereNull('website_category.real_pid') //只显示顶级
  1618. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1619. ->select(
  1620. "website_category.*",
  1621. // DB::raw('real_pid AS pid'),
  1622. // DB::raw('real_category_arr_id AS category_arr_id'),
  1623. "category.name as name"
  1624. )
  1625. // ->leftJoin("category", 'website_category.category_id', 'category.id')
  1626. // ->leftJoin("department", 'category.department_id', 'department.id')
  1627. // ->leftJoin("district", 'category.city_id', 'district.id')
  1628. // ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1629. // ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1630. ->orderBy("sort", "asc")
  1631. ->orderBy("updated_at", "desc")
  1632. ->get()->toArray();
  1633. $result = array_merge($result, $result_real);
  1634. // var_dump($result, '-----------1-');
  1635. if (empty($result)) {
  1636. return Result::error("没有数据", 0);
  1637. }
  1638. if ($result) {
  1639. return Result::success($result);
  1640. } else {
  1641. return Result::error("查询失败", 0);
  1642. }
  1643. }
  1644. /**
  1645. * 递归查询数据
  1646. * @param $id
  1647. * @param $ids
  1648. * @return string
  1649. */
  1650. public function getUnderlingUIds($id, $ids = '')
  1651. {
  1652. $back = Category::where(['pid' => $id])->get();
  1653. $back = $back->toArray();
  1654. if (!empty($back) && is_array($back)) {
  1655. foreach ($back as $v) {
  1656. //防止当前人的ID重复去查询,形成恶性循环
  1657. if ($v['id'] == $id) {
  1658. continue;
  1659. }
  1660. $back2 = Category::where(['pid' => $id])->count('id');
  1661. if ($back2 > 0) {
  1662. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1663. } else {
  1664. $ids .= ',' . $v['id'];
  1665. }
  1666. }
  1667. }
  1668. $ids = $id . ',' . $ids . ',';
  1669. $ids = str_replace(',,', ",", $ids);
  1670. $ids = trim($ids, ',');
  1671. return $ids;
  1672. }
  1673. /**
  1674. * 检测网站名称是否重复
  1675. * @param array $data
  1676. * @return array
  1677. */
  1678. public function checkWebsiteName(array $data): array
  1679. {
  1680. if (isset($data['id'])) {
  1681. $data[] = ['id', "!=", $data['id']];
  1682. unset($data['id']);
  1683. }
  1684. $websiteInfo = Website::query()->where($data)->first();
  1685. if (empty($websiteInfo)) {
  1686. return Result::error("找不到网站", 0);
  1687. }
  1688. return Result::success($websiteInfo->toArray());
  1689. }
  1690. /**
  1691. * 检测网站url是否重复
  1692. * @param array $data
  1693. * @return array
  1694. */
  1695. public function checkWebsiteUrl(array $data): array
  1696. {
  1697. $whereData = [];
  1698. if (isset($data['id'])) {
  1699. $whereData = [['id', "!=", $data['id']]];
  1700. unset($data['id']);
  1701. }
  1702. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1703. if (empty($websiteInfo)) {
  1704. return Result::error("找不到URL", 0);
  1705. }
  1706. return Result::success($websiteInfo->toArray());
  1707. }
  1708. /*
  1709. * 搜索网站二级导航
  1710. * @param array $data
  1711. * @return array
  1712. * */
  1713. public function selectWebsiteCategory(array $data): array
  1714. {
  1715. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1716. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1717. if (empty($website)) {
  1718. return Result::error("暂无该网站", 0);
  1719. }
  1720. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id')->all();
  1721. // return Result::success($category);
  1722. if (empty($category)) {
  1723. return Result::error("暂无此导航", 0);
  1724. }
  1725. $query = Category::whereIn('id', $category);
  1726. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1727. $cityid = District::where('id', $data['cityid'])->first();
  1728. if (empty($cityid)) {
  1729. return Result::error("暂无此城市", 0);
  1730. } else {
  1731. $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
  1732. // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
  1733. if (empty($city_category)) {
  1734. return Result::error("暂无此城市下的导航", 0);
  1735. }
  1736. $result['catid'] = $city_category;
  1737. $city = 1;
  1738. // var_dump("城市====================",$result);
  1739. }
  1740. }
  1741. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1742. $departmentid = Department::where('id', $data['department_id'])->first();
  1743. if (empty($departmentid)) {
  1744. return Result::error("暂无此部门", 0);
  1745. } else {
  1746. $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1747. if (empty($depart_category)) {
  1748. return Result::error("暂无此部门下的导航", 0);
  1749. }
  1750. $result['catid'] = $depart_category;
  1751. // var_dump("职能部门*******************",$result);
  1752. $department = 1;
  1753. }
  1754. }
  1755. if (!empty($city) && !empty($department)) {
  1756. // var_dump("城市和职能部门----------------------",$result);
  1757. $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
  1758. if (empty($sel_category)) {
  1759. return Result::error("暂无此城市和职能部门下的导航", 0);
  1760. }
  1761. $result['catid'] = $sel_category;
  1762. }
  1763. if (empty($result)) {
  1764. return Result::error("暂无导航", 0);
  1765. }
  1766. // department_id
  1767. } else {
  1768. return Result::error("参数错误", 0);
  1769. }
  1770. return Result::success($result);
  1771. }
  1772. // 自助建站--fr-------------------
  1773. /**
  1774. * 获取并搜索 网站模板信息
  1775. * @param array $data
  1776. * @return array
  1777. */
  1778. public function getWebsiteintel(array $data): array
  1779. {
  1780. //查询所有网站模板信息
  1781. $query = Website::leftJoin("website_template_info", "website_template_info.website_id", "zxt_website.id")
  1782. ->leftJoin("template", "template.template_id", "website_template_info.template_id")
  1783. ->leftJoin("template_class", "template_class.class_id", "template.template_class_id")
  1784. ->leftJoin('zxt_website_column', 'zxt_website_column.id', 'zxt_website.website_column_id')
  1785. ->leftJoin('zxt_website_column as parent_column', function ($join) {
  1786. $join->on('zxt_website_column.pid', '=', 'parent_column.id')
  1787. ->where('zxt_website_column.pid', 2);
  1788. })
  1789. ->whereRaw('NOT JSON_CONTAINS(website_column_arr_id, \'3\')')
  1790. ->select(
  1791. "website_template_info.id",
  1792. "template_class.name",
  1793. "zxt_website.id as website_id",
  1794. "zxt_website.website_name",
  1795. "zxt_website.website_url",
  1796. "website_template_info.action_id",
  1797. "website_template_info.created_at",
  1798. "website_template_info.updated_at",
  1799. "website_template_info.page_type",
  1800. 'zxt_website_column.column_name',
  1801. 'parent_column.column_name as parent_column_name',
  1802. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1803. "template.template_name"
  1804. );
  1805. //若存在条件;则在$query的基础上进行筛选
  1806. if (isset($data['website_name']) && !empty($data['website_name'])) {
  1807. $query->where('zxt_website.website_name', 'like', '%' . $data['website_name'] . '%');
  1808. }
  1809. if (isset($data['status']) && !empty($data['status'])) {
  1810. $query->where('website_template_info.status', $data['status']);
  1811. }
  1812. $count = $query->count();
  1813. $query->limit($data['pageSize'])
  1814. ->offset(($data['page'] - 1) * $data['pageSize'])
  1815. ->orderBy("website_template_info.updated_at", "desc");
  1816. $rep = $query->get();
  1817. if ($rep->count() == 0) {
  1818. return Result::error("没有查找到相关数据", 0);
  1819. } else {
  1820. $rep->each(function ($item) {
  1821. if (!empty($item->page_type)) {
  1822. $pageTypeArray = json_decode($item->page_type, true);
  1823. if (is_array($pageTypeArray)) {
  1824. $item->page_type = $pageTypeArray;
  1825. }
  1826. }
  1827. });
  1828. $result = [
  1829. "rows" => $rep->toArray(),
  1830. "count" => $count,
  1831. ];
  1832. return Result::success($result);
  1833. }
  1834. // return Result::success($result);
  1835. }
  1836. /**
  1837. * 自助建站-验证搭建网站
  1838. * @param array $data
  1839. * @return array
  1840. */
  1841. public function checkWebsiteBuild(array $data): array
  1842. {
  1843. $website = Website::where('zxt_website.id', $data['website_id'])->first();
  1844. if (empty($website)) {
  1845. return Result::error("请输入正确的网站id!", 0);
  1846. }
  1847. if (empty($website['website_column_id'])) {
  1848. return Result::error("请先关联导航池!", 0);
  1849. }
  1850. // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
  1851. $foot_type = FooterCategory::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1852. if (empty($foot_type)) {
  1853. return Result::error("请先关联单页!", 0);
  1854. }
  1855. // if (!in_array(1, $foot_type) ) {
  1856. // $missingTypes[] = "列表型底部导航";
  1857. // }
  1858. if (!in_array(0, $foot_type) ) {
  1859. $missingTypes = "单页(详情)";
  1860. }
  1861. if (!empty($missingTypes)) {
  1862. $errorMessage = "请先添加" . $missingTypes . "!";
  1863. return Result::error($errorMessage, 0);
  1864. }
  1865. $result['foot_type'] = $foot_type;
  1866. // 友情链接类型'1:图片 2:文字 3:底部';
  1867. $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
  1868. $missingTypes = [];
  1869. if (!in_array(1, $types)) {
  1870. $missingTypes[] = "文字链接";
  1871. }
  1872. if (!in_array(2, $types)) {
  1873. $missingTypes[] = "图片链接";
  1874. }
  1875. if (!in_array(3, $types)) {
  1876. $missingTypes[] = "底部链接";
  1877. }
  1878. if (!empty($missingTypes)) {
  1879. $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
  1880. return Result::error($errorMessage, 0);
  1881. }
  1882. return Result::success($result);
  1883. }
  1884. /**
  1885. * 自助建站-验证编辑网站
  1886. * @return array
  1887. *
  1888. */
  1889. public function checkWebsiteEdit(array $data): array
  1890. {
  1891. $result = WebsiteTemplateInfo::where('website_template_info.website_id', $data['website_id'])->first();
  1892. if (empty($result)) {
  1893. return Result::error("请输入正确的网站id!", 0);
  1894. }
  1895. // 0:未构建 1:未应用 2:已应用
  1896. if ($result['status'] == 2) {
  1897. return Result::error("此网站的模板正在应用中,暂不可编辑!", 0);
  1898. }
  1899. // 订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束
  1900. $order = Order::where('website_id', $data['website_id'])->where('status', 1)->first();
  1901. if (!empty($order)) {
  1902. return Result::error("此网站的广告位正在使用中,暂不可编辑!", 0);
  1903. }
  1904. $check = $this->checkWebsiteBuild($data);
  1905. if ($check['code'] != 200) {
  1906. return Result::error($check['message'], 0);
  1907. }
  1908. // return Result::success($check);
  1909. if ($result['page_type']) {
  1910. $result['page_type'] = json_decode($result['page_type'], true);
  1911. return Result::success('网站编辑验证通过!');
  1912. } else {
  1913. return Result::error("请先选择网站页面类型!", 0);
  1914. }
  1915. }
  1916. /**
  1917. * 修改网站基础信息
  1918. *
  1919. * @return array
  1920. */
  1921. public function upWebsiteTemplateintel(array $data): array
  1922. {
  1923. $web = Website::where('zxt_website.id', $data['website_id'])->first();
  1924. if (empty($web)) {
  1925. return Result::error("请输入正确的网站id!", 0);
  1926. }
  1927. $where = ['website_id' => $data['website_id']];
  1928. $result = WebsiteTemplateInfo::where($where)->first();
  1929. if (empty($result)) {
  1930. return Result::error("请先添加网站基础信息!", 0);
  1931. } else {
  1932. unset($data['website_id']);
  1933. // 删除重复元素
  1934. $data['page_type'] = array_unique($data['page_type']);
  1935. // 重新索引数组
  1936. $data['page_type'] = array_values($data['page_type']);
  1937. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1938. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1939. // 将数组转换为 JSON 字符串
  1940. $data['page_type'] = json_encode($data['page_type']) ?? '';
  1941. try {
  1942. $result = WebsiteTemplateInfo::where($where)->update($data);
  1943. } catch (\Exception $e) {
  1944. if ($e->getCode() == 22001) {
  1945. $errorMessage = $e->getMessage();
  1946. return Result::error("请检查表单,某个字段超出了长度限制!");
  1947. } else {
  1948. // 处理其他类型的数据库错误
  1949. return Result::error("修改操作失败: " . $e->getMessage());
  1950. }
  1951. return Result::error("修改失败!", 0);
  1952. }
  1953. } else {
  1954. return Result::error("请先选择首页和单页(详情)!", 0);
  1955. }
  1956. }
  1957. if (empty($result)) {
  1958. return Result::error("修改失败!", 0);
  1959. } else {
  1960. return Result::success($result);
  1961. }
  1962. }
  1963. /**
  1964. * 获取所有网站风格信息
  1965. *
  1966. * @return array
  1967. */
  1968. public function getAllTemplateClass(array $data): array
  1969. {
  1970. $result = TemplateClass::all();
  1971. if (empty($result)) {
  1972. return Result::error("没有查找到相关数据!", 0);
  1973. } else {
  1974. return Result::success($result);
  1975. }
  1976. }
  1977. /**
  1978. * 搜索并获取网站模板信息
  1979. * @param array $data
  1980. * @return array
  1981. */
  1982. public function getWebsiteTemplateList(array $data): array
  1983. {
  1984. $website = Website::where('zxt_website.id', $data['website_id'])->first();
  1985. if (empty($website)) {
  1986. return Result::error("请输入正确的网站id!", 0);
  1987. } else {
  1988. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->select('page_type')->first();
  1989. if (empty($page_type)) {
  1990. return Result::error("此网站还未添加基础信息!", 0);
  1991. } else {
  1992. $where = json_decode($page_type['page_type'], true);
  1993. // $where = $data["page_type"];
  1994. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  1995. $template_class = TemplateClass::where('id', $data['template_class_id'])->first();
  1996. if (empty($template_class)) {
  1997. return Result::error("请输入正确的模板风格id!", 0);
  1998. } else {
  1999. // 获取指定风格下的模板
  2000. $rep = Template::where('template_class_id', $data['template_class_id'])
  2001. ->where(function ($query) use ($where) {
  2002. foreach ($where as $value) {
  2003. $query->whereJsonContains('template_img', ['value' => $value]);
  2004. }
  2005. })
  2006. ->limit($data['pageSize'])
  2007. ->offset(($data['page'] - 1) * $data['pageSize'])
  2008. ->orderBy("template.updated_at", "desc")
  2009. ->get();
  2010. $count = Template::where('template_class_id', $data['template_class_id'])
  2011. ->where(function ($query) use ($where) {
  2012. foreach ($where as $value) {
  2013. $query->whereJsonContains('template_img', ['value' => $value]);
  2014. }
  2015. })->count();
  2016. }
  2017. } else {
  2018. //获取所有模板
  2019. $rep = Template::where(function ($query) use ($where) {
  2020. foreach ($where as $value) {
  2021. $query->whereJsonContains('template_img', ['value' => $value]);
  2022. }
  2023. })
  2024. ->limit($data['pageSize'])
  2025. ->offset(($data['page'] - 1) * $data['pageSize'])
  2026. ->orderBy("template.updated_at", "desc")
  2027. ->get();
  2028. $count = Template::where(function ($query) use ($where) {
  2029. foreach ($where as $value) {
  2030. $query->whereJsonContains('template_img', ['value' => $value]);
  2031. }
  2032. })->count();
  2033. }
  2034. if (empty($rep) || $rep->count() == 0) {
  2035. return Result::error("没有查找到相关数据!", 0);
  2036. } else {
  2037. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  2038. // $rep->each(function ($item) use ($where) {
  2039. // $template_img = json_decode($item->template_img, true);
  2040. // if(is_array($template_img)){
  2041. // $filtered_img = array_filter($template_img, function ($img) use ($where) {
  2042. // return isset($img['value']) && in_array($img['value'], $where);
  2043. // });
  2044. // }
  2045. // $item->template_img = $filtered_img;
  2046. // });
  2047. // $result = [
  2048. // "rows" => $rep->toArray(),
  2049. // "count" => $count
  2050. // ];
  2051. $rep->each(function ($item) use ($where) {
  2052. $template_img = json_decode($item->template_img, true);
  2053. if (is_array($template_img)) {
  2054. $filtered_img = array_filter($template_img, function ($img) use ($where) {
  2055. return isset($img['value']) && in_array($img['value'], $where);
  2056. });
  2057. // 对过滤后的数组进行重新排序
  2058. $sorted_img = array_values($filtered_img);
  2059. $item->template_img = $sorted_img;
  2060. } else {
  2061. $item->template_img = []; // 如果无法解码为数组,则设置为空数组
  2062. }
  2063. });
  2064. $result = [
  2065. "rows" => $rep->toArray(),
  2066. "count" => $count,
  2067. ];
  2068. }
  2069. }
  2070. }
  2071. return Result::success($result);
  2072. }
  2073. /**
  2074. * 添加网站模板
  2075. * @param array $data
  2076. */
  2077. public function addWebsiteTemplateclassintel(array $data): array
  2078. {
  2079. $template = Template::where('id', $data['template_id'])->first();
  2080. $web = Website::where('id', $data['website_id'])->first();
  2081. if (empty($template)) {
  2082. return Result::error("请输入正确的模板id", 0);
  2083. }
  2084. if (empty($web)) {
  2085. return Result::error("请输入正确的网站id", 0);
  2086. }
  2087. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
  2088. if (empty($result)) {
  2089. return Result::error("添加失败", 0);
  2090. } else {
  2091. return Result::success($result);
  2092. }
  2093. }
  2094. /**
  2095. * 获取网站模板信息
  2096. * @param array $data
  2097. */
  2098. public function getWebsiteTemplateclassintel(array $data): array
  2099. {
  2100. // return Result::success($data);
  2101. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2102. if (empty($template)) {
  2103. return Result::error("请输入正确的搭建网站id", 0);
  2104. }
  2105. $page_type = json_decode($template['page_type'], true);
  2106. // 获取指定网站下的基础信息和模板及风格信息
  2107. $result = WebsiteTemplateInfo::where([
  2108. ['website_template_info.website_id', $data['website_id']],
  2109. ['website_template_info.template_id', '!=', null],
  2110. ])
  2111. ->leftJoin('template', 'template.id', 'website_template_info.template_id')
  2112. ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
  2113. ->where(function ($query) use ($page_type) {
  2114. // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
  2115. foreach ($page_type as $pageType) {
  2116. $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
  2117. }
  2118. })
  2119. ->select(
  2120. 'template.template_name',
  2121. 'template.template_img',
  2122. 'template.id as tid',
  2123. 'template_class.name',
  2124. 'template_class.id as class_id',
  2125. 'website_template_info.page_type',
  2126. 'website_template_info.website_id'
  2127. )
  2128. ->first();
  2129. if (empty($result)) {
  2130. return Result::error("没有查找到相关数据", 0);
  2131. }
  2132. // return Result::success($result);
  2133. // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
  2134. $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
  2135. $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
  2136. foreach ($template_img as $key => $value) {
  2137. if (!in_array($value['value'], $page_type)) {
  2138. unset($template_img[$key]);
  2139. }
  2140. }
  2141. // return Result::success($result);
  2142. $result['template_img'] = array_values($template_img);
  2143. $result['page_type'] = $page_type;
  2144. // $templateList = $this->getWebsiteTemplateList($data);
  2145. // $count = $templateList['data']['count']??'';
  2146. // $pages = $count / $data['pageSize'];
  2147. // $found = false;
  2148. // while ($pages && !$found) {
  2149. // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
  2150. // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
  2151. // if ($index !== false) {
  2152. // $found = true;
  2153. // $result['page'] = $pages;
  2154. // $pages = 0;
  2155. // // echo "查询到的 template 在第 $page 页";
  2156. // }
  2157. // $pages--;
  2158. // }
  2159. return Result::success($result);
  2160. }
  2161. /**
  2162. * 获取网站模板下的板块信息
  2163. * @param array $data
  2164. */
  2165. public function getWebsiteSectorList(array $data): array
  2166. {
  2167. $website = Website::where('id', $data['website_id'])->first();
  2168. if (empty($website)) {
  2169. return Result::error("请输入正确的网站id", 0);
  2170. }
  2171. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2172. if (empty($template['template_id'])) {
  2173. return Result::error("请先添加网站模板", 0);
  2174. }
  2175. $query = Sector::where('template_id', $template['template_id']);
  2176. if ($query->count() == 0) {
  2177. return Result::error("没有查找到相关板块数据", 0);
  2178. } elseif ($query->count() == 1) {
  2179. $sector = $query->first();
  2180. } else {
  2181. $sector = $query->get();
  2182. }
  2183. $result['page_type'] = $template['page_type'];
  2184. $result['tid'] = $template['template_id'];
  2185. $result = [
  2186. "tid" => $template['template_id'],
  2187. "page_type" => $template['page_type'],
  2188. "sector" => $sector,
  2189. ];
  2190. return Result::success($result);
  2191. }
  2192. // 自助建站---------------fr---------------
  2193. // 网站底基础信息--fr-------------------
  2194. /**
  2195. * 添加网站底基础信息
  2196. * @param array $data
  2197. */
  2198. public function addWebFootInfo(array $data): array
  2199. {
  2200. $website = Website::where('id', $data['website_id'])->first();
  2201. if (empty($website)) {
  2202. return Result::error("请输入正确的网站id!", 0);
  2203. }
  2204. $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2205. if (!empty($info)) {
  2206. return Result::error("该网站已经添加过了!", 0);
  2207. }
  2208. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->insertGetId($data);
  2209. if (empty($result)) {
  2210. return Result::error("请先添加网站基础信息!", 0);
  2211. } else {
  2212. return Result::success($result);
  2213. }
  2214. }
  2215. /**
  2216. * 获取网站底基础信息
  2217. * @param array $data
  2218. */
  2219. public function getWebFootInfo(array $data): array
  2220. {
  2221. $website = Website::where('id', $data['website_id'])->first();
  2222. if (empty($website)) {
  2223. return Result::error("请输入正确的网站id!", 0);
  2224. }
  2225. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2226. if (empty($result)) {
  2227. return Result::error("请先添加网站基础信息!", 0);
  2228. }
  2229. return Result::success($result);
  2230. }
  2231. /**
  2232. * 修改网站底基础信息
  2233. * @param array $data
  2234. */
  2235. public function upWebFootInfo(array $data): array
  2236. {
  2237. // return Result::success($data);
  2238. $website = Website::where('id', $data['website_id'])->first();
  2239. if (empty($website)) {
  2240. return Result::error("请输入正确的网站id!", 0);
  2241. }
  2242. $web = $data['website_id'];
  2243. unset($data['website_id']);
  2244. $where = ['website_id' => $web];
  2245. // return Result::success($data);
  2246. $result = WebsiteTemplateInfo::where($where)->first();
  2247. if (empty($result)) {
  2248. $data['website_id'] = $web;
  2249. $result = WebsiteTemplateInfo::insertGetId($data);
  2250. // return Result::error("请先添加网站基础信息!",0);
  2251. } else {
  2252. $result = WebsiteTemplateInfo::where($where)->update($data);
  2253. }
  2254. // $where = ['website_id'=>$data['website_id']];
  2255. // unset($data['website_id']);
  2256. // $result = WebsiteTemplateInfo::updateOrInsert($where, $data);
  2257. if (empty($result)) {
  2258. return Result::error("修改失败!", 0);
  2259. }
  2260. return Result::success($result);
  2261. }
  2262. /*
  2263. * 获取父级/子级栏目------路由
  2264. * @param array $data
  2265. * @return array
  2266. * */
  2267. public function getWebsiteParentCategory(array $data): array
  2268. {
  2269. // return Result::success($data);
  2270. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2271. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  2272. }
  2273. if (empty($website)) {
  2274. return Result::error("暂无该网站", 0);
  2275. }
  2276. // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法。
  2277. // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理。
  2278. $category['parent'] = WebsiteCategory::where('website_id', $data['website_id'])
  2279. ->where('pid', 0)
  2280. ->selectRaw("category_id as cid, alias as name, CONCAT('/', '', aLIas_pinyin, '/') as path")
  2281. ->get() // 添加 get() 方法获取结果集合
  2282. ->all();
  2283. // 提前查询所有父级栏目,避免在 map 中多次查询
  2284. // 提前查询所有父级栏目信息并以 category_id 作为键存储
  2285. $parentCategories = WebsiteCategory::where('website_id', $data['website_id'])
  2286. ->where('pid', 0)
  2287. ->select('category_id', 'aLIas_pinyin')
  2288. ->get()
  2289. ->keyBy('category_id');
  2290. // 直接查询子栏目信息
  2291. $child = WebsiteCategory::where('website_id', $data['website_id'])
  2292. ->where('pid', '!=', 0)
  2293. ->select('alias', 'category_id', 'aLIas_pinyin', 'pid')
  2294. ->get();
  2295. // 使用集合的 map 方法处理子栏目信息
  2296. $category['child'] = $child->map(function ($item) use ($parentCategories) {
  2297. $alias = $item->alias;
  2298. $category_id = $item->category_id;
  2299. $aLIas_pinyin = $item->aLIas_pinyin;
  2300. $parent = $parentCategories->get($item->pid);
  2301. $parentAlias = $parent ? $parent->aLIas_pinyin : '';
  2302. $result = [
  2303. 'name' => $alias,
  2304. 'cid' => $category_id
  2305. ];
  2306. if (!empty($aLIas_pinyin) && !empty($parentAlias)) {
  2307. $result['path'] = "/{$parentAlias}/{$aLIas_pinyin}/";
  2308. }
  2309. return $result;
  2310. })->values()->all();
  2311. if (empty($category)) {
  2312. return Result::error("暂无此导航", 0);
  2313. }
  2314. return Result::success($category);
  2315. }
  2316. //20250212 网站标识
  2317. public function addWebsiteGroup(array $data): array
  2318. {
  2319. //判斷name是不是重复
  2320. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2321. if (!empty($websiteGroupInfo)) {
  2322. return Result::error("网站标识重复", 0);
  2323. }
  2324. //添加信息
  2325. $result = WebsiteGroup::insertGetId($data);
  2326. var_dump($result);
  2327. if (empty($result)) {
  2328. return Result::error("创建失败", 0);
  2329. } else {
  2330. return Result::success($result);
  2331. }
  2332. }
  2333. public function getWebsiteGroupList(array $data): array
  2334. {
  2335. $where = [];
  2336. if (isset($data['name']) && !empty($data['name'])) {
  2337. array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
  2338. }
  2339. $result = WebsiteGroup::where($where)
  2340. ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
  2341. ->get();
  2342. foreach ($result as $websiteGroup) {
  2343. $webIds = json_decode($websiteGroup->web_ids, true);
  2344. $websites = Website::whereIn('id', $webIds)->get();
  2345. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2346. $websiteGroup->website_names = $websiteNames;
  2347. $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
  2348. }
  2349. $count = WebsiteGroup::where($where)->count();
  2350. if (empty($result)) {
  2351. return Result::error("没有数据", 0);
  2352. }
  2353. return Result::success(['list' => $result->toArray(), 'count' => $count]);
  2354. }
  2355. public function getWebsiteGroupInfo(array $data): array
  2356. {
  2357. $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
  2358. $webIds = json_decode($websiteInfo->web_ids, true);
  2359. $websites = Website::whereIn('id', $webIds)->get();
  2360. $websiteNames = $websites->pluck('website_name', 'id')->toArray();
  2361. $websiteInfo->website_names = $websiteNames;
  2362. $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
  2363. if (empty($websiteInfo)) {
  2364. return Result::error("找不到URL", 0);
  2365. }
  2366. return Result::success($websiteInfo->toArray());
  2367. }
  2368. public function updateWebsiteGroup(array $data): array
  2369. {
  2370. $where = [
  2371. 'id' => $data['id'],
  2372. ];
  2373. $insertData = [
  2374. 'name' => $data['name'],
  2375. 'web_ids' => $data['web_ids'],
  2376. ];
  2377. //判斷name是不是重复
  2378. $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
  2379. if (!empty($websiteGroupInfo) && $websiteGroupInfo->id != $data['id']) {
  2380. return Result::error("网站标识重复", 0);
  2381. }
  2382. $result = WebsiteGroup::where($where)->update($insertData);
  2383. var_dump($result, '------更新');
  2384. if (empty($result)) {
  2385. return Result::error("更新失败", 0);
  2386. } else {
  2387. return Result::success();
  2388. }
  2389. }
  2390. public function deleteWebsiteGroup(array $data): array
  2391. {
  2392. $where = [
  2393. 'id' => $data['id'],
  2394. ];
  2395. //看看user表是不是有这个id
  2396. $userGroup = User::query()->where('sszq', $data['id'])->first();
  2397. if (!empty($userGroup)) {
  2398. return Result::error("有用户在使用该网站标识,不能删除", 0);
  2399. }
  2400. $result = WebsiteGroup::where($where)->delete();
  2401. if (empty($result)) {
  2402. return Result::error("删除失败", 0);
  2403. } else {
  2404. return Result::success();
  2405. }
  2406. }
  2407. public function getWebsiteNavList(array $data): array
  2408. {
  2409. $data['type'] = isset($data['type']) ? $data['type'] : 1;
  2410. $where = [];
  2411. if (isset($data['website_id']) && !empty($data['website_id'])) {
  2412. array_push($where, ['website_id', '=', $data['website_id']]);
  2413. }
  2414. if (isset($data['pid'])) {
  2415. array_push($where, ['pid', '=', $data['pid']]);
  2416. }
  2417. if (isset($data['type']) && !empty($data['type'])) {
  2418. array_push($where, ['type', '=', $data['type']]);
  2419. }
  2420. // 根据站点和type获取websiteCategory 中的id
  2421. $websiteCategoryids = WebsiteCategory::query()
  2422. ->where('website_id', '=', $data['website_id'])
  2423. ->where('type', '=', $data['type'])
  2424. ->pluck('category_arr_id')->toArray();
  2425. var_dump($websiteCategoryids, '------获取websiteCategory 中的id');
  2426. //合并去重
  2427. $category_ids = [];
  2428. foreach ($websiteCategoryids as $key => $value) {
  2429. $v = json_decode($value, true);
  2430. $category_ids = array_unique(array_merge($category_ids, $v));
  2431. }
  2432. // var_dump($category_ids, '------获取websiteCategory 中的id');
  2433. $realList = WebsiteCategory::query()
  2434. ->where('website_id', '=', $data['website_id'])
  2435. ->where('is_url', '!=', 1)
  2436. ->where('real_pid', '=', $data['pid'])
  2437. ->select(
  2438. '*',
  2439. DB::raw('real_pid AS pid'),
  2440. DB::raw('real_category_arr_id AS category_arr_id')
  2441. )
  2442. ->whereIn('category_id', $category_ids)
  2443. ->get();
  2444. //根据pid取出所有的websiteCategory 中的id
  2445. $list = WebsiteCategory::query()
  2446. ->where('website_id', '=', $data['website_id'])
  2447. ->where('is_url', '!=', 1)
  2448. ->where('pid', '=', $data['pid'])
  2449. ->whereIn('category_id', $category_ids)
  2450. ->get();
  2451. $list = $list->merge($realList);
  2452. if (empty($list)) {
  2453. return Result::error("获取失败", 0);
  2454. } else {
  2455. return Result::success($list);
  2456. }
  2457. }
  2458. // 20250307 根据网站标识获和导航获取站点
  2459. public function getWebsiteNavPoolSite(array $data): array
  2460. {
  2461. $where = [];
  2462. if (isset($data['category_id']) && !empty($data['category_id'])) {
  2463. array_push($where, ['category_id', '=', $data['category_id']]);
  2464. }
  2465. if($data['article_id'] != 0){
  2466. $list = Article::where('article.id', $data['article_id'])
  2467. ->leftJoin('website_category', 'article.catid', '=', 'website_category.category_id')
  2468. // WebsiteCategory::query()->where($where)
  2469. ->leftJoin('website', 'zxt_website.id', '=', 'website_category.website_id')
  2470. ->leftJoinSub(function ($query) use ($data) {
  2471. $query->from('article_ignore')
  2472. ->where('article_ignore.article_id', $data['article_id']);
  2473. }, 'article_ignore', function ($join) {
  2474. $join->on('website_category.website_id', '=', 'article_ignore.website_id');
  2475. })
  2476. ->select('website_category.*', 'zxt_website.website_name', DB::raw('IFNULL(article_ignore.c_show_time, "") as c_show_time')) // 选择需要的字段,不存在记录时 c_show_time 为空字符串
  2477. ->distinct('zxt_website.website_name') // 使用DISTINCT关键字按website_name过滤重复数据
  2478. ->get();
  2479. // ->array_map(function ($item) {
  2480. // $item['c_show_time'] = json_decode($item['category_arr_id'], true);
  2481. // return $item;
  2482. // })
  2483. ;
  2484. }else{
  2485. $list = WebsiteCategory::query()->where($where)
  2486. ->leftJoin('website', 'zxt_website.id', '=', 'website_category.website_id')
  2487. ->select('website_category.*', 'zxt_website.website_name')
  2488. ->distinct()
  2489. ->get();
  2490. }
  2491. if (empty($list)) {
  2492. return Result::error("获取失败", 0);
  2493. } else {
  2494. return Result::success($list);
  2495. }
  2496. }
  2497. public function getWebsiteNavPool(array $data): array
  2498. {
  2499. // 初始化查询条件数组
  2500. $query = WebsiteCategory::query();
  2501. // 如果传入了 websiteids,则添加到查询条件中
  2502. if (isset($data['websiteids']) && !empty($data['websiteids'])) {
  2503. $query->whereIn('website_id', $data['websiteids']);
  2504. }
  2505. // 如果传入了 pid,则添加到查询条件中
  2506. if (isset($data['pid'])) {
  2507. $query->where('pid', '=', $data['pid']);
  2508. }
  2509. // 执行查询 唯一性 id
  2510. $list = $query->distinct()->get();
  2511. // 根据查询结果返回相应的结果
  2512. if ($list->isEmpty()) {
  2513. return Result::error("获取失败", 0);
  2514. } else {
  2515. return Result::success($list->toArray());
  2516. }
  2517. }
  2518. /**
  2519. *
  2520. * @param array $data
  2521. * @return array
  2522. */
  2523. public function getAllCategory(array $data): array
  2524. {
  2525. $total = Category::count();
  2526. $pageSize = 2000;
  2527. $pages = (int) ceil($total / $pageSize);
  2528. $results = [];
  2529. $concurrency = 5; // 最大并发数
  2530. $running = 0;
  2531. $chan = new \Swoole\Coroutine\Channel($pages);
  2532. for ($i = 0; $i < $pages; $i++) {
  2533. Coroutine::create(function () use ($i, $pageSize, $chan) {
  2534. $offset = $i * $pageSize;
  2535. $data = Category::useIndex('idx_covering')
  2536. ->orderBy('id', 'asc')
  2537. ->select('id', 'name', 'pid')
  2538. ->offset($offset)
  2539. ->limit($pageSize)
  2540. ->get()
  2541. ->toArray();
  2542. $chan->push($data);
  2543. });
  2544. }
  2545. for ($i = 0; $i < $pages; $i++) {
  2546. $res = $chan->pop();
  2547. if (is_array($res)) {
  2548. $results = array_merge($results, $res);
  2549. }
  2550. }
  2551. return Result::success($results);
  2552. }
  2553. /**
  2554. * 修改网站栏目排序
  2555. * @param array $data
  2556. * @return array
  2557. */
  2558. public function upWebsiteCategorySort(array $data): array
  2559. {
  2560. $where = [
  2561. 'website_id' => $data['website_id'],
  2562. 'id' => $data['id'],
  2563. ];
  2564. $result = WebsiteCategory::where($where)->update($data);
  2565. if ($result) {
  2566. return Result::success($result);
  2567. } else {
  2568. return Result::error("更新失败", 0);
  2569. }
  2570. }
  2571. //获取底部导航内容详情
  2572. public function getFooterContentInfo(array $data): array
  2573. {
  2574. $where = [
  2575. "id" => $data['content_id']
  2576. ];
  2577. $result = FooterContent::where($where)->first();
  2578. if ($result) {
  2579. return Result::success($result);
  2580. } else {
  2581. return Result::error("没有数据");
  2582. }
  2583. }
  2584. //获取底部导航内容列表
  2585. public function getFooterContentList(array $data): array
  2586. {
  2587. $where = [
  2588. "fcat_id" => $data['fcat_id'],
  2589. ];
  2590. switch (intval($data['type'])) {
  2591. case 0:
  2592. $result = FooterContent::where($where)->first();
  2593. break;
  2594. case 1:
  2595. $result = FooterContent::where($where)->get();
  2596. break;
  2597. }
  2598. if ($result) {
  2599. return Result::success($result);
  2600. } else {
  2601. return Result::error("没有数据");
  2602. }
  2603. }
  2604. /**
  2605. * 获取底部导航列表
  2606. * @param array $data
  2607. * @return array
  2608. */
  2609. public function getFooterCategoryList(array $data): array
  2610. {
  2611. $where = [
  2612. "website_id" => $data['website_id']
  2613. ];
  2614. $result = FooterCategory::where($where)->get();
  2615. if ($result) {
  2616. return Result::success($result);
  2617. } else {
  2618. return Result::error("没有数据");
  2619. }
  2620. }
  2621. // --自助建站-----------20250522fr----------------------start
  2622. /**
  2623. * 获取网站模板下的板块信息
  2624. * @param array $data
  2625. * @return array
  2626. */
  2627. public function getStaticResourceList(array $data): array
  2628. {
  2629. // return Result::success($data);
  2630. $where = [];
  2631. if (isset($data['img_alias']) && !empty($data['img_alias'])) {
  2632. array_push($where, ['website_img.img_alias', 'like', '%' . $data['img_alias'] . '%']);
  2633. }
  2634. if (isset($data['img_type']) && !empty($data['img_type'])) {
  2635. array_push($where, ['website_img.img_type', '=', $data['img_type']]);
  2636. }
  2637. if (isset($data['website_name']) && !empty($data['website_name'])) {
  2638. $website = Website::where('website_name', 'like', '%' . $data['website_name'] . '%')->first();
  2639. if (empty($website)) {
  2640. return Result::error("没有查找到相关数据", 0);
  2641. } else {
  2642. array_push($where, ['website_img.website_id', '=', $website['id']]);
  2643. }
  2644. }
  2645. // return Result::success($where);
  2646. $query = WebsiteImg::when(!empty($where), function ($query) use ($where) {
  2647. $query->where($where);
  2648. })
  2649. ->orderBy('updated_at', 'desc');
  2650. $count = $query->count();
  2651. $row = $query->leftJoin('website', 'zxt_website.id', '=', 'website_img.website_id')
  2652. ->select('website_img.*', 'zxt_website.website_name')
  2653. ->limit($data['pageSize'])
  2654. ->offset(($data['page'] - 1) * $data['pageSize'])
  2655. ->get();
  2656. if (empty($row)) {
  2657. return Result::error("没有查找到相关数据", 0);
  2658. } else {
  2659. $result = [
  2660. 'row' => $row,
  2661. 'count' => $count,
  2662. ];
  2663. }
  2664. return Result::success($result);
  2665. }
  2666. /**
  2667. * 添加网站模板下的板块信息
  2668. * @param array $data
  2669. */
  2670. public function addStaticResource(array $data): array
  2671. {
  2672. // $file = $data['img_url']->file('image');
  2673. // $size = $file->getSize();
  2674. $img_data = [
  2675. 'website_id' => $data['website_id'] ?? 0,
  2676. 'img_alias' => $data['img_alias'] ?? '',
  2677. 'img_url' => $data['img_url'],
  2678. 'img_size' => $data['img_size'],
  2679. ];
  2680. $img = WebsiteImg::insertGetId($img_data);
  2681. if (empty($img)) {
  2682. return Result::error("添加失败", 0);
  2683. }
  2684. $img_id['id'] = $img;
  2685. $url = WebsiteImg::where($img_id)->value('img_url');
  2686. // 1. 分割路径部分(以 / 为分隔符)
  2687. $pathSegments = explode('/', parse_url($url, PHP_URL_PATH));
  2688. // 2. 取最后一个元素作为文件名
  2689. $fileName = end($pathSegments); // 1743041040714597.jpg
  2690. // 3. 分割文件名获取扩展名
  2691. $fileParts = explode('.', $fileName);
  2692. $fileType = end($fileParts); // jpg
  2693. $img_datas = [
  2694. 'img_type' => $fileType,
  2695. 'name' => $fileName
  2696. ];
  2697. $up_img = WebsiteImg::where($img_id)->update($img_datas);
  2698. if (empty($up_img)) {
  2699. return Result::error("修改失败", 0);
  2700. }
  2701. return Result::success($img);
  2702. // 将字节转换为更友好的单位
  2703. // $friendlySize = $this->formatFileSize($size);
  2704. // $data['img_size'] = $friendlySize;
  2705. }
  2706. /**
  2707. * 修改网站模板下的板块信息
  2708. * @param array $data
  2709. */
  2710. public function delStaticResource(array $data): array
  2711. {
  2712. $where = [
  2713. 'id' => $data['id'],
  2714. ];
  2715. $result = WebsiteImg::where($where)->delete();
  2716. if (empty($result)) {
  2717. return Result::error("修改失败", 0);
  2718. }
  2719. return Result::success($result);
  2720. }
  2721. /**
  2722. * 获取尺寸列表
  2723. * @param array $data
  2724. */
  2725. public function getSizeList(array $data): array
  2726. {
  2727. $where = [];
  2728. if (isset($data['width']) && !empty($data['width'])) {
  2729. array_push($where, ['width', 'like', '%' . $data['width'] . '%']);
  2730. }
  2731. if (isset($data['height']) && !empty($data['height'])) {
  2732. array_push($where, ['height', 'like', '%' . $data['height'] . '%']);
  2733. }
  2734. $query = Size::when($where, function ($query) use ($where) {
  2735. $query->where($where);
  2736. })
  2737. ->orderBy('updated_at', 'desc');
  2738. $count = $query->count();
  2739. $rep = $query
  2740. ->offset(($data['page'] - 1) * $data['pageSize'])
  2741. ->limit($data['pageSize'])
  2742. ->get();
  2743. $result = [
  2744. 'row' => $rep,
  2745. 'count' => $count,
  2746. ];
  2747. if (empty($result)) {
  2748. return Result::error("获取失败", 0);
  2749. } else {
  2750. return Result::success($result);
  2751. }
  2752. }
  2753. /**
  2754. * 添加尺寸
  2755. * @param array $data
  2756. */
  2757. public function addSize(array $data): array
  2758. {
  2759. $size = Size::where('width', $data['width'])->where('height', $data['height'])->first();
  2760. if (!empty($size)) {
  2761. return Result::error("尺寸已存在", 0);
  2762. }
  2763. $result = Size::insertGetId($data);
  2764. if (empty($result)) {
  2765. return Result::error("添加失败", 0);
  2766. }
  2767. return Result::success($result);
  2768. }
  2769. /**
  2770. * 删除尺寸
  2771. * @param array $data
  2772. */
  2773. public function delSize(array $data): array
  2774. {
  2775. $where = [
  2776. 'id' => $data['id'],
  2777. ];
  2778. $result = Size::where($where)->delete();
  2779. if (empty($result)) {
  2780. return Result::error("删除失败", 0);
  2781. }
  2782. return Result::success($result);
  2783. }
  2784. /**
  2785. * 修改尺寸
  2786. * @param array $data
  2787. */
  2788. public function upSize(array $data): array
  2789. {
  2790. $where = [
  2791. 'id' => $data['id'],
  2792. ];
  2793. $size = Size::where('id', '!=', $data['id'])->where('width', $data['width'])->where('height', $data['height'])->first();
  2794. if (!empty($size)) {
  2795. return Result::error("尺寸已存在", 0);
  2796. }
  2797. $result = Size::where($where)->update($data);
  2798. if (empty($result)) {
  2799. return Result::error("修改失败", 0);
  2800. }
  2801. return Result::success($result);
  2802. }
  2803. /**
  2804. * 获取尺寸详情
  2805. * @param array $data
  2806. */
  2807. public function getSizeInfo(array $data): array
  2808. {
  2809. $where = [
  2810. 'id' => $data['id'],
  2811. ];
  2812. $result = Size::where($where)->first();
  2813. if (empty($result)) {
  2814. return Result::error("获取失败", 0);
  2815. } else {
  2816. return Result::success($result);
  2817. }
  2818. }
  2819. /**
  2820. * 获取网站名称缩写
  2821. * @param array $data
  2822. */
  2823. public function getWebsiteAdkey(array $data): array
  2824. {
  2825. $result = PinyinHelper::getFirstLetter($data['website_name']);
  2826. if (empty($result)) {
  2827. return Result::error("没有数据", 0);
  2828. } else {
  2829. return Result::success($result);
  2830. }
  2831. }
  2832. /**
  2833. * 静态资源管理-修改图片别名
  2834. * @param array $data
  2835. */
  2836. public function upStaticResource(array $data): array
  2837. {
  2838. $id = $data['id'];
  2839. unset($data['id']);
  2840. if(isset($data['img_url']) && !empty($data['img_url'])){
  2841. $url = $data['img_url'];
  2842. // 1. 分割路径部分(以 / 为分隔符)
  2843. $pathSegments = explode('/', parse_url($url, PHP_URL_PATH));
  2844. // 2. 取最后一个元素作为文件名
  2845. $fileName = end($pathSegments); // 1743041040714597.jpg
  2846. // 3. 分割文件名获取扩展名
  2847. $fileParts = explode('.', $fileName);
  2848. $fileType = end($fileParts); // jpg
  2849. $data['img_type'] = $fileType;
  2850. $data['name'] = $fileName;
  2851. }
  2852. $result = WebsiteImg::where('id', $id)->update($data);
  2853. if (empty($result)) {
  2854. return Result::error("修改失败", 0);
  2855. }
  2856. return Result::success($result);
  2857. }
  2858. /**
  2859. * 自助建站-修改网站应用状态
  2860. * @param array $data
  2861. */
  2862. public function upWebsiteStatus(array $data): array
  2863. {
  2864. $where = [
  2865. 'website_id' => $data['website_id'],
  2866. ];
  2867. $website_template = WebsiteTemplate::where($where)->first();
  2868. unset($data['website_id']);
  2869. // if($data['status'] == 2){
  2870. // $template_status = 6;
  2871. // }else{
  2872. // $template_status = 1;
  2873. // }
  2874. if (empty($website_template)) {
  2875. return Result::error("网站预制模板获取失败", 0);
  2876. } else {
  2877. // Db::beginTransaction();
  2878. // try {
  2879. // $result['website_template'] = WebsiteTemplate::where($where)->update(['status'=>$template_status]);
  2880. // if (empty($result['website_template'])) {
  2881. // return Result::error("修改网站模板状态失败", 0);
  2882. // }
  2883. $result['website_template_info'] = WebsiteTemplateInfo::where($where)->update(['status' => $data['status']]);
  2884. if (empty($result['website_template_info'])) {
  2885. return Result::error("修改网站基础信息状态失败", 0);
  2886. }
  2887. // Db::commit();
  2888. return Result::success($result);
  2889. // } catch (\Exception $e) {
  2890. // Db::rollBack();
  2891. // return Result::error($e->getMessage(), 0);
  2892. // }
  2893. }
  2894. }
  2895. // --自助建站-----------20250522fr----------------------end
  2896. /**
  2897. * 获取网站白名单路由地址
  2898. * @param array $data
  2899. * @return array
  2900. */
  2901. public function getWhiteRouterList(array $data): array
  2902. {
  2903. // 构建基础查询
  2904. $baseQuery = WhiteRouter::query();
  2905. // 功能名称模糊查询
  2906. if (!empty($data['function_name'])) {
  2907. $baseQuery->where('function_name', 'like', '%' . $data['function_name'] . '%');
  2908. }
  2909. // 网站ID查询 - 使用 JSON_CONTAINS 检查数组中是否包含指定的 website_id
  2910. if (!empty($data['website_id'])) {
  2911. $baseQuery->whereRaw('JSON_CONTAINS(website_id, ?)', [json_encode((int)$data['website_id'])]);
  2912. }
  2913. // 获取总数
  2914. $count = $baseQuery->count();
  2915. // 分页查询
  2916. $result = $baseQuery->orderBy('updated_at', 'desc')
  2917. ->limit($data['pageSize'])
  2918. ->offset(($data['page'] - 1) * $data['pageSize'])
  2919. ->get();
  2920. if (empty($result)) {
  2921. return Result::error("暂无数据", 0);
  2922. }
  2923. // 处理结果,将 website_id 转换为数组并获取对应的网站名称
  2924. $result->transform(function ($item) {
  2925. $websiteIds = json_decode($item->website_id, true);
  2926. $websiteNames = Website::whereIn('id', $websiteIds)
  2927. ->pluck('website_name')
  2928. ->toArray();
  2929. $item->website_names = $websiteNames;
  2930. $item->website_id = $websiteIds; // 将 website_id 转换为数组
  2931. return $item;
  2932. });
  2933. return Result::success([
  2934. 'rows' => $result->toArray(),
  2935. 'count' => $count
  2936. ]);
  2937. }
  2938. /**
  2939. * 添加网站白名单路由地址
  2940. * @param array $data
  2941. * @return array
  2942. */
  2943. public function addWhiteRouter(array $data): array
  2944. {
  2945. // 确保 website_id 是数组
  2946. $websiteIds = is_array($data['website_id']) ? $data['website_id'] : [$data['website_id']];
  2947. // 过滤空值并去重
  2948. $websiteIds = array_filter($websiteIds);
  2949. $websiteIds = array_unique($websiteIds);
  2950. // 将数组中的值转换为整数
  2951. $websiteIds = array_map(function ($value) {
  2952. return (int)$value;
  2953. }, $websiteIds);
  2954. // 转换为 JSON 字符串存储
  2955. $data['website_id'] = json_encode($websiteIds);
  2956. $result = WhiteRouter::insertGetId($data);
  2957. if (empty($result)) {
  2958. return Result::error("添加失败", 0);
  2959. }
  2960. return Result::success($result);
  2961. }
  2962. /**
  2963. * 修改网站白名单路由地址
  2964. * @param array $data
  2965. * @return array
  2966. */
  2967. public function upWhiteRouter(array $data): array
  2968. {
  2969. $where = [
  2970. 'id' => $data['id'],
  2971. ];
  2972. // 确保 website_id 是数组
  2973. $websiteIds = is_array($data['website_id']) ? $data['website_id'] : [$data['website_id']];
  2974. // 过滤空值并去重
  2975. $websiteIds = array_filter($websiteIds);
  2976. $websiteIds = array_unique($websiteIds);
  2977. // 将数组中的值转换为整数
  2978. $websiteIds = array_map(function ($value) {
  2979. return (int)$value;
  2980. }, $websiteIds);
  2981. // 转换为 JSON 字符串存储
  2982. $data['website_id'] = json_encode($websiteIds);
  2983. $result = WhiteRouter::where($where)->update($data);
  2984. if (empty($result)) {
  2985. return Result::error("修改失败", 0);
  2986. }
  2987. return Result::success($result);
  2988. }
  2989. /**
  2990. * 删除网站白名单路由地址
  2991. * @param array $data
  2992. * @return array
  2993. */
  2994. public function delWhiteRouter(array $data): array
  2995. {
  2996. $where = [
  2997. 'id' => $data['id'],
  2998. ];
  2999. $result = WhiteRouter::where($where)->delete();
  3000. if (empty($result)) {
  3001. return Result::error("删除失败", 0);
  3002. }
  3003. return Result::success($result);
  3004. }
  3005. /**
  3006. * 获取网站白名单路由地址详情
  3007. * @param array $data
  3008. * @return array
  3009. */
  3010. public function getWhiteRouterInfo(array $data): array
  3011. {
  3012. $where = [
  3013. 'id' => $data['id'],
  3014. ];
  3015. $result = WhiteRouter::where($where)->first();
  3016. if (empty($result)) {
  3017. return Result::error("没有查找到相关数据", 0);
  3018. }
  3019. // 将 website_id 从 JSON 字符串转换为数组
  3020. $result->website_id = json_decode($result->website_id, true);
  3021. return Result::success($result);
  3022. }
  3023. /**
  3024. * 克隆网站
  3025. * @param array $data
  3026. * @return array
  3027. */
  3028. public function cloneWebsite(array $data): array
  3029. {
  3030. DB::beginTransaction();
  3031. try {
  3032. // 获取原始网站信息
  3033. $originalWebsite = Website::find($data['website_id']);
  3034. if (!$originalWebsite) {
  3035. return Result::error("找不到该网站", 0);
  3036. }
  3037. // 提取基础名称(去除已有 _copy 或 _copy_xxx)
  3038. $baseName = preg_replace('/_copy(\d+)?$/', '', $originalWebsite->website_name);
  3039. // 查询当前系统中已存在的克隆名称数量
  3040. $count = Website::where('website_name', 'like', $baseName . '_copy%')
  3041. ->orWhere('website_name', $baseName)
  3042. ->count();
  3043. // 构造新名称:第一次是 _copy,之后是 _copy_1, _copy_2 ...
  3044. $newName = $baseName . ($count === 0 ? '_copy' : '_copy_' . $count);
  3045. // 创建克隆网站实例
  3046. $clone_website = $originalWebsite->replicate();
  3047. $clone_website->website_name = $newName;
  3048. $clone_website->save();
  3049. $clone_website->website_url = "[]";
  3050. $clone_website->save();
  3051. // var_dump("返回值:",$clone_website->id);
  3052. //克隆网站基础信息 website_template_info website_category
  3053. $resultWebsiteTemplateInfo = WebsiteTemplateInfo::where(['website_id' => $data['website_id']])->first();
  3054. $clone_website_template_info = $resultWebsiteTemplateInfo->replicate();
  3055. $clone_website_template_info->status = 0;
  3056. $clone_website_template_info->action_id = 0;
  3057. $clone_website_template_info->website_id = $clone_website->id;
  3058. $clone_website_template_info->save();
  3059. //克隆网站导航 获取原始 website_id 对应的所有 WebsiteCategory 记录
  3060. $originalCategories = WebsiteCategory::where('website_id', $data['website_id'])->get();
  3061. // 克隆网站后的新 ID(假设 $clone_website->id 已存在)
  3062. $newWebsiteId = $clone_website->id;
  3063. if ($originalCategories && count($originalCategories) > 0) {
  3064. // 遍历每条记录并克隆
  3065. foreach ($originalCategories as $category) {
  3066. // 使用 replicate() 方法创建模型副本(不包含主键)
  3067. $clonedCategory = $category->replicate();
  3068. // 修改外键字段指向新网站 ID
  3069. $clonedCategory->website_id = $newWebsiteId;
  3070. // 保存克隆后的记录到数据库
  3071. $clonedCategory->save();
  3072. }
  3073. }
  3074. //克隆友情链接 Link 对应的是多个
  3075. $originalLinks = Link::where('website_id', $data['website_id'])->get();
  3076. if ($originalLinks && count($originalLinks) > 0) {
  3077. foreach ($originalLinks as $link) {
  3078. // 使用 replicate() 方法创建模型副本(不包含主键)
  3079. $clonedLink = $link->replicate();
  3080. // 修改外键字段指向新网站 ID
  3081. $clonedLink->website_id = $newWebsiteId;
  3082. // 保存克隆后的记录到数据库
  3083. $clonedLink->save();
  3084. }
  3085. }
  3086. //克隆网站底部信息 footer_category 表 和footer_content 表 footer_category.id = footer_content.fcat_id 都是一对多关系
  3087. $originalFooterCategories = FooterCategory::where('website_id', $data['website_id'])->get();
  3088. if ($originalFooterCategories && count($originalFooterCategories) > 0) {
  3089. foreach ($originalFooterCategories as $footerCategory) {
  3090. $clonedFooterCategory = $footerCategory->replicate();
  3091. $clonedFooterCategory->website_id = $newWebsiteId;
  3092. $clonedFooterCategory->save();
  3093. $originalFooterContents = FooterContent::where('fcat_id', $footerCategory->id)->get();
  3094. if ($originalFooterContents && count($originalFooterContents) > 0) {
  3095. foreach ($originalFooterContents as $footerContent) {
  3096. $clonedFooterContent = $footerContent->replicate();
  3097. $clonedFooterContent->fcat_id = $clonedFooterCategory->id;
  3098. $clonedFooterContent->save();
  3099. }
  3100. }
  3101. }
  3102. }
  3103. Db::commit();
  3104. return Result::success([]);
  3105. } catch (\Exception $e) {
  3106. Db::rollBack();
  3107. return Result::error($e->getMessage(), 0);
  3108. }
  3109. }
  3110. /**
  3111. * 更新网站状态
  3112. * @param array $data
  3113. * @return array
  3114. */
  3115. public function updateWebsiteStatus(array $data): array
  3116. {
  3117. try {
  3118. Website::where(["id" => $data['id']])->update(["status" => intval($data['status'])]);
  3119. return Result::success([]);
  3120. } catch (\Exception $e) {
  3121. return Result::error($e->getMessage(), 0);
  3122. }
  3123. }
  3124. /**
  3125. * 删除网站url
  3126. * @param array $data
  3127. * @return array
  3128. */
  3129. public function delWebsiteUrl(array $data): array
  3130. {
  3131. try {
  3132. $wensiteInfo = Website::where(["id" => $data['website_id']])->first();
  3133. if (empty($wensiteInfo)) {
  3134. return Result::error("找不到该网站", 0);
  3135. }
  3136. $websiteUrlArray = [];
  3137. if (!empty($wensiteInfo->website_url)) {
  3138. $decoded = json_decode((string) $wensiteInfo->website_url, true);
  3139. $websiteUrlArray = is_array($decoded) ? $decoded : [];
  3140. }
  3141. // 从数组中按值删除对应的 URL
  3142. $index = array_search($data['website_url'] ?? null, $websiteUrlArray, true);
  3143. if ($index !== false) {
  3144. unset($websiteUrlArray[$index]);
  3145. // 重新索引,保持为连续的 JSON 数组
  3146. $websiteUrlArray = array_values($websiteUrlArray);
  3147. }
  3148. $newWebsiteUrlJson = json_encode($websiteUrlArray, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  3149. Website::where(["id" => $data['website_id']])->update(["website_url" => $newWebsiteUrlJson]);
  3150. return Result::success([]);
  3151. } catch (\Exception $e) {
  3152. return Result::error($e->getMessage(), 0);
  3153. }
  3154. }
  3155. public function checkPath(array $data): array
  3156. {
  3157. var_dump("检查路径");
  3158. // return Result::success([]);
  3159. // website_category查找相同path的数据,返回那些数据重复了
  3160. // 查找所有具有相同path的重复记录
  3161. $duplicatePaths = WebsiteCategory::select('path', DB::raw('COUNT(*) as count'))
  3162. ->where('website_id', $data['website_id'])
  3163. ->groupBy('path')
  3164. ->havingRaw('COUNT(*) > 1')
  3165. ->get();
  3166. if ($duplicatePaths->isEmpty()) {
  3167. return Result::success([]);
  3168. }
  3169. // 获取所有重复记录的详细信息
  3170. $duplicateRecords = [];
  3171. foreach ($duplicatePaths as $duplicatePath) {
  3172. $records = WebsiteCategory::where(['path' => $duplicatePath->path])
  3173. ->where('website_id', $data['website_id'])
  3174. ->orderBy('id')
  3175. ->get();
  3176. $duplicateRecords[] = [
  3177. 'path' => $duplicatePath->path,
  3178. 'count' => $duplicatePath->count,
  3179. 'records' => $records
  3180. ];
  3181. }
  3182. return Result::success($duplicateRecords);
  3183. }
  3184. /**
  3185. * 获取栏目
  3186. * @param array $data
  3187. * @return array
  3188. */
  3189. public function getWebsiteModelCategory(array $data): array
  3190. {
  3191. // return Result::success($data);
  3192. $website_id = [
  3193. 'website_id' => $data['website_id'],
  3194. ];
  3195. $website_column_arr = Website::where('id', $data['website_id'])->value('website_column_arr_id');
  3196. if (empty($website_column_arr)) {
  3197. return Result::error("未查询到此网站所属网系!", 0);
  3198. }
  3199. $website_column_arr = json_decode($website_column_arr, true);
  3200. // return Result::success(!in_array(3,$website_column_arr) && $data['pid'] == 0);
  3201. // 初始化 $pid 数组
  3202. // $pid = [];
  3203. // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
  3204. $pidQuery = WebsiteCategory::where($website_id)
  3205. ->where('pid', '!=', 0)
  3206. ->orderBy('sort')
  3207. ->select('pid', 'category_id', 'alias', 'aLIas_pinyin');
  3208. $pid = $pidQuery->pluck('pid');
  3209. $pid = array_values(array_unique($pid->toArray()));
  3210. // 构建查询语句
  3211. $query = WebsiteCategory::where($website_id)
  3212. ->when(!in_array(3, $website_column_arr) && $data['pid'] == 0, function ($query) use ($website_column_arr) {
  3213. $query->where('is_show', 1);
  3214. })
  3215. ->when(in_array(3, $website_column_arr) || $data['pid'] != 0, function ($query) use ($data) {
  3216. $query->where('pid', $data['pid']);
  3217. })
  3218. ->offset($data['placeid'])
  3219. ->limit($data['num'])
  3220. ->orderBy('sort')
  3221. ->orderBy('updated_at', 'desc');
  3222. // 如果 $pid 数组不为空,添加 CASE WHEN 条件
  3223. if (!empty($pid)) {
  3224. $placeholders = implode(',', array_fill(0, count($pid), '?'));
  3225. $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
  3226. } else {
  3227. // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
  3228. $query->select('website_category.*', DB::raw('0 as children_count'));
  3229. }
  3230. // 执行查询
  3231. $placeid = $data['placeid'] - 1;
  3232. $result = $query->offset($placeid)->limit($data['num'])->get();
  3233. if (!empty($result)) {
  3234. $pidResults = $pidQuery->get();
  3235. if (isset($data['type']) && $data['type'] == 1) {
  3236. $result = $result->map(function ($item) use ($pidResults) {
  3237. $children = $pidResults->where('pid', $item->category_id)->map(function ($child) {
  3238. if (!empty($child)) {
  3239. return $child;
  3240. }
  3241. });
  3242. // 重置索引,使 key 值从 0 开始
  3243. $item->children = $children->values();
  3244. return $item;
  3245. });
  3246. } else {
  3247. $pidMap = $pidResults->keyBy('pid');
  3248. $result->each(function ($record) use ($pidMap, $data) {
  3249. if ($data['pid'] == 0) {
  3250. $record->aLIas_pinyin = $record->path;
  3251. }
  3252. // $record->aLIas_pinyin = $record->path;
  3253. if ($pidMap->has($record->category_id)) {
  3254. $pidResult = $pidMap->get($record->category_id);
  3255. $record->chilid_id = $pidResult->category_id;
  3256. $record->chilid_alias = $pidResult->alias;
  3257. // $record->aLIas_pinyin = $pidResult->aLIas_pinyin;
  3258. }
  3259. });
  3260. }
  3261. return Result::success($result);
  3262. } else {
  3263. return Result::error("本网站暂无栏目", 0);
  3264. }
  3265. }
  3266. /**
  3267. * 获取网站栏目信息
  3268. * @param array $data
  3269. */
  3270. public function getWebsiteFootAll(array $data): array
  3271. {
  3272. if(!isset($data['is_diyweb']) || empty($data['is_diyweb'])){
  3273. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  3274. }else{
  3275. $website = Website::where('id',$data['website_id'])->first();
  3276. }
  3277. if (empty($website)) {
  3278. return Result::error("暂无该网站", 0);
  3279. }
  3280. // 1:图片 2:文字 3:底部
  3281. $result['foot_cate'] = FooterCategory::where('website_id', $data['website_id'])->get()->all();
  3282. $result['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  3283. $result['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  3284. $result['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  3285. $result['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  3286. if (empty($result)) {
  3287. return Result::error("暂无此网站信息", 0);
  3288. }
  3289. return Result::success($result);
  3290. }
  3291. }