You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.0 KiB
54 lines
2.0 KiB
<?php
|
|
|
|
namespace App\Service\v3\Implementations;
|
|
use App\Service\v3\Interfaces\CollectStoreServiceInterface;
|
|
use App\Constants\v3\SsdbKeys;
|
|
use App\TaskWorker\SSDBTask;
|
|
use Hyperf\Utils\ApplicationContext;
|
|
|
|
class CollectStoreService implements CollectStoreServiceInterface
|
|
{
|
|
public function do($userId,$storeId)
|
|
{
|
|
$ssdb = ApplicationContext::getContainer()->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;
|
|
}
|
|
}
|