PublicRpcService.php 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252
  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. $data['status'] = 0;
  1112. // 通栏分类:1:资讯类:2:通栏广告类;3:混合类;4:头条类;5:轮播图类;
  1113. $sector_code = [
  1114. 'sectorName' => $data['sector_name'],
  1115. 'sectorId' => $data['sector_id'],
  1116. 'sectorType' => $data['sector_type'],
  1117. 'sectorPlace' => $data['place_type'],
  1118. ];
  1119. // return Result::success($sector_code);
  1120. $data['sector_code'] = json_encode($sector_code);
  1121. $result = Sector::insertGetId($data);
  1122. if (empty($result)) {
  1123. return Result::error('添加失败');
  1124. }
  1125. return Result::success($result);
  1126. }
  1127. /**
  1128. * 删除通栏
  1129. * @param array $data
  1130. * @return array
  1131. */
  1132. public function delSector(array $data): array
  1133. {
  1134. $component_id = Component::where('sector_id', $data['id'])->pluck('id')->toArray();
  1135. if (!empty($component_id)) {
  1136. return Result::error('请先删除相关组件!');
  1137. }
  1138. $result = Sector::where('id', $data['id'])->delete();
  1139. if ($result == 1) {
  1140. return Result::success('删除成功');
  1141. } else {
  1142. return Result::error('删除失败');
  1143. }
  1144. }
  1145. /**
  1146. * 修改通栏
  1147. * @param array $data
  1148. * @return array
  1149. */
  1150. public function updateSector(array $data): array
  1151. {
  1152. unset($data['user_id']);
  1153. $sector = Sector::where('id', $data['id'])->first();
  1154. if (empty($sector)) {
  1155. return Result::error('通栏不存在!');
  1156. }
  1157. if($sector['sector_id'] != $data['sector_id']){
  1158. $sector_id = Sector::where('sector_id',$data['sector_id'])->first();
  1159. if(!empty($sector_id)){
  1160. return Result::error('通栏编号已存在!');
  1161. }
  1162. }
  1163. $sector_code = [
  1164. 'sectorName' => strval($data['sector_name']),
  1165. 'sectorId' => intval($data['sector_id']),
  1166. 'sectorType' => intval($data['sector_type']),
  1167. 'sectorPlace' => intval($data['place_type']),
  1168. ];
  1169. // return Result::success($sector_code);
  1170. $data['sector_code'] = json_encode($sector_code);
  1171. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1172. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1173. $data['page_type'] = json_encode($data['page_type']);
  1174. $template = Template::where('template_id', $data['template_id'])
  1175. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
  1176. ->first();
  1177. if (empty($template)) {
  1178. return Result::error('皮肤不存在!');
  1179. }
  1180. $result = Sector::where('id', $data['id'])->update($data);
  1181. if ($result == 1) {
  1182. return Result::success('修改成功');
  1183. } else {
  1184. return Result::error('修改失败');
  1185. }
  1186. }
  1187. public function getComponentList(array $data): array
  1188. {
  1189. $where = [];
  1190. if (isset($data['component_name']) && !empty($data['component_name'])) {
  1191. array_push($where, ['component.component_name', 'like', '%' . $data['component_name'] . '%']);
  1192. }
  1193. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])) {
  1194. array_push($where, ['size.width', 'like', '%' . $data['width'] . '%']);
  1195. array_push($where, ['size.height', 'like', '%' . $data['height'] . '%']);
  1196. } else if (isset($data['width']) && !empty($data['width'])) {
  1197. array_push($where, ['size.width', 'like', '%' . $data['width'] . '%']);
  1198. } else if (isset($data['height']) && !empty($data['height'])) {
  1199. array_push($where, ['size.height', 'like', '%' . $data['height'] . '%']);
  1200. } else {
  1201. }
  1202. if(isset($data['type_id']) && !empty($data['type_id'])){
  1203. $where['component.type_id'] = $data['type_id'];
  1204. }
  1205. $result = Component::where($where)
  1206. ->leftJoin('component_type','component_type.id','=','component.type_id')
  1207. ->select( 'component.*', 'component_type.com_typename')
  1208. ->orderBy('component.updated_at', 'desc')
  1209. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  1210. if(empty($result)){
  1211. return Result::error('暂无数据');
  1212. }
  1213. return Result::success($result);
  1214. }
  1215. public function getComponentInfo(array $data): array
  1216. {
  1217. $where = ['component.id'=>$data['id']];
  1218. $result = Component::where($where)
  1219. ->leftJoin('component_type','component_type.id','=','component.type_id')
  1220. ->select( 'component.*','component_type.com_typename')
  1221. ->get();
  1222. if(empty($result)){
  1223. return Result::error('暂无数据');
  1224. }
  1225. return Result::success($result);
  1226. }
  1227. /*
  1228. 新增组件
  1229. */
  1230. public function addComponent(array $data): array
  1231. {
  1232. unset($data['user_id']);
  1233. $component_id = Component::where('component_type',$data['component_type'])->first();
  1234. if(!empty($component_id)){
  1235. return Result::error('组件编号已存在!');
  1236. }
  1237. $component_type = ComponentType::where('id',$data['type_id'])->first();
  1238. if(empty($component_type)){
  1239. return Result::error('组件分类不存在!');
  1240. }
  1241. // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
  1242. // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
  1243. $data['type_id'] = intval($data['type_id']);
  1244. $add_arr = [
  1245. // 'template_id' => intval($data['template_id']),
  1246. 'component_type' => intval($data['component_type']),
  1247. 'component_name' => $data['component_name'],
  1248. 'component_img' => $data['component_img'],
  1249. 'component_width' => $data['component_width'],
  1250. 'component_height' => $data['component_height'],
  1251. 'type_id' => intval($data['type_id']),
  1252. 'component_keyword' => $data['component_keyword'],
  1253. ];
  1254. $component_head_code = [
  1255. 'component_type' => $add_arr['component_type'],
  1256. 'type_id' => $add_arr['type_id'],
  1257. 'component_name' => $add_arr['component_name'],
  1258. ];
  1259. $add_arr['component_code'] = json_encode($component_head_code,true);
  1260. switch($data['type_id']){
  1261. case 1: //1:资讯-头条组件;
  1262. case 2: //2:资讯-轮播组件;
  1263. case 3: //3:资讯-推荐图类组件;
  1264. case 4: //4:资讯-最新类组件;
  1265. case 5: //5:资讯-推荐类组件;
  1266. case 6: //6:资讯-热点类组件;
  1267. $add_arr['level'] = $data['type_id'];
  1268. $add_arr['img_num'] = intval($data['img_num']);
  1269. $add_arr['text_num'] = intval($data['text_num']);
  1270. $component_data['componentData'] = [
  1271. 'category_id' => '',
  1272. 'level' => $add_arr['level'],
  1273. 'imgSize' => $data['img_num'] ?? '',
  1274. 'textSize' => $data['text_num'] ?? '',
  1275. 'child' => [
  1276. 'id' => '',
  1277. 'imgSize' => '',
  1278. 'textSize' => ''
  1279. ]
  1280. ];
  1281. $add_arr['component_data'] = json_encode($component_data, true);
  1282. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1283. break;
  1284. case 7: //7:资讯-栏目类组件;
  1285. $add_arr['img_num'] = intval($data['img_num']);
  1286. $add_arr['text_num'] = intval($data['text_num']);
  1287. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1288. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1289. $component_data['componentData'] = [
  1290. 'category_id' => '',
  1291. 'level' => '',
  1292. 'imgSize' => $add_arr['img_num'] ?? '',
  1293. 'textSize' => $add_arr['text_num'] ?? '',
  1294. 'child' => [
  1295. 'id' => '',
  1296. 'imgSize' => $add_arr['child_imgnum'] ?? '',
  1297. 'textSize' => $add_arr['child_textnum'] ?? '',
  1298. ]
  1299. ];
  1300. $add_arr['component_data'] = json_encode($component_data,true);
  1301. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1302. break;
  1303. case 8: //8:列表类组件;
  1304. $add_arr['pageSize'] = intval($data['pageSize']);
  1305. $component_data['componentData'] = [
  1306. 'category_id' => '',
  1307. 'pageType' => [
  1308. 'page' => 1,
  1309. 'pageSize' => $add_arr['pageSize'] ?? '',
  1310. ]
  1311. ];
  1312. $add_arr['component_data'] = json_encode($component_data,true);
  1313. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1314. break;
  1315. case 9: //9:详情类组件;
  1316. $component_data['componentData'] = [
  1317. 'article_id' => '',
  1318. ];
  1319. $add_arr['component_data'] = json_encode($component_data,true);
  1320. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1321. break;
  1322. case 10: //10:二级导航类组件;
  1323. $add_arr['cate_place'] = 1;
  1324. $add_arr['num'] = intval($data['num']);
  1325. $component_data['componentData'] = [
  1326. 'pid' => '',
  1327. 'placeid' => 1,
  1328. 'num' => $add_arr['num'],
  1329. ];
  1330. $add_arr['component_data'] = json_encode($component_data,true);
  1331. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1332. break;
  1333. case 11: //11:广告类;
  1334. $add_arr['ad_width'] = intval($data['ad_width']);
  1335. $add_arr['ad_height'] = intval($data['ad_height']);
  1336. $add_arr['component_width'] = intval($data['ad_width']);
  1337. $add_arr['component_height'] = intval($data['ad_height']);
  1338. $add_arr['ad_type'] = intval($data['ad_type']);
  1339. $add_arr['ad_img'] = $data['ad_img'];
  1340. $ad = [
  1341. 'width' => $add_arr['ad_width'],
  1342. 'height' => $add_arr['ad_height'],
  1343. 'name' => '',
  1344. 'price' => '',
  1345. 'introduce' => '',
  1346. 'website_id' => '',
  1347. 'thumb' => $add_arr['ad_img'],
  1348. 'typeid' => $add_arr['ad_type'],
  1349. 'ad_tag' => '',
  1350. ];
  1351. $add_arr['ad'] = json_encode($ad,true);
  1352. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1353. break;
  1354. case 13: //13:底部导航类;
  1355. $component_data['componentData'] = [
  1356. 'fcat_id' => '',
  1357. ];
  1358. $add_arr['component_data'] = json_encode($component_data,true);
  1359. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1360. break;
  1361. case 14:
  1362. $add_arr['ad_width'] = intval($data['ad_width']);
  1363. $add_arr['ad_height'] = intval($data['ad_height']);
  1364. $add_arr['component_width'] = intval($data['component_width']);
  1365. $add_arr['component_height'] = intval($data['component_height']);
  1366. $add_arr['ad_type'] = intval($data['ad_type']);
  1367. $add_arr['ad_img'] = $data['ad_img'];
  1368. $add_arr['img_num'] = intval($data['img_num']);
  1369. $add_arr['text_num'] = intval($data['text_num']);
  1370. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1371. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1372. $component_data['componentData'] = [
  1373. 'category_id' => '',
  1374. 'level' => '',
  1375. 'imgSize' => $data['img_num'] ?? '',
  1376. 'textSize' => $data['text_num'] ?? '',
  1377. 'child' => [
  1378. 'id' => '',
  1379. 'imgSize' => $data['child_imgnum'] ?? '',
  1380. 'textSize' => $data['child_textnum'] ?? '',
  1381. ]
  1382. ];
  1383. $ad = [
  1384. 'width' => $add_arr['ad_width'],
  1385. 'height' => $add_arr['ad_height'],
  1386. 'name' => '',
  1387. 'price' => '',
  1388. 'introduce' => '',
  1389. 'website_id' => '',
  1390. 'thumb' => $add_arr['ad_img'],
  1391. 'typeid' => $add_arr['ad_type'],
  1392. 'ad_tag' => '',
  1393. ];
  1394. $add_arr['ad'] = json_encode($ad,true);
  1395. $add_arr['component_data'] = json_encode($component_data,true);
  1396. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1397. break;
  1398. default:
  1399. break;
  1400. }
  1401. // return Result::success($add_arr['component_data']);
  1402. $result = Component::insertGetId($add_arr);
  1403. if(empty($result)){
  1404. return Result::error('添加失败!');
  1405. }
  1406. return Result::success($result);
  1407. }
  1408. public function delComponent(array $data): array
  1409. {
  1410. $component = Component::where('id', $data['id'])->first();
  1411. if(empty($component)){
  1412. return Result::error('组件不存在!');
  1413. }
  1414. $result = Component::where('id',$data['id'])->delete();
  1415. if(empty($result)){
  1416. return Result::error('删除失败!');
  1417. }
  1418. return Result::success($result);
  1419. }
  1420. public function updateComponent(array $data): array
  1421. {
  1422. unset($data['user_id']);
  1423. $id = $data['id'];
  1424. unset($data['id']);
  1425. $component_id = Component::where('id','!=',$id)->where('component_type',$data['component_type'])->first();
  1426. if(!empty($component_id) || $component_id != null){
  1427. return Result::error('组件编号已存在!');
  1428. }
  1429. $component_type = ComponentType::where('id',$data['type_id'])->first();
  1430. if(empty($component_type)){
  1431. return Result::error('组件分类不存在!');
  1432. }
  1433. // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
  1434. // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
  1435. $data['type_id'] = intval($data['type_id']);
  1436. $add_arr = [
  1437. // 'template_id' => intval($data['template_id']),
  1438. 'component_type' => intval($data['component_type']),
  1439. 'component_name' => $data['component_name'],
  1440. 'component_img' => $data['component_img'],
  1441. 'component_width' => $data['component_width'],
  1442. 'component_height' => $data['component_height'],
  1443. 'type_id' => intval($data['type_id']),
  1444. 'component_keyword' => $data['component_keyword'],
  1445. ];
  1446. $component_head_code = [
  1447. 'component_type' => $add_arr['component_type'],
  1448. 'type_id' => $add_arr['type_id'],
  1449. 'component_name' => $add_arr['component_name'],
  1450. ];
  1451. $add_arr['component_code'] = json_encode($component_head_code,true);
  1452. switch($data['type_id']){
  1453. case 1: //1:资讯-头条组件;
  1454. case 2: //2:资讯-轮播组件;
  1455. case 3: //3:资讯-推荐图类组件;
  1456. case 4: //4:资讯-最新类组件;
  1457. case 5: //5:资讯-推荐类组件;
  1458. case 6: //6:资讯-热点类组件;
  1459. $add_arr['level'] = $data['type_id'];
  1460. $add_arr['img_num'] = intval($data['img_num']);
  1461. $add_arr['text_num'] = intval($data['text_num']);
  1462. $component_data['componentData'] = [
  1463. 'category_id' => '',
  1464. 'level' => $add_arr['level'],
  1465. 'imgSize' => $data['img_num'] ?? '',
  1466. 'textSize' => $data['text_num'] ?? '',
  1467. 'child' => [
  1468. 'id' => '',
  1469. 'imgSize' => '',
  1470. 'textSize' => ''
  1471. ]
  1472. ];
  1473. $add_arr['component_data'] = json_encode($component_data, true);
  1474. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1475. break;
  1476. case 7: //7:资讯-栏目类组件;
  1477. $add_arr['img_num'] = intval($data['img_num']);
  1478. $add_arr['text_num'] = intval($data['text_num']);
  1479. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1480. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1481. $component_data['componentData'] = [
  1482. 'category_id' => '',
  1483. 'level' => '',
  1484. 'imgSize' => $add_arr['img_num'] ?? '',
  1485. 'textSize' => $add_arr['text_num'] ?? '',
  1486. 'child' => [
  1487. 'id' => '',
  1488. 'imgSize' => $add_arr['child_imgnum'] ?? '',
  1489. 'textSize' => $add_arr['child_textnum'] ?? '',
  1490. ]
  1491. ];
  1492. $add_arr['component_data'] = json_encode($component_data,true);
  1493. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1494. break;
  1495. case 8: //8:列表类组件;
  1496. $add_arr['pageSize'] = intval($data['pageSize']);
  1497. $component_data['componentData'] = [
  1498. 'category_id' => '',
  1499. 'pageType' => [
  1500. 'page' => 1,
  1501. 'pageSize' => $add_arr['pageSize'] ?? '',
  1502. ]
  1503. ];
  1504. $add_arr['component_data'] = json_encode($component_data,true);
  1505. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1506. break;
  1507. case 9: //9:详情类组件;
  1508. $component_data['componentData'] = [
  1509. 'article_id' => '',
  1510. ];
  1511. $add_arr['component_data'] = json_encode($component_data,true);
  1512. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1513. break;
  1514. case 10: //10:二级导航类组件;
  1515. $add_arr['cate_place'] = 1;
  1516. $add_arr['num'] = intval($data['num']);
  1517. $component_data['componentData'] = [
  1518. 'pid' => '',
  1519. 'placeid' => 1,
  1520. 'num' => $add_arr['num'],
  1521. ];
  1522. $add_arr['component_data'] = json_encode($component_data,true);
  1523. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1524. break;
  1525. case 11: //11:广告类;
  1526. $add_arr['ad_width'] = intval($data['ad_width']);
  1527. $add_arr['ad_height'] = intval($data['ad_height']);
  1528. $add_arr['component_width'] = intval($data['ad_width']);
  1529. $add_arr['component_height'] = intval($data['ad_height']);
  1530. $add_arr['ad_type'] = intval($data['ad_type']);
  1531. $add_arr['ad_img'] = $data['ad_img'];
  1532. $ad = [
  1533. 'width' => $add_arr['ad_width'],
  1534. 'height' => $add_arr['ad_height'],
  1535. 'name' => '',
  1536. 'price' => '',
  1537. 'introduce' => '',
  1538. 'website_id' => '',
  1539. 'thumb' => $add_arr['ad_img'],
  1540. 'typeid' => $add_arr['ad_type'],
  1541. 'ad_tag' => '',
  1542. ];
  1543. $add_arr['ad'] = json_encode($ad,true);
  1544. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1545. break;
  1546. case 13: //13:底部导航类;
  1547. $component_data['componentData'] = [
  1548. 'fcat_id' => '',
  1549. ];
  1550. $add_arr['component_data'] = json_encode($component_data,true);
  1551. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1552. break;
  1553. case 14:
  1554. $add_arr['ad_width'] = intval($data['ad_width']);
  1555. $add_arr['ad_height'] = intval($data['ad_height']);
  1556. $add_arr['component_width'] = intval($data['component_width']);
  1557. $add_arr['component_height'] = intval($data['component_height']);
  1558. $add_arr['ad_type'] = intval($data['ad_type']);
  1559. $add_arr['ad_img'] = $data['ad_img'];
  1560. $add_arr['img_num'] = intval($data['img_num']);
  1561. $add_arr['text_num'] = intval($data['text_num']);
  1562. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1563. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1564. $component_data['componentData'] = [
  1565. 'category_id' => '',
  1566. 'level' => '',
  1567. 'imgSize' => $data['img_num'] ?? '',
  1568. 'textSize' => $data['text_num'] ?? '',
  1569. 'child' => [
  1570. 'id' => '',
  1571. 'imgSize' => $data['child_imgnum'] ?? '',
  1572. 'textSize' => $data['child_textnum'] ?? '',
  1573. ]
  1574. ];
  1575. $ad = [
  1576. 'width' => $add_arr['ad_width'],
  1577. 'height' => $add_arr['ad_height'],
  1578. 'name' => '',
  1579. 'price' => '',
  1580. 'introduce' => '',
  1581. 'website_id' => '',
  1582. 'thumb' => $add_arr['ad_img'],
  1583. 'typeid' => $add_arr['ad_type'],
  1584. 'ad_tag' => '',
  1585. ];
  1586. $add_arr['ad'] = json_encode($ad,true);
  1587. $add_arr['component_data'] = json_encode($component_data,true);
  1588. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1589. break;
  1590. default:
  1591. break;
  1592. }
  1593. $result = Component::where('id',$id)->update($add_arr);
  1594. if(empty($result)){
  1595. Db::rollBack();
  1596. return Result::error('修改失败!');
  1597. }
  1598. return Result::success($result);
  1599. }
  1600. public function getWebsiteTemplateInfo(array $data)
  1601. {
  1602. $where = [];
  1603. if (isset($data['id'])) {
  1604. $where[] = ['id', '=', $data['id']];
  1605. }
  1606. $result = WebsiteTemplateInfo::where($where)
  1607. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1608. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  1609. ->select('website_template_info.*', 'website.website_name')
  1610. ->get();
  1611. if ($result) {
  1612. return Result::success($result);
  1613. } else {
  1614. return Result::error('暂无数据');
  1615. }
  1616. }
  1617. /**
  1618. * 自助建站----1.获取页面类型回显
  1619. * @param array $data
  1620. * @return array
  1621. */
  1622. public function getWebPageType(array $data): array
  1623. {
  1624. // 1:图片 2:文字 3:底部
  1625. $friend_link = Link::where('website_id', $data['website_id'])->where('type', 3)->get();
  1626. if (empty($friend_link->toArray())) {
  1627. return Result::error('暂无友情链接数据!');
  1628. }
  1629. $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
  1630. if (empty($footer_category->toArray())) {
  1631. return Result::error('暂无底部导航数据!');
  1632. }
  1633. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('page_type');
  1634. if (empty($page_type)) {
  1635. $page_type = [];
  1636. } else {
  1637. $page_type = json_decode($page_type, true);
  1638. }
  1639. // '网站页面类型(存数组)1:首页 2:分类页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页
  1640. if (isset($page_type) && in_array(5, $page_type)) {
  1641. $page_type = 1;
  1642. } else {
  1643. $page_type = 0;
  1644. }
  1645. $result = [
  1646. 'friend_link' => $friend_link,
  1647. 'footer_category' => $footer_category,
  1648. 'page_type' => $page_type,
  1649. ];
  1650. return Result::success($result);
  1651. }
  1652. /**
  1653. * 自助建站----2.添加页面类型
  1654. * @param array $data
  1655. * @return array
  1656. */
  1657. public function addWebPageType(array $data): array
  1658. {
  1659. // return Result::success($data);
  1660. // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
  1661. if ($data['is_search'] == 1) {
  1662. $page_type = json_encode([1, 2, 3, 4, 5, 6, 7]);
  1663. } else {
  1664. $page_type = json_encode([1, 2, 3, 4, 6, 7]);
  1665. }
  1666. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1667. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1668. // return Result::success($website_template_info);
  1669. // return Result::success(empty($website_template_info));
  1670. if (empty($website_template_info)) {
  1671. $result = WebsiteTemplateInfo::insertGetId(['website_id' => $data['website_id'], 'page_type' => $page_type, 'user_id' => $data['user_id']]);
  1672. } else {
  1673. if ($website_template_info['status'] == 2) {
  1674. return Result::error('网站已应用,不可再次修改!');
  1675. }
  1676. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type], ['action_id' => 1, 'user_id' => $data['user_id']]);
  1677. }
  1678. if ($result) {
  1679. return Result::success($result);
  1680. } else {
  1681. return Result::error('添加失败');
  1682. }
  1683. }
  1684. /**
  1685. * 自助建站---流程---3.选择皮肤列表
  1686. * @param array $data
  1687. * @return array
  1688. */
  1689. public function getWebsiteTemplateList(array $data): array
  1690. {
  1691. $where = [];
  1692. if (isset($data['template_class_id']) && $data['template_class_id']) {
  1693. $where[] = ['template_class_id', '=', $data['template_class_id']];
  1694. }
  1695. // 0:未构建 1:未应用 2:已应用 status
  1696. $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1697. if (empty($templste_info)) {
  1698. return Result::error('请先填写网站基础信息!');
  1699. }
  1700. if ($templste_info['status'] == 2) {
  1701. return Result::error('网站已应用,不可再次修改!');
  1702. }
  1703. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1704. if (is_array($data['keyword'])) {
  1705. // 拼接多个模糊查询条件
  1706. $query = Template::query();
  1707. foreach ($data['keyword'] as $kw) {
  1708. $escapedKw = addcslashes($kw, '%_'); // 转义通配符
  1709. $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
  1710. }
  1711. } else {
  1712. $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
  1713. $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
  1714. }
  1715. } else {
  1716. $query = Template::where($where);
  1717. }
  1718. $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
  1719. // return Result::success($template_id);
  1720. if (!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])) {
  1721. $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
  1722. } else {
  1723. $template_page = [];
  1724. }
  1725. if (!empty($template_id['template_id'])) {
  1726. $result['template_id'] = $templste_info['template_id'];
  1727. }
  1728. // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
  1729. $template_page_str = json_encode($template_page);
  1730. $result['template'] = $query->where($where)
  1731. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1732. ->orderBy('updated_at', 'desc')
  1733. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1734. if (empty($result['template'])) {
  1735. $result['template'] = Template::orderBy('updated_at', 'desc')
  1736. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1737. }
  1738. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('template_id');
  1739. if ($template) {
  1740. $result['template_id'] = $template;
  1741. } else {
  1742. $result['template_id'] = 0;
  1743. }
  1744. return Result::success($result);
  1745. }
  1746. /**
  1747. * 自助建站---流程---4.选择皮肤
  1748. * @param array $data
  1749. * @return array
  1750. */
  1751. public function chooseWebsiteTemplate(array $data): array
  1752. {
  1753. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1754. if (empty($website_template_info)) {
  1755. return Result::error('请先填写网站基础信息!');
  1756. }
  1757. // 0:未构建 1:未应用 2:已应用 status
  1758. if ($website_template_info['status'] == 2) {
  1759. return Result::error('网站已应用,不可再次修改!');
  1760. }
  1761. $template = Template::where('template_id', $data['template_id'])->first();
  1762. if (empty($template)) {
  1763. return Result::error('未查询到皮肤!');
  1764. }
  1765. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1766. $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
  1767. if ($web_template) {
  1768. return Result::success($web_template);
  1769. } else {
  1770. return Result::error('选择皮肤失败!');
  1771. }
  1772. }
  1773. /**
  1774. * 自助建站---流程---5.保存模版
  1775. * @param array $data
  1776. * @return array
  1777. */
  1778. public function saveWebsiteTemplate(array $data): array
  1779. {
  1780. // return Result::success($data);
  1781. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1782. if (empty($website_template_info) || empty($website_template_info->template_id) || empty($website_template_info->page_type)) {
  1783. return Result::error('请先填写网站基础信息!');
  1784. }
  1785. // 0:未构建 1:未应用 2:已应用 status
  1786. if ($website_template_info['status'] == 2) {
  1787. return Result::error('网站已应用,不可再次保存!');
  1788. }
  1789. if ($website_template_info['action_id'] != 2) {
  1790. return Result::error('请完成之前的步骤!');
  1791. }
  1792. $template_info = WebsiteTemplate::where('website_id', $data['website_id'])->first();
  1793. // var_dump($data['template_data']);
  1794. try {
  1795. Db::beginTransaction();
  1796. if (empty($template_info)) {
  1797. $template = WebsiteTemplate::insertGetId([
  1798. 'website_id' => $data['website_id'],
  1799. 'template_data' => $data['template_data'],
  1800. 'user_id' => $data['user_id'],
  1801. 'canvas_data' => $data['canvas_data'],
  1802. 'page_type' => $website_template_info['page_type'],
  1803. 'template_id' => $website_template_info['template_id'],
  1804. ]);
  1805. } else {
  1806. $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(
  1807. [
  1808. 'template_data' => $data['template_data'],
  1809. 'user_id' => $data['user_id'],
  1810. 'canvas_data' => $data['canvas_data'],
  1811. 'page_type' => $website_template_info['page_type'],
  1812. 'template_id' => $website_template_info['template_id'],
  1813. ]
  1814. );
  1815. }
  1816. if (empty($template)) {
  1817. Db::rollback();
  1818. return Result::error('保存失败!');
  1819. } else {
  1820. $tempalte_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['status' => 1]);
  1821. if (empty($tempalte_info)) {
  1822. Db::rollback();
  1823. return Result::error('保存失败!');
  1824. }
  1825. Db::commit();
  1826. }
  1827. } catch (\Exception $e) {
  1828. return Result::error('模版数据格式错误!');
  1829. }
  1830. return Result::success($template);
  1831. }
  1832. /**
  1833. * 自助建站---流程---6.返显保存的模版
  1834. * @param array $data
  1835. * @return array
  1836. */
  1837. public function getWebsiteTemplate(array $data): array
  1838. {
  1839. $web = Website::where('id', $data['website_id'])->first();
  1840. if (empty($web)) {
  1841. return Result::error('未查询到网站信息!');
  1842. }
  1843. $template = WebsiteTemplate::where('website_id', $data['website_id'])
  1844. ->first(['website_id', 'template_id', 'page_type', 'template_data', 'canvas_data']);
  1845. if (empty($template)) {
  1846. return Result::error('未查询到模版!');
  1847. }
  1848. return Result::success($template);
  1849. }
  1850. /**
  1851. * 通栏版式管理-获取通栏版式列表
  1852. */
  1853. public function getSectorPlaceList(array $data): array
  1854. {
  1855. $where['sector_place.type_id'] = $data['type_id'];
  1856. if(isset($data['component_num']) && !empty($data['component_num'])){
  1857. $where['sector_place.component_num'] = $data['component_num'];
  1858. }
  1859. if(isset($data['sector_type']) && !empty($data['sector_type'])){
  1860. $where['sector_place.sector_type'] = $data['sector_type'];
  1861. }
  1862. // if(isset($data['component_type']) && !empty($data['component_type'])){
  1863. // $where['sector_place.component_type'] = $data['component_type'];
  1864. // }
  1865. if(isset($data['name']) && !empty($data['name'])){
  1866. array_push($where,['sector_place.name', 'like', '%'.$data['name'].'%']);
  1867. }
  1868. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
  1869. $size_id = Size::where('width','like','%' .$data['width'].'%')->where('height','like','%' .$data['height'].'%')->pluck('id');
  1870. } else if( isset($data['width']) && !empty($data['width'])){
  1871. $size_id = Size::where('width','like','%' .$data['width'].'%')->pluck('id');
  1872. }else if( isset($data['height']) && !empty($data['height'])){
  1873. $size_id = Size::where('height','like','%' .$data['height'].'%')->pluck('id');
  1874. }else{
  1875. $size_id = [];
  1876. }
  1877. $sector_place = SectorPlace::where($where)
  1878. ->when(!empty($size_id), function ($query) use ($size_id) {
  1879. $query->whereIn('sector_place.size_id', $size_id);
  1880. })
  1881. ->leftJoin('size','sector_place.size_id','=','size.id')
  1882. ->select('sector_place.*','size.width','size.height');
  1883. $result['count'] = $sector_place->count();
  1884. $result['row'] =$sector_place->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1885. if(empty($result['count'])){
  1886. return Result::error("暂无相关版式数据!");
  1887. }
  1888. return Result::success($result);
  1889. }
  1890. /**
  1891. * 通栏版式管理-添加通栏版式
  1892. */
  1893. public function addSectorPlace(array $data): array
  1894. {
  1895. // 1:通栏;2:组件;
  1896. if($data['type_id'] == 1){
  1897. $sector_place = SectorPlace::where('sector_type', $data['type'])->first();
  1898. if(!empty($sector_place)){
  1899. return Result::error('通栏版式类别编号已存在!');
  1900. }
  1901. $data = [
  1902. 'name' => $data['name'],
  1903. 'component_num' => $data['component_num'],
  1904. 'size_id' => $data['size_id'],
  1905. 'sort_id' => 0,
  1906. 'sector_img' => $data['sector_img'],
  1907. 'sector_type' => $data['type'],
  1908. 'type_id' => $data['type_id'],
  1909. 'status' => 0,
  1910. ];
  1911. }else{
  1912. $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
  1913. if(empty($sector_type)){
  1914. return Result::error('通栏版式类别不存在!');
  1915. }
  1916. // $com_query = SectorPlace::where('type_id',2);
  1917. // ->query(function($query) use ($data){
  1918. // $query->where('component_type', $data['type'])
  1919. // ->Subquery(function($subQuery) use ($data) {
  1920. // $subQuery->where('sector_type', $data['sector_type'])
  1921. // ->where('sort_id', $data['sort']);
  1922. // });
  1923. // }) //若是组件版式编号或者组件版式位置重复用此语句筛选
  1924. // ->where('sector_type',$data['sector_type']) //若是组件版式编号在同一个通栏版式下不重复就行,则启用此语句
  1925. $component = SectorPlace::where('type_id',2)->where('component_type',$data['type'])->first();
  1926. if(!empty($component)){
  1927. return Result::error('组件版式类别编号已存在!');
  1928. }
  1929. // $com_query = clone $com_query;
  1930. $com_num = SectorPlace::where('type_id',2)->where('sector_type',$data['sector_type'])->count('sort_id');
  1931. // return Result::success($com_num);
  1932. if($sector_type['component_num'] = $com_num){
  1933. $sector = SectorPlace::where('sector_type',$data['sector_type'])->where('type_id',1)->update(['status'=>1]);
  1934. if(empty($sector)){
  1935. return Result::error('通栏版式状态修改失败!');
  1936. }
  1937. }
  1938. $data = [
  1939. 'name' => $data['name'],
  1940. 'component_num' => 0,
  1941. 'size_id' => $data['size_id'],
  1942. 'sort_id' => $data['sort_id'],
  1943. 'sector_img' => $data['sector_img'],
  1944. 'component_type' => $data['type'],
  1945. 'type_id' => $data['type_id'],
  1946. 'sector_type' => $data['sector_type'],
  1947. ];
  1948. }
  1949. $result = SectorPlace::insertGetId($data);
  1950. if(empty($result)){
  1951. return Result::error('添加失败!');
  1952. }
  1953. return Result::success('添加成功!',$result);
  1954. }
  1955. /**
  1956. * 通栏版式管理-修改通栏版式
  1957. */
  1958. public function upSectorPlace(array $data): array
  1959. {
  1960. $id = $data['id'];
  1961. // 1:通栏;2:组件;
  1962. if($data['type_id'] == 1){
  1963. $sector_place = SectorPlace::where('id','!=',$id)->where('sector_type', $data['type'])->where('type_id',1)->first();
  1964. if(!empty($sector_place)){
  1965. return Result::error('通栏版式类别编号已存在!');
  1966. }
  1967. $data = [
  1968. 'name' => $data['name'],
  1969. 'component_num' => $data['component_num'],
  1970. 'size_id' => $data['size_id'],
  1971. 'sort_id' => 0,
  1972. 'sector_img' => $data['sector_img'],
  1973. 'sector_type' => $data['type'],
  1974. 'type_id' => $data['type_id'],
  1975. ];
  1976. }else{
  1977. $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
  1978. if(empty($sector_type)){
  1979. return Result::error('通栏版式类别不存在!');
  1980. }
  1981. $component = SectorPlace::where('id','!=',$id)
  1982. ->where('component_type', $data['type'])
  1983. ->where('type_id',2)
  1984. ->first();
  1985. if(!empty($component)){
  1986. return Result::error('组件版式类别编号已存在!');
  1987. }
  1988. $data = [
  1989. 'name' => $data['name'],
  1990. 'component_num' => 0,
  1991. 'size_id' => $data['size_id'],
  1992. 'sort_id' => $data['sort_id'],
  1993. 'sector_img' => $data['sector_img'],
  1994. 'component_type' => $data['type'],
  1995. 'type_id' => $data['type_id'],
  1996. 'sector_type' => $data['sector_type'],
  1997. ];
  1998. }
  1999. $result = SectorPlace::where('id',$id)->update($data);
  2000. if(empty($result)){
  2001. return Result::error('修改失败!');
  2002. }
  2003. return Result::success('修改成功!',$result);
  2004. }
  2005. /**
  2006. * 通栏版式管理-删除通栏版式
  2007. */
  2008. public function delSectorPlace(array $data): array
  2009. {
  2010. $sector_place = SectorPlace::where('id',$data['id'])->first();
  2011. if(empty($sector_place)){
  2012. return Result::error('通栏版式不存在!');
  2013. }
  2014. if($sector_place['type_id'] == 1){
  2015. $sector = Sector::where('place_type', $sector_place['sector_type'])->first();
  2016. $component = SectorPlace::where('sector_type', $sector_place['sector_type'])
  2017. ->where('type_id',2)
  2018. ->first();
  2019. if(!empty($sector) || !empty($component)){
  2020. return Result::error('通栏版式分类已应用,暂不可删除!');
  2021. }
  2022. }else{
  2023. $sector = Component::where('place_type', $sector_place['component_type'])->first();
  2024. if(!empty($sector)){
  2025. return Result::error('组件版式分类已应用,暂不可删除!');
  2026. }
  2027. $component_num = SectorPlace::where('sector_type', $sector_place['sector_type'])
  2028. ->where('type_id',1)->update(['status'=> 0]);
  2029. if(empty($component_num)){
  2030. return Result::error('通栏版式状态修改失败!');
  2031. }
  2032. }
  2033. $result = SectorPlace::where('id',$data['id'])->delete();
  2034. if(empty($result)){
  2035. return Result::error('删除失败!');
  2036. }
  2037. return Result::success('删除成功!');
  2038. }
  2039. /**
  2040. * 自助建站-通栏版式管理-获取通栏版式详情
  2041. */
  2042. public function getSectorPlaceInfo(array $data): array
  2043. {
  2044. $result = SectorPlace::where('sector_place.id',$data['id'])
  2045. ->leftJoin('size','sector_place.size_id','=','size.id')
  2046. ->select('sector_place.*','size.width','size.height')
  2047. ->first();
  2048. if(empty($result)){
  2049. return Result::error('通栏版式不存在!');
  2050. }
  2051. return Result::success($result);
  2052. }
  2053. /**
  2054. * 自助建站-通栏版式管理-获取通栏版式列表
  2055. */
  2056. public function getSectorPlaceSort(array $data): array
  2057. {
  2058. $sector = SectorPlace::where('sector_type',$data['sector_type'])->first();
  2059. if(empty($sector)){
  2060. return Result::error('通栏版式不存在!');
  2061. }
  2062. $component = SectorPlace::where('type_id',2)->where('sector_type',$sector['sector_type'])->pluck('sort_id')->toArray();
  2063. if(count($component) < $sector['component_num']){
  2064. // 根据 $sector['component_num'] 的值生成对应元素数量的数组
  2065. if (isset($sector['component_num']) && is_numeric($sector['component_num'])) {
  2066. $num = intval($sector['component_num']);
  2067. if ($num > 0 && $num <= 10) {
  2068. // 使用 range 函数生成一个从 1 到 $num 的连续整数数组,存储到 $sector_arr 中
  2069. $sector_arr = range(1, $num);
  2070. } else {
  2071. $sector_arr = [];
  2072. }
  2073. } else {
  2074. $sector_arr = [];
  2075. }
  2076. // 获取 $sector_arr 中不在 $component 里的元素
  2077. $sort = array_diff($sector_arr, $component);
  2078. // return Result::success($sort);
  2079. }
  2080. if(!empty($sort)){
  2081. $sort = array_values(array_map(function($value) {
  2082. return ['id' => $value];
  2083. }, $sort));
  2084. }else{
  2085. return Result::error("组件版式数量已达上限!");
  2086. }
  2087. return Result::success($sort);
  2088. }
  2089. /**
  2090. * 获取所有通栏版式
  2091. */
  2092. public function getAllSectorPlace(array $data): array
  2093. {
  2094. $where['type_id'] = $data['type_id'];
  2095. if($data['type_id'] == 1){
  2096. $where['status'] = 1;
  2097. }
  2098. if(isset($data['sector_type']) && !empty($data['sector_type'])){
  2099. $where['sector_type'] = $data['sector_type'];
  2100. }
  2101. if(isset($data['component_num']) && !empty($data['component_num'])){
  2102. $where['component_num'] = $data['component_num'];
  2103. }
  2104. $sector_place = SectorPlace::where($where)
  2105. ->leftJoin('size','sector_place.size_id','=','size.id')
  2106. ->select('sector_place.*','size.width','size.height')
  2107. ->get()->all();
  2108. if(empty($sector_place)){
  2109. return Result::error('通栏版式不存在!');
  2110. }
  2111. return Result::success($sector_place);
  2112. }
  2113. /**
  2114. * 组件管理-获取组件类型
  2115. */
  2116. public function getComponentType(array $data): array
  2117. {
  2118. $where = [];
  2119. if(isset($data['id']) && !empty($data['id'])){
  2120. $where['id'] = $data['id'];
  2121. }
  2122. $component_type = ComponentType::where($where)->get()->all();
  2123. if(empty($component_type)){
  2124. return Result::error('组件类型不存在!');
  2125. }
  2126. if(count($component_type) == 1){
  2127. $all_code = json_decode($component_type[0]['com_code'] ?? '',true);
  2128. $component_type[0]['all_code'] = $all_code['listType'] ?? [];
  2129. $result = $component_type[0];
  2130. }else{
  2131. $result = $component_type;
  2132. }
  2133. if(empty($component_type)){
  2134. return Result::error('组件类型不存在!');
  2135. }
  2136. return Result::success($component_type);
  2137. }
  2138. /**
  2139. * 组件管理-获取所有组件
  2140. */
  2141. public function getAllComponent(array $data): array
  2142. {
  2143. $where = [];
  2144. if(isset($data['sector_id']) && !empty($data['sector_id'])){
  2145. $where['component.sector_id'] = $data['sector_id'];
  2146. }
  2147. if(isset($data['sort_id']) && !empty($data['sort_id'])){
  2148. $where['component.sort_id'] = $data['sort_id'];
  2149. }
  2150. $component = Component::where($where)->leftJoin('size','component.size_id','=','size.id')
  2151. ->select('component.*','size.width','size.height')
  2152. ->get()->all();
  2153. if(empty($component)){
  2154. return Result::error('组件不存在!');
  2155. }
  2156. return Result::success($component);
  2157. }
  2158. /**
  2159. * 自助建站-流程管理-获取所有通栏
  2160. */
  2161. public function getAllSector(array $data): array
  2162. {
  2163. $where = [];
  2164. if(isset($data['template_id']) && !empty($data['template_id'])){
  2165. $where['template_id'] = $data['template_id'];
  2166. }
  2167. if(isset($data['page_type']) && !empty($data['page_type'])){
  2168. array_push($where,['page_type', 'like', '%'.$data['page_type'].'%']);
  2169. }
  2170. if(isset($data['status']) && !empty($data['status'])){
  2171. array_push($where,['status','!=',0]);
  2172. }
  2173. $sector = Sector::where($where)
  2174. ->leftJoin('size','sector.size_id','=','size.id')
  2175. ->select('sector.*','size.width','size.height')
  2176. ->get()->all();
  2177. if(empty($sector)){
  2178. return Result::error('通栏不存在!');
  2179. }
  2180. return Result::success($sector);
  2181. }
  2182. }