WebsiteService.php 139 KB

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