Commit 56298307 by 杨树贤

修复冲突

parents 1d880627 1b9e07f6
......@@ -21,7 +21,7 @@ class CartApiController extends Controller
{
//添加购物车, items: {"goods_id":1166788996788323407,"goods_number":2}
public function addCart(Request $request)
public function saveCart(Request $request)
{
$validator = Validator::make($request->all(), [
'items' => 'required|string',
......@@ -37,13 +37,13 @@ class CartApiController extends Controller
'data',
]);
$result = CartService::addCart($data, $request->user->id);
$result = CartService::saveCart($data, $request->user->id);
return !$result ? $this->setError('Add cart failed , please contact administrator'):$this->setSuccess('Add inquiry success');
}
//购物车列表
public function cartLists(){
public function cartLists(Request $request){
$result = CartService::cartLists($request->user->id);
}
......
......@@ -14,8 +14,8 @@ use App\Models\CartModel;
//购物车服务器层
class CartService
{
//添加购物车
public static function addCart($data, $user_id)
//添加或者更新购物车
public static function saveCart($data, $user_id)
{
try{
......@@ -47,14 +47,14 @@ class CartService
$checkHas = CartModel::where(["user_id"=>$user_id,"goods_id"=>$goods_id,"status"=>1])->first();
if ($checkHas){ //存在累计库存
$temp["goods_number"] = $skuInfo["stock"] > ($item['buy_number']+$checkHas["buy_number"]) ? $item['buy_number']+$checkHas["buy_number"] : $skuInfo["stock"];
$temp["buy_number"] = $skuInfo["stock"] > ($item['buy_number']+$checkHas["buy_number"]) ? $item['buy_number']+$checkHas["buy_number"] : $skuInfo["stock"];
$temp["update_time"] = time();
$flag = CartModel::where(["cart_id"=>$checkHas["cart_id"]])->update($temp);
if (!$flag){
return false;
}
}else{ //不存在插入购物车
$temp["goods_number"] = $skuInfo["stock"] > $item['buy_number'] ? $item['buy_number'] : $skuInfo["stock"];
$temp["buy_number"] = $skuInfo["stock"] > $item['buy_number'] ? $item['buy_number'] : $skuInfo["stock"];
$temp["create_time"] = time();
$temp["update_time"] = time();
......@@ -75,7 +75,7 @@ class CartService
}
//刷新购物车并且返回列表
public static function cartUpdateGetLists($user_id){
public static function cartLists($user_id){
//当前用户所有可用的购物车数据
$query = CartModel::where(['user_id'=>$user_id,"status"=>1])
......@@ -92,6 +92,7 @@ class CartService
$redis = Redis::connection();
$goodsInfoArr = ThirdService::getGoodsInfo(array_column($result,"goods_id"));
$cartList = [];
foreach ($result as $item) {
$goods_id = $item['goods_id'];
......
......@@ -22,3 +22,42 @@ if (!function_exists('generate_letters')) {
return $letters;
}
}
/*
* 反爬虫用html标签替换数字,不包括“.”
* $number 数字串
*/
function numberToHtml($number){
$arr = [
['asfgdqwer','asfgdtyhg','asfgdpolk','asfgdpoqw'],
['asfgdrfdf','asfgderfd','asfgdwdsa','asfgdpoer'],
['asfgdasde','asfgdqwsz','asfgdrtgd','asfgdpovv'],
['asfgdwsxc','asfgdwsxz','asfgdrfvb','asfgdpoee'],
['asfgdqazs','asfgdqasd','asfgdqwag','asfgdpogh'],
['asfgdrtyh','asfgdyutr','asfgdeews','asfgdpotg'],
['asfgdpluj','asfgdikjf','asfgdesgj','asfgdpfff'],
['asfgdtrdb','asfgdiksf','asfgdsgkp','asfgdprty'],
['asfgdpehl','asfgdstgb','asfgderll','asfgdpokf'],
['asfgdpehg','asfgdstgf','asfgderlf','asfgdpogk']
];
if(empty($arr)){
return $number;
}
$len = strlen($number);
if($len>0){
$str = '';
for($i=0;$i<$len;$i++){
$num = substr($number, $i,1);
if(preg_match('/\d/', $num)){
$index = rand(0, 3);
$class = $arr[$num][$index];
$other_class = strRandom($class);
$num = '<font class="'.$class.$other_class.'"></font>';
}
$str .= $num;
}
return $str;
}else{
return $number;
}
}
......@@ -43,7 +43,8 @@ Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () {
Route::get('country/list', 'CountryApiController@list');
Route::POST('cart/addCart', 'CartApiController@addCart'); //添加购物车
Route::POST('cart/saveCart', 'CartApiController@saveCart'); //添加或者更新购物车
Route::POST('cart/cartLists', 'CartApiController@cartLists'); //购物车列表
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment