CategoryController.php 2.3 KB

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