MGoodsGroups.Class.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Gss
  5. * Date: 2021/4/15 0015
  6. * Time: 14:48
  7. */
  8. namespace JinDouYun\Model\Goods;
  9. use Mall\Framework\Core\ErrorCode;
  10. use Mall\Framework\Core\StatusCode;
  11. use Mall\Framework\Core\ResultWrapper;
  12. use JinDouYun\Dao\Goods\DGoodsGroups;
  13. class MGoodsGroups
  14. {
  15. private $objDGoodsGroups;
  16. private $userCenterId;
  17. private $enterpriseId;
  18. public function __construct($enterpriseId, $userCenterId = false)
  19. {
  20. $this->enterpriseId = $enterpriseId;
  21. $this->userCenterId = $userCenterId;
  22. $this->objDGoodsGroups = new DGoodsGroups();
  23. $this->objDGoodsGroups->setTable('qianniao_goods_groups_'.$enterpriseId);
  24. }
  25. /**
  26. * 商品分组添加
  27. * @param $params
  28. * @return ResultWrapper
  29. * @throws Exception
  30. */
  31. public function addGoodsGroups($params)
  32. {
  33. $dbResult = $this->objDGoodsGroups->insert($params);
  34. if($dbResult === false){
  35. return ResultWrapper::fail($this->objDGoodsGroups->error(), ErrorCode::$dberror);
  36. }
  37. return ResultWrapper::success($dbResult);
  38. }
  39. /**
  40. * 商品分组修改
  41. * @param $update
  42. * @param $where
  43. * @return ResultWrapper
  44. */
  45. public function updateGoodsGroups($update, $where)
  46. {
  47. $update['updateTime'] = time();
  48. $dbResult = $this->objDGoodsGroups->update($update,$where);
  49. if($dbResult === false){
  50. return ResultWrapper::fail($this->objDGoodsGroups->error(), ErrorCode::$dberror);
  51. }
  52. return ResultWrapper::success($dbResult);
  53. }
  54. /**
  55. * 商品分组列表
  56. * @param $selectParams
  57. * @return ResultWrapper
  58. */
  59. public function getAllGoodsGroups($selectParams)
  60. {
  61. $limit = $selectParams['limit'];
  62. unset($selectParams['limit']);
  63. $offset = $selectParams['offset'];
  64. unset($selectParams['offset']);
  65. $return = [
  66. 'data' => [],
  67. 'total' => 0,
  68. ];
  69. $whereSql = '';
  70. if (isset($selectParams['name']) && !empty($selectParams['name'])) {
  71. $where = empty($whereSql) ? ' WHERE ' : ' AND ';
  72. $whereSql .= $where . 'name LIKE "%' . $selectParams['name'] . '%" ';
  73. }
  74. $where = empty($whereSql) ? ' WHERE ' : ' AND ';
  75. $whereSql .= $where . ' deleteStatus = ' . StatusCode::$standard;
  76. $sql = 'SELECT * FROM ' .$this->objDGoodsGroups->get_Table().$whereSql . ' ORDER BY sort DESC,updateTime DESC LIMIT ' . $offset . ' , ' . $limit;
  77. $dbResult = $this->objDGoodsGroups->query($sql);
  78. if ($dbResult === false) {
  79. return ResultWrapper::fail($this->objDGoodsGroups->error(), ErrorCode::$dberror);
  80. }
  81. if(empty($dbResult)){
  82. return ResultWrapper::success($return);
  83. }
  84. $totalSql = 'SELECT COUNT(1) as count FROM ' .$this->objDGoodsGroups->get_Table() . $whereSql;
  85. $dbTotalResult = $this->objDGoodsGroups->query($totalSql);
  86. if ($dbTotalResult === false) {
  87. return ResultWrapper::fail($this->objDGoodsGroups->error(), ErrorCode::$dberror);
  88. }
  89. if(empty($dbTotalResult)){
  90. return ResultWrapper::success([]);
  91. }
  92. $return = [
  93. 'data' => $dbResult,
  94. 'total' => $dbTotalResult[0]['count'],
  95. ];
  96. return ResultWrapper::success($return);
  97. }
  98. /**
  99. * 商品分组详情
  100. * @param $where
  101. * @return ResultWrapper
  102. */
  103. public function getReservoirInfo($where)
  104. {
  105. $dbResult = $this->objDGoodsGroups->get($where);
  106. if($dbResult === false){
  107. return ResultWrapper::fail($this->objDGoodsGroups->error(), ErrorCode::$dberror);
  108. }
  109. return ResultWrapper::success($dbResult);
  110. }
  111. }