src/Controller/IndexController.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\OGoodsImage;
  4. use App\Entity\OIndexHeadImage;
  5. use App\Entity\OIndexHighlight;
  6. use App\Entity\OGoods;
  7. use App\Entity\OGoodsIntro;
  8. use App\Entity\OOrder;
  9. use App\Entity\OSubscribe;
  10. use App\Service\jsonResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Component\Validator\Validator\ValidatorInterface;
  16. class IndexController extends AbstractController
  17. {
  18.     /**
  19.      * @todo
  20.      * @Route("/test/{str}", name="test")
  21.      */
  22.     public function test($str)
  23.     {
  24.         $str str_replace(',','","',$str);
  25.         $re '["'.$str.'"]';
  26.         echo $re;exit;
  27.     }
  28.     /**
  29.      * @Route("/", name="index")
  30.      */
  31.     public function index(): Response
  32.     {
  33.         $D $this->getDoctrine();
  34.         $firstImage $D->getRepository(OIndexHeadImage::class)->firstImage();
  35.         $highlights $D->getRepository(OIndexHighlight::class)->highlights();
  36.         $indexGoods $D->getRepository(OGoods::class)->indexGoods();
  37.         return $this->render('index/index.html.twig', [
  38.             'firstImage' => $firstImage,
  39.             'highlights' => $highlights,
  40.             'indexGoods' => $indexGoods,
  41.         ]);
  42.     }
  43.     /**
  44.      * @Route("/subscribe", name="subscribe")
  45.      */
  46.     public function subscribe(Request $requestValidatorInterface $validatorjsonResponse $jsonResponse)
  47.     {
  48.         $email $request->query->get('email');
  49.         $type $request->query->get('type');
  50.         $em $this->getDoctrine()->getManager();
  51.         $s = new OSubscribe();
  52.         $s->setOEmail($email);
  53.         $s->setOGender($type);
  54.         $eor $validator->validate($s);
  55.         if (count($eor) > 0) {
  56.             $jsonResponse->setEor('error');
  57.         }else{
  58.             $em->persist($s);
  59.             $em->flush();
  60.         }
  61.         return $this->json($jsonResponse->return());
  62.     }
  63.     /**
  64.      * @Route("/order", name="order")
  65.      */
  66.     public function order(Request $requestValidatorInterface $validatorjsonResponse $jsonResponse)
  67.     {
  68.         $id $request->query->get('id');
  69.         $quantity $request->query->get('quantity');
  70.         $color $request->query->get('color');
  71.         $size $request->query->get('size');
  72.         $phone $request->query->get('phone');
  73.         $email $request->query->get('email');
  74.         $content $request->query->get('content');
  75.         $price $request->query->get('price');
  76.         $em $this->getDoctrine()->getManager();
  77.         $goods $em->getRepository(OGoods::class)->find($id);
  78.         if (!$goods) {
  79.             $jsonResponse->setEor('Goods does not exist.');
  80.             return $this->json($jsonResponse->return());
  81.         }
  82.         $order = new OOrder();
  83.         $order->setOQuantity($quantity);
  84.         $order->setOColor($color);
  85.         $order->setOSize($size);
  86.         $order->setOPhone($phone);
  87.         $order->setOEmail($email);
  88.         $order->setOContent($content);
  89.         $order->setOGoods($goods);
  90.         $order->setOPirce($price);
  91.         $user $this->getUser();
  92.         if($user){
  93.             $order->setOUser($user);
  94.         }
  95.         $eor $validator->validate($order);
  96.         if (count($eor) > 0) {
  97.             $jsonResponse->setEor($eor);
  98.         }else{
  99.             $em->persist($order);
  100.             $em->flush();
  101.         }
  102.         return $this->json($jsonResponse->return());
  103.     }
  104.     /**
  105.      * @Route(
  106.      *     "/list/{category}/{sub}/{sort}",
  107.      *     name="list",
  108.      *     defaults={"sort":"recommend"},
  109.      *     requirements={
  110.      *         "sort": "price|price_desc|newest",
  111.      *     }
  112.      * )
  113.      */
  114.     public function list($category$sub$sort)
  115.     {
  116.         $D $this->getDoctrine();
  117.         $goodses $D->getRepository(OGoods::class)->getGoodsList($category$sub$sort);
  118.         return $this->render('index/list.html.twig', [
  119.             'goodses' => $goodses,
  120.             'sort' => $sort,
  121.             'category' => $category,
  122.             'sub' => $sub
  123.         ]);
  124.     }
  125.     /**
  126.      * TODO
  127.      * @Route("/aaa", name="aaa")
  128.      */
  129.     public function aaa(Request $request)
  130.     {
  131.         $hex1 $request->query->get('hex1');
  132.         $hex2 $request->query->get('hex2','');
  133.         $id $request->query->get('id');
  134.         $type $request->query->get('t');
  135.         $D $this->getDoctrine();
  136.         $im $D->getRepository(OGoodsImage::class);
  137.         $obj $im->find($id);
  138.         $hex $im->getImageHex($type$hex1$hex2);
  139.         $obj->setOHex($hex);
  140.         $em $D->getManager();
  141.         $em->persist($obj);
  142.         $em->flush();
  143.         echo 1;exit;
  144.     }
  145.     /**
  146.      * @Route("/search", name="search")
  147.      */
  148.     public function search(Request $request)
  149.     {
  150.         $key $request->query->get('key');
  151.         $D $this->getDoctrine();
  152.         $goodses $D->getRepository(OGoods::class)->getGoodsListByKeyword($key);
  153.         return $this->render('index/search.html.twig', [
  154.             'goodses' => $goodses,
  155.             'key' => $key,
  156.         ]);
  157.     }
  158.     /**
  159.      * @Route("/detail/{id}", name="detail")
  160.      */
  161.     public function detail($id)
  162.     {
  163.         $D $this->getDoctrine();
  164.         $goods $D->getRepository(OGoods::class)->getGoods($id);
  165.         $intro $D->getRepository(OGoodsIntro::class)->findBy(['oGoods'=>$goods],['oSort'=>'ASC']);
  166.         return $this->render('index/detail.html.twig', [
  167.             'goods' => $goods,
  168.             'intro' => $intro
  169.         ]);
  170.     }
  171.     /**
  172.      * TODO
  173.      * @Route("/image/{id}", name="image")
  174.      */
  175.     public function image($id)
  176.     {
  177.         $D $this->getDoctrine();
  178.         $goods $D->getRepository(OGoodsImage::class)->find($id);
  179.         return $this->render('index/image.html.twig', [
  180.             'image' => $goods
  181.         ]);
  182.     }
  183.     /**
  184.      * TODO
  185.      * @Route("/hex/{id}/{x}/{y}", name="hex")
  186.      */
  187.     public function imageHex($id,$x,$y)
  188.     {
  189.         $DRe $this->getDoctrine()->getRepository(OGoodsImage::class);
  190.         $goods $DRe->find($id);
  191.         $image $this->getParameter('cdn_url').$goods->getOUrl();
  192.         list($width$height$type$attr) = getimagesize($image);
  193.         $x intval($x/500*$width);
  194.         $y intval($y/500*$width);
  195.         $hex $DRe->point_color($image,$x,$y);
  196.         echo $hex;exit;
  197.     }
  198.     /**
  199.      * @Route("/reset-password", name="reset-password")
  200.      */
  201.     public function resetPassword()
  202.     {
  203.         return $this->render('index/resetPassword.html.twig', []);
  204.     }
  205.     /**
  206.      * @Route("/filter", name="filter")
  207.      */
  208.     public function getFilterData()
  209.     {
  210.     }
  211. }