get(SSDBTask::class); //收藏店铺 $userSet = $ssdb->exec('set', SsdbKeys::COLLECT_STORE_USER.$userId.'_store_'.$storeId,time()); //用户收藏数量自增 $userIncr = $ssdb->exec('incr', SsdbKeys::COLLECT_STORE_NUM_USER.$userId,1); //店铺被收藏数自增 $storeIncr = $ssdb->exec('incr', SsdbKeys::COLLECT_NUM_STORE.$storeId,1); return $userSet && $userIncr && $storeIncr; } public function check($userId,$storeId) { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); return $ssdb->exec('exists', SsdbKeys::COLLECT_STORE_USER.$userId.'_store_'.$storeId); } public function undo($userId,$storeId) { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); //取消收藏店铺 $userDel = $ssdb->exec('del', SsdbKeys::COLLECT_STORE_USER.$userId.'_store_'.$storeId,time()); //用户收藏数量自减 $userIncr = $ssdb->exec('incr', SsdbKeys::COLLECT_STORE_NUM_USER.$userId,'-1'); //店铺被收藏数自减 $storeIncr = $ssdb->exec('incr', SsdbKeys::COLLECT_NUM_STORE.$userId,'-1'); return $userDel && $userIncr && $storeIncr; } public function countByUser($userId) { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $num = $ssdb->exec('get',SsdbKeys::COLLECT_STORE_NUM_USER.$userId); return $num; } public function countByStore($storeId) { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $num = $ssdb->exec('get',SsdbKeys::COLLECT_NUM_STORE.$storeId); return $num; } }