|
|
|
@ -123,34 +123,61 @@ class Order extends Api |
|
|
|
|
* @return [type] [description] |
|
|
|
|
*/ |
|
|
|
|
public function limitBuyNum($user, $warehouse){ |
|
|
|
|
|
|
|
|
|
$is_allow_access = 0; |
|
|
|
|
//return $is_allow_access; |
|
|
|
|
//是否在时间范围内 |
|
|
|
|
$start = strtotime($warehouse['start']); |
|
|
|
|
$end = strtotime($warehouse['end']); |
|
|
|
|
$start_date = date("Y-m-d H:i:s",$start); |
|
|
|
|
$end_date = date("Y-m-d H:i:s", $end); |
|
|
|
|
$code = $start."-".$end; |
|
|
|
|
//仓库限制用户总抢购次数 |
|
|
|
|
$count = Db::name('user_access_record')->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->count(); |
|
|
|
|
|
|
|
|
|
if ($warehouse['limit_buy_num'] > 0 && $count > $warehouse['limit_buy_num']) { |
|
|
|
|
$start_date = date("Y-m-d H:i",$start); |
|
|
|
|
$end_date = date("Y-m-d H:i", $end); |
|
|
|
|
$code = $start_date."-".$end_date; |
|
|
|
|
//提前下单次数(买单) |
|
|
|
|
$advance_count = OrderModel::where('order_type',0)->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->where('is_advance', 1)->count(); |
|
|
|
|
if ($user['advance_access_num'] > 0 && $advance_count >= $user['advance_access_num']) { |
|
|
|
|
$is_allow_access = 1; |
|
|
|
|
return $is_allow_access; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//提前进入次数 |
|
|
|
|
$count = Db::name('user_access_record')->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->where('is_advance', 1)->count(); |
|
|
|
|
if ($user['advance_access_num'] > 0 && $count > $user['advance_access_num']) { |
|
|
|
|
//正常下单次数(买单) |
|
|
|
|
$normal_count = OrderModel::where('order_type',0)->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->where('is_advance', 0)->count(); |
|
|
|
|
// var_dump($normal_count); |
|
|
|
|
// exit(); |
|
|
|
|
if ($user['buy_goods_num_per_day'] > 0 && $normal_count >= $user['buy_goods_num_per_day']) { |
|
|
|
|
$is_allow_access = 1; |
|
|
|
|
return $is_allow_access; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//正常进入次数 |
|
|
|
|
$count = Db::name('user_access_record')->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->where('is_advance',0)->count(); |
|
|
|
|
if ($user['buy_goods_num_per_day'] > 0 && $count > $user['buy_goods_num_per_day']) { |
|
|
|
|
$count = $advance_count + $normal_count; |
|
|
|
|
//总下单次数 |
|
|
|
|
if ($warehouse['limit_buy_num'] > 0 && $count >= $warehouse['limit_buy_num']) { |
|
|
|
|
$is_allow_access = 1; |
|
|
|
|
return $is_allow_access; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//正常下单次数(买单) |
|
|
|
|
// $start_date = date("Y-m-d H:i:s",$start); |
|
|
|
|
// $end_date = date("Y-m-d H:i:s", $end); |
|
|
|
|
// $code = $start."-".$end; |
|
|
|
|
// //仓库限制用户总抢购次数 |
|
|
|
|
// $count = Db::name('user_access_record')->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->count(); |
|
|
|
|
|
|
|
|
|
// if ($warehouse['limit_buy_num'] > 0 && $count > $warehouse['limit_buy_num']) { |
|
|
|
|
// $is_allow_access = 1; |
|
|
|
|
// return $is_allow_access; |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
// //提前进入次数 |
|
|
|
|
// $count = Db::name('user_access_record')->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->where('is_advance', 1)->count(); |
|
|
|
|
// if ($user['advance_access_num'] > 0 && $count > $user['advance_access_num']) { |
|
|
|
|
// $is_allow_access = 1; |
|
|
|
|
// return $is_allow_access; |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
// //正常进入次数 |
|
|
|
|
// $count = Db::name('user_access_record')->where('user_id', $user['id'])->where('warehouse_id', $warehouse['id'])->where('code', $code)->where('is_advance',0)->count(); |
|
|
|
|
// if ($user['buy_goods_num_per_day'] > 0 && $count > $user['buy_goods_num_per_day']) { |
|
|
|
|
// $is_allow_access = 1; |
|
|
|
|
// return $is_allow_access; |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $is_allow_access; |
|
|
|
@ -233,8 +260,11 @@ class Order extends Api |
|
|
|
|
if (!$goods) { |
|
|
|
|
$this->error("售卖商品不存在"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$warehouse = Warehouse::where('id', $order['warehouse_id'])->find(); |
|
|
|
|
$is_allow_access = $this->limitBuyNum($user, $warehouse); |
|
|
|
|
if ($is_allow_access > 0 ) { |
|
|
|
|
$this->error("抢购次数被限制"); |
|
|
|
|
} |
|
|
|
|
$this->getBuyTime($warehouse, $user); |
|
|
|
|
$owner = User::where('id', $goods['owner_id'])->field(['id', 'username', 'nickname', 'mobile', 'avatar', 'score','sign_image','sign_status','alipay_image','wechat_image','buy_goods_num_per_day','advance_access_num','bank_realname','bank_mobile','bank_no','bank_address','reason','warehouse_id','advance_access_minute','deadline','pid','total_commission_amount','available_commission_amount'])->find(); |
|
|
|
|
$goods['warehouse'] = $warehouse; |
|
|
|
@ -242,13 +272,13 @@ class Order extends Api |
|
|
|
|
$goods['image'] = cdnurl($goods['image'], true); |
|
|
|
|
|
|
|
|
|
//写进入记录 |
|
|
|
|
$start = date("Y-m-d H:i:s", strtotime($warehouse['start'])); |
|
|
|
|
$end = date("Y-m-d H:i:s", strtotime($warehouse['end'])); |
|
|
|
|
$code = $start."-".$end; |
|
|
|
|
$info1 = Db::name('user_access_record')->where('warehouse_id', $goods['warehouse_id'])->where('user_id', $user['id'])->where('code', $code)->count(); |
|
|
|
|
if (!$info1) { |
|
|
|
|
Db::name('user_access_record')->insert(['user_id' => $user['id'],'warehouse_id' => $goods['warehouse_id'],'code' => $code, "createtime"=>time(), 'is_advance' => $user['advance_access_minute'] > 0 ? 1 : 0]); |
|
|
|
|
} |
|
|
|
|
// $start = date("Y-m-d H:i", strtotime($warehouse['start'])); |
|
|
|
|
// $end = date("Y-m-d H:i", strtotime($warehouse['end'])); |
|
|
|
|
// $code = $start."-".$end; |
|
|
|
|
// $info1 = Db::name('user_access_record')->where('warehouse_id', $goods['warehouse_id'])->where('user_id', $user['id'])->where('code', $code)->count(); |
|
|
|
|
// if (!$info1) { |
|
|
|
|
// Db::name('user_access_record')->insert(['user_id' => $user['id'],'warehouse_id' => $goods['warehouse_id'],'code' => $code, "createtime"=>time(), 'is_advance' => $user['advance_access_minute'] > 0 ? 1 : 0]); |
|
|
|
|
// } |
|
|
|
|
$order['goods'] = $goods; |
|
|
|
|
$this->success("succ", $order); |
|
|
|
|
} |
|
|
|
@ -288,8 +318,12 @@ class Order extends Api |
|
|
|
|
if (time() > strtotime($warehouse['end'])) { |
|
|
|
|
$this->error("抢购时间已结束!"); |
|
|
|
|
} |
|
|
|
|
$is_allow_access = $this->limitBuyNum($user, $warehouse); |
|
|
|
|
if ($is_allow_access > 0) { |
|
|
|
|
$this->error("抢购次数被限制"); |
|
|
|
|
} |
|
|
|
|
//使用redis锁,限制下单 |
|
|
|
|
$lock_key = $this->request->domain()."_createOrder_".$goods_id; |
|
|
|
|
$lock_key = $this->request->domain()."_createOrder_".$seller_order_id; |
|
|
|
|
$res = Cache::store('redis')->setnx($lock_key, 1); |
|
|
|
|
|
|
|
|
|
if (!$res) { |
|
|
|
@ -300,6 +334,9 @@ class Order extends Api |
|
|
|
|
$order_amount = $order['pay_amount']; |
|
|
|
|
$pay_amount = $order_amount; |
|
|
|
|
$order_sn = "ZH".date("YmdHis").rand(1000,9999); |
|
|
|
|
$start = date("Y-m-d H:i", strtotime($warehouse['start'])); |
|
|
|
|
$end = date("Y-m-d H:i", strtotime($warehouse['end'])); |
|
|
|
|
$code = $start."-".$end; |
|
|
|
|
//创建订单 |
|
|
|
|
$orderData = [ |
|
|
|
|
"user_id" => $user_id, |
|
|
|
@ -319,6 +356,8 @@ class Order extends Api |
|
|
|
|
"city" => $address['city_name'], |
|
|
|
|
"district" => $address['district_name'], |
|
|
|
|
"address" => $address['address'], |
|
|
|
|
"is_advance" => $start > time() ? 1 : 0, |
|
|
|
|
"code" => $code, |
|
|
|
|
]; |
|
|
|
|
$order = OrderModel::create($orderData); |
|
|
|
|
if ($order === false) { |
|
|
|
@ -578,6 +617,7 @@ class Order extends Api |
|
|
|
|
$fee = bcmul($order_amount, Config::get("site.entrustment_ratio") * 0.01, 2); |
|
|
|
|
$pay_amount = $fee - $coupon_price; |
|
|
|
|
$pay_amount = $pay_amount > 0 ? $pay_amount : 0; |
|
|
|
|
$pay_amount = round($pay_amount);//四舍五入取整数 |
|
|
|
|
$pay_method = "mp"; |
|
|
|
|
$order_data = [ |
|
|
|
|
'order_id' => $order_id, |
|
|
|
|