PublicRpcService.php 31 KB

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