Merge pull request 'feat: 优化业务逻辑和异常处理,提升系统安全性和稳定性' (#174) from dev into main

Reviewed-on: https://gitea.lihaink.cn/mkm/multi-store/pulls/174
This commit is contained in:
mkm 2024-08-29 20:18:00 +08:00
commit b3f9ef6dde
3 changed files with 19 additions and 17 deletions

View File

@ -44,11 +44,6 @@ class IndexController extends BaseApiController
public function index()
{
$a=StoreProduct::where('is_show',1)->select();
foreach($a as $k=>$v){
$find=StoreBranchProduct::where('product_id',$v['id'])->find();
StoreProduct::where('id',$v['id'])->update(['top_cate_id'=>$find['top_cate_id'],'two_cate_id'=>$find['two_cate_id'],'cate_id'=>$find['cate_id']]);
}
return json([1]);
}

View File

@ -84,12 +84,19 @@ class CartLogic extends BaseLogic
{
Db::startTrans();
try {
Cart::where([
'uid' => $params['uid'],
'store_id' => $params['store_id'],
'product_id' => $params['product_id']
])
->update(['cart_num' => $params['cart_num']]);
if(isset($params['type']) && $params['type']=='inc'){
Cart::where([
'uid' => $params['uid'],
'store_id' => $params['store_id'],
'product_id' => $params['product_id']
])->inc('cart_num')->update();
}else{
Cart::where([
'uid' => $params['uid'],
'store_id' => $params['store_id'],
'product_id' => $params['product_id']
])->update(['cart_num' => $params['cart_num']]);
}
Db::commit();
return true;
} catch (\Throwable $e) {

View File

@ -10,7 +10,7 @@ use app\common\model\auth\Admin;
use app\common\model\system_store\SystemStoreStaff;
use app\common\service\ConfigService;
use app\common\validate\BaseValidate;
use app\MyBusinessException;
use support\exception\BusinessException;
use Webman\Config;
class LoginValidate extends BaseValidate
@ -55,7 +55,7 @@ class LoginValidate extends BaseValidate
//后台账号安全机制,连续输错后锁定,防止账号密码暴力破解
if ($config['login_restrictions'] == 1 && !$adminAccountSafeCache->isSafe()) {
throw new MyBusinessException('密码连续' . $adminAccountSafeCache->count . '次输入错误,请' . $adminAccountSafeCache->minute . '分钟后重试');
throw new BusinessException('密码连续' . $adminAccountSafeCache->count . '次输入错误,请' . $adminAccountSafeCache->minute . '分钟后重试');
}
$staffInfo = SystemStoreStaff::where('account', '=', $data['account'])
@ -63,21 +63,21 @@ class LoginValidate extends BaseValidate
->findOrEmpty();
if ($staffInfo->isEmpty()) {
return '账号不存在';
throw new BusinessException('账号不存在');
}
if ($staffInfo['disable'] === 1) {
return '账号已禁用';
throw new BusinessException('账号已禁用');
}
if (empty($staffInfo['pwd'])) {
$adminAccountSafeCache->record();
return '账号不存在';
throw new BusinessException('账号不存在');
}
$pwdSalt = Config::get('project.unique_identification');
if ($staffInfo['pwd'] !== create_password($password, $pwdSalt)) {
$adminAccountSafeCache->record();
return '密码错误';
throw new BusinessException('密码错误');
}
$adminAccountSafeCache->relieve();