CategoryController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shish <shish@zhhinc.com>
  5. * Date: 2019/6/29
  6. * Time: 14:27
  7. */
  8. namespace mini\controllers;
  9. use biz\goods\services\CategoryRelateService;
  10. use biz\goods\services\CategoryService;
  11. use biz\goods\services\GoodsCategoryService;
  12. use biz\goods\services\GoodsUsageService;
  13. use biz\goods\services\UsageRelationService;
  14. use common\components\util;
  15. use Yii;
  16. class CategoryController extends BaseController
  17. {
  18. //取商家分类和第一个分类的商品 shish 2019.7.3
  19. public function actionGetCategoryList()
  20. {
  21. $menuList = CategoryRelateService::getShowList();
  22. $firstGoodsList = [];
  23. $id = 0;
  24. if (!empty($menuList)) {
  25. $first = reset($menuList);
  26. $id = $first['id'];
  27. $type = $first['type'];
  28. if ($type == 'category') {
  29. $goodsList = GoodsCategoryService::getGoodsList($id);
  30. } elseif ($type == 'usage') {
  31. $goodsList = GoodsUsageService::getGoodsData($id);
  32. } else {
  33. util::fail('菜单类型不存在');
  34. }
  35. $firstGoodsList = $goodsList;
  36. }
  37. $data = ['categoryList' => $menuList, 'firstGoodsList' => $firstGoodsList, 'categoryId' => $id];
  38. util::sendJson($data);
  39. }
  40. //取分类下的商品 shish 2019.7.9
  41. public function actionGetList()
  42. {
  43. $id = Yii::$app->request->get('id', 0);
  44. $type = Yii::$app->request->get('type', 'category');
  45. if ($type == 'category') {
  46. $data = GoodsCategoryService::getCategoryAndList($id);
  47. $data['category']['categoryName'] = $data['category']['showName'];
  48. } elseif ($type == 'usage') {
  49. $data = GoodsUsageService::getGoodsList($id);
  50. $data['category'] = $data['info'];
  51. $data['category']['categoryName'] = $data['info']['showName'];
  52. } else {
  53. util::fail('无效类型');
  54. }
  55. $data['vipShow'] = 1;
  56. util::sendJson($data);
  57. }
  58. }