Merge pull request 'feat: 修改商品与库存逻辑,优化库存检查与错误处理,增强代码安全性' (#131) from dev into main
Reviewed-on: #131
This commit is contained in:
commit
a427cd50fd
@ -8,7 +8,7 @@ use app\api\controller\BaseApiController;
|
|||||||
use app\api\lists\order\CartList;
|
use app\api\lists\order\CartList;
|
||||||
use app\common\model\order\Cart;
|
use app\common\model\order\Cart;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
|
use app\common\model\store_product_unit\StoreProductUnit;
|
||||||
|
|
||||||
class CartController extends BaseApiController
|
class CartController extends BaseApiController
|
||||||
{
|
{
|
||||||
@ -27,14 +27,26 @@ class CartController extends BaseApiController
|
|||||||
$result = Cart::where(['uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0, 'delete_time' => null])->find();
|
$result = Cart::where(['uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0, 'delete_time' => null])->find();
|
||||||
|
|
||||||
//判断起批发价
|
//判断起批发价
|
||||||
$batch = StoreBranchProduct::where(
|
$branchProduct = StoreBranchProduct::where(
|
||||||
['product_id'=>$params['product_id'],
|
[
|
||||||
|
'product_id' => $params['product_id'],
|
||||||
'store_id' => $params['store_id']
|
'store_id' => $params['store_id']
|
||||||
]
|
]
|
||||||
)->value('batch');
|
)->find();
|
||||||
if($params['cart_num'] < $batch){
|
if (!$branchProduct) {
|
||||||
return $this->fail('起批发量低于最低值'.$batch);
|
return $this->fail('商品不存在');
|
||||||
}
|
}
|
||||||
|
if ($params['cart_num'] < $branchProduct['batch']) {
|
||||||
|
return $this->fail('起批发量低于最低值' . $branchProduct['batch']);
|
||||||
|
}
|
||||||
|
if ($params['cart_num']<1) {
|
||||||
|
$is_bulk = StoreProductUnit::where('id', $branchProduct['unit'])->value('is_bulk');
|
||||||
|
if ($is_bulk == 0) {
|
||||||
|
return $this->fail('非计量商品,不能有小数');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//数量下单判断
|
||||||
$count = Cart::where(['uid' => $params['uid'], 'delete_time' => null, 'is_pay' => 0])->count();
|
$count = Cart::where(['uid' => $params['uid'], 'delete_time' => null, 'is_pay' => 0])->count();
|
||||||
if ($count > 100) {
|
if ($count > 100) {
|
||||||
return $this->fail('购物车商品不能大于100个,请先结算');
|
return $this->fail('购物车商品不能大于100个,请先结算');
|
||||||
@ -92,6 +104,4 @@ class CartController extends BaseApiController
|
|||||||
return $this->fail(CartLogic::getError());
|
return $this->fail(CartLogic::getError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface
|
|||||||
$v['image'] = '';
|
$v['image'] = '';
|
||||||
$v['price'] = '';
|
$v['price'] = '';
|
||||||
$v['unit_name']='';
|
$v['unit_name']='';
|
||||||
|
$v['cart_num']=floatval($v['cart_num']);
|
||||||
if(isset($v['cart_info'])){
|
if(isset($v['cart_info'])){
|
||||||
// foreach( $v['cart_info'] as $k=>$vv){
|
// foreach( $v['cart_info'] as $k=>$vv){
|
||||||
$v['store_name'] =$v['cart_info']['name'];
|
$v['store_name'] =$v['cart_info']['name'];
|
||||||
|
@ -90,6 +90,13 @@ class OrderLogic extends BaseLogic
|
|||||||
self::setError('商品不存在');
|
self::setError('商品不存在');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (convertNumber($v['cart_num'])==false) {
|
||||||
|
$is_bulk = StoreProductUnit::where('id', $find['unit'])->value('is_bulk');
|
||||||
|
if ($is_bulk == 0) {
|
||||||
|
self::setError('非计量商品,不能有小数,请编辑购物车');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
$StoreCategory=StoreCategory::where('id',$find['cate_id'])->find();
|
$StoreCategory=StoreCategory::where('id',$find['cate_id'])->find();
|
||||||
$find['top_cate_id']=$find['cate_id'];
|
$find['top_cate_id']=$find['cate_id'];
|
||||||
if($StoreCategory && $StoreCategory['pid']>0){
|
if($StoreCategory && $StoreCategory['pid']>0){
|
||||||
@ -527,6 +534,7 @@ class OrderLogic extends BaseLogic
|
|||||||
$find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find();
|
$find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find();
|
||||||
}
|
}
|
||||||
$item['store_name'] = $find['store_name'];
|
$item['store_name'] = $find['store_name'];
|
||||||
|
$item['nums'] = floatval($item['nums']);
|
||||||
$item['image'] = $find['image'];
|
$item['image'] = $find['image'];
|
||||||
$item['price'] = $find['price'];
|
$item['price'] = $find['price'];
|
||||||
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? '';
|
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? '';
|
||||||
|
@ -480,10 +480,23 @@ if (!function_exists('countRate')) {
|
|||||||
|
|
||||||
if (!function_exists('payPassword')) {
|
if (!function_exists('payPassword')) {
|
||||||
//支付密码
|
//支付密码
|
||||||
function payPassword($password){
|
function payPassword($password)
|
||||||
|
{
|
||||||
return password_hash($password, PASSWORD_BCRYPT);
|
return password_hash($password, PASSWORD_BCRYPT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!function_exists('convertNumber')) {
|
||||||
|
|
||||||
|
function convertNumber($str)
|
||||||
|
{
|
||||||
|
// 将字符串转换为浮点数
|
||||||
|
$number = (float)$str;
|
||||||
|
// 将字符串转换为整数
|
||||||
|
$int = (int)$str;
|
||||||
|
if ($number == $int) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user