123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Gss
- * Date: 2021/4/15 0015
- * Time: 14:48
- */
- namespace JinDouYun\Model\Goods;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Dao\Goods\DGoodsGroups;
- class MGoodsGroups
- {
- private $objDGoodsGroups;
- private $userCenterId;
- private $enterpriseId;
- public function __construct($enterpriseId, $userCenterId = false)
- {
- $this->enterpriseId = $enterpriseId;
- $this->userCenterId = $userCenterId;
- $this->objDGoodsGroups = new DGoodsGroups();
- $this->objDGoodsGroups->setTable('qianniao_goods_groups_'.$enterpriseId);
- }
- /**
- * 商品分组添加
- * @param $params
- * @return ResultWrapper
- * @throws Exception
- */
- public function addGoodsGroups($params)
- {
- $dbResult = $this->objDGoodsGroups->insert($params);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDGoodsGroups->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 商品分组修改
- * @param $update
- * @param $where
- * @return ResultWrapper
- */
- public function updateGoodsGroups($update, $where)
- {
- $update['updateTime'] = time();
- $dbResult = $this->objDGoodsGroups->update($update,$where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDGoodsGroups->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 商品分组列表
- * @param $selectParams
- * @return ResultWrapper
- */
- public function getAllGoodsGroups($selectParams)
- {
- $limit = $selectParams['limit'];
- unset($selectParams['limit']);
- $offset = $selectParams['offset'];
- unset($selectParams['offset']);
- $return = [
- 'data' => [],
- 'total' => 0,
- ];
- $whereSql = '';
- if (isset($selectParams['name']) && !empty($selectParams['name'])) {
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . 'name LIKE "%' . $selectParams['name'] . '%" ';
- }
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' deleteStatus = ' . StatusCode::$standard;
- $sql = 'SELECT * FROM ' .$this->objDGoodsGroups->get_Table().$whereSql . ' ORDER BY sort DESC,updateTime DESC LIMIT ' . $offset . ' , ' . $limit;
- $dbResult = $this->objDGoodsGroups->query($sql);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDGoodsGroups->error(), ErrorCode::$dberror);
- }
- if(empty($dbResult)){
- return ResultWrapper::success($return);
- }
- $totalSql = 'SELECT COUNT(1) as count FROM ' .$this->objDGoodsGroups->get_Table() . $whereSql;
- $dbTotalResult = $this->objDGoodsGroups->query($totalSql);
- if ($dbTotalResult === false) {
- return ResultWrapper::fail($this->objDGoodsGroups->error(), ErrorCode::$dberror);
- }
- if(empty($dbTotalResult)){
- return ResultWrapper::success([]);
- }
- $return = [
- 'data' => $dbResult,
- 'total' => $dbTotalResult[0]['count'],
- ];
- return ResultWrapper::success($return);
- }
- /**
- * 商品分组详情
- * @param $where
- * @return ResultWrapper
- */
- public function getReservoirInfo($where)
- {
- $dbResult = $this->objDGoodsGroups->get($where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDGoodsGroups->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- }
|