|
@@ -14,9 +14,12 @@
|
|
|
namespace app\controller\api\store\order;
|
|
|
|
|
|
|
|
|
+use app\common\model\user\User;
|
|
|
use app\common\repositories\delivery\DeliveryOrderRepository;
|
|
|
use app\common\repositories\store\order\StoreOrderCreateRepository;
|
|
|
use app\common\repositories\store\order\StoreOrderReceiptRepository;
|
|
|
+use app\common\repositories\user\UserBillRepository;
|
|
|
+use app\common\repositories\user\UserRepository;
|
|
|
use app\validate\api\UserReceiptValidate;
|
|
|
use crmeb\basic\BaseController;
|
|
|
use app\common\repositories\store\order\StoreCartRepository;
|
|
@@ -305,4 +308,49 @@ class StoreOrder extends BaseController
|
|
|
$res = $orderRepository->show($id, $this->request->uid());
|
|
|
return app('json')->success($res);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @param $id
|
|
|
+ * @return mixed
|
|
|
+ * @author xaboy
|
|
|
+ * @day 2020/6/10
|
|
|
+ */
|
|
|
+ public function final_payment(UserRepository $repository,User $user)
|
|
|
+ {
|
|
|
+ $payType = $this->request->param('pay_type');
|
|
|
+ $id = $this->request->param('id');
|
|
|
+ if(empty($payType) || empty($id)){
|
|
|
+ return app('json')->fail('参数错误');
|
|
|
+ }
|
|
|
+ $order = $this->repository->getDetail((int)$id, $this->request->uid());
|
|
|
+ if (!$order)
|
|
|
+ return app('json')->fail('订单不存在');
|
|
|
+ if ($order->status != 4 || $order->residue_percentage <= 0) {
|
|
|
+ return app('json')->fail('订单信息有误');
|
|
|
+ }
|
|
|
+ $pay_money = sprintf('%.2f',$order->residue_percentage * $order->total_price / 100);
|
|
|
+ if($pay_money <= 0){
|
|
|
+ return app('json')->fail('支付金额不正确');
|
|
|
+ }
|
|
|
+ if($payType == 'balance'){
|
|
|
+ if (!systemConfig('yue_pay_status'))
|
|
|
+ throw new ValidateException('未开启余额支付');
|
|
|
+ if ($user['now_money'] < $pay_money)
|
|
|
+ throw new ValidateException('余额不足,请更换支付方式');
|
|
|
+ $user->now_money = bcsub($user->now_money, $pay_money, 2);
|
|
|
+ $user->save();
|
|
|
+ $userBillRepository = app()->make(UserBillRepository::class);
|
|
|
+ $userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [
|
|
|
+ 'link_id' => $id,
|
|
|
+ 'status' => 1,
|
|
|
+ 'title' => '购买商品支付尾款',
|
|
|
+ 'number' => $pay_money,
|
|
|
+ 'mark' => '余额支付支付' . floatval($pay_money) . '元支付改订单尾款',
|
|
|
+ 'balance' => $user->now_money
|
|
|
+ ]);
|
|
|
+ //更改订单状态
|
|
|
+ $order->status = 0;
|
|
|
+ $order->save();
|
|
|
+ }
|
|
|
+ return app('json')->success('支付成功');
|
|
|
+ }
|
|
|
}
|