PublicRpcService.php 36 KB

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