PublicRpcService.php 94 KB

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