mirror of
https://github.com/crmeb/CRMEB.git
synced 2025-12-11 01:52:49 +00:00
【程序目录】更新缓存问题
This commit is contained in:
parent
fa91f801b0
commit
bac01f8317
@ -14,6 +14,7 @@ use app\adminapi\controller\AuthController;
|
||||
use app\services\system\admin\SystemAdminServices;
|
||||
use app\services\system\admin\SystemRoleServices;
|
||||
use app\services\system\SystemMenusServices;
|
||||
use crmeb\services\CacheService;
|
||||
use think\facade\App;
|
||||
|
||||
/**
|
||||
@ -79,12 +80,12 @@ class SystemRole extends AuthController
|
||||
$data['rules'] = implode(',', $data['rules']);
|
||||
if ($id) {
|
||||
if (!$this->services->update($id, $data)) return app('json')->fail(100007);
|
||||
\think\facade\Cache::clear();
|
||||
CacheService::clear();
|
||||
return app('json')->success(100001);
|
||||
} else {
|
||||
$data['level'] = $this->adminInfo['level'] + 1;
|
||||
if (!$this->services->save($data)) return app('json')->fail(400223);
|
||||
\think\facade\Cache::clear();
|
||||
CacheService::clear();
|
||||
return app('json')->success(400222);
|
||||
}
|
||||
}
|
||||
@ -122,7 +123,7 @@ class SystemRole extends AuthController
|
||||
if (!$this->services->delete($id))
|
||||
return app('json')->fail(100008);
|
||||
else {
|
||||
\think\facade\Cache::clear();
|
||||
CacheService::clear();
|
||||
return app('json')->success(100002);
|
||||
}
|
||||
}
|
||||
@ -144,7 +145,7 @@ class SystemRole extends AuthController
|
||||
}
|
||||
$role->status = $status;
|
||||
if ($role->save()) {
|
||||
\think\facade\Cache::clear();
|
||||
CacheService::clear();
|
||||
return app('json')->success(100001);
|
||||
} else {
|
||||
return app('json')->fail(100007);
|
||||
|
||||
@ -40,7 +40,7 @@ class UserAddressController
|
||||
public function address(Request $request, $id)
|
||||
{
|
||||
if (!$id) {
|
||||
app('json')->fail(100100);
|
||||
return app('json')->fail(100100);
|
||||
}
|
||||
return app('json')->success($this->services->address((int)$id));
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ class UserInvoiceController
|
||||
public function invoice($id)
|
||||
{
|
||||
if (!$id) {
|
||||
app('json')->fail(100100);
|
||||
return app('json')->fail(100100);
|
||||
}
|
||||
return app('json')->success($this->services->getInvoice((int)$id));
|
||||
}
|
||||
|
||||
@ -797,7 +797,7 @@ class StoreOrderDao extends BaseDao
|
||||
*/
|
||||
public function getOrderListByWhere(array $where, $field = "*")
|
||||
{
|
||||
return $this->search($where)->field()->select($field)->toArray();
|
||||
return $this->search($where)->field($field)->select()->toArray();
|
||||
}
|
||||
|
||||
/**批量修改订单
|
||||
|
||||
@ -25,7 +25,7 @@ class StoreServiceDao extends BaseDao
|
||||
/**
|
||||
* 不存在的用户直接禁止掉
|
||||
* @param array $uids
|
||||
* @return bool
|
||||
* @return bool|\crmeb\basic\BaseModel
|
||||
*/
|
||||
public function deleteNonExistentService(array $uids = [])
|
||||
{
|
||||
|
||||
@ -14,10 +14,6 @@ namespace app\services\message;
|
||||
|
||||
use app\dao\system\SystemNotificationDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\serve\ServeServices;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\template\Template;
|
||||
use think\facade\Cache;
|
||||
use crmeb\exceptions\AdminException;
|
||||
|
||||
/**
|
||||
|
||||
@ -35,6 +35,7 @@ use app\services\system\store\SystemStoreServices;
|
||||
use app\services\activity\combination\StoreCombinationServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Config;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
@ -61,17 +62,28 @@ class StoreOrderCreateServices extends BaseServices
|
||||
public function getNewOrderId(string $prefix = 'wx')
|
||||
{
|
||||
$snowflake = new \Godruoyi\Snowflake\Snowflake();
|
||||
$is_callable = function ($currentTime) {
|
||||
$redis = Cache::store('redis');
|
||||
$swooleSequenceResolver = new \Godruoyi\Snowflake\RedisSequenceResolver($redis->handler());
|
||||
return $swooleSequenceResolver->sequence($currentTime);
|
||||
};
|
||||
//32位
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$id = abs($snowflake->setSequenceResolver($is_callable)->id());
|
||||
|
||||
if (Config::get('cache.default') == 'file') {
|
||||
//32位
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$id = abs($snowflake->id());
|
||||
} else {
|
||||
$id = $snowflake->setStartTimeStamp(time() * 1000)->id();
|
||||
}
|
||||
} else {
|
||||
$id = $snowflake->setStartTimeStamp(strtotime('2020-06-05') * 1000)->setSequenceResolver($is_callable)->id();
|
||||
$is_callable = function ($currentTime) {
|
||||
$redis = Cache::store('redis');
|
||||
$swooleSequenceResolver = new \Godruoyi\Snowflake\RedisSequenceResolver($redis->handler());
|
||||
return $swooleSequenceResolver->sequence($currentTime);
|
||||
};
|
||||
//32位
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
$id = abs($snowflake->setSequenceResolver($is_callable)->id());
|
||||
} else {
|
||||
$id = $snowflake->setStartTimeStamp(time() * 1000)->setSequenceResolver($is_callable)->id();
|
||||
}
|
||||
}
|
||||
|
||||
return $prefix . $id;
|
||||
}
|
||||
|
||||
|
||||
@ -1713,7 +1713,7 @@ HTML;
|
||||
/**
|
||||
* 修改支付方式为线下支付
|
||||
* @param string $orderId
|
||||
* @return bool
|
||||
* @return bool|\crmeb\basic\BaseModel
|
||||
*/
|
||||
public function setOrderTypePayOffline(string $orderId)
|
||||
{
|
||||
|
||||
@ -1600,12 +1600,19 @@ class StoreProductServices extends BaseServices
|
||||
|
||||
/**
|
||||
* 商品是否存在
|
||||
* @param $productId
|
||||
* @return bool
|
||||
* @param int $productId
|
||||
* @param string $field
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 吴汐
|
||||
* @email 442384644@qq.com
|
||||
* @date 2023/02/15
|
||||
*/
|
||||
public function isValidProduct(int $productId)
|
||||
public function isValidProduct(int $productId, string $field = '*')
|
||||
{
|
||||
return $this->dao->getOne(['id' => $productId, 'is_del' => 0, 'is_show' => 1]);
|
||||
return $this->dao->getOne(['id' => $productId, 'is_del' => 0, 'is_show' => 1], $field);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -265,7 +265,7 @@ class SystemAdminServices extends BaseServices
|
||||
|
||||
return $this->transaction(function () use ($data) {
|
||||
if ($this->dao->save($data)) {
|
||||
\think\facade\Cache::clear();
|
||||
CacheService::clear();
|
||||
return true;
|
||||
} else {
|
||||
throw new AdminException(100022);
|
||||
@ -329,7 +329,7 @@ class SystemAdminServices extends BaseServices
|
||||
$adminInfo->account = $data['account'] ?? $adminInfo->account;
|
||||
$adminInfo->status = $data['status'];
|
||||
if ($adminInfo->save()) {
|
||||
\think\facade\Cache::clear();
|
||||
CacheService::clear();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@ -105,7 +105,7 @@ class SystemRoleServices extends BaseServices
|
||||
}
|
||||
|
||||
// 获取所有接口类型以及对应的接口
|
||||
$allAuth = Cache::get('all_auth', function () {
|
||||
$allAuth = $this->cacheDriver()->remember('all_auth', function () {
|
||||
/** @var SystemMenusServices $menusService */
|
||||
$menusService = app()->make(SystemMenusServices::class);
|
||||
$allList = $menusService->getColumn([['api_url', '<>', ''], ['auth_type', '=', 2]], 'api_url,methods');
|
||||
@ -140,7 +140,7 @@ class SystemRoleServices extends BaseServices
|
||||
{
|
||||
if (empty($rules)) return [];
|
||||
$cacheName = md5($cachePrefix . '_' . $type . '_' . implode('_', $rules));
|
||||
return Cache::get($cacheName, function () use ($rules, $type) {
|
||||
return $this->cacheDriver()->remember($cacheName, function () use ($rules, $type) {
|
||||
/** @var SystemMenusServices $menusService */
|
||||
$menusService = app()->make(SystemMenusServices::class);
|
||||
$authList = $menusService->getColumn([['id', 'IN', $this->getRoleIds($rules)], ['auth_type', '=', $type]], 'api_url,methods');
|
||||
|
||||
@ -692,7 +692,7 @@ class UserBillServices extends BaseServices
|
||||
$where = [];
|
||||
$where['not_type'] = ['gain', 'system_sub', 'deduction', 'sign'];
|
||||
$where['not_category'] = ['exp', 'integral'];
|
||||
return Cache::get('user_type_list', function () use ($where) {
|
||||
return $this->cacheDriver()->remember('user_type_list', function () use ($where) {
|
||||
return ['list' => $this->getBillType($where)];
|
||||
}, 600);
|
||||
}
|
||||
|
||||
@ -14,7 +14,6 @@ namespace crmeb\services;
|
||||
use think\cache\Driver;
|
||||
use think\cache\TagSet;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Cache as CacheStatic;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
@ -246,47 +245,33 @@ class CacheService
|
||||
|
||||
/**
|
||||
* 检查锁
|
||||
* @param int $uid
|
||||
* @param string $key
|
||||
* @param int $timeout
|
||||
* @return bool
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2022/11/22
|
||||
*/
|
||||
public static function setMutex(string $key, int $timeout = 10)
|
||||
public static function setMutex(string $key, int $timeout = 10): bool
|
||||
{
|
||||
$curTime = time();
|
||||
$readMutexKey = "redis:mutex:{$key}";
|
||||
$mutexRes = self::redisHandler()->handler()->setnx($readMutexKey, $curTime + $timeout);
|
||||
$mutexRes = Cache::store('redis')->handler()->setnx($readMutexKey, $curTime + $timeout);
|
||||
if ($mutexRes) {
|
||||
return true;
|
||||
}
|
||||
//就算意外退出,下次进来也会检查key,防止死锁
|
||||
$time = self::redisHandler()->handler()->get($readMutexKey);
|
||||
$time = Cache::store('redis')->handler()->get($readMutexKey);
|
||||
if ($curTime > $time) {
|
||||
self::redisHandler()->handler()->del($readMutexKey);
|
||||
return self::redisHandler()->handler()->setnx($readMutexKey, $curTime + $timeout);
|
||||
Cache::store('redis')->handler()->del($readMutexKey);
|
||||
return Cache::store('redis')->handler()->setnx($readMutexKey, $curTime + $timeout);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redis缓存句柄
|
||||
*
|
||||
* @return Driver|TagSet
|
||||
*/
|
||||
public static function redisHandler($type = null)
|
||||
{
|
||||
if ($type) {
|
||||
return CacheStatic::store('redis')->tag($type);
|
||||
} else {
|
||||
return CacheStatic::store('redis');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除锁
|
||||
* @param $uid
|
||||
* @param string $key
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2022/11/22
|
||||
@ -294,6 +279,23 @@ class CacheService
|
||||
public static function delMutex(string $key)
|
||||
{
|
||||
$readMutexKey = "redis:mutex:{$key}";
|
||||
self::redisHandler()->handler()->del($readMutexKey);
|
||||
Cache::store('redis')->handler()->del($readMutexKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redis缓存句柄
|
||||
* @param null $type
|
||||
* @return mixed
|
||||
* @author 吴汐
|
||||
* @email 442384644@qq.com
|
||||
* @date 2023/02/10
|
||||
*/
|
||||
public static function redisHandler($type = null)
|
||||
{
|
||||
if ($type) {
|
||||
return Cache::store('redis')->tag($type);
|
||||
} else {
|
||||
return Cache::store('redis');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,11 +150,11 @@ class Local extends BaseUpload
|
||||
|
||||
/**
|
||||
* 文件流上传
|
||||
* @param $fileContent
|
||||
* @param string $fileContent
|
||||
* @param string|null $key
|
||||
* @return array|bool|mixed|\StdClass
|
||||
*/
|
||||
public function stream($fileContent, string $key = null)
|
||||
public function stream(string $fileContent, string $key = null)
|
||||
{
|
||||
if (!$key) {
|
||||
$key = $this->saveFileName();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user