Commit 9e736fdd by 朱继来

自营线上下单

parent 63b284bb
...@@ -326,6 +326,24 @@ Class AddOrderController extends Controller ...@@ -326,6 +326,24 @@ Class AddOrderController extends Controller
} }
} }
// 切换销售类型
public function switchSaleType(Request $request)
{
if ($request->isMethod('post')) {
$data['sale_type'] = $request->input('sale_type');
$data['cart_ids'] = $request->input('cart_ids');
$data['k1'] = time();
$data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
$url = Config('website.api_domain').'cart/switchSaleType';
$response = json_decode(curlApi($url, $data), true);
return ['errcode' => $response['err_code'], 'errmsg' => $response['err_msg']];
}
}
// 获取购物车列表 // 获取购物车列表
public function cartList(Request $request) public function cartList(Request $request)
{ {
...@@ -420,6 +438,37 @@ Class AddOrderController extends Controller ...@@ -420,6 +438,37 @@ Class AddOrderController extends Controller
} }
} }
// 检查期货库存
public function checkStock(Request $request)
{
if ($request->isMethod('post')) {
$cart_info = json_decode($request->input('cart_info', ''), true);
$data['k1'] = time();
$data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
$url = Config('website.api_domain').'goods/detail';
$err_name = array();
foreach ($cart_info as $k=>$v) {
$data['id'] = $v['gid'];
$response = json_decode(curlApi($url, $data), true);
if ($v['num'] < $response['data']['goods_number']) {
$err_name[] = $response['data']['goods_name'];
}
}
if (!empty($err_name)) {
return ['errcode' => -1, 'errmsg' => '所购商品数量小于可用库存', 'data'=>$err_name];
}
return ['errcode' => 0, 'errmsg' => ''];
}
}
// 提交订单 // 提交订单
public function create(Request $request) public function create(Request $request)
{ {
...@@ -439,12 +488,16 @@ Class AddOrderController extends Controller ...@@ -439,12 +488,16 @@ Class AddOrderController extends Controller
$data['user_coupon_id'] = $request->input('user_coupon_id'); $data['user_coupon_id'] = $request->input('user_coupon_id');
} }
$data['sale_type'] = $request->input('sale_type', ''); // 自营线上选择销售类型
$data['k1'] = time(); $data['k1'] = time();
$data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi'); $data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
// $url = Config('website.api_domain').'order/createByOrderSystem';
$url = Config('website.api_domain').'order/create'; $url = Config('website.api_domain').'order/create';
// echo '<pre>';
// print_r(curlApi($url, $data));die;
$response = json_decode(curlApi($url, $data), true); $response = json_decode(curlApi($url, $data), true);
if ($response['err_code'] == 0) { if ($response['err_code'] == 0) {
......
...@@ -98,6 +98,9 @@ Route::group(['middleware' => 'web'], function () { ...@@ -98,6 +98,9 @@ Route::group(['middleware' => 'web'], function () {
Route::post('/ajax/create', 'AddOrderController@create'); Route::post('/ajax/create', 'AddOrderController@create');
Route::get('/addorder/success', 'AddOrderController@success'); Route::get('/addorder/success', 'AddOrderController@success');
Route::post('/ajax/selfCheck', 'AddOrderController@selfCheck'); Route::post('/ajax/selfCheck', 'AddOrderController@selfCheck');
Route::post('/ajax/switchSaleType', 'AddOrderController@switchSaleType');
Route::post('/ajax/checkStock', 'AddOrderController@checkStock');
Route::match(['get', 'post'],'/web/{key}', 'WebController@info'); Route::match(['get', 'post'],'/web/{key}', 'WebController@info');
Route::match(['get', 'post'],'/api/{key}', 'ApiController@Entrance'); Route::match(['get', 'post'],'/api/{key}', 'ApiController@Entrance');
......
...@@ -455,6 +455,39 @@ ...@@ -455,6 +455,39 @@
loading.confirm(user_id, address_id, cart_ids, coupon_id, goods_type); // 确认订单信息 loading.confirm(user_id, address_id, cart_ids, coupon_id, goods_type); // 确认订单信息
}) })
// 切换销售类型
$('#sale_type').change(function() {
var coupon_id = $('.user_coupon_id').val();
var address_id = $('.address_id').val();
var user_id = $('.user_id').val();
var sale_type = $(this).val();
var cart_ids = [];
$('.shop-table tbody').find('tr').each(function() {
var cid = $(this).data('cid');
cart_ids.push(cid);
})
if (cart_ids.length > 0) {
$.ajax({
type: "POST",
url: '/ajax/switchSaleType',
data: {sale_type: sale_type, cart_ids: cart_ids},
dataType: "json",
success: function(resp){
if (resp.errcode == 0) {
layer.msg(resp.errmsg);
loading.lists(user_id, goods_type, is_online); // 加载购物车列表
return false;
}
layer.msg(resp.errmsg);
},
})
}
})
// 提交订单 // 提交订单
$('.submit-order').click(function() { $('.submit-order').click(function() {
var address_id = $('input[name=address_id]').val(); var address_id = $('input[name=address_id]').val();
...@@ -506,6 +539,68 @@ ...@@ -506,6 +539,68 @@
datax.user_coupon_id = user_coupon_id; datax.user_coupon_id = user_coupon_id;
} }
// 自营线上
if (type == 2) {
var sale_type = $('#sale_type').val();
if (sale_type == 2) { // 选择期货
var cart_info = [];
$('.shop-table tbody tr').each(function() {
var gid = $(this).find('.goods_id').text();
var num = $(this).find('.goods_num').val();
cart_info.push({'gid':gid, 'num':num});
})
$.ajax({
type: "POST",
url: '/ajax/checkStock',
data: {cart_info: JSON.stringify(cart_info), num: 11},
dataType: "json",
success: function(resp){
if (resp.errcode == -1) {
var data = resp.data;
var content = '<p>确定设置以下型号为期货吗?</p>';
for (var i = 0; i < data.length; i++) {
content += '<p><span>'+(i+1)+'、</span>'+data[i]+'</p>';
}
// 弹出提示
layer.open({
area: ['500px', '300px'],
title: '提示信息',
content: content,
btn:['确定', '取消'],
yes: function(index, layero){
$.ajax({
type: "POST",
url: '/ajax/create',
data: datax,
dataType: "json",
success: function(resp){
if (resp.errcode == 0) {
layer.msg(resp.errmsg);
location.href = '/addorder/success?order_id='+resp.data.order_id+'&type='+resp.data.type;
}
layer.msg(resp.errmsg);
},
})
},
btn2: function(index, layero){
layer.close(index);
}
});
}
},
})
return false;
}
}
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: '/ajax/create', url: '/ajax/create',
...@@ -551,7 +646,7 @@ ...@@ -551,7 +646,7 @@
// 购物车列表 // 购物车列表
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
html += '<tr data-cid="'+list[i].cart_id+'">'+ html += '<tr data-cid="'+list[i].cart_id+'">'+
'<td>'+list[i].goods_id+'</td>'+ '<td class="goods_id">'+list[i].goods_id+'</td>'+
'<td>'+list[i].goods_name+'</td>'+ '<td>'+list[i].goods_name+'</td>'+
'<td>'+list[i].brand_name+'</td>'+ '<td>'+list[i].brand_name+'</td>'+
'<td><input type="text" class="goods_num" name="goods_num" value="'+list[i].goods_number+'"></td>'+ '<td><input type="text" class="goods_num" name="goods_num" value="'+list[i].goods_number+'"></td>'+
...@@ -568,6 +663,8 @@ ...@@ -568,6 +663,8 @@
$('.shop-lists').show(); $('.shop-lists').show();
$('.shop-table tbody').empty().append(html); $('.shop-table tbody').empty().append(html);
$('#sale_type').val(list[0].sale_type); // 自营线上订单选择销售类型
var address_id = $('.address_id').val(); var address_id = $('.address_id').val();
self.confirm(user_id, address_id, cart_ids, user_coupon_id, goods_type, is_online); // 确认订单信息 self.confirm(user_id, address_id, cart_ids, user_coupon_id, goods_type, is_online); // 确认订单信息
} }
...@@ -647,7 +744,7 @@ ...@@ -647,7 +744,7 @@
$('.preferential_price_val').empty().text(data.preferential_price_format); $('.preferential_price_val').empty().text(data.preferential_price_format);
} }
if (goods_type == 2 && address_id) { if (goods_type == 2) {
$('.express_fee_val').empty().text(data.finally_shipping_price_format); // 运费 $('.express_fee_val').empty().text(data.finally_shipping_price_format); // 运费
} }
} else { } else {
......
...@@ -355,13 +355,23 @@ ...@@ -355,13 +355,23 @@
<div class="ibox-content"> <div class="ibox-content">
<div class="row"> <div class="row">
<p class="con-title"><span style="margin-top: 5px;">订单类型:</span></p>
<p class="con-val">
<select name="sale_type" id="sale_type">
<option value="1" selectd>自营现货</option>
<option value="2">自营期货</option>
</select>
</p>
</div>
<div class="row">
<p class="con-title"><span>商品总额:</span></p> <p class="con-title"><span>商品总额:</span></p>
<p class="con-val goods_amount_val"></p> <p class="con-val goods_amount_val"></p>
</div> </div>
<div class="row"> <div class="row">
<input type="hidden" class="user_coupon_id" name="user_coupon_id" value=""> <input type="hidden" class="user_coupon_id" name="user_coupon_id" value="">
<p class="con-title"><span>选择优惠券:</span></p> <p class="con-title"><span style="margin-top: 5px;">选择优惠券:</span></p>
<p class="con-val"> <p class="con-val">
<select name="user_coupon" id="user_coupon"> <select name="user_coupon" id="user_coupon">
<option value="">请选择</option> <option value="">请选择</option>
......
...@@ -381,7 +381,7 @@ ...@@ -381,7 +381,7 @@
<div class="row"> <div class="row">
<input type="hidden" class="user_coupon_id" name="user_coupon_id" value=""> <input type="hidden" class="user_coupon_id" name="user_coupon_id" value="">
<p class="con-title"><span>选择优惠券:</span></p> <p class="con-title"><span style="margin-top: 5px;">选择优惠券:</span></p>
<p class="con-val"> <p class="con-val">
<select name="user_coupon" id="user_coupon"> <select name="user_coupon" id="user_coupon">
<option value="">请选择</option> <option value="">请选择</option>
......
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