PublicRpcService.php 120 KB

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