PublicRpcService.php 26 KB

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