MGoodsSupport.Class.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: kang
  5. * Date: 2021/3/27
  6. * Time: 12:11
  7. */
  8. namespace JinDouYun\Model\Goods;
  9. use JinDouYun\Model\MBaseModel;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use JinDouYun\Dao\Goods\DGoodsSupport;
  14. class MGoodsSupport extends MBaseModel
  15. {
  16. private $objDGoodsSupport;
  17. private $enterpriseId;
  18. private $userCenterId;
  19. public function __construct($enterpriseId, $userCenterId)
  20. {
  21. $this->userCenterId = $userCenterId;
  22. $this->enterpriseId = $enterpriseId;
  23. parent::__construct($enterpriseId, $userCenterId);
  24. $this->objDGoodsSupport = new DGoodsSupport('default');
  25. }
  26. /**
  27. * 添加商品服务
  28. * @param $params
  29. * @return ResultWrapper
  30. * @throws Exception
  31. */
  32. public function addGoodsSupport($addGoodsSupportData)
  33. {
  34. $dbResult = $this->objDGoodsSupport->get(['servicesName' => $addGoodsSupportData['servicesName']]);
  35. if($dbResult === false){
  36. return ResultWrapper::fail($this->objDGoodsSupport->error(), ErrorCode::$dberror);
  37. }
  38. if(!empty($dbResult)){
  39. return ResultWrapper::fail('该商品服务已存在', ErrorCode::$paramError);
  40. }
  41. unset($dbResult);
  42. $addGoodsServiceDataId = $this->objDGoodsSupport->insert($addGoodsSupportData);
  43. if($addGoodsServiceDataId === false){
  44. return ResultWrapper::fail($this->objDGoodsSupport->error(), ErrorCode::$dberror);
  45. }
  46. return ResultWrapper::success($addGoodsServiceDataId);
  47. }
  48. /**
  49. * 获取指定商品服务
  50. */
  51. public function getGoodsSupportInfo($GoodsSupportId)
  52. {
  53. if( empty($GoodsSupportId) ){
  54. return ResultWrapper::fail('接收不到要请求的商品服务', ErrorCode::$paramError);
  55. }
  56. $dbResult = $this->objDGoodsSupport->get($GoodsSupportId);
  57. if($dbResult === false){
  58. return ResultWrapper::fail($this->objDGoodsSupport->error(), ErrorCode::$dberror);
  59. }else{
  60. return ResultWrapper::success($dbResult);
  61. }
  62. }
  63. /**
  64. * 编辑商品服务
  65. *
  66. * @param int|array $params 修改商品服务的数据
  67. *
  68. * @return ResultWrapper
  69. */
  70. public function editGoodsSupport($params)
  71. {
  72. if( empty($params['id']) ){
  73. return ResultWrapper::fail('没有指定要修改的商品服务', ErrorCode::$paramError);
  74. }
  75. $updateGoodsSupportId = $params['id'];
  76. unset($params['id']);
  77. $dbResult = $this->objDGoodsSupport->update($params, $updateGoodsSupportId);
  78. if($dbResult === false){
  79. return ResultWrapper::fail($this->objDGoodsSupport->error(), ErrorCode::$dberror);
  80. }else{
  81. return ResultWrapper::success($dbResult);
  82. }
  83. }
  84. /**
  85. * 删除商品服务
  86. *
  87. * @param array $params 要删除商品服务
  88. *
  89. * @return ResultWrapper
  90. */
  91. public function delGoodsSupport($GoodsSupportId)
  92. {
  93. $updateData = [
  94. 'deleteStatus' => StatusCode::$delete,
  95. ];
  96. $dbResult = $this->objDGoodsSupport->update($updateData, $GoodsSupportId);
  97. if($dbResult === false){
  98. return ResultWrapper::fail($this->objDGoodsSupport->error(), ErrorCode::$dberror);
  99. }else{
  100. return ResultWrapper::success($dbResult);
  101. }
  102. }
  103. /**
  104. * 获取所有商品服务
  105. *
  106. * @param array $selectParams 过滤条件
  107. *
  108. * @return ResultWrapper
  109. */
  110. public function getAllGoodsSupport($selectParams)
  111. {
  112. $limit = $selectParams['limit'];
  113. unset($selectParams['limit']);
  114. $offset = $selectParams['offset'];
  115. unset($selectParams['offset']);
  116. $returnData = [
  117. 'data' => [],
  118. 'total' => 0,
  119. ];
  120. $where = 'deleteStatus = '.StatusCode::$standard .' and enterprise ='.$this->enterpriseId;
  121. if( isset($selectParams['servicesName']) ){
  122. $where .= ' and servicesName like "%'.$selectParams['servicesName'].'%" ';
  123. }
  124. $dbResult = $this->objDGoodsSupport->select($where, '*', 'createTime desc',$limit,$offset);
  125. if($dbResult === false){
  126. return ResultWrapper::fail($this->objDGoodsSupport->error(), ErrorCode::$dberror);
  127. }
  128. if( empty($dbResult) ){
  129. return ResultWrapper::success($returnData);
  130. }
  131. $dbTotalResult = $this->objDGoodsSupport->count($where);
  132. if ($dbTotalResult === false) {
  133. return ResultWrapper::fail($this->objDGoodsSupport->error(), ErrorCode::$dberror);
  134. }
  135. $return = [
  136. 'data' => $dbResult,
  137. 'total' => $dbTotalResult,
  138. ];
  139. return ResultWrapper::success($return);
  140. }
  141. /**
  142. * 获取goods中存储的商品服务数据
  143. */
  144. public function getGoodsSupport($SupportId)
  145. {
  146. if( empty($SupportId) ){
  147. return ResultWrapper::success([]);
  148. }
  149. $sql ='select servicesName,`describe`,Icon FROM qianniao_goods_service WHERE id IN ('.$SupportId.') and deleteStatus ='.StatusCode::$standard;
  150. $dbResult = $this->objDGoodsSupport->query($sql);
  151. if($dbResult === false){
  152. return ResultWrapper::fail($this->objDGoodsSupport->error(), ErrorCode::$dberror);
  153. }else{
  154. return ResultWrapper::success($dbResult);
  155. }
  156. }
  157. }