PublicRpcService.php 100 KB

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