|
|
@@ -8,12 +8,11 @@ use app\common\model\ProductOrder;
|
|
|
use app\common\model\ProductPopular;
|
|
|
use app\common\model\ProductLists;
|
|
|
use app\common\model\LedgerWalletModel;
|
|
|
-use app\common\model\UserBalanceLog;
|
|
|
use app\common\model\UserArea;
|
|
|
use app\common\model\UserModel;
|
|
|
use app\common\model\OfflineRechargeRecordModel;
|
|
|
use Exception;
|
|
|
-use fast\MembershipLevel;
|
|
|
+use fast\Asset;
|
|
|
use think\Db;
|
|
|
use think\Env;
|
|
|
|
|
|
@@ -26,7 +25,7 @@ class Order extends Api
|
|
|
/**
|
|
|
* 创建订单
|
|
|
*/
|
|
|
- public function create(ProductPopular $productPopular, ProductOrder $productOrder, ProductLists $productLists)
|
|
|
+ public function create(ProductPopular $productPopular, ProductOrder $productOrder, ProductLists $productLists, LedgerWalletModel $ledgerWalletModel)
|
|
|
{
|
|
|
$params = $this->request->post();
|
|
|
$validate = \think\Loader::validate('Order');
|
|
|
@@ -47,7 +46,7 @@ class Order extends Api
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
|
|
|
- $amount = bcsub($this->auth->balance, $this->auth->frozen_amount, 2);
|
|
|
+ $amount = $ledgerWalletModel::getWalletChaBao($this->auth->id);
|
|
|
if(bccomp($order_info['price'], $amount, 2) > 0) throw new Exception(__("余额不足请前往充值"));
|
|
|
if($order_info->stock == 0 || time() >= $order_info->end_time) throw new Exception(__("抢购已结束"));
|
|
|
// 生成订单
|
|
|
@@ -57,8 +56,8 @@ class Order extends Api
|
|
|
$productLists->where('id', $order_data['area_id'])->update(['status'=> $productLists::STOP]);
|
|
|
|
|
|
//余额记录
|
|
|
- UserBalanceLog::changeWalletAccount($this->auth->id, UserBalanceLog::Popular, $order_info['price'],
|
|
|
- $this->auth->balance, bcsub($this->auth->balance, $order_info['price'], 6), $order->id, '-');
|
|
|
+ $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_info['price'], $ledgerWalletModel::Popular, $this->auth->id);
|
|
|
+
|
|
|
//扣除库存
|
|
|
if($order_info->stock == 1 || time() >= $order_info->end_time) $order_info->status= $productPopular::STOP;
|
|
|
$order_info->num += 1;
|
|
|
@@ -78,7 +77,7 @@ class Order extends Api
|
|
|
/**
|
|
|
* 提货订单
|
|
|
*/
|
|
|
- public function pickupOrder(UserArea $userArea, ProductOrder $productOrder, ProductLists $productLists)
|
|
|
+ public function pickupOrder(UserArea $userArea, ProductOrder $productOrder)
|
|
|
{
|
|
|
$params = $this->request->post();
|
|
|
$validate = \think\Loader::validate('Order');
|
|
|
@@ -88,8 +87,8 @@ class Order extends Api
|
|
|
if(empty($order_info)) $this->error( __("参数有误,无可用产品"));
|
|
|
$order_data['name'] = $params['name'];
|
|
|
$order_data['phone'] = $params['phone'];
|
|
|
- $order_data['address'] = $params['address'];
|
|
|
- $order_data['order_id'] = $params['order_id'];
|
|
|
+ $order_data['address'] = $params['address'];
|
|
|
+ $order_data['order_id'] = $params['order_id'];
|
|
|
// 启动事务
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
@@ -152,7 +151,7 @@ class Order extends Api
|
|
|
* 转让订单购买
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function transferOrder(ProductOrder $productOrder, ProductTransfer $productTransfer)
|
|
|
+ public function transferOrder(ProductOrder $productOrder, ProductTransfer $productTransfer, LedgerWalletModel $ledgerWalletModel)
|
|
|
{
|
|
|
$params = $this->request->post();
|
|
|
$validate = \think\Loader::validate('Order');
|
|
|
@@ -163,7 +162,8 @@ class Order extends Api
|
|
|
|
|
|
$order_info = $productTransfer->where('id', $params['order_id'])->where('status', $productTransfer::NORMAL)->find();
|
|
|
if(empty($order_info)) throw new Exception(__("订单不存在"));
|
|
|
- if(bccomp($order_info['price'], $this->auth->balance, 2) > 0) throw new Exception(__("余额不足请前往充值"));
|
|
|
+ $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);
|
|
|
+ if(bccomp($order_info['price'], $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"));
|
|
|
|
|
|
$order_data['order_id'] = $params['order_id'];
|
|
|
$order_data['product_id']= $order_info['product_id'];
|
|
|
@@ -178,21 +178,12 @@ class Order extends Api
|
|
|
// 生成订单
|
|
|
$order = $productOrder->create($order_data);
|
|
|
//扣除余额记录
|
|
|
- $balance = bcsub($this->auth->balance, $this->auth->frozen_amount, 2);
|
|
|
- UserBalanceLog::changeWalletAccount(
|
|
|
- $this->auth->id, UserBalanceLog::Payment,
|
|
|
- $order_info['price'], $balance,
|
|
|
- bcsub($balance, $order_info['price'], 2),
|
|
|
- $order->id, '-');
|
|
|
+ $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);
|
|
|
- $atBalance= UserModel::getUserAmount($order_info['user_id']);
|
|
|
- UserBalanceLog::changeWalletAccount(
|
|
|
- $order_info['user_id'], UserBalanceLog::Receive,
|
|
|
- $amount,
|
|
|
- $atBalance,
|
|
|
- bcadd($atBalance, $amount, 2),
|
|
|
- $order->id);
|
|
|
+ $amount = bcsub($order_info['price'], $order_info['fees'], 2);
|
|
|
+ $ledgerWalletModel->changeWalletAccount($order_info['user_id'], Asset::TOKEN, $amount, $ledgerWalletModel::Receive, $this->auth->id);
|
|
|
|
|
|
//修改原订单状态
|
|
|
$productOrder->where('id', $order_info['order_id'])->setField('status', $productOrder::Complete);
|