PublicRpcService.php 108 KB

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