PublicController.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. <?php
  2. declare (strict_types = 1);
  3. namespace App\Controller;
  4. use App\JsonRpc\PublicRpcServiceInterface;
  5. use App\Tools\CommonService;
  6. use App\Tools\PublicData;
  7. use App\Tools\Result;
  8. use function Hyperf\Support\env;
  9. use Hyperf\Context\Context;
  10. use Hyperf\Di\Annotation\Inject;
  11. use Hyperf\HttpServer\Contract\RequestInterface;
  12. use Hyperf\HttpServer\Contract\ResponseInterface;
  13. use Hyperf\Validation\Contract\ValidatorFactoryInterface;
  14. use ZipArchive;
  15. /**
  16. * Class PublicController
  17. * @package App\Controller
  18. */
  19. //#[AutoController]
  20. class PublicController extends AbstractController
  21. {
  22. #[Inject]
  23. protected ValidatorFactoryInterface $validationFactory;
  24. /**
  25. * @var PublicRpcServiceInterface
  26. */
  27. #[Inject]
  28. private $publicServiceClient;
  29. /**
  30. * 地区
  31. * @return array
  32. */
  33. public function getDistrictList()
  34. {
  35. $pid = $this->request->input("pid", 0);
  36. $data = [
  37. 'pid' => $pid,
  38. ];
  39. $result = $this->publicServiceClient->getDistrictList($data);
  40. return $result ? Result::success($result['data']) : Result::error($result['message']);
  41. }
  42. /**
  43. * 获取用户等级
  44. * @return array
  45. */
  46. public function getUserLevelList()
  47. {
  48. $requireData = $this->request->all();
  49. $result = $this->publicServiceClient->getUserLevelList($requireData);
  50. return $result ? Result::success($result['data']) : Result::error($result['message']);
  51. }
  52. /**
  53. * 上传图片
  54. * @return array
  55. */
  56. public function uploadFile()
  57. {
  58. $urlN = new CommonService();
  59. $file = $this->request->file('file');
  60. $fileName = $this->request->input("fileName", '');
  61. try {
  62. if ($file == null) {
  63. return Result::error("未找到上传文件");
  64. }
  65. $data = CommonService::uploadFile($file, ['png', 'jpg', 'jpeg', 'gif', 'xls', 'xlsx', 'pdf', 'doc', 'docx', 'ppt', 'zip', 'pptx', 'mp4', 'flv','rar','tar'], 'image');
  66. $data['imgUrl'] = $urlN->imgUrl($data['src']);
  67. $data['oldFileName'] = $fileName;
  68. return Result::success($data, '上传成功');
  69. } catch (\Exception $e) {
  70. return Result::error($e->getMessage());
  71. }
  72. }
  73. /**
  74. * 添加用户等级
  75. * @return array
  76. */
  77. public function addUserLevel()
  78. {
  79. $requireData = $this->request->all();
  80. $validator = $this->validationFactory->make(
  81. $requireData,
  82. [
  83. 'name' => 'required',
  84. ],
  85. [
  86. 'name.required' => '等级名不能为空',
  87. ]
  88. );
  89. if ($validator->fails()) {
  90. $errorMessage = $validator->errors()->first();
  91. return Result::error($errorMessage);
  92. }
  93. $result = $this->publicServiceClient->addUserLevel($requireData);
  94. return $result ? Result::success($result['data']) : Result::error($result['message']);
  95. }
  96. /**
  97. * 删除用户等级
  98. * @return array
  99. */
  100. public function delUserLevel()
  101. {
  102. $requireData = $this->request->all();
  103. $validator = $this->validationFactory->make(
  104. $requireData,
  105. [
  106. 'id' => 'required',
  107. ],
  108. [
  109. 'id.required' => 'ID不能为空',
  110. ]
  111. );
  112. if ($validator->fails()) {
  113. $errorMessage = $validator->errors()->first();
  114. return Result::error($errorMessage);
  115. }
  116. $result = $this->publicServiceClient->delUserLevel($requireData);
  117. return $result ? Result::success($result['data']) : Result::error($result['message']);
  118. }
  119. /**
  120. * 更新用户等级
  121. * @return array
  122. */
  123. public function updateUserLevel()
  124. {
  125. $requireData = $this->request->all();
  126. $validator = $this->validationFactory->make(
  127. $requireData,
  128. [
  129. 'name' => 'required',
  130. 'id' => 'required',
  131. ],
  132. [
  133. 'id.required' => 'ID不能为空',
  134. 'name.required' => '名称不能为空',
  135. ]
  136. );
  137. if ($validator->fails()) {
  138. $errorMessage = $validator->errors()->first();
  139. return Result::error($errorMessage);
  140. }
  141. $result = $this->publicServiceClient->updateUserLevel($requireData);
  142. return $result ? Result::success($result['data']) : Result::error($result['message']);
  143. }
  144. /**
  145. * 城市列表
  146. * @return array
  147. */
  148. public function getCityList()
  149. {
  150. $requireData = $this->request->all();
  151. var_dump($requireData);
  152. $result = $this->publicServiceClient->getDistrictList($requireData);
  153. return $result ? Result::success($result['data']) : Result::error($result['message']);
  154. }
  155. /**
  156. * 投诉举报
  157. * @return void
  158. */
  159. public function addComplaint()
  160. {
  161. $requireData = $this->request->all();
  162. $validator = $this->validationFactory->make(
  163. $requireData,
  164. [
  165. 'title' => 'required',
  166. 'nature' => 'required',
  167. 'nature_level0' => 'required',
  168. 'name' => 'required',
  169. 'mobile' => 'required',
  170. 'describe' => 'required',
  171. ],
  172. [
  173. 'title.required' => '标题不能为空',
  174. 'nature.required' => '类型不能为空',
  175. 'nature_level0.required' => '类型进度不能为空',
  176. 'name.required' => '姓名不能为空',
  177. 'mobile.required' => '手机号码不能为空',
  178. 'describe.required' => '详细说明不能为空',
  179. ]
  180. );
  181. if ($validator->fails()) {
  182. $errorMessage = $validator->errors()->first();
  183. return Result::error($errorMessage);
  184. }
  185. $requireData = $this->request->all();
  186. $requireData['user_id'] = Context::get("UserId");
  187. if ($requireData['id']) {
  188. $result = $this->publicServiceClient->userUpLetterOfComplaint($requireData);
  189. } else {
  190. $result = $this->publicServiceClient->addLetterOfComplaint($requireData);
  191. }
  192. return $result ? Result::success($result['data']) : Result::error($result['message']);
  193. }
  194. /**
  195. * 更新投诉举报信息
  196. * @return array
  197. */
  198. public function upComplaint()
  199. {
  200. $requireData = $this->request->all();
  201. $validator = $this->validationFactory->make(
  202. $requireData,
  203. [
  204. 'id' => 'required',
  205. ],
  206. [
  207. 'id.required' => 'id不能为空',
  208. ]
  209. );
  210. if ($validator->fails()) {
  211. $errorMessage = $validator->errors()->first();
  212. return Result::error($errorMessage);
  213. }
  214. var_dump($requireData);
  215. if (isset($requireData['is_admin']) && !empty($requireData['is_admin'])) {
  216. $requireData['admin_id'] = Context::get("UserId");
  217. }
  218. $result = $this->publicServiceClient->upLetterOfComplaint($requireData);
  219. return $result ? Result::success([]) : Result::error($result['message']);
  220. }
  221. /**
  222. * 获取投诉列表
  223. * @return array
  224. */
  225. public function getComplaint()
  226. {
  227. $requireData = $this->request->all();
  228. $requireData['user_id'] = Context::get("UserId");
  229. if (isset($requireData['is_admin']) && !empty($requireData['is_admin'])) {
  230. unset($requireData['user_id']);
  231. }
  232. $result = $this->publicServiceClient->getLetterOfComplaint($requireData);
  233. if($result['code']==200){
  234. foreach ($result['data']['rows']as $key=>$val){
  235. $result['data']['rows'][$key]['created_at'] = date("Y-m-d",strtotime($val['created_at']));
  236. }
  237. }
  238. return $result ? Result::success($result['data']) : Result::error($result['message']);
  239. }
  240. /**
  241. * 获取投诉举报信息
  242. * @return array
  243. */
  244. public function getLetterOfComplaintInfo()
  245. {
  246. $requireData = $this->request->all();
  247. $requireData['user_id'] = Context::get("UserId");
  248. if (isset($requireData['is_admin']) && !empty($requireData['is_admin'])) {
  249. unset($requireData['user_id']);
  250. }
  251. $result = $this->publicServiceClient->getLetterOfComplaintInfo($requireData);
  252. if ($result) {
  253. $result['data']['judgment'] = $result['data']['judgment'] ? json_decode($result['data']['judgment']) : '';
  254. $result['data']['audio_and_video'] = $result['data']['audio_and_video'] ? json_decode($result['data']['audio_and_video']) : '';
  255. $result['data']['contract'] = $result['data']['contract'] ? json_decode($result['data']['contract']) : '';
  256. $result['data']['qualifications'] = $result['data']['qualifications'] ? json_decode($result['data']['qualifications']) : '';
  257. }
  258. return $result ? Result::success($result['data']) : Result::error($result['message']);
  259. }
  260. /**
  261. * 删除投诉举报信息
  262. * @return array
  263. */
  264. public function delLetterOfComplaint()
  265. {
  266. $requireData = $this->request->all();
  267. $requireData['user_id'] = Context::get("UserId");
  268. if (isset($requireData['is_admin']) && !empty($requireData['is_admin'])) {
  269. unset($requireData['user_id']);
  270. }
  271. $result = $this->publicServiceClient->delLetterOfComplaint($requireData);
  272. return $result ? Result::success($result['data']) : Result::error($result['message']);
  273. }
  274. /**
  275. * 获取投诉分类信息
  276. * @return array
  277. */
  278. public function getLetterType()
  279. {
  280. $requireData = $this->request->all();
  281. $validator = $this->validationFactory->make(
  282. $requireData,
  283. [
  284. 'type' => 'required',
  285. ],
  286. [
  287. 'type.required' => '类型不能为空',
  288. ]
  289. );
  290. if ($validator->fails()) {
  291. $errorMessage = $validator->errors()->first();
  292. return Result::error($errorMessage);
  293. }
  294. $result = $this->publicServiceClient->getLetterType($requireData);
  295. $rep = PublicData::buildMenuTree($result['data']);
  296. return $rep ? Result::success($rep) : Result::error("查询失败");
  297. }
  298. /**
  299. * @return array
  300. */
  301. public function getLetterTypeChildren()
  302. {
  303. $requireData = $this->request->all();
  304. $validator = $this->validationFactory->make(
  305. $requireData,
  306. [
  307. 'type' => 'required',
  308. 'pid' => 'required',
  309. ],
  310. [
  311. 'type.required' => '类型不能为空',
  312. 'pid.required' => 'PID不能为空',
  313. ]
  314. );
  315. if ($validator->fails()) {
  316. $errorMessage = $validator->errors()->first();
  317. return Result::error($errorMessage);
  318. }
  319. $result = $this->publicServiceClient->getLetterType($requireData);
  320. return $result['code']==200 ? Result::success($result['data']) : Result::error("查询失败");
  321. }
  322. public function downloadFile(RequestInterface $request, ResponseInterface $response)
  323. {
  324. //验证是否有传参数
  325. $requireData = $this->request->all();
  326. $validator = $this->validationFactory->make(
  327. $requireData,
  328. [
  329. 'files' => 'required',
  330. ],
  331. [
  332. 'files.required' => '文件不能为空',
  333. ]
  334. );
  335. if ($validator->fails()) {
  336. $errorMessage = $validator->errors()->first();
  337. return Result::error($errorMessage);
  338. }
  339. $requireData['fileName'] = $requireData['fileName'] ?? '政讯通';
  340. //打包文件
  341. $zip = new ZipArchive();
  342. $fileType = 'zip';
  343. $date = date('Ymd');
  344. $filePath = $fileType . DIRECTORY_SEPARATOR . $date;
  345. $allDir = 'public' . DIRECTORY_SEPARATOR . $filePath;
  346. if (!is_dir($allDir)) {
  347. if (!mkdir($allDir, 0755, true)) {
  348. return Result::error('创建文件夹失败');
  349. }
  350. }
  351. $fileName = $requireData['fileName'] . time() . mt_rand(1, 1000000) . '.zip';
  352. $zipFileName = $allDir . DIRECTORY_SEPARATOR . $requireData['fileName'] . time() . mt_rand(1, 1000000) . '.zip';
  353. // $zipFileName = 'public/zip/files.zip';
  354. if ($zip->open($zipFileName, ZipArchive::CREATE) === true) {
  355. // 将要下载的文件逐个添加到zip文件中
  356. // $string = trim($requireData['files'], "[]'"); // 去掉最外层的方括号和单引号(注意:这里假设了单引号,如果是双引号则替换为 ")
  357. // $string = str_replace("'", '', $string); // 去掉所有剩余的单引号(如果原字符串中使用的是双引号,则替换为双引号)
  358. // $filePaths = explode(',', $string);
  359. foreach ($requireData['files'] as $filePathu) {
  360. $attachmentItem = 'public/' . $filePathu;
  361. $zip->addFile($attachmentItem, pathinfo($attachmentItem, PATHINFO_BASENAME));
  362. }
  363. // 关闭zip文件
  364. $zip->close();
  365. // 将zip文件提供给用户进行下载
  366. // readfile($zipFileName);
  367. $fileUrlName = explode("public", $zipFileName);
  368. return Result::success(['fileUrl' => env('HOST') . $fileUrlName[1]]);
  369. } else {
  370. return Result::error('无法创建zip文件');
  371. }
  372. }
  373. /**
  374. * 检测是否被处理
  375. * @return array
  376. */
  377. public function checkMeasure()
  378. {
  379. $requireData = $this->request->all();
  380. $validator = $this->validationFactory->make(
  381. $requireData,
  382. [
  383. 'id' => 'required',
  384. ],
  385. [
  386. 'id.required' => 'id不能为空',
  387. ]
  388. );
  389. if ($validator->fails()) {
  390. $errorMessage = $validator->errors()->first();
  391. return Result::error($errorMessage);
  392. }
  393. $requireData['user_id'] = Context::get("UserId");
  394. $result = $this->publicServiceClient->checkMeasure($requireData);
  395. return $result['code'] == 200 ? Result::success() : Result::error("已经处理了");
  396. }
  397. /**
  398. * 获取职能部门
  399. * @return void
  400. */
  401. public function getDepartment()
  402. {
  403. $requireData = $this->request->all();
  404. $validator = $this->validationFactory->make(
  405. $requireData,
  406. [
  407. 'pid' => 'required',
  408. ],
  409. [
  410. 'pid.required' => 'id不能为空',
  411. ]
  412. );
  413. if ($validator->fails()) {
  414. $errorMessage = $validator->errors()->first();
  415. return Result::error($errorMessage);
  416. }
  417. $result = $this->publicServiceClient->getDepartment($requireData);
  418. return $result['code'] == 200 ? Result::success($result['data']) : Result::error("查询失败");
  419. }
  420. /**
  421. * 获取职能部门
  422. * @return array
  423. */
  424. public function getZhinengbumenList()
  425. {
  426. // 获取请求参数
  427. $requireData = $this->request->all();
  428. // 参数验证
  429. $validator = $this->validationFactory->make(
  430. $requireData,
  431. [
  432. 'page' => 'integer|min:1',
  433. 'pagesize' => 'integer|min:1',
  434. 'search' => 'string|nullable',
  435. ],
  436. [
  437. 'page.integer' => 'page 必须是整数',
  438. 'page.min' => 'page 必须大于等于 1',
  439. 'pagesize.integer' => 'pagesize 必须是整数',
  440. 'pagesize.min' => 'pagesize 必须大于等于 1',
  441. 'search.string' => 'search 必须是字符串',
  442. ]
  443. );
  444. if ($validator->fails()) {
  445. $errorMessage = $validator->errors()->first();
  446. return Result::error($errorMessage);
  447. }
  448. // 添加用户 ID
  449. $requireData['user_id'] = Context::get("UserId");
  450. // 调用服务客户端方法获取分页数据
  451. $result = $this->publicServiceClient->getZhinengbumenList($requireData);
  452. // 处理结果
  453. return $result['code'] == 200 ? Result::success($result['data']) : Result::error("查询失败");
  454. }
  455. /**
  456. * 添加职能部门
  457. * @return array
  458. */
  459. public function addZhinengbumen()
  460. {
  461. // 获取请求参数
  462. $requireData = $this->request->all();
  463. $validator = $this->validationFactory->make(
  464. $requireData,
  465. [
  466. 'name' => 'required|string|regex:/^[\x{4e00}-\x{9fa5}]+$/u',
  467. 'pid' => 'required|integer',
  468. ],
  469. [
  470. 'name.required' => 'name 不能为空',
  471. 'name.string' => 'name 必须是字符串',
  472. 'name.regex' => 'name 必须是汉字',
  473. 'pid.required' => 'pid 不能为空',
  474. 'pid.integer' => 'pid 必须是整数',
  475. ]
  476. );
  477. if ($validator->fails()) {
  478. $errorMessage = $validator->errors()->first();
  479. return Result::error($errorMessage);
  480. }
  481. // $requireData['user_id'] = Context::get("UserId");
  482. $result = $this->publicServiceClient->addZhinengbumen($requireData);
  483. return $result['code'] == 200 ? Result::success() : Result::error("添加失败");
  484. }
  485. /**
  486. * 删除职能部门
  487. * @return array
  488. */
  489. public function delZhinengbumen()
  490. {
  491. $requireData = $this->request->all();
  492. $validator = $this->validationFactory->make(
  493. $requireData,
  494. [
  495. 'id' => 'required|integer',
  496. ],
  497. [
  498. 'id.required' => 'id 不能为空',
  499. 'id.integer' => 'id 必须是整数',
  500. ]
  501. );
  502. if ($validator->fails()) {
  503. $errorMessage = $validator->errors()->first();
  504. return Result::error($errorMessage);
  505. }
  506. $requireData['user_id'] = Context::get("UserId");
  507. $result = $this->publicServiceClient->delZhinengbumen($requireData);
  508. return $result['code'] == 200 ? Result::success() : Result::error("删除失败");
  509. }
  510. /**
  511. * 职能部门详情
  512. * @return array
  513. */
  514. public function getZhinengbumen()
  515. {
  516. $requireData = $this->request->all();
  517. $validator = $this->validationFactory->make(
  518. $requireData,
  519. [
  520. 'id' => 'required|integer',
  521. ],
  522. [
  523. 'id.required' => 'id 不能为空',
  524. 'id.integer' => 'id 必须是整数',
  525. ]
  526. );
  527. if ($validator->fails()) {
  528. $errorMessage = $validator->errors()->first();
  529. return Result::error($errorMessage);
  530. }
  531. $requireData['user_id'] = Context::get("UserId");
  532. $result = $this->publicServiceClient->getZhinengbumen($requireData);
  533. return $result['code'] == 200 ? Result::success($result['data']) : Result::error("查询失败");
  534. }
  535. /**
  536. * 获取职能部门某pid的所有子级,默认0级
  537. * @return array
  538. */
  539. public function getPidZhinengbumen()
  540. {
  541. // 获取请求参数
  542. $requireData = $this->request->all();
  543. // 参数验证
  544. $validator = $this->validationFactory->make(
  545. $requireData,
  546. [
  547. 'pid' => 'integer|min:0',
  548. ],
  549. [
  550. 'pid.integer' => 'pid 必须是整数',
  551. 'pid.min' => 'pid 必须大于等于 0',
  552. ]
  553. );
  554. if ($validator->fails()) {
  555. $errorMessage = $validator->errors()->first();
  556. return Result::error($errorMessage);
  557. }
  558. $requireData['user_id'] = Context::get("UserId");
  559. $result = $this->publicServiceClient->getPidZhinengbumen($requireData);
  560. return $result['code'] == 200 ? Result::success($result['data']) : Result::error("查询失败");
  561. }
  562. /**
  563. * 修改职能部门名称
  564. * @return array
  565. */
  566. public function modZhinengbumen()
  567. {
  568. $requireData = $this->request->all();
  569. // 参数验证
  570. $validator = $this->validationFactory->make(
  571. $requireData,
  572. [
  573. 'id' => 'required|integer',
  574. 'name' => 'required|string|regex:/^[\x{4e00}-\x{9fa5}]+$/u',
  575. ],
  576. [
  577. 'id.required' => 'id 不能为空',
  578. 'id.integer' => 'id 必须是整数',
  579. 'name.required' => 'name 不能为空',
  580. 'name.string' => 'name 必须是字符串',
  581. 'name.regex' => 'name 必须是汉字',
  582. ]
  583. );
  584. if ($validator->fails()) {
  585. $errorMessage = $validator->errors()->first();
  586. return Result::error($errorMessage);
  587. }
  588. $requireData['user_id'] = Context::get("UserId");
  589. $result = $this->publicServiceClient->modZhinengbumen($requireData);
  590. return $result['code'] == 200 ? Result::success() : Result::error("修改失败");
  591. }
  592. /**
  593. * 获取风格名称
  594. * @return array
  595. */
  596. public function getTemplateClass()
  597. {
  598. $requireData = $this->request->all();
  599. // 参数验证
  600. $validator = $this->validationFactory->make(
  601. $requireData,
  602. [
  603. // 'type' => 'required|integer',
  604. ],
  605. [
  606. // 'type.required' => 'type 不能为空',
  607. // 'type.integer' => 'type 必须是整数',
  608. ]
  609. );
  610. if ($validator->fails()) {
  611. $errorMessage = $validator->errors()->first();
  612. return Result::error($errorMessage);
  613. }
  614. $requireData['user_id'] = Context::get("UserId");
  615. $result = $this->publicServiceClient->getTemplateClass($requireData);
  616. return $result['code'] == 200 ? Result::success($result['data']) : Result::error("查询失败");
  617. }
  618. /**
  619. * 获取风格列表
  620. * @return array
  621. */
  622. public function getTemplateList()
  623. {
  624. $requireData = $this->request->all();
  625. $validator = $this->validationFactory->make(
  626. $requireData,
  627. [
  628. 'page' => 'required|integer|min:1',
  629. 'page_size' => 'required|integer|min:1',
  630. 'template_name' => 'string|nullable',
  631. ],
  632. [
  633. 'page.required' => 'page 不能为空',
  634. 'page.integer' => 'page 必须是整数',
  635. 'page.min' => 'page 必须大于等于 1',
  636. 'page_size.required' => 'page_size 不能为空',
  637. 'page_size.integer' => 'page_size 必须是整数',
  638. 'page_size.min' => 'page_size 必须大于等于 1',
  639. 'template_name.string' => 'template_name 必须是字符串',
  640. ]
  641. );
  642. if ($validator->fails()) {
  643. $errorMessage = $validator->errors()->first();
  644. return Result::error($errorMessage);
  645. }
  646. $requireData['user_id'] = Context::get("UserId");
  647. $result = $this->publicServiceClient->getTemplateList($requireData);
  648. return $result['code'] == 200 ? Result::success($result['data']) : Result::error("查询失败");
  649. }
  650. /**
  651. * 获取风格详情
  652. * @return array
  653. */
  654. public function getTemplateInfo()
  655. {
  656. $requireData = $this->request->all();
  657. $validator = $this->validationFactory->make(
  658. $requireData,
  659. [
  660. 'id' => 'required|integer',
  661. ],
  662. [
  663. 'id.required' => 'id 不能为空',
  664. 'id.integer' => 'id 必须是整数',
  665. ]
  666. );
  667. if ($validator->fails()) {
  668. $errorMessage = $validator->errors()->first();
  669. return Result::error($errorMessage);
  670. }
  671. $requireData['user_id'] = Context::get("UserId");
  672. $result = $this->publicServiceClient->getTemplateInfo($requireData);
  673. return $result['code'] == 200 ? Result::success($result['data']) : Result::error("查询失败");
  674. }
  675. /**
  676. * 删除模板
  677. */
  678. public function delTemplate()
  679. {
  680. $requireData = $this->request->all();
  681. var_dump($requireData);
  682. $validator = $this->validationFactory->make(
  683. $requireData,
  684. [
  685. 'id' => 'required|integer',
  686. ],
  687. [
  688. 'id.required' => 'id 不能为空',
  689. 'id.integer' => 'id 必须是整数',
  690. ]
  691. );
  692. if ($validator->fails()) {
  693. $errorMessage = $validator->errors()->first();
  694. return Result::error($errorMessage);
  695. }
  696. $requireData['user_id'] = Context::get("UserId");
  697. $result = $this->publicServiceClient->delTemplate($requireData);
  698. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  699. }
  700. /**
  701. * 更新模板
  702. */
  703. public function updateTemplate()
  704. {
  705. $requireData = $this->request->all();
  706. $validator = $this->validationFactory->make(
  707. $requireData,
  708. [
  709. 'id' => 'required',
  710. ],
  711. [
  712. 'id.required' => 'id不能为空',
  713. ]
  714. );
  715. if ($validator->fails()) {
  716. $errorMessage = $validator->errors()->first();
  717. return Result::error($errorMessage);
  718. }
  719. $requireData['user_id'] = Context::get("UserId");
  720. $result = $this->publicServiceClient->updateTemplate($requireData);
  721. var_dump($result,'1001010');
  722. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  723. }
  724. /**
  725. * 新增风格
  726. */
  727. public function addTemplate()
  728. {
  729. $requireData = $this->request->all();
  730. $validator = $this->validationFactory->make($requireData, [
  731. 'template_name' => 'required',
  732. 'template_class_id' => 'required',
  733. 'template_img' => 'required',
  734. ],
  735. [
  736. 'template_name.required' => '请输入模板名称',
  737. 'template_class_id.required' => '请选择模板分类',
  738. 'template_img.required' => '请上传模板图片',
  739. ]
  740. );
  741. if ($validator->fails()) {
  742. $errorMessage = $validator->errors()->first();
  743. return Result::error($errorMessage);
  744. }
  745. $requireData['user_id'] = Context::get("UserId");
  746. $result = $this->publicServiceClient->addTemplate($requireData);
  747. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  748. }
  749. /**
  750. * 新增板块
  751. */
  752. public function addSector()
  753. {
  754. $requireData = $this->request->all();
  755. $validator = $this->validationFactory->make(
  756. $requireData,
  757. [
  758. // 'id' => 'required|integer',
  759. 'template_id'=>'required|integer',
  760. 'sector_name'=>'required|string',
  761. 'sector_code'=>'required|string',
  762. 'page_type'=>'required|string',
  763. 'sector_img'=>'required|string',
  764. ],
  765. [
  766. // 'id.required' => 'id 不能为空',
  767. // 'id.integer' => 'id 必须是整数',
  768. 'template_id.required' => '模板id 不能为空',
  769. 'template_id.integer' => '模板id 必须是整数',
  770. 'sector_name.required' => '板块名称 不能为空',
  771. 'sector_name.string' => '板块名称 必须是字符串',
  772. 'sector_code.required' => '板块代码 不能为空',
  773. 'sector_code.string' => '板块代码 必须是字符串',
  774. 'page_type.required' => '页面类型 不能为空',
  775. 'page_type.string' => '页面类型 必须是字符串',
  776. 'sector_img.required' => '板块图片 不能为空',
  777. 'sector_img.string' => '板块图片 必须是字符串',
  778. ]
  779. );
  780. if ($validator->fails()) {
  781. $errorMessage = $validator->errors()->first();
  782. return Result::error($errorMessage);
  783. }
  784. $requireData['user_id'] = Context::get("UserId");
  785. $result = $this->publicServiceClient->addSector($requireData);
  786. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  787. }
  788. /**
  789. * 获取板块信息
  790. */
  791. public function getSectorInfo()
  792. {
  793. $requireData = $this->request->all();
  794. $validator = $this->validationFactory->make(
  795. $requireData,
  796. [
  797. 'id' => 'required|integer',
  798. ],
  799. [
  800. 'id.required' => 'id 不能为空',
  801. 'id.integer' => 'id 必须是整数',
  802. ]
  803. );
  804. if ($validator->fails()) {
  805. $errorMessage = $validator->errors()->first();
  806. return Result::error($errorMessage);
  807. }
  808. $requireData['user_id'] = Context::get("UserId");
  809. $result = $this->publicServiceClient->getSectorInfo($requireData);
  810. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  811. }
  812. /**
  813. * 添加板块
  814. */
  815. public function delSector()
  816. {
  817. $requireData = $this->request->all();
  818. $validator = $this->validationFactory->make(
  819. $requireData,
  820. [
  821. 'id' => 'required|integer',
  822. ],
  823. [
  824. 'id.required' => 'id 不能为空',
  825. 'id.integer' => 'id 必须是整数',
  826. ]
  827. );
  828. if ($validator->fails()) {
  829. $errorMessage = $validator->errors()->first();
  830. return Result::error($errorMessage);
  831. }
  832. $requireData['user_id'] = Context::get("UserId");
  833. $result = $this->publicServiceClient->delSector($requireData);
  834. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  835. }
  836. /**
  837. * 更新板块
  838. */
  839. public function updateSector()
  840. {
  841. $requireData = $this->request->all();
  842. $validator = $this->validationFactory->make(
  843. $requireData,
  844. [
  845. 'id' => 'required|integer',
  846. ],
  847. [
  848. 'id.required' => 'id 不能为空',
  849. 'id.integer' => 'id 必须是整数',
  850. ]
  851. );
  852. if ($validator->fails()) {
  853. $errorMessage = $validator->errors()->first();
  854. return Result::error($errorMessage);
  855. }
  856. $requireData['user_id'] = Context::get("UserId");
  857. $result = $this->publicServiceClient->updateSector($requireData);
  858. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  859. }
  860. /**
  861. * 获取板块信息列表
  862. */
  863. public function getSectorList(){
  864. $requireData = $this->request->all();
  865. $validator = $this->validationFactory->make(
  866. $requireData,
  867. [
  868. 'page' => 'required|integer|min:1',
  869. 'page_size' => 'required|integer|min:1',
  870. ],
  871. [
  872. 'page.required' => 'page 不能为空',
  873. 'page.integer' => 'page 必须是整数',
  874. 'page.min' => 'page 必须大于等于 1',
  875. 'page_size.required' => 'page_size 不能为空',
  876. 'page_size.integer' => 'page_size 必须是整数',
  877. 'page_size.min' => 'page_size 必须大于等于 1',
  878. ]
  879. );
  880. if ($validator->fails()) {
  881. $errorMessage = $validator->errors()->first();
  882. return Result::error($errorMessage);
  883. }
  884. $requireData['user_id'] = Context::get("UserId");
  885. $result = $this->publicServiceClient->getSectorList($requireData);
  886. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  887. }
  888. /*
  889. * 获取板块列表
  890. */
  891. public function getComponentInfo()
  892. {
  893. $requireData = $this->request->all();
  894. $validator = $this->validationFactory->make(
  895. $requireData,
  896. [
  897. 'id' => 'required|integer',
  898. ],
  899. [
  900. 'id.required' => 'id 不能为空',
  901. 'id.integer' => 'id 必须是整数',
  902. ]
  903. );
  904. if ($validator->fails()) {
  905. $errorMessage = $validator->errors()->first();
  906. return Result::error($errorMessage);
  907. }
  908. $requireData['user_id'] = Context::get("UserId");
  909. $result = $this->publicServiceClient->getComponentInfo($requireData);
  910. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  911. }
  912. /**
  913. * 删除板块
  914. */
  915. public function delComponent()
  916. {
  917. $requireData = $this->request->all();
  918. $validator = $this->validationFactory->make(
  919. $requireData,
  920. [
  921. 'id' => 'required|integer',
  922. ],
  923. [
  924. 'id.required' => 'id 不能为空',
  925. 'id.integer' => 'id 必须是整数',
  926. ]
  927. );
  928. if ($validator->fails()) {
  929. $errorMessage = $validator->errors()->first();
  930. return Result::error($errorMessage);
  931. }
  932. $requireData['user_id'] = Context::get("UserId");
  933. $result = $this->publicServiceClient->delComponent($requireData);
  934. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  935. }
  936. public function addComponent()
  937. {
  938. $requireData = $this->request->all();
  939. $validator = $this->validationFactory->make(
  940. $requireData,
  941. [
  942. 'template_id' => 'required|integer',
  943. 'sector_id' => 'required|integer',
  944. 'component_name' => 'required|string',
  945. 'component_img' => 'required|string',
  946. 'component_code' => 'required|string',
  947. ],
  948. [
  949. 'template_id.required' => 'template_id 不能为空',
  950. 'template_id.integer' => 'template_id 必须是整数',
  951. 'sector_id.required' => 'sector_id 不能为空',
  952. 'sector_id.integer' => 'sector_id 必须是整数',
  953. 'component_name.required' => 'component_name 不能为空',
  954. 'component_name.string' => 'component_name 必须是字符串',
  955. 'component_type.required' => 'component_type 不能为空',
  956. 'component_type.integer' => 'component_type 必须是整数',
  957. ]
  958. );
  959. if ($validator->fails()) {
  960. $errorMessage = $validator->errors()->first();
  961. return Result::error($errorMessage);
  962. }
  963. // $requireData['user_id'] = Context::get("UserId");
  964. $result = $this->publicServiceClient->addComponent($requireData);
  965. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  966. }
  967. public function getComponentList()
  968. {
  969. $requireData = $this->request->all();
  970. $validator = $this->validationFactory->make(
  971. $requireData,
  972. [
  973. 'page' => 'required|integer|min:1',
  974. 'page_size' => 'required|integer|min:1',
  975. ],
  976. [
  977. 'page.required' => 'page 不能为空',
  978. 'page.integer' => 'page 必须是整数',
  979. 'page.min' => 'page 必须大于等于 1',
  980. 'page_size.required' => 'page_size 不能为空',
  981. 'page_size.integer' => 'page_size 必须是整数',
  982. 'page_size.min' => 'page_size 必须大于等于 1',
  983. ]
  984. );
  985. if ($validator->fails()) {
  986. $errorMessage = $validator->errors()->first();
  987. return Result::error($errorMessage);
  988. }
  989. $requireData['user_id'] = Context::get("UserId");
  990. $result = $this->publicServiceClient->getComponentList($requireData);
  991. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  992. }
  993. public function updateComponent()
  994. {
  995. $requireData = $this->request->all();
  996. $validator = $this->validationFactory->make(
  997. $requireData,
  998. [
  999. 'id' => 'required|integer',
  1000. ],
  1001. [
  1002. 'id.required' => 'id 不能为空',
  1003. 'id.integer' => 'id 必须是整数',
  1004. ]
  1005. );
  1006. if ($validator->fails()) {
  1007. $errorMessage = $validator->errors()->first();
  1008. return Result::error($errorMessage);
  1009. }
  1010. // $requireData['user_id'] = Context::get("UserId");
  1011. $result = $this->publicServiceClient->updateComponent($requireData);
  1012. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  1013. }
  1014. public function getWebsiteTemplateList()
  1015. {
  1016. $requireData = $this->request->all();
  1017. $validator = $this->validationFactory->make(
  1018. $requireData,
  1019. [
  1020. 'page' => 'required|integer|min:1',
  1021. 'page_size' => 'required|integer|min:1',
  1022. ],
  1023. [
  1024. 'page.required' => 'page 不能为空',
  1025. 'page.integer' => 'page 必须是整数',
  1026. 'page.min' => 'page 必须大于等于 1',
  1027. 'page_size.required' => 'page_size 不能为空',
  1028. 'page_size.integer' => 'page_size 必须是整数',
  1029. 'page_size.min' => 'page_size 必须大于等于 1',
  1030. ]
  1031. );
  1032. if ($validator->fails()) {
  1033. $errorMessage = $validator->errors()->first();
  1034. return Result::error($errorMessage);
  1035. }
  1036. $requireData['user_id'] = Context::get("UserId");
  1037. $result = $this->publicServiceClient->getWebsiteTemplateList($requireData);
  1038. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  1039. }
  1040. public function getWebsiteTemplateInfo()
  1041. {
  1042. $requireData = $this->request->all();
  1043. $validator = $this->validationFactory->make(
  1044. $requireData,
  1045. [
  1046. 'id' => 'required|integer',
  1047. ],
  1048. [
  1049. 'id.required' => 'id 不能为空',
  1050. 'id.integer' => 'id 必须是整数',
  1051. ]
  1052. );
  1053. if ($validator->fails()) {
  1054. $errorMessage = $validator->errors()->first();
  1055. return Result::error($errorMessage);
  1056. }
  1057. $requireData['user_id'] = Context::get("UserId");
  1058. $result = $this->publicServiceClient->getWebsiteTemplateInfo($requireData);
  1059. return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
  1060. }
  1061. }