CategoryController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace mall\controllers;
  3. use bizHd\custom\classes\CustomClass;
  4. use bizMall\goods\services\CategoryService;
  5. use bizMall\goods\services\GoodsCategoryService;
  6. use Yii;
  7. use common\components\util;
  8. class CategoryController extends BaseController
  9. {
  10. public $guestAccess = ['list']; // 'goods-list' ---- 为什么不用认证
  11. //获取分类 ssh 2019.12.2
  12. public function actionList()
  13. {
  14. $user = $this->user;
  15. if (empty($user)) {
  16. util::success([]);
  17. }
  18. //普莲花艺、叶上花、丰行、小武鲜花、九江云朵、源花汇、紫荆不能在花卉宝下单,多处要同步修改,关键词ls_mall_not_open
  19. $mainId = $this->mainId;
  20. if (getenv('YII_ENV') == 'production') {
  21. if (in_array($mainId, [40057, 7779, 42940, 26374, 10536, 65381])) {
  22. util::fail('暂无商品哦,编号25395');
  23. }
  24. } else {
  25. if (in_array($mainId, [0, 1])) {
  26. util::fail('暂无商品哦!编号639942');
  27. }
  28. }
  29. //建立客户关系
  30. CustomClass::buildRelation($this->shop, $this->user);
  31. $mainId = $this->mainId ?? 0;
  32. $where = ['mainId' => $mainId, 'delStatus' => 0, 'status' => 1];
  33. //默认列出正常分类,美团等第三方分类不列表
  34. $where['style'] = 0;
  35. $return = CategoryService::getAllCategory($where);
  36. util::success($return);
  37. }
  38. //取分类下商品 ssh 2019.12.2
  39. public function actionGoodsList()
  40. {
  41. $user = $this->user;
  42. if (empty($user)) {
  43. util::success(['list' => []]);
  44. }
  45. $categoryId = Yii::$app->request->get('categoryId');
  46. if (empty($categoryId)) {
  47. util::fail('没有找到分类');
  48. }
  49. $where = [];
  50. $where['mainId'] = $this->mainId;
  51. $where['cId'] = $categoryId;
  52. $where['delStatus'] = 0;
  53. $where['status'] = 1;
  54. $shop = $this->shop;
  55. $stockModel = $shop->stockModel ?? 0;
  56. if ($stockModel == 1) {
  57. //管到支的,查看所有上架并且花材数量设置好的商品
  58. //$where['setItemNum'] = 1;
  59. }
  60. $data = GoodsCategoryService::getGoodsList($where);
  61. util::success($data);
  62. }
  63. }