enterpriseId = $enterpriseId; $this->userCenterId = $userCenterId; $this->objDCommonApp = new DCommonApp('default'); //按照企业分表 $this->objDCommonApp->setTable($this->objDCommonApp->get_Table().'_'.$this->enterpriseId); //引入redis $this->objCacheMan = new CacheMan($this->enterpriseId, $this->userCenterId); } /** * 修改常用应用 * @param $params * @param $where * @return ResultWrapper */ public function updateCommonApp($params, $where) { $dbResult = $this->objDCommonApp->get($where); if($dbResult === false){ return ResultWrapper::fail($this->objDCommonApp->error(), ErrorCode::$dberror); } $commonData = $dbResult; unset($dbResult); if($commonData){ //修改 $updateData = [ 'content' => json_encode($params), 'updateTime' => time(), ]; $dbResult = $this->objDCommonApp->update($updateData, $where); //删除redis $this->objCacheMan->delCacheHash($where['userCenterId'], $this->cacheKey); }else{ //新增 $addCommonData = [ 'userCenterId' => $where['userCenterId'], 'enterpriseId' => $where['enterpriseId'], 'content' => json_encode($params), 'updateTime' => time(), 'createTime' => time(), ]; $dbResult = $this->objDCommonApp->insert($addCommonData); //增加redis $this->objCacheMan->addCacheHash($where['userCenterId'], $addCommonData['content'], $this->cacheKey); } if($dbResult === false){ return ResultWrapper::fail($this->objDCommonApp->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 常用应用详情 * @param $where * @return ResultWrapper */ public function getCommonAppInfo($where) { //获取redis $cacheResult = $this->objCacheMan->getCacheHash($where['userCenterId'], $this->cacheKey); if(!empty($cacheResult)){ return ResultWrapper::success($cacheResult); } $dbResult = $this->objDCommonApp->get($where); if ($dbResult === false) { return ResultWrapper::fail($this->objDCommonApp->error(), ErrorCode::$dberror); } if(empty($dbResult)){ return ResultWrapper::success($dbResult); } $dbResult['content'] = json_decode($dbResult['content'], true); //保存redis if($dbResult){ $this->objCacheMan->addCacheHash($where['userCenterId'], $dbResult['content'], $this->cacheKey); } return ResultWrapper::success($dbResult['content']); } }