Portal.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\controller\v2;
  3. use app\extra\basic\Base;
  4. use app\extra\service\blue\TaskService;
  5. use app\middleware\WxMiddleware;
  6. use app\model\blue\BlueBanner;
  7. use app\model\blue\BlueCategory;
  8. use DI\Attribute\Inject;
  9. use LinFly\Annotation\Route\Controller;
  10. use LinFly\Annotation\Route\Middleware;
  11. use LinFly\Annotation\Route\Route;
  12. use support\Request;
  13. use support\Response;
  14. #[Controller(prefix: "/wx_v2/portal"),Middleware(WxMiddleware::class)]
  15. class Portal extends Base
  16. {
  17. protected array $noNeedLogin = ['getPortal'];
  18. #[Inject]
  19. protected TaskService $service;
  20. /**
  21. * 小程序首页信息
  22. * @param Request $request
  23. * @return Response
  24. */
  25. #[Route(path: "home",methods: "get")]
  26. public function getPortal(Request $request): Response
  27. {
  28. try {
  29. $param = $this->_valid([
  30. "category.default" => 0,
  31. "size.default" => 10,
  32. "page.default" => 1,
  33. ],$request->method());
  34. $banner = (new BlueBanner)->where("status",1)->field("title,img,path")->select()->toArray();
  35. $category = (new BlueCategory)->where("type",1)->field("name,icon,small_icon,sign")->append(['id'])->withAttr(['id' => function($data,$resp){
  36. return $resp['sign'];
  37. }])->select()->toArray();
  38. if (empty($param['category']) || $param['category'] == 0) {
  39. $param['category'] = $category[0]['id'];
  40. }
  41. $share = [
  42. "image" => sConf("wechat.share"),
  43. "title" => sConf("wechat.share_title")
  44. ];
  45. $rank = [];
  46. $star = [];
  47. $list = $this->service->getHomeList(['category' => $param['category'],'pageSize' => $param['size'],'page' => $param['page']]);
  48. $task = pageFormat($list);
  49. return success("ok",compact("banner","category",'task','share','rank','star'));
  50. } catch (\Throwable $throwable) {
  51. return error($throwable->getMessage());
  52. }
  53. }
  54. }