WebsiteService_BACKUP_1335.php 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799
  1. <<<<<<< HEAD
  2. <?php
  3. namespace App\JsonRpc;
  4. use App\Model\Article;
  5. use App\Model\Category;
  6. use App\Model\FooterCategory;
  7. use App\Model\FooterContent;
  8. use App\Model\LetterOfComplaint;
  9. use App\Model\Sector;
  10. use App\Model\TemplateClass;
  11. use App\Model\Template;
  12. use App\Model\User;
  13. use App\Model\WebsiteRole;
  14. use App\Model\WebsiteRoleUser;
  15. use App\Model\Website;
  16. use App\Model\WebsiteColumn;
  17. use App\Model\WebsiteTemplate;
  18. use Hyperf\DbConnection\Db;
  19. use Hyperf\RpcServer\Annotation\RpcService;
  20. use App\Tools\Result;
  21. use App\Model\WebsiteCategory;
  22. use App\Model\WebsiteTemplateInfo;
  23. use function PHPUnit\Framework\isNull;
  24. use App\Model\Component;
  25. use App\Model\District;
  26. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  27. class WebsiteService implements WebsiteServiceInterface
  28. {
  29. /**
  30. * @param string $keyword
  31. * @param int $page
  32. * @param int $pageSize
  33. * @return array
  34. */
  35. public function getWebsitetList(array $data): array
  36. {
  37. $resultWwhere = Website::when($data,function ($query) use ($data){
  38. if(isset($data['keyword']) && !empty($data['keyword'])){
  39. $query->where('website.website_name','like','%'.$data['keyword'].'%');
  40. }
  41. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  42. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  43. }
  44. if(isset($data['city_id']) && !empty($data['city_id'])){
  45. $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
  46. }
  47. });
  48. $result = $resultWwhere->leftJoin("website_column","website.website_column_id","website_column.id")
  49. ->leftJoin("district","district.id","website.city_id")
  50. ->select("website.*","website_column.column_name","district.name as city_name")
  51. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("website.id","desc")->get();
  52. $count = $resultWwhere->count();
  53. if (empty($result)) {
  54. return Result::error("没有数据",0);
  55. }
  56. $data = [
  57. 'rows'=>$result->toArray(),
  58. 'count'=>$count
  59. ];
  60. return Result::success($data);
  61. }
  62. /**
  63. * @param array $data
  64. * @return array
  65. */
  66. public function createWebsite(array $data): array
  67. {
  68. var_dump("网站数据:", $data);
  69. $insertData = [
  70. 'website_name' => $data['website_name'],
  71. 'logo' => $data['logo'] ?? '',
  72. 'website_url' => $data['website_url'] ?? '',
  73. 'city_id' => $data['city_id'] ?? 0,
  74. 'website_column_id' => $data['website_column_id'],
  75. 'title' => $data['title'] ?? '',
  76. 'keywords' => $data['keywords'] ?? '',
  77. 'description' => $data['description'] ?? '',
  78. 'status' => $data['status'] ?? 0,
  79. 'website_column_arr_id' => $data['website_column_arr_id'],
  80. 'city_arr_id' => $data['city_arr_id'] ?? [0],
  81. 'template_id' => $data['template_id'] ?? 0,
  82. ];
  83. $result = Website::insertGetId($insertData);
  84. if (empty($result)) {
  85. return Result::error("创建失败", 0);
  86. } else {
  87. return Result::success(["id" => $result]);
  88. }
  89. }
  90. /**
  91. * @param int $id
  92. * @param array $data
  93. * @return array
  94. */
  95. public function updateWebsite(int $id, array $data): array
  96. {
  97. $insertData = [
  98. 'website_name' => $data['website_name'],
  99. 'logo' => $data['logo'] ?? '',
  100. 'website_url' => $data['website_url'] ?? '',
  101. 'city_id' => $data['city_id'] ?? 0,
  102. 'website_column_id' => $data['website_column_id'],
  103. 'title' => $data['title'] ?? '',
  104. 'keywords' => $data['keywords'] ?? '',
  105. 'description' => $data['description'] ?? '',
  106. 'status' => $data['status'] ?? 0,
  107. 'website_column_arr_id' => $data['website_column_arr_id'],
  108. 'city_arr_id' => $data['city_arr_id'] ?? [0],
  109. 'template_id' => $data['template_id'] ?? 0,
  110. ];
  111. $result = Website::where('id', $id)->update($insertData);
  112. var_dump("更新站点", $result);
  113. if (empty($result)) {
  114. return Result::error("更新失败", 0);
  115. } else {
  116. return Result::success();
  117. }
  118. }
  119. /**
  120. * @param int $id
  121. * @return array
  122. */
  123. public function delWebsite(int $id): array
  124. {
  125. $result = Website::where('id', $id)->delete();
  126. if (empty($result)) {
  127. return Result::error("删除失败", 0);
  128. } else {
  129. return Result::success();
  130. }
  131. }
  132. /**
  133. * @param int $id
  134. * @return array
  135. */
  136. public function getWebsiteInfo(int $id): array
  137. {
  138. $where = [
  139. ['website.id', '=', $id]
  140. ];
  141. $result = Website::where($where)
  142. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  143. ->select("website.*",
  144. "website_template_info.template_id",
  145. "website_template_info.page_type",
  146. "website_template_info.statement",
  147. "website_template_info.organizer",
  148. "website_template_info.copyright_information",
  149. "website_template_info.contact_number",
  150. "website_template_info.company_address",
  151. "website_template_info.project_logo",
  152. "website_template_info.project_name",
  153. "website_template_info.project_url",
  154. "website_template_info.company_logo",
  155. "website_template_info.company_name",
  156. "website_template_info.company_url",
  157. "website_template_info.record_number",
  158. "website_template_info.record_number_url",
  159. "website_template_info.icp_number",
  160. "website_template_info.icp_number_url",
  161. "website_template_info.customer_service_qq",
  162. "website_template_info.communications",
  163. "website_template_info.status",
  164. )
  165. ->first();
  166. if (empty($result)) {
  167. return Result::error("数据不存在", 0);
  168. } else {
  169. return Result::success($result->toArray());
  170. }
  171. }
  172. /**
  173. * 查询所有的站点栏目
  174. * @return array
  175. */
  176. public function getWebsiteColumn(array $data): array
  177. {
  178. $result = WebsiteColumn::where($data)->get();
  179. if (empty($result)) {
  180. return Result::error("数据不存在", 0);
  181. } else {
  182. return Result::success($result->toArray());
  183. }
  184. }
  185. /**
  186. * @param string $keyword
  187. * @param int $page
  188. * @param int $pageSize
  189. * @return array
  190. */
  191. public function getWebsiteColumnList(array $data): array
  192. {
  193. $where = [];
  194. if (isset($data['keyword']) && $data['keyword']) {
  195. array_push($where, ['website_column.column_name', 'like', '%' . $data['keyword'] . '%']);
  196. }
  197. $result = WebsiteColumn::where($where)
  198. ->leftJoin("website_column as wc", "website_column.pid", "wc.id")
  199. ->select("website_column.*", "wc.column_name as parent_column_name")
  200. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
  201. $count = WebsiteColumn::where($where)->count();
  202. if (empty($result)) {
  203. return Result::error("没有数据", 0);
  204. }
  205. $data = [
  206. 'rows' => $result->toArray(),
  207. 'count' => $count
  208. ];
  209. return Result::success($data);
  210. }
  211. /**
  212. * @param array $data
  213. * @return array
  214. */
  215. public function createWebsiteColumn(array $data): array
  216. {
  217. $insertData = [
  218. 'column_name' => $data['column_name'],
  219. 'pid' => $data['pid'] ?? '',
  220. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  221. 'sort' => $data['sort'] ?? 0,
  222. 'remark' => $data['remark'] ?? '',
  223. ];
  224. $result = WebsiteColumn::insertGetId($insertData);
  225. if (empty($result)) {
  226. return Result::error("创建失败", 0);
  227. } else {
  228. return Result::success(["id" => $result]);
  229. }
  230. }
  231. /**
  232. * @param int $id
  233. * @param array $data
  234. * @return array
  235. */
  236. public function updateWebsiteColumn(int $id, array $data): array
  237. {
  238. $insertData = [
  239. 'column_name' => $data['column_name'],
  240. 'pid' => $data['pid'] ?? '',
  241. 'column_arr_id' => $data['column_arr_id'] ?? [0],
  242. 'sort' => $data['sort'] ?? 0,
  243. 'remark' => $data['remark'] ?? '',
  244. ];
  245. $result = WebsiteColumn::where('id', $id)->update($insertData);
  246. if (empty($result)) {
  247. return Result::error("更新失败", 0);
  248. } else {
  249. return Result::success();
  250. }
  251. }
  252. /**
  253. * @param int $id
  254. * @return array
  255. */
  256. public function delWebsiteColumn(int $id): array
  257. {
  258. $list = WebsiteColumn::where(['pid' => $id])->get();
  259. if ($list) {
  260. return Result::error("存在子网系,不能删除,请先删除子网系", 0);
  261. }
  262. $result = WebsiteColumn::where('id', $id)->delete();
  263. if (empty($result)) {
  264. return Result::error("删除失败", 0);
  265. } else {
  266. return Result::success();
  267. }
  268. }
  269. /**
  270. * @param string $keyword
  271. * @param int $page
  272. * @param int $pageSize
  273. * @return array
  274. */
  275. public function getWebsiteRoleList(string $keyword, int $page, int $pageSize, int $websiteId): array
  276. {
  277. $where = [
  278. ['role.role_name', 'like', '%' . $keyword . '%'],
  279. ['website_role.website_id', '=', $websiteId],
  280. ];
  281. $result = WebsiteRole::where($where)
  282. ->leftJoin("role", "role.id", "website_role.role_id")
  283. ->select("role.*", "website_role.type", "website_role.role_id", "website_role.id as website_role_id", "website_role.website_id")
  284. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  285. $count = WebsiteRole::where($where)->leftJoin("role", "role.id", "website_role.role_id")->count();
  286. if (empty($result)) {
  287. return Result::error("没有数据", 0);
  288. }
  289. $data = [
  290. 'rows' => $result->toArray(),
  291. 'count' => $count
  292. ];
  293. return Result::success($data);
  294. }
  295. /**
  296. * @param array $data
  297. * @return array
  298. */
  299. public function createWebsiteRole(array $data): array
  300. {
  301. $insertData = [
  302. 'website_id' => $data['website_id'],
  303. 'role_id' => $data['role_id'] ?? ''
  304. ];
  305. $info = WebsiteRole::where($insertData)->first();
  306. if ($info) {
  307. return Result::error("不能重复添加角色", 0);
  308. }
  309. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  310. $insertData['type'] = $data['type'] ?? '';
  311. $result = WebsiteRole::insertGetId($insertData);
  312. if (empty($result)) {
  313. return Result::error("创建失败", 0);
  314. } else {
  315. return Result::success(["id" => $result]);
  316. }
  317. }
  318. /**
  319. * 暂时用不上
  320. * @param int $id
  321. * @param array $data
  322. * @return array
  323. */
  324. public function updateWebsiteRole(int $id, array $data): array
  325. {
  326. $insertData = [
  327. 'website_id' => $data['website_id'],
  328. 'type' => $data['type'] ?? '',
  329. ];
  330. $result = WebsiteRole::where('id', $id)->update($insertData);
  331. if (empty($result)) {
  332. return Result::error("更新失败", 0);
  333. } else {
  334. return Result::success();
  335. }
  336. }
  337. /**
  338. * @param int $id
  339. * @return array
  340. */
  341. public function delWebsiteRole(int $id): array
  342. {
  343. $result = WebsiteRole::where('id', $id)->delete();
  344. if (empty($result)) {
  345. return Result::error("删除失败", 0);
  346. } else {
  347. return Result::success();
  348. }
  349. }
  350. /**
  351. * @param string $keyword
  352. * @param int $page
  353. * @param int $pageSize
  354. * @return array
  355. */
  356. public function getWebsiteRoleUserList(string $keyword, int $page, int $pageSize, int $websiteId, int $roleId): array
  357. {
  358. $where = [
  359. ['website_role_user.website_id', '=', $websiteId],
  360. ['website_role_user.role_id', '=', $roleId],
  361. ];
  362. $count = WebsiteRoleUser::where($where)->count();
  363. $where[] = ['u.user_name', 'like', '%' . $keyword . '%'];
  364. $result = WebsiteRoleUser::where($where)
  365. ->leftJoin("user as u", "website_role_user.user_id", "u.id")
  366. ->leftJoin("website as w", "website_role_user.website_id", "u.id")
  367. ->leftJoin("role as r", "website_role_user.role_id", "r.id")
  368. ->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')
  369. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  370. if (empty($result)) {
  371. return Result::error("没有数据", 0);
  372. }
  373. $data = [
  374. 'rows' => $result->toArray(),
  375. 'count' => $count
  376. ];
  377. return Result::success($data);
  378. }
  379. /**
  380. * @param array $data
  381. * @return array
  382. */
  383. public function createWebsiteRoleUser(array $data): array
  384. {
  385. $insertData = [
  386. 'website_id' => $data['website_id'],
  387. 'user_id' => $data['user_id'] ?? '',
  388. ];
  389. $info = WebsiteRoleUser::where($insertData)->first();
  390. if ($info) {
  391. return Result::error("不能重复添加角色用户", 0);
  392. }
  393. $insertData['role_id'] = $data['role_id'] ?? '';
  394. $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
  395. $insertData['type'] = $data['type'] ?? '';
  396. $result = WebsiteRoleUser::insertGetId($insertData);
  397. if (empty($result)) {
  398. return Result::error("创建失败", 0);
  399. } else {
  400. return Result::success(["id" => $result]);
  401. }
  402. }
  403. /**
  404. * @param int $id
  405. * @param array $data
  406. * @return array
  407. */
  408. public function updateWebsiteRoleUser(int $id, array $data): array
  409. {
  410. $insertData = [
  411. 'website_id' => $data['website_id'],
  412. 'type' => $data['type'] ?? '',
  413. 'type_id' => $data['type_id'] ?? '',
  414. 'role_id' => $data['role_id'] ?? '',
  415. ];
  416. $result = WebsiteRoleUser::where('id', $id)->update($insertData);
  417. if (empty($result)) {
  418. return Result::error("更新失败", 0);
  419. } else {
  420. return Result::success();
  421. }
  422. }
  423. /**
  424. * @param int $id
  425. * @return array
  426. */
  427. public function delWebsiteRoleUser(int $id): array
  428. {
  429. $result = WebsiteRoleUser::where('id', $id)->delete();
  430. if (empty($result)) {
  431. return Result::error("删除失败", 0);
  432. } else {
  433. return Result::success();
  434. }
  435. }
  436. /**
  437. * 根据域名获取网站 站点id
  438. * @param array $data
  439. * @return array
  440. */
  441. public function getWebsiteId(array $data): array
  442. {
  443. $result = Website::whereJsonContains('website_url', $data['website_url'])->first();
  444. if (empty($result)) {
  445. return Result::error("查询站点失败", 0);
  446. } else {
  447. return Result::success($result);
  448. }
  449. }
  450. /**
  451. * 查询网站下面的导航
  452. * @param array $data
  453. * @return array
  454. */
  455. public function getWebsiteCategory(array $data): array
  456. {
  457. $where = [
  458. 'website_id' => $data['website_id'],
  459. 'pid' => 0
  460. ];
  461. $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
  462. if (empty($result)) {
  463. return Result::error("查询站点栏目失败", 0);
  464. } else {
  465. return Result::success($result);
  466. }
  467. }
  468. /**
  469. * 查询网站的广告
  470. * @param array $data
  471. * @return array
  472. */
  473. public function getWebsiteAdvertisement(array $data): array
  474. {
  475. $where = [
  476. 'website_id' => $data['website_id'],
  477. 'id' => $data['ad_placeid']
  478. ];
  479. $ad_place = AdPlace::where($where)->orderBy('id', 'asc')->limit(1)->get();
  480. $today = Carbon::now();
  481. if (empty($ad_place)) {
  482. return Result::error("error", 0);
  483. } else {
  484. foreach ($ad_place as $val) {
  485. $adplaceid = $val;
  486. }
  487. $ad = Ad::where('pid', $adplaceid['id'])->where('status', 1)->orderBy('id', 'asc')->get();
  488. if (empty($ad)) {
  489. $result = $adplaceid;
  490. return Result::success($result);
  491. } else {
  492. foreach ($ad as $i) {
  493. $starttime = Carbon::parse($i['fromtime']);
  494. $endtime = Carbon::parse($i['totime']);
  495. $time = $today->between($starttime, $endtime);
  496. if ($time) {
  497. $result = $i;
  498. }
  499. }
  500. if (empty($result)) {
  501. $result = $ad;
  502. return Result::success($result);
  503. } else {
  504. return Result::success($result);
  505. }
  506. }
  507. }
  508. }
  509. /**
  510. * 网站行政职能搜索
  511. * @param array $data
  512. * @return array
  513. */
  514. public function selectWebsiteDepartment(array $data): array
  515. {
  516. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->limit(10)->get();
  517. if (isset($data['keyword']) && !empty($data['keyword'])) {
  518. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  519. if (empty($departments)) {
  520. $result['message'] = "未查询到与此相关职能部门";
  521. } else {
  522. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  523. $m = [
  524. 'department' => $depart,
  525. 'type' => $departments,
  526. 'count' => $count
  527. ];
  528. }
  529. $result['sele'] = $m;
  530. return Result::success($result['sele']);
  531. }
  532. $result = $depart;
  533. return Result::success($result['data']);
  534. }
  535. /**
  536. * 搜索地区
  537. */
  538. public function selectWebsiteArea(array $data): array
  539. {
  540. $provinces = District::where('pid', 0)->where('status', 1)->get();
  541. if (isset($data['province'])) {
  542. $province = District::where('pid', 0)->where('status', 1)->where('id', $data['province'])->orderBy('id')->get();
  543. $province = $province->toArray();
  544. if (!empty($province)) {
  545. $citys = District::where('pid', $data['province'])->where('status', 1)->orderBy('id')->get();
  546. if (!empty($citys) && isset($data['city']) && !empty($data['city'])) {
  547. // $province = $province->toArray();
  548. $province_id = [];
  549. foreach ($province as $val) {
  550. array_push($province_id, $val['id']);
  551. }
  552. // var_dump($province_id);
  553. $city = District::whereIn('pid', $province_id)->where('status', 1)->where('id', $data['city'])->orderBy('id')->get();
  554. if (!empty($city)) {
  555. $city_id = [];
  556. foreach ($city as $val) {
  557. array_push($city_id, $val['id']);
  558. }
  559. $regions = District::whereIn('pid', $city_id)->where('status', 1)->orderBy('id')->get();
  560. $result = [
  561. 'province' => $province,
  562. 'city' => $city,
  563. 'region' => $regions
  564. ];
  565. } else {
  566. return Result::error("未查询到此城市", 0);
  567. }
  568. } else {
  569. $result = [
  570. 'province' => $province,
  571. 'city' => $citys,
  572. 'region' => null
  573. ];
  574. }
  575. } else {
  576. return Result::error("未查询到此省份", 0);
  577. }
  578. } else {
  579. // $keys = array('data');
  580. $result = $provinces;
  581. }
  582. return Result::success($result);
  583. }
  584. /**
  585. * 获取栏目
  586. * @param array $data
  587. * @return array
  588. */
  589. public function getWebsiteModelCategory(array $data): array
  590. {
  591. $website_id = [
  592. 'website_id' => $data['website_id']
  593. ];
  594. $placeid = $data['placeid'] - 1;
  595. $pid = [
  596. 'pid' => $data['pid'],
  597. ];
  598. $num = $data['num'];
  599. $result = WebsiteCategory::where($website_id)->where($pid)->orderBy('sort')->offset($placeid)->limit($num)->get();
  600. $result = $result->toArray();
  601. if (!empty($result)) {
  602. return Result::success($result);
  603. } else {
  604. return Result::error("本网站暂无栏目", 0);
  605. }
  606. }
  607. /**
  608. *获取友情链接
  609. * @param array $data
  610. * @return array
  611. */
  612. public function selectWebsiteLinks(array $data): array
  613. {
  614. $where = [
  615. 'website_id' => $data['website_id'],
  616. 'status' => 1,
  617. 'type' => $data['type']
  618. ];
  619. $num=$data['num'];
  620. $result=Link::where($where)->orderBy('id')->limit($num)->get();
  621. if(!empty($result)){
  622. return Result::success($result);
  623. }else{
  624. return Result::error("本网站暂无此类型友情链接",0);
  625. }
  626. }
  627. /**
  628. * 网站首页数据统计, 管理员
  629. * @return void
  630. */
  631. public function getAdminIndex(array $data): array
  632. {
  633. var_dump("用户类型:", $data['type_id']);
  634. switch ($data['type_id']) {
  635. case 4:
  636. $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;');
  637. return Result::success($result);
  638. break;
  639. case 10000:
  640. $res = [];
  641. //网站
  642. $res['website']['count'] = 0;
  643. $res['website']['growth_rate'] = 0;
  644. //资讯
  645. $res['article']['count'] = 0;
  646. $res['article']['growth_rate'] = 0;
  647. //导航池
  648. $res['category']['count'] = 0;
  649. $res['category']['growth_rate'] = 0;
  650. //近一月数据
  651. $res['monthArticle'] = [];
  652. //用户类型
  653. $res['userType'] = [];
  654. $res['website']['count'] = Website::where([])->count();
  655. $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
  656. $res['category']['count'] = Category::where([])->count();
  657. $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;');
  658. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  659. return Result::success($res);
  660. }
  661. return [];
  662. }
  663. /**
  664. * 获取模板类型
  665. * @return void
  666. */
  667. public function getTemplateClass(array $data): array
  668. {
  669. $where = [];
  670. if (isset($data['name']) && $data['name']) {
  671. array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
  672. }
  673. $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
  674. if (empty($result)) {
  675. return Result::error("没有模板类型", 0);
  676. } else {
  677. return Result::success($result);
  678. }
  679. }
  680. /**
  681. * 添加模板类型
  682. * @param
  683. * @return void
  684. */
  685. public function addTemplateClass(array $data): array
  686. {
  687. $insertData = [
  688. 'name' => $data['name']
  689. ];
  690. $result = TemplateClass::insertGetId($insertData);
  691. if (empty($result)) {
  692. return Result::error("创建失败", 0);
  693. } else {
  694. return Result::success(["id" => $result]);
  695. }
  696. }
  697. /**
  698. * 更新模板
  699. * @param array $data
  700. * @return array
  701. */
  702. public function upTemplateClass(array $data): array
  703. {
  704. $where = [
  705. 'id' => $data['id']
  706. ];
  707. $insertData = [
  708. 'name' => $data['name']
  709. ];
  710. $result = TemplateClass::where($where)->update($insertData);
  711. if (empty($result)) {
  712. return Result::error("更新失败", 0);
  713. } else {
  714. return Result::success();
  715. }
  716. }
  717. /**
  718. * 删除模板
  719. * @param array $data
  720. * @return array
  721. */
  722. public function delTemplateClass(array $data): array
  723. {
  724. $where = [
  725. 'id' => $data['id']
  726. ];
  727. $result = TemplateClass::where($where)->delete();
  728. if (empty($result)) {
  729. return Result::error("删除失败", 0);
  730. } else {
  731. return Result::success();
  732. }
  733. }
  734. /**
  735. * 获取分类下的模板
  736. * @param array $data
  737. * @return array
  738. */
  739. public function getTemplate(array $data): array
  740. {
  741. $page = $data['page'];
  742. $pageSize = $data['pageSize'];
  743. $where = [];
  744. if (isset($data['template_class_id']) && $data['template_class_id']) {
  745. array_push($where, ['template_class_id', '=', $data['template_class_id']]);
  746. }
  747. $result = Template::where($where)
  748. ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
  749. $count = Template::where($where)->count();
  750. if (empty($result)) {
  751. return Result::error("没有数据", 0);
  752. }
  753. $data = [
  754. 'rows' => $result->toArray(),
  755. 'count' => $count
  756. ];
  757. return Result::success($data);
  758. }
  759. /**
  760. * 创建模板
  761. * @param
  762. * @return void
  763. */
  764. public function addTemplate(array $data): array
  765. {
  766. $insertData = [
  767. 'template_name' => $data['template_name'],
  768. 'template_img' => json_encode($data['template_img']),
  769. 'template_class_id' => $data['template_class_id'],
  770. ];
  771. $result = Template::insertGetId($insertData);
  772. if (empty($result)) {
  773. return Result::error("创建模板失败", 0);
  774. } else {
  775. return Result::success(["id" => $result]);
  776. }
  777. }
  778. /**
  779. * 更新模板
  780. * @param array $data
  781. * @return array
  782. */
  783. public function upTemplate(array $data): array
  784. {
  785. $where = [
  786. 'id' => $data['id']
  787. ];
  788. $insertData = [
  789. 'template_name' => $data['template_name'],
  790. 'template_img' => json_encode($data['template_img']),
  791. 'template_class_id' => $data['template_class_id'],
  792. ];
  793. $result = Template::where($where)->update($insertData);
  794. if (empty($result)) {
  795. return Result::error("更新模板失败", 0);
  796. } else {
  797. return Result::success();
  798. }
  799. }
  800. /**
  801. * 删除模板
  802. * @param array $data
  803. * @return array
  804. */
  805. public function delTemplate(array $data): array
  806. {
  807. $where = [
  808. 'id' => $data['id']
  809. ];
  810. $result = Template::where($where)->delete();
  811. if (empty($result)) {
  812. return Result::error("删除模板失败", 0);
  813. } else {
  814. return Result::success();
  815. }
  816. }
  817. /**
  818. * 搜索网站
  819. * @param array $data
  820. * @return array
  821. */
  822. public function websiteList(array $data): array
  823. {
  824. $where = [];
  825. if (isset($data['keyword']) && !empty($data['keyword'])) {
  826. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  827. }
  828. $result = Website::where($where)->get();
  829. if ($result) {
  830. return Result::success($result);
  831. } else {
  832. return Result::error("没有网站", 0);
  833. }
  834. }
  835. public function addWebsiteCategory(array $data): array
  836. {
  837. $website_id = $data['website_id'];
  838. $category_arr_id = $data['category_arr_id'];
  839. $categoryList = Category::whereIn('id', $category_arr_id)->get();
  840. $categoryListIds = [];
  841. if ($categoryList) {
  842. foreach ($categoryList->toArray() as $val) {
  843. array_push($categoryListIds, $val['id']);
  844. }
  845. }
  846. $arr = [];
  847. if ($categoryListIds) {
  848. foreach ($categoryListIds as $v) {
  849. $ids = $this->getUnderlingUIds(intval($v));
  850. $ids_arr = explode(",", $ids);
  851. array_push($arr, $ids_arr);
  852. }
  853. }
  854. $mergedArray = [];
  855. foreach ($arr as $subarray) {
  856. $mergedArray = array_merge($mergedArray, $subarray);
  857. }
  858. var_dump("所有:", $arr, $mergedArray);
  859. //查询出所有的分类进行分割插入 组装数据
  860. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  861. $categoryListData = $categoryListData->toArray();
  862. $insertData = [];
  863. if ($categoryListData) {
  864. foreach ($categoryListData as $key => $value) {
  865. $insertData[$key]['website_id'] = $website_id;
  866. $insertData[$key]['name'] = $value['name'];
  867. $insertData[$key]['sort'] = $value['sort'];
  868. $insertData[$key]['pid'] = $value['pid'];
  869. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  870. $insertData[$key]['seo_title'] = $value['seo_title'];
  871. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  872. $insertData[$key]['seo_description'] = $value['seo_description'];
  873. $insertData[$key]['alias'] = $value['name'];
  874. $insertData[$key]['category_id'] = $value['id'];
  875. }
  876. }
  877. $result = WebsiteCategory::insert($insertData);
  878. var_dump("插入数据状态:", $result);
  879. if ($result) {
  880. return Result::success($result);
  881. } else {
  882. return Result::error("创建失败", 0);
  883. }
  884. }
  885. /**
  886. * 删除网站导航
  887. * @param array $data
  888. * @return array
  889. */
  890. public function delWebsiteCategory(array $data): array
  891. {
  892. $website_id = $data['website_id'] ?? 0;
  893. $category_id = $data['category_id'] ?? 0;
  894. $ids = $this->getUnderlingUIds(intval($category_id));
  895. $ids_arr = explode(",", $ids);
  896. $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
  897. if ($result) {
  898. return Result::success($result);
  899. } else {
  900. return Result::error("删除失败", 0);
  901. }
  902. }
  903. /**
  904. * 获取网站导航
  905. * @param array $data
  906. * @return array
  907. */
  908. public function getAdminWebsiteCategory(array $data): array
  909. {
  910. $where = [
  911. 'website_id' => $data['website_id'],
  912. 'pid' => 0
  913. ];
  914. $result = WebsiteCategory::where($where)->get();
  915. if ($result) {
  916. return Result::success($result);
  917. } else {
  918. return Result::error("查询失败", 0);
  919. }
  920. }
  921. /**
  922. * 更新网站导航
  923. * @param array $data
  924. * @return array
  925. */
  926. public function upWebsiteCategory(array $data): array
  927. {
  928. Db::beginTransaction();
  929. try {
  930. //合并栏目id
  931. $reqIds = array_merge($data['old_category_arr_id'], $data['new_category_arr_id']);
  932. //对比old 数组差异化,把差异化的删除
  933. $result = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])->get();
  934. $result = $result->toArray();
  935. $categoryIds = [];
  936. if ($result) {
  937. foreach ($result as $val) {
  938. array_push($categoryIds, $val['category_id']);
  939. }
  940. }
  941. //和原始数据对比取交际
  942. $reqidsIntersect = array_intersect($reqIds, $categoryIds);
  943. //再取差集 进行对比
  944. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds), array_diff($categoryIds, $reqidsIntersect));
  945. var_dump("差集:", $differenceIDS);
  946. $arr_ids = [];
  947. if (count($differenceIDS) > 0) {
  948. foreach ($differenceIDS as $vv) {
  949. $idV = $this->getUnderlingUIds(intval($vv));
  950. $ids_arrV = explode(",", $idV);
  951. array_push($arr_ids, $ids_arrV);
  952. }
  953. }
  954. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  955. //有差异 删除
  956. if (count($del_ids) > 0) {
  957. WebsiteCategory::where(['website_id' => $data['website_id']])->whereIn("category_id", $del_ids)->delete();
  958. }
  959. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  960. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect), array_diff($reqidsIntersect, $reqIds));
  961. var_dump("要存储的:", $insertIDS);
  962. //新的数组重新创建
  963. if (count($insertIDS) > 0) {
  964. $arr = [];
  965. $categoryListIds = $insertIDS;
  966. if ($categoryListIds) {
  967. foreach ($categoryListIds as $v) {
  968. $ids = $this->getUnderlingUIds(intval($v));
  969. $ids_arr = explode(",", $ids);
  970. array_push($arr, $ids_arr);
  971. }
  972. }
  973. $mergedArray = [];
  974. foreach ($arr as $subarray) {
  975. $mergedArray = array_merge($mergedArray, $subarray);
  976. }
  977. var_dump("要插入的ID:", $mergedArray);
  978. //查询出所有的分类进行分割插入 组装数据
  979. $categoryListData = Category::whereIn('id', $mergedArray)->get();
  980. $categoryListData = $categoryListData->toArray();
  981. $insertData = [];
  982. if ($categoryListData) {
  983. foreach ($categoryListData as $key => $value) {
  984. $insertData[$key]['website_id'] = $data['website_id'];
  985. $insertData[$key]['name'] = $value['name'];
  986. $insertData[$key]['sort'] = $value['sort'];
  987. $insertData[$key]['pid'] = $value['pid'];
  988. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  989. $insertData[$key]['seo_title'] = $value['seo_title'];
  990. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  991. $insertData[$key]['seo_description'] = $value['seo_description'];
  992. $insertData[$key]['alias'] = $value['name'];
  993. $insertData[$key]['category_id'] = $value['id'];
  994. }
  995. }
  996. WebsiteCategory::insert($insertData);
  997. }
  998. Db::commit();
  999. } catch (\Throwable $ex) {
  1000. Db::rollBack();
  1001. var_dump($ex->getMessage());
  1002. return Result::error("修改失败", 0);
  1003. }
  1004. return Result::success();
  1005. }
  1006. /**
  1007. * 获取网站列表
  1008. * @param array $data
  1009. * @return array
  1010. */
  1011. public function getWebsiteCategoryList(array $data): array
  1012. {
  1013. $where = [];
  1014. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1015. array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
  1016. }
  1017. if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
  1018. array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
  1019. }
  1020. $result = Website::where($where)
  1021. ->with(["websiteCategory" => function ($query) {
  1022. $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
  1023. }])
  1024. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1025. ->get();
  1026. $count = Website::where($where)->count();
  1027. if (empty($result)) {
  1028. return Result::error("没有数据", 0);
  1029. }
  1030. $data = [
  1031. 'rows' => $result->toArray(),
  1032. 'count' => $count
  1033. ];
  1034. if ($result) {
  1035. return Result::success($data);
  1036. } else {
  1037. return Result::error("查询失败", 0);
  1038. }
  1039. }
  1040. /**
  1041. * 删除网站下的所有导航
  1042. * @param array $data
  1043. * @return array
  1044. */
  1045. public function delWebsiteAllCategory(array $data): array
  1046. {
  1047. $website_id = $data['website_id'];
  1048. $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
  1049. if ($result) {
  1050. return Result::success($result);
  1051. } else {
  1052. return Result::error("删除失败", 0);
  1053. }
  1054. }
  1055. /**
  1056. * 获取网站下的某一个导航
  1057. * @param array $data
  1058. * @return array
  1059. */
  1060. public function getWebsiteCategoryOnes(array $data): array
  1061. {
  1062. $website_id = $data['website_id'];
  1063. $category_id = $data['category_id'];
  1064. $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
  1065. ->first();
  1066. if ($result) {
  1067. return Result::success($result);
  1068. } else {
  1069. return Result::error("查询失败", 0);
  1070. }
  1071. }
  1072. /**
  1073. * 更新网闸下的某一个导航
  1074. * @param array $data
  1075. * @return array
  1076. */
  1077. public function upWebsiteCategoryones(array $data): array
  1078. {
  1079. $where = [
  1080. 'website_id' => $data['website_id'],
  1081. 'category_id' => $data['category_id'],
  1082. ];
  1083. $result = WebsiteCategory::where($where)->update($data);
  1084. if ($result) {
  1085. return Result::success($result);
  1086. } else {
  1087. return Result::error("更新失败", 0);
  1088. }
  1089. }
  1090. /**
  1091. * 获取网站下的所有导航(包含子导航)
  1092. * @param array $data
  1093. * @return array
  1094. */
  1095. public function getWebsiteAllCategory(array $data): array
  1096. {
  1097. $where = [];
  1098. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1099. array_push($where, ['website_category.website_id', '=', $data['website_id']]);
  1100. }
  1101. if (isset($data['name']) && !empty($data['name'])) {
  1102. array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
  1103. }
  1104. if (isset($data['alias']) && !empty($data['alias'])) {
  1105. array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
  1106. }
  1107. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1108. array_push($where, ['category.department_id', '=', $data['department_id']]);
  1109. }
  1110. if (isset($data['city_id']) && !empty($data['city_id'])) {
  1111. array_push($where, ['category.city_id', '=', $data['city_id']]);
  1112. }
  1113. $result = WebsiteCategory::where($where)
  1114. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1115. ->leftJoin("department", 'category.department_id', 'department.id')
  1116. ->leftJoin("district", 'category.city_id', 'district.id')
  1117. ->select("website_category.*", "department.name as department_name", "district.name as city_name")
  1118. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1119. ->get();
  1120. $count = WebsiteCategory::where($where)
  1121. ->leftJoin("category", 'website_category.category_id', 'category.id')
  1122. ->leftJoin("department", 'category.department_id', 'department.id')
  1123. ->leftJoin("district", 'category.city_id', 'district.id')
  1124. ->count();
  1125. if (empty($result)) {
  1126. return Result::error("没有数据", 0);
  1127. }
  1128. $data = [
  1129. 'rows' => $result->toArray(),
  1130. 'count' => $count
  1131. ];
  1132. if ($result) {
  1133. return Result::success($data);
  1134. } else {
  1135. return Result::error("查询失败", 0);
  1136. }
  1137. if ($result) {
  1138. return Result::success($result);
  1139. } else {
  1140. return Result::error("查询失败", 0);
  1141. }
  1142. }
  1143. /**
  1144. * 递归查询数据
  1145. * @param $id
  1146. * @param $ids
  1147. * @return string
  1148. */
  1149. public function getUnderlingUIds($id, $ids = '')
  1150. {
  1151. $back = Category::where(['pid' => $id])->get();
  1152. $back = $back->toArray();
  1153. if (!empty($back) && is_array($back)) {
  1154. foreach ($back as $v) {
  1155. //防止当前人的ID重复去查询,形成恶性循环
  1156. if ($v['id'] == $id) {
  1157. continue;
  1158. }
  1159. $back2 = Category::where(['pid' => $id])->count('id');
  1160. if ($back2 > 0) {
  1161. $ids = $this->getUnderlingUIds($v['id'], $ids);
  1162. } else {
  1163. $ids .= ',' . $v['id'];
  1164. }
  1165. }
  1166. }
  1167. $ids = $id . ',' . $ids . ',';
  1168. $ids = str_replace(',,', ",", $ids);
  1169. $ids = trim($ids, ',');
  1170. return $ids;
  1171. }
  1172. /**
  1173. * 检测网站名称是否重复
  1174. * @param array $data
  1175. * @return array
  1176. */
  1177. public function checkWebsiteName(array $data): array
  1178. {
  1179. if (isset($data['id'])) {
  1180. $data[] = ['id', "!=", $data['id']];
  1181. unset($data['id']);
  1182. }
  1183. $websiteInfo = Website::query()->where($data)->first();
  1184. if (empty($websiteInfo)) {
  1185. return Result::error("找不到网站", 0);
  1186. }
  1187. return Result::success($websiteInfo->toArray());
  1188. }
  1189. /**
  1190. * 检测网站url是否重复
  1191. * @param array $data
  1192. * @return array
  1193. */
  1194. public function checkWebsiteUrl(array $data): array
  1195. {
  1196. $whereData = [];
  1197. if (isset($data['id'])) {
  1198. $whereData = [['id', "!=", $data['id']]];
  1199. unset($data['id']);
  1200. }
  1201. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  1202. if (empty($websiteInfo)) {
  1203. return Result::error("找不到URL", 0);
  1204. }
  1205. return Result::success($websiteInfo->toArray());
  1206. }
  1207. /**
  1208. * 获取并搜索 网站模板信息
  1209. * @param array $data
  1210. * @return array
  1211. */
  1212. public function getWebsiteTemplateintel(array $data): array
  1213. {
  1214. $where = []; // 初始化 $where 数组
  1215. //若存在条件;则在$rep的基础上进行筛选
  1216. if(isset($data['website_name'])){
  1217. array_push($where, ['website.website_name','like','%'.$data['website_name'].'%']);
  1218. }
  1219. if(isset($data['status'])){
  1220. if($data['status'] == 0){
  1221. array_push($where, ['website_template_info.status','=',null]);
  1222. }else{
  1223. array_push($where, ['website_template_info.status','=',$data['status']]);
  1224. }
  1225. }
  1226. //查询所有网站模板信息
  1227. if(empty($where)){
  1228. $rep = Website::where('website.status', 1)
  1229. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1230. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1231. ->select(
  1232. "website.website_name",
  1233. "website.website_url",
  1234. "website_template_info.id as tid",
  1235. "website_template_info.created_at",
  1236. "website_template_info.updated_at",
  1237. "website_template_info.page_type",
  1238. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1239. "template.template_name"
  1240. )
  1241. ->limit($data['pageSize'])
  1242. ->offset(($data['page'] - 1) * $data['pageSize'])
  1243. ->orderBy("website_template_info.updated_at", "asc")
  1244. ->get();
  1245. }else{
  1246. $rep = Website::where($where)
  1247. ->where('website.status', 1)
  1248. ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
  1249. ->leftJoin("template", "template.id", "website_template_info.template_id")
  1250. ->select(
  1251. "website.website_name",
  1252. "website.website_url",
  1253. "website_template_info.id as tid",
  1254. "website_template_info.created_at",
  1255. "website_template_info.updated_at",
  1256. "website_template_info.page_type",
  1257. DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
  1258. "template.template_name"
  1259. )
  1260. ->limit($data['pageSize'])
  1261. ->offset(($data['page'] - 1) * $data['pageSize'])
  1262. ->orderBy("website_template_info.updated_at", "asc")
  1263. ->get();
  1264. }
  1265. $result = [
  1266. "rows" => $rep->toArray(),
  1267. "count" => $rep->count()
  1268. ];
  1269. if($rep->count()==0){
  1270. return Result::error("没有查找到相关数据",0);
  1271. } else {
  1272. return Result::success($result); // 返回结果应该是 $result,而不是 $where
  1273. }
  1274. // return Result::success($result);
  1275. }
  1276. /**
  1277. * 添加网站基础信息
  1278. * @param array $data
  1279. * @return array
  1280. */
  1281. public function addWebsiteTemplateintel(array $data): array
  1282. {
  1283. $website = Website::where('website.id',$data['website_id'])->first();
  1284. if(empty($website)){
  1285. $message = "请输入正确的网站id!";
  1286. }else{
  1287. if(empty($website['website_column_id'])){
  1288. $message = "请先关联导航池!";
  1289. }
  1290. if(isset($data['page_type'])){
  1291. if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
  1292. // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
  1293. // $result = 'yes';
  1294. $data['page_type'] = json_encode($data['page_type'])??''; // 将数组转换为 JSON 字符串
  1295. $result = WebsiteTemplateInfo::insertGetId($data);
  1296. } else {
  1297. $message = "请先选择首页和底部导航详情页!";
  1298. }
  1299. }else{
  1300. $footer = FooterCategory::where('website_id',$data['website_id'])->select('type')->get();
  1301. if(empty($footer)){
  1302. $types = '2';
  1303. }else{
  1304. $types = 2;
  1305. foreach ($footer as $v) {
  1306. if ($v['type'] == 1) {
  1307. $types = 1;
  1308. } else {
  1309. $types = 0;
  1310. }
  1311. }
  1312. }
  1313. $result['type'] = $types;
  1314. }
  1315. }
  1316. if(empty($result)){
  1317. return Result::error($message,0);
  1318. }else{
  1319. return Result::success($result);
  1320. }
  1321. }
  1322. /**
  1323. * 获取所有网站风格信息
  1324. *
  1325. * @return array
  1326. */
  1327. public function getAllTemplateClass(array $data): array
  1328. {
  1329. $result = TemplateClass::all();
  1330. if(empty($result)){
  1331. return Result::error("没有查找到相关数据!",0);
  1332. }else{
  1333. return Result::success($result);
  1334. }
  1335. }
  1336. /**
  1337. * 获取网站模板信息
  1338. * @param array $data
  1339. * @return array
  1340. */
  1341. public function getWebsiteTemplateList(array $data): array
  1342. {
  1343. $website = Website::where('website.id',$data['website_id'])->first();
  1344. if(empty($website)){
  1345. $message = "请输入正确的网站id!";
  1346. }else{
  1347. $page_type = WebsiteTemplateInfo::where('website_id',$data['website_id'])->select('page_type')->first();
  1348. $where = json_decode($page_type['page_type'], true);
  1349. // $where = $data["page_type"];
  1350. if(isset($data['template_class_id'])){
  1351. $template_class = TemplateClass::where('id',$data['template_class_id'])->first();
  1352. if(empty($template_class)){
  1353. $message = "请输入正确的模板风格id!";
  1354. }else{
  1355. // 获取指定风格下的模板
  1356. $rep = Template::where('template_class_id', $data['template_class_id'])
  1357. ->where(function ($query) use ($where) {
  1358. foreach ($where as $value) {
  1359. $query->whereJsonContains('template_img', ['value' => $value]);
  1360. }
  1361. })
  1362. ->leftJoin('template_class','template_class.id','template.template_class_id')
  1363. ->select('template.*','template_class.name')
  1364. ->limit($data['pageSize'])
  1365. ->offset(($data['page'] - 1) * $data['pageSize'])
  1366. ->orderBy("template.updated_at", "desc")
  1367. ->get();
  1368. }
  1369. }else{
  1370. //获取所有模板
  1371. $rep = Template::where(function ($query) use ($where) {
  1372. foreach ($where as $value) {
  1373. $query->whereJsonContains('template_img', ['value' => $value]);
  1374. }
  1375. })
  1376. ->offset(($data['page'] - 1) * $data['pageSize'])
  1377. ->limit($data['pageSize'])
  1378. ->orderBy("template.updated_at", "desc")
  1379. ->get();
  1380. }
  1381. if(empty($rep->toArray())){
  1382. $message = "没有查找到相关数据!";
  1383. }else{
  1384. $result = [
  1385. "rows" => $rep->toArray(),
  1386. "count" => $rep->count()
  1387. ];
  1388. }
  1389. }
  1390. if(empty($rep)){
  1391. return Result::error($message,0);
  1392. }else{
  1393. return Result::success($result);
  1394. }
  1395. }
  1396. /**
  1397. * 添加网站模板
  1398. * @param array $data
  1399. */
  1400. public function addWebsiteTemplateclassintel(array $data): array
  1401. {
  1402. $template = Template::where('id',$data['template_id'])->first();
  1403. $web = Website::where('id',$data['website_id'])->first();
  1404. if(empty($template)){
  1405. return Result::error("请输入正确的模板id",0);
  1406. }
  1407. if(empty($web)){
  1408. return Result::error("请输入正确的网站id",0);
  1409. }
  1410. $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])->update(['template_id' => $data['template_id']]);
  1411. if(empty($result)){
  1412. return Result::error("添加失败",0);
  1413. }else{
  1414. return Result::success($result);
  1415. }
  1416. }
  1417. /**
  1418. * 风格下的板块
  1419. * @return void
  1420. */
  1421. public function templateSectorList(array $data): array
  1422. {
  1423. $where = [
  1424. 'template_id' => $data['template_id']
  1425. ];
  1426. $result = Sector::where($where)->whereJsonContains("page_type", $data['page_type'])
  1427. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1428. ->get();
  1429. $count = Sector::where($where)->count();
  1430. if (empty($result)) {
  1431. return Result::error("没有数据", 0);
  1432. }
  1433. $data = [
  1434. 'rows' => $result->toArray(),
  1435. 'count' => $count
  1436. ];
  1437. if (empty($result)) {
  1438. return Result::error("没有数据", 0);
  1439. }
  1440. return Result::success($data);
  1441. }
  1442. /**
  1443. * 板块下的组件
  1444. * @param array $data
  1445. * @return array
  1446. */
  1447. public function sectorComponentList(array $data): array
  1448. {
  1449. $where = [
  1450. 'template_id' => $data['template_id'],
  1451. 'sector_id' => $data['sector_id'],
  1452. ];
  1453. $result = Component::where($where)
  1454. ->select("*")
  1455. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
  1456. ->get();
  1457. $count = Component::where($where)->count();
  1458. if (empty($result)) {
  1459. return Result::error("没有数据", 0);
  1460. }
  1461. $data = [
  1462. 'rows' => $result->toArray(),
  1463. 'count' => $count
  1464. ];
  1465. if (empty($result)) {
  1466. return Result::error("没有数据", 0);
  1467. }
  1468. return Result::success($data);
  1469. }
  1470. /**
  1471. * 获取模板内容
  1472. * @return void
  1473. */
  1474. public function getWebsiteTemplateInfo(array $data): array
  1475. {
  1476. $wehre = [
  1477. "website_id" => $data['website_id']
  1478. ];
  1479. $result = WebsiteTemplate::where($wehre)->first();
  1480. if ($result) {
  1481. return Result::success($result);
  1482. } else {
  1483. return Result::error("没有数据", 0);
  1484. }
  1485. }
  1486. /**
  1487. * 保存网站模板
  1488. * @param array $data
  1489. * @return array
  1490. */
  1491. public function addWebsiteTemplate(array $data): array
  1492. {
  1493. var_dump("接收参数:", $data['template_data']);
  1494. $result = WebsiteTemplate::updateOrInsert(['website_id' => $data['website_id']], ['template_data' => json_encode($data['template_data'])]);
  1495. if ($result) {
  1496. return Result::success($result);
  1497. } else {
  1498. return Result::error("创建失败", 0);
  1499. }
  1500. }
  1501. /**
  1502. * 预览网站首页模板数据
  1503. * @param array $data
  1504. * @return array
  1505. */
  1506. public function getWebsiteTemplateData(array $data): array
  1507. {
  1508. $wehre = [
  1509. "website_id" => $data['website_id']
  1510. ];
  1511. $result = WebsiteTemplate::where($wehre)->first();
  1512. if ($result) {
  1513. $templateData = json_decode($result['template_data'], true);
  1514. // var_dump("数据:",$templateData[1]);
  1515. $templateData[1] = $this->getNewsList($templateData[1]);
  1516. return Result::success($templateData);
  1517. } else {
  1518. return Result::error("没有数据", 0);
  1519. }
  1520. }
  1521. /**
  1522. * 获取数据
  1523. * @return void
  1524. */
  1525. public function getNewsList(array $data): array
  1526. {
  1527. if ($data) {
  1528. foreach ($data as $key => $val) {
  1529. if ($val) {
  1530. foreach ($val['data'] as $k => $item) {
  1531. if ($item['isReturn'] && intval($item['isReturn']) == 1) {
  1532. $imgList = [];
  1533. if ($item['data']['imgNum'] && intval($item['data']['imgNum']) > 0) {
  1534. $imgList = Article::where('imgurl', "!=", "")
  1535. ->where('catid', $item['data']['category_id'])
  1536. ->select($item['data']['selectField'])
  1537. ->orderBy("created_at", "desc")
  1538. ->offset(0)
  1539. ->limit(intval($item['data']['imgNum']))
  1540. ->get();
  1541. $imgList = $imgList->toArray();
  1542. $listIds = [];
  1543. if ($imgList) {
  1544. $listIds = array_column($imgList, 'id');
  1545. }
  1546. $dataList = Article::whereNotIn('id', $listIds)
  1547. ->where('catid', $item['data']['category_id'])
  1548. ->select($item['data']['selectField'])
  1549. ->orderBy("created_at", "desc")
  1550. ->offset(0)
  1551. ->limit(intval($item['data']['pageSize']) - intval($item['data']['imgNum']))
  1552. ->get();
  1553. $dataList = $dataList->toArray();
  1554. var_dump("图片列表:", $imgList, "数据列表:", $dataList);
  1555. $datas = array_merge($imgList, $dataList);
  1556. // return $datas;
  1557. var_dump("合并列表:", $datas);
  1558. $data[$key]['data'][$k]['dataList'] = $datas;
  1559. } else {
  1560. $dataList = Article::where('catid', $item['data']['category_id'])
  1561. ->select($item['data']['selectField'])
  1562. ->orderBy("created_at", "desc")
  1563. ->offset(0)
  1564. ->limit(intval($item['data']['pageSize']))
  1565. ->get();
  1566. $dataList = $dataList->toArray();
  1567. var_dump("数据列表:", $dataList);
  1568. }
  1569. }
  1570. }
  1571. }
  1572. }
  1573. }
  1574. return $data;
  1575. }
  1576. /**
  1577. * 获取底部导航列表
  1578. * @param array $data
  1579. * @return array
  1580. */
  1581. public function getFooterCategoryList(array $data): array
  1582. {
  1583. $where = [
  1584. "website_id" => $data['website_id']
  1585. ];
  1586. $result = FooterCategory::where($where)->get();
  1587. if ($result) {
  1588. return Result::success($result);
  1589. } else {
  1590. return Result::error("没有数据");
  1591. }
  1592. }
  1593. //获取底部导航内容列表
  1594. public function getFooterContentList(array $data): array
  1595. {
  1596. $where = [
  1597. "fcat_id" => $data['fcat_id'],
  1598. ];
  1599. switch (intval($data['type'])) {
  1600. case 0:
  1601. $result = FooterContent::where($where)->first();
  1602. break;
  1603. case 1:
  1604. $result = FooterContent::where($where)->get();
  1605. break;
  1606. }
  1607. if ($result) {
  1608. return Result::success($result);
  1609. } else {
  1610. return Result::error("没有数据");
  1611. }
  1612. }
  1613. //获取底部导航内容详情
  1614. public function getFooterContentInfo(array $data): array
  1615. {
  1616. $where = [
  1617. "id" => $data['content_id']
  1618. ];
  1619. $result = FooterContent::where($where)->first();
  1620. if ($result) {
  1621. return Result::success($result);
  1622. } else {
  1623. return Result::error("没有数据");
  1624. }
  1625. }
  1626. =======
  1627. <?php
  1628. namespace App\JsonRpc;
  1629. use App\Model\Article;
  1630. use App\Model\Category;
  1631. use App\Model\LetterOfComplaint;
  1632. use App\Model\TemplateClass;
  1633. use App\Model\Template;
  1634. use App\Model\User;
  1635. use App\Model\WebsiteRole;
  1636. use App\Model\WebsiteRoleUser;
  1637. use App\Model\Website;
  1638. use App\Model\WebsiteColumn;
  1639. use Hyperf\DbConnection\Db;
  1640. use Hyperf\RpcServer\Annotation\RpcService;
  1641. use App\Tools\Result;
  1642. use App\Model\WebsiteCategory;
  1643. use function PHPUnit\Framework\isNull;
  1644. #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  1645. class WebsiteService implements WebsiteServiceInterface
  1646. {
  1647. /**
  1648. * 获取网站列表
  1649. * @param string $keyword
  1650. * @param int $page
  1651. * @param int $pageSize
  1652. * @return array
  1653. */
  1654. public function getWebsitetList(array $data): array
  1655. {
  1656. $resultWwhere = Website::when($data,function ($query) use ($data){
  1657. if(isset($data['keyword']) && !empty($data['keyword'])){
  1658. $query->where('website.website_name','like','%'.$data['keyword'].'%');
  1659. }
  1660. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  1661. $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
  1662. }
  1663. if(isset($data['city_id']) && !empty($data['city_id'])){
  1664. $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
  1665. }
  1666. });
  1667. $result = $resultWwhere->leftJoin("website_column","website.website_column_id","website_column.id")
  1668. ->leftJoin("district","district.id","website.city_id")
  1669. ->select("website.*","website_column.column_name","district.name as city_name")
  1670. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("website.id","desc")->get();
  1671. $count = $resultWwhere->count();
  1672. if (empty($result)) {
  1673. return Result::error("没有数据",0);
  1674. }
  1675. $data = [
  1676. 'rows'=>$result->toArray(),
  1677. 'count'=>$count
  1678. ];
  1679. return Result::success($data);
  1680. }
  1681. /**
  1682. * @param array $data
  1683. * @return array
  1684. */
  1685. public function createWebsite(array $data): array
  1686. {
  1687. var_dump("网站数据:",$data);
  1688. $insertData = [
  1689. 'website_name'=>$data['website_name'],
  1690. 'logo'=>$data['logo']??'',
  1691. 'website_url'=>$data['website_url']??'',
  1692. // 'city_id'=>$data['city_id']??0,
  1693. 'website_column_id'=>$data['website_column_id'],
  1694. 'title'=>$data['title']??'',
  1695. 'keywords'=>$data['keywords']??'',
  1696. 'description'=>$data['description']??'',
  1697. 'status'=>$data['status']??0,
  1698. 'website_column_arr_id'=>$data['website_column_arr_id'],
  1699. // 'city_arr_id'=>$data['city_arr_id']??[0],
  1700. 'template_id' =>$data['template_id']??0,
  1701. ];
  1702. $result = Website::insertGetId($insertData);
  1703. if(empty($result)){
  1704. return Result::error("创建失败",0);
  1705. }else{
  1706. return Result::success(["id"=>$result]);
  1707. }
  1708. }
  1709. /**
  1710. * @param int $id
  1711. * @param array $data
  1712. * @return array
  1713. */
  1714. public function updateWebsite(int $id,array $data): array
  1715. {
  1716. $insertData = [
  1717. 'website_name'=>$data['website_name'],
  1718. 'logo'=>$data['logo']??'',
  1719. 'website_url'=>$data['website_url']??'',
  1720. // 'city_id'=>$data['city_id']??0,
  1721. 'website_column_id'=>$data['website_column_id'],
  1722. 'title'=>$data['title']??'',
  1723. 'keywords'=>$data['keywords']??'',
  1724. 'description'=>$data['description']??'',
  1725. 'status'=>$data['status']??0,
  1726. 'website_column_arr_id'=>$data['website_column_arr_id'],
  1727. // 'city_arr_id'=>$data['city_arr_id']??[0],
  1728. 'template_id' =>$data['template_id']??0,
  1729. ];
  1730. $result = Website::where('id',$id)->update($insertData);
  1731. var_dump("更新站点",$result);
  1732. if(empty($result)){
  1733. return Result::error("更新失败",0);
  1734. }else{
  1735. return Result::success();
  1736. }
  1737. }
  1738. /**
  1739. * @param int $id
  1740. * @return array
  1741. */
  1742. public function delWebsite(int $id): array
  1743. {
  1744. $result = Website::where('id',$id )->delete();
  1745. if(empty($result)){
  1746. return Result::error("删除失败",0);
  1747. }else{
  1748. return Result::success();
  1749. }
  1750. }
  1751. /**
  1752. * @param int $id
  1753. * @return array
  1754. */
  1755. public function getWebsiteInfo(int $id): array
  1756. {
  1757. $where = [
  1758. ['website.id','=',$id]
  1759. ];
  1760. $result = Website::where($where )
  1761. ->leftJoin("template","template.id","website.template_id")
  1762. ->select("website.*","template.template_name","template.template_img")
  1763. ->first();
  1764. if(empty($result)){
  1765. return Result::error("数据不存在",0);
  1766. }else{
  1767. return Result::success($result->toArray());
  1768. }
  1769. }
  1770. /**
  1771. * 查询所有的站点栏目
  1772. * @return array
  1773. */
  1774. public function getWebsiteColumn(array $data): array
  1775. {
  1776. $result = WebsiteColumn::where($data)->get();
  1777. if(empty($result)){
  1778. return Result::error("数据不存在",0);
  1779. }else{
  1780. return Result::success($result->toArray());
  1781. }
  1782. }
  1783. /**
  1784. * @param string $keyword
  1785. * @param int $page
  1786. * @param int $pageSize
  1787. * @return array
  1788. */
  1789. public function getWebsiteColumnList(array $data):array
  1790. {
  1791. $where = [];
  1792. if(isset($data['keyword']) && $data['keyword']){
  1793. array_push($where,['website_column.column_name','like','%'.$data['keyword'].'%']);
  1794. }
  1795. $result = WebsiteColumn::where($where)
  1796. ->leftJoin("website_column as wc","website_column.pid","wc.id")
  1797. ->select("website_column.*","wc.column_name as parent_column_name")
  1798. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->get();
  1799. $count = WebsiteColumn::where($where)->count();
  1800. if (empty($result)) {
  1801. return Result::error("没有数据",0);
  1802. }
  1803. $data = [
  1804. 'rows'=>$result->toArray(),
  1805. 'count'=>$count
  1806. ];
  1807. return Result::success($data);
  1808. }
  1809. /**
  1810. * @param array $data
  1811. * @return array
  1812. */
  1813. public function createWebsiteColumn(array $data): array
  1814. {
  1815. $insertData = [
  1816. 'column_name'=>$data['column_name'],
  1817. 'pid'=>$data['pid']??'',
  1818. 'column_arr_id'=>$data['column_arr_id']??[0],
  1819. 'sort'=>$data['sort']??0,
  1820. 'remark'=>$data['remark']??'',
  1821. ];
  1822. $result = WebsiteColumn::insertGetId($insertData);
  1823. if(empty($result)){
  1824. return Result::error("创建失败",0);
  1825. }else{
  1826. return Result::success(["id"=>$result]);
  1827. }
  1828. }
  1829. /**
  1830. * @param int $id
  1831. * @param array $data
  1832. * @return array
  1833. */
  1834. public function updateWebsiteColumn(int $id,array $data): array
  1835. {
  1836. $insertData = [
  1837. 'column_name'=>$data['column_name'],
  1838. 'pid'=>$data['pid']??'',
  1839. 'column_arr_id'=>$data['column_arr_id']??[0],
  1840. 'sort'=>$data['sort']??0,
  1841. 'remark'=>$data['remark']??'',
  1842. ];
  1843. $result = WebsiteColumn::where('id',$id)->update($insertData);
  1844. if(empty($result)){
  1845. return Result::error("更新失败",0);
  1846. }else{
  1847. return Result::success();
  1848. }
  1849. }
  1850. /**
  1851. * @param int $id
  1852. * @return array
  1853. */
  1854. public function delWebsiteColumn(int $id): array
  1855. {
  1856. $list = WebsiteColumn::where(['pid'=>$id])->get();
  1857. if($list){
  1858. return Result::error("存在子网系,不能删除,请先删除子网系",0);
  1859. }
  1860. $result = WebsiteColumn::where('id',$id )->delete();
  1861. if(empty($result)){
  1862. return Result::error("删除失败",0);
  1863. }else{
  1864. return Result::success();
  1865. }
  1866. }
  1867. /**
  1868. * @param string $keyword
  1869. * @param int $page
  1870. * @param int $pageSize
  1871. * @return array
  1872. */
  1873. public function getWebsiteRoleList(string $keyword,int $page,int $pageSize,int $websiteId):array
  1874. {
  1875. $where = [
  1876. ['role.role_name','like','%'.$keyword.'%'],
  1877. ['website_role.website_id','=',$websiteId],
  1878. ];
  1879. $result = WebsiteRole::where($where)
  1880. ->leftJoin("role","role.id","website_role.role_id")
  1881. ->select("role.*","website_role.type","website_role.role_id","website_role.id as website_role_id","website_role.website_id")
  1882. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  1883. $count = WebsiteRole::where($where) ->leftJoin("role","role.id","website_role.role_id")->count();
  1884. if (empty($result)) {
  1885. return Result::error("没有数据",0);
  1886. }
  1887. $data = [
  1888. 'rows'=>$result->toArray(),
  1889. 'count'=>$count
  1890. ];
  1891. return Result::success($data);
  1892. }
  1893. /**
  1894. * @param array $data
  1895. * @return array
  1896. */
  1897. public function createWebsiteRole(array $data): array
  1898. {
  1899. $insertData = [
  1900. 'website_id'=>$data['website_id'],
  1901. 'role_id'=>$data['role_id']??''
  1902. ];
  1903. $info = WebsiteRole::where($insertData)->first();
  1904. if($info){
  1905. return Result::error("不能重复添加角色",0);
  1906. }
  1907. $insertData['admin_user_id'] = $data['admin_user_id']??'';
  1908. $insertData['type'] = $data['type']??'';
  1909. $result = WebsiteRole::insertGetId($insertData);
  1910. if(empty($result)){
  1911. return Result::error("创建失败",0);
  1912. }else{
  1913. return Result::success(["id"=>$result]);
  1914. }
  1915. }
  1916. /**
  1917. * 暂时用不上
  1918. * @param int $id
  1919. * @param array $data
  1920. * @return array
  1921. */
  1922. public function updateWebsiteRole(int $id,array $data): array
  1923. {
  1924. $insertData = [
  1925. 'website_id'=>$data['website_id'],
  1926. 'type'=>$data['type']??'',
  1927. ];
  1928. $result = WebsiteRole::where('id',$id)->update($insertData);
  1929. if(empty($result)){
  1930. return Result::error("更新失败",0);
  1931. }else{
  1932. return Result::success();
  1933. }
  1934. }
  1935. /**
  1936. * @param int $id
  1937. * @return array
  1938. */
  1939. public function delWebsiteRole(int $id): array
  1940. {
  1941. $result = WebsiteRole::where('id',$id )->delete();
  1942. if(empty($result)){
  1943. return Result::error("删除失败",0);
  1944. }else{
  1945. return Result::success();
  1946. }
  1947. }
  1948. /**
  1949. * @param string $keyword
  1950. * @param int $page
  1951. * @param int $pageSize
  1952. * @return array
  1953. */
  1954. public function getWebsiteRoleUserList(string $keyword,int $page,int $pageSize,int $websiteId,int $roleId):array
  1955. {
  1956. $where = [
  1957. ['website_role_user.website_id','=',$websiteId],
  1958. ['website_role_user.role_id','=',$roleId],
  1959. ];
  1960. $count = WebsiteRoleUser::where($where)->count();
  1961. $where[] = ['u.user_name','like','%'.$keyword.'%'];
  1962. $result = WebsiteRoleUser::where($where)
  1963. ->leftJoin("user as u","website_role_user.user_id","u.id")
  1964. ->leftJoin("website as w","website_role_user.website_id","u.id")
  1965. ->leftJoin("role as r","website_role_user.role_id","r.id")
  1966. ->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')
  1967. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  1968. if (empty($result)) {
  1969. return Result::error("没有数据",0);
  1970. }
  1971. $data = [
  1972. 'rows'=>$result->toArray(),
  1973. 'count'=>$count
  1974. ];
  1975. return Result::success($data);
  1976. }
  1977. /**
  1978. * @param array $data
  1979. * @return array
  1980. */
  1981. public function createWebsiteRoleUser(array $data): array
  1982. {
  1983. $insertData = [
  1984. 'website_id'=>$data['website_id'],
  1985. 'user_id'=>$data['user_id']??'',
  1986. ];
  1987. $info = WebsiteRoleUser::where($insertData)->first();
  1988. if($info){
  1989. return Result::error("不能重复添加角色用户",0);
  1990. }
  1991. $insertData['role_id'] = $data['role_id']??'';
  1992. $insertData['admin_user_id'] = $data['admin_user_id']??'';
  1993. $insertData['type'] = $data['type']??'';
  1994. $result = WebsiteRoleUser::insertGetId($insertData);
  1995. if(empty($result)){
  1996. return Result::error("创建失败",0);
  1997. }else{
  1998. return Result::success(["id"=>$result]);
  1999. }
  2000. }
  2001. /**
  2002. * @param int $id
  2003. * @param array $data
  2004. * @return array
  2005. */
  2006. public function updateWebsiteRoleUser(int $id,array $data): array
  2007. {
  2008. $insertData = [
  2009. 'website_id'=>$data['website_id'],
  2010. 'type'=>$data['type']??'',
  2011. 'type_id'=>$data['type_id']??'',
  2012. 'role_id'=>$data['role_id']??'',
  2013. ];
  2014. $result = WebsiteRoleUser::where('id',$id)->update($insertData);
  2015. if(empty($result)){
  2016. return Result::error("更新失败",0);
  2017. }else{
  2018. return Result::success();
  2019. }
  2020. }
  2021. /**
  2022. * @param int $id
  2023. * @return array
  2024. */
  2025. public function delWebsiteRoleUser(int $id): array
  2026. {
  2027. $result = WebsiteRoleUser::where('id',$id )->delete();
  2028. if(empty($result)){
  2029. return Result::error("删除失败",0);
  2030. }else{
  2031. return Result::success();
  2032. }
  2033. }
  2034. /**
  2035. * 根据域名获取网站 站点id
  2036. * @param array $data
  2037. * @return array
  2038. */
  2039. public function getWebsiteId(array $data): array
  2040. {
  2041. $result = Website::whereJsonContains('website_url',$data['website_url'])->first();
  2042. if(empty($result)){
  2043. return Result::error("查询站点失败",0);
  2044. }else{
  2045. return Result::success($result);
  2046. }
  2047. }
  2048. /**
  2049. * 查询网站下面的导航
  2050. * @param array $data
  2051. * @return array
  2052. */
  2053. public function getWebsiteCategory(array $data): array
  2054. {
  2055. $where = [
  2056. 'website_id'=>$data['website_id'],
  2057. 'pid'=>0
  2058. ];
  2059. $result = WebsiteCategory::where($where)->orderBy('sort','asc')->get();
  2060. if(empty($result)){
  2061. return Result::error("查询站点栏目失败",0);
  2062. }else{
  2063. return Result::success($result);
  2064. }
  2065. }
  2066. /**
  2067. * 网站首页数据统计, 管理员
  2068. * @return void
  2069. */
  2070. public function getAdminIndex(array $data): array
  2071. {
  2072. var_dump("用户类型:",$data['type_id']);
  2073. switch ($data['type_id']){
  2074. case 4:
  2075. $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;');
  2076. return Result::success($result);
  2077. break;
  2078. case 10000:
  2079. $res = [];
  2080. //网站
  2081. $res['website']['count'] = 0;
  2082. $res['website']['growth_rate'] = 0;
  2083. //资讯
  2084. $res['article']['count'] = 0;
  2085. $res['article']['growth_rate'] = 0;
  2086. //导航池
  2087. $res['category']['count'] = 0;
  2088. $res['category']['growth_rate'] = 0;
  2089. //近一月数据
  2090. $res['monthArticle']= [];
  2091. //用户类型
  2092. $res['userType'] = [];
  2093. $res['website']['count'] = Website::where([])->count();
  2094. $res['article']['count'] = Article::whereNotIn('status',['404'])->count();
  2095. $res['category']['count'] = Category::where([])->count();
  2096. $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;');
  2097. $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
  2098. return Result::success($res);
  2099. }
  2100. return [];
  2101. }
  2102. /**
  2103. * 获取模板类型
  2104. * @return void
  2105. */
  2106. public function getTemplateClass(array $data): array
  2107. {
  2108. $where = [];
  2109. if(isset($data['name']) && $data['name']){
  2110. array_push($where,['name','like','%'.$data['name'].'%']);
  2111. }
  2112. $result = TemplateClass::where($where)->orderBy('sort','asc')->get();
  2113. if(empty($result)){
  2114. return Result::error("没有模板类型",0);
  2115. }else{
  2116. return Result::success($result);
  2117. }
  2118. }
  2119. /**
  2120. * 添加模板类型
  2121. * @param
  2122. * @return void
  2123. */
  2124. public function addTemplateClass(array $data): array
  2125. {
  2126. $insertData = [
  2127. 'name'=>$data['name']
  2128. ];
  2129. $result = TemplateClass::insertGetId($insertData);
  2130. if(empty($result)){
  2131. return Result::error("创建失败",0);
  2132. }else{
  2133. return Result::success(["id"=>$result]);
  2134. }
  2135. }
  2136. /**
  2137. * 更新模板
  2138. * @param array $data
  2139. * @return array
  2140. */
  2141. public function upTemplateClass(array $data): array
  2142. {
  2143. $where = [
  2144. 'id'=>$data['id']
  2145. ];
  2146. $insertData = [
  2147. 'name'=>$data['name']
  2148. ];
  2149. $result = TemplateClass::where($where)->update($insertData);
  2150. if(empty($result)){
  2151. return Result::error("更新失败",0);
  2152. }else{
  2153. return Result::success();
  2154. }
  2155. }
  2156. /**
  2157. * 删除模板
  2158. * @param array $data
  2159. * @return array
  2160. */
  2161. public function delTemplateClass(array $data): array
  2162. {
  2163. $where = [
  2164. 'id'=>$data['id']
  2165. ];
  2166. $result = TemplateClass::where($where)->delete();
  2167. if(empty($result)){
  2168. return Result::error("删除失败",0);
  2169. }else{
  2170. return Result::success();
  2171. }
  2172. }
  2173. /**
  2174. * 获取分类下的模板
  2175. * @param array $data
  2176. * @return array
  2177. */
  2178. public function getTemplate(array $data): array
  2179. {
  2180. $page = $data['page'];
  2181. $pageSize = $data['pageSize'];
  2182. $where = [];
  2183. if(isset($data['template_class_id']) && $data['template_class_id']){
  2184. array_push($where,['template_class_id','=',$data['template_class_id']]);
  2185. }
  2186. $result = Template::where($where)
  2187. ->limit($pageSize)->offset(($page-1)*$pageSize)->get();
  2188. $count = Template::where($where)->count();
  2189. if (empty($result)) {
  2190. return Result::error("没有数据",0);
  2191. }
  2192. $data = [
  2193. 'rows'=>$result->toArray(),
  2194. 'count'=>$count
  2195. ];
  2196. return Result::success($data);
  2197. }
  2198. /**
  2199. * 创建模板
  2200. * @param
  2201. * @return void
  2202. */
  2203. public function addTemplate(array $data): array
  2204. {
  2205. $insertData = [
  2206. 'template_name'=>$data['template_name'],
  2207. 'template_img'=>json_encode($data['template_img']),
  2208. 'template_class_id'=>$data['template_class_id'],
  2209. ];
  2210. $result = Template::insertGetId($insertData);
  2211. if(empty($result)){
  2212. return Result::error("创建模板失败",0);
  2213. }else{
  2214. return Result::success(["id"=>$result]);
  2215. }
  2216. }
  2217. /**
  2218. * 更新模板
  2219. * @param array $data
  2220. * @return array
  2221. */
  2222. public function upTemplate(array $data): array
  2223. {
  2224. $where = [
  2225. 'id'=>$data['id']
  2226. ];
  2227. $insertData = [
  2228. 'template_name'=>$data['template_name'],
  2229. 'template_img'=>json_encode($data['template_img']),
  2230. 'template_class_id'=>$data['template_class_id'],
  2231. ];
  2232. $result = Template::where($where)->update($insertData);
  2233. if(empty($result)){
  2234. return Result::error("更新模板失败",0);
  2235. }else{
  2236. return Result::success();
  2237. }
  2238. }
  2239. /**
  2240. * 删除模板
  2241. * @param array $data
  2242. * @return array
  2243. */
  2244. public function delTemplate(array $data): array
  2245. {
  2246. $where = [
  2247. 'id'=>$data['id']
  2248. ];
  2249. $result = Template::where($where)->delete();
  2250. if(empty($result)){
  2251. return Result::error("删除模板失败",0);
  2252. }else{
  2253. return Result::success();
  2254. }
  2255. }
  2256. /**
  2257. * 搜索网站
  2258. * @param array $data
  2259. * @return array
  2260. */
  2261. public function websiteList(array $data): array
  2262. {
  2263. $where = [];
  2264. if(isset($data['keyword']) && !empty($data['keyword'])){
  2265. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  2266. }
  2267. $result = Website::where($where)->get();
  2268. if($result){
  2269. return Result::success($result);
  2270. }else{
  2271. return Result::error("没有网站",0);
  2272. }
  2273. }
  2274. public function addWebsiteCategory(array $data): array
  2275. {
  2276. $website_id = $data['website_id'];
  2277. $category_arr_id = $data['category_arr_id'];
  2278. $categoryList = Category::whereIn('id',$category_arr_id)->get();
  2279. $categoryListIds = [];
  2280. if($categoryList){
  2281. foreach ($categoryList->toArray() as $val){
  2282. array_push($categoryListIds,$val['id']);
  2283. }
  2284. }
  2285. $arr = [];
  2286. if($categoryListIds){
  2287. foreach ($categoryListIds as $v){
  2288. $ids = $this->getUnderlingUIds(intval($v));
  2289. $ids_arr = explode(",", $ids);
  2290. array_push($arr,$ids_arr);
  2291. }
  2292. }
  2293. $mergedArray = [];
  2294. foreach ($arr as $subarray) {
  2295. $mergedArray = array_merge($mergedArray, $subarray);
  2296. }
  2297. var_dump("所有:",$arr,$mergedArray);
  2298. //查询出所有的分类进行分割插入 组装数据
  2299. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  2300. $categoryListData = $categoryListData->toArray();
  2301. $insertData = [];
  2302. if($categoryListData){
  2303. foreach ($categoryListData as $key=>$value){
  2304. $insertData[$key]['website_id'] = $website_id;
  2305. $insertData[$key]['name'] = $value['name'];
  2306. $insertData[$key]['sort'] = $value['sort'];
  2307. $insertData[$key]['pid'] = $value['pid'];
  2308. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  2309. $insertData[$key]['seo_title'] = $value['seo_title'];
  2310. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  2311. $insertData[$key]['seo_description'] = $value['seo_description'];
  2312. $insertData[$key]['alias'] = $value['name'];
  2313. $insertData[$key]['category_id'] = $value['id'];
  2314. }
  2315. }
  2316. $result = WebsiteCategory::insert($insertData);
  2317. var_dump("插入数据状态:",$result);
  2318. if($result){
  2319. return Result::success($result);
  2320. }else{
  2321. return Result::error("创建失败",0);
  2322. }
  2323. }
  2324. /**
  2325. * 删除网站导航
  2326. * @param array $data
  2327. * @return array
  2328. */
  2329. public function delWebsiteCategory(array $data): array
  2330. {
  2331. $website_id = $data['website_id']??0;
  2332. $category_id = $data['category_id']??0;
  2333. $ids = $this->getUnderlingUIds(intval($category_id));
  2334. $ids_arr = explode(",", $ids);
  2335. $result = WebsiteCategory::where(['website_id'=>$website_id])->whereIn("category_id",$ids_arr)->delete();
  2336. if($result){
  2337. return Result::success($result);
  2338. }else{
  2339. return Result::error("删除失败",0);
  2340. }
  2341. }
  2342. /**
  2343. * 获取网站导航
  2344. * @param array $data
  2345. * @return array
  2346. */
  2347. public function getAdminWebsiteCategory(array $data): array
  2348. {
  2349. $where = [
  2350. 'website_id'=>$data['website_id'],
  2351. 'pid'=>0
  2352. ];
  2353. $result = WebsiteCategory::where($where)->get();
  2354. if($result){
  2355. return Result::success($result);
  2356. }else{
  2357. return Result::error("查询失败",0);
  2358. }
  2359. }
  2360. /**
  2361. * 更新网站导航
  2362. * @param array $data
  2363. * @return array
  2364. */
  2365. public function upWebsiteCategory(array $data): array
  2366. {
  2367. Db::beginTransaction();
  2368. try{
  2369. //合并栏目id
  2370. $reqIds = array_merge($data['old_category_arr_id'],$data['new_category_arr_id']);
  2371. //对比old 数组差异化,把差异化的删除
  2372. $result = WebsiteCategory::where(['website_id'=>$data['website_id'],'pid'=>0])->get();
  2373. $result = $result->toArray();
  2374. $categoryIds = [];
  2375. if($result){
  2376. foreach ($result as $val){
  2377. array_push($categoryIds,$val['category_id']);
  2378. }
  2379. }
  2380. //和原始数据对比取交际
  2381. $reqidsIntersect = array_intersect($reqIds,$categoryIds);
  2382. //再取差集 进行对比
  2383. $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds),array_diff($categoryIds,$reqidsIntersect));
  2384. var_dump("差集:",$differenceIDS);
  2385. $arr_ids = [];
  2386. if(count($differenceIDS)>0){
  2387. foreach ($differenceIDS as $vv){
  2388. $idV = $this->getUnderlingUIds(intval($vv));
  2389. $ids_arrV = explode(",", $idV);
  2390. array_push($arr_ids,$ids_arrV);
  2391. }
  2392. }
  2393. $del_ids = array_reduce($arr_ids, 'array_merge', array());
  2394. //有差异 删除
  2395. if(count($del_ids)>0){
  2396. WebsiteCategory::where(['website_id'=>$data['website_id']])->whereIn("category_id",$del_ids)->delete();
  2397. }
  2398. //传过来的值 和 交际 对比,选出要添加的值 进行插入
  2399. $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect),array_diff($reqidsIntersect,$reqIds));
  2400. var_dump("要存储的:",$insertIDS);
  2401. //新的数组重新创建
  2402. if(count($insertIDS)>0){
  2403. $arr = [];
  2404. $categoryListIds = $insertIDS;
  2405. if($categoryListIds){
  2406. foreach ($categoryListIds as $v){
  2407. $ids = $this->getUnderlingUIds(intval($v));
  2408. $ids_arr = explode(",", $ids);
  2409. array_push($arr,$ids_arr);
  2410. }
  2411. }
  2412. $mergedArray = [];
  2413. foreach ($arr as $subarray) {
  2414. $mergedArray = array_merge($mergedArray, $subarray);
  2415. }
  2416. var_dump("要插入的ID:",$mergedArray);
  2417. //查询出所有的分类进行分割插入 组装数据
  2418. $categoryListData = Category::whereIn('id',$mergedArray)->get();
  2419. $categoryListData = $categoryListData->toArray();
  2420. $insertData = [];
  2421. if($categoryListData){
  2422. foreach ($categoryListData as $key=>$value){
  2423. $insertData[$key]['website_id'] = $data['website_id'];
  2424. $insertData[$key]['name'] = $value['name'];
  2425. $insertData[$key]['sort'] = $value['sort'];
  2426. $insertData[$key]['pid'] = $value['pid'];
  2427. $insertData[$key]['pid_arr'] = $value['pid_arr'];
  2428. $insertData[$key]['seo_title'] = $value['seo_title'];
  2429. $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
  2430. $insertData[$key]['seo_description'] = $value['seo_description'];
  2431. $insertData[$key]['alias'] = $value['name'];
  2432. $insertData[$key]['category_id'] = $value['id'];
  2433. }
  2434. }
  2435. WebsiteCategory::insert($insertData);
  2436. }
  2437. Db::commit();
  2438. } catch(\Throwable $ex){
  2439. Db::rollBack();
  2440. var_dump($ex->getMessage());
  2441. return Result::error("修改失败",0);
  2442. }
  2443. return Result::success();
  2444. }
  2445. /**
  2446. * 获取网站列表
  2447. * @param array $data
  2448. * @return array
  2449. */
  2450. public function getWebsiteCategoryList(array $data): array
  2451. {
  2452. $where = [];
  2453. if(isset($data['keyword']) && !empty($data['keyword'])){
  2454. array_push($where,['website.website_name','like','%'.$data['keyword'].'%']);
  2455. }
  2456. if(isset($data['website_column_id']) && !empty($data['website_column_id'])){
  2457. array_push($where,['website.website_column_id','=',$data['website_column_id']]);
  2458. }
  2459. $result = Website::where($where)
  2460. ->with(["websiteCategory"=>function ($query) {
  2461. $query->where(['pid'=>0])->select('website_id','name','alias','category_id');
  2462. }])
  2463. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  2464. ->get();
  2465. $count = Website::where($where)->count();
  2466. if (empty($result)) {
  2467. return Result::error("没有数据",0);
  2468. }
  2469. $data = [
  2470. 'rows'=>$result->toArray(),
  2471. 'count'=>$count
  2472. ];
  2473. if($result){
  2474. return Result::success($data);
  2475. }else{
  2476. return Result::error("查询失败",0);
  2477. }
  2478. }
  2479. /**
  2480. * 删除网站下的所有导航
  2481. * @param array $data
  2482. * @return array
  2483. */
  2484. public function delWebsiteAllCategory(array $data): array
  2485. {
  2486. $website_id = $data['website_id'];
  2487. $result = WebsiteCategory::where(['website_id'=>$website_id])->delete();
  2488. if($result){
  2489. return Result::success($result);
  2490. }else{
  2491. return Result::error("删除失败",0);
  2492. }
  2493. }
  2494. /**
  2495. * 获取网站下的某一个导航
  2496. * @param array $data
  2497. * @return array
  2498. */
  2499. public function getWebsiteCategoryOnes(array $data): array
  2500. {
  2501. $website_id = $data['website_id'];
  2502. $category_id = $data['category_id'];
  2503. $result = WebsiteCategory::where(['website_category.website_id'=>$website_id,'website_category.category_id'=>$category_id])
  2504. ->first();
  2505. if($result){
  2506. return Result::success($result);
  2507. }else{
  2508. return Result::error("查询失败",0);
  2509. }
  2510. }
  2511. /**
  2512. * 更新网闸下的某一个导航
  2513. * @param array $data
  2514. * @return array
  2515. */
  2516. public function upWebsiteCategoryones(array $data): array
  2517. {
  2518. $where = [
  2519. 'website_id'=>$data['website_id'],
  2520. 'category_id'=>$data['category_id'],
  2521. ];
  2522. $result = WebsiteCategory::where($where)->update($data);
  2523. if($result){
  2524. return Result::success($result);
  2525. }else{
  2526. return Result::error("更新失败",0);
  2527. }
  2528. }
  2529. /**
  2530. * 获取网站下的所有导航(包含子导航)
  2531. * @param array $data
  2532. * @return array
  2533. */
  2534. public function getWebsiteAllCategory(array $data): array
  2535. {
  2536. $where = [];
  2537. if(isset($data['website_id']) && !empty($data['website_id'])){
  2538. array_push($where,['website_category.website_id','=',$data['website_id']]);
  2539. }
  2540. if(isset($data['name']) && !empty($data['name'])){
  2541. array_push($where,['website_category.name','like','%'.$data['name'].'%']);
  2542. }
  2543. if(isset($data['alias']) && !empty($data['alias'])){
  2544. array_push($where,['website_category.alias','like','%'.$data['alias'].'%']);
  2545. }
  2546. if(isset($data['department_id']) && !empty($data['department_id'])){
  2547. array_push($where,['category.department_id','=',$data['department_id']]);
  2548. }
  2549. if(isset($data['city_id']) && !empty($data['city_id'])){
  2550. array_push($where,['category.city_id','=',$data['city_id']]);
  2551. }
  2552. $result = WebsiteCategory::where($where)
  2553. ->leftJoin("category",'website_category.category_id','category.id')
  2554. ->leftJoin("department",'category.department_id','department.id')
  2555. ->leftJoin("district",'category.city_id','district.id')
  2556. ->select("website_category.*","department.name as department_name","district.name as city_name")
  2557. ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])
  2558. ->get();
  2559. $count = WebsiteCategory::where($where)
  2560. ->leftJoin("category",'website_category.category_id','category.id')
  2561. ->leftJoin("department",'category.department_id','department.id')
  2562. ->leftJoin("district",'category.city_id','district.id')
  2563. ->count();
  2564. if (empty($result)) {
  2565. return Result::error("没有数据",0);
  2566. }
  2567. $data = [
  2568. 'rows'=>$result->toArray(),
  2569. 'count'=>$count
  2570. ];
  2571. if($result){
  2572. return Result::success($data);
  2573. }else{
  2574. return Result::error("查询失败",0);
  2575. }
  2576. if($result){
  2577. return Result::success($result);
  2578. }else{
  2579. return Result::error("查询失败",0);
  2580. }
  2581. }
  2582. /**
  2583. * 递归查询数据
  2584. * @param $id
  2585. * @param $ids
  2586. * @return string
  2587. */
  2588. public function getUnderlingUIds($id, $ids='')
  2589. {
  2590. $back = Category::where(['pid'=>$id])->get();
  2591. $back = $back->toArray();
  2592. if (!empty($back) && is_array($back)) {
  2593. foreach ($back as $v) {
  2594. //防止当前人的ID重复去查询,形成恶性循环
  2595. if ($v['id'] == $id) {
  2596. continue;
  2597. }
  2598. $back2 = Category::where(['pid'=>$id])->count('id');
  2599. if ($back2 > 0) {
  2600. $ids = $this->getUnderlingUIds($v['id'],$ids);
  2601. } else {
  2602. $ids .= ','.$v['id'];
  2603. }
  2604. }
  2605. }
  2606. $ids = $id.','.$ids.',';
  2607. $ids = str_replace(',,', ",", $ids);
  2608. $ids = trim($ids, ',');
  2609. return $ids;
  2610. }
  2611. /**
  2612. * 检测网站名称是否重复
  2613. * @param array $data
  2614. * @return array
  2615. */
  2616. public function checkWebsiteName(array $data): array
  2617. {
  2618. if(isset($data['id'])){
  2619. $data[] = ['id',"!=",$data['id']];
  2620. unset($data['id']);
  2621. }
  2622. $websiteInfo = Website::query()->where($data)->first();
  2623. if (empty($websiteInfo)) {
  2624. return Result::error("找不到网站",0);
  2625. }
  2626. return Result::success($websiteInfo->toArray());
  2627. }
  2628. /**
  2629. * 检测网站url是否重复
  2630. * @param array $data
  2631. * @return array
  2632. */
  2633. public function checkWebsiteUrl(array $data): array
  2634. {
  2635. $whereData = [];
  2636. if(isset($data['id'])){
  2637. $whereData = [['id',"!=",$data['id']]];
  2638. unset($data['id']);
  2639. }
  2640. $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
  2641. if (empty($websiteInfo)) {
  2642. return Result::error("找不到URL",0);
  2643. }
  2644. return Result::success($websiteInfo->toArray());
  2645. }
  2646. >>>>>>> bugfix_12_20_liu
  2647. }