PublicRpcService.php 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813
  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. #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  36. class PublicRpcService implements PublicRpcServiceInterface
  37. {
  38. #[Inject]
  39. protected Redis $redis;
  40. /**
  41. * @param array $data
  42. * @return array
  43. */
  44. public function getDistrictList(array $data): array
  45. {
  46. $where = [];
  47. if (isset($data['keyWord'])) {
  48. $where = [
  49. ['name', 'like', '%' . $data['keyWord'] . '%']
  50. ];
  51. }
  52. $result = [];
  53. if (isset($data['pageSize'])) {
  54. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
  55. $count = District::where($where)->count();
  56. $result = [
  57. 'rows' => $rep,
  58. 'count' => $count
  59. ];
  60. } else {
  61. $result = District::where($data)->orderBy("code", "asc")->get();
  62. }
  63. return $result ? Result::success($result) : Result::error("没有查到数据");
  64. }
  65. /**
  66. * @param array $data
  67. * @return array
  68. */
  69. public function getUserLevelList(array $data): array
  70. {
  71. $where = [];
  72. if (isset($data['keyWord'])) {
  73. $where = [
  74. ['name', 'like', '%' . $data['keyWord'] . '%'],
  75. ];
  76. }
  77. $result = [];
  78. if (isset($data['pageSize'])) {
  79. $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get();
  80. $count = UserLevel::where($where)->count();
  81. $result = [
  82. 'rows' => $rep,
  83. 'count' => $count,
  84. ];
  85. } else {
  86. $result = UserLevel::orderBy("id", "asc")->get();
  87. }
  88. return $result ? Result::success($result) : Result::error("没有查到数据");
  89. }
  90. /**
  91. * 添加用户等级
  92. * @param array $data
  93. * @return array
  94. */
  95. public function addUserLevel(array $data): array
  96. {
  97. LevelUser::insertGetId($data);
  98. return Result::success([]);
  99. }
  100. /**
  101. * 更新等级
  102. * @param array $data
  103. * @return array
  104. */
  105. public function updateUserLevel(array $data): array
  106. {
  107. $result = LevelUser::where(['id' => $data['id']])->update($data);
  108. if ($result) {
  109. return Result::success($result);
  110. }
  111. return Result::error("更新失败");
  112. }
  113. /**
  114. * 删除等级
  115. * @param array $data
  116. * @return array
  117. */
  118. public function delUserLevel(array $data): array
  119. {
  120. $result = LevelUser::where(['id' => $data['id']])->delete();
  121. if ($result) {
  122. return Result::success($result);
  123. }
  124. return Result::error("删除失败");
  125. }
  126. /**
  127. * 查询投诉举报信息
  128. * @param array $data
  129. * @return array
  130. */
  131. public function getLetterOfComplaint(array $data = []): array
  132. {
  133. var_dump("====");
  134. $where = [];
  135. if (isset($data['user_id']) && !empty($data['user_id'])) {
  136. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  137. }
  138. if (isset($data['nature']) && !empty($data['nature'])) {
  139. array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
  140. }
  141. if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
  142. array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
  143. }
  144. if (isset($data['status']) && !empty($data['status'])) {
  145. array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
  146. }
  147. $result = [];
  148. if (isset($data['pageSize'])) {
  149. $rep = LetterOfComplaint::where($where)
  150. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  151. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  152. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  153. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  154. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  155. ->select(
  156. "letter_of_complaint.*",
  157. "type_a.type_name as nature_name",
  158. "type_b.type_name as nature_name1",
  159. "type_c.type_name as nature_name0",
  160. "type_d.type_name as status_name",
  161. "type_e.type_name as nature_name3"
  162. )
  163. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
  164. $count = LetterOfComplaint::where($where)->count();
  165. if ($rep) {
  166. foreach ($rep as $val) {
  167. if ($val['judgment']) {
  168. $val['judgment'] = json_decode($val['judgment']);
  169. }
  170. if ($val['audio_and_video']) {
  171. $val['audio_and_video'] = json_decode($val['audio_and_video']);
  172. }
  173. if ($val['contract']) {
  174. $val['contract'] = json_decode($val['contract']);
  175. }
  176. if ($val['qualifications']) {
  177. $val['qualifications'] = json_decode($val['qualifications']);
  178. }
  179. }
  180. }
  181. $result = [
  182. 'rows' => $rep,
  183. 'count' => $count,
  184. ];
  185. } else {
  186. $result = LetterOfComplaint::where($where)
  187. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  188. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  189. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  190. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  191. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  192. ->select(
  193. "letter_of_complaint.*",
  194. "type_a.type_name as nature_name",
  195. "type_b.type_name as nature_name1",
  196. "type_c.type_name as nature_name0",
  197. "type_d.type_name as status_name",
  198. "type_e.type_name as nature_name3"
  199. )
  200. ->orderBy("letter_of_complaint.id", "desc")->get();
  201. }
  202. return $result ? Result::success($result) : Result::error("没有查到数据");
  203. }
  204. /**
  205. * 添加投诉举报信息
  206. * @param array $data
  207. * @return array
  208. */
  209. public function addLetterOfComplaint(array $data): array
  210. {
  211. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  212. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  213. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  214. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  215. unset($data['id']);
  216. $result = LetterOfComplaint::insertGetId($data);
  217. if (empty($result)) {
  218. return Result::error("创建失败", 0);
  219. } else {
  220. return Result::success(["id" => $result]);
  221. }
  222. }
  223. /**
  224. * 用户端更新投诉举报
  225. * @param array $data
  226. * @return array
  227. */
  228. public function userUpLetterOfComplaint(array $data): array
  229. {
  230. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  231. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  232. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  233. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  234. $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
  235. if (empty($result)) {
  236. return Result::error("创建失败", 0);
  237. } else {
  238. return Result::success(["id" => $result]);
  239. }
  240. }
  241. /**
  242. * 管理后台更新投诉举报信息
  243. * @param array $data
  244. * @return array
  245. */
  246. public function upLetterOfComplaint(array $data): array
  247. {
  248. var_dump("admin:", $data);
  249. $where = [
  250. 'id' => $data['id'],
  251. ];
  252. $filtered_array = array_filter($data, function ($value) {
  253. return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
  254. });
  255. $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
  256. $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
  257. $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
  258. $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
  259. unset($filtered_array['nature_name']);
  260. unset($filtered_array['type_name']);
  261. unset($filtered_array['nature_level_name']);
  262. unset($filtered_array['status_name']);
  263. unset($filtered_array['is_admin']);
  264. unset($filtered_array['type_level_name']);
  265. $result = LetterOfComplaint::where($where)->update($filtered_array);
  266. if ($result) {
  267. return Result::success($result);
  268. }
  269. return Result::error("更新失败", 0);
  270. }
  271. /**
  272. * 查询投诉举报记录
  273. * @param array $data
  274. * @return array
  275. */
  276. public function getLetterOfComplaintInfo(array $data): array
  277. {
  278. $where = [
  279. 'letter_of_complaint.id' => $data['id'],
  280. ];
  281. if (isset($data['user_id']) && !empty($data['user_id'])) {
  282. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  283. }
  284. $result = LetterOfComplaint::where($where)
  285. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  286. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  287. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  288. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  289. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  290. ->select(
  291. "letter_of_complaint.*",
  292. "type_a.type_name as nature_name",
  293. "type_b.type_name as nature_name1",
  294. "type_c.type_name as nature_name0",
  295. "type_d.type_name as status_name",
  296. "type_e.type_name as nature_name3"
  297. )
  298. ->first();
  299. return Result::success($result);
  300. }
  301. /**
  302. * 删除投诉举报信息
  303. * @param array $data
  304. * @return array
  305. */
  306. public function delLetterOfComplaint(array $data): array
  307. {
  308. $result = LetterOfComplaint::when($data, function ($query) use ($data) {
  309. if (isset($data['id']) && !empty($data['id'])) {
  310. $query->where(['id' => $data['id']]);
  311. }
  312. if (isset($data['user_id']) && !empty($data['user_id'])) {
  313. $query->where(['user_id' => $data['user_id']]);
  314. }
  315. })->delete();
  316. if (empty($result)) {
  317. return Result::error("删除失败", 0);
  318. } else {
  319. return Result::success();
  320. }
  321. }
  322. /**
  323. * 获取举报信息类型
  324. * @param array $data
  325. * @return array
  326. */
  327. public function getLetterType(array $data): array
  328. {
  329. $where = [];
  330. if (isset($data['type'])) {
  331. array_push($where, ['type', '=', $data['type']]);
  332. }
  333. if (isset($data['pid']) && $data['pid'] > 0) {
  334. array_push($where, ['pid', '=', $data['pid']]);
  335. }
  336. $result = LetterType::where($where)->orderBy('sort', 'asc')->get();
  337. return $result ? Result::success($result) : Result::error("没有查到数据");
  338. }
  339. /**
  340. * 更新举报类型
  341. * @param array $data
  342. * @return array
  343. */
  344. public function upLetterType(array $data): array
  345. {
  346. return [];
  347. }
  348. /**
  349. * 添加举报类型
  350. * @param array $data
  351. * @return array
  352. */
  353. public function addLetterType(array $data): array
  354. {
  355. $result = LetterType::insertGetId($data);
  356. if (empty($result)) {
  357. return Result::error("创建失败", 0);
  358. } else {
  359. return Result::success(["id" => $result]);
  360. }
  361. }
  362. /**
  363. * 删除举报类型
  364. * @param array $data
  365. * @return array
  366. */
  367. public function delLetterType(array $data): array
  368. {
  369. $result = LetterType::where('id', $data['id'])->delete();
  370. if (empty($result)) {
  371. return Result::error("删除失败", 0);
  372. } else {
  373. return Result::success();
  374. }
  375. }
  376. /**
  377. * 检测是否已经被接案
  378. * @param array $data
  379. * @return array
  380. */
  381. public function checkMeasure(array $data): array
  382. {
  383. $where = [
  384. 'id' => $data['id'],
  385. ];
  386. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  387. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  388. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  389. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  390. return Result::success();
  391. } else {
  392. return Result::error("您不能处理其他人已经接过的案件", 0);
  393. }
  394. }
  395. /**
  396. * 后台获取职能部门
  397. * @param array $data
  398. * @return array
  399. */
  400. public function getZhinengbumenList(array $data): array
  401. {
  402. // 获取分页参数,默认每页 10 条记录
  403. $page = isset($data['page']) ? (int) $data['page'] : 1;
  404. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  405. // 查询数据并分页
  406. $query = Department::query();
  407. // 可以在这里添加更多的查询条件
  408. if (isset($data['search'])) {
  409. $query->where('name', 'like', '%' . $data['search'] . '%');
  410. }
  411. // 执行分页查询
  412. $result = $query->paginate($perPage, ['*'], 'page', $page);
  413. // 返回分页结果
  414. return Result::success([
  415. 'count' => $result->total(),
  416. 'current_page' => $result->currentPage(),
  417. 'last_page' => $result->lastPage(),
  418. 'pagesize' => $result->perPage(),
  419. 'rows' => $result->items(),
  420. ]);
  421. }
  422. /**
  423. * 添加获取职能部门
  424. * @param array $data
  425. * @return array
  426. */
  427. public function addZhinengbumen(array $data): array
  428. {
  429. $result = Department::insertGetId($data);
  430. if (empty($result)) {
  431. return Result::error("创建失败", 0);
  432. } else {
  433. return Result::success(["id" => $result]);
  434. }
  435. }
  436. public function delZhinengbumen(array $data): array
  437. {
  438. $result = Department::where('id', $data['id'])->delete();
  439. if (empty($result)) {
  440. return Result::error("删除失败", 0);
  441. } else {
  442. return Result::success();
  443. }
  444. }
  445. public function getZhinengbumen(array $data): array
  446. {
  447. $result = Department::where('id', $data['id'])
  448. ->orderBy('department', 'desc')
  449. ->first();
  450. return Result::success($result);
  451. }
  452. public function getPidZhinengbumen(array $data): array
  453. {
  454. if (empty($data['pid'])) {
  455. $data['pid'] = 0;
  456. }
  457. $result = Department::where('pid', $data['pid'])->get();
  458. return Result::success($result);
  459. }
  460. public function modZhinengbumen(array $data): array
  461. {
  462. $result = Department::where('id', $data['id'])->update($data);
  463. if (empty($result)) {
  464. return Result::error("修改失败", 0);
  465. } else {
  466. return Result::success();
  467. }
  468. }
  469. /**
  470. * 查询职能列表
  471. * @param array $data
  472. * @return array
  473. */
  474. public function getDepartment(array $data): array
  475. {
  476. $where = [];
  477. if (isset($data['pid'])) {
  478. $where = [
  479. 'pid' => $data['pid'] ?? 0
  480. ];
  481. }
  482. $result = Department::when(!empty($where), function ($query) use ($where) {
  483. $query->where($where);
  484. })->orderBy("sort", "desc")->get();
  485. if (empty($result)) {
  486. return Result::error("查询失败", 0);
  487. } else {
  488. return Result::success($result);
  489. }
  490. }
  491. /**
  492. * 获取所有的buckets
  493. * @param array $data
  494. * @return array
  495. */
  496. public function getBuckets(array $data): array
  497. {
  498. $result = new MinioService();
  499. // 调用服务层的方法获取存储桶列表
  500. $bucketsResponse = $result->listBuckets();
  501. // 直接返回服务层生成的响应
  502. return Result::success($bucketsResponse['data']);
  503. }
  504. /**
  505. * 上传文件
  506. * @param array $data
  507. * @return array
  508. */
  509. public function uploadFile(array $data): array
  510. {
  511. $result = new MinioService();
  512. $rep = $result->uploadFile($data);
  513. if ($rep['code'] == 200) {
  514. return Result::success($rep['data']);
  515. } else {
  516. return Result::error("上传失败!");
  517. }
  518. }
  519. /**
  520. * 黑名单管理
  521. * @param array $data
  522. * @return array
  523. */
  524. public function getBlackWordList(array $data): array
  525. {
  526. $result = BlackWord::when($data, function ($query) use ($data) {
  527. if (isset($data['name']) && $data['name']) {
  528. $query->where('black_word.name', 'like', '%' . $data['name'] . '%');
  529. }
  530. })->orderBy('black_word.id', 'desc')
  531. ->paginate(
  532. intval($data['pageSize']),
  533. [
  534. 'black_word.*',
  535. ],
  536. 'page',
  537. intval($data['page'])
  538. );
  539. $count = $result->total();
  540. $returnData = [
  541. 'rows' => $result->items(),
  542. 'count' => $count
  543. ];
  544. return Result::success($returnData);
  545. }
  546. /**
  547. * 添加黑名单
  548. * @param array $data
  549. * @return array
  550. */
  551. public function addBlackWord(array $data): array
  552. {
  553. Db::beginTransaction();
  554. try {
  555. $info = BlackWord::where(['name' => $data['name']])->first();
  556. if ($info) {
  557. Db::rollBack();
  558. return Result::error("该黑名单已存在", 0);
  559. }
  560. $data['type'] = 10;
  561. $result = BlackWord::insertGetId($data);
  562. $redisKey = 'black_word';
  563. $this->redis->sAdd($redisKey, $data['name']);
  564. Db::commit();
  565. return Result::success(["id" => $result]);
  566. } catch (\Exception $e) {
  567. Db::rollBack();
  568. return Result::error("创建失败" . $e->getMessage(), 0);
  569. }
  570. }
  571. /**
  572. * 删除黑名单
  573. * @param array $data
  574. * @return array
  575. */
  576. public function delBlackWord(array $data): array
  577. {
  578. Db::beginTransaction();
  579. try {
  580. BlackWord::where(['name' => $data['name']])->delete();
  581. $redisKey = 'black_word';
  582. $this->redis->sRem($redisKey, $data['name']);
  583. Db::commit();
  584. return Result::success([]);
  585. } catch (\Exception $e) {
  586. Db::rollBack();
  587. return Result::error("删除失败" . $e->getMessage(), 0);
  588. }
  589. }
  590. /**
  591. * 修改违禁词
  592. * @param array $data
  593. * @return array
  594. */
  595. public function upBlackWord(array $data): array
  596. {
  597. Db::beginTransaction();
  598. try {
  599. $checkInfo = BlackWord::where(['name' => $data['name']])->first();
  600. if ($checkInfo) {
  601. Db::rollBack();
  602. return Result::error("该违禁词已经存在", 0);
  603. }
  604. $blackWordInfo = BlackWord::where(['id' => $data['id']])->first();
  605. if ($blackWordInfo) {
  606. //先删除redis
  607. $blackWordInfo = $blackWordInfo->toArray();
  608. $redisKey = 'black_word';
  609. $this->redis->sRem($redisKey, $blackWordInfo['name']);
  610. $this->redis->sAdd($redisKey, $data['name']);
  611. BlackWord::where(['id' => $data['id']])->update(['name' => $data['name']]);
  612. Db::commit();
  613. return Result::success([]);
  614. } else {
  615. Db::rollBack();
  616. return Result::error("系统错误", 0);
  617. }
  618. } catch (\Exception $e) {
  619. Db::rollBack();
  620. return Result::error("修改失败" . $e->getMessage(), 0);
  621. }
  622. }
  623. /**
  624. * 获取风格
  625. * @return void
  626. */
  627. public function getTemplateClassList(array $data): array
  628. {
  629. $where = [];
  630. if (isset($data['name']) && $data['name']) {
  631. array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
  632. }
  633. if (isset($data['keyword']) && $data['keyword']) {
  634. array_push($where, ['template_class.keyword', 'like', '%' . $data['keyword'] . '%']);
  635. }
  636. $template = TemplateClass::when($where, function ($query) use ($where) {
  637. $query->where($where);
  638. });
  639. $count = $template->count();
  640. // $countQuery = clone $template;
  641. $row = $template
  642. ->leftJoin('template', function ($join) {
  643. $join->on('template_class.class_id', '=', 'template.template_class_id');
  644. })
  645. ->select('template_class.*', DB::raw('COUNT(template.template_class_id) as template_count'))
  646. ->groupBy('template_class.id')
  647. ->orderBy('template_class.id', 'desc')
  648. ->offset(($data['page'] - 1) * $data['pageSize'])
  649. ->limit($data['pageSize'])
  650. ->get();
  651. $result = [
  652. 'rows' => $row,
  653. 'count' => $count,
  654. ];
  655. if ($row->isEmpty()) {
  656. return Result::error("暂无风格", 0);
  657. } else {
  658. return Result::success($result);
  659. }
  660. }
  661. /**
  662. * 添加风格
  663. * @param
  664. * @return void
  665. */
  666. public function addTemplateClass(array $data): array
  667. {
  668. $data['keyword'] = json_encode($data['keyword']);
  669. $template_class = TemplateClass::where('name', $data['name'])
  670. ->orWhere('class_id', $data['class_id'])
  671. ->first();
  672. if ($template_class) {
  673. return Result::error("风格名称或者风格编号已存在,不可添加!", 0);
  674. }
  675. $result = TemplateClass::insertGetId($data);
  676. if (empty($result)) {
  677. return Result::error("创建风格失败", 0);
  678. } else {
  679. return Result::success(["id" => $result]);
  680. }
  681. }
  682. /**
  683. * 更新风格
  684. * @param array $data
  685. * @return array
  686. */
  687. public function upTemplateClass(array $data): array
  688. {
  689. $where = [
  690. 'id' => $data['id'],
  691. ];
  692. $template_class = TemplateClass::where($where)->first();
  693. if (empty($template_class)) {
  694. return Result::error("未查询到风格", 0);
  695. }
  696. if ($template_class->type == 1) {
  697. return Result::error("默认风格不能修改", 0);
  698. }
  699. $template = TemplateClass::where('id', '!=', $data['id'])
  700. // ->where(['name' => $data['name']])
  701. // ->orWhere(['class_id' => $data['class_id']])
  702. ->where(function ($query) use ($data) {
  703. $query->where('name', $data['name'])
  704. ->orWhere('class_id', $data['class_id']);
  705. })
  706. ->first();
  707. if ($template) {
  708. return Result::error("风格名称或者风格编号已存在,不可编辑!", 0);
  709. }
  710. $updateData = [
  711. 'name' => $data['name'],
  712. 'keyword' => json_encode($data['keyword']),
  713. 'class_id' => $data['class_id'],
  714. ];
  715. $result = TemplateClass::where($where)->update($updateData);
  716. if (empty($result)) {
  717. return Result::error("更新失败", 0);
  718. } else {
  719. return Result::success($result);
  720. }
  721. }
  722. /**
  723. * 删除风格
  724. * @param array $data
  725. * @return array
  726. */
  727. public function delTemplateClass(array $data): array
  728. {
  729. $where = [
  730. 'id' => $data['id'],
  731. ];
  732. $template_class = TemplateClass::where($where)->first();
  733. if (empty($template_class)) {
  734. return Result::error("未查询到风格", 0);
  735. }
  736. if ($template_class->type == 1) {
  737. return Result::error("默认风格不能删除", 0);
  738. }
  739. $template = Template::where('template_class_id', $template_class['class_id'])->get();
  740. if (!empty($template->all())) {
  741. try {
  742. // 默认风格 1
  743. Db::beginTransaction();
  744. $template = Template::where('template_class_id', $template['class_id'])->update(['template_class_id' => 1]);
  745. if (empty($template)) {
  746. Db::rollBack();
  747. return Result::error("删除失败", 0);
  748. }
  749. $result = TemplateClass::where($where)->delete();
  750. } catch (\Exception $e) {
  751. return Result::error("删除失败" . $e->getMessage(), 0);
  752. }
  753. } else {
  754. $result = TemplateClass::where('id', $data['id'])->delete();
  755. }
  756. if (empty($result)) {
  757. return Result::error("删除失败", 0);
  758. }
  759. return Result::success($result);
  760. }
  761. /**
  762. * 根据风格名称-获取获取所有风格
  763. * @param array $data
  764. * @return array
  765. */
  766. public function getTemplateClass(array $data): array
  767. {
  768. $where = [];
  769. if (!empty($data['template_name'])) {
  770. $where['name'] = $data['template_name'];
  771. }
  772. $result = TemplateClass::where($where)->get();
  773. if (empty($result)) {
  774. return Result::error("暂无风格", 0);
  775. }
  776. return Result::success($result);
  777. }
  778. /**
  779. * 获取皮肤列表
  780. * @param array $data
  781. * @return array
  782. */
  783. public function getTemplateList(array $data): array
  784. {
  785. $where = [];
  786. if (!empty($data['template_class_id'])) {
  787. $where['template_class_id'] = $data['template_class_id'];
  788. }
  789. if (!empty($data['template_name'])) {
  790. array_push($where, ['template_name', 'like', '%' . $data['template_name'] . '%']);
  791. }
  792. if (!empty($data['template_keyword'])) {
  793. array_push($where, ['template_keyword', 'like', '%' . $data['template_keyword'] . '%']);
  794. }
  795. $result = Template::where($where)
  796. ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
  797. ->select('template.*', 'template_class.name as template_class_name')
  798. ->orderBy('template.id', 'desc')
  799. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  800. if (empty($result)) {
  801. return Result::error("暂无皮肤", 0);
  802. }
  803. return Result::success($result);
  804. }
  805. public function getTemplateInfo(array $data): array
  806. {
  807. $result = Template::where('template.id', $data['id'])
  808. ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
  809. ->select('template.*', 'template_class.name as template_class_name')
  810. ->first();
  811. if (empty($result)) {
  812. return Result::error("暂无皮肤", 0);
  813. }
  814. return Result::success($result);
  815. }
  816. /**
  817. * 添加皮肤
  818. * @param array $data
  819. * @return array
  820. */
  821. public function addTemplate(array $data): array
  822. {
  823. var_dump($data);
  824. unset($data['user_id']);
  825. $template = Template::where('template_name', $data['template_name'])
  826. ->orWhere('template_id', $data['template_id'])
  827. ->first();
  828. if ($template) {
  829. return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
  830. }
  831. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  832. $page_type = json_decode($data['page_type'], true);
  833. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  834. $result = Template::insertGetId($data);
  835. if (empty($result)) {
  836. return Result::error("创建失败", 0);
  837. } else {
  838. return Result::success($result);
  839. }
  840. }
  841. /**
  842. * 删除皮肤
  843. * @param array $data
  844. * @return array
  845. */
  846. public function delTemplate(array $data): array
  847. {
  848. $rector = Sector::where('template_id', $data['id'])->first();
  849. if (!empty($rector)) {
  850. return Result::error("此皮肤已被绑定通栏,不可删除", 0);
  851. }
  852. $template = WebsiteTemplateInfo::where('template_id', $data['id'])->first();
  853. if (empty($template)) {
  854. return Result::error("此皮肤已被绑定网站,不可删除", 0);
  855. }
  856. if ($template->type == 1) {
  857. return Result::error("默认皮肤不能删除", 0);
  858. }
  859. $result = Template::where('id', $data['id'])->delete();
  860. var_dump($result, '-------------------delete');
  861. if ($result) {
  862. return Result::success($result);
  863. } else {
  864. return Result::error("删除失败", 0);
  865. }
  866. }
  867. /**
  868. * 更新皮肤
  869. * @param array $data
  870. * @return array
  871. */
  872. public function updateTemplate(array $data): array
  873. {
  874. unset($data['user_id']);
  875. $template = Template::where('id', $data['id'])
  876. ->first();
  877. if (empty($template)) {
  878. return Result::error("此皮肤不存在!", 0);
  879. }
  880. $template = Template::where('id', '!=', $data['id'])
  881. ->where(function ($query) use ($data) {
  882. $query->where('template_name', $data['template_name'])
  883. ->orWhere('template_id', $data['template_id']);
  884. })
  885. ->first();
  886. if ($template) {
  887. return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
  888. }
  889. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  890. $page_type = json_decode($data['page_type'], true);
  891. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  892. $result = Template::where('id', $data['id'])->update($data);
  893. var_dump($result, '-------------------update');
  894. if (!$result) {
  895. return Result::error("更新失败", 0);
  896. } else {
  897. return Result::success('更新成功');
  898. }
  899. }
  900. /**
  901. * 获取所有尺寸
  902. * @param array $data
  903. * @return array
  904. */
  905. public function getAllSize(array $data): array
  906. {
  907. if(isset($data['id']) && !empty($data['id'])){
  908. $result = Size::where('id', $data['id'])->get()->all();
  909. }else{
  910. $result = Size::get()->all();
  911. }
  912. if(empty($result)){
  913. return Result::error("暂无尺寸", 0);
  914. }
  915. return Result::success($result);
  916. }
  917. /**
  918. * 根据皮肤名称-获取所有皮肤
  919. * @param array $data
  920. * @return array
  921. */
  922. public function getAllTemplate(array $data): array
  923. {
  924. $where = [];
  925. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  926. $where[] = ['template_class_id', $data['template_class_id']];
  927. }
  928. if (isset($data['template_name']) && !empty($data['template_name'])) {
  929. $where[] = ['template_name', 'like', '%' . $data['template_name'] . '%'];
  930. }
  931. $result = Template::where($where)->get()->all();
  932. if (empty($result)) {
  933. return Result::error("暂无皮肤", 0);
  934. }
  935. return Result::success($result);
  936. }
  937. /**
  938. * 获取通栏列表
  939. * @param array $data
  940. * @return array
  941. */
  942. public function getSectorList(array $data): array
  943. {
  944. $where = [];
  945. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  946. $where['template.template_class_id'] = $data['template_class_id'];
  947. }
  948. if (isset($data['template_id']) && !empty($data['template_id'])) {
  949. array_push($where, ['template.template_id', $data['template_id']]);
  950. }
  951. if (isset($data['sector_name']) && !empty($data['sector_name'])) {
  952. array_push($where, ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%']);
  953. }
  954. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])) {
  955. $size_id = Size::where('width', 'like', '%' . $data['width'] . '%')->where('height', 'like', '%' . $data['height'] . '%')->pluck('id');
  956. } else if (isset($data['width']) && !empty($data['width'])) {
  957. $size_id = Size::where('width', 'like', '%' . $data['width'] . '%')->pluck('id');
  958. } else if (isset($data['height']) && !empty($data['height'])) {
  959. $size_id = Size::where('height', 'like', '%' . $data['height'] . '%')->pluck('id');
  960. } else {
  961. $size_id = [];
  962. }
  963. $result = Sector::when(!empty($size_id), function ($query) use ($size_id) {
  964. $query->whereIn('size_id', $size_id);
  965. })
  966. ->leftJoin('size', 'size.id', '=', 'sector.size_id')
  967. ->leftJoin('template', 'template.template_id', '=', 'sector.template_id')
  968. ->leftJoin('template_class', 'template_class.class_id', '=', 'template.template_class_id')
  969. ->leftJoin('sector_place', 'sector_place.sector_type', '=', 'sector.place_type')
  970. ->where($where)
  971. ->where('sector_place.type_id',1)
  972. ->select('sector.*', 'size.width','size.height','template_class.name as class_name','template.template_name'
  973. ,'sector_place.name as place_name','sector_place.sector_img as place_img')
  974. ->orderBy('sector.id', 'desc')
  975. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  976. if(empty($result)){
  977. return Result::error('暂无通栏!');
  978. }
  979. return Result::success($result);
  980. }
  981. /**
  982. * 获取通栏详情
  983. * @param array $data
  984. * @return array
  985. */
  986. public function getSectorInfo(array $data): array
  987. {
  988. $where = [];
  989. $where[] = ['sector.id', '=', $data['id']];
  990. $result = Sector::where($where)
  991. ->leftJoin('size', 'size.id', '=', 'sector.size_id')
  992. ->select('sector.*', 'size.width', 'size.height')
  993. ->orderBy('sector.id', 'desc')
  994. ->first();
  995. if (empty($result)) {
  996. return Result::error('此通栏不存在!');
  997. }
  998. return Result::success($result);
  999. }
  1000. /**
  1001. * 获取经纬度信息
  1002. * @return void
  1003. */
  1004. public function getIpInfo(array $data): array
  1005. {
  1006. if (empty($data['ip'])) {
  1007. // 在RPC服务中,依赖$_SERVER是不可靠的,强制要求调用方传入IP
  1008. return Result::error('IP地址不能为空!');
  1009. }
  1010. $client_ip = $data['ip'];
  1011. try {
  1012. // 直接从容器获取 Guzzle 客户端实例
  1013. /** @var \GuzzleHttp\Client $client */
  1014. $client = \Hyperf\Context\ApplicationContext::getContainer()->get(Client::class);
  1015. // 使用新的 GeoJS API 地址
  1016. $api_url = "https://get.geojs.io/v1/ip/geo/{$client_ip}.json";
  1017. // 将 timeout 作为请求选项传递
  1018. $response = $client->get($api_url, ['timeout' => 5]);
  1019. if ($response->getStatusCode() !== 200) {
  1020. return Result::error('IP查询接口请求失败,状态码:' . $response->getStatusCode());
  1021. }
  1022. $ip_info = json_decode($response->getBody()->getContents(), true);
  1023. // GeoJS 的成功响应不包含 'status' 字段,直接检查关键数据是否存在
  1024. if ($ip_info && isset($ip_info['latitude']) && isset($ip_info['longitude'])) {
  1025. // GeoJS 返回的经纬度是字符串,转换为浮点数
  1026. $ip_info['latitude'] = floatval($ip_info['latitude']);
  1027. $ip_info['longitude'] = floatval($ip_info['longitude']);
  1028. return Result::success($ip_info);
  1029. }
  1030. // 如果返回的数据不符合预期,提供一个通用错误
  1031. $errorMessage = $ip_info['message'] ?? '获取IP地理位置信息失败';
  1032. return Result::error($errorMessage);
  1033. } catch (GuzzleException $e) {
  1034. // 这个异常会给出详细的网络错误信息,如超时、无法解析域名等
  1035. return Result::error('请求IP查询接口异常: ' . $e->getMessage());
  1036. } catch (\Throwable $e) {
  1037. return Result::error('获取IP信息时发生未知错误: ' . $e->getMessage());
  1038. }
  1039. }
  1040. /**
  1041. * 获取天气
  1042. * @param array $data
  1043. * @return array
  1044. */
  1045. public function getWeatherInfo(array $data): array
  1046. {
  1047. $month = $data['month'] ?? date('m');
  1048. $day = $data['day'] ?? date('d');
  1049. // 使用缓存键
  1050. $cacheKey = "tsbb_data_weather_{$month}_{$day}";
  1051. // 尝试从缓存获取数据
  1052. $container = \Hyperf\Context\ApplicationContext::getContainer();
  1053. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  1054. if ($cachedData = $cache->get($cacheKey)) {
  1055. return Result::success(unserialize($cachedData));
  1056. }
  1057. $location = $data['latitude'] . ":" . $data['longitude'];
  1058. $api_url = "https://api.seniverse.com/v3/weather/now.json?key=" . \Hyperf\Support\env('WEATHER_KEY') . "&location=" . $location . "&language=zh-Hans&unit=c";
  1059. $ch = curl_init($api_url);
  1060. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1061. $response = curl_exec($ch);
  1062. curl_close($ch);
  1063. // 解析 JSON 响应
  1064. $WeatherInfo = json_decode($response, true);
  1065. // 缓存结果,设置1小时过期
  1066. $cache->set($cacheKey, serialize($WeatherInfo), 3600);
  1067. if ($WeatherInfo) {
  1068. return Result::success($WeatherInfo);
  1069. } else {
  1070. return Result::error("获取天气失败", 0);
  1071. }
  1072. }
  1073. /**
  1074. * 获取农历信息
  1075. * @return void
  1076. */
  1077. public function getCalendar(array $data): array
  1078. {
  1079. $calendar = new Calendar();
  1080. $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
  1081. return Result::success($result);
  1082. }
  1083. /**
  1084. * 添加通栏
  1085. * @param array $data
  1086. * @return array
  1087. */
  1088. public function addSector(array $data): array
  1089. {
  1090. unset($data['user_id']);
  1091. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1092. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1093. $data['page_type'] = json_encode($data['page_type']);
  1094. $template = Template::where('template_id', $data['template_id'])
  1095. ->first();
  1096. if (empty($template)) {
  1097. return Result::error('皮肤不存在!');
  1098. }
  1099. $sector_id = Sector::where('sector_id',$data['sector_id'])->first();
  1100. if(!empty($sector_id)){
  1101. return Result::error('通栏编号已存在!');
  1102. }
  1103. $data['status'] = 0;
  1104. // 通栏分类:1:资讯类:2:通栏广告类;3:混合类;4:头条类;5:轮播图类;
  1105. $sector_code = [
  1106. 'sectorName' => $data['sector_name'],
  1107. 'sectorId' => $data['sector_id'],
  1108. 'sectorType' => $data['sector_type'],
  1109. 'sectorPlace' => $data['place_type'],
  1110. ];
  1111. // return Result::success($sector_code);
  1112. $data['sector_code'] = json_encode($sector_code);
  1113. $result = Sector::insertGetId($data);
  1114. if (empty($result)) {
  1115. return Result::error('添加失败');
  1116. }
  1117. return Result::success($result);
  1118. }
  1119. /**
  1120. * 删除通栏
  1121. * @param array $data
  1122. * @return array
  1123. */
  1124. public function delSector(array $data): array
  1125. {
  1126. $component_id = Component::where('sector_id', $data['id'])->pluck('id')->toArray();
  1127. if (!empty($component_id)) {
  1128. return Result::error('请先删除相关组件!');
  1129. }
  1130. $result = Sector::where('id', $data['id'])->delete();
  1131. if ($result == 1) {
  1132. return Result::success('删除成功');
  1133. } else {
  1134. return Result::error('删除失败');
  1135. }
  1136. }
  1137. /**
  1138. * 修改通栏
  1139. * @param array $data
  1140. * @return array
  1141. */
  1142. public function updateSector(array $data): array
  1143. {
  1144. unset($data['user_id']);
  1145. $sector = Sector::where('id', $data['id'])->first();
  1146. if (empty($sector)) {
  1147. return Result::error('通栏不存在!');
  1148. }
  1149. if($sector['sector_id'] != $data['sector_id']){
  1150. $sector_id = Sector::where('sector_id',$data['sector_id'])->first();
  1151. if(!empty($sector_id)){
  1152. return Result::error('通栏编号已存在!');
  1153. }
  1154. }
  1155. $sector_code = [
  1156. 'sectorName' => strval($data['sector_name']),
  1157. 'sectorId' => intval($data['sector_id']),
  1158. 'sectorType' => intval($data['sector_type']),
  1159. 'sectorPlace' => intval($data['place_type']),
  1160. ];
  1161. // return Result::success($sector_code);
  1162. $data['sector_code'] = json_encode($sector_code);
  1163. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1164. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1165. $data['page_type'] = json_encode($data['page_type']);
  1166. $template = Template::where('template_id', $data['template_id'])
  1167. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
  1168. ->first();
  1169. if (empty($template)) {
  1170. return Result::error('皮肤不存在!');
  1171. }
  1172. $result = Sector::where('id', $data['id'])->update($data);
  1173. if ($result == 1) {
  1174. return Result::success('修改成功');
  1175. } else {
  1176. return Result::error('修改失败');
  1177. }
  1178. }
  1179. public function getComponentList(array $data): array
  1180. {
  1181. var_dump($data, '---------');
  1182. $where = [];
  1183. // $where[] = ['sector.id', '=', $data['id']];
  1184. if (!empty($data['template_class_id'])) {
  1185. $where['template_class.id'] = $data['template_class_id'];
  1186. }
  1187. if (!empty($data['component_name'])) {
  1188. $where['component.component_name'] = $data['component_name'];
  1189. }
  1190. if (!empty($data['sector_id'])) {
  1191. $where['sector.id'] = $data['sector_id'];
  1192. };
  1193. $result = Component::where($where)
  1194. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1195. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1196. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1197. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'template_class.id as template_class_id', 'sector.sector_name as sector_name', 'component.*', 'sector.id as sector_id') // 修改这一行)
  1198. ->orderBy('sector.updated_at', 'desc')
  1199. ->orderBy('sector.created_at', 'desc')
  1200. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  1201. return Result::success($result);
  1202. }
  1203. public function getComponentInfo(array $data): array
  1204. {
  1205. $where = [];
  1206. $result = Component::where($where)
  1207. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1208. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1209. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1210. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
  1211. ->get();
  1212. return Result::success($result);
  1213. }
  1214. public function addComponent(array $data): array
  1215. {
  1216. unset($data['user_id']);
  1217. $result = Component::insertGetId($data);
  1218. if ($result) {
  1219. return Result::success($result);
  1220. } else {
  1221. return Result::error('添加失败');
  1222. }
  1223. }
  1224. public function delComponent(array $data): array
  1225. {
  1226. $result = Component::where('id', $data['id'])->delete();
  1227. return Result::success($result);
  1228. }
  1229. public function updateComponent(array $data): array
  1230. {
  1231. $result = Component::where('id', $data['id'])->update($data);
  1232. return Result::success($result);
  1233. }
  1234. public function getWebsiteTemplateInfo(array $data)
  1235. {
  1236. $where = [];
  1237. if (isset($data['id'])) {
  1238. $where[] = ['id', '=', $data['id']];
  1239. }
  1240. $result = WebsiteTemplateInfo::where($where)
  1241. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1242. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  1243. ->select('website_template_info.*', 'website.website_name')
  1244. ->get();
  1245. if ($result) {
  1246. return Result::success($result);
  1247. } else {
  1248. return Result::error('暂无数据');
  1249. }
  1250. }
  1251. /**
  1252. * 自助建站----1.获取页面类型回显
  1253. * @param array $data
  1254. * @return array
  1255. */
  1256. public function getWebPageType(array $data): array
  1257. {
  1258. // 1:图片 2:文字 3:底部
  1259. $friend_link = Link::where('website_id', $data['website_id'])->where('type', 3)->get();
  1260. if (empty($friend_link->toArray())) {
  1261. return Result::error('暂无友情链接数据!');
  1262. }
  1263. $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
  1264. if (empty($footer_category->toArray())) {
  1265. return Result::error('暂无底部导航数据!');
  1266. }
  1267. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('page_type');
  1268. if (empty($page_type)) {
  1269. $page_type = [];
  1270. } else {
  1271. $page_type = json_decode($page_type, true);
  1272. }
  1273. // '网站页面类型(存数组)1:首页 2:分类页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页
  1274. if (isset($page_type) && in_array(5, $page_type)) {
  1275. $page_type = 1;
  1276. } else {
  1277. $page_type = 0;
  1278. }
  1279. $result = [
  1280. 'friend_link' => $friend_link,
  1281. 'footer_category' => $footer_category,
  1282. 'page_type' => $page_type,
  1283. ];
  1284. return Result::success($result);
  1285. }
  1286. /**
  1287. * 自助建站----2.添加页面类型
  1288. * @param array $data
  1289. * @return array
  1290. */
  1291. public function addWebPageType(array $data): array
  1292. {
  1293. // return Result::success($data);
  1294. // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
  1295. if ($data['is_search'] == 1) {
  1296. $page_type = json_encode([1, 2, 3, 4, 5, 6, 7]);
  1297. } else {
  1298. $page_type = json_encode([1, 2, 3, 4, 6, 7]);
  1299. }
  1300. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1301. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1302. // return Result::success($website_template_info);
  1303. // return Result::success(empty($website_template_info));
  1304. if (empty($website_template_info)) {
  1305. $result = WebsiteTemplateInfo::insertGetId(['website_id' => $data['website_id'], 'page_type' => $page_type, 'user_id' => $data['user_id']]);
  1306. } else {
  1307. if ($website_template_info['status'] == 2) {
  1308. return Result::error('网站已应用,不可再次修改!');
  1309. }
  1310. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type], ['action_id' => 1, 'user_id' => $data['user_id']]);
  1311. }
  1312. if ($result) {
  1313. return Result::success($result);
  1314. } else {
  1315. return Result::error('添加失败');
  1316. }
  1317. }
  1318. /**
  1319. * 自助建站---流程---3.选择皮肤列表
  1320. * @param array $data
  1321. * @return array
  1322. */
  1323. public function getWebsiteTemplateList(array $data): array
  1324. {
  1325. $where = [];
  1326. if (isset($data['template_class_id']) && $data['template_class_id']) {
  1327. $where[] = ['template_class_id', '=', $data['template_class_id']];
  1328. }
  1329. // 0:未构建 1:未应用 2:已应用 status
  1330. $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1331. if (empty($templste_info)) {
  1332. return Result::error('请先填写网站基础信息!');
  1333. }
  1334. if ($templste_info['status'] == 2) {
  1335. return Result::error('网站已应用,不可再次修改!');
  1336. }
  1337. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1338. if (is_array($data['keyword'])) {
  1339. // 拼接多个模糊查询条件
  1340. $query = Template::query();
  1341. foreach ($data['keyword'] as $kw) {
  1342. $escapedKw = addcslashes($kw, '%_'); // 转义通配符
  1343. $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
  1344. }
  1345. } else {
  1346. $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
  1347. $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
  1348. }
  1349. } else {
  1350. $query = Template::where($where);
  1351. }
  1352. $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
  1353. // return Result::success($template_id);
  1354. if (!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])) {
  1355. $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
  1356. } else {
  1357. $template_page = [];
  1358. }
  1359. if (!empty($template_id['template_id'])) {
  1360. $result['template_id'] = $templste_info['template_id'];
  1361. }
  1362. // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
  1363. $template_page_str = json_encode($template_page);
  1364. $result['template'] = $query->where($where)
  1365. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1366. ->orderBy('updated_at', 'desc')
  1367. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1368. if (empty($result['template'])) {
  1369. $result['template'] = Template::orderBy('updated_at', 'desc')
  1370. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1371. }
  1372. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('template_id');
  1373. if ($template) {
  1374. $result['template_id'] = $template;
  1375. } else {
  1376. $result['template_id'] = 0;
  1377. }
  1378. return Result::success($result);
  1379. }
  1380. /**
  1381. * 自助建站---流程---4.选择皮肤
  1382. * @param array $data
  1383. * @return array
  1384. */
  1385. public function chooseWebsiteTemplate(array $data): array
  1386. {
  1387. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1388. if (empty($website_template_info)) {
  1389. return Result::error('请先填写网站基础信息!');
  1390. }
  1391. // 0:未构建 1:未应用 2:已应用 status
  1392. if ($website_template_info['status'] == 2) {
  1393. return Result::error('网站已应用,不可再次修改!');
  1394. }
  1395. $template = Template::where('template_id', $data['template_id'])->first();
  1396. if (empty($template)) {
  1397. return Result::error('未查询到皮肤!');
  1398. }
  1399. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1400. $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
  1401. if ($web_template) {
  1402. return Result::success($web_template);
  1403. } else {
  1404. return Result::error('选择皮肤失败!');
  1405. }
  1406. }
  1407. /**
  1408. * 自助建站---流程---5.保存模版
  1409. * @param array $data
  1410. * @return array
  1411. */
  1412. public function saveWebsiteTemplate(array $data): array
  1413. {
  1414. // return Result::success($data);
  1415. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1416. if (empty($website_template_info) || empty($website_template_info->template_id) || empty($website_template_info->page_type)) {
  1417. return Result::error('请先填写网站基础信息!');
  1418. }
  1419. // 0:未构建 1:未应用 2:已应用 status
  1420. if ($website_template_info['status'] == 2) {
  1421. return Result::error('网站已应用,不可再次保存!');
  1422. }
  1423. if ($website_template_info['action_id'] != 2) {
  1424. return Result::error('请完成之前的步骤!');
  1425. }
  1426. $template_info = WebsiteTemplate::where('website_id', $data['website_id'])->first();
  1427. // var_dump($data['template_data']);
  1428. try {
  1429. Db::beginTransaction();
  1430. if (empty($template_info)) {
  1431. $template = WebsiteTemplate::insertGetId([
  1432. 'website_id' => $data['website_id'],
  1433. 'template_data' => $data['template_data'],
  1434. 'user_id' => $data['user_id'],
  1435. 'canvas_data' => $data['canvas_data'],
  1436. 'page_type' => $website_template_info['page_type'],
  1437. 'template_id' => $website_template_info['template_id'],
  1438. ]);
  1439. } else {
  1440. $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(
  1441. [
  1442. 'template_data' => $data['template_data'],
  1443. 'user_id' => $data['user_id'],
  1444. 'canvas_data' => $data['canvas_data'],
  1445. 'page_type' => $website_template_info['page_type'],
  1446. 'template_id' => $website_template_info['template_id'],
  1447. ]
  1448. );
  1449. }
  1450. if (empty($template)) {
  1451. Db::rollback();
  1452. return Result::error('保存失败!');
  1453. } else {
  1454. $tempalte_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['status' => 1]);
  1455. if (empty($tempalte_info)) {
  1456. Db::rollback();
  1457. return Result::error('保存失败!');
  1458. }
  1459. Db::commit();
  1460. }
  1461. } catch (\Exception $e) {
  1462. return Result::error('模版数据格式错误!');
  1463. }
  1464. return Result::success($template);
  1465. }
  1466. /**
  1467. * 自助建站---流程---6.返显保存的模版
  1468. * @param array $data
  1469. * @return array
  1470. */
  1471. public function getWebsiteTemplate(array $data): array
  1472. {
  1473. $web = Website::where('id', $data['website_id'])->first();
  1474. if (empty($web)) {
  1475. return Result::error('未查询到网站信息!');
  1476. }
  1477. $template = WebsiteTemplate::where('website_id', $data['website_id'])
  1478. ->first(['website_id', 'template_id', 'page_type', 'template_data', 'canvas_data']);
  1479. if (empty($template)) {
  1480. return Result::error('未查询到模版!');
  1481. }
  1482. return Result::success($template);
  1483. }
  1484. /**
  1485. * 通栏版式管理-获取通栏版式列表
  1486. */
  1487. public function getSectorPlaceList(array $data): array
  1488. {
  1489. $where['sector_place.type_id'] = $data['type_id'];
  1490. if(isset($data['component_num']) && !empty($data['component_num'])){
  1491. $where['sector_place.component_num'] = $data['component_num'];
  1492. }
  1493. if(isset($data['sector_type']) && !empty($data['sector_type'])){
  1494. $where['sector_place.sector_type'] = $data['sector_type'];
  1495. }
  1496. // if(isset($data['component_type']) && !empty($data['component_type'])){
  1497. // $where['sector_place.component_type'] = $data['component_type'];
  1498. // }
  1499. if(isset($data['name']) && !empty($data['name'])){
  1500. array_push($where,['sector_place.name', 'like', '%'.$data['name'].'%']);
  1501. }
  1502. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
  1503. $size_id = Size::where('width','like','%' .$data['width'].'%')->where('height','like','%' .$data['height'].'%')->pluck('id');
  1504. } else if( isset($data['width']) && !empty($data['width'])){
  1505. $size_id = Size::where('width','like','%' .$data['width'].'%')->pluck('id');
  1506. }else if( isset($data['height']) && !empty($data['height'])){
  1507. $size_id = Size::where('height','like','%' .$data['height'].'%')->pluck('id');
  1508. }else{
  1509. $size_id = [];
  1510. }
  1511. $sector_place = SectorPlace::where($where)
  1512. ->when(!empty($size_id), function ($query) use ($size_id) {
  1513. $query->whereIn('sector_place.size_id', $size_id);
  1514. })
  1515. ->leftJoin('size','sector_place.size_id','=','size.id')
  1516. ->select('sector_place.*','size.width','size.height');
  1517. $result['count'] = $sector_place->count();
  1518. $result['row'] =$sector_place->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1519. if(empty($result['count'])){
  1520. return Result::error("暂无相关版式数据!");
  1521. }
  1522. return Result::success($result);
  1523. }
  1524. /**
  1525. * 通栏版式管理-添加通栏版式
  1526. */
  1527. public function addSectorPlace(array $data): array
  1528. {
  1529. // 1:通栏;2:组件;
  1530. if($data['type_id'] == 1){
  1531. $sector_place = SectorPlace::where('sector_type', $data['type'])->first();
  1532. if(!empty($sector_place)){
  1533. return Result::error('通栏版式类别编号已存在!');
  1534. }
  1535. $data = [
  1536. 'name' => $data['name'],
  1537. 'component_num' => $data['component_num'],
  1538. 'size_id' => $data['size_id'],
  1539. 'sort_id' => 0,
  1540. 'sector_img' => $data['sector_img'],
  1541. 'sector_type' => $data['type'],
  1542. 'type_id' => $data['type_id'],
  1543. 'status' => 0,
  1544. ];
  1545. }else{
  1546. $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
  1547. if(empty($sector_type)){
  1548. return Result::error('通栏版式类别不存在!');
  1549. }
  1550. // $com_query = SectorPlace::where('type_id',2);
  1551. // ->query(function($query) use ($data){
  1552. // $query->where('component_type', $data['type'])
  1553. // ->Subquery(function($subQuery) use ($data) {
  1554. // $subQuery->where('sector_type', $data['sector_type'])
  1555. // ->where('sort_id', $data['sort']);
  1556. // });
  1557. // }) //若是组件版式编号或者组件版式位置重复用此语句筛选
  1558. // ->where('sector_type',$data['sector_type']) //若是组件版式编号在同一个通栏版式下不重复就行,则启用此语句
  1559. $component = SectorPlace::where('type_id',2)->where('component_type',$data['type'])->first();
  1560. if(!empty($component)){
  1561. return Result::error('组件版式类别编号已存在!');
  1562. }
  1563. // $com_query = clone $com_query;
  1564. $com_num = SectorPlace::where('type_id',2)->where('sector_type',$data['sector_type'])->count('sort_id');
  1565. // return Result::success($com_num);
  1566. if($sector_type['component_num'] = $com_num){
  1567. $sector = SectorPlace::where('sector_type',$data['sector_type'])->where('type_id',1)->update(['status'=>1]);
  1568. if(empty($sector)){
  1569. return Result::error('通栏版式状态修改失败!');
  1570. }
  1571. }
  1572. $data = [
  1573. 'name' => $data['name'],
  1574. 'component_num' => 0,
  1575. 'size_id' => $data['size_id'],
  1576. 'sort_id' => $data['sort_id'],
  1577. 'sector_img' => $data['sector_img'],
  1578. 'component_type' => $data['type'],
  1579. 'type_id' => $data['type_id'],
  1580. 'sector_type' => $data['sector_type'],
  1581. ];
  1582. }
  1583. $result = SectorPlace::insertGetId($data);
  1584. if(empty($result)){
  1585. return Result::error('添加失败!');
  1586. }
  1587. return Result::success('添加成功!',$result);
  1588. }
  1589. /**
  1590. * 通栏版式管理-修改通栏版式
  1591. */
  1592. public function upSectorPlace(array $data): array
  1593. {
  1594. $id = $data['id'];
  1595. // 1:通栏;2:组件;
  1596. if($data['type_id'] == 1){
  1597. $sector_place = SectorPlace::where('id','!=',$id)->where('sector_type', $data['type'])->where('type_id',1)->first();
  1598. if(!empty($sector_place)){
  1599. return Result::error('通栏版式类别编号已存在!');
  1600. }
  1601. $data = [
  1602. 'name' => $data['name'],
  1603. 'component_num' => $data['component_num'],
  1604. 'size_id' => $data['size_id'],
  1605. 'sort_id' => 0,
  1606. 'sector_img' => $data['sector_img'],
  1607. 'sector_type' => $data['type'],
  1608. 'type_id' => $data['type_id'],
  1609. ];
  1610. }else{
  1611. $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
  1612. if(empty($sector_type)){
  1613. return Result::error('通栏版式类别不存在!');
  1614. }
  1615. $component = SectorPlace::where('id','!=',$id)
  1616. ->where('component_type', $data['type'])
  1617. ->where('type_id',2)
  1618. ->first();
  1619. if(!empty($component)){
  1620. return Result::error('组件版式类别编号已存在!');
  1621. }
  1622. $data = [
  1623. 'name' => $data['name'],
  1624. 'component_num' => 0,
  1625. 'size_id' => $data['size_id'],
  1626. 'sort_id' => $data['sort_id'],
  1627. 'sector_img' => $data['sector_img'],
  1628. 'component_type' => $data['type'],
  1629. 'type_id' => $data['type_id'],
  1630. 'sector_type' => $data['sector_type'],
  1631. ];
  1632. }
  1633. $result = SectorPlace::where('id',$id)->update($data);
  1634. if(empty($result)){
  1635. return Result::error('修改失败!');
  1636. }
  1637. return Result::success('修改成功!',$result);
  1638. }
  1639. /**
  1640. * 通栏版式管理-删除通栏版式
  1641. */
  1642. public function delSectorPlace(array $data): array
  1643. {
  1644. $sector_place = SectorPlace::where('id',$data['id'])->first();
  1645. if(empty($sector_place)){
  1646. return Result::error('通栏版式不存在!');
  1647. }
  1648. if($sector_place['type_id'] == 1){
  1649. $sector = Sector::where('place_type', $sector_place['sector_type'])->first();
  1650. $component = SectorPlace::where('sector_type', $sector_place['sector_type'])
  1651. ->where('type_id',2)
  1652. ->first();
  1653. if(!empty($sector) || !empty($component)){
  1654. return Result::error('通栏版式分类已应用,暂不可删除!');
  1655. }
  1656. }else{
  1657. $sector = Component::where('place_type', $sector_place['component_type'])->first();
  1658. if(!empty($sector)){
  1659. return Result::error('组件版式分类已应用,暂不可删除!');
  1660. }
  1661. $component_num = SectorPlace::where('sector_type', $sector_place['sector_type'])
  1662. ->where('type_id',1)->update(['status'=> 0]);
  1663. if(empty($component_num)){
  1664. return Result::error('通栏版式状态修改失败!');
  1665. }
  1666. }
  1667. $result = SectorPlace::where('id',$data['id'])->delete();
  1668. if(empty($result)){
  1669. return Result::error('删除失败!');
  1670. }
  1671. return Result::success('删除成功!');
  1672. }
  1673. /**
  1674. * 自助建站-通栏版式管理-获取通栏版式详情
  1675. */
  1676. public function getSectorPlaceInfo(array $data): array
  1677. {
  1678. $result = SectorPlace::where('sector_place.id',$data['id'])
  1679. ->leftJoin('size','sector_place.size_id','=','size.id')
  1680. ->select('sector_place.*','size.width','size.height')
  1681. ->first();
  1682. if(empty($result)){
  1683. return Result::error('通栏版式不存在!');
  1684. }
  1685. return Result::success($result);
  1686. }
  1687. /**
  1688. * 自助建站-通栏版式管理-获取通栏版式列表
  1689. */
  1690. public function getSectorPlaceSort(array $data): array
  1691. {
  1692. $sector = SectorPlace::where('sector_type',$data['sector_type'])->first();
  1693. if(empty($sector)){
  1694. return Result::error('通栏版式不存在!');
  1695. }
  1696. $component = SectorPlace::where('type_id',2)->where('sector_type',$sector['sector_type'])->pluck('sort_id')->toArray();
  1697. if(count($component) < $sector['component_num']){
  1698. // 根据 $sector['component_num'] 的值生成对应元素数量的数组
  1699. if (isset($sector['component_num']) && is_numeric($sector['component_num'])) {
  1700. $num = intval($sector['component_num']);
  1701. if ($num > 0 && $num <= 10) {
  1702. // 使用 range 函数生成一个从 1 到 $num 的连续整数数组,存储到 $sector_arr 中
  1703. $sector_arr = range(1, $num);
  1704. } else {
  1705. $sector_arr = [];
  1706. }
  1707. } else {
  1708. $sector_arr = [];
  1709. }
  1710. // 获取 $sector_arr 中不在 $component 里的元素
  1711. $sort = array_diff($sector_arr, $component);
  1712. // return Result::success($sort);
  1713. }
  1714. if(!empty($sort)){
  1715. $sort = array_values(array_map(function($value) {
  1716. return ['id' => $value];
  1717. }, $sort));
  1718. }else{
  1719. return Result::error("组件版式数量已达上限!");
  1720. }
  1721. return Result::success($sort);
  1722. }
  1723. /**
  1724. * 获取所有通栏版式
  1725. */
  1726. public function getAllSectorPlace(array $data): array
  1727. {
  1728. $where['type_id'] = $data['type_id'];
  1729. if($data['type_id'] == 1){
  1730. $where['status'] = 1;
  1731. }
  1732. if(isset($data['sector_type']) && !empty($data['sector_type'])){
  1733. $where['sector_type'] = $data['sector_type'];
  1734. }
  1735. if(isset($data['component_num']) && !empty($data['component_num'])){
  1736. $where['component_num'] = $data['component_num'];
  1737. }
  1738. $sector_place = SectorPlace::where($where)
  1739. ->leftJoin('size','sector_place.size_id','=','size.id')
  1740. ->select('sector_place.*','size.width','size.height')
  1741. ->get()->all();
  1742. if(empty($sector_place)){
  1743. return Result::error('通栏版式不存在!');
  1744. }
  1745. return Result::success($sector_place);
  1746. }
  1747. }