enterpriseId = $enterpriseId; $this->userCenterId = $userCenterId; $this->objDMaterialCategory = new DMaterialCategory('default'); $this->objDMaterialContent = new DMaterialContent('default'); $this->objDMaterialContent->setTable($this->objDMaterialContent->get_Table().'_'.$enterpriseId); } /** * 素材内容添加 * @param $params * @return ResultWrapper * @throws Exception */ public function addMaterialContent($params) { $insertData['shopId'] = isset($params['shopId']) ? $params['shopId'] : 0; $insertData['categoryId'] = $params['categoryId']; $insertData['name'] = $params['name']; $insertData['content'] = $params['content']; $insertData['deleteStatus'] = StatusCode::$standard; $insertData['createTime'] = time(); $insertData['updateTime'] = time(); $dbResult = $this->objDMaterialContent->insert($insertData); if($dbResult === false){ return ResultWrapper::fail($this->objDMaterialContent->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 素材分类添加 * @param $params * @return ResultWrapper * @throws Exception */ public function addMaterialCategory($params) { $insertData['shopId'] = isset($params['shopId']) ? $params['shopId'] : 0; $insertData['enterpriseId'] = $this->enterpriseId; $insertData['pid'] = $params['pid']; $insertData['title'] = $params['title']; $insertData['deleteStatus'] = StatusCode::$standard; $insertData['createTime'] = time(); $insertData['updateTime'] = time(); $dbResult = $this->objDMaterialCategory->insert($insertData); if($dbResult === false){ return ResultWrapper::fail($this->objDMaterialCategory->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 素材内容修改 * @param $params * @return ResultWrapper * @throws Exception */ public function updateMaterialContent($params) { $dbResult = $this->objDMaterialContent->update(['categoryId' => $params['categoryId'], 'updateTime' => time()], ['id' => $params['id']]); if($dbResult === false){ return ResultWrapper::fail($this->objDMaterialContent->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 素材分类修改 * @param $params * @return ResultWrapper * @throws Exception */ public function updateMaterialCategory($params) { $where = ['id' => $params['id']]; unset($params['id']); $dbResult = $this->objDMaterialCategory->update($params, $where); if($dbResult === false){ return ResultWrapper::fail($this->objDMaterialCategory->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 素材内容删除 * @param $params * @return ResultWrapper */ public function delMaterialContent($params) { $where = ['id' => $params['id']]; $dbResult = $this->objDMaterialContent->update(['deleteStatus' => StatusCode::$delete,'updateTime' => time(), 'extend' => json_encode(['userCenterId' => $this->userCenterId])], $where); if($dbResult === false){ return ResultWrapper::fail($this->objDMaterialContent->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 素材分类删除 * @param $params * @return ResultWrapper */ public function delMaterialCategory($params) { $where = ['id' => $params['id']]; //判断是否有内容 $dbResult = $this->objDMaterialContent->select(['categoryId' => $where['id'], 'deleteStatus' => StatusCode::$standard]); if($dbResult === false){ return ResultWrapper::fail($this->objDMaterialContent->error(), ErrorCode::$dberror); } if($dbResult){ return ResultWrapper::fail('请先删除分组里内容', ErrorCode::$paramError); } $dbResult = $this->objDMaterialCategory->update(['deleteStatus' => StatusCode::$delete], $where); if($dbResult === false){ return ResultWrapper::fail($this->objDMaterialCategory->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 素材分类列表 * @return ResultWrapper */ public function getAllMaterialCategory($params = []) { $where = [ 'pid' => 0, 'enterpriseId' => $this->enterpriseId, 'deleteStatus' => StatusCode::$standard, 'shopId' => isset($params['shopId']) ? $params['shopId'] : 0, ]; $dbResult = $this->objDMaterialCategory->select($where, '*', 'id desc'); if ($dbResult === false) { return ResultWrapper::fail($this->objDMaterialCategory->error(), ErrorCode::$dberror); } $defaultCategory = [ 'id' => 0, 'enterpriseId' => $this->enterpriseId, 'pid' => 0, 'title' => '默认分组', 'deleteStatus' => StatusCode::$standard, 'createTime' => 0, 'updateTime' => 0, ]; array_unshift($dbResult, $defaultCategory); return ResultWrapper::success($dbResult); } /** * 素材内容列表 * @param $params * @return ResultWrapper */ public function getAllMaterialContent($params) { $limit = $params['limit']; unset($params['limit']); $offset = $params['offset']; unset($params['offset']); $where = ' categoryId = '.$params['categoryId']. ' and deleteStatus = '.StatusCode::$standard; !empty($params['name']) && $where .= " and name like '%".$params['name']."%'"; $where .= ' and shopId = '.(isset($params['shopId']) ? $params['shopId'] : 0); $dbResult = $this->objDMaterialContent->select($where, '*', 'id desc', $limit, $offset); if ($dbResult === false) { return ResultWrapper::fail($this->objDMaterialContent->error(), ErrorCode::$dberror); } $total = $this->objDMaterialContent->count($where); $return = [ 'data' => $dbResult, 'total' => ($total) ? intval($total) : 0, ]; return ResultWrapper::success($return); } }