|
|
@@ -26,7 +26,7 @@ class Order extends Api
|
|
|
/**
|
|
|
* 创建订单
|
|
|
*/
|
|
|
- public function create(ProductPopular $productPopular, ProductOrder $productOrder, ProductArea $productArea, LedgerWalletModel $ledgerWalletModel)
|
|
|
+ public function create(ProductPopular $productPopular, ProductOrder $productOrder, ProductArea $productArea, LedgerWalletModel $ledgerWalletModel, UserModel $userModel)
|
|
|
{
|
|
|
$params = $this->request->post();
|
|
|
$validate = \think\Loader::validate('Order');
|
|
|
@@ -45,6 +45,7 @@ class Order extends Api
|
|
|
$amount = $ledgerWalletModel::getWalletChaBao($this->auth->id);
|
|
|
$totalPrice = bcmul($order_info['price'], $areaNum, 2);
|
|
|
if(bccomp($totalPrice, $amount, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
|
|
|
+ if($order_info->start_time > time()) throw new Exception(__("抢购未开始"));
|
|
|
if($order_info->stock == 0 || time() >= $order_info->end_time) throw new Exception(__("抢购已结束"));
|
|
|
//批量地区添加
|
|
|
foreach ($areaArr as $item) {
|
|
|
@@ -67,10 +68,12 @@ class Order extends Api
|
|
|
$ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$totalPrice, $ledgerWalletModel::Popular, $this->auth->id);
|
|
|
|
|
|
//直推收益: pv* ×10%
|
|
|
- if($order_info['pv'] > 0 && $this->auth->parent_id > 0 && $productOrder::getEffectiveOrder($this->auth->parent_id) > 0){
|
|
|
+ if($order_info['pv'] > 0 && $this->auth->parent_id > 0 && $userModel::getUserRwaNum($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);
|
|
|
}
|
|
|
+ //更新Rwa持有数量
|
|
|
+ $userModel->updateForRwaNum($this->auth->id, $areaNum, '+');
|
|
|
//扣除库存
|
|
|
if(($order_info->stock - $areaNum) == 0 || time() >= $order_info->end_time) $order_info->status= $productPopular::STOP;
|
|
|
$order_info->num += $areaNum;
|
|
|
@@ -89,7 +92,7 @@ class Order extends Api
|
|
|
/**
|
|
|
* 提货订单
|
|
|
*/
|
|
|
- public function pickupOrder(UserArea $userArea, ProductOrder $productOrder)
|
|
|
+ public function pickupOrder(UserArea $userArea, ProductOrder $productOrder, UserModel $userModel)
|
|
|
{
|
|
|
$params = $this->request->post();
|
|
|
$validate = \think\Loader::validate('Order');
|
|
|
@@ -105,6 +108,9 @@ class Order extends Api
|
|
|
try {
|
|
|
// 生成订单
|
|
|
$userArea->create($order_data);
|
|
|
+ //扣除Rwa数量
|
|
|
+ $userModel->updateForRwaNum($order_info->user_id, 1, '-');
|
|
|
+
|
|
|
$order_info->status= $productOrder::Shipped;
|
|
|
$order_info->save();
|
|
|
// 提交事务
|
|
|
@@ -122,7 +128,7 @@ class Order extends Api
|
|
|
* 订单转让
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function transfer(ProductOrder $productOrder, ProductTransfer $productTransfer)
|
|
|
+ public function transfer(ProductOrder $productOrder, ProductTransfer $productTransfer, UserModel $userModel)
|
|
|
{
|
|
|
$params = $this->request->post();
|
|
|
$validate = \think\Loader::validate('Order');
|
|
|
@@ -139,6 +145,9 @@ class Order extends Api
|
|
|
$feeAmount = bcmul($params['price'], $fee, 2) ;
|
|
|
$productTransfer::setTransferOrder($this->auth->id, $order_info['product_id'], $order_info['area_id'], $feeAmount, $params);
|
|
|
|
|
|
+ //扣除Rwa有效
|
|
|
+ $userModel->updateForRwaNum($order_info['user_id'], 1, '-');
|
|
|
+
|
|
|
//修改状态
|
|
|
$order_info->status = $productOrder::Transferred;
|
|
|
$order_info->save();
|
|
|
@@ -154,7 +163,7 @@ class Order extends Api
|
|
|
* 转让订单购买
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function transferOrder(ProductOrder $productOrder, ProductTransfer $productTransfer, LedgerWalletModel $ledgerWalletModel)
|
|
|
+ public function transferOrder(ProductOrder $productOrder, ProductTransfer $productTransfer, LedgerWalletModel $ledgerWalletModel, UserModel $userModel)
|
|
|
{
|
|
|
$params = $this->request->post();
|
|
|
$validate = \think\Loader::validate('Order');
|
|
|
@@ -185,11 +194,13 @@ class Order extends Api
|
|
|
//扣除余额记录
|
|
|
$ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_info['price'], $ledgerWalletModel::Payment, $order_info['user_id']);
|
|
|
|
|
|
-
|
|
|
//增加转让人余额
|
|
|
$amount = bcsub($order_info['price'], $order_info['fees'], 2);
|
|
|
$ledgerWalletModel->changeWalletAccount($order_info['user_id'], Asset::TOKEN, $amount, $ledgerWalletModel::Receive, $this->auth->id);
|
|
|
|
|
|
+ //增加Rwa有效
|
|
|
+ $userModel->updateForRwaNum($this->auth->id, 1, '+');
|
|
|
+
|
|
|
//修改原订单状态
|
|
|
$productOrder->where('id', $order_info['order_id'])->setField('status', $productOrder::Closure);
|
|
|
//修改状态
|
|
|
@@ -242,6 +253,9 @@ class Order extends Api
|
|
|
//扣除手续费
|
|
|
$ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$fees, $ledgerWalletModel::Giveaway, $user['id']);
|
|
|
|
|
|
+ //扣除Rwa有效
|
|
|
+ $userModel->updateForRwaNum($this->auth->id, 1, '-');
|
|
|
+
|
|
|
$order_info->status= $productOrder::Closure;
|
|
|
$order_info->save();
|
|
|
|
|
|
@@ -257,7 +271,7 @@ class Order extends Api
|
|
|
|
|
|
|
|
|
//取消转让
|
|
|
- public function cancel(ProductOrder $productOrder, ProductTransfer $productTransfer)
|
|
|
+ public function cancel(ProductOrder $productOrder, ProductTransfer $productTransfer, UserModel $userModel)
|
|
|
{
|
|
|
$params = $this->request->post();
|
|
|
$validate = \think\Loader::validate('Order');
|
|
|
@@ -271,6 +285,9 @@ class Order extends Api
|
|
|
|
|
|
//转让列表取消
|
|
|
$productTransfer::where('order_id',$params['order_id'])->setField('status', $productTransfer::STOP);
|
|
|
+
|
|
|
+ //增加Rwa有效
|
|
|
+ $userModel->updateForRwaNum($order_info['user_id'], 1, '+');
|
|
|
$order_info->status= $productOrder::Paid;
|
|
|
$order_info->save();
|
|
|
// 提交事务
|