WebsiteService.php 131 KB

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