ApiGoodsCategory.Class.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * 前台分类相关接口
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/11/15
  7. * Time: 17:09
  8. */
  9. namespace JinDouYun\Controller\GoodsCategory;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\GoodsCategory\MGoodsCategory;
  14. class ApiGoodsCategory extends BaseController
  15. {
  16. private $objMGoodsCategory;
  17. /**
  18. * GoodsCategory constructor.
  19. * @param bool $isCheckAcl
  20. * @param bool $isMustLogin
  21. * @throws \Exception
  22. */
  23. public function __construct($isCheckAcl = false, $isMustLogin = false)
  24. {
  25. parent::__construct($isCheckAcl, $isMustLogin);
  26. $this->objMGoodsCategory = new MGoodsCategory($this->onlineUserId, $this->onlineEnterpriseId);
  27. $authorization = $this->request->getServerParam('HTTP_AUTHORIZATION');
  28. if (!empty($authorization)) {
  29. self::getUserIdByAuthorization();
  30. }
  31. }
  32. /**
  33. * 商品分类
  34. */
  35. public function getAllCategory()
  36. {
  37. $params = $this->request->getRawJson();
  38. if($this->onlineUserId){
  39. $data['userCenterId'] = $this->onlineUserId;
  40. }
  41. $data['enableStatus'] = StatusCode::$standard;
  42. $result = $this->objMGoodsCategory->apiGetAllCategory($data);
  43. if ($result->isSuccess()) {
  44. $returnData = $result->getData();
  45. parent::sendOutput($returnData['data'], 0, ['pageTotal'=>count($returnData['data'])]);
  46. } else {
  47. parent::sendOutput($result->getData(), $result->getErrorCode());
  48. }
  49. }
  50. /**
  51. * 获取所有一级分类或一级分类下的二级分类
  52. */
  53. public function getAllCategoryByPid()
  54. {
  55. $params['id'] = $this->request->param('request_id');
  56. $selectParams['pid'] = 0;
  57. if (isset($params['id']) && (int)$params['id']) {
  58. $selectParams['pid'] = (int)$params['id'];
  59. }
  60. $selectParams['deleteStatus'] = StatusCode::$standard;
  61. $result = $this->objMGoodsCategory->getCategoryTitleByIds($selectParams);
  62. if ($result->isSuccess()) {
  63. $returnData = $result->getData();
  64. $pageData = [
  65. 'pageIndex' => 0,
  66. 'pageSize' => 10,
  67. 'pageTotal' => count($returnData),
  68. ];
  69. parent::sendOutput($returnData, 0, $pageData);
  70. } else {
  71. parent::sendOutput($result->getData(), $result->getErrorCode());
  72. }
  73. }
  74. }