PublicRpcService.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Department;
  4. use App\Model\District;
  5. use App\Model\LetterOfComplaint;
  6. use App\Model\LetterType;
  7. use App\Model\LevelUser;
  8. use App\Model\UserLevel;
  9. use App\Model\TemplateClass;
  10. use App\Model\Template;
  11. use App\Model\WebsiteTemplate;
  12. use App\Model\WebsiteTemplateInfo;
  13. use App\Model\Sector;
  14. use App\Model\Component;
  15. use App\Tools\Result;
  16. use Hyperf\RpcServer\Annotation\RpcService;
  17. use Hyperf\Support\Collection;
  18. use App\Service\MinioService;
  19. #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  20. class PublicRpcService implements PublicRpcServiceInterface
  21. {
  22. /**
  23. * @param array $data
  24. * @return array
  25. */
  26. public function getDistrictList(array $data): array
  27. {
  28. $where = [];
  29. if (isset($data['keyWord'])) {
  30. $where = [
  31. ['name', 'like', '%' . $data['keyWord'] . '%'],
  32. ];
  33. }
  34. $result = [];
  35. if (isset($data['pageSize'])) {
  36. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
  37. $count = District::where($where)->count();
  38. $result = [
  39. 'rows' => $rep,
  40. 'count' => $count,
  41. ];
  42. } else {
  43. $result = District::where($data)->orderBy("code", "asc")->get();
  44. }
  45. return $result ? Result::success($result) : Result::error("没有查到数据");
  46. }
  47. /**
  48. * @param array $data
  49. * @return array
  50. */
  51. public function getUserLevelList(array $data): array
  52. {
  53. $where = [];
  54. if (isset($data['keyWord'])) {
  55. $where = [
  56. ['name', 'like', '%' . $data['keyWord'] . '%'],
  57. ];
  58. }
  59. $result = [];
  60. if (isset($data['pageSize'])) {
  61. $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get();
  62. $count = UserLevel::where($where)->count();
  63. $result = [
  64. 'rows' => $rep,
  65. 'count' => $count,
  66. ];
  67. } else {
  68. $result = UserLevel::orderBy("id", "asc")->get();
  69. }
  70. return $result ? Result::success($result) : Result::error("没有查到数据");
  71. }
  72. /**
  73. * 添加用户等级
  74. * @param array $data
  75. * @return array
  76. */
  77. public function addUserLevel(array $data): array
  78. {
  79. LevelUser::insertGetId($data);
  80. return Result::success([]);
  81. }
  82. /**
  83. * 更新等级
  84. * @param array $data
  85. * @return array
  86. */
  87. public function updateUserLevel(array $data): array
  88. {
  89. $result = LevelUser::where(['id' => $data['id']])->update($data);
  90. if ($result) {
  91. return Result::success($result);
  92. }
  93. return Result::error("更新失败");
  94. }
  95. /**
  96. * 删除等级
  97. * @param array $data
  98. * @return array
  99. */
  100. public function delUserLevel(array $data): array
  101. {
  102. $result = LevelUser::where(['id' => $data['id']])->delete();
  103. if ($result) {
  104. return Result::success($result);
  105. }
  106. return Result::error("删除失败");
  107. }
  108. /**
  109. * 查询投诉举报信息
  110. * @param array $data
  111. * @return array
  112. */
  113. public function getLetterOfComplaint(array $data = []): array
  114. {
  115. var_dump("====");
  116. $where = [];
  117. if (isset($data['user_id']) && !empty($data['user_id'])) {
  118. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  119. }
  120. if (isset($data['nature']) && !empty($data['nature'])) {
  121. array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
  122. }
  123. if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
  124. array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
  125. }
  126. if (isset($data['status']) && !empty($data['status'])) {
  127. array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
  128. }
  129. $result = [];
  130. if (isset($data['pageSize'])) {
  131. $rep = LetterOfComplaint::where($where)
  132. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  133. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  134. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  135. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  136. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  137. ->select("letter_of_complaint.*",
  138. "type_a.type_name as nature_name",
  139. "type_b.type_name as nature_name1",
  140. "type_c.type_name as nature_name0",
  141. "type_d.type_name as status_name",
  142. "type_e.type_name as nature_name3")
  143. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
  144. $count = LetterOfComplaint::where($where)->count();
  145. if ($rep) {
  146. foreach ($rep as $val) {
  147. if ($val['judgment']) {
  148. $val['judgment'] = json_decode($val['judgment']);
  149. }
  150. if ($val['audio_and_video']) {
  151. $val['audio_and_video'] = json_decode($val['audio_and_video']);
  152. }
  153. if ($val['contract']) {
  154. $val['contract'] = json_decode($val['contract']);
  155. }
  156. if ($val['qualifications']) {
  157. $val['qualifications'] = json_decode($val['qualifications']);
  158. }
  159. }
  160. }
  161. $result = [
  162. 'rows' => $rep,
  163. 'count' => $count,
  164. ];
  165. } else {
  166. $result = LetterOfComplaint::where($where)
  167. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  168. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  169. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  170. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  171. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  172. ->select("letter_of_complaint.*",
  173. "type_a.type_name as nature_name",
  174. "type_b.type_name as nature_name1",
  175. "type_c.type_name as nature_name0",
  176. "type_d.type_name as status_name",
  177. "type_e.type_name as nature_name3")
  178. ->orderBy("letter_of_complaint.id", "desc")->get();
  179. }
  180. return $result ? Result::success($result) : Result::error("没有查到数据");
  181. }
  182. /**
  183. * 添加投诉举报信息
  184. * @param array $data
  185. * @return array
  186. */
  187. public function addLetterOfComplaint(array $data): array
  188. {
  189. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  190. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  191. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  192. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  193. unset($data['id']);
  194. $result = LetterOfComplaint::insertGetId($data);
  195. if (empty($result)) {
  196. return Result::error("创建失败", 0);
  197. } else {
  198. return Result::success(["id" => $result]);
  199. }
  200. }
  201. /**
  202. * 用户端更新投诉举报
  203. * @param array $data
  204. * @return array
  205. */
  206. public function userUpLetterOfComplaint(array $data): array
  207. {
  208. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  209. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  210. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  211. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  212. $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
  213. if (empty($result)) {
  214. return Result::error("创建失败", 0);
  215. } else {
  216. return Result::success(["id" => $result]);
  217. }
  218. }
  219. /**
  220. * 管理后台更新投诉举报信息
  221. * @param array $data
  222. * @return array
  223. */
  224. public function upLetterOfComplaint(array $data): array
  225. {
  226. var_dump("admin:", $data);
  227. $where = [
  228. 'id' => $data['id'],
  229. ];
  230. $filtered_array = array_filter($data, function ($value) {
  231. return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
  232. });
  233. $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
  234. $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
  235. $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
  236. $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
  237. unset($filtered_array['nature_name']);
  238. unset($filtered_array['type_name']);
  239. unset($filtered_array['nature_level_name']);
  240. unset($filtered_array['status_name']);
  241. unset($filtered_array['is_admin']);
  242. unset($filtered_array['type_level_name']);
  243. $result = LetterOfComplaint::where($where)->update($filtered_array);
  244. if ($result) {
  245. return Result::success($result);
  246. }
  247. return Result::error("更新失败", 0);
  248. }
  249. /**
  250. * 查询投诉举报记录
  251. * @param array $data
  252. * @return array
  253. */
  254. public function getLetterOfComplaintInfo(array $data): array
  255. {
  256. $where = [
  257. 'letter_of_complaint.id' => $data['id'],
  258. ];
  259. if (isset($data['user_id']) && !empty($data['user_id'])) {
  260. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  261. }
  262. $result = LetterOfComplaint::where($where)
  263. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  264. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  265. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  266. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  267. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  268. ->select("letter_of_complaint.*",
  269. "type_a.type_name as nature_name",
  270. "type_b.type_name as nature_name1",
  271. "type_c.type_name as nature_name0",
  272. "type_d.type_name as status_name",
  273. "type_e.type_name as nature_name3")
  274. ->first();
  275. return Result::success($result);
  276. }
  277. /**
  278. * 删除投诉举报信息
  279. * @param array $data
  280. * @return array
  281. */
  282. public function delLetterOfComplaint(array $data): array
  283. {
  284. $result = LetterOfComplaint::when($data,function ($query) use ($data){
  285. if(isset($data['id']) && !empty($data['id'])){
  286. $query->where(['id'=>$data['id']]);
  287. }
  288. if(isset($data['user_id']) && !empty($data['user_id'])){
  289. $query->where(['user_id'=>$data['user_id']]);
  290. }
  291. })->delete();
  292. if (empty($result)) {
  293. return Result::error("删除失败", 0);
  294. } else {
  295. return Result::success();
  296. }
  297. }
  298. /**
  299. * 获取举报信息类型
  300. * @param array $data
  301. * @return array
  302. */
  303. public function getLetterType(array $data): array
  304. {
  305. $where = [];
  306. if (isset($data['type'])) {
  307. array_push($where, ['type', '=', $data['type']]);
  308. }
  309. if (isset($data['pid']) && $data['pid'] > 0) {
  310. array_push($where, ['pid', '=', $data['pid']]);
  311. }
  312. $result = LetterType::where($where)->orderBy('sort', 'asc')->get();
  313. return $result ? Result::success($result) : Result::error("没有查到数据");
  314. }
  315. /**
  316. * 更新举报类型
  317. * @param array $data
  318. * @return array
  319. */
  320. public function upLetterType(array $data): array
  321. {
  322. return [];
  323. }
  324. /**
  325. * 添加举报类型
  326. * @param array $data
  327. * @return array
  328. */
  329. public function addLetterType(array $data): array
  330. {
  331. $result = LetterType::insertGetId($data);
  332. if (empty($result)) {
  333. return Result::error("创建失败", 0);
  334. } else {
  335. return Result::success(["id" => $result]);
  336. }
  337. }
  338. /**
  339. * 删除举报类型
  340. * @param array $data
  341. * @return array
  342. */
  343. public function delLetterType(array $data): array
  344. {
  345. $result = LetterType::where('id', $data['id'])->delete();
  346. if (empty($result)) {
  347. return Result::error("删除失败", 0);
  348. } else {
  349. return Result::success();
  350. }
  351. }
  352. /**
  353. * 检测是否已经被接案
  354. * @param array $data
  355. * @return array
  356. */
  357. public function checkMeasure(array $data): array
  358. {
  359. $where = [
  360. 'id' => $data['id'],
  361. ];
  362. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  363. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  364. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  365. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  366. return Result::success();
  367. } else {
  368. return Result::error("您不能处理其他人已经接过的案件", 0);
  369. }
  370. }
  371. /**
  372. * 后台获取职能部门
  373. * @param array $data
  374. * @return array
  375. */
  376. public function getZhinengbumenList(array $data): array
  377. {
  378. // 获取分页参数,默认每页 10 条记录
  379. $page = isset($data['page']) ? (int) $data['page'] : 1;
  380. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  381. // 查询数据并分页
  382. $query = Department::query();
  383. // 可以在这里添加更多的查询条件
  384. if (isset($data['search'])) {
  385. $query->where('name', 'like', '%' . $data['search'] . '%');
  386. }
  387. // 执行分页查询
  388. $result = $query->paginate($perPage, ['*'], 'page', $page);
  389. // 返回分页结果
  390. return Result::success([
  391. 'count' => $result->total(),
  392. 'current_page' => $result->currentPage(),
  393. 'last_page' => $result->lastPage(),
  394. 'pagesize' => $result->perPage(),
  395. 'rows' => $result->items(),
  396. ]);
  397. }
  398. /**
  399. * 添加获取职能部门
  400. * @param array $data
  401. * @return array
  402. */
  403. public function addZhinengbumen(array $data): array
  404. {
  405. $result = Department::insertGetId($data);
  406. if (empty($result)) {
  407. return Result::error("创建失败", 0);
  408. } else {
  409. return Result::success(["id" => $result]);
  410. }
  411. }
  412. public function delZhinengbumen(array $data): array
  413. {
  414. $result = Department::where('id', $data['id'])->delete();
  415. if (empty($result)) {
  416. return Result::error("删除失败", 0);
  417. } else {
  418. return Result::success();
  419. }
  420. }
  421. public function getZhinengbumen(array $data): array
  422. {
  423. $result = Department::where('id', $data['id'])->first();
  424. return Result::success($result);
  425. }
  426. public function getPidZhinengbumen(array $data): array
  427. {
  428. if (empty($data['pid'])) {
  429. $data['pid'] = 0;
  430. }
  431. $result = Department::where('pid', $data['pid'])->get();
  432. return Result::success($result);
  433. }
  434. public function modZhinengbumen(array $data): array
  435. {
  436. $result = Department::where('id', $data['id'])->update($data);
  437. if (empty($result)) {
  438. return Result::error("修改失败", 0);
  439. } else {
  440. return Result::success();
  441. }
  442. }
  443. /**
  444. * 查询职能列表
  445. * @param array $data
  446. * @return array
  447. */
  448. public function getDepartment(array $data): array
  449. {
  450. $where = [];
  451. if(isset($data['pid'])){
  452. $where = [
  453. 'pid'=>$data['pid']??0
  454. ];
  455. }
  456. $result = Department::when(!empty($where),function ($query) use ($where){
  457. $query->where($where);
  458. })->orderBy("sort","desc")->get();
  459. if (empty($result)) {
  460. return Result::error("查询失败", 0);
  461. } else {
  462. return Result::success($result);
  463. }
  464. }
  465. /**
  466. * 获取getTemplateClass
  467. * @param array $data
  468. * @return array
  469. */
  470. public function getTemplateClass(array $data): array
  471. {
  472. $result = TemplateClass::get();
  473. return Result::success($result);
  474. }
  475. public function getTemplateList(array $data): array
  476. {
  477. $where = [];
  478. if (!empty($data['template_class_id'])) {
  479. $where['template_class_id'] = $data['template_class_id'];
  480. }
  481. if (!empty($data['template_name'])) {
  482. $where['template_name'] = $data['template_name'];
  483. }
  484. $result = Template::where($where)
  485. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  486. ->select('template.*', 'template_class.name as template_class_name')
  487. ->orderBy('template.id', 'desc')
  488. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  489. // 使用 items 方法获取分页数据
  490. // $items = collect($result->items());
  491. // $items->each(function ($item) {
  492. // $item['template_content'] = json_decode($item['template_content'], true);
  493. // });
  494. return Result::success($result);
  495. }
  496. public function getTemplateInfo(array $data): array
  497. {
  498. $result = Template::where('template.id', $data['id'])
  499. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  500. ->select('template.*', 'template_class.name as template_class_name')
  501. ->first();
  502. return Result::success($result);
  503. }
  504. public function addTemplate(array $data): array
  505. {
  506. var_dump($data);
  507. unset($data['user_id']);
  508. $result = Template::insertGetId($data);
  509. if ($result) {
  510. $returData = Template::where('id', $result)->first();
  511. return Result::success($returData);
  512. } else {
  513. return Result::error("添加失败", 0);
  514. }
  515. }
  516. public function delTemplate(array $data): array
  517. {
  518. $result = Template::where('id', $data['id'])->delete();
  519. var_dump($result, '-------------------delete');
  520. if ($result) {
  521. return Result::success($result);
  522. } else {
  523. return Result::error("删除失败", 0);
  524. }
  525. }
  526. public function updateTemplate(array $data): array
  527. {
  528. unset($data['user_id']);
  529. $result = Template::where('id', $data['id'])->update($data);
  530. var_dump($result, '-------------------update');
  531. if (!$result) {
  532. return Result::error("更新失败", 0);
  533. } else {
  534. return Result::success('更新成功');
  535. }
  536. }
  537. public function getSectorList(array $data): array
  538. {
  539. $where = [];
  540. if (!empty($data['template_class_id'])) {
  541. $where['template_class.id'] = $data['template_class_id'];
  542. }
  543. if (!empty($data['template_class_name'])) {
  544. $where[] = ['template_class.name', 'like', '%' . $data['template_class_name'] . '%'];
  545. }
  546. if (!empty($data['sector_name'])) {
  547. if (!empty($data['sector_name'])) {
  548. // $where['sector_name'] = $data['sector_name'];
  549. $where[] = ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%'];
  550. }
  551. }
  552. $result = Sector::where($where)
  553. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  554. ->leftJoin('template_class', 'template_class.id', '=', 'sector.template_id') // 添加这一行
  555. ->select('sector.*', 'sector.sector_name', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  556. ->orderBy('sector.id', 'desc')
  557. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  558. return Result::success($result);
  559. }
  560. public function getSectorInfo(array $data): array
  561. {
  562. $where = [];
  563. $where[] = ['sector.id', '=', $data['id']];
  564. $result = Sector::where($where)
  565. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  566. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  567. ->select('sector.*', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  568. ->orderBy('sector.id', 'desc')
  569. ->get();
  570. return Result::success($result);
  571. }
  572. public function addSector(array $data): array
  573. {
  574. unset($data['user_id']);
  575. // $data['page_type'] = json_encode($data['page_type']);
  576. $result = Sector::insertGetId($data);
  577. return Result::success();
  578. }
  579. public function delSector(array $data): array
  580. {
  581. $result = Sector::where('id', $data['id'])->delete();
  582. if ($result == 1) {
  583. return Result::success('删除成功');
  584. } else {
  585. return Result::error('删除失败');
  586. }
  587. }
  588. public function updateSector(array $data): array
  589. {
  590. unset($data['user_id']);
  591. $result = Sector::where('id', $data['id'])->update($data);
  592. if ($result == 1) {
  593. return Result::success('修改成功');
  594. } else {
  595. return Result::error('修改失败');
  596. }
  597. }
  598. public function getComponentList(array $data): array
  599. {
  600. var_dump($data, '---------');
  601. $where = [];
  602. // $where[] = ['sector.id', '=', $data['id']];
  603. if (!empty($data['template_class_id'])) {
  604. $where['template_class.id'] = $data['template_class_id'];
  605. }
  606. if (!empty($data['component_name'])) {
  607. $where['component.component_name'] = $data['component_name'];
  608. }
  609. if (!empty($data['sector_id'])) {
  610. $where['sector.id'] = $data['sector_id'];
  611. };
  612. $result = Component::where($where)
  613. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  614. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  615. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  616. ->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') // 修改这一行)
  617. ->orderBy('sector.updated_at', 'desc')
  618. ->orderBy('sector.created_at', 'desc')
  619. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  620. return Result::success($result);
  621. }
  622. public function getComponentInfo(array $data): array
  623. {
  624. $where = [];
  625. $result = Component::where($where)
  626. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  627. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  628. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  629. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
  630. ->get();
  631. return Result::success($result);
  632. }
  633. public function addComponent(array $data): array
  634. {
  635. unset($data['user_id']);
  636. $result = Component::insertGetId($data);
  637. if ($result) {
  638. return Result::success($result);
  639. } else {
  640. return Result::error('添加失败');
  641. }
  642. }
  643. public function delComponent(array $data): array
  644. {
  645. $result = Component::where('id', $data['id'])->delete();
  646. return Result::success($result);
  647. }
  648. public function updateComponent(array $data): array
  649. {
  650. $result = Component::where('id', $data['id'])->update($data);
  651. return Result::success($result);
  652. }
  653. public function getWebsiteTemplateList(array $data): array
  654. {
  655. $where = [];
  656. $result = WebsiteTemplateInfo::where($where)
  657. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  658. ->select('website_template_info.*', 'website.website_name')
  659. ->orderBy('website_template_info.id', 'desc')
  660. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  661. if ($result) {
  662. return Result::success($result);
  663. } else {
  664. return Result::error('暂无数据');
  665. }
  666. }
  667. public function getWebsiteTemplateInfo(array $data)
  668. {
  669. $where = [];
  670. if (isset($data['id'])) {
  671. $where[] = ['id', '=', $data['id']];
  672. }
  673. $result = WebsiteTemplateInfo::where($where)
  674. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  675. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  676. ->select('website_template_info.*', 'website.website_name')
  677. ->get();
  678. if ($result) {
  679. return Result::success($result);
  680. } else {
  681. return Result::error('暂无数据');
  682. }
  683. }
  684. /**
  685. * 获取所有的buckets
  686. * @param array $data
  687. * @return array
  688. */
  689. public function getBuckets(array $data) :array
  690. {
  691. $result = new MinioService();
  692. // 调用服务层的方法获取存储桶列表
  693. $bucketsResponse =$result->listBuckets();
  694. // 直接返回服务层生成的响应
  695. return Result::success($bucketsResponse['data']);
  696. }
  697. /**
  698. * 上传文件
  699. * @param array $data
  700. * @return array
  701. */
  702. public function uploadFile(array $data) :array
  703. {
  704. $result = new MinioService();
  705. $rep = $result->uploadFile($data);
  706. if($rep['code']==200){
  707. return Result::success($rep['data']);
  708. }else{
  709. return Result::error("上传失败!");
  710. }
  711. }
  712. }