PublicRpcService.php 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. <?php
  2. namespace App\JsonRpc;
  3. use _PHPStan_62c6a0a8b\OndraM\CiDetector\Env;
  4. use App\Model\BlackWord;
  5. use App\Model\Department;
  6. use App\Model\District;
  7. use App\Model\LetterOfComplaint;
  8. use App\Model\LetterType;
  9. use App\Model\LevelUser;
  10. use App\Model\UserLevel;
  11. use App\Tools\Result;
  12. use Hyperf\DbConnection\Db;
  13. use Hyperf\Di\Annotation\Inject;
  14. use Hyperf\RpcServer\Annotation\RpcService;
  15. use App\Service\MinioService;
  16. use Hyperf\Redis\Redis;
  17. use Overtrue\ChineseCalendar\Calendar;
  18. use App\Model\TemplateClass;
  19. use App\Model\Template;
  20. use App\Model\WebsiteTemplate;
  21. use App\Model\WebsiteTemplateInfo;
  22. use App\Model\Sector;
  23. use App\Model\Component;
  24. #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  25. class PublicRpcService implements PublicRpcServiceInterface
  26. {
  27. #[Inject]
  28. protected Redis $redis;
  29. /**
  30. * @param array $data
  31. * @return array
  32. */
  33. public function getDistrictList(array $data): array
  34. {
  35. $where = [];
  36. if (isset($data['keyWord'])) {
  37. $where = [
  38. ['name', 'like', '%' . $data['keyWord'] . '%']
  39. ];
  40. }
  41. $result = [];
  42. if (isset($data['pageSize'])) {
  43. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
  44. $count = District::where($where)->count();
  45. $result = [
  46. 'rows' => $rep,
  47. 'count' => $count
  48. ];
  49. } else {
  50. $result = District::where($data)->orderBy("code", "asc")->get();
  51. }
  52. return $result ? Result::success($result) : Result::error("没有查到数据");
  53. }
  54. /**
  55. * @param array $data
  56. * @return array
  57. */
  58. public function getUserLevelList(array $data): array
  59. {
  60. $where = [];
  61. if (isset($data['keyWord'])) {
  62. $where = [
  63. ['name', 'like', '%' . $data['keyWord'] . '%'],
  64. ];
  65. }
  66. $result = [];
  67. if (isset($data['pageSize'])) {
  68. $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get();
  69. $count = UserLevel::where($where)->count();
  70. $result = [
  71. 'rows' => $rep,
  72. 'count' => $count,
  73. ];
  74. } else {
  75. $result = UserLevel::orderBy("id", "asc")->get();
  76. }
  77. return $result ? Result::success($result) : Result::error("没有查到数据");
  78. }
  79. /**
  80. * 添加用户等级
  81. * @param array $data
  82. * @return array
  83. */
  84. public function addUserLevel(array $data): array
  85. {
  86. LevelUser::insertGetId($data);
  87. return Result::success([]);
  88. }
  89. /**
  90. * 更新等级
  91. * @param array $data
  92. * @return array
  93. */
  94. public function updateUserLevel(array $data): array
  95. {
  96. $result = LevelUser::where(['id' => $data['id']])->update($data);
  97. if ($result) {
  98. return Result::success($result);
  99. }
  100. return Result::error("更新失败");
  101. }
  102. /**
  103. * 删除等级
  104. * @param array $data
  105. * @return array
  106. */
  107. public function delUserLevel(array $data): array
  108. {
  109. $result = LevelUser::where(['id' => $data['id']])->delete();
  110. if ($result) {
  111. return Result::success($result);
  112. }
  113. return Result::error("删除失败");
  114. }
  115. /**
  116. * 查询投诉举报信息
  117. * @param array $data
  118. * @return array
  119. */
  120. public function getLetterOfComplaint(array $data = []): array
  121. {
  122. var_dump("====");
  123. $where = [];
  124. if (isset($data['user_id']) && !empty($data['user_id'])) {
  125. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  126. }
  127. if (isset($data['nature']) && !empty($data['nature'])) {
  128. array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
  129. }
  130. if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
  131. array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
  132. }
  133. if (isset($data['status']) && !empty($data['status'])) {
  134. array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
  135. }
  136. $result = [];
  137. if (isset($data['pageSize'])) {
  138. $rep = LetterOfComplaint::where($where)
  139. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  140. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  141. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  142. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  143. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  144. ->select(
  145. "letter_of_complaint.*",
  146. "type_a.type_name as nature_name",
  147. "type_b.type_name as nature_name1",
  148. "type_c.type_name as nature_name0",
  149. "type_d.type_name as status_name",
  150. "type_e.type_name as nature_name3"
  151. )
  152. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
  153. $count = LetterOfComplaint::where($where)->count();
  154. if ($rep) {
  155. foreach ($rep as $val) {
  156. if ($val['judgment']) {
  157. $val['judgment'] = json_decode($val['judgment']);
  158. }
  159. if ($val['audio_and_video']) {
  160. $val['audio_and_video'] = json_decode($val['audio_and_video']);
  161. }
  162. if ($val['contract']) {
  163. $val['contract'] = json_decode($val['contract']);
  164. }
  165. if ($val['qualifications']) {
  166. $val['qualifications'] = json_decode($val['qualifications']);
  167. }
  168. }
  169. }
  170. $result = [
  171. 'rows' => $rep,
  172. 'count' => $count,
  173. ];
  174. } else {
  175. $result = LetterOfComplaint::where($where)
  176. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  177. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  178. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  179. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  180. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  181. ->select(
  182. "letter_of_complaint.*",
  183. "type_a.type_name as nature_name",
  184. "type_b.type_name as nature_name1",
  185. "type_c.type_name as nature_name0",
  186. "type_d.type_name as status_name",
  187. "type_e.type_name as nature_name3"
  188. )
  189. ->orderBy("letter_of_complaint.id", "desc")->get();
  190. }
  191. return $result ? Result::success($result) : Result::error("没有查到数据");
  192. }
  193. /**
  194. * 添加投诉举报信息
  195. * @param array $data
  196. * @return array
  197. */
  198. public function addLetterOfComplaint(array $data): array
  199. {
  200. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  201. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  202. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  203. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  204. unset($data['id']);
  205. $result = LetterOfComplaint::insertGetId($data);
  206. if (empty($result)) {
  207. return Result::error("创建失败", 0);
  208. } else {
  209. return Result::success(["id" => $result]);
  210. }
  211. }
  212. /**
  213. * 用户端更新投诉举报
  214. * @param array $data
  215. * @return array
  216. */
  217. public function userUpLetterOfComplaint(array $data): array
  218. {
  219. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  220. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  221. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  222. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  223. $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
  224. if (empty($result)) {
  225. return Result::error("创建失败", 0);
  226. } else {
  227. return Result::success(["id" => $result]);
  228. }
  229. }
  230. /**
  231. * 管理后台更新投诉举报信息
  232. * @param array $data
  233. * @return array
  234. */
  235. public function upLetterOfComplaint(array $data): array
  236. {
  237. var_dump("admin:", $data);
  238. $where = [
  239. 'id' => $data['id'],
  240. ];
  241. $filtered_array = array_filter($data, function ($value) {
  242. return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
  243. });
  244. $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
  245. $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
  246. $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
  247. $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
  248. unset($filtered_array['nature_name']);
  249. unset($filtered_array['type_name']);
  250. unset($filtered_array['nature_level_name']);
  251. unset($filtered_array['status_name']);
  252. unset($filtered_array['is_admin']);
  253. unset($filtered_array['type_level_name']);
  254. $result = LetterOfComplaint::where($where)->update($filtered_array);
  255. if ($result) {
  256. return Result::success($result);
  257. }
  258. return Result::error("更新失败", 0);
  259. }
  260. /**
  261. * 查询投诉举报记录
  262. * @param array $data
  263. * @return array
  264. */
  265. public function getLetterOfComplaintInfo(array $data): array
  266. {
  267. $where = [
  268. 'letter_of_complaint.id' => $data['id'],
  269. ];
  270. if (isset($data['user_id']) && !empty($data['user_id'])) {
  271. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  272. }
  273. $result = LetterOfComplaint::where($where)
  274. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  275. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  276. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  277. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  278. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  279. ->select(
  280. "letter_of_complaint.*",
  281. "type_a.type_name as nature_name",
  282. "type_b.type_name as nature_name1",
  283. "type_c.type_name as nature_name0",
  284. "type_d.type_name as status_name",
  285. "type_e.type_name as nature_name3"
  286. )
  287. ->first();
  288. return Result::success($result);
  289. }
  290. /**
  291. * 删除投诉举报信息
  292. * @param array $data
  293. * @return array
  294. */
  295. public function delLetterOfComplaint(array $data): array
  296. {
  297. $result = LetterOfComplaint::when($data, function ($query) use ($data) {
  298. if (isset($data['id']) && !empty($data['id'])) {
  299. $query->where(['id' => $data['id']]);
  300. }
  301. if (isset($data['user_id']) && !empty($data['user_id'])) {
  302. $query->where(['user_id' => $data['user_id']]);
  303. }
  304. })->delete();
  305. if (empty($result)) {
  306. return Result::error("删除失败", 0);
  307. } else {
  308. return Result::success();
  309. }
  310. }
  311. /**
  312. * 获取举报信息类型
  313. * @param array $data
  314. * @return array
  315. */
  316. public function getLetterType(array $data): array
  317. {
  318. $where = [];
  319. if (isset($data['type'])) {
  320. array_push($where, ['type', '=', $data['type']]);
  321. }
  322. if (isset($data['pid']) && $data['pid'] > 0) {
  323. array_push($where, ['pid', '=', $data['pid']]);
  324. }
  325. $result = LetterType::where($where)->orderBy('sort', 'asc')->get();
  326. return $result ? Result::success($result) : Result::error("没有查到数据");
  327. }
  328. /**
  329. * 更新举报类型
  330. * @param array $data
  331. * @return array
  332. */
  333. public function upLetterType(array $data): array
  334. {
  335. return [];
  336. }
  337. /**
  338. * 添加举报类型
  339. * @param array $data
  340. * @return array
  341. */
  342. public function addLetterType(array $data): array
  343. {
  344. $result = LetterType::insertGetId($data);
  345. if (empty($result)) {
  346. return Result::error("创建失败", 0);
  347. } else {
  348. return Result::success(["id" => $result]);
  349. }
  350. }
  351. /**
  352. * 删除举报类型
  353. * @param array $data
  354. * @return array
  355. */
  356. public function delLetterType(array $data): array
  357. {
  358. $result = LetterType::where('id', $data['id'])->delete();
  359. if (empty($result)) {
  360. return Result::error("删除失败", 0);
  361. } else {
  362. return Result::success();
  363. }
  364. }
  365. /**
  366. * 检测是否已经被接案
  367. * @param array $data
  368. * @return array
  369. */
  370. public function checkMeasure(array $data): array
  371. {
  372. $where = [
  373. 'id' => $data['id'],
  374. ];
  375. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  376. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  377. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  378. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  379. return Result::success();
  380. } else {
  381. return Result::error("您不能处理其他人已经接过的案件", 0);
  382. }
  383. }
  384. /**
  385. * 后台获取职能部门
  386. * @param array $data
  387. * @return array
  388. */
  389. public function getZhinengbumenList(array $data): array
  390. {
  391. // 获取分页参数,默认每页 10 条记录
  392. $page = isset($data['page']) ? (int) $data['page'] : 1;
  393. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  394. // 查询数据并分页
  395. $query = Department::query();
  396. // 可以在这里添加更多的查询条件
  397. if (isset($data['search'])) {
  398. $query->where('name', 'like', '%' . $data['search'] . '%');
  399. }
  400. // 执行分页查询
  401. $result = $query->paginate($perPage, ['*'], 'page', $page);
  402. // 返回分页结果
  403. return Result::success([
  404. 'count' => $result->total(),
  405. 'current_page' => $result->currentPage(),
  406. 'last_page' => $result->lastPage(),
  407. 'pagesize' => $result->perPage(),
  408. 'rows' => $result->items(),
  409. ]);
  410. }
  411. /**
  412. * 添加获取职能部门
  413. * @param array $data
  414. * @return array
  415. */
  416. public function addZhinengbumen(array $data): array
  417. {
  418. $result = Department::insertGetId($data);
  419. if (empty($result)) {
  420. return Result::error("创建失败", 0);
  421. } else {
  422. return Result::success(["id" => $result]);
  423. }
  424. }
  425. public function delZhinengbumen(array $data): array
  426. {
  427. $result = Department::where('id', $data['id'])->delete();
  428. if (empty($result)) {
  429. return Result::error("删除失败", 0);
  430. } else {
  431. return Result::success();
  432. }
  433. }
  434. public function getZhinengbumen(array $data): array
  435. {
  436. $result = Department::where('id', $data['id'])->first();
  437. return Result::success($result);
  438. }
  439. public function getPidZhinengbumen(array $data): array
  440. {
  441. if (empty($data['pid'])) {
  442. $data['pid'] = 0;
  443. }
  444. $result = Department::where('pid', $data['pid'])->get();
  445. return Result::success($result);
  446. }
  447. public function modZhinengbumen(array $data): array
  448. {
  449. $result = Department::where('id', $data['id'])->update($data);
  450. if (empty($result)) {
  451. return Result::error("修改失败", 0);
  452. } else {
  453. return Result::success();
  454. }
  455. }
  456. /**
  457. * 查询职能列表
  458. * @param array $data
  459. * @return array
  460. */
  461. public function getDepartment(array $data): array
  462. {
  463. $where = [];
  464. if (isset($data['pid'])) {
  465. $where = [
  466. 'pid' => $data['pid'] ?? 0
  467. ];
  468. }
  469. $result = Department::when(!empty($where), function ($query) use ($where) {
  470. $query->where($where);
  471. })->orderBy("sort", "desc")->get();
  472. if (empty($result)) {
  473. return Result::error("查询失败", 0);
  474. } else {
  475. return Result::success($result);
  476. }
  477. }
  478. /**
  479. * 获取所有的buckets
  480. * @param array $data
  481. * @return array
  482. */
  483. public function getBuckets(array $data): array
  484. {
  485. $result = new MinioService();
  486. // 调用服务层的方法获取存储桶列表
  487. $bucketsResponse = $result->listBuckets();
  488. // 直接返回服务层生成的响应
  489. return Result::success($bucketsResponse['data']);
  490. }
  491. /**
  492. * 上传文件
  493. * @param array $data
  494. * @return array
  495. */
  496. public function uploadFile(array $data): array
  497. {
  498. $result = new MinioService();
  499. $rep = $result->uploadFile($data);
  500. if ($rep['code'] == 200) {
  501. return Result::success($rep['data']);
  502. } else {
  503. return Result::error("上传失败!");
  504. }
  505. }
  506. /**
  507. * 黑名单管理
  508. * @param array $data
  509. * @return array
  510. */
  511. public function getBlackWordList(array $data): array
  512. {
  513. $result = BlackWord::when($data, function ($query) use ($data) {
  514. if (isset($data['name']) && $data['name']) {
  515. $query->where('black_word.name', 'like', '%' . $data['name'] . '%');
  516. }
  517. })->orderBy('black_word.id', 'desc')
  518. ->paginate(
  519. intval($data['pageSize']),
  520. [
  521. 'black_word.*',
  522. ],
  523. 'page',
  524. intval($data['page'])
  525. );
  526. $count = $result->total();
  527. $returnData = [
  528. 'rows' => $result->items(),
  529. 'count' => $count
  530. ];
  531. return Result::success($returnData);
  532. }
  533. /**
  534. * 添加黑名单
  535. * @param array $data
  536. * @return array
  537. */
  538. public function addBlackWord(array $data): array
  539. {
  540. Db::beginTransaction();
  541. try {
  542. $info = BlackWord::where(['name' => $data['name']])->first();
  543. if ($info) {
  544. Db::rollBack();
  545. return Result::error("该黑名单已存在", 0);
  546. }
  547. $data['type'] = 10;
  548. $result = BlackWord::insertGetId($data);
  549. $redisKey = 'black_word';
  550. $this->redis->sAdd($redisKey, $data['name']);
  551. Db::commit();
  552. return Result::success(["id" => $result]);
  553. } catch (\Exception $e) {
  554. Db::rollBack();
  555. return Result::error("创建失败" . $e->getMessage(), 0);
  556. }
  557. }
  558. /**
  559. * 删除黑名单
  560. * @param array $data
  561. * @return array
  562. */
  563. public function delBlackWord(array $data): array
  564. {
  565. Db::beginTransaction();
  566. try {
  567. BlackWord::where(['name' => $data['name']])->delete();
  568. $redisKey = 'black_word';
  569. $this->redis->sRem($redisKey, $data['name']);
  570. Db::commit();
  571. return Result::success([]);
  572. } catch (\Exception $e) {
  573. Db::rollBack();
  574. return Result::error("删除失败" . $e->getMessage(), 0);
  575. }
  576. }
  577. /**
  578. * 修改违禁词
  579. * @param array $data
  580. * @return array
  581. */
  582. public function upBlackWord(array $data): array
  583. {
  584. Db::beginTransaction();
  585. try {
  586. $checkInfo = BlackWord::where(['name' => $data['name']])->first();
  587. if ($checkInfo) {
  588. Db::rollBack();
  589. return Result::error("该违禁词已经存在", 0);
  590. }
  591. $blackWordInfo = BlackWord::where(['id' => $data['id']])->first();
  592. if ($blackWordInfo) {
  593. //先删除redis
  594. $blackWordInfo = $blackWordInfo->toArray();
  595. $redisKey = 'black_word';
  596. $this->redis->sRem($redisKey, $blackWordInfo['name']);
  597. $this->redis->sAdd($redisKey, $data['name']);
  598. BlackWord::where(['id' => $data['id']])->update(['name' => $data['name']]);
  599. Db::commit();
  600. return Result::success([]);
  601. } else {
  602. Db::rollBack();
  603. return Result::error("系统错误", 0);
  604. }
  605. } catch (\Exception $e) {
  606. Db::rollBack();
  607. return Result::error("修改失败" . $e->getMessage(), 0);
  608. }
  609. }
  610. /**
  611. * 获取风格
  612. * @return void
  613. */
  614. public function getTemplateClassList(array $data): array
  615. {
  616. $where = [];
  617. if (isset($data['name']) && $data['name']) {
  618. array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
  619. }
  620. if(isset($data['keyword']) && $data['keyword']){
  621. array_push($where, ['template_class.keyword', 'like', '%'. $data['keyword']. '%']);
  622. }
  623. $template = TemplateClass::when($where, function ($query) use ($where) {
  624. $query->where($where);
  625. });
  626. $count = $template->count();
  627. // $countQuery = clone $template;
  628. $row = $template
  629. ->leftJoin('template', 'template_class.id', '=', 'template.template_class_id')
  630. ->select('template_class.*', DB::raw('COUNT(template.id) as template_count'))
  631. ->groupBy('template_class.id')
  632. ->orderBy('template_class.updated_at', 'desc')
  633. ->offset(($data['page'] - 1) * $data['pageSize'])
  634. ->limit($data['pageSize'])
  635. ->get();
  636. $result = [
  637. 'rows' => $row,
  638. 'count' => $count,
  639. ];
  640. if ($row->isEmpty()) {
  641. return Result::error("暂无风格", 0);
  642. } else {
  643. return Result::success($result);
  644. }
  645. }
  646. /**
  647. * 添加风格
  648. * @param
  649. * @return void
  650. */
  651. public function addTemplateClass(array $data): array
  652. {
  653. $data['keyword'] = json_encode($data['keyword']);
  654. $template_class = TemplateClass::where('name', $data['name'])
  655. ->orWhere('class_id', $data['class_id'])
  656. ->first();
  657. if ($template_class) {
  658. return Result::error("风格名称或者风格编号已存在,不可添加!", 0);
  659. }
  660. $result = TemplateClass::insertGetId($data);
  661. if (empty($result)) {
  662. return Result::error("创建风格失败", 0);
  663. } else {
  664. return Result::success(["id" => $result]);
  665. }
  666. }
  667. /**
  668. * 更新风格
  669. * @param array $data
  670. * @return array
  671. */
  672. public function upTemplateClass(array $data): array
  673. {
  674. $where = [
  675. 'id' => $data['id'],
  676. ];
  677. $template_class = TemplateClass::where($where)->first();
  678. if (empty($template_class)) {
  679. return Result::error("未查询到风格", 0);
  680. }
  681. if($template_class->type == 1){
  682. return Result::error("默认风格不能修改", 0);
  683. }
  684. $template = TemplateClass::where('id','!=',$data['id'])
  685. ->where(['name' => $data['name']])
  686. ->orWhere(['class_id' => $data['class_id']])
  687. ->first();
  688. if ($template) {
  689. return Result::error("风格名称或者风格编号已存在,不可编辑!", 0);
  690. }
  691. $updateData = [
  692. 'name' => $data['name'],
  693. 'keyword' => json_encode($data['keyword']),
  694. 'class_id' => $data['class_id'],
  695. ];
  696. $result = TemplateClass::where($where)->update($updateData);
  697. if (empty($result)) {
  698. return Result::error("更新失败", 0);
  699. } else {
  700. return Result::success($result);
  701. }
  702. }
  703. /**
  704. * 删除风格
  705. * @param array $data
  706. * @return array
  707. */
  708. public function delTemplateClass(array $data): array
  709. {
  710. $where = [
  711. 'id' => $data['id'],
  712. ];
  713. $template = TemplateClass::where($where)->first();
  714. if (empty($template)) {
  715. return Result::error("未查询到风格", 0);
  716. }
  717. if($template->type == 1){
  718. return Result::error("默认风格不能删除", 0);
  719. }
  720. $result = TemplateClass::where($where)->delete();
  721. if (empty($result)) {
  722. return Result::error("删除失败", 0);
  723. } else {
  724. return Result::success($result);
  725. }
  726. }
  727. /**
  728. * 获取getTemplateClass
  729. * @param array $data
  730. * @return array
  731. */
  732. public function getTemplateClass(array $data): array
  733. {
  734. $result = TemplateClass::get();
  735. return Result::success($result);
  736. }
  737. /**
  738. * 获取皮肤列表
  739. * @param array $data
  740. * @return array
  741. */
  742. public function getTemplateList(array $data): array
  743. {
  744. $where = [];
  745. if (!empty($data['template_class_id'])) {
  746. $where['template_class_id'] = $data['template_class_id'];
  747. }
  748. if (!empty($data['template_name'])) {
  749. array_push($where, ['template_name', 'like', '%'. $data['template_name']. '%']);
  750. }
  751. if (!empty($data['template_keyword'])) {
  752. array_push($where, ['template_keyword', 'like', '%'. $data['template_keyword']. '%']);
  753. }
  754. $result = Template::where($where)
  755. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  756. ->select('template.*', 'template_class.name as template_class_name')
  757. ->orderBy('template.id', 'desc')
  758. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  759. // 使用 items 方法获取分页数据
  760. // $items = collect($result->items());
  761. // $items->each(function ($item) {
  762. // $item['template_content'] = json_decode($item['template_content'], true);
  763. // });
  764. return Result::success($result);
  765. }
  766. public function getTemplateInfo(array $data): array
  767. {
  768. $result = Template::where('template.id', $data['id'])
  769. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  770. ->select('template.*', 'template_class.name as template_class_name')
  771. ->first();
  772. return Result::success($result);
  773. }
  774. /**
  775. * 添加皮肤
  776. * @param array $data
  777. * @return array
  778. */
  779. public function addTemplate(array $data): array
  780. {
  781. var_dump($data);
  782. unset($data['user_id']);
  783. $template = Template::where('template_name', $data['template_name'])
  784. ->orWhere('template_id', $data['template_id'])
  785. ->first();
  786. if ($template) {
  787. return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
  788. }
  789. $result = Template::insertGetId($data);
  790. if(empty($result)){
  791. return Result::error("创建失败", 0);
  792. }else{
  793. return Result::success($result);
  794. }
  795. }
  796. /**
  797. * 删除皮肤
  798. * @param array $data
  799. * @return array
  800. */
  801. public function delTemplate(array $data): array
  802. {
  803. $result = Template::where('id', $data['id'])->delete();
  804. var_dump($result, '-------------------delete');
  805. if ($result) {
  806. return Result::success($result);
  807. } else {
  808. return Result::error("删除失败", 0);
  809. }
  810. }
  811. /**
  812. * 更新皮肤
  813. * @param array $data
  814. * @return array
  815. */
  816. public function updateTemplate(array $data): array
  817. {
  818. unset($data['user_id']);
  819. $template = Template::where('id', $data['id'])
  820. ->first();
  821. if (empty($template)) {
  822. return Result::error("此皮肤不存在!", 0);
  823. }
  824. $template = Template::where('id','!=',$data['id'])
  825. ->where(['template_name' => $data['template_name']])
  826. ->orWhere(['template_id' => $data['template_id']])
  827. ->first();
  828. if ($template) {
  829. return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
  830. }
  831. $result = Template::where('id', $data['id'])->update($data);
  832. var_dump($result, '-------------------update');
  833. if (!$result) {
  834. return Result::error("更新失败", 0);
  835. } else {
  836. return Result::success('更新成功');
  837. }
  838. }
  839. public function getSectorList(array $data): array
  840. {
  841. $where = [];
  842. if (!empty($data['template_class_id'])) {
  843. $where['template_class.id'] = $data['template_class_id'];
  844. }
  845. if (!empty($data['template_class_name'])) {
  846. $where[] = ['template_class.name', 'like', '%' . $data['template_class_name'] . '%'];
  847. }
  848. if (!empty($data['sector_name'])) {
  849. if (!empty($data['sector_name'])) {
  850. // $where['sector_name'] = $data['sector_name'];
  851. $where[] = ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%'];
  852. }
  853. }
  854. $result = Sector::where($where)
  855. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  856. ->leftJoin('template_class', 'template_class.id', '=', 'sector.template_id') // 添加这一行
  857. ->select('sector.*', 'sector.sector_name', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  858. ->orderBy('sector.id', 'desc')
  859. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  860. return Result::success($result);
  861. }
  862. public function getSectorInfo(array $data): array
  863. {
  864. $where = [];
  865. $where[] = ['sector.id', '=', $data['id']];
  866. $result = Sector::where($where)
  867. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  868. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  869. ->select('sector.*', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  870. ->orderBy('sector.id', 'desc')
  871. ->get();
  872. return Result::success($result);
  873. }
  874. /**
  875. * 获取经纬度信息
  876. * @return void
  877. */
  878. public function getIpInfo(array $data) :array
  879. {
  880. $client_ip = isset($data['ip']) && $data['ip']??$_SERVER['REMOTE_ADDR'];
  881. // 使用 IPinfo 服务获取 IP 信息
  882. $api_url = "https://ipinfo.io/{$client_ip}/json";
  883. $ch = curl_init($api_url);
  884. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  885. $response = curl_exec($ch);
  886. curl_close($ch);
  887. // 解析 JSON 响应
  888. $ip_info = json_decode($response, true);
  889. // 提取地址和经纬度
  890. if ($ip_info && !isset($ip_info['bogon'])) {
  891. $latitude = explode(',', $ip_info['loc'])[0];
  892. $longitude = explode(',', $ip_info['loc'])[1];
  893. $ip_info['latitude'] = $latitude;
  894. $ip_info['longitude'] = $longitude;
  895. return Result::success($ip_info);
  896. } else {
  897. $data['ip'] = '101.254.114.212';
  898. $this->getIpinfo(["ip"=>$data['ip']]);
  899. }
  900. }
  901. /**
  902. * 获取天气
  903. * @param array $data
  904. * @return array
  905. */
  906. public function getWeatherInfo(array $data) :array
  907. {
  908. $month = $data['month'] ?? date('m');
  909. $day = $data['day'] ?? date('d');
  910. // 使用缓存键
  911. $cacheKey = "tsbb_data_weather_{$month}_{$day}";
  912. // 尝试从缓存获取数据
  913. $container = \Hyperf\Context\ApplicationContext::getContainer();
  914. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  915. if ($cachedData = $cache->get($cacheKey)) {
  916. return Result::success(unserialize($cachedData));
  917. }
  918. $location = $data['latitude'].":".$data['longitude'];
  919. $api_url = "https://api.seniverse.com/v3/weather/now.json?key=".\Hyperf\Support\env('WEATHER_KEY')."&location=".$location."&language=zh-Hans&unit=c";
  920. $ch = curl_init($api_url);
  921. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  922. $response = curl_exec($ch);
  923. curl_close($ch);
  924. // 解析 JSON 响应
  925. $WeatherInfo = json_decode($response, true);
  926. // 缓存结果,设置1小时过期
  927. $cache->set($cacheKey, serialize($WeatherInfo), 3600);
  928. if($WeatherInfo){
  929. return Result::success($WeatherInfo);
  930. }else{
  931. return Result::error("获取天气失败", 0);
  932. }
  933. }
  934. /**
  935. * 获取农历信息
  936. * @return void
  937. */
  938. public function getCalendar(array $data) :array
  939. {
  940. $calendar = new Calendar();
  941. $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
  942. return Result::success($result);
  943. }
  944. public function addSector(array $data): array
  945. {
  946. unset($data['user_id']);
  947. // $data['page_type'] = json_encode($data['page_type']);
  948. $result = Sector::insertGetId($data);
  949. return Result::success();
  950. }
  951. public function delSector(array $data): array
  952. {
  953. $result = Sector::where('id', $data['id'])->delete();
  954. if ($result == 1) {
  955. return Result::success('删除成功');
  956. } else {
  957. return Result::error('删除失败');
  958. }
  959. }
  960. public function updateSector(array $data): array
  961. {
  962. unset($data['user_id']);
  963. $result = Sector::where('id', $data['id'])->update($data);
  964. if ($result == 1) {
  965. return Result::success('修改成功');
  966. } else {
  967. return Result::error('修改失败');
  968. }
  969. }
  970. public function getComponentList(array $data): array
  971. {
  972. var_dump($data, '---------');
  973. $where = [];
  974. // $where[] = ['sector.id', '=', $data['id']];
  975. if (!empty($data['template_class_id'])) {
  976. $where['template_class.id'] = $data['template_class_id'];
  977. }
  978. if (!empty($data['component_name'])) {
  979. $where['component.component_name'] = $data['component_name'];
  980. }
  981. if (!empty($data['sector_id'])) {
  982. $where['sector.id'] = $data['sector_id'];
  983. };
  984. $result = Component::where($where)
  985. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  986. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  987. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  988. ->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') // 修改这一行)
  989. ->orderBy('sector.updated_at', 'desc')
  990. ->orderBy('sector.created_at', 'desc')
  991. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  992. return Result::success($result);
  993. }
  994. public function getComponentInfo(array $data): array
  995. {
  996. $where = [];
  997. $result = Component::where($where)
  998. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  999. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1000. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1001. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
  1002. ->get();
  1003. return Result::success($result);
  1004. }
  1005. public function addComponent(array $data): array
  1006. {
  1007. unset($data['user_id']);
  1008. $result = Component::insertGetId($data);
  1009. if ($result) {
  1010. return Result::success($result);
  1011. } else {
  1012. return Result::error('添加失败');
  1013. }
  1014. }
  1015. public function delComponent(array $data): array
  1016. {
  1017. $result = Component::where('id', $data['id'])->delete();
  1018. return Result::success($result);
  1019. }
  1020. public function updateComponent(array $data): array
  1021. {
  1022. $result = Component::where('id', $data['id'])->update($data);
  1023. return Result::success($result);
  1024. }
  1025. public function getWebsiteTemplateList(array $data): array
  1026. {
  1027. $where = [];
  1028. $result = WebsiteTemplateInfo::where($where)
  1029. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1030. ->select('website_template_info.*', 'website.website_name')
  1031. ->orderBy('website_template_info.id', 'desc')
  1032. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1033. if ($result) {
  1034. return Result::success($result);
  1035. } else {
  1036. return Result::error('暂无数据');
  1037. }
  1038. }
  1039. public function getWebsiteTemplateInfo(array $data)
  1040. {
  1041. $where = [];
  1042. if (isset($data['id'])) {
  1043. $where[] = ['id', '=', $data['id']];
  1044. }
  1045. $result = WebsiteTemplateInfo::where($where)
  1046. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1047. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  1048. ->select('website_template_info.*', 'website.website_name')
  1049. ->get();
  1050. if ($result) {
  1051. return Result::success($result);
  1052. } else {
  1053. return Result::error('暂无数据');
  1054. }
  1055. }
  1056. }