PublicRpcService.php 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957
  1. <?php
  2. namespace App\JsonRpc;
  3. use _PHPStan_62c6a0a8b\OndraM\CiDetector\Env;
  4. use App\Model\BlackWord;
  5. use App\Model\Department;
  6. use App\Model\District;
  7. use App\Model\LetterOfComplaint;
  8. use App\Model\LetterType;
  9. use App\Model\LevelUser;
  10. use App\Model\UserLevel;
  11. use App\Tools\Result;
  12. use Hyperf\DbConnection\Db;
  13. use Hyperf\Di\Annotation\Inject;
  14. use Hyperf\RpcServer\Annotation\RpcService;
  15. use App\Service\MinioService;
  16. use Hyperf\Redis\Redis;
  17. use Overtrue\ChineseCalendar\Calendar;
  18. use App\Model\TemplateClass;
  19. use App\Model\Template;
  20. use App\Model\WebsiteTemplate;
  21. use App\Model\WebsiteTemplateInfo;
  22. use App\Model\Sector;
  23. use App\Model\Component;
  24. use App\Model\Link;
  25. use App\Model\FooterCategory;
  26. use App\Model\Size;
  27. use function Hyperf\Support\retry;
  28. use Hyperf\Paginator\Paginator;
  29. use App\Model\User;
  30. use App\Model\Website;
  31. use App\Constants\ErrorCode;
  32. use GuzzleHttp\Client;
  33. use GuzzleHttp\Exception\GuzzleException;
  34. use App\Model\SectorPlace;
  35. use App\Model\ComponentType;
  36. use App\Model\Article;
  37. use App\Model\WebsiteCategory;
  38. use App\Model\AdPlace;
  39. use App\Model\Company;
  40. use App\Model\WebsiteImg;
  41. use App\Model\SectorComponent;
  42. use App\Model\ComponentImg;
  43. use App\Model\TemplateRule;
  44. use App\Model\SectorType;
  45. use App\Model\StyleCode;
  46. #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  47. class PublicRpcService implements PublicRpcServiceInterface
  48. {
  49. #[Inject]
  50. protected Redis $redis;
  51. /**
  52. * @param array $data
  53. * @return array
  54. */
  55. public function getDistrictList(array $data): array
  56. {
  57. $where = [];
  58. if (isset($data['keyWord'])) {
  59. $where = [
  60. ['name', 'like', '%' . $data['keyWord'] . '%']
  61. ];
  62. }
  63. $result = [];
  64. if (isset($data['pageSize'])) {
  65. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
  66. $count = District::where($where)->count();
  67. $result = [
  68. 'rows' => $rep,
  69. 'count' => $count
  70. ];
  71. } else {
  72. $result = District::where($data)->orderBy("code", "asc")->get();
  73. }
  74. return $result ? Result::success($result) : Result::error("没有查到数据");
  75. }
  76. /**
  77. * @param array $data
  78. * @return array
  79. */
  80. public function getUserLevelList(array $data): array
  81. {
  82. $where = [];
  83. if (isset($data['keyWord'])) {
  84. $where = [
  85. ['name', 'like', '%' . $data['keyWord'] . '%'],
  86. ];
  87. }
  88. $result = [];
  89. if (isset($data['pageSize'])) {
  90. $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get();
  91. $count = UserLevel::where($where)->count();
  92. $result = [
  93. 'rows' => $rep,
  94. 'count' => $count,
  95. ];
  96. } else {
  97. $result = UserLevel::orderBy("id", "asc")->get();
  98. }
  99. return $result ? Result::success($result) : Result::error("没有查到数据");
  100. }
  101. /**
  102. * 添加用户等级
  103. * @param array $data
  104. * @return array
  105. */
  106. public function addUserLevel(array $data): array
  107. {
  108. LevelUser::insertGetId($data);
  109. return Result::success([]);
  110. }
  111. /**
  112. * 更新等级
  113. * @param array $data
  114. * @return array
  115. */
  116. public function updateUserLevel(array $data): array
  117. {
  118. $result = LevelUser::where(['id' => $data['id']])->update($data);
  119. if ($result) {
  120. return Result::success($result);
  121. }
  122. return Result::error("更新失败");
  123. }
  124. /**
  125. * 删除等级
  126. * @param array $data
  127. * @return array
  128. */
  129. public function delUserLevel(array $data): array
  130. {
  131. $result = LevelUser::where(['id' => $data['id']])->delete();
  132. if ($result) {
  133. return Result::success($result);
  134. }
  135. return Result::error("删除失败");
  136. }
  137. /**
  138. * 查询投诉举报信息
  139. * @param array $data
  140. * @return array
  141. */
  142. public function getLetterOfComplaint(array $data = []): array
  143. {
  144. var_dump("====");
  145. $where = [];
  146. if (isset($data['user_id']) && !empty($data['user_id'])) {
  147. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  148. }
  149. if (isset($data['nature']) && !empty($data['nature'])) {
  150. array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
  151. }
  152. if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
  153. array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
  154. }
  155. if (isset($data['status']) && !empty($data['status'])) {
  156. array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
  157. }
  158. $result = [];
  159. if (isset($data['pageSize'])) {
  160. $rep = LetterOfComplaint::where($where)
  161. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  162. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  163. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  164. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  165. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  166. ->select(
  167. "letter_of_complaint.*",
  168. "type_a.type_name as nature_name",
  169. "type_b.type_name as nature_name1",
  170. "type_c.type_name as nature_name0",
  171. "type_d.type_name as status_name",
  172. "type_e.type_name as nature_name3"
  173. )
  174. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
  175. $count = LetterOfComplaint::where($where)->count();
  176. if ($rep) {
  177. foreach ($rep as $val) {
  178. if ($val['judgment']) {
  179. $val['judgment'] = json_decode($val['judgment']);
  180. }
  181. if ($val['audio_and_video']) {
  182. $val['audio_and_video'] = json_decode($val['audio_and_video']);
  183. }
  184. if ($val['contract']) {
  185. $val['contract'] = json_decode($val['contract']);
  186. }
  187. if ($val['qualifications']) {
  188. $val['qualifications'] = json_decode($val['qualifications']);
  189. }
  190. }
  191. }
  192. $result = [
  193. 'rows' => $rep,
  194. 'count' => $count,
  195. ];
  196. } else {
  197. $result = LetterOfComplaint::where($where)
  198. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  199. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  200. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  201. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  202. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  203. ->select(
  204. "letter_of_complaint.*",
  205. "type_a.type_name as nature_name",
  206. "type_b.type_name as nature_name1",
  207. "type_c.type_name as nature_name0",
  208. "type_d.type_name as status_name",
  209. "type_e.type_name as nature_name3"
  210. )
  211. ->orderBy("letter_of_complaint.id", "desc")->get();
  212. }
  213. return $result ? Result::success($result) : Result::error("没有查到数据");
  214. }
  215. /**
  216. * 添加投诉举报信息
  217. * @param array $data
  218. * @return array
  219. */
  220. public function addLetterOfComplaint(array $data): array
  221. {
  222. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  223. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  224. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  225. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  226. unset($data['id']);
  227. $result = LetterOfComplaint::insertGetId($data);
  228. if (empty($result)) {
  229. return Result::error("创建失败", 0);
  230. } else {
  231. return Result::success(["id" => $result]);
  232. }
  233. }
  234. /**
  235. * 用户端更新投诉举报
  236. * @param array $data
  237. * @return array
  238. */
  239. public function userUpLetterOfComplaint(array $data): array
  240. {
  241. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  242. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  243. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  244. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  245. $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
  246. if (empty($result)) {
  247. return Result::error("创建失败", 0);
  248. } else {
  249. return Result::success(["id" => $result]);
  250. }
  251. }
  252. /**
  253. * 管理后台更新投诉举报信息
  254. * @param array $data
  255. * @return array
  256. */
  257. public function upLetterOfComplaint(array $data): array
  258. {
  259. var_dump("admin:", $data);
  260. $where = [
  261. 'id' => $data['id'],
  262. ];
  263. $filtered_array = array_filter($data, function ($value) {
  264. return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
  265. });
  266. $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
  267. $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
  268. $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
  269. $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
  270. unset($filtered_array['nature_name']);
  271. unset($filtered_array['type_name']);
  272. unset($filtered_array['nature_level_name']);
  273. unset($filtered_array['status_name']);
  274. unset($filtered_array['is_admin']);
  275. unset($filtered_array['type_level_name']);
  276. $result = LetterOfComplaint::where($where)->update($filtered_array);
  277. if ($result) {
  278. return Result::success($result);
  279. }
  280. return Result::error("更新失败", 0);
  281. }
  282. /**
  283. * 查询投诉举报记录
  284. * @param array $data
  285. * @return array
  286. */
  287. public function getLetterOfComplaintInfo(array $data): array
  288. {
  289. $where = [
  290. 'letter_of_complaint.id' => $data['id'],
  291. ];
  292. if (isset($data['user_id']) && !empty($data['user_id'])) {
  293. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  294. }
  295. $result = LetterOfComplaint::where($where)
  296. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  297. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  298. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  299. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  300. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  301. ->select(
  302. "letter_of_complaint.*",
  303. "type_a.type_name as nature_name",
  304. "type_b.type_name as nature_name1",
  305. "type_c.type_name as nature_name0",
  306. "type_d.type_name as status_name",
  307. "type_e.type_name as nature_name3"
  308. )
  309. ->first();
  310. return Result::success($result);
  311. }
  312. /**
  313. * 删除投诉举报信息
  314. * @param array $data
  315. * @return array
  316. */
  317. public function delLetterOfComplaint(array $data): array
  318. {
  319. $result = LetterOfComplaint::when($data, function ($query) use ($data) {
  320. if (isset($data['id']) && !empty($data['id'])) {
  321. $query->where(['id' => $data['id']]);
  322. }
  323. if (isset($data['user_id']) && !empty($data['user_id'])) {
  324. $query->where(['user_id' => $data['user_id']]);
  325. }
  326. })->delete();
  327. if (empty($result)) {
  328. return Result::error("删除失败", 0);
  329. } else {
  330. return Result::success();
  331. }
  332. }
  333. /**
  334. * 获取举报信息类型
  335. * @param array $data
  336. * @return array
  337. */
  338. public function getLetterType(array $data): array
  339. {
  340. $where = [];
  341. if (isset($data['type'])) {
  342. array_push($where, ['type', '=', $data['type']]);
  343. }
  344. if (isset($data['pid']) && $data['pid'] > 0) {
  345. array_push($where, ['pid', '=', $data['pid']]);
  346. }
  347. $result = LetterType::where($where)->orderBy('sort', 'asc')->get();
  348. return $result ? Result::success($result) : Result::error("没有查到数据");
  349. }
  350. /**
  351. * 更新举报类型
  352. * @param array $data
  353. * @return array
  354. */
  355. public function upLetterType(array $data): array
  356. {
  357. return [];
  358. }
  359. /**
  360. * 添加举报类型
  361. * @param array $data
  362. * @return array
  363. */
  364. public function addLetterType(array $data): array
  365. {
  366. $result = LetterType::insertGetId($data);
  367. if (empty($result)) {
  368. return Result::error("创建失败", 0);
  369. } else {
  370. return Result::success(["id" => $result]);
  371. }
  372. }
  373. /**
  374. * 删除举报类型
  375. * @param array $data
  376. * @return array
  377. */
  378. public function delLetterType(array $data): array
  379. {
  380. $result = LetterType::where('id', $data['id'])->delete();
  381. if (empty($result)) {
  382. return Result::error("删除失败", 0);
  383. } else {
  384. return Result::success();
  385. }
  386. }
  387. /**
  388. * 检测是否已经被接案
  389. * @param array $data
  390. * @return array
  391. */
  392. public function checkMeasure(array $data): array
  393. {
  394. $where = [
  395. 'id' => $data['id'],
  396. ];
  397. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  398. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  399. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  400. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  401. return Result::success();
  402. } else {
  403. return Result::error("您不能处理其他人已经接过的案件", 0);
  404. }
  405. }
  406. /**
  407. * 后台获取职能部门
  408. * @param array $data
  409. * @return array
  410. */
  411. public function getZhinengbumenList(array $data): array
  412. {
  413. // 获取分页参数,默认每页 10 条记录
  414. $page = isset($data['page']) ? (int) $data['page'] : 1;
  415. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  416. // 查询数据并分页
  417. $query = Department::query();
  418. // 可以在这里添加更多的查询条件
  419. if (isset($data['search'])) {
  420. $query->where('name', 'like', '%' . $data['search'] . '%');
  421. }
  422. // 执行分页查询
  423. $result = $query->paginate($perPage, ['*'], 'page', $page);
  424. // 返回分页结果
  425. return Result::success([
  426. 'count' => $result->total(),
  427. 'current_page' => $result->currentPage(),
  428. 'last_page' => $result->lastPage(),
  429. 'pagesize' => $result->perPage(),
  430. 'rows' => $result->items(),
  431. ]);
  432. }
  433. /**
  434. * 添加获取职能部门
  435. * @param array $data
  436. * @return array
  437. */
  438. public function addZhinengbumen(array $data): array
  439. {
  440. $result = Department::insertGetId($data);
  441. if (empty($result)) {
  442. return Result::error("创建失败", 0);
  443. } else {
  444. return Result::success(["id" => $result]);
  445. }
  446. }
  447. public function delZhinengbumen(array $data): array
  448. {
  449. $result = Department::where('id', $data['id'])->delete();
  450. if (empty($result)) {
  451. return Result::error("删除失败", 0);
  452. } else {
  453. return Result::success();
  454. }
  455. }
  456. public function getZhinengbumen(array $data): array
  457. {
  458. $result = Department::where('id', $data['id'])
  459. ->orderBy('department', 'desc')
  460. ->first();
  461. return Result::success($result);
  462. }
  463. public function getPidZhinengbumen(array $data): array
  464. {
  465. if (empty($data['pid'])) {
  466. $data['pid'] = 0;
  467. }
  468. $result = Department::where('pid', $data['pid'])->get();
  469. return Result::success($result);
  470. }
  471. public function modZhinengbumen(array $data): array
  472. {
  473. $result = Department::where('id', $data['id'])->update($data);
  474. if (empty($result)) {
  475. return Result::error("修改失败", 0);
  476. } else {
  477. return Result::success();
  478. }
  479. }
  480. /**
  481. * 查询职能列表
  482. * @param array $data
  483. * @return array
  484. */
  485. public function getDepartment(array $data): array
  486. {
  487. $where = [];
  488. if (isset($data['pid'])) {
  489. $where = [
  490. 'pid' => $data['pid'] ?? 0
  491. ];
  492. }
  493. $result = Department::when(!empty($where), function ($query) use ($where) {
  494. $query->where($where);
  495. })->orderBy("sort", "desc")->get();
  496. if (empty($result)) {
  497. return Result::error("查询失败", 0);
  498. } else {
  499. return Result::success($result);
  500. }
  501. }
  502. /**
  503. * 获取所有的buckets
  504. * @param array $data
  505. * @return array
  506. */
  507. public function getBuckets(array $data): array
  508. {
  509. $result = new MinioService();
  510. // 调用服务层的方法获取存储桶列表
  511. $bucketsResponse = $result->listBuckets();
  512. // 直接返回服务层生成的响应
  513. return Result::success($bucketsResponse['data']);
  514. }
  515. /**
  516. * 上传文件
  517. * @param array $data
  518. * @return array
  519. */
  520. public function uploadFile(array $data): array
  521. {
  522. $result = new MinioService();
  523. $rep = $result->uploadFile($data);
  524. if ($rep['code'] == 200) {
  525. return Result::success($rep['data']);
  526. } else {
  527. return Result::error("上传失败!");
  528. }
  529. }
  530. /**
  531. * 黑名单管理
  532. * @param array $data
  533. * @return array
  534. */
  535. public function getBlackWordList(array $data): array
  536. {
  537. $result = BlackWord::when($data, function ($query) use ($data) {
  538. if (isset($data['name']) && $data['name']) {
  539. $query->where('black_word.name', 'like', '%' . $data['name'] . '%');
  540. }
  541. })->orderBy('black_word.id', 'desc')
  542. ->paginate(
  543. intval($data['pageSize']),
  544. [
  545. 'black_word.*',
  546. ],
  547. 'page',
  548. intval($data['page'])
  549. );
  550. $count = $result->total();
  551. $returnData = [
  552. 'rows' => $result->items(),
  553. 'count' => $count
  554. ];
  555. return Result::success($returnData);
  556. }
  557. /**
  558. * 添加黑名单
  559. * @param array $data
  560. * @return array
  561. */
  562. public function addBlackWord(array $data): array
  563. {
  564. Db::beginTransaction();
  565. try {
  566. $info = BlackWord::where(['name' => $data['name']])->first();
  567. if ($info) {
  568. Db::rollBack();
  569. return Result::error("该黑名单已存在", 0);
  570. }
  571. $data['type'] = 10;
  572. $result = BlackWord::insertGetId($data);
  573. $redisKey = 'black_word';
  574. $this->redis->sAdd($redisKey, $data['name']);
  575. Db::commit();
  576. return Result::success(["id" => $result]);
  577. } catch (\Exception $e) {
  578. Db::rollBack();
  579. return Result::error("创建失败" . $e->getMessage(), 0);
  580. }
  581. }
  582. /**
  583. * 删除黑名单
  584. * @param array $data
  585. * @return array
  586. */
  587. public function delBlackWord(array $data): array
  588. {
  589. Db::beginTransaction();
  590. try {
  591. BlackWord::where(['name' => $data['name']])->delete();
  592. $redisKey = 'black_word';
  593. $this->redis->sRem($redisKey, $data['name']);
  594. Db::commit();
  595. return Result::success([]);
  596. } catch (\Exception $e) {
  597. Db::rollBack();
  598. return Result::error("删除失败" . $e->getMessage(), 0);
  599. }
  600. }
  601. /**
  602. * 修改违禁词
  603. * @param array $data
  604. * @return array
  605. */
  606. public function upBlackWord(array $data): array
  607. {
  608. Db::beginTransaction();
  609. try {
  610. $checkInfo = BlackWord::where(['name' => $data['name']])->first();
  611. if ($checkInfo) {
  612. Db::rollBack();
  613. return Result::error("该违禁词已经存在", 0);
  614. }
  615. $blackWordInfo = BlackWord::where(['id' => $data['id']])->first();
  616. if ($blackWordInfo) {
  617. //先删除redis
  618. $blackWordInfo = $blackWordInfo->toArray();
  619. $redisKey = 'black_word';
  620. $this->redis->sRem($redisKey, $blackWordInfo['name']);
  621. $this->redis->sAdd($redisKey, $data['name']);
  622. BlackWord::where(['id' => $data['id']])->update(['name' => $data['name']]);
  623. Db::commit();
  624. return Result::success([]);
  625. } else {
  626. Db::rollBack();
  627. return Result::error("系统错误", 0);
  628. }
  629. } catch (\Exception $e) {
  630. Db::rollBack();
  631. return Result::error("修改失败" . $e->getMessage(), 0);
  632. }
  633. }
  634. /**
  635. * 获取风格
  636. * @return void
  637. */
  638. public function getTemplateClassList(array $data): array
  639. {
  640. $where = [];
  641. if (isset($data['name']) && $data['name']) {
  642. array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
  643. }
  644. if (isset($data['keyword']) && $data['keyword']) {
  645. array_push($where, ['template_class.keyword', 'like', '%' . $data['keyword'] . '%']);
  646. }
  647. $template = TemplateClass::when($where, function ($query) use ($where) {
  648. $query->where($where);
  649. });
  650. $count = $template->count();
  651. // $countQuery = clone $template;
  652. $row = $template
  653. ->leftJoin('template', function ($join) {
  654. $join->on('template_class.class_id', '=', 'template.template_class_id');
  655. })
  656. ->select('template_class.*', DB::raw('COUNT(template.template_class_id) as template_count'))
  657. ->groupBy('template_class.id')
  658. ->orderBy('template_class.id', 'desc')
  659. ->offset(($data['page'] - 1) * $data['pageSize'])
  660. ->limit($data['pageSize'])
  661. ->get();
  662. $result = [
  663. 'rows' => $row,
  664. 'count' => $count,
  665. ];
  666. if ($row->isEmpty()) {
  667. return Result::error("暂无风格", 0);
  668. } else {
  669. return Result::success($result);
  670. }
  671. }
  672. /**
  673. * 添加风格
  674. * @param
  675. * @return void
  676. */
  677. public function addTemplateClass(array $data): array
  678. {
  679. $data['keyword'] = json_encode($data['keyword']);
  680. $template_class = TemplateClass::where('name', $data['name'])
  681. ->orWhere('class_id', $data['class_id'])
  682. ->first();
  683. if ($template_class) {
  684. return Result::error("风格名称或者风格编号已存在,不可添加!", 0);
  685. }
  686. $result = TemplateClass::insertGetId($data);
  687. if (empty($result)) {
  688. return Result::error("创建风格失败", 0);
  689. } else {
  690. return Result::success(["id" => $result]);
  691. }
  692. }
  693. /**
  694. * 更新风格
  695. * @param array $data
  696. * @return array
  697. */
  698. public function upTemplateClass(array $data): array
  699. {
  700. $where = [
  701. 'id' => $data['id'],
  702. ];
  703. $template_class = TemplateClass::where($where)->first();
  704. if (empty($template_class)) {
  705. return Result::error("未查询到风格", 0);
  706. }
  707. if ($template_class->type == 1) {
  708. return Result::error("默认风格不能修改", 0);
  709. }
  710. $template = TemplateClass::where('id', '!=', $data['id'])
  711. // ->where(['name' => $data['name']])
  712. // ->orWhere(['class_id' => $data['class_id']])
  713. ->where(function ($query) use ($data) {
  714. $query->where('name', $data['name'])
  715. ->orWhere('class_id', $data['class_id']);
  716. })
  717. ->first();
  718. if ($template) {
  719. return Result::error("风格名称或者风格编号已存在,不可编辑!", 0);
  720. }
  721. $updateData = [
  722. 'name' => $data['name'],
  723. 'keyword' => json_encode($data['keyword']),
  724. 'class_id' => $data['class_id'],
  725. ];
  726. $result = TemplateClass::where($where)->update($updateData);
  727. if (empty($result)) {
  728. return Result::error("更新失败", 0);
  729. } else {
  730. return Result::success($result);
  731. }
  732. }
  733. /**
  734. * 删除风格
  735. * @param array $data
  736. * @return array
  737. */
  738. public function delTemplateClass(array $data): array
  739. {
  740. $where = [
  741. 'id' => $data['id'],
  742. ];
  743. $template_class = TemplateClass::where($where)->first();
  744. if (empty($template_class)) {
  745. return Result::error("未查询到风格", 0);
  746. }
  747. if ($template_class->type == 1) {
  748. return Result::error("默认风格不能删除", 0);
  749. }
  750. $template = Template::where('template_class_id', $template_class['class_id'])->get();
  751. if (!empty($template->all())) {
  752. try {
  753. // 默认风格 1
  754. Db::beginTransaction();
  755. $template = Template::where('template_class_id', $template['class_id'])->update(['template_class_id' => 1]);
  756. if (empty($template)) {
  757. Db::rollBack();
  758. return Result::error("删除失败", 0);
  759. }
  760. $result = TemplateClass::where($where)->delete();
  761. } catch (\Exception $e) {
  762. return Result::error("删除失败" . $e->getMessage(), 0);
  763. }
  764. } else {
  765. $result = TemplateClass::where('id', $data['id'])->delete();
  766. }
  767. if (empty($result)) {
  768. return Result::error("删除失败", 0);
  769. }
  770. return Result::success($result);
  771. }
  772. /**
  773. * 根据风格名称-获取获取所有风格
  774. * @param array $data
  775. * @return array
  776. */
  777. public function getTemplateClass(array $data): array
  778. {
  779. $where = [];
  780. if (!empty($data['template_name'])) {
  781. $where['name'] = $data['template_name'];
  782. }
  783. $result = TemplateClass::where($where)->get();
  784. if (empty($result)) {
  785. return Result::error("暂无风格", 0);
  786. }
  787. return Result::success($result);
  788. }
  789. /**
  790. * 获取皮肤列表
  791. * @param array $data
  792. * @return array
  793. */
  794. public function getTemplateList(array $data): array
  795. {
  796. $where = [];
  797. if (!empty($data['template_class_id'])) {
  798. $where['template_class_id'] = $data['template_class_id'];
  799. }
  800. if (!empty($data['template_name'])) {
  801. array_push($where, ['template_name', 'like', '%' . $data['template_name'] . '%']);
  802. }
  803. if (!empty($data['template_keyword'])) {
  804. array_push($where, ['template_keyword', 'like', '%' . $data['template_keyword'] . '%']);
  805. }
  806. $result = Template::where($where)
  807. ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
  808. ->select('template.*', 'template_class.name as template_class_name')
  809. ->orderBy('template.template_id','desc')
  810. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  811. if (empty($result)) {
  812. return Result::error("暂无皮肤", 0);
  813. }
  814. return Result::success($result);
  815. }
  816. public function getTemplateInfo(array $data): array
  817. {
  818. $result = Template::where('template.id', $data['id'])
  819. ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
  820. ->select('template.*', 'template_class.name as template_class_name')
  821. ->first();
  822. if (empty($result)) {
  823. return Result::error("暂无皮肤", 0);
  824. }
  825. return Result::success($result);
  826. }
  827. /**
  828. * 添加皮肤
  829. * @param array $data
  830. * @return array
  831. */
  832. public function addTemplate(array $data): array
  833. {
  834. var_dump($data);
  835. unset($data['user_id']);
  836. $template = Template::where('template_name', $data['template_name'])
  837. ->orWhere('template_id', $data['template_id'])
  838. ->first();
  839. if ($template) {
  840. return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
  841. }
  842. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  843. $page_type = json_decode($data['page_type'], true);
  844. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  845. $result = Template::insertGetId($data);
  846. if (empty($result)) {
  847. return Result::error("创建失败", 0);
  848. } else {
  849. return Result::success($result);
  850. }
  851. }
  852. /**
  853. * 删除皮肤
  854. * @param array $data
  855. * @return array
  856. */
  857. public function delTemplate(array $data): array
  858. {
  859. $rector = Sector::where('template_id', $data['id'])->first();
  860. if (!empty($rector)) {
  861. return Result::error("此皮肤已被绑定通栏,不可删除", 0);
  862. }
  863. $template = Template::where('id', $data['id'])->first();
  864. if(empty($template)){
  865. return Result::error("此皮肤不存在!", 0);
  866. }
  867. $web_template = WebsiteTemplateInfo::where('template_id', $template['template_id'])->first();
  868. if (!empty($web_template)) {
  869. return Result::error("此皮肤已被绑定网站,不可删除", 0);
  870. }
  871. // if ($template->type == 1) {
  872. // return Result::error("默认皮肤不能删除", 0);
  873. // }
  874. $component_img = ComponentImg::where('template_id',$template['template_id'])->get();
  875. if(!empty($component_img) && $component_img->count() > 0){
  876. return Result::error('此皮肤已绑定组件预览图,不可删除!'.$component_img);
  877. }
  878. $result = Template::where('id', $data['id'])->delete();
  879. var_dump($result, '-------------------delete');
  880. if ($result) {
  881. return Result::success($result);
  882. } else {
  883. return Result::error("删除失败", 0);
  884. }
  885. }
  886. /**
  887. * 更新皮肤
  888. * @param array $data
  889. * @return array
  890. */
  891. public function updateTemplate(array $data): array
  892. {
  893. unset($data['user_id']);
  894. $template = Template::where('id', $data['id'])
  895. ->first();
  896. if (empty($template)) {
  897. return Result::error("此皮肤不存在!", 0);
  898. }
  899. $template = Template::where('id', '!=', $data['id'])
  900. ->where(function ($query) use ($data) {
  901. $query->where('template_name', $data['template_name'])
  902. ->orWhere('template_id', $data['template_id']);
  903. })
  904. ->first();
  905. if ($template) {
  906. return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
  907. }
  908. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  909. $page_type = json_decode($data['page_type'], true);
  910. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  911. $result = Template::where('id', $data['id'])->update($data);
  912. var_dump($result, '-------------------update');
  913. if (!$result) {
  914. return Result::error("更新失败", 0);
  915. } else {
  916. return Result::success('更新成功');
  917. }
  918. }
  919. /**
  920. * 获取所有尺寸
  921. * @param array $data
  922. * @return array
  923. */
  924. public function getAllSize(array $data): array
  925. {
  926. if(isset($data['id']) && !empty($data['id'])){
  927. $result = Size::where('id', $data['id'])->get()->all();
  928. }else{
  929. $result = Size::get()->all();
  930. }
  931. if(empty($result)){
  932. return Result::error("暂无尺寸", 0);
  933. }
  934. return Result::success($result);
  935. }
  936. /**
  937. * 根据皮肤名称-获取所有皮肤
  938. * @param array $data
  939. * @return array
  940. */
  941. public function getAllTemplate(array $data): array
  942. {
  943. $where = [];
  944. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  945. $where[] = ['template_class_id', $data['template_class_id']];
  946. }
  947. if (isset($data['template_name']) && !empty($data['template_name'])) {
  948. $where[] = ['template_name', 'like', '%' . $data['template_name'] . '%'];
  949. }
  950. $result = Template::where($where)->get()->all();
  951. if (empty($result)) {
  952. return Result::error("暂无皮肤", 0);
  953. }
  954. return Result::success($result);
  955. }
  956. /**
  957. * 获取通栏列表
  958. * @param array $data
  959. * @return array
  960. */
  961. public function getSectorList(array $data): array
  962. {
  963. $where = [];
  964. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  965. $where['template.template_class_id'] = $data['template_class_id'];
  966. }
  967. if (isset($data['template_id']) && !empty($data['template_id'])) {
  968. array_push($where, ['template.template_id', $data['template_id']]);
  969. }
  970. if (isset($data['sector_name']) && !empty($data['sector_name'])) {
  971. array_push($where, ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%']);
  972. }
  973. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])) {
  974. $size_id = Size::where('width', 'like', '%' . $data['width'] . '%')->where('height', 'like', '%' . $data['height'] . '%')->pluck('id');
  975. } else if (isset($data['width']) && !empty($data['width'])) {
  976. $size_id = Size::where('width', 'like', '%' . $data['width'] . '%')->pluck('id');
  977. } else if (isset($data['height']) && !empty($data['height'])) {
  978. $size_id = Size::where('height', 'like', '%' . $data['height'] . '%')->pluck('id');
  979. } else {
  980. $size_id = [];
  981. }
  982. if(isset($data['page_type']) && !empty($data['page_type'])){
  983. array_push($where, ['sector.page_type', 'like', '%' . $data['page_type'] . '%']);
  984. }
  985. $result = Sector::when(!empty($size_id), function ($query) use ($size_id) {
  986. $query->whereIn('sector.size_id', $size_id);
  987. })
  988. ->leftJoin('size', 'size.id', '=', 'sector.size_id')
  989. ->leftJoin('template', 'template.template_id', '=', 'sector.template_id')
  990. ->leftJoin('template_class', 'template_class.class_id', '=', 'template.template_class_id')
  991. ->leftJoin('sector_place', 'sector_place.sector_type', '=', 'sector.place_type')
  992. ->where($where)
  993. ->where('sector_place.type_id', 1)
  994. ->select('sector.*', 'size.width', 'size.height', 'template_class.name as class_name', 'template_class.class_id', 'template.template_name',
  995. 'sector_place.name as place_name', 'sector_place.sector_img as place_img')
  996. ->orderBy('sector.id', 'desc')
  997. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  998. if(empty($result)){
  999. return Result::error('暂无通栏!');
  1000. }
  1001. return Result::success($result);
  1002. }
  1003. /**
  1004. * 获取通栏详情
  1005. * @param array $data
  1006. * @return array
  1007. */
  1008. public function getSectorInfo(array $data): array
  1009. {
  1010. // $where = [];
  1011. $where[] = ['sector.id', '=', $data['id']];
  1012. $result = Sector::where($where)
  1013. ->leftJoin('template', 'template.template_id', '=', 'sector.template_id')
  1014. ->select('sector.*','template.template_name','template.template_id')
  1015. ->orderBy('sector.id', 'desc')
  1016. ->first();
  1017. $result['component'] = SectorComponent::where('sector_component.sector_id', $data['id'])
  1018. ->leftJoin('component', 'component.component_type', '=', 'sector_component.component_id')
  1019. ->select('component.component_type','sector_component.sort_id','component.component_name')
  1020. ->get()->all();
  1021. // $sorts = array_values(array_unique(array_column($components, 'sort_id')));
  1022. // $result['component'] = $components;
  1023. $result['place'] = SectorPlace::where('sector_place.sector_type', $result['place_type'])
  1024. ->where('sector_place.type_id',1)
  1025. ->select('sector_place.sector_img','sector_place.map')
  1026. ->first();
  1027. // $key_num = 0;
  1028. // foreach($result['place'] as $key => $value){
  1029. // if($value['type_id'] == 1){
  1030. // $sector_place['sector_plate'] = $value;
  1031. // }else{
  1032. // $sector_place['component_place'][$key_num] = $value;
  1033. // $key_num++;
  1034. // }
  1035. // }
  1036. // $result['place'] = $sector_place;
  1037. if (empty($result)) {
  1038. return Result::error('此通栏不存在!');
  1039. }
  1040. return Result::success($result);
  1041. }
  1042. /**
  1043. * 获取经纬度信息
  1044. * @return void
  1045. */
  1046. public function getIpInfo(array $data): array
  1047. {
  1048. if (empty($data['ip'])) {
  1049. // 在RPC服务中,依赖$_SERVER是不可靠的,强制要求调用方传入IP
  1050. return Result::error('IP地址不能为空!');
  1051. }
  1052. $client_ip = $data['ip'];
  1053. try {
  1054. // 直接从容器获取 Guzzle 客户端实例
  1055. /** @var \GuzzleHttp\Client $client */
  1056. $client = \Hyperf\Context\ApplicationContext::getContainer()->get(Client::class);
  1057. // 使用新的 GeoJS API 地址
  1058. $api_url = "https://get.geojs.io/v1/ip/geo/{$client_ip}.json";
  1059. // 将 timeout 作为请求选项传递
  1060. $response = $client->get($api_url, ['timeout' => 5]);
  1061. if ($response->getStatusCode() !== 200) {
  1062. return Result::error('IP查询接口请求失败,状态码:' . $response->getStatusCode());
  1063. }
  1064. $ip_info = json_decode($response->getBody()->getContents(), true);
  1065. // GeoJS 的成功响应不包含 'status' 字段,直接检查关键数据是否存在
  1066. if ($ip_info && isset($ip_info['latitude']) && isset($ip_info['longitude'])) {
  1067. // GeoJS 返回的经纬度是字符串,转换为浮点数
  1068. $ip_info['latitude'] = floatval($ip_info['latitude']);
  1069. $ip_info['longitude'] = floatval($ip_info['longitude']);
  1070. return Result::success($ip_info);
  1071. }
  1072. // 如果返回的数据不符合预期,提供一个通用错误
  1073. $errorMessage = $ip_info['message'] ?? '获取IP地理位置信息失败';
  1074. return Result::error($errorMessage);
  1075. } catch (GuzzleException $e) {
  1076. // 这个异常会给出详细的网络错误信息,如超时、无法解析域名等
  1077. return Result::error('请求IP查询接口异常: ' . $e->getMessage());
  1078. } catch (\Throwable $e) {
  1079. return Result::error('获取IP信息时发生未知错误: ' . $e->getMessage());
  1080. }
  1081. }
  1082. /**
  1083. * 获取天气
  1084. * @param array $data
  1085. * @return array
  1086. */
  1087. public function getWeatherInfo(array $data): array
  1088. {
  1089. $month = $data['month'] ?? date('m');
  1090. $day = $data['day'] ?? date('d');
  1091. // 使用缓存键
  1092. $cacheKey = "tsbb_data_weather_{$month}_{$day}";
  1093. // 尝试从缓存获取数据
  1094. $container = \Hyperf\Context\ApplicationContext::getContainer();
  1095. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  1096. if ($cachedData = $cache->get($cacheKey)) {
  1097. return Result::success(unserialize($cachedData));
  1098. }
  1099. $location = $data['latitude'] . ":" . $data['longitude'];
  1100. $api_url = "https://api.seniverse.com/v3/weather/now.json?key=" . \Hyperf\Support\env('WEATHER_KEY') . "&location=" . $location . "&language=zh-Hans&unit=c";
  1101. $ch = curl_init($api_url);
  1102. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1103. $response = curl_exec($ch);
  1104. curl_close($ch);
  1105. // 解析 JSON 响应
  1106. $WeatherInfo = json_decode($response, true);
  1107. // 缓存结果,设置1小时过期
  1108. $cache->set($cacheKey, serialize($WeatherInfo), 3600);
  1109. if ($WeatherInfo) {
  1110. return Result::success($WeatherInfo);
  1111. } else {
  1112. return Result::error("获取天气失败", 0);
  1113. }
  1114. }
  1115. /**
  1116. * 获取农历信息
  1117. * @return void
  1118. */
  1119. public function getCalendar(array $data): array
  1120. {
  1121. $calendar = new Calendar();
  1122. $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
  1123. return Result::success($result);
  1124. }
  1125. /**
  1126. * 添加通栏
  1127. * @param array $data
  1128. * @return array
  1129. */
  1130. public function addSector(array $data): array
  1131. {
  1132. unset($data['user_id']);
  1133. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1134. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1135. $data['page_type'] = json_encode($data['page_type']);
  1136. $template = Template::where('template_id', $data['template_id'])
  1137. ->first();
  1138. if (empty($template)) {
  1139. return Result::error('皮肤不存在!');
  1140. }
  1141. $sector_id = Sector::where('sector_id',$data['sector_id'])->where('template_id',$data['template_id'])->first();
  1142. if(!empty($sector_id)){
  1143. return Result::error('通栏编号已存在!');
  1144. }
  1145. $sector_place = SectorPlace::where('sector_type',$data['place_type'])->get();
  1146. if(empty($sector_place)){
  1147. return Result::error('位置不存在!');
  1148. }
  1149. $sort = json_decode($data['component_code'],true);
  1150. $sector = 0;
  1151. // $flattened = [];
  1152. // $sector = [];
  1153. $sector_component = [];
  1154. foreach ($sort as $key => $subArray) {
  1155. foreach ($subArray as $k => $item) {
  1156. // // $component[] = $item;
  1157. $sector_component[] = [
  1158. 'sector_id' => $data['sector_id'],
  1159. 'component_id' => $subArray[$k],
  1160. 'sort_id' => $key + 1,
  1161. 'place_id' => $data['place_type'],
  1162. // 'sectorid' => $data['id'],
  1163. ];
  1164. // // // ---------同步通栏的sort_id到组件之中,目前已废弃,涉及到批量修改------
  1165. // // $componentTypes[] = $item;
  1166. // // $components[] = [
  1167. // // 'sort_id' => $key + 1,
  1168. // // 'component_type' => $item,
  1169. // // ];
  1170. // // $place_ids[] = $data['place_type'];
  1171. }
  1172. }
  1173. // $component_num = count($component);
  1174. // $count = count(array_unique($component));
  1175. // 使用array_map批量替换sector_id
  1176. // return Result::success($sector_component);
  1177. if(count($sort) != $data['component_num']){
  1178. return Result::error('组件关联错误!');
  1179. }
  1180. // 通栏分类:1:资讯类:2:通栏广告类;3:混合类;4:头条类;5:轮播图类;
  1181. $sector_code = [
  1182. $data['sector_id'] => [
  1183. 'sectorName' => $data['sector_name'],
  1184. 'sectorHeight' => $data['pic_height'],
  1185. 'sectorImg' => $data['sector_img'],
  1186. ]
  1187. ];
  1188. // return Result::success($sector_code);
  1189. $data['sector_code'] = json_encode($sector_code);
  1190. Db::beginTransaction();
  1191. try {
  1192. $sector = Sector::insertGetId($data);
  1193. if (empty($sector)) {
  1194. Db::rollBack();
  1195. return Result::error('添加失败');
  1196. }
  1197. $sector_com = array_map(function ($item) use ($sector) {
  1198. // 替换当前记录的sector_id为变量值(保留其他字段不变)
  1199. $item['sectorid'] = $sector;
  1200. return $item;
  1201. }, $sector_component);
  1202. // Db::rollBack();
  1203. // return Result::success($sector_com);
  1204. $com_sector = SectorComponent::insert($sector_com);
  1205. if(empty($com_sector)){
  1206. Db::rollBack();
  1207. return Result::error('通栏关联组件失败!');
  1208. }
  1209. // ---------同步通栏的sort_id到组件之中,目前已废弃,涉及到批量修改------
  1210. // 查询数据库中已存在的component_type(只保留存在的记录)
  1211. // $existingTypes = Component::whereIn('component_type', $componentTypes)
  1212. // ->pluck('component_type') // 提取存在的component_type
  1213. // ->toArray();
  1214. // if(empty($existingTypes)){
  1215. // Db::rollBack();
  1216. // return Result::error('组件不存在!');
  1217. // }
  1218. // // var_dump($existingTypes);
  1219. // // 3. 过滤$components数组,只保留数据库中已存在的记录(核心:避免新增)
  1220. // $updateData = array_filter($components, function ($item) use ($existingTypes) {
  1221. // return in_array($item['component_type'], $existingTypes);
  1222. // });
  1223. // // 4. 执行upsert(此时$updateData中只有已存在的记录,不会新增)
  1224. // if (!empty($updateData)) {
  1225. // $component_sort = Component::upsert($updateData,['component_type'],['sort_id']);
  1226. // }
  1227. // if(empty($component_sort)){
  1228. // Db::rollBack();
  1229. // return Result::error('组件位置关联失败!');
  1230. // }
  1231. Db::commit();
  1232. return Result::success($sector);
  1233. } catch (\Exception $e) {
  1234. Db::rollBack();
  1235. return Result::error($e->getMessage());
  1236. }
  1237. }
  1238. /**
  1239. * 删除通栏
  1240. * @param array $data
  1241. * @return array
  1242. */
  1243. public function delSector(array $data): array
  1244. {
  1245. $sector = Sector::where('id', $data['id'])->first();
  1246. if (empty($sector)) {
  1247. return Result::error('通栏不存在!');
  1248. }
  1249. Db::beginTransaction();
  1250. try {
  1251. $component_id = SectorComponent::where('sectorid', $data['id'])->delete();
  1252. if (empty($component_id)) {
  1253. Db::rollBack();
  1254. return Result::error('解除相关组件关联关系失败!');
  1255. }
  1256. $result = Sector::where('id', $data['id'])->delete();
  1257. if (empty($result)) {
  1258. Db::rollBack();
  1259. return Result::error('通栏删除失败!');
  1260. }
  1261. Db::commit();
  1262. return Result::success('通栏删除成功!');
  1263. } catch (\Exception $e) {
  1264. Db::rollBack();
  1265. return Result::error($e->getMessage());
  1266. }
  1267. }
  1268. /**
  1269. * 修改通栏
  1270. * @param array $data
  1271. * @return array
  1272. */
  1273. public function updateSector(array $data): array
  1274. {
  1275. unset($data['user_id']);
  1276. $sector = Sector::where('id', $data['id'])->first();
  1277. if (empty($sector)) {
  1278. return Result::error('通栏不存在!');
  1279. }
  1280. if($sector['sector_id'] != $data['sector_id']){
  1281. $sector_id = Sector::where('sector_id',$data['sector_id'])->where('template_id',$data['template_id'])->first();
  1282. if(!empty($sector_id)){
  1283. return Result::error('通栏编号已存在!');
  1284. }
  1285. }
  1286. $sector_code = [
  1287. $data['sector_id'] => [
  1288. 'sectorName' => $data['sector_name'],
  1289. 'sectorHeight' => $data['pic_height'],
  1290. 'sectorImg' => $data['sector_img'],
  1291. ]
  1292. ];
  1293. // return Result::success($sector_code);
  1294. $data['sector_code'] = json_encode($sector_code);
  1295. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1296. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1297. $data['page_type'] = json_encode($data['page_type']);
  1298. $template = Template::where('template_id', $data['template_id'])
  1299. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
  1300. ->first();
  1301. if (empty($template)) {
  1302. return Result::error('皮肤不存在!');
  1303. }
  1304. $sort = json_decode($data['component_code'],true);
  1305. $sector_component = [];
  1306. foreach ($sort as $key => $subArray) {
  1307. foreach ($subArray as $k => $item) {
  1308. // // $component[] = $item;
  1309. $sector_component[] = [
  1310. 'sector_id' => $data['sector_id'],
  1311. 'component_id' => $subArray[$k],
  1312. 'sort_id' => $key + 1,
  1313. 'place_id' => $data['place_type'],
  1314. 'sectorid' => $data['id'],
  1315. ];
  1316. // // // ---------同步通栏的sort_id到组件之中,目前已废弃,涉及到批量修改------
  1317. // // $componentTypes[] = $item;
  1318. // // $components[] = [
  1319. // // 'sort_id' => $key + 1,
  1320. // // 'component_type' => $item,
  1321. // // ];
  1322. // // $place_ids[] = $data['place_type'];
  1323. }
  1324. }
  1325. if(count($sort) != $data['component_num']){
  1326. return Result::error('组件关联错误!');
  1327. }
  1328. $data['sector_code'] = json_encode($sector_code);
  1329. Db::beginTransaction();
  1330. try {
  1331. $com_sector = SectorComponent::where('sectorid', $data['id'])->pluck('component_id');
  1332. if(empty($com_sector)){
  1333. Db::rollBack();
  1334. return Result::error('通栏解除组件关联失败!');
  1335. }
  1336. $del_SectorComponent = SectorComponent::where('sectorid', $data['id'])->delete();
  1337. if(empty($del_SectorComponent)){
  1338. Db::rollBack();
  1339. return Result::error('通栏解除组件关联失败!1');
  1340. }
  1341. $sector = Sector::where('id', $data['id'])->update($data);
  1342. if (empty($sector)) {
  1343. Db::rollBack();
  1344. return Result::error('修改失败');
  1345. }
  1346. $sector_com = array_map(function ($item) use ($data) {
  1347. // 替换当前记录的sector_id为变量值(保留其他字段不变)
  1348. $item['sectorid'] = $data['id'];
  1349. return $item;
  1350. }, $sector_component);
  1351. // var_dump($sector_com);
  1352. $com_sector = SectorComponent::insert($sector_com);
  1353. if(empty($com_sector)){
  1354. Db::rollBack();
  1355. return Result::error('通栏关联组件失败!');
  1356. }
  1357. // ---------同步通栏的sort_id到组件之中,目前已废弃,涉及到批量修改------
  1358. // $up_component = Component::whereIn('component_id',$sector_component['component_type'])
  1359. // ->update(['status' => 2,]);
  1360. // if(empty($up_component)){
  1361. // Db::rollBack();
  1362. // return Result::error('通栏关联组件失败!');
  1363. // }
  1364. // 2. 查询数据库中已存在的component_type(只保留存在的记录)
  1365. // $existingTypes = Component::whereIn('component_type', $componentTypes)
  1366. // ->pluck('component_type') // 提取存在的component_type
  1367. // ->toArray();
  1368. // // 3. 过滤$components数组,只保留数据库中已存在的记录(核心:避免新增)
  1369. // $updateData = array_filter($components, function ($item) use ($existingTypes) {
  1370. // return in_array($item['component_type'], $existingTypes);
  1371. // });
  1372. // // 4. 执行upsert(此时$updateData中只有已存在的记录,不会新增)
  1373. // if (!empty($updateData)) {
  1374. // $component_sort = Component::upsert($updateData,['component_type'],['sort_id']);
  1375. // }
  1376. // if(empty($component_sort)){
  1377. // Db::rollBack();
  1378. // return Result::error('组件位置关联失败!');
  1379. // }
  1380. Db::commit();
  1381. return Result::success($sector);
  1382. } catch (\Exception $e) {
  1383. Db::rollBack();
  1384. return Result::error($e->getMessage());
  1385. }
  1386. }
  1387. public function getComponentList(array $data): array
  1388. {
  1389. $where = [];
  1390. if (isset($data['component_name']) && !empty($data['component_name'])) {
  1391. array_push($where, ['component.component_name', 'like', '%' . $data['component_name'] . '%']);
  1392. }
  1393. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])) {
  1394. array_push($where, ['component.component_width', 'like', '%' . $data['width'] . '%']);
  1395. array_push($where, ['component.component_height', 'like', '%' . $data['height'] . '%']);
  1396. } else if (isset($data['width']) && !empty($data['width'])) {
  1397. array_push($where, ['component.component_width', 'like', '%' . $data['width'] . '%']);
  1398. } else if (isset($data['height']) && !empty($data['height'])) {
  1399. array_push($where, ['component.component_height', 'like', '%' . $data['height'] . '%']);
  1400. } else {
  1401. }
  1402. if(isset($data['type_id']) && !empty($data['type_id'])){
  1403. $where['component.type_id'] = $data['type_id'];
  1404. }
  1405. $result = Component::where($where)
  1406. ->leftJoin('component_type', 'component_type.id', '=', 'component.type_id')
  1407. ->leftJoin('component_img', 'component.component_type', '=', 'component_img.component_id')
  1408. ->select(
  1409. 'component.*',
  1410. 'component_type.com_typename',
  1411. DB::raw('COUNT(component_img.id) as img_count')
  1412. )
  1413. ->groupBy('component.id') // 按组件ID分组,确保统计每个组件的图片数量
  1414. ->orderBy('component.updated_at', 'desc')
  1415. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  1416. if(empty($result)){
  1417. return Result::error('暂无数据');
  1418. }
  1419. return Result::success($result);
  1420. }
  1421. public function getComponentInfo(array $data): array
  1422. {
  1423. $where = ['component.id'=>$data['id']];
  1424. $result = Component::where($where)
  1425. ->leftJoin('component_type','component_type.id','=','component.type_id')
  1426. ->select( 'component.*','component_type.com_typename')
  1427. ->get();
  1428. if(empty($result)){
  1429. return Result::error('暂无数据');
  1430. }
  1431. return Result::success($result);
  1432. }
  1433. /*
  1434. 新增组件
  1435. */
  1436. public function addComponent(array $data): array
  1437. {
  1438. unset($data['user_id']);
  1439. $component_id = Component::where('component_type',$data['component_type'])->first();
  1440. if(!empty($component_id)){
  1441. return Result::error('组件编号已存在!');
  1442. }
  1443. $component_type = ComponentType::where('id',$data['type_id'])->first();
  1444. if(empty($component_type)){
  1445. return Result::error('组件分类不存在!');
  1446. }
  1447. // '组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;7:资讯-栏目类组件;
  1448. // 8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;14:广告资讯混合类
  1449. $data['type_id'] = intval($data['type_id']);
  1450. $add_arr = [
  1451. // 'template_id' => intval($data['template_id']),
  1452. 'component_type' => intval($data['component_type']),
  1453. 'component_name' => $data['component_name'],
  1454. 'component_img' => $data['component_img'],
  1455. 'component_width' => $data['component_width'],
  1456. 'component_height' => $data['component_height'],
  1457. 'type_id' => intval($data['type_id']),
  1458. 'component_keyword' => $data['component_keyword'],
  1459. ];
  1460. $component_head_code = [
  1461. 'component_id' => $add_arr['component_type'],
  1462. 'component_type' => $add_arr['type_id'],
  1463. 'component_name' => $add_arr['component_name'],
  1464. 'component_style' => 1,
  1465. ];
  1466. $add_arr['component_code'] = json_encode($component_head_code,true);
  1467. switch($data['type_id']){
  1468. case 1: //1:资讯-头条组件;
  1469. case 2: //2:资讯-轮播组件;
  1470. case 3: //3:资讯-推荐图类组件;
  1471. case 4: //4:资讯-最新类组件;
  1472. case 5: //5:资讯-推荐类组件;
  1473. case 6: //6:资讯-热点类组件;
  1474. // $component_data['componentData']['name'] = '';
  1475. $add_arr['level'] = $data['type_id'];
  1476. $add_arr['img_num'] = intval($data['img_num']);
  1477. $add_arr['text_num'] = intval($data['text_num']);
  1478. $component_data['componentData'] = [
  1479. // 'category_id' => '',
  1480. 'level' => $add_arr['level'],
  1481. 'name' => '',
  1482. // 'category_arr' => [],
  1483. 'imgSize' => $data['img_num'] ?? '',
  1484. 'textSize' => $data['text_num'] ?? '',
  1485. 'child' => [
  1486. 'id' => '',
  1487. 'imgSize' => '',
  1488. 'textSize' => ''
  1489. ]
  1490. ];
  1491. if($data['type_id'] == 4){
  1492. $component_data['componentData']['name'] = '最新资讯';
  1493. }
  1494. if($data['type_id'] == 5 || $data['type_id'] == 6){
  1495. $component_data['componentData']['name'] = '热点精选';
  1496. }
  1497. $add_arr['component_data'] = json_encode($component_data, true);
  1498. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1499. break;
  1500. case 7: //7:资讯-栏目类组件;
  1501. case 15: //15:滚动图文类;
  1502. $add_arr['img_num'] = intval($data['img_num']);
  1503. $add_arr['text_num'] = intval($data['text_num']);
  1504. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1505. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1506. $component_data['componentData'] = [
  1507. 'category_id' => '',
  1508. 'level' => '',
  1509. 'name' => '',
  1510. 'category_arr' => [],
  1511. 'imgSize' => $add_arr['img_num'] ?? '',
  1512. 'textSize' => $add_arr['text_num'] ?? '',
  1513. 'child' => [
  1514. 'id' => '',
  1515. 'imgSize' => $add_arr['child_imgnum'] ?? '',
  1516. 'textSize' => $add_arr['child_textnum'] ?? '',
  1517. ]
  1518. ];
  1519. $add_arr['component_data'] = json_encode($component_data,true);
  1520. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1521. break;
  1522. case 8: //8:列表类组件;
  1523. $add_arr['pageSize'] = intval($data['pageSize']);
  1524. $component_data['componentData'] = [
  1525. 'category_id' => '',
  1526. 'pageType' => [
  1527. 'page' => 1,
  1528. 'pageSize' => $add_arr['pageSize'] ?? '',
  1529. ]
  1530. ];
  1531. $add_arr['component_data'] = json_encode($component_data,true);
  1532. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1533. break;
  1534. case 9: //9:详情类组件;
  1535. $component_data['componentData'] = [
  1536. 'article_id' => '',
  1537. ];
  1538. $add_arr['component_data'] = json_encode($component_data,true);
  1539. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1540. break;
  1541. case 10: //10:二级导航类组件;
  1542. $add_arr['cate_place'] = 1;
  1543. $add_arr['num'] = intval($data['num']);
  1544. $component_data['componentData'] = [
  1545. 'pid' => '',
  1546. 'placeid' => 1,
  1547. 'num' => $add_arr['num'],
  1548. ];
  1549. $add_arr['component_data'] = json_encode($component_data,true);
  1550. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1551. break;
  1552. case 11: //11:广告类;
  1553. $add_arr['ad_width'] = intval($data['ad_width']);
  1554. $add_arr['ad_height'] = intval($data['ad_height']);
  1555. $add_arr['component_width'] = intval($data['ad_width']);
  1556. $add_arr['component_height'] = intval($data['ad_height']);
  1557. $add_arr['ad_type'] = intval($data['ad_type']);
  1558. // $add_arr['ad_img'] = $data['ad_img'];
  1559. $ad = [
  1560. 'width' => $add_arr['ad_width'],
  1561. 'height' => $add_arr['ad_height'],
  1562. 'name' => '',
  1563. 'price' => '',
  1564. 'introduce' => '',
  1565. 'website_id' => '',
  1566. // 'thumb' => $add_arr['ad_img'],
  1567. 'typeid' => $add_arr['ad_type'],
  1568. 'ad_tag' => '',
  1569. ];
  1570. $add_arr['ad'] = json_encode($ad,true);
  1571. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1572. // $add_arr['adimg_info'] = $data['img_info'];
  1573. // $ad_imginfo = json_decode($data['img_info'],true);
  1574. break;
  1575. // case 13: //13:底部导航类;
  1576. case 17: //17:单页列表类;
  1577. case 18: //18:单页详情类;
  1578. $component_data['componentData'] = [
  1579. 'fcat_id' => '',
  1580. ];
  1581. $add_arr['component_data'] = json_encode($component_data,true);
  1582. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1583. break;
  1584. case 14:
  1585. $add_arr['ad_width'] = intval($data['ad_width']);
  1586. $add_arr['ad_height'] = intval($data['ad_height']);
  1587. $add_arr['component_width'] = intval($data['component_width']);
  1588. $add_arr['component_height'] = intval($data['component_height']);
  1589. $add_arr['ad_type'] = intval($data['ad_type']);
  1590. $add_arr['ad_img'] = $data['ad_img'];
  1591. $add_arr['img_num'] = intval($data['img_num']);
  1592. $add_arr['text_num'] = intval($data['text_num']);
  1593. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1594. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1595. $component_data['componentData'] = [
  1596. 'category_id' => '',
  1597. 'level' => '',
  1598. 'name' => '',
  1599. 'category_arr' => [],
  1600. 'imgSize' => $data['img_num'] ?? '',
  1601. 'textSize' => $data['text_num'] ?? '',
  1602. 'child' => [
  1603. 'id' => '',
  1604. 'imgSize' => $data['child_imgnum'] ?? '',
  1605. 'textSize' => $data['child_textnum'] ?? '',
  1606. ]
  1607. ];
  1608. $ad = [
  1609. 'width' => $add_arr['ad_width'],
  1610. 'height' => $add_arr['ad_height'],
  1611. 'name' => '',
  1612. 'price' => '',
  1613. 'introduce' => '',
  1614. 'website_id' => '',
  1615. 'thumb' => $add_arr['ad_img'],
  1616. 'typeid' => $add_arr['ad_type'],
  1617. 'ad_tag' => '',
  1618. ];
  1619. $add_arr['ad'] = json_encode($ad,true);
  1620. $add_arr['component_data'] = json_encode($component_data,true);
  1621. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1622. // $add_arr['adimg_info'] = $data['img_info'];
  1623. // $ad_imginfo = json_decode($data['img_info'],true);
  1624. break;
  1625. default:
  1626. break;
  1627. }
  1628. if($data['type_id'] == 11 || $data['type_id'] == 14){
  1629. Db::beginTransaction();
  1630. try{
  1631. // $website_img = WebsiteImg::insertGetId($ad_imginfo);
  1632. // var_dump($website_img);
  1633. // $add_arr['ad_imgid'] = $website_img;
  1634. // if(empty($website_img)){
  1635. // Db::rollBack();
  1636. // return Result::error('广告默认图上传失败!');
  1637. // }
  1638. $result = Component::insertGetId($add_arr);
  1639. if(empty($result)){
  1640. Db::rollBack();
  1641. return Result::error('添加失败!');
  1642. }
  1643. Db::commit();
  1644. }catch(\Exception $e){
  1645. Db::rollback();
  1646. return Result::error('添加失败!');
  1647. }
  1648. }else{
  1649. $result = Component::insertGetId($add_arr);
  1650. if(empty($result)){
  1651. return Result::error('添加组件失败!');
  1652. }
  1653. }
  1654. return Result::success($result);
  1655. }
  1656. public function delComponent(array $data): array
  1657. {
  1658. $component = Component::where('id', $data['id'])->first();
  1659. if(empty($component)){
  1660. return Result::error('组件不存在!');
  1661. }
  1662. $component_id = SectorComponent::where('component_id', $component['component_type'])->first();
  1663. if (!empty($component_id)) {
  1664. return Result::error('请先解除相关组件关联关系!');
  1665. }
  1666. Db::beginTransaction();
  1667. try{
  1668. // if($component['type_id'] == 11 || $component['type_id'] == 14){
  1669. // $ad_img = WebsiteImg::where('id',$component['ad_imgid'])->first();
  1670. // if(!empty($ad_img)){
  1671. // $ad_img = WebsiteImg::where('id',$component['ad_imgid'])->delete();
  1672. // if(empty($ad_img)){
  1673. // Db::rollBack();
  1674. // return Result::error('删除广告默认图失败!');
  1675. // }
  1676. // }
  1677. // }
  1678. $component_img = ComponentImg::where('component_id',$component['component_type'])->first();
  1679. if(!empty($component_img)){
  1680. $del_img = ComponentImg::where('component_id',$component['component_type'])->delete();
  1681. if(empty($del_img)){
  1682. Db::rollBack();
  1683. return Result::error('删除组件预览图失败!');
  1684. }
  1685. }
  1686. $result = Component::where('id',$data['id'])->delete();
  1687. if(empty($result)){
  1688. Db::rollBack();
  1689. return Result::error('删除失败!');
  1690. }
  1691. Db::commit();
  1692. return Result::success($result);
  1693. }catch(\Exception $e){
  1694. Db::rollback();
  1695. return Result::error('删除失败!');
  1696. }
  1697. }
  1698. public function updateComponent(array $data): array
  1699. {
  1700. unset($data['user_id']);
  1701. $id = $data['id'];
  1702. unset($data['id']);
  1703. $component_id = Component::where('id','!=',$id)->where('component_type',$data['component_type'])->first();
  1704. if(!empty($component_id) || $component_id != null){
  1705. return Result::error('组件编号已存在!');
  1706. }
  1707. $component_type = ComponentType::where('id',$data['type_id'])->first();
  1708. if(empty($component_type)){
  1709. return Result::error('组件分类不存在!');
  1710. }
  1711. $component = Component::where('id',$id)->first();
  1712. if(empty($component)){
  1713. return Result::error('组件不存在!');
  1714. }
  1715. // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
  1716. // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
  1717. $data['type_id'] = intval($data['type_id']);
  1718. $add_arr = [
  1719. // 'template_id' => intval($data['template_id']),
  1720. 'component_type' => intval($data['component_type']),
  1721. 'component_name' => $data['component_name'],
  1722. 'component_img' => $data['component_img'],
  1723. 'component_width' => $data['component_width'],
  1724. 'component_height' => $data['component_height'],
  1725. 'type_id' => intval($data['type_id']),
  1726. 'component_keyword' => $data['component_keyword'],
  1727. ];
  1728. $component_head_code = [
  1729. 'component_id' => $add_arr['component_type'],
  1730. 'component_type' => $add_arr['type_id'],
  1731. 'component_name' => $add_arr['component_name'],
  1732. 'component_style' => 1,
  1733. ];
  1734. $add_arr['component_code'] = json_encode($component_head_code,true);
  1735. switch($data['type_id']){
  1736. case 1: //1:资讯-头条组件;
  1737. case 2: //2:资讯-轮播组件;
  1738. case 3: //3:资讯-推荐图类组件;
  1739. case 4: //4:资讯-最新类组件;
  1740. case 5: //5:资讯-推荐类组件;
  1741. case 6: //6:资讯-热点类组件;
  1742. // $component_data['componentData']['name'] = '';
  1743. $add_arr['level'] = $data['type_id'];
  1744. $add_arr['img_num'] = intval($data['img_num']);
  1745. $add_arr['text_num'] = intval($data['text_num']);
  1746. $component_data['componentData'] = [
  1747. // 'category_id' => '',
  1748. 'level' => $add_arr['level'],
  1749. // 'category_arr' => [],
  1750. 'name' => '',
  1751. 'imgSize' => $data['img_num'] ?? '',
  1752. 'textSize' => $data['text_num'] ?? '',
  1753. 'child' => [
  1754. 'id' => '',
  1755. 'imgSize' => '',
  1756. 'textSize' => ''
  1757. ]
  1758. ];
  1759. if($data['type_id'] == 4){
  1760. $component_data['componentData']['name'] = '最新资讯';
  1761. }
  1762. if($data['type_id'] == 5 || $data['type_id'] == 6){
  1763. $component_data['componentData']['name'] = '热点精选';
  1764. }
  1765. $add_arr['component_data'] = json_encode($component_data, true);
  1766. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1767. break;
  1768. case 7: //7:资讯-栏目类组件;
  1769. case 15: //15:滚动图文类;
  1770. $add_arr['img_num'] = intval($data['img_num']);
  1771. $add_arr['text_num'] = intval($data['text_num']);
  1772. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1773. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1774. $component_data['componentData'] = [
  1775. 'category_id' => '',
  1776. 'level' => '',
  1777. 'name' => '',
  1778. 'category_arr' => [],
  1779. 'imgSize' => $add_arr['img_num'] ?? '',
  1780. 'textSize' => $add_arr['text_num'] ?? '',
  1781. 'child' => [
  1782. 'id' => '',
  1783. 'imgSize' => $add_arr['child_imgnum'] ?? '',
  1784. 'textSize' => $add_arr['child_textnum'] ?? '',
  1785. ]
  1786. ];
  1787. $add_arr['component_data'] = json_encode($component_data,true);
  1788. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1789. break;
  1790. case 8: //8:列表类组件;
  1791. $add_arr['pageSize'] = intval($data['pageSize']);
  1792. $component_data['componentData'] = [
  1793. 'category_id' => '',
  1794. 'pageType' => [
  1795. 'page' => 1,
  1796. 'pageSize' => $add_arr['pageSize'] ?? '',
  1797. ]
  1798. ];
  1799. $add_arr['component_data'] = json_encode($component_data,true);
  1800. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1801. break;
  1802. case 9: //9:详情类组件;
  1803. $component_data['componentData'] = [
  1804. 'article_id' => '',
  1805. ];
  1806. $add_arr['component_data'] = json_encode($component_data,true);
  1807. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1808. break;
  1809. case 10: //10:二级导航类组件;
  1810. $add_arr['cate_place'] = 1;
  1811. $add_arr['num'] = intval($data['num']);
  1812. $component_data['componentData'] = [
  1813. 'pid' => '',
  1814. 'placeid' => 1,
  1815. 'num' => $add_arr['num'],
  1816. ];
  1817. $add_arr['component_data'] = json_encode($component_data,true);
  1818. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1819. break;
  1820. case 11: //11:广告类;
  1821. $add_arr['ad_width'] = intval($data['ad_width']);
  1822. $add_arr['ad_height'] = intval($data['ad_height']);
  1823. $add_arr['component_width'] = intval($data['ad_width']);
  1824. $add_arr['component_height'] = intval($data['ad_height']);
  1825. $add_arr['ad_type'] = intval($data['ad_type']);
  1826. // $add_arr['ad_img'] = $data['ad_img'];
  1827. $ad = [
  1828. 'width' => $add_arr['ad_width'],
  1829. 'height' => $add_arr['ad_height'],
  1830. 'name' => '',
  1831. 'price' => '',
  1832. 'introduce' => '',
  1833. 'website_id' => '',
  1834. 'thumb' => $add_arr['ad_img'],
  1835. // 'typeid' => $add_arr['ad_type'],
  1836. 'ad_tag' => '',
  1837. ];
  1838. $add_arr['ad'] = json_encode($ad,true);
  1839. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1840. // $add_arr['adimg_info'] = $data['img_info'];
  1841. // $ad_imginfo = json_decode($data['img_info'],true);
  1842. break;
  1843. // case 13: //13:底部导航类;
  1844. case 17: //17:单页列表类;
  1845. case 18: //18:单页详情类;
  1846. $component_data['componentData'] = [
  1847. 'fcat_id' => '',
  1848. ];
  1849. $add_arr['component_data'] = json_encode($component_data,true);
  1850. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1851. break;
  1852. case 14:
  1853. $add_arr['ad_width'] = intval($data['ad_width']);
  1854. $add_arr['ad_height'] = intval($data['ad_height']);
  1855. $add_arr['component_width'] = intval($data['component_width']);
  1856. $add_arr['component_height'] = intval($data['component_height']);
  1857. $add_arr['ad_type'] = intval($data['ad_type']);
  1858. $add_arr['ad_img'] = $data['ad_img'];
  1859. $add_arr['img_num'] = intval($data['img_num']);
  1860. $add_arr['text_num'] = intval($data['text_num']);
  1861. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1862. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1863. $component_data['componentData'] = [
  1864. 'category_id' => '',
  1865. 'level' => '',
  1866. 'name' => '',
  1867. 'category_arr' => [],
  1868. 'imgSize' => $data['img_num'] ?? '',
  1869. 'textSize' => $data['text_num'] ?? '',
  1870. 'child' => [
  1871. 'id' => '',
  1872. 'imgSize' => $data['child_imgnum'] ?? '',
  1873. 'textSize' => $data['child_textnum'] ?? '',
  1874. ]
  1875. ];
  1876. $ad = [
  1877. 'width' => $add_arr['ad_width'],
  1878. 'height' => $add_arr['ad_height'],
  1879. 'name' => '',
  1880. 'price' => '',
  1881. 'introduce' => '',
  1882. 'website_id' => '',
  1883. 'thumb' => $add_arr['ad_img'],
  1884. 'typeid' => $add_arr['ad_type'],
  1885. 'ad_tag' => '',
  1886. ];
  1887. $add_arr['ad'] = json_encode($ad,true);
  1888. $add_arr['component_data'] = json_encode($component_data,true);
  1889. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1890. // $add_arr['adimg_info'] = $data['img_info'];
  1891. // $ad_imginfo = json_decode($data['img_info'],true);
  1892. break;
  1893. default:
  1894. break;
  1895. }
  1896. // var_dump("ad_imginfo:",$ad_imginfo);
  1897. $cll_column = [
  1898. 'img_num' => null,
  1899. 'text_num' => null,
  1900. 'child_imgnum' => null,
  1901. 'child_textnum' => null,
  1902. 'category_id' => null,
  1903. 'child_id' => null,
  1904. 'num' => null,
  1905. 'level' => null,
  1906. 'fcatid' => null,
  1907. 'article_id' => null,
  1908. 'cate_place' => null,
  1909. 'pageSize' => null,
  1910. // 'ad_img' => null,
  1911. 'ad_width' => null,
  1912. 'ad_height' => null,
  1913. 'ad' => '',
  1914. 'ad_type' => null,
  1915. // 'ad_imgid' => null,
  1916. 'adimg_info' => '[]',
  1917. ];
  1918. Db::beginTransaction();
  1919. try{
  1920. // return Result::success($add_arr);
  1921. // if(($component['type_id'] == 11 || $component['type_id'] == 14) && ($data['type_id'] != 11 && $data['type_id'] != 14)){
  1922. // // $website_img = WebsiteImg::where('id',$component['ad_imgid'])->delete();
  1923. // if(empty($website_img)){
  1924. // Db::rollBack();
  1925. // return Result::error('广告默认图删除失败!');
  1926. // }
  1927. // var_dump("删除",$website_img);
  1928. // }
  1929. // if(($data['type_id'] == 11 || $data['type_id'] == 14) && ($component['type_id'] != 11 && $component['type_id'] != 14)){
  1930. // $website_img = WebsiteImg::insertGetId($ad_imginfo);
  1931. // $add_arr['ad_imgid'] = $website_img;
  1932. // if(empty($website_img)){
  1933. // Db::rollBack();
  1934. // return Result::error('广告默认图上传失败!');
  1935. // }
  1936. // var_dump("上传",$website_img);
  1937. // }
  1938. // if(($component['type_id'] == 11 || $component['type_id'] == 14) && ($data['type_id'] == 11 || $data['type_id'] == 14)){
  1939. // $website_img = WebsiteImg::where('id',$component['ad_imgid'])->first();
  1940. // if(empty($website_img)){
  1941. // $website_img = WebsiteImg::insertGetId($ad_imginfo);
  1942. // $add_arr['ad_imgid'] = $website_img;
  1943. // }else{
  1944. // $website_img = WebsiteImg::where('id',$component['ad_imgid'])->update($ad_imginfo);
  1945. // $add_arr['ad_imgid'] = $component['ad_imgid'];
  1946. // }
  1947. // if(empty($website_img)){
  1948. // Db::rollBack();
  1949. // return Result::error('广告默认图修改失败!');
  1950. // }
  1951. // }
  1952. $add_arr = array_merge($cll_column,$add_arr);
  1953. $result = Component::where('id',$id)->update($add_arr);
  1954. if(empty($result)){
  1955. Db::rollBack();
  1956. return Result::error('修改失败!');
  1957. }
  1958. Db::commit();
  1959. }catch(\Exception $e){
  1960. Db::rollBack();
  1961. return Result::error('修改失败!');
  1962. }
  1963. return Result::success($result);
  1964. }
  1965. public function getWebsiteTemplateInfo(array $data)
  1966. {
  1967. $where = [];
  1968. if (isset($data['id'])) {
  1969. $where[] = ['id', '=', $data['id']];
  1970. }
  1971. $result = WebsiteTemplateInfo::where($where)
  1972. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1973. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  1974. ->select('website_template_info.*', 'website.website_name')
  1975. ->get();
  1976. if ($result) {
  1977. return Result::success($result);
  1978. } else {
  1979. return Result::error('暂无数据');
  1980. }
  1981. }
  1982. /**
  1983. * 自助建站----1.获取页面类型回显
  1984. * @param array $data
  1985. * @return array
  1986. */
  1987. public function getWebPageType(array $data): array
  1988. {
  1989. // 1:图片 2:文字 3:底部
  1990. $friend_link = Link::where('website_id', $data['website_id'])->where('type', 3)->get();
  1991. if (empty($friend_link->toArray())) {
  1992. return Result::error('暂无友情链接数据!');
  1993. }
  1994. $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
  1995. if (empty($footer_category->toArray())) {
  1996. return Result::error('暂无底部导航数据!');
  1997. }
  1998. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('page_type');
  1999. if (empty($page_type)) {
  2000. $page_type = [];
  2001. } else {
  2002. $page_type = json_decode($page_type, true);
  2003. }
  2004. // '网站页面类型(存数组)1:首页 2:分类页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页
  2005. if (isset($page_type) && in_array(5, $page_type)) {
  2006. $page_type = 1;
  2007. } else {
  2008. $page_type = 0;
  2009. }
  2010. $result = [
  2011. 'friend_link' => $friend_link,
  2012. 'footer_category' => $footer_category,
  2013. 'page_type' => $page_type,
  2014. ];
  2015. return Result::success($result);
  2016. }
  2017. /**
  2018. * 自助建站----2.添加页面类型
  2019. * @param array $data
  2020. * @return array
  2021. */
  2022. public function addWebPageType(array $data): array
  2023. {
  2024. // return Result::success($data);
  2025. // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
  2026. if ($data['is_search'] == 1) {
  2027. $page_type = json_encode([1,2,3,4,5,6,7]);
  2028. } else {
  2029. $page_type = json_encode([1,2,3,4,6,7]);
  2030. }
  2031. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  2032. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2033. $website_template = WebsiteTemplate::where('website_id', $data['website_id'])->first();
  2034. Db::beginTransaction();
  2035. try{
  2036. if (empty($website_template_info)) {
  2037. $result['template_info'] = WebsiteTemplateInfo::insertGetId([
  2038. 'website_id' => $data['website_id'],
  2039. 'page_type' => $page_type,
  2040. 'user_id' => $data['user_id'],
  2041. 'status' => 0,
  2042. 'action_id' => 1,
  2043. ]);
  2044. } else {
  2045. if ($website_template_info['status'] == 2) {
  2046. Db::rollBack();
  2047. return Result::error('网站已应用,不可再次修改!');
  2048. }
  2049. $result['template_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type, 'action_id' => 1, 'user_id' => $data['user_id']]);
  2050. }
  2051. if (!$result['template_info']) {
  2052. Db::rollBack();
  2053. return Result::error('网站所选页面添加失败');
  2054. }
  2055. if(empty($website_template)){
  2056. $result['template'] = WebsiteTemplate::insertGetId([
  2057. 'website_id' => $data['website_id'],
  2058. 'page_type' => $page_type,
  2059. 'user_id' => $data['user_id'],
  2060. ]);
  2061. }else{
  2062. $result['template'] = WebsiteTemplate::where('website_id', $data['website_id'])->update([
  2063. 'page_type' => $page_type,
  2064. ]);
  2065. }
  2066. if(!$result['template']){
  2067. Db::rollBack();
  2068. return Result::error('添加网站预制模版信息失败!');
  2069. }
  2070. Db::commit();
  2071. return Result::success($result);
  2072. }catch(\Exception $e){
  2073. Db::rollBack();
  2074. return Result::error('添加失败');
  2075. }
  2076. }
  2077. /**
  2078. * 自助建站---流程---3.选择皮肤列表
  2079. * @param array $data
  2080. * @return array
  2081. */
  2082. public function getWebsiteTemplateList(array $data): array
  2083. {
  2084. $where = [];
  2085. if (isset($data['template_class_id']) && $data['template_class_id']) {
  2086. $where[] = ['template_class_id', '=', $data['template_class_id']];
  2087. }
  2088. // 0:未构建 1:未应用 2:已应用 status
  2089. $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2090. if (empty($templste_info)) {
  2091. return Result::error('请先填写网站基础信息!');
  2092. }
  2093. if ($templste_info['status'] == 2) {
  2094. return Result::error('网站已应用,不可再次修改!');
  2095. }
  2096. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2097. if (is_array($data['keyword'])) {
  2098. // 拼接多个模糊查询条件
  2099. $query = Template::query();
  2100. foreach ($data['keyword'] as $kw) {
  2101. $escapedKw = addcslashes($kw, '%_'); // 转义通配符
  2102. $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
  2103. }
  2104. } else {
  2105. $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
  2106. $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
  2107. }
  2108. } else {
  2109. $query = Template::where($where);
  2110. }
  2111. $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
  2112. // return Result::success($template_id);
  2113. if (!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])) {
  2114. $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
  2115. } else {
  2116. $template_page = [];
  2117. }
  2118. if (!empty($template_id['template_id'])) {
  2119. $result['template_id'] = $templste_info['template_id'];
  2120. }
  2121. // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
  2122. $template_page_str = json_encode($template_page);
  2123. $result['template'] = $query->where($where)
  2124. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  2125. ->orderBy('template.template_id','desc')
  2126. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  2127. if (empty($result['template'])) {
  2128. $result['template'] = Template::orderBy('template.template_id','desc')
  2129. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  2130. }
  2131. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('template_id');
  2132. if ($template) {
  2133. $result['template_id'] = $template;
  2134. } else {
  2135. $result['template_id'] = 0;
  2136. }
  2137. return Result::success($result);
  2138. }
  2139. /**
  2140. * 自助建站---流程---4.选择皮肤
  2141. * @param array $data
  2142. * @return array
  2143. */
  2144. public function chooseWebsiteTemplate(array $data): array
  2145. {
  2146. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2147. if (empty($website_template_info)) {
  2148. return Result::error('请先填写网站基础信息!');
  2149. }
  2150. // 0:未构建 1:未应用 2:已应用 status
  2151. if ($website_template_info['status'] == 2) {
  2152. return Result::error('网站已应用,不可再次修改!');
  2153. }
  2154. $template = Template::where('template_id', $data['template_id'])->first();
  2155. if (empty($template)) {
  2156. return Result::error('未查询到皮肤!');
  2157. }
  2158. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  2159. // 分别更新 WebsiteTemplateInfo 和 WebsiteTemplate 表
  2160. Db::beginTransaction();
  2161. try {
  2162. $reuslt['template_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])
  2163. ->update(['template_id' => $data['template_id'],'action_id' => 2,'user_id'=> $data['user_id']]);
  2164. if(empty($reuslt['template_info'])){
  2165. Db::rollBack();
  2166. return Result::error('选择皮肤失败!');
  2167. }
  2168. $result['template'] = WebsiteTemplate::where('website_id', $data['website_id'])
  2169. ->update(['template_id' => $data['template_id'],'user_id'=> $data['user_id']]);
  2170. if(empty($result['template'])){
  2171. Db::rollBack();
  2172. return Result::error('网站模版选择皮肤失败!');
  2173. }
  2174. Db::commit();
  2175. return Result::success($result);
  2176. } catch (\Exception $e) {
  2177. Db::rollBack();
  2178. return Result::error('选择皮肤失败!');
  2179. }
  2180. }
  2181. /**
  2182. * 自助建站---流程---5.保存模版
  2183. * @param array $data
  2184. * @return array
  2185. */
  2186. public function saveWebsiteTemplate(array $data): array
  2187. {
  2188. // return Result::success($data);
  2189. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2190. if (empty($website_template_info) || empty($website_template_info->template_id) || empty($website_template_info->page_type)) {
  2191. return Result::error('请先填写网站基础信息!');
  2192. }
  2193. // 0:未构建 1:未应用 2:已应用 status
  2194. if ($website_template_info['status'] == 2) {
  2195. return Result::error('网站已应用,不可再次保存!');
  2196. }
  2197. if ($website_template_info['action_id'] != 2) {
  2198. return Result::error('请完成之前的步骤!');
  2199. }
  2200. $template_info = WebsiteTemplate::where('website_id', $data['website_id'])->first();
  2201. // var_dump($data['template_data']);
  2202. try {
  2203. Db::beginTransaction();
  2204. if (empty($template_info)) {
  2205. Db::rollback();
  2206. return Result::error('该网站不存在已保存的模版!');
  2207. } else {
  2208. $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(
  2209. [
  2210. 'template_data' => $data['template_data'],
  2211. 'user_id' => $data['user_id'],
  2212. 'canvas_data' => $data['canvas_data'],
  2213. ]
  2214. );
  2215. }
  2216. if (empty($template)) {
  2217. Db::rollback();
  2218. return Result::error('保存失败!');
  2219. } else {
  2220. $tempalte_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['status' => 1]);
  2221. if (empty($tempalte_info)) {
  2222. Db::rollback();
  2223. return Result::error('网站搭建状态保存失败!');
  2224. }
  2225. Db::commit();
  2226. }
  2227. } catch (\Exception $e) {
  2228. return Result::error('模版数据格式错误!');
  2229. }
  2230. return Result::success($template);
  2231. }
  2232. /**
  2233. * 自助建站---流程---6.返显保存的模版
  2234. * @param array $data
  2235. * @return array
  2236. */
  2237. public function getWebsiteTemplate(array $data): array
  2238. {
  2239. $web = Website::where('id', $data['website_id'])->first();
  2240. if (empty($web)) {
  2241. return Result::error('未查询到网站信息!');
  2242. }
  2243. $template = WebsiteTemplate::where('website_id', $data['website_id'])
  2244. ->first(['website_id', 'template_id', 'page_type', 'template_data', 'canvas_data']);
  2245. if (empty($template)) {
  2246. return Result::error('未查询到模版!');
  2247. }
  2248. $template['page_type'] = json_decode($template['page_type'],true);
  2249. return Result::success($template);
  2250. }
  2251. /**
  2252. * 通栏版式管理-获取通栏版式列表
  2253. */
  2254. public function getSectorPlaceList(array $data): array
  2255. {
  2256. $where['sector_place.type_id'] = $data['type_id'];
  2257. if(isset($data['component_num']) && !empty($data['component_num'])){
  2258. $where['sector_place.component_num'] = $data['component_num'];
  2259. }
  2260. if(isset($data['sector_type']) && !empty($data['sector_type'])){
  2261. $where['sector_place.sector_type'] = $data['sector_type'];
  2262. }
  2263. // if(isset($data['component_type']) && !empty($data['component_type'])){
  2264. // $where['sector_place.component_type'] = $data['component_type'];
  2265. // }
  2266. if(isset($data['name']) && !empty($data['name'])){
  2267. array_push($where,['sector_place.name', 'like', '%'.$data['name'].'%']);
  2268. }
  2269. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
  2270. array_push($where,['sector_place.width','like','%'.$data['width'].'%']);
  2271. array_push($where,['sector_place.height','like','%'.$data['height'].'%']);
  2272. } else if( isset($data['width']) && !empty($data['width'])){
  2273. array_push($where,['sector_place.width','like','%'.$data['width'].'%']);
  2274. }else if( isset($data['height']) && !empty($data['height'])){
  2275. array_push($where,['sector_place.height','like','%'.$data['height'].'%']);
  2276. }else{
  2277. $size_id = [];
  2278. }
  2279. $sector_place = SectorPlace::where($where)
  2280. // ->when(!empty($size_id), function ($query) use ($size_id) {
  2281. // $query->whereIn('sector_place.size_id', $size_id);
  2282. // })
  2283. // ->leftJoin('size','sector_place.size_id','=','size.id')
  2284. ->select('sector_place.*');
  2285. $result['count'] = $sector_place->count();
  2286. $result['row'] =$sector_place->paginate($data['page_size'], ['*'], 'page', $data['page']);
  2287. if(empty($result['count'])){
  2288. return Result::error("暂无相关版式数据!");
  2289. }
  2290. return Result::success($result);
  2291. }
  2292. /**
  2293. * 通栏版式管理-添加通栏版式
  2294. */
  2295. public function addSectorPlace(array $data): array
  2296. {
  2297. // 1:通栏;2:组件;
  2298. if($data['type_id'] == 1){
  2299. $sector_place = SectorPlace::where('sector_type', $data['type'])->first();
  2300. if(!empty($sector_place)){
  2301. return Result::error('通栏版式类别编号已存在!');
  2302. }
  2303. $data = [
  2304. 'name' => $data['name'],
  2305. 'component_num' => $data['component_num'],
  2306. 'size_id' => $data['size_id'],
  2307. 'sort_id' => 0,
  2308. 'sector_img' => $data['sector_img'],
  2309. 'sector_type' => $data['type'],
  2310. 'type_id' => $data['type_id'],
  2311. 'status' => 0,
  2312. ];
  2313. }else{
  2314. $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
  2315. if(empty($sector_type)){
  2316. return Result::error('通栏版式类别不存在!');
  2317. }
  2318. // $com_query = SectorPlace::where('type_id',2);
  2319. // ->query(function($query) use ($data){
  2320. // $query->where('component_type', $data['type'])
  2321. // ->Subquery(function($subQuery) use ($data) {
  2322. // $subQuery->where('sector_type', $data['sector_type'])
  2323. // ->where('sort_id', $data['sort']);
  2324. // });
  2325. // }) //若是组件版式编号或者组件版式位置重复用此语句筛选
  2326. // ->where('sector_type',$data['sector_type']) //若是组件版式编号在同一个通栏版式下不重复就行,则启用此语句
  2327. $component = SectorPlace::where('type_id',2)->where('component_type',$data['type'])->first();
  2328. if(!empty($component)){
  2329. return Result::error('组件版式类别编号已存在!');
  2330. }
  2331. // $com_query = clone $com_query;
  2332. $com_num = SectorPlace::where('type_id',2)->where('sector_type',$data['sector_type'])->count('sort_id');
  2333. // return Result::success($com_num);
  2334. if($sector_type['component_num'] = $com_num){
  2335. $sector = SectorPlace::where('sector_type',$data['sector_type'])->where('type_id',1)->update(['status'=>1]);
  2336. if(empty($sector)){
  2337. return Result::error('通栏版式状态修改失败!');
  2338. }
  2339. }
  2340. $data = [
  2341. 'name' => $data['name'],
  2342. 'component_num' => 0,
  2343. 'size_id' => $data['size_id'],
  2344. 'sort_id' => $data['sort_id'],
  2345. 'sector_img' => $data['sector_img'],
  2346. 'component_type' => $data['type'],
  2347. 'type_id' => $data['type_id'],
  2348. 'sector_type' => $data['sector_type'],
  2349. ];
  2350. }
  2351. $result = SectorPlace::insertGetId($data);
  2352. if(empty($result)){
  2353. return Result::error('添加失败!');
  2354. }
  2355. return Result::success('添加成功!',$result);
  2356. }
  2357. /**
  2358. * 通栏版式管理-修改通栏版式
  2359. */
  2360. public function upSectorPlace(array $data): array
  2361. {
  2362. $id = $data['id'];
  2363. // 1:通栏;2:组件;
  2364. if($data['type_id'] == 1){
  2365. $sector_place = SectorPlace::where('id','!=',$id)->where('sector_type', $data['type'])->where('type_id',1)->first();
  2366. if(!empty($sector_place)){
  2367. return Result::error('通栏版式类别编号已存在!');
  2368. }
  2369. $data = [
  2370. 'name' => $data['name'],
  2371. 'component_num' => $data['component_num'],
  2372. 'size_id' => $data['size_id'],
  2373. 'sort_id' => 0,
  2374. 'sector_img' => $data['sector_img'],
  2375. 'sector_type' => $data['type'],
  2376. 'type_id' => $data['type_id'],
  2377. ];
  2378. }else{
  2379. $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
  2380. if(empty($sector_type)){
  2381. return Result::error('通栏版式类别不存在!');
  2382. }
  2383. $component = SectorPlace::where('id','!=',$id)
  2384. ->where('component_type', $data['type'])
  2385. ->where('type_id',2)
  2386. ->first();
  2387. if(!empty($component)){
  2388. return Result::error('组件版式类别编号已存在!');
  2389. }
  2390. $data = [
  2391. 'name' => $data['name'],
  2392. 'component_num' => 0,
  2393. 'size_id' => $data['size_id'],
  2394. 'sort_id' => $data['sort_id'],
  2395. 'sector_img' => $data['sector_img'],
  2396. 'component_type' => $data['type'],
  2397. 'type_id' => $data['type_id'],
  2398. 'sector_type' => $data['sector_type'],
  2399. ];
  2400. }
  2401. $result = SectorPlace::where('id',$id)->update($data);
  2402. if(empty($result)){
  2403. return Result::error('修改失败!');
  2404. }
  2405. return Result::success('修改成功!',$result);
  2406. }
  2407. /**
  2408. * 通栏版式管理-删除通栏版式
  2409. */
  2410. public function delSectorPlace(array $data): array
  2411. {
  2412. $sector_place = SectorPlace::where('id',$data['id'])->first();
  2413. if(empty($sector_place)){
  2414. return Result::error('通栏版式不存在!');
  2415. }
  2416. if($sector_place['type_id'] == 1){
  2417. $sector = Sector::where('place_type', $sector_place['sector_type'])->first();
  2418. $component = SectorPlace::where('sector_type', $sector_place['sector_type'])
  2419. ->where('type_id',2)
  2420. ->first();
  2421. if(!empty($sector) || !empty($component)){
  2422. return Result::error('通栏版式分类已应用,暂不可删除!');
  2423. }
  2424. }else{
  2425. $sector = Component::where('place_type', $sector_place['component_type'])->first();
  2426. if(!empty($sector)){
  2427. return Result::error('组件版式分类已应用,暂不可删除!');
  2428. }
  2429. $component_num = SectorPlace::where('sector_type', $sector_place['sector_type'])
  2430. ->where('type_id',1)->update(['status'=> 0]);
  2431. if(empty($component_num)){
  2432. return Result::error('通栏版式状态修改失败!');
  2433. }
  2434. }
  2435. $result = SectorPlace::where('id',$data['id'])->delete();
  2436. if(empty($result)){
  2437. return Result::error('删除失败!');
  2438. }
  2439. return Result::success('删除成功!');
  2440. }
  2441. /**
  2442. * 自助建站-通栏版式管理-获取通栏版式详情
  2443. */
  2444. public function getSectorPlaceInfo(array $data): array
  2445. {
  2446. $result = SectorPlace::where('sector_place.id',$data['id'])
  2447. ->leftJoin('size','sector_place.size_id','=','size.id')
  2448. ->select('sector_place.*','size.width','size.height')
  2449. ->first();
  2450. if(empty($result)){
  2451. return Result::error('通栏版式不存在!');
  2452. }
  2453. return Result::success($result);
  2454. }
  2455. /**
  2456. * 自助建站-通栏版式管理-获取通栏版式列表
  2457. */
  2458. public function getSectorPlaceSort(array $data): array
  2459. {
  2460. $sector = SectorPlace::where('sector_type',$data['sector_type'])->first();
  2461. if(empty($sector)){
  2462. return Result::error('通栏版式不存在!');
  2463. }
  2464. $component = SectorPlace::where('type_id',2)->where('sector_type',$sector['sector_type'])->pluck('sort_id')->toArray();
  2465. if(count($component) < $sector['component_num']){
  2466. // 根据 $sector['component_num'] 的值生成对应元素数量的数组
  2467. if (isset($sector['component_num']) && is_numeric($sector['component_num'])) {
  2468. $num = intval($sector['component_num']);
  2469. if ($num > 0 && $num <= 10) {
  2470. // 使用 range 函数生成一个从 1 到 $num 的连续整数数组,存储到 $sector_arr 中
  2471. $sector_arr = range(1, $num);
  2472. } else {
  2473. $sector_arr = [];
  2474. }
  2475. } else {
  2476. $sector_arr = [];
  2477. }
  2478. // 获取 $sector_arr 中不在 $component 里的元素
  2479. $sort = array_diff($sector_arr, $component);
  2480. // return Result::success($sort);
  2481. }
  2482. if(!empty($sort)){
  2483. $sort = array_values(array_map(function($value) {
  2484. return ['id' => $value];
  2485. }, $sort));
  2486. }else{
  2487. return Result::error("组件版式数量已达上限!");
  2488. }
  2489. return Result::success($sort);
  2490. }
  2491. /**
  2492. * 获取所有通栏版式
  2493. */
  2494. public function getAllSectorPlace(array $data): array
  2495. {
  2496. $where['type_id'] = $data['type_id'];
  2497. // if($data['type_id'] == 1){
  2498. // $where['status'] = 1;
  2499. // }
  2500. if(isset($data['sector_type']) && !empty($data['sector_type'])){
  2501. $where['sector_type'] = $data['sector_type'];
  2502. }
  2503. if(isset($data['component_num']) && !empty($data['component_num'])){
  2504. $where['component_num'] = $data['component_num'];
  2505. }
  2506. $sector_place = SectorPlace::where($where)
  2507. ->when($data['type_id'] == 2, function($query) use($data){
  2508. $query->orderBy('sort_id','asc');
  2509. })
  2510. ->get()->all();
  2511. if($data['type_id'] == 2){
  2512. foreach($sector_place as $key => $value){
  2513. $sector_place[$key]['component'] = Component::where('type_id',$value['type'])
  2514. ->where('component_width',$value['width'])
  2515. ->where('component_height',$value['height'])
  2516. ->get()->all();
  2517. }
  2518. }
  2519. if(empty($sector_place)){
  2520. return Result::error('通栏版式不存在!');
  2521. }
  2522. return Result::success($sector_place);
  2523. }
  2524. /**
  2525. * 组件管理-获取组件类型
  2526. */
  2527. public function getComponentType(array $data): array
  2528. {
  2529. $where = [];
  2530. if(isset($data['id']) && !empty($data['id'])){
  2531. $where['id'] = $data['id'];
  2532. }
  2533. $component_type = ComponentType::where($where)->get()->all();
  2534. if(empty($component_type)){
  2535. return Result::error('组件类型不存在!');
  2536. }
  2537. if(count($component_type) == 1){
  2538. $all_code = json_decode($component_type[0]['com_code'] ?? '',true);
  2539. $component_type[0]['all_code'] = $all_code['listType'] ?? [];
  2540. $result = $component_type[0];
  2541. }else{
  2542. $result = $component_type;
  2543. }
  2544. if(empty($component_type)){
  2545. return Result::error('组件类型不存在!');
  2546. }
  2547. return Result::success($component_type);
  2548. }
  2549. /**
  2550. * 组件管理-获取所有组件样式
  2551. */
  2552. public function getAllComponent(array $data): array
  2553. {
  2554. $where = [];
  2555. if((isset($data['sector_id']) && !empty($data['sector_id'])) || (isset($data['sort_id']) && !empty($data['sort_id']))){
  2556. $sector_id['sector.sector_id'] = $data['sector_id'];
  2557. $sector['sector_component.sort_id'] = $data['sort_id'];
  2558. $sectors = Sector::where($sector_id)
  2559. ->where('sector.template_id',$data['template_id'])
  2560. ->leftJoin('sector_component','sector.id','sector_component.sectorid')
  2561. ->where($sector)
  2562. ->select('sector.template_id','sector_component.component_id')
  2563. ->get()->all();
  2564. // return Result::success($sectors);
  2565. $component_id = array_column($sectors,'component_id');
  2566. $template = ['template_id' => $sectors[0]['template_id']];
  2567. $component = ComponentImg::whereIn('component_id',$component_id)
  2568. ->where($template)
  2569. ->select('img_id','img_name','img_url','template_id')
  2570. ->orderBy('component_img.img_id','asc')
  2571. ->get()->all();
  2572. }else{
  2573. if(isset($data['type_id']) && !empty($data['type_id'])){
  2574. $where['component.type_id'] = $data['type_id'];
  2575. }
  2576. if(isset($data['width']) && !empty($data['width'])){
  2577. $where['component.component_width'] = $data['width'];
  2578. }
  2579. if(isset($data['height']) && !empty($data['height'])){
  2580. $where['component.component_height'] = $data['height'];
  2581. }
  2582. $component = Component::where($where)
  2583. ->leftJoin('component_img','component.component_id','=','component_img.component_id')
  2584. ->select('component.*','component_img.img_id','component_img.img_url','component_img.img_name')
  2585. // ->orderBy('component_img.template_id')
  2586. ->orderBy('component_img.img_id','asc')
  2587. ->get()->all();
  2588. }
  2589. if(empty($component)){
  2590. return Result::error('组件不存在!');
  2591. }
  2592. return Result::success($component);
  2593. }
  2594. /**
  2595. * 自助建站-流程管理-获取所有通栏
  2596. */
  2597. public function getAllSector(array $data): array
  2598. {
  2599. $where = [];
  2600. if(isset($data['template_id']) && !empty($data['template_id'])){
  2601. $where['sector.template_id'] = $data['template_id'];
  2602. }
  2603. if(isset($data['page_type']) && !empty($data['page_type'])){
  2604. array_push($where,['sector.page_type', 'like', '%'.$data['page_type'].'%']);
  2605. }
  2606. $sector = Sector::where($where)
  2607. ->leftJoin('sector_component', 'sector.id', '=', 'sector_component.sectorid')
  2608. ->leftJoin('component', 'sector_component.component_id', '=', 'component.component_type')
  2609. ->when(isset($data['template_id']), function ($query) use ($data) {
  2610. // 当 type_id 等于 11 时,关联查询 component_img 表并添加 img_url 字段
  2611. return $query->leftJoin('component_img', function ($join) use ($data) {
  2612. $join->on('component.component_type', '=', 'component_img.component_id')
  2613. ->where('component_img.template_id', $data['template_id'])
  2614. ->where('component.type_id', 11);
  2615. });
  2616. })
  2617. ->select('sector.sector_name', 'sector.sector_id', 'component.*', 'component_img.img_url'
  2618. ,'sector.pic_height','sector.sector_img','sector_component.sort_id')
  2619. ->orderBy('sector_component.sort_id')
  2620. ->orderBy('sector_component.sector_id')
  2621. ->get()->all();
  2622. if(empty($sector)){
  2623. return Result::error('通栏不存在!');
  2624. }
  2625. $com_num = array_count_values(array_column($sector,'sector_id'));
  2626. // 使用 array_keys 和 array_diff 函数,不使用循环将值不为 1 的字段键提取到 $sectors_key 中
  2627. $sectors_key = array_keys(array_diff($com_num, [1]));
  2628. // return Result::success($sector);
  2629. $num = 0;
  2630. $array_key = 0;
  2631. foreach($sector as $key => $value){
  2632. $sector_id = $value['sector_id'];
  2633. $sectors[$key] = $value['sector_id'];
  2634. // if(isset($comlist_key) && !empty($comlist_key)){
  2635. // $sector_arr_key[$key] = array_keys($comlist_key);
  2636. // }
  2637. if(in_array($sector_id,$sectors_key) && in_array($sector_id,$sectors)){
  2638. $array_key = array_search($sector_id,$sectors);
  2639. if(isset($sectors) && !in_array($sector_id,$sectors)){
  2640. $array_key++;
  2641. }
  2642. $num++;
  2643. $array_key++;
  2644. }else{
  2645. $array_key++;
  2646. }
  2647. // var_dump($array_key);
  2648. // var_dump(in_array($sector_id,$sectors_key));
  2649. $comlist_key[$array_key][$sector_id]['sectorName'] = $value['sector_name'];
  2650. $comlist_key[$array_key][$sector_id]['sectorHeight'] = $value['pic_height'];
  2651. $comlist_key[$array_key][$sector_id]['sectorImg'] = $value['sector_img'];
  2652. $componentList['component_style'] = 1;
  2653. $componentList['sort'] = $value['sort_id'];
  2654. // 1:资讯;2:广告;3:静态;
  2655. $component_data = empty($value['component_data']) ? null : (json_decode($value['component_data']) ?? []);
  2656. // 检查 $value['component_column'] 是否为非空字符串,避免传递 null 给 json_decode
  2657. $listType = empty($value['component_column']) ? null : (json_decode($value['component_column']) ?? []);;
  2658. // $page[$key][$setor_id]['componentList'] =
  2659. // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;7:资讯-栏目类组件;8:列表类组件;9:详情类组件;
  2660. // 10:二级导航栏类组件;11:广告类;12:静态资源类;13:单页导航类;14:广告资讯混合类;15:滚动图文;16:搜索框类;17:单页列表类;18:单页详情类;
  2661. if(in_array($value['type_id'],[1,2,3,4,5,6,7,8,9,15,17,18])){
  2662. $type = 1;
  2663. $componentList['component_type'] = $type;
  2664. if(in_array($value['type_id'],[7,15]) && $data['page_type'] == 1){
  2665. $component_data->componentData->name = '请选择导航..';
  2666. }else if(in_array($value['type_id'],[7,15]) && $data['page_type'] == 2){
  2667. $component_data->componentData->name = '自动生成';
  2668. }else if($data['page_type'] == 3){
  2669. if($value['type_id'] == 4){
  2670. $component_data->componentData->name = '最新资讯';
  2671. }
  2672. if($value['type_id'] == 6){
  2673. $component_data->componentData->name = '热点精选';
  2674. }
  2675. }else{
  2676. unset($component_data->componentData->name);
  2677. }
  2678. $componentData = $component_data->componentData;
  2679. $componentList['componentData'] = is_object($componentData) ? (array)$componentData ?? [] : $componentData ?? [];
  2680. // $page_listType = is_object($listType) ? (array)$listType->listType ?? [] : $listType['listType'] ?? [];
  2681. $componentList['componentData']['listType'] = $listType->listType;
  2682. }else if(in_array($value['type_id'],[10,12,13,16])){
  2683. $type = 3;
  2684. $componentList['component_type'] = $type;
  2685. $componentList['componentData']=(object)[];
  2686. }else if($value['type_id']== 11){
  2687. $type = 2;
  2688. $componentList['component_type'] = $type;
  2689. $componentList['componentData']=(object)[];
  2690. $ad = json_decode($value['ad']) ?? [];
  2691. if(is_object($ad)){
  2692. $ad->thumb = $value['img_url'];
  2693. }else{
  2694. $ad['thumb'] = $value['img_url'];
  2695. }
  2696. $comlist_key[$array_key][$sector_id]['ad'] =is_object($ad) ? (array)$ad ?? [] : $ad ?? [];
  2697. // 在 $page[$key][$setor_id] 中增加一个键值为 ad 的数组
  2698. // $page[$key][$setor_id]['ad'] = is_object($ad) ? (array)$ad->ad ?? [] : $ad['ad'] ?? [];
  2699. }else if($value['type_id'] == 14){
  2700. $type = 1;
  2701. $componentList['component_type'] = $type;
  2702. if($data['page_type'] == 1){
  2703. $component_data->componentData->name = '请选择导航..';
  2704. }
  2705. $componentData = $component_data->componentData;
  2706. $componentList['componentData'] = is_object($componentData) ? (array)$componentData ?? [] : $componentData ?? [];
  2707. $componentList['componentData']['listType'] = $listType->listType;
  2708. $ad = json_decode($value['ad']) ?? [];
  2709. $comlist_key[$array_key][$sector_id]['ad'] =is_object($ad) ? (array)$ad ?? [] : $ad ?? [];
  2710. }else{
  2711. }
  2712. if( in_array($sector_id,$sectors_key)){
  2713. $comlist_key[$array_key][$sector_id]['componentList'][$num-1] = $componentList;
  2714. $comlist_key[$array_key][$sector_id]['componentList'] = array_values($comlist_key[$array_key][$sector_id]['componentList']);
  2715. }else{
  2716. $comlist_key[$array_key][$sector_id]['componentList'] = $componentList;
  2717. }
  2718. $keys[$key] = $key;
  2719. }
  2720. // return Result::success($sector_arr_key);
  2721. // $page[$keys] = array_column($page,$sectors_key[0]);
  2722. $comlist_key = array_values($comlist_key);
  2723. // $sector_page = json_encode($comlist_key);
  2724. if(empty($comlist_key)){
  2725. return Result::error('通栏不存在!');
  2726. }
  2727. return Result::success($comlist_key);
  2728. // return Result::success(gettype($listType));
  2729. }
  2730. /**
  2731. * 自助建站-组件管理-获取组件预览图列表
  2732. */
  2733. public function getComponentImgList(array $data): array
  2734. {
  2735. $where['component_img.component_id'] = $data['component_id'];
  2736. if(isset($data['template_id']) && !empty($data['template_id'])){
  2737. $where['component_img.template_id'] = $data['template_id'];
  2738. }
  2739. $component_img = ComponentImg::where($where)
  2740. ->leftJoin('template','component_img.template_id','=','template.template_id')
  2741. ->leftJoin('component','component_img.component_id','=','component.component_type')
  2742. ->select('component_img.*','template.template_name','component.component_name')
  2743. ->orderBy('component_img.template_id')
  2744. ->orderBy('component_img.img_id')
  2745. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  2746. if($component_img->isEmpty()){
  2747. return Result::error('组件预览图不存在!');
  2748. }
  2749. $component_img = [
  2750. 'data' => $component_img->items(),
  2751. 'total' => $component_img->total(),
  2752. ];
  2753. return Result::success($component_img);
  2754. }
  2755. /**
  2756. * 自助建站-组件管理-添加组件预览图
  2757. */
  2758. public function addComponentImg(array $data): array
  2759. {
  2760. unset($data['user_id']);
  2761. $component = Component::where('component_type',$data['component_id'])->first();
  2762. if(empty($component)){
  2763. return Result::error('组件不存在!');
  2764. }
  2765. if($component['type_id'] == 11){
  2766. $img = ComponentImg::where('component_id',$data['component_id'])->where('template_id',$data['template_id'])->get()->all();
  2767. if(!empty($img)){
  2768. return Result::error('该组件已存在此皮肤的预览图!');
  2769. }
  2770. }
  2771. $component = ComponentImg::where('template_id',$data['template_id'])->where('component_id',$data['component_id'])->where('img_id',$data['img_id'])->first();
  2772. if(!empty($component)){
  2773. return Result::error('组件预览图编号已存在!');
  2774. }
  2775. $component_img = ComponentImg::insertGetId($data);
  2776. if(empty($component_img)){
  2777. return Result::error('添加失败!');
  2778. }
  2779. return Result::success($component_img);
  2780. }
  2781. /**
  2782. * 自助建站-组件管理-删除组件预览图
  2783. */
  2784. public function delComponentImg(array $data): array
  2785. {
  2786. $component_img = ComponentImg::where('id',$data['id'])->delete();
  2787. if(empty($component_img)){
  2788. return Result::error('删除失败!');
  2789. }
  2790. return Result::success($component_img);
  2791. }
  2792. /**
  2793. * 自助建站-组件管理-更新组件预览图
  2794. */
  2795. public function updateComponentImg(array $data): array
  2796. {
  2797. $component = Component::where('component_type',$data['component_id'])->first();
  2798. if(empty($component)){
  2799. return Result::error('组件不存在!');
  2800. }
  2801. if($component['type_id'] == 11){
  2802. $img = ComponentImg::where('id','!=',$data['id'])->where('component_id',$data['component_id'])->where('template_id',$data['template_id'])->get()->all();
  2803. if(!empty($img)){
  2804. return Result::error('该组件已存在此皮肤的预览图!');
  2805. }
  2806. }
  2807. $component = ComponentImg::where('id','!=',$data['id'])->where('component_id',$data['component_id'])->where('template_id',$data['template_id'])->where('img_id',$data['img_id'])->first();
  2808. if(!empty($component)){
  2809. return Result::error('组件预览图编号已存在!');
  2810. }
  2811. // return Result::success($component);
  2812. unset($data['user_id']);
  2813. // unset($data['updated_at']);
  2814. $id = $data['id'];
  2815. unset($data['id']);
  2816. // return Result::success($data);
  2817. $component_img = ComponentImg::where('id',$id)->update($data);
  2818. if(empty($component_img)){
  2819. return Result::error('更新失败!');
  2820. }
  2821. return Result::success($component_img);
  2822. }
  2823. /**
  2824. * 自助建站-获取通栏类型
  2825. */
  2826. public function getSectorType(array $data): array
  2827. {
  2828. $sector = SectorType::get()->all();
  2829. if(empty($sector)){
  2830. return Result::error('通栏类型不存在!');
  2831. }
  2832. return Result::success($sector);
  2833. }
  2834. /**
  2835. * 自助建站-添加样式代码
  2836. */
  2837. public function addStyleCode(array $data): array
  2838. {
  2839. unset($data['status']);
  2840. $style_code = StyleCode::insertGetId($data);
  2841. if(empty($style_code)){
  2842. return Result::error('添加失败!');
  2843. }
  2844. return Result::success($style_code);
  2845. }
  2846. /**
  2847. * 自助建站-获取样式代码
  2848. */
  2849. public function getStyleCode(array $data): array
  2850. {
  2851. unset($data['status']);
  2852. $style_code = StyleCode::get()->all();
  2853. if(empty($style_code)){
  2854. return Result::error('样式代码不存在!');
  2855. }
  2856. return Result::success($style_code);
  2857. }
  2858. }