PublicRpcService.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  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. * 获取风格
  610. * @return void
  611. */
  612. public function getTemplateClassList(array $data): array
  613. {
  614. $where = [];
  615. if (isset($data['name']) && $data['name']) {
  616. array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
  617. }
  618. $template = TemplateClass::when($where, function ($query) use ($where) {
  619. $query->where($where);
  620. })
  621. ->leftJoin('template', 'template_class.id', '=', 'template.template_class_id')
  622. ->select('template_class.*', DB::raw('COUNT(template.id) as template_count'))
  623. ->groupBy('template_class.id')
  624. ->orderBy('template_class.updated_at', 'desc');
  625. $countQuery = clone $template;
  626. $count = $countQuery->count();
  627. $row = $template
  628. ->offset(($data['page'] - 1) * $data['pageSize'])
  629. ->limit($data['pageSize'])
  630. ->get();
  631. $result = [
  632. 'rows' => $row,
  633. 'count' => $count,
  634. ];
  635. if ($row->isEmpty()) {
  636. return Result::error("暂无风格", 0);
  637. } else {
  638. return Result::success($result);
  639. }
  640. }
  641. /**
  642. * 添加风格
  643. * @param
  644. * @return void
  645. */
  646. public function addTemplateClass(array $data): array
  647. {
  648. $data['keyword'] = json_encode($data['keyword']);
  649. $template = TemplateClass::where(['name' => $data['name']])->first();
  650. if ($template) {
  651. return Result::error("风格名称已存在", 0);
  652. }
  653. $result = TemplateClass::insertGetId($data);
  654. if (empty($result)) {
  655. return Result::error("创建风格失败", 0);
  656. } else {
  657. return Result::success(["id" => $result]);
  658. }
  659. }
  660. /**
  661. * 更新风格
  662. * @param array $data
  663. * @return array
  664. */
  665. public function upTemplateClass(array $data): array
  666. {
  667. $where = [
  668. 'id' => $data['id'],
  669. ];
  670. $template = TemplateClass::where($where)->first();
  671. if (empty($template)) {
  672. return Result::error("未查询到风格", 0);
  673. }
  674. if($template->type == 1){
  675. return Result::error("默认风格不能修改", 0);
  676. }
  677. $template = TemplateClass::where('id','!=',$data['id'])->where(['name' => $data['name']])->first();
  678. if ($template) {
  679. return Result::error("风格名称已存在", 0);
  680. }
  681. $updateData = [
  682. 'name' => $data['name'],
  683. 'keyword' => json_encode($data['keyword']),
  684. ];
  685. $result = TemplateClass::where($where)->update($updateData);
  686. if (empty($result)) {
  687. return Result::error("更新失败", 0);
  688. } else {
  689. return Result::success($result);
  690. }
  691. }
  692. /**
  693. * 删除风格
  694. * @param array $data
  695. * @return array
  696. */
  697. public function delTemplateClass(array $data): array
  698. {
  699. $where = [
  700. 'id' => $data['id'],
  701. ];
  702. $template = TemplateClass::where($where)->first();
  703. if (empty($template)) {
  704. return Result::error("未查询到风格", 0);
  705. }
  706. if($template->type == 1){
  707. return Result::error("默认风格不能删除", 0);
  708. }
  709. $result = TemplateClass::where($where)->delete();
  710. if (empty($result)) {
  711. return Result::error("删除失败", 0);
  712. } else {
  713. return Result::success($result);
  714. }
  715. }
  716. /**
  717. * 获取getTemplateClass
  718. * @param array $data
  719. * @return array
  720. */
  721. public function getTemplateClass(array $data): array
  722. {
  723. $result = TemplateClass::get();
  724. return Result::success($result);
  725. }
  726. public function getTemplateList(array $data): array
  727. {
  728. $where = [];
  729. if (!empty($data['template_class_id'])) {
  730. $where['template_class_id'] = $data['template_class_id'];
  731. }
  732. if (!empty($data['template_name'])) {
  733. $where['template_name'] = $data['template_name'];
  734. }
  735. $result = Template::where($where)
  736. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  737. ->select('template.*', 'template_class.name as template_class_name')
  738. ->orderBy('template.id', 'desc')
  739. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  740. // 使用 items 方法获取分页数据
  741. // $items = collect($result->items());
  742. // $items->each(function ($item) {
  743. // $item['template_content'] = json_decode($item['template_content'], true);
  744. // });
  745. return Result::success($result);
  746. }
  747. public function getTemplateInfo(array $data): array
  748. {
  749. $result = Template::where('template.id', $data['id'])
  750. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  751. ->select('template.*', 'template_class.name as template_class_name')
  752. ->first();
  753. return Result::success($result);
  754. }
  755. public function addTemplate(array $data): array
  756. {
  757. var_dump($data);
  758. unset($data['user_id']);
  759. $result = Template::insertGetId($data);
  760. if ($result) {
  761. $returData = Template::where('id', $result)->first();
  762. return Result::success($returData);
  763. } else {
  764. return Result::error("添加失败", 0);
  765. }
  766. }
  767. public function delTemplate(array $data): array
  768. {
  769. $result = Template::where('id', $data['id'])->delete();
  770. var_dump($result, '-------------------delete');
  771. if ($result) {
  772. return Result::success($result);
  773. } else {
  774. return Result::error("删除失败", 0);
  775. }
  776. }
  777. public function updateTemplate(array $data): array
  778. {
  779. unset($data['user_id']);
  780. $result = Template::where('id', $data['id'])->update($data);
  781. var_dump($result, '-------------------update');
  782. if (!$result) {
  783. return Result::error("更新失败", 0);
  784. } else {
  785. return Result::success('更新成功');
  786. }
  787. }
  788. public function getSectorList(array $data): array
  789. {
  790. $where = [];
  791. if (!empty($data['template_class_id'])) {
  792. $where['template_class.id'] = $data['template_class_id'];
  793. }
  794. if (!empty($data['template_class_name'])) {
  795. $where[] = ['template_class.name', 'like', '%' . $data['template_class_name'] . '%'];
  796. }
  797. if (!empty($data['sector_name'])) {
  798. if (!empty($data['sector_name'])) {
  799. // $where['sector_name'] = $data['sector_name'];
  800. $where[] = ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%'];
  801. }
  802. }
  803. $result = Sector::where($where)
  804. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  805. ->leftJoin('template_class', 'template_class.id', '=', 'sector.template_id') // 添加这一行
  806. ->select('sector.*', 'sector.sector_name', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  807. ->orderBy('sector.id', 'desc')
  808. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  809. return Result::success($result);
  810. }
  811. public function getSectorInfo(array $data): array
  812. {
  813. $where = [];
  814. $where[] = ['sector.id', '=', $data['id']];
  815. $result = Sector::where($where)
  816. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  817. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  818. ->select('sector.*', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  819. ->orderBy('sector.id', 'desc')
  820. ->get();
  821. return Result::success($result);
  822. }
  823. public function addSector(array $data): array
  824. {
  825. unset($data['user_id']);
  826. // $data['page_type'] = json_encode($data['page_type']);
  827. $result = Sector::insertGetId($data);
  828. return Result::success();
  829. }
  830. public function delSector(array $data): array
  831. {
  832. $result = Sector::where('id', $data['id'])->delete();
  833. if ($result == 1) {
  834. return Result::success('删除成功');
  835. } else {
  836. return Result::error('删除失败');
  837. }
  838. }
  839. public function updateSector(array $data): array
  840. {
  841. unset($data['user_id']);
  842. $result = Sector::where('id', $data['id'])->update($data);
  843. if ($result == 1) {
  844. return Result::success('修改成功');
  845. } else {
  846. return Result::error('修改失败');
  847. }
  848. }
  849. public function getComponentList(array $data): array
  850. {
  851. var_dump($data, '---------');
  852. $where = [];
  853. // $where[] = ['sector.id', '=', $data['id']];
  854. if (!empty($data['template_class_id'])) {
  855. $where['template_class.id'] = $data['template_class_id'];
  856. }
  857. if (!empty($data['component_name'])) {
  858. $where['component.component_name'] = $data['component_name'];
  859. }
  860. if (!empty($data['sector_id'])) {
  861. $where['sector.id'] = $data['sector_id'];
  862. };
  863. $result = Component::where($where)
  864. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  865. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  866. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  867. ->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') // 修改这一行)
  868. ->orderBy('sector.updated_at', 'desc')
  869. ->orderBy('sector.created_at', 'desc')
  870. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  871. return Result::success($result);
  872. }
  873. public function getComponentInfo(array $data): array
  874. {
  875. $where = [];
  876. $result = Component::where($where)
  877. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  878. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  879. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  880. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
  881. ->get();
  882. return Result::success($result);
  883. }
  884. public function addComponent(array $data): array
  885. {
  886. unset($data['user_id']);
  887. $result = Component::insertGetId($data);
  888. if ($result) {
  889. return Result::success($result);
  890. } else {
  891. return Result::error('添加失败');
  892. }
  893. }
  894. public function delComponent(array $data): array
  895. {
  896. $result = Component::where('id', $data['id'])->delete();
  897. return Result::success($result);
  898. }
  899. public function updateComponent(array $data): array
  900. {
  901. $result = Component::where('id', $data['id'])->update($data);
  902. return Result::success($result);
  903. }
  904. public function getWebsiteTemplateList(array $data): array
  905. {
  906. $where = [];
  907. $result = WebsiteTemplateInfo::where($where)
  908. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  909. ->select('website_template_info.*', 'website.website_name')
  910. ->orderBy('website_template_info.id', 'desc')
  911. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  912. if ($result) {
  913. return Result::success($result);
  914. } else {
  915. return Result::error('暂无数据');
  916. }
  917. }
  918. public function getWebsiteTemplateInfo(array $data)
  919. {
  920. $where = [];
  921. if (isset($data['id'])) {
  922. $where[] = ['id', '=', $data['id']];
  923. }
  924. $result = WebsiteTemplateInfo::where($where)
  925. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  926. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  927. ->select('website_template_info.*', 'website.website_name')
  928. ->get();
  929. if ($result) {
  930. return Result::success($result);
  931. } else {
  932. return Result::error('暂无数据');
  933. }
  934. }
  935. }