CashierGoods.Class.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace JInDouYun\Controller\Cashier;
  3. use JinDouYun\Controller\BaseController;
  4. use JinDouYun\Model\Goods\MGoods;
  5. use Mall\Framework\Core\ErrorCode;
  6. /**
  7. * Description:
  8. * Class CashierGoods
  9. * @package JInDouYun\Controller\Cashier
  10. */
  11. class CashierGoods extends BaseController
  12. {
  13. public function __construct($isCheckAcl = false, $isMustLogin = false, $checkToken = true, $getAreaCode = false)
  14. {
  15. parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode);
  16. }
  17. /**
  18. * Doc: (des="")
  19. * User: XMing
  20. * Date: 2020/9/7
  21. * Time: 9:27 上午
  22. * @throws \Exception
  23. */
  24. public function getGoodsByCategory()
  25. {
  26. $params = $this->request->getRawJson();
  27. if( empty($params) ){
  28. $this->sendOutput('参数为空', ErrorCode::$paramError );
  29. }
  30. $selectParams = [
  31. 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '',
  32. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
  33. 'areaCode'=> '',
  34. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  35. ];
  36. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  37. $selectParams['limit'] = $pageParams['limit'];
  38. $selectParams['offset'] = $pageParams['offset'];
  39. if (isset($params['userCenterId']) && !empty($params['userCenterId'])){
  40. $objMGoods = new MGoods($this->onlineEnterpriseId,true,$params['userCenterId']);
  41. }else{
  42. $objMGoods = new MGoods($this->onlineEnterpriseId,true,$this->onlineUserId);
  43. }
  44. $selectParams['userCenterId'] = isset($params['userCenterId']) ? $params['userCenterId'] : $this->onlineUserId;
  45. $result = $objMGoods->search($selectParams);
  46. if($result->isSuccess()){
  47. $returnData = $result->getData();
  48. $pageData = [
  49. 'pageIndex' => $params['page'],
  50. 'pageSize' => $params['pageSize'],
  51. 'pageTotal' => $returnData['total'],
  52. ];
  53. parent::sendOutput($returnData['data'], 0, $pageData);
  54. }
  55. parent::sendOutput($result->getData(), $result->getErrorCode());
  56. }
  57. /**
  58. * Doc: (des="")
  59. * User: XMing
  60. * Date: 2020/9/30
  61. * Time: 3:08 下午
  62. * @throws \Exception
  63. */
  64. public function getGoodsByBarCode()
  65. {
  66. $userCenterId = $this->request->param('userCenterId');
  67. if (!empty($userCenterId)){
  68. $objMGoods = new MGoods($this->onlineEnterpriseId,true,$userCenterId);
  69. }else{
  70. $objMGoods = new MGoods($this->onlineEnterpriseId,true,$this->onlineUserId);
  71. }
  72. $params = $this->request->getRawJson();
  73. if (empty($params['barCode'])) {
  74. $this->sendOutput('barCode参数为空', ErrorCode::$paramError);
  75. }
  76. $result = $objMGoods->getGoodsByBarCode($params['barCode']);
  77. if (!$result->isSuccess()) {
  78. parent::sendOutput($result->getData(), $result->getErrorCode());
  79. }
  80. parent::sendOutput($result->getData());
  81. }
  82. /**
  83. * Doc: (des="")
  84. * User: XMing
  85. * Date: 2020/9/7
  86. * Time: 9:44 上午
  87. * @throws \Exception
  88. */
  89. public function getGoodsDetail()
  90. {
  91. $goodsId = $this->request->param('request_id');
  92. $userCenterId = $this->request->param('userCenterId');
  93. if ( !$goodsId ) {
  94. self::sendOutput('参数错误', ErrorCode::$paramError );
  95. }
  96. if (!empty($userCenterId)){
  97. $objMGoods = new MGoods($this->onlineEnterpriseId,true,$userCenterId);
  98. }else{
  99. $objMGoods = new MGoods($this->onlineEnterpriseId,true,$this->onlineUserId);
  100. }
  101. $result = $objMGoods->getApiGoodsInfo($goodsId, '');
  102. if($result->isSuccess()){
  103. $resultData = $result->getData();
  104. self::sendOutput($resultData);
  105. }
  106. self::sendOutput($result->getData(), $result->getErrorCode());
  107. }
  108. }