GoodsController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\GoodsCategoryService;
  11. use biz\goods\services\GoodsUsageService;
  12. use common\components\util;
  13. use common\services\xhGoodsService;
  14. use common\services\xhRecommendService;
  15. use Yii;
  16. use yii\helpers\Json;
  17. class GoodsController extends BaseController
  18. {
  19. public $withoutLogin = ['get-index-data'];
  20. public function actionGetLimitGoods()
  21. {
  22. $list = xhGoodsService::getLimitGoods($this->merchantId);
  23. util::sendJson($list);
  24. }
  25. public function actionGetIndexData()
  26. {
  27. $slide = xhRecommendService::getSlide($this->merchantId);
  28. $list = xhGoodsService::getLimitGoods($this->merchantId);
  29. $categoryData = CategoryRelateService::getShowList(8);
  30. $chunkData = array_chunk($categoryData, 4);
  31. $category1 = $chunkData[0];
  32. $category2 = $chunkData[1];
  33. //首页第一个分类列表的名称 shish 2019.8.3
  34. $firstCategoryName = '掌柜推荐';
  35. //是否显示第一个分类列表的名称 shish 2019.8.3
  36. $showFirstCategory = 1;
  37. $data = ['goods' => $list, 'slide' => $slide, 'category1' => $category1,
  38. 'category2' => $category2, 'firstCategoryName' => $firstCategoryName, 'showFirstCategory' => $showFirstCategory];
  39. util::sendJson($data);
  40. }
  41. public function actionGetById()
  42. {
  43. $id = Yii::$app->request->get('id', 0);
  44. $info = xhGoodsService::getById($id);
  45. $info['shopImg'] = json_decode($info['shopImg'], true);
  46. util::sendJson($info);
  47. }
  48. //根据分类取商品列表 shish 2019.7.3
  49. public function actionGetListByCategory()
  50. {
  51. $id = Yii::$app->request->get('categoryId', 0);
  52. $type = Yii::$app->request->get('type', 'category');
  53. if ($type == 'category') {
  54. $return = GoodsCategoryService::getGoodsList($id);
  55. } else {
  56. $return = GoodsUsageService::getGoodsData($id);
  57. }
  58. util::sendJson($return);
  59. }
  60. }