PublicRpcService.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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. $result = LetterOfComplaint::when($data,function ($query) use ($data){
  284. if(isset($data['id']) && !empty($data['id'])){
  285. $query->where(['id'=>$data['id']]);
  286. }
  287. if(isset($data['user_id']) && !empty($data['user_id'])){
  288. $query->where(['user_id'=>$data['user_id']]);
  289. }
  290. })->delete();
  291. if (empty($result)) {
  292. return Result::error("删除失败", 0);
  293. } else {
  294. return Result::success();
  295. }
  296. }
  297. /**
  298. * 获取举报信息类型
  299. * @param array $data
  300. * @return array
  301. */
  302. public function getLetterType(array $data): array
  303. {
  304. $where = [];
  305. if (isset($data['type'])) {
  306. array_push($where, ['type', '=', $data['type']]);
  307. }
  308. if (isset($data['pid']) && $data['pid'] > 0) {
  309. array_push($where, ['pid', '=', $data['pid']]);
  310. }
  311. $result = LetterType::where($where)->orderBy('sort', 'asc')->get();
  312. return $result ? Result::success($result) : Result::error("没有查到数据");
  313. }
  314. /**
  315. * 更新举报类型
  316. * @param array $data
  317. * @return array
  318. */
  319. public function upLetterType(array $data): array
  320. {
  321. return [];
  322. }
  323. /**
  324. * 添加举报类型
  325. * @param array $data
  326. * @return array
  327. */
  328. public function addLetterType(array $data): array
  329. {
  330. $result = LetterType::insertGetId($data);
  331. if (empty($result)) {
  332. return Result::error("创建失败", 0);
  333. } else {
  334. return Result::success(["id" => $result]);
  335. }
  336. }
  337. /**
  338. * 删除举报类型
  339. * @param array $data
  340. * @return array
  341. */
  342. public function delLetterType(array $data): array
  343. {
  344. $result = LetterType::where('id', $data['id'])->delete();
  345. if (empty($result)) {
  346. return Result::error("删除失败", 0);
  347. } else {
  348. return Result::success();
  349. }
  350. }
  351. /**
  352. * 检测是否已经被接案
  353. * @param array $data
  354. * @return array
  355. */
  356. public function checkMeasure(array $data): array
  357. {
  358. $where = [
  359. 'id' => $data['id'],
  360. ];
  361. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  362. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  363. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  364. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  365. return Result::success();
  366. } else {
  367. return Result::error("您不能处理其他人已经接过的案件", 0);
  368. }
  369. }
  370. /**
  371. * 后台获取职能部门
  372. * @param array $data
  373. * @return array
  374. */
  375. public function getZhinengbumenList(array $data): array
  376. {
  377. // 获取分页参数,默认每页 10 条记录
  378. $page = isset($data['page']) ? (int) $data['page'] : 1;
  379. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  380. // 查询数据并分页
  381. $query = Department::query();
  382. // 可以在这里添加更多的查询条件
  383. if (isset($data['search'])) {
  384. $query->where('name', 'like', '%' . $data['search'] . '%');
  385. }
  386. // 执行分页查询
  387. $result = $query->paginate($perPage, ['*'], 'page', $page);
  388. // 返回分页结果
  389. return Result::success([
  390. 'count' => $result->total(),
  391. 'current_page' => $result->currentPage(),
  392. 'last_page' => $result->lastPage(),
  393. 'pagesize' => $result->perPage(),
  394. 'rows' => $result->items(),
  395. ]);
  396. }
  397. /**
  398. * 添加获取职能部门
  399. * @param array $data
  400. * @return array
  401. */
  402. public function addZhinengbumen(array $data): array
  403. {
  404. $result = Department::insertGetId($data);
  405. if (empty($result)) {
  406. return Result::error("创建失败", 0);
  407. } else {
  408. return Result::success(["id" => $result]);
  409. }
  410. }
  411. public function delZhinengbumen(array $data): array
  412. {
  413. $result = Department::where('id', $data['id'])->delete();
  414. if (empty($result)) {
  415. return Result::error("删除失败", 0);
  416. } else {
  417. return Result::success();
  418. }
  419. }
  420. public function getZhinengbumen(array $data): array
  421. {
  422. $result = Department::where('id', $data['id'])->first();
  423. return Result::success($result);
  424. }
  425. public function getPidZhinengbumen(array $data): array
  426. {
  427. if (empty($data['pid'])) {
  428. $data['pid'] = 0;
  429. }
  430. $result = Department::where('pid', $data['pid'])->get();
  431. return Result::success($result);
  432. }
  433. public function modZhinengbumen(array $data): array
  434. {
  435. $result = Department::where('id', $data['id'])->update($data);
  436. if (empty($result)) {
  437. return Result::error("修改失败", 0);
  438. } else {
  439. return Result::success();
  440. }
  441. }
  442. /**
  443. * 查询职能列表
  444. * @param array $data
  445. * @return array
  446. */
  447. public function getDepartment(array $data): array
  448. {
  449. $where = [];
  450. if(isset($data['pid'])){
  451. $where = [
  452. 'pid'=>$data['pid']??0
  453. ];
  454. }
  455. $result = Department::when(!empty($where),function ($query) use ($where){
  456. $query->where($where);
  457. })->orderBy("sort","desc")->get();
  458. if (empty($result)) {
  459. return Result::error("查询失败", 0);
  460. } else {
  461. return Result::success($result);
  462. }
  463. }
  464. /**
  465. * 获取getTemplateClass
  466. * @param array $data
  467. * @return array
  468. */
  469. public function getTemplateClass(array $data): array
  470. {
  471. $result = TemplateClass::get();
  472. return Result::success($result);
  473. }
  474. public function getTemplateList(array $data): array
  475. {
  476. $where = [];
  477. if (!empty($data['template_class_id'])) {
  478. $where['template_class_id'] = $data['template_class_id'];
  479. }
  480. if (!empty($data['template_name'])) {
  481. $where['template_name'] = $data['template_name'];
  482. }
  483. $result = Template::where($where)
  484. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  485. ->select('template.*', 'template_class.name as template_class_name')
  486. ->orderBy('template.id', 'desc')
  487. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  488. // 使用 items 方法获取分页数据
  489. // $items = collect($result->items());
  490. // $items->each(function ($item) {
  491. // $item['template_content'] = json_decode($item['template_content'], true);
  492. // });
  493. return Result::success($result);
  494. }
  495. public function getTemplateInfo(array $data): array
  496. {
  497. $result = Template::where('template.id', $data['id'])
  498. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  499. ->select('template.*', 'template_class.name as template_class_name')
  500. ->first();
  501. return Result::success($result);
  502. }
  503. public function addTemplate(array $data): array
  504. {
  505. var_dump($data);
  506. unset($data['user_id']);
  507. $result = Template::insertGetId($data);
  508. if ($result) {
  509. $returData = Template::where('id', $result)->first();
  510. return Result::success($returData);
  511. } else {
  512. return Result::error("添加失败", 0);
  513. }
  514. }
  515. public function delTemplate(array $data): array
  516. {
  517. $result = Template::where('id', $data['id'])->delete();
  518. var_dump($result, '-------------------delete');
  519. if ($result) {
  520. return Result::success($result);
  521. } else {
  522. return Result::error("删除失败", 0);
  523. }
  524. }
  525. public function updateTemplate(array $data): array
  526. {
  527. unset($data['user_id']);
  528. $result = Template::where('id', $data['id'])->update($data);
  529. var_dump($result, '-------------------update');
  530. if (!$result) {
  531. return Result::error("更新失败", 0);
  532. } else {
  533. return Result::success('更新成功');
  534. }
  535. }
  536. public function getSectorList(array $data): array
  537. {
  538. $where = [];
  539. if (!empty($data['template_class_id'])) {
  540. $where['template_class.id'] = $data['template_class_id'];
  541. }
  542. if (!empty($data['template_class_name'])) {
  543. $where[] = ['template_class.name', 'like', '%' . $data['template_class_name'] . '%'];
  544. }
  545. if (!empty($data['sector_name'])) {
  546. if (!empty($data['sector_name'])) {
  547. // $where['sector_name'] = $data['sector_name'];
  548. $where[] = ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%'];
  549. }
  550. }
  551. $result = Sector::where($where)
  552. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  553. ->leftJoin('template_class', 'template_class.id', '=', 'sector.template_id') // 添加这一行
  554. ->select('sector.*', 'sector.sector_name', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  555. ->orderBy('sector.id', 'desc')
  556. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  557. return Result::success($result);
  558. }
  559. public function getSectorInfo(array $data): array
  560. {
  561. $where = [];
  562. $where[] = ['sector.id', '=', $data['id']];
  563. $result = Sector::where($where)
  564. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  565. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  566. ->select('sector.*', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  567. ->orderBy('sector.id', 'desc')
  568. ->get();
  569. return Result::success($result);
  570. }
  571. public function addSector(array $data): array
  572. {
  573. unset($data['user_id']);
  574. // $data['page_type'] = json_encode($data['page_type']);
  575. $result = Sector::insertGetId($data);
  576. return Result::success();
  577. }
  578. public function delSector(array $data): array
  579. {
  580. $result = Sector::where('id', $data['id'])->delete();
  581. if ($result == 1) {
  582. return Result::success('删除成功');
  583. } else {
  584. return Result::error('删除失败');
  585. }
  586. }
  587. public function updateSector(array $data): array
  588. {
  589. unset($data['user_id']);
  590. $result = Sector::where('id', $data['id'])->update($data);
  591. if ($result == 1) {
  592. return Result::success('修改成功');
  593. } else {
  594. return Result::error('修改失败');
  595. }
  596. }
  597. public function getComponentList(array $data): array
  598. {
  599. var_dump($data, '---------');
  600. $where = [];
  601. // $where[] = ['sector.id', '=', $data['id']];
  602. if (!empty($data['template_class_id'])) {
  603. $where['template_class.id'] = $data['template_class_id'];
  604. }
  605. if (!empty($data['component_name'])) {
  606. $where['component.component_name'] = $data['component_name'];
  607. }
  608. if (!empty($data['sector_id'])) {
  609. $where['sector.id'] = $data['sector_id'];
  610. };
  611. $result = Component::where($where)
  612. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  613. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  614. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  615. ->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') // 修改这一行)
  616. ->orderBy('sector.updated_at', 'desc')
  617. ->orderBy('sector.created_at', 'desc')
  618. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  619. return Result::success($result);
  620. }
  621. public function getComponentInfo(array $data): array
  622. {
  623. $where = [];
  624. $result = Component::where($where)
  625. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  626. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  627. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  628. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
  629. ->get();
  630. return Result::success($result);
  631. }
  632. public function addComponent(array $data): array
  633. {
  634. unset($data['user_id']);
  635. $result = Component::insertGetId($data);
  636. if ($result) {
  637. return Result::success($result);
  638. } else {
  639. return Result::error('添加失败');
  640. }
  641. }
  642. public function delComponent(array $data): array
  643. {
  644. $result = Component::where('id', $data['id'])->delete();
  645. return Result::success($result);
  646. }
  647. public function updateComponent(array $data): array
  648. {
  649. $result = Component::where('id', $data['id'])->update($data);
  650. return Result::success($result);
  651. }
  652. public function getWebsiteTemplateList(array $data): array
  653. {
  654. $where = [];
  655. $result = WebsiteTemplateInfo::where($where)
  656. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  657. ->select('website_template_info.*', 'website.website_name')
  658. ->orderBy('website_template_info.id', 'desc')
  659. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  660. if ($result) {
  661. return Result::success($result);
  662. } else {
  663. return Result::error('暂无数据');
  664. }
  665. }
  666. public function getWebsiteTemplateInfo(array $data)
  667. {
  668. $where = [];
  669. if (isset($data['id'])) {
  670. $where[] = ['id', '=', $data['id']];
  671. }
  672. $result = WebsiteTemplateInfo::where($where)
  673. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  674. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  675. ->select('website_template_info.*', 'website.website_name')
  676. ->get();
  677. if ($result) {
  678. return Result::success($result);
  679. } else {
  680. return Result::error('暂无数据');
  681. }
  682. }
  683. }