PublicRpcService.php 85 KB

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