|
|
@@ -90,15 +90,14 @@ class Order extends Api
|
|
|
$params = $this->request->post();
|
|
|
$validate = \think\Loader::validate('Order');
|
|
|
if(!$validate->scene('pick')->check($params)) $this->error($validate->getError());
|
|
|
- $order_info = $productOrder->where('id', $params['order_id'])->find();
|
|
|
- if(empty($order_info)) $this->error( __("参数有误,无可用产品"));
|
|
|
+ $order_info = $productOrder::getProductOrder($params['order_id'], productOrder::Paid, 'b.freight,b.is_freight');
|
|
|
+ if(empty($order_info) || empty($order_info->is_freight)) $this->error( __("参数有误,无可用产品"));
|
|
|
// 启动事务
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
|
|
|
- $freight= getConfig('logistics_freight');
|
|
|
- $amount = $ledgerWalletModel::getWalletChaBao($this->auth->id);
|
|
|
- if(bccomp($freight, $amount, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
|
|
|
+ $amount = $ledgerWalletModel::getWalletTotalChaBao($this->auth->id);
|
|
|
+ if(bccomp($order_info->freight, $amount, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
|
|
|
|
|
|
// 生成订单
|
|
|
$userArea->create(['name'=>$params['name'], 'type_id'=>$userArea::TakeAdders, 'phone'=>$params['phone'],'address'=>$params['address'],'order_id'=>$params['order_id']]);
|
|
|
@@ -107,7 +106,7 @@ class Order extends Api
|
|
|
if($order_info->popular_price > config('min_rwa_price')) $userModel::updateForRwaNum($order_info->user_id, $userModel::getByParentId($order_info->user_id), 1, '-');
|
|
|
|
|
|
//扣除运费
|
|
|
- $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$freight, $ledgerWalletModel::Freight, $this->auth->id);
|
|
|
+ if($order_info->freight > 0) $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_info->freight, $ledgerWalletModel::Freight, $this->auth->id);
|
|
|
|
|
|
$order_info->status= $productOrder::Shipped;
|
|
|
$order_info->save();
|
|
|
@@ -123,7 +122,7 @@ class Order extends Api
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 订单转让
|
|
|
+ * 订单寄售转让
|
|
|
* @return void
|
|
|
*/
|
|
|
public function transfer(ProductOrder $productOrder, ProductTransfer $productTransfer, ProductPopular $productPopular)
|
|
|
@@ -134,12 +133,9 @@ class Order extends Api
|
|
|
//启动事务
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
-
|
|
|
- $order_info = $productOrder->where('id', $params['order_id'])->where('status', $productOrder::Paid)->find();
|
|
|
- if(empty($order_info)) throw new Exception(__("订单不存在"));
|
|
|
-
|
|
|
- $min_transfer = $productPopular::where('id', $order_info->order_id)->value('min_transfer');
|
|
|
- if(bccomp($params['price'],$min_transfer, 2) < 0) throw new Exception(__("当前订单最低转让金额为").$min_transfer);
|
|
|
+ $order_info = $productOrder::getProductOrder($params['order_id'], productOrder::Paid, 'b.is_transfer,b.min_transfer_fee,b.max_transfer_fee');
|
|
|
+ if(empty($order_info) || empty($order_info->is_transfer)) throw new Exception(__("订单不存在"));
|
|
|
+ if($params['price'] < $order_info->min_transfer_fee || $params['price'] > $order_info->max_transfer_fee) throw new Exception(__("当前订单转让金额为").$order_info->min_transfer_fee.'~'.$order_info->max_transfer_fee);
|
|
|
|
|
|
//转让订单
|
|
|
$fee = getConfig('transfer_fee');
|
|
|
@@ -219,15 +215,16 @@ class Order extends Api
|
|
|
// 启动事务
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
- $order_info = $productOrder->where('id', $params['order_id'])->where('status', $productOrder::Paid)->find();
|
|
|
- if(empty($order_info)) throw new Exception(__("参数有误,无可用产品"));
|
|
|
+
|
|
|
+ $order_info = $productOrder::getProductOrder($params['order_id'], $productOrder::Paid, 'b.is_gift,b.gift_fee');
|
|
|
+ if(empty($order_info) || empty($order_info->is_gift)) throw new Exception(__("参数有误,无可用产品"));
|
|
|
|
|
|
$user = $userModel->getByAddress($params['address']);
|
|
|
if(empty($user)) throw new Exception(__("赠送用户不存在"));
|
|
|
if($user['id'] == $order_info['user_id']) throw new Exception(__("赠送用户不能是自己"));
|
|
|
|
|
|
- $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);
|
|
|
- $fees = bcmul($order_info['price'], getConfig('giveaway'), 2);
|
|
|
+ $chabao = $ledgerWalletModel::getWalletTotalChaBao($this->auth->id);
|
|
|
+ $fees = bcmul($order_info['price'], $order_info->gift_fee, 2);
|
|
|
if(bccomp($fees, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
|
|
|
|
|
|
//添加记录
|