|
|
@@ -24,12 +24,11 @@ class SettleController extends BaseController
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
try {
|
|
|
-
|
|
|
$staff = $this->shopAdmin;
|
|
|
$payWay = $post['payWay'] ?? dict::getDict('payWay', 'wxPay');
|
|
|
$idData = $post['id'] ?? '';
|
|
|
if (is_numeric($idData)) {
|
|
|
- util::fail('请求参数错误');
|
|
|
+ util::fail('请求参数错误哦');
|
|
|
}
|
|
|
$customId = $post['customId'] ?? 0;
|
|
|
$custom = CustomClass::getLockById($customId);
|
|
|
@@ -41,34 +40,49 @@ class SettleController extends BaseController
|
|
|
if (empty($hd)) {
|
|
|
util::fail('客户信息缺失');
|
|
|
}
|
|
|
-
|
|
|
- //1、先充值
|
|
|
- $rechargeAmount = 0;
|
|
|
- if (is_numeric($id)) {
|
|
|
- $order = OrderClass::getById($id, true);
|
|
|
- $rechargeAmount = $order->remainDebtPrice ?? 0;
|
|
|
- } else {
|
|
|
- $idArr = json_decode($id, true);
|
|
|
- $ids = array_column($idArr, 'id');
|
|
|
- $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
|
|
|
- if (!empty($orderList)) {
|
|
|
- foreach ($orderList as $order) {
|
|
|
- $remainDebtPrice = $order->remainDebtPrice ?? 0;
|
|
|
- $rechargeAmount = bcadd($rechargeAmount, $remainDebtPrice, 2);
|
|
|
- }
|
|
|
+ //先充值
|
|
|
+ $mayClearAmount = 0;
|
|
|
+ $idList = json_decode($idData, true);
|
|
|
+ $ids = array_column($idList, 'id');
|
|
|
+ if (empty($ids)) {
|
|
|
+ util::fail('请选择订单');
|
|
|
+ }
|
|
|
+ $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
|
|
|
+ if (empty($orderList)) {
|
|
|
+ util::fail('请选择订单呢');
|
|
|
+ }
|
|
|
+ foreach ($orderList as $order) {
|
|
|
+ if ($order->mainId != $this->mainId) {
|
|
|
+ util::fail('不是你的订单哦');
|
|
|
}
|
|
|
+ $remainDebtPrice = $order->remainDebtPrice ?? 0;
|
|
|
+ $mayClearAmount = bcadd($mayClearAmount, $remainDebtPrice, 2);
|
|
|
}
|
|
|
- if (empty($rechargeAmount)) {
|
|
|
+ if (empty($mayClearAmount)) {
|
|
|
util::fail('不需要销账');
|
|
|
}
|
|
|
$staffId = $this->shopAdminId;
|
|
|
$staffName = $this->shopAdminName;
|
|
|
$customName = $custom->name ?? '';
|
|
|
+ $userId = $custom->userId;
|
|
|
$hdName = $hd->name;
|
|
|
$shopId = $this->shopId;
|
|
|
$mainId = $this->mainId;
|
|
|
$orderSn = orderSn::getRechargeSn();
|
|
|
- $rechargeData = [
|
|
|
+ $shop = $this->shop;
|
|
|
+ $settleParams = [];
|
|
|
+
|
|
|
+ $hasSettle = SettleClass::getByCondition(['customId' => $customId, 'status' => 1], true);
|
|
|
+ if (!empty($hasSettle)) {
|
|
|
+ util::fail('这个客户名下有待结账单,请先取消');
|
|
|
+ }
|
|
|
+
|
|
|
+ //创建待账单
|
|
|
+ $settle = SettleClass::addSettle(0, $orderList, $shop, $custom, $hd, $staff, $settleParams);
|
|
|
+ $settleId = $settle->id;
|
|
|
+ $settleAmount = $settle->actPrice;
|
|
|
+
|
|
|
+ $addData = [
|
|
|
'orderSn' => $orderSn,
|
|
|
'modPrice' => 1,
|
|
|
'payWay' => $payWay,
|
|
|
@@ -78,38 +92,25 @@ class SettleController extends BaseController
|
|
|
'hdId' => $hdId,
|
|
|
'hdName' => $hdName,
|
|
|
'onlinePay' => 1,
|
|
|
- 'amount' => $rechargeAmount,
|
|
|
+ 'amount' => $mayClearAmount,
|
|
|
'staffId' => $staffId,
|
|
|
'staffName' => $staffName,
|
|
|
'payStatus' => 0,
|
|
|
'payTime' => '0000-00-00 00:00:00',
|
|
|
'status' => 0,
|
|
|
+ 'clearId' => $settleId,
|
|
|
+ 'clearAmount' => $settleAmount,
|
|
|
'remark' => '',
|
|
|
'customId' => $customId,
|
|
|
'customName' => $customName,
|
|
|
+ 'userId' => $userId,
|
|
|
];
|
|
|
- $respond = RechargeClass::addRecharge($rechargeData);
|
|
|
+ $respond = RechargeClass::addRecharge($addData);
|
|
|
$retId = $respond->id;
|
|
|
+ //充值成功并且销账成功
|
|
|
$recharge = RechargeClass::getLockById($retId);
|
|
|
$params = ['onlinePay' => 1, 'side' => 0];
|
|
|
RechargeClass::complete($recharge, $payWay, $params);
|
|
|
-
|
|
|
- //2、再销账
|
|
|
- $idArr = json_decode($idData, true);
|
|
|
- $ids = array_column($idArr, 'id');
|
|
|
- $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
|
|
|
- if (!empty($orderList)) {
|
|
|
- foreach ($orderList as $order) {
|
|
|
- if (empty($order)) {
|
|
|
- util::fail('没有找到订单呢');
|
|
|
- }
|
|
|
- if ($order->mainId != $this->mainId) {
|
|
|
- util::fail('不是你的订单');
|
|
|
- }
|
|
|
- SettleClass::confirmSettle($order, $payWay, $staff);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
$transaction->commit();
|
|
|
util::complete();
|
|
|
} catch (\Exception $exception) {
|