|
|
@@ -33,7 +33,8 @@ class Order extends Api
|
|
|
if(!$validate->scene('add')->check($params)) $this->error($validate->getError());
|
|
|
|
|
|
$order_info = $productPopular->where('id', $params['order_id'])->find();
|
|
|
- if(empty($order_info)) $this->error( __("参数有误,无可用产品"));
|
|
|
+ if($order_info->num == $order_info->stock) $this->error(__("库存不足"));
|
|
|
+ if(empty($order_info)) $this->error(__("参数有误,无可用产品"));
|
|
|
$order_data['order_id'] = $params['order_id'];
|
|
|
$order_data['product_id']= $params['product_id'];
|
|
|
$order_data['price'] = $order_info['price'];
|
|
|
@@ -54,20 +55,19 @@ class Order extends Api
|
|
|
$productOrder->create($order_data);
|
|
|
|
|
|
//修改区域状态
|
|
|
- $productArea->where('id', $order_data['area_id'])->update(['status'=> ProductLists::STOP]);
|
|
|
+ $productArea->where('id', $order_data['area_id'])->setField('status', ProductLists::STOP);
|
|
|
|
|
|
//余额记录
|
|
|
$ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_info['price'], $ledgerWalletModel::Popular, $this->auth->id);
|
|
|
|
|
|
//直推收益: pv* ×10%
|
|
|
- if($order_info['pv'] > 0 && $this->auth->parent_id > 0){
|
|
|
+ if($order_info['pv'] > 0 && $this->auth->parent_id > 0 && $productOrder::getEffectiveOrder($this->auth->parent_id) > 0){
|
|
|
$pv = bcmul($order_info['pv'], getConfig('pv_rate'), 2);
|
|
|
$ledgerWalletModel->changeWalletAccount($this->auth->parent_id, Asset::TOKEN, $pv, $ledgerWalletModel::Direct, $this->auth->id);
|
|
|
}
|
|
|
//扣除库存
|
|
|
if($order_info->stock == 1 || time() >= $order_info->end_time) $order_info->status= $productPopular::STOP;
|
|
|
$order_info->num += 1;
|
|
|
- $order_info->stock-= 1;
|
|
|
$order_info->save();
|
|
|
// 提交事务
|
|
|
Db::commit();
|