diff --git a/crmeb/app/adminapi/controller/v1/setting/SystemRole.php b/crmeb/app/adminapi/controller/v1/setting/SystemRole.php index 3797abf38..533eebbea 100644 --- a/crmeb/app/adminapi/controller/v1/setting/SystemRole.php +++ b/crmeb/app/adminapi/controller/v1/setting/SystemRole.php @@ -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); diff --git a/crmeb/app/api/controller/v1/user/UserAddressController.php b/crmeb/app/api/controller/v1/user/UserAddressController.php index c042499ac..699ef7113 100644 --- a/crmeb/app/api/controller/v1/user/UserAddressController.php +++ b/crmeb/app/api/controller/v1/user/UserAddressController.php @@ -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)); } diff --git a/crmeb/app/api/controller/v2/user/UserInvoiceController.php b/crmeb/app/api/controller/v2/user/UserInvoiceController.php index af8bd37f9..8078132b3 100644 --- a/crmeb/app/api/controller/v2/user/UserInvoiceController.php +++ b/crmeb/app/api/controller/v2/user/UserInvoiceController.php @@ -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)); } diff --git a/crmeb/app/dao/service/StoreServiceDao.php b/crmeb/app/dao/service/StoreServiceDao.php index b628718d0..8c87e417f 100644 --- a/crmeb/app/dao/service/StoreServiceDao.php +++ b/crmeb/app/dao/service/StoreServiceDao.php @@ -25,7 +25,7 @@ class StoreServiceDao extends BaseDao /** * 不存在的用户直接禁止掉 * @param array $uids - * @return bool + * @return bool|\crmeb\basic\BaseModel */ public function deleteNonExistentService(array $uids = []) { diff --git a/crmeb/app/services/message/SystemNotificationServices.php b/crmeb/app/services/message/SystemNotificationServices.php index 8f5e66ca0..710afb40c 100644 --- a/crmeb/app/services/message/SystemNotificationServices.php +++ b/crmeb/app/services/message/SystemNotificationServices.php @@ -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; /** diff --git a/crmeb/app/services/order/StoreOrderCreateServices.php b/crmeb/app/services/order/StoreOrderCreateServices.php index db2782720..c24fbbdde 100644 --- a/crmeb/app/services/order/StoreOrderCreateServices.php +++ b/crmeb/app/services/order/StoreOrderCreateServices.php @@ -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; } diff --git a/crmeb/app/services/order/StoreOrderServices.php b/crmeb/app/services/order/StoreOrderServices.php index 4f072dc54..3c7f63694 100644 --- a/crmeb/app/services/order/StoreOrderServices.php +++ b/crmeb/app/services/order/StoreOrderServices.php @@ -1713,7 +1713,7 @@ HTML; /** * 修改支付方式为线下支付 * @param string $orderId - * @return bool + * @return bool|\crmeb\basic\BaseModel */ public function setOrderTypePayOffline(string $orderId) { diff --git a/crmeb/app/services/product/product/StoreProductServices.php b/crmeb/app/services/product/product/StoreProductServices.php index 0409c9e7a..be5c066bb 100644 --- a/crmeb/app/services/product/product/StoreProductServices.php +++ b/crmeb/app/services/product/product/StoreProductServices.php @@ -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); } /** diff --git a/crmeb/app/services/system/admin/SystemAdminServices.php b/crmeb/app/services/system/admin/SystemAdminServices.php index 5c970dac7..7b6d554a1 100644 --- a/crmeb/app/services/system/admin/SystemAdminServices.php +++ b/crmeb/app/services/system/admin/SystemAdminServices.php @@ -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; diff --git a/crmeb/app/services/system/admin/SystemRoleServices.php b/crmeb/app/services/system/admin/SystemRoleServices.php index f6575b95c..f455b906d 100644 --- a/crmeb/app/services/system/admin/SystemRoleServices.php +++ b/crmeb/app/services/system/admin/SystemRoleServices.php @@ -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'); diff --git a/crmeb/app/services/user/UserBillServices.php b/crmeb/app/services/user/UserBillServices.php index 6fca001ea..2b7204f20 100644 --- a/crmeb/app/services/user/UserBillServices.php +++ b/crmeb/app/services/user/UserBillServices.php @@ -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); } diff --git a/crmeb/crmeb/services/CacheService.php b/crmeb/crmeb/services/CacheService.php index cf85c6cd8..6af6bf8a0 100644 --- a/crmeb/crmeb/services/CacheService.php +++ b/crmeb/crmeb/services/CacheService.php @@ -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'); + } } } diff --git a/crmeb/crmeb/services/upload/storage/Local.php b/crmeb/crmeb/services/upload/storage/Local.php index c917f59cb..48b90125b 100644 --- a/crmeb/crmeb/services/upload/storage/Local.php +++ b/crmeb/crmeb/services/upload/storage/Local.php @@ -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();