CategoryController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. $where = [];
  46. $get = Yii::$app->request->get();
  47. $categoryId = isset($get['categoryId']) ? intval($get['categoryId']) : 0;
  48. if ($categoryId != 0) {
  49. $where['cId'] = $categoryId;
  50. }
  51. $where['mainId'] = $this->mainId;
  52. $where['delStatus'] = 0;//只获取非删除状态
  53. $where['status'] = 1;//上下架状态为1(正常)
  54. $searchText = $get['searchText'] ?? '';
  55. if (!empty($searchText)) {
  56. $where['name'] = ['like', $searchText];
  57. }
  58. $shop = $this->shop;
  59. $stockModel = $shop->stockModel ?? 0;
  60. if ($stockModel == 1) {
  61. //管到支的,查看所有上架并且花材数量设置好的商品
  62. //$where['setItemNum'] = 1;
  63. }
  64. $data = GoodsCategoryService::getGoodsList($where);
  65. util::success($data);
  66. }
  67. }