|
|
@@ -50,14 +50,13 @@ class Order extends Api
|
|
|
if(bccomp($order_info['price'], $amount, 2) > 0) throw new Exception(__("余额不足请前往充值"));
|
|
|
if($order_info->stock == 0 || time() >= $order_info->end_time) throw new Exception(__("抢购已结束"));
|
|
|
// 生成订单
|
|
|
- $order =$productOrder->create($order_data);
|
|
|
+ $productOrder->create($order_data);
|
|
|
|
|
|
//修改区域状态
|
|
|
$productLists->where('id', $order_data['area_id'])->update(['status'=> $productLists::STOP]);
|
|
|
|
|
|
//余额记录
|
|
|
$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;
|
|
|
@@ -82,7 +81,6 @@ 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_data['name'] = $params['name'];
|
|
|
@@ -94,7 +92,6 @@ class Order extends Api
|
|
|
try {
|
|
|
// 生成订单
|
|
|
$userArea->create($order_data);
|
|
|
-
|
|
|
$order_info->status= $productOrder::Shipped;
|
|
|
$order_info->save();
|
|
|
// 提交事务
|
|
|
@@ -135,7 +132,6 @@ class Order extends Api
|
|
|
|
|
|
// 生成订单
|
|
|
$productTransfer->create($order_data);
|
|
|
-
|
|
|
//修改状态
|
|
|
$order_info->status = $productOrder::Transferred;
|
|
|
$order_info->save();
|
|
|
@@ -172,11 +168,13 @@ class Order extends Api
|
|
|
$order_data['area_id'] = $order_info['area_id'];
|
|
|
$order_data['order_no'] = getOrderSN('Z');
|
|
|
$order_data['user_id'] = $this->auth->id;
|
|
|
+ $order_data['from_user'] = $order_info['user_id'];
|
|
|
$order_data['price'] = $order_info['price'];
|
|
|
+ $order_data['fees'] = $order_info['fees'];
|
|
|
$order_data['num'] = 1;
|
|
|
|
|
|
// 生成订单
|
|
|
- $order = $productOrder->create($order_data);
|
|
|
+ $productOrder->create($order_data);
|
|
|
//扣除余额记录
|
|
|
$ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_info['price'], $ledgerWalletModel::Payment, $order_info['user_id']);
|
|
|
|
|
|
@@ -186,7 +184,7 @@ class Order extends Api
|
|
|
$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);
|
|
|
+ $productOrder->where('id', $order_info['order_id'])->setField('status', $productOrder::Closure);
|
|
|
//修改状态
|
|
|
$order_info->status = $productTransfer::STOP;
|
|
|
$order_info->save();
|
|
|
@@ -198,6 +196,59 @@ class Order extends Api
|
|
|
$this->success('ok');
|
|
|
}
|
|
|
|
|
|
+ //赠送
|
|
|
+ public function giveaway(ProductOrder $productOrder, UserModel $userModel, LedgerWalletModel $ledgerWalletModel)
|
|
|
+ {
|
|
|
+ $params = $this->request->post();
|
|
|
+ $validate = \think\Loader::validate('Order');
|
|
|
+ if(!$validate->scene('giv')->check($params)) $this->error($validate->getError());
|
|
|
+
|
|
|
+ // 启动事务
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $order_info = $productOrder->where('id', $params['order_id'])->where('status', $productOrder::Paid)->find();
|
|
|
+ if(empty($order_info)) throw new Exception(__("参数有误,无可用产品"));
|
|
|
+
|
|
|
+ $user = $userModel->getByAddress($params['address']);
|
|
|
+ if(empty($user)) throw new Exception(__("赠送用户不存在"));
|
|
|
+ if($user['id'] == $this->auth->id) throw new Exception(__("赠送用户不能是自己"));
|
|
|
+
|
|
|
+ $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);
|
|
|
+ $fees = bcmul($order_info['price'], getConfig('giveaway'), 2);
|
|
|
+ if(bccomp($fees, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"));
|
|
|
+
|
|
|
+ //添加记录
|
|
|
+ $order_data['order_id'] = $params['order_id'];
|
|
|
+ $order_data['product_id']= $order_info['product_id'];
|
|
|
+ $order_data['type_id'] = $productOrder::Giveaway;
|
|
|
+ $order_data['status'] = $productOrder::Paid;
|
|
|
+ $order_data['area_id'] = $order_info['area_id'];
|
|
|
+ $order_data['order_no'] = getOrderSN('G');
|
|
|
+ $order_data['user_id'] = $user['id'];
|
|
|
+ $order_data['from_user'] = $this->auth->id;
|
|
|
+ $order_data['price'] = $order_info['price'];
|
|
|
+ $order_data['fees'] = $fees;
|
|
|
+ $order_data['num'] = 1;
|
|
|
+
|
|
|
+ $productOrder::create($order_data);
|
|
|
+
|
|
|
+ //扣除手续费
|
|
|
+ $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$fees, $ledgerWalletModel::Giveaway, $user['id']);
|
|
|
+
|
|
|
+ $order_info->status= $productOrder::Closure;
|
|
|
+ $order_info->save();
|
|
|
+
|
|
|
+ // 提交事务
|
|
|
+ Db::commit();
|
|
|
+ } catch (Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ Db::rollback();
|
|
|
+ $this->error( $e->getMessage());
|
|
|
+ }
|
|
|
+ $this->success('ok');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//取消转让
|
|
|
public function cancel(ProductOrder $productOrder, ProductTransfer $productTransfer)
|
|
|
{
|
|
|
@@ -209,7 +260,7 @@ class Order extends Api
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
$order_info = $productOrder->where('id', $params['order_id'])->find();
|
|
|
- if(empty($order_info)) throw new Exception( __("参数有误,无可用产品"));
|
|
|
+ if(empty($order_info)) throw new Exception(__("参数有误,无可用产品"));
|
|
|
|
|
|
//转让列表取消
|
|
|
$productTransfer::where('order_id',$params['order_id'])->setField('status', $productTransfer::STOP);
|
|
|
@@ -225,6 +276,18 @@ class Order extends Api
|
|
|
$this->success('ok');
|
|
|
}
|
|
|
|
|
|
+ //查看快递信息
|
|
|
+ public function getTracking(UserArea $userArea)
|
|
|
+ {
|
|
|
+ $order_id = $this->request->post('order_id'); // 订单id
|
|
|
+ if(empty($order_id)) $this->error(__("参数有误,无可用产品"));
|
|
|
+
|
|
|
+ $tracking_no = $userArea->where('order_id', $order_id)->value('tracking_no');
|
|
|
+ if(empty($tracking_no)) $this->error(__("暂无物流信息"));
|
|
|
+
|
|
|
+ $this->success('ok', $tracking_no);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 更新订单hash
|