GoodsSupport.Class.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: kang
  5. * Date: 2021/3/27
  6. * Time: 12:09
  7. */
  8. namespace JinDouYun\Controller\Goods;
  9. use Mall\Framework\Core\ErrorCode;
  10. use JinDouYun\Controller\BaseController;
  11. use JinDouYun\Model\Goods\MGoodsSupport;
  12. class GoodsSupport extends BaseController
  13. {
  14. private $objMGoodsSupport;
  15. public function __construct($isCheckAcl = true, $isMustLogin = true)
  16. {
  17. parent::__construct($isCheckAcl, $isMustLogin);
  18. $this->objMGoodsSupport = new MGoodsSupport($this->onlineEnterpriseId, $this->onlineUserId);
  19. }
  20. /**
  21. * 添加和编辑商品服务公共字段处理方法
  22. *
  23. * @return array
  24. */
  25. public function commonFieldFilter(){
  26. $params = $this->request->getRawJson();
  27. if( empty($params) ){
  28. $this->sendOutput('参数为空', ErrorCode::$paramError );
  29. }
  30. $goodsData = [
  31. 'enterprise' => $this->onlineEnterpriseId,
  32. 'servicesName' => getArrayItem($params,'servicesName'),
  33. ];
  34. foreach($goodsData as $key => $value){
  35. if(empty($value) && $value !== 0){
  36. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  37. }
  38. }
  39. $goodsData['describe'] = getArrayItem($params,'describe','');
  40. $goodsData['Icon'] = getArrayItem($params,'Icon','');
  41. $goodsData['createTime'] = time();
  42. return $goodsData;
  43. }
  44. /**
  45. * 添加商品服务
  46. */
  47. public function addGoodsSupport()
  48. {
  49. $addGoodsSupportData = $this->commonFieldFilter();
  50. $result = $this->objMGoodsSupport ->addGoodsSupport($addGoodsSupportData);
  51. if($result->isSuccess()){
  52. parent::sendOutput($result->getData());
  53. }else{
  54. parent::sendOutput($result->getData(), $result->getErrorCode());
  55. }
  56. }
  57. /**
  58. * 获取指定商品服务
  59. */
  60. public function getGoodsSupportInfo()
  61. {
  62. $GoodsSupportId = $this->request->param('request_id');
  63. if ( !$GoodsSupportId ) {
  64. $this->sendOutput('参数错误', ErrorCode::$paramError );
  65. }
  66. $result = $this->objMGoodsSupport->getGoodsSupportInfo($GoodsSupportId);
  67. if($result->isSuccess()){
  68. $this->sendOutput($result->getData());
  69. }else{
  70. $this->sendOutput($result->getData(), $result->getErrorCode());
  71. }
  72. }
  73. /**
  74. * 编辑商品服务
  75. */
  76. public function editGoodsSupport()
  77. {
  78. $params = $this->request->getRawJson();
  79. if(empty($params)){
  80. $this->sendOutput('参数错误', ErrorCode::$paramError);
  81. }
  82. $result = $this->objMGoodsSupport->editGoodsSupport($params);
  83. if($result->isSuccess()){
  84. parent::sendOutput($result->getData());
  85. }else{
  86. parent::sendOutput($result->getData(), $result->getErrorCode());
  87. }
  88. }
  89. /**
  90. * 删除商品服务
  91. */
  92. public function delGoodsSupport()
  93. {
  94. $GoodsSupportId = $this->request->param('request_id');
  95. if ( !$GoodsSupportId ) {
  96. $this->sendOutput('参数错误', ErrorCode::$paramError );
  97. }
  98. $result = $this->objMGoodsSupport->delGoodsSupport($GoodsSupportId);
  99. if($result->isSuccess()){
  100. parent::sendOutput($result->getData());
  101. }else{
  102. parent::sendOutput($result->getData(), $result->getErrorCode());
  103. }
  104. }
  105. /**
  106. * 后台所有商品服务
  107. */
  108. public function getAllGoodsSupport()
  109. {
  110. $params = $this->request->getRawJson();
  111. if(empty($params)){
  112. $this->sendOutput('参数错误', ErrorCode::$paramError);
  113. }
  114. $params['servicesName'] = getArrayItem($params,'servicesName','');
  115. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  116. $params['limit'] = $pageParams['limit'];
  117. $params['offset'] = $pageParams['offset'];
  118. $returnData = $this->objMGoodsSupport->getAllGoodsSupport($params);
  119. if ($returnData->isSuccess()) {
  120. $returnData = $returnData->getData();
  121. $pageData = [
  122. 'pageIndex' => $params['page'],
  123. 'pageSize' => $params['pageSize'],
  124. 'pageTotal' => $returnData['total'],
  125. ];
  126. parent::sendOutput($returnData['data'], 0, $pageData);
  127. } else {
  128. parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
  129. }
  130. }
  131. }