|
@@ -36,20 +36,21 @@ class Order extends Api
|
|
|
if(!$validate->scene('add')->check($params)) $this->error($validate->getError());
|
|
if(!$validate->scene('add')->check($params)) $this->error($validate->getError());
|
|
|
$order_info = $productPopular->where('id', $params['order_id'])->find();
|
|
$order_info = $productPopular->where('id', $params['order_id'])->find();
|
|
|
if(empty($order_info)) $this->error(__("参数有误,无可用产品"));
|
|
if(empty($order_info)) $this->error(__("参数有误,无可用产品"));
|
|
|
- $areaArr = ($params['type'] == 1)? explode(',', $params['area_id']): '';
|
|
|
|
|
|
|
+ $areaArr = ($params['type'] == 1)? explode(',', $params['area_id']): [];
|
|
|
$areaNum = ($params['type'] == 1)? count($areaArr): $params['num'];
|
|
$areaNum = ($params['type'] == 1)? count($areaArr): $params['num'];
|
|
|
if(($order_info->num +$order_info->init_num+ $areaNum) > $order_info->stock) $this->error(__("库存不足"));
|
|
if(($order_info->num +$order_info->init_num+ $areaNum) > $order_info->stock) $this->error(__("库存不足"));
|
|
|
$result = false;
|
|
$result = false;
|
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
|
try {
|
|
try {
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$amount = $ledgerWalletModel::getWalletChaBao($this->auth->id);
|
|
$amount = $ledgerWalletModel::getWalletChaBao($this->auth->id);
|
|
|
$totalPrice = bcmul($order_info['price'], $areaNum, 2);
|
|
$totalPrice = bcmul($order_info['price'], $areaNum, 2);
|
|
|
|
|
+
|
|
|
if(bccomp($totalPrice, $amount, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
|
|
if(bccomp($totalPrice, $amount, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
|
|
|
if($order_info->start_time > time()) throw new Exception(__("抢购未开始"));
|
|
if($order_info->start_time > time()) throw new Exception(__("抢购未开始"));
|
|
|
if($order_info->stock == 0 || time() >= $order_info->end_time) throw new Exception(__("抢购已结束"));
|
|
if($order_info->stock == 0 || time() >= $order_info->end_time) throw new Exception(__("抢购已结束"));
|
|
|
|
|
|
|
|
- // //批量地区添加 1选择地区 2未选择地区
|
|
|
|
|
|
|
+ //批量地区添加 1选择地区 2未选择地区
|
|
|
$result = $orderLogic::createOrderByType($params['type'], $areaArr, $params['order_id'], $order_info->price, $params['product_id'], $this->auth->id, $areaNum);
|
|
$result = $orderLogic::createOrderByType($params['type'], $areaArr, $params['order_id'], $order_info->price, $params['product_id'], $this->auth->id, $areaNum);
|
|
|
|
|
|
|
|
//余额记录
|
|
//余额记录
|