|
|
@@ -9,7 +9,7 @@ use bizGhs\custom\classes\CustomDebtChangeClass;
|
|
|
use bizGhs\express\classes\GhsDeliveryOrderClass;
|
|
|
use bizGhs\express\services\DadaExpressServices;
|
|
|
use bizGhs\ghs\classes\GhsClass;
|
|
|
-use bizGhs\order\classes\OrderForwardClass;
|
|
|
+use bizGhs\order\classes\NextDayRefundClass;
|
|
|
use bizGhs\order\classes\OrderItemClass;
|
|
|
use bizGhs\order\classes\RefundOrderClass;
|
|
|
use bizHd\purchase\classes\PurchaseClass;
|
|
|
@@ -1286,6 +1286,7 @@ class OrderController extends BaseController
|
|
|
|
|
|
$shopId = $this->shopId;
|
|
|
$customId = $post['customId'] ?? 0;
|
|
|
+ $post['customId'] = $customId;
|
|
|
//开单必须选客户
|
|
|
if (empty($customId)) {
|
|
|
util::fail('请选择客户');
|
|
|
@@ -1562,27 +1563,12 @@ class OrderController extends BaseController
|
|
|
$addPriceMap['risePercent'] = $custom['risePercent'] ?? 0;
|
|
|
|
|
|
$level = $custom['level'] ?? 1;
|
|
|
- $skipLimitBuy = !empty($shop->skCustomId) && intval($shop->skCustomId) == intval($customId);
|
|
|
- $limitBuyCheckList = [];
|
|
|
- foreach ($productList as $currentProduct) {
|
|
|
- $limitBuyCheckList[] = [
|
|
|
- 'id' => $currentProduct['productId'] ?? 0,
|
|
|
- 'bigCount' => $currentProduct['bigNum'] ?? 0,
|
|
|
- 'smallCount' => $currentProduct['smallNum'] ?? 0,
|
|
|
- ];
|
|
|
- }
|
|
|
- $limitBuyInfoList = ProductClass::getLimitBuyInfoByList($limitBuyCheckList, $customId);
|
|
|
- $limitBuyInfoMap = array_column($limitBuyInfoList, null, 'id');
|
|
|
foreach ($productList as $ptKey => $currentProduct) {
|
|
|
$currentPrice = $currentProduct['price'] ?? 0;
|
|
|
$currentId = $currentProduct['productId'] ?? 0;
|
|
|
$systemInfo = $itemInfo[$currentId] ?? [];
|
|
|
$name = $systemInfo['name'] ?? '';
|
|
|
- $limitBuyInfo = $limitBuyInfoMap[$currentId] ?? [];
|
|
|
- $buyNum = $skipLimitBuy ? 0 : ($limitBuyInfo['currentBuyNum'] ?? 0);
|
|
|
- $hasBuyNum = $skipLimitBuy ? 0 : ($limitBuyInfo['hasBuyNum'] ?? 0);
|
|
|
- $totalBuyNum = $skipLimitBuy ? 0 : bcadd($hasBuyNum, $buyNum, 2);
|
|
|
- $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap, 0, $buyNum, $totalBuyNum);
|
|
|
+ $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
|
|
|
|
|
|
if (getenv('YII_ENV') == 'production') {
|
|
|
//苏州小蔡鲜花,几个出车,不能低于原价卖,但可以高于原价卖的
|
|
|
@@ -1689,7 +1675,6 @@ class OrderController extends BaseController
|
|
|
try {
|
|
|
$return = OrderService::createNewOrder($post, $custom, $hasPay);
|
|
|
$transaction->commit();
|
|
|
- ProductClass::clearLimitBuyRollbackSnapshot();
|
|
|
} catch (\Exception $exception) {
|
|
|
if ($transaction->isActive) {
|
|
|
$transaction->rollBack();
|
|
|
@@ -1700,6 +1685,7 @@ class OrderController extends BaseController
|
|
|
// 复杂分支/关键逻辑:优化。直接将创建成功的 $return 赋值给 $order,避免重复 SELECT 销售单
|
|
|
$order = $return;
|
|
|
if (!empty($order)) {
|
|
|
+
|
|
|
//订单发跑腿流程
|
|
|
GhsDeliveryOrderClass::prepareAskData($post, $order);
|
|
|
|
|
|
@@ -1756,7 +1742,6 @@ class OrderController extends BaseController
|
|
|
}
|
|
|
util::success($return);
|
|
|
} catch (\Exception $e) {
|
|
|
- ProductClass::rollbackLimitBuySnapshot();
|
|
|
Yii::error("下单失败原因:" . $e->getMessage());
|
|
|
noticeUtil::push("批发线下开单失败,原因:" . $e->getMessage(), '15280215347');
|
|
|
if (util::isDbConcurrencyException($e)) {
|
|
|
@@ -1767,124 +1752,6 @@ class OrderController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 创建冲销单(金额为负的独立订单)ssh 冲销单功能
|
|
|
- * 独立通道,不复用常规开单主链路(actionCreateOrder->createNewOrder),避免误伤现网正常开单流程。
|
|
|
- * 支持两种入口:
|
|
|
- * 1. 从 selectCustom(forward=1) 自由开单:不传 relateOrderId,不关联具体原订单。
|
|
|
- * 2. 从售后 refund.vue 转入(原订单非当天/欠款已结清):传 relateOrderId,做累计冲销上限校验,
|
|
|
- * 并强制按原订单实际支付方式覆盖 payWay(不信任前端传值)。
|
|
|
- * 资金处理方式(originalRefund/returnBalance)也按原单支付渠道在 OrderService::createForwardOrder 内强制/校验,
|
|
|
- * 不完全信任前端传值:挂账/余额支付强制返充余额;线上支付(微信/支付宝)可二选一原路退回或返充余额。
|
|
|
- */
|
|
|
- public function actionCreateForwardOrder()
|
|
|
- {
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $customId = $post['customId'] ?? 0;
|
|
|
- if (empty($customId)) {
|
|
|
- util::fail('请选择客户');
|
|
|
- }
|
|
|
- $custom = CustomClass::getCustom($customId);
|
|
|
- if (empty($custom)) {
|
|
|
- util::fail('请选客户哦');
|
|
|
- }
|
|
|
- CustomClass::valid($custom, $this->shopId);
|
|
|
-
|
|
|
- $shopAdmin = $this->shopAdmin;
|
|
|
- $shopAdminId = $this->shopAdminId;
|
|
|
- $shopAdminName = $shopAdmin->name ?? '';
|
|
|
-
|
|
|
- //售后转冲销单场景(带relateOrderId/refundOrderId)本质是在做"售后退款审批",
|
|
|
- //权限口径与老的 /refund/create-order、/refund/pass 保持一致,只有超管能操作;
|
|
|
- //不带这两个参数的是"直接开冲销单"(selectCustom->index2->affirmForward),维持原有权限不变。ssh 冲销单功能
|
|
|
- if (!empty($post['relateOrderId']) || !empty($post['refundOrderId'])) {
|
|
|
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
|
|
|
- util::fail('超管才能操作退款');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //防止连点/重复提交
|
|
|
- util::checkRepeatCommit('forward_' . $this->shopId . '_' . $this->adminId . '_' . $customId, 3);
|
|
|
-
|
|
|
- //refundOrderId 场景由 OrderService::createForwardOrder 内部按售后申请明细自动生成商品列表,
|
|
|
- //不需要前端再传product(也不信任前端在这个场景下传的商品,避免和售后申请不一致)
|
|
|
- if (empty($post['refundOrderId'])) {
|
|
|
- $productJson = $post['product'] ?? '';
|
|
|
- $productList = is_string($productJson) ? json_decode($productJson, true) : $productJson;
|
|
|
- if (empty($productList)) {
|
|
|
- util::fail('请选择花材');
|
|
|
- }
|
|
|
- $post['product'] = $productList;
|
|
|
- }
|
|
|
- $post['sjId'] = $this->sjId;
|
|
|
- $post['shopId'] = $this->shopId;
|
|
|
- $post['mainId'] = $this->mainId;
|
|
|
- $post['shopAdminId'] = $shopAdminId;
|
|
|
- $post['shopAdminName'] = $shopAdminName;
|
|
|
-
|
|
|
- $connection = Yii::$app->db;
|
|
|
- $transaction = $connection->beginTransaction();
|
|
|
- try {
|
|
|
- $result = OrderService::createForwardOrder($post, $custom);
|
|
|
- $transaction->commit();
|
|
|
- } catch (\Exception $exception) {
|
|
|
- if ($transaction->isActive) {
|
|
|
- $transaction->rollBack();
|
|
|
- }
|
|
|
- Yii::error('冲销单创建失败原因:' . $exception->getMessage());
|
|
|
- if (util::isDbConcurrencyException($exception)) {
|
|
|
- util::fail('系统繁忙中,请稍后再试');
|
|
|
- }
|
|
|
- throw $exception;
|
|
|
- }
|
|
|
-
|
|
|
- $order = $result['order'];
|
|
|
- util::success([
|
|
|
- 'id' => $order->id,
|
|
|
- 'orderSn' => $order->orderSn,
|
|
|
- 'actPrice' => $order->actPrice,
|
|
|
- 'customName' => $order->customName,
|
|
|
- 'customBalance' => $result['customBalance'],
|
|
|
- 'thirdRefundNo' => $result['thirdRefundNo'] ?? '',
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- //按原销售单查询关联的冲销记录(供售后记录页“冲销记录”展示)ssh 冲销单功能
|
|
|
- public function actionGetForwardListByOrder()
|
|
|
- {
|
|
|
- $get = Yii::$app->request->get();
|
|
|
- $orderSn = $get['orderSn'] ?? '';
|
|
|
- if (empty($orderSn)) {
|
|
|
- util::fail('缺少订单号');
|
|
|
- }
|
|
|
- $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
|
|
|
- if (empty($order)) {
|
|
|
- util::fail('没有找到订单');
|
|
|
- }
|
|
|
- if ($order->mainId != $this->mainId) {
|
|
|
- util::fail('无权查看');
|
|
|
- }
|
|
|
- $list = OrderForwardClass::getByOrderId($order->id);
|
|
|
- if (empty($list)) {
|
|
|
- util::success(['list' => []]);
|
|
|
- }
|
|
|
- $forwardOrderIds = array_unique(array_filter(array_column($list, 'forwardOrderId')));
|
|
|
- $forwardOrderInfo = empty($forwardOrderIds) ? [] : OrderClass::getByIds($forwardOrderIds, null, 'id');
|
|
|
- $data = [];
|
|
|
- foreach ($list as $row) {
|
|
|
- $forwardOrder = $forwardOrderInfo[$row['forwardOrderId']] ?? [];
|
|
|
- $data[] = [
|
|
|
- 'forwardOrderId' => $row['forwardOrderId'],
|
|
|
- 'forwardOrderSn' => $row['forwardOrderSn'],
|
|
|
- 'forwardPrice' => $row['forwardPrice'],
|
|
|
- 'addTime' => $row['addTime'],
|
|
|
- 'shopAdminName' => $forwardOrder['shopAdminName'] ?? '',
|
|
|
- 'forwardStock' => $forwardOrder['forwardStock'] ?? 1,
|
|
|
- ];
|
|
|
- }
|
|
|
- util::success(['list' => $data]);
|
|
|
- }
|
|
|
-
|
|
|
//修改订单 ssh 20210810
|
|
|
public function actionUpdateOrder()
|
|
|
{
|
|
|
@@ -2490,17 +2357,6 @@ class OrderController extends BaseController
|
|
|
$shopBusiness = $shop->business ?? 0;
|
|
|
$info['shopBusiness'] = $shopBusiness;
|
|
|
|
|
|
- //冲销单详情页展示"原单"入口:如果当前订单本身就是一张冲销单(forward==1),
|
|
|
- //反查 xhGhsOrderForward 关联记录拿到原销售单id/单号,供前端跳转查看原单。ssh 冲销单功能
|
|
|
- $forward = $info['forward'] ?? 0;
|
|
|
- if ($forward == 1) {
|
|
|
- $relate = OrderForwardClass::getByForwardOrderId($id);
|
|
|
- if (!empty($relate)) {
|
|
|
- $info['relateOrderId'] = $relate['orderId'] ?? 0;
|
|
|
- $info['relateOrderSn'] = $relate['orderSn'] ?? '';
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
util::success($info);
|
|
|
}
|
|
|
|
|
|
@@ -2835,7 +2691,6 @@ class OrderController extends BaseController
|
|
|
*/
|
|
|
public function actionPrintLog()
|
|
|
{
|
|
|
-
|
|
|
$id = intval(Yii::$app->request->get('id', 0));
|
|
|
if ($id <= 0) {
|
|
|
util::fail('订单id不对');
|
|
|
@@ -3119,7 +2974,10 @@ class OrderController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //应收款统计 ssh 20240528
|
|
|
+ /**
|
|
|
+ * 应收统计:按支付日汇总。
|
|
|
+ * originAmount=未扣隔天;nextDayAmount=隔天售后;amount=已扣隔天(净额)。
|
|
|
+ */
|
|
|
public function actionAccountList()
|
|
|
{
|
|
|
$get = Yii::$app->request->get();
|
|
|
@@ -3146,7 +3004,9 @@ class OrderController extends BaseController
|
|
|
$where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
|
|
|
$orderList = OrderClass::getAllByCondition($where, null, '*');
|
|
|
$list = [];
|
|
|
+ $totalOriginAmount = 0;
|
|
|
$totalAmount = 0;
|
|
|
+ $nextDayDeduct = '0.00';
|
|
|
if (!empty($orderList)) {
|
|
|
foreach ($orderList as $orderInfo) {
|
|
|
$actPrice = $orderInfo['actPrice'] ?? 0;
|
|
|
@@ -3160,16 +3020,54 @@ class OrderController extends BaseController
|
|
|
continue;
|
|
|
}
|
|
|
if (isset($list[$customId])) {
|
|
|
+ $list[$customId]['originAmount'] = bcadd($list[$customId]['originAmount'], $actPrice, 2);
|
|
|
$list[$customId]['amount'] = bcadd($list[$customId]['amount'], $actPrice, 2);
|
|
|
$list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
|
|
|
} else {
|
|
|
$name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
|
|
|
- $list[$customId] = ['id' => $customId, 'name' => $name, 'amount' => $actPrice, 'num' => 1];
|
|
|
+ $list[$customId] = [
|
|
|
+ 'id' => $customId,
|
|
|
+ 'name' => $name,
|
|
|
+ 'originAmount' => $actPrice,
|
|
|
+ 'amount' => $actPrice,
|
|
|
+ 'num' => 1,
|
|
|
+ 'nextDayAmount' => '0.00',
|
|
|
+ ];
|
|
|
}
|
|
|
+ $totalOriginAmount = bcadd($totalOriginAmount, $actPrice, 2);
|
|
|
$totalAmount = bcadd($totalAmount, $actPrice, 2);
|
|
|
}
|
|
|
- $list = array_values($list);
|
|
|
}
|
|
|
+
|
|
|
+ // 隔天售后:只扣 amount,originAmount 保持未扣口径
|
|
|
+ $fwdMap = NextDayRefundClass::sumAmountGroupByCustom($mainId, $currentStartTime, $currentEndTime);
|
|
|
+ foreach ($fwdMap as $cid => $amt) {
|
|
|
+ if (bccomp((string)$amt, '0', 2) == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!isset($list[$cid])) {
|
|
|
+ $list[$cid] = [
|
|
|
+ 'id' => $cid,
|
|
|
+ 'name' => $customList[$cid]['name'] ?? '未命名',
|
|
|
+ 'originAmount' => '0.00',
|
|
|
+ 'amount' => '0.00',
|
|
|
+ 'num' => 0,
|
|
|
+ 'nextDayAmount' => '0.00',
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if (!isset($list[$cid]['originAmount'])) {
|
|
|
+ $list[$cid]['originAmount'] = (string)($list[$cid]['amount'] ?? '0');
|
|
|
+ }
|
|
|
+ if (!isset($list[$cid]['nextDayAmount'])) {
|
|
|
+ $list[$cid]['nextDayAmount'] = '0.00';
|
|
|
+ }
|
|
|
+ $list[$cid]['amount'] = bcsub((string)$list[$cid]['amount'], (string)$amt, 2);
|
|
|
+ $list[$cid]['nextDayAmount'] = bcadd((string)$list[$cid]['nextDayAmount'], (string)$amt, 2);
|
|
|
+ $totalAmount = bcsub((string)$totalAmount, (string)$amt, 2);
|
|
|
+ $nextDayDeduct = bcadd($nextDayDeduct, (string)$amt, 2);
|
|
|
+ }
|
|
|
+ $list = array_values($list);
|
|
|
+
|
|
|
if ($export == 1) {
|
|
|
if (empty($list)) {
|
|
|
util::fail('没有数据需要导出');
|
|
|
@@ -3179,7 +3077,12 @@ class OrderController extends BaseController
|
|
|
OrderClass::exportAccountList($list, $mainId);
|
|
|
util::stop();
|
|
|
}
|
|
|
- util::success(['list' => $list, 'totalAmount' => $totalAmount]);
|
|
|
+ util::success([
|
|
|
+ 'list' => $list,
|
|
|
+ 'totalOriginAmount' => $totalOriginAmount,
|
|
|
+ 'totalAmount' => $totalAmount,
|
|
|
+ 'nextDayDeduct' => floatval($nextDayDeduct),
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -3221,7 +3124,10 @@ class OrderController extends BaseController
|
|
|
}
|
|
|
|
|
|
|
|
|
- //客户业绩,有多个地方,需要同步,搜索关键词 customYj ssh 20240628
|
|
|
+ /**
|
|
|
+ * 客户业绩(PC):按支付日汇总开单;隔天售后按通过日扣实际金额并计入退款。
|
|
|
+ * 与小程序 statCustomCg 同步,搜索关键词 customYj。
|
|
|
+ */
|
|
|
public function actionYj()
|
|
|
{
|
|
|
$get = Yii::$app->request->get();
|
|
|
@@ -3383,6 +3289,7 @@ class OrderController extends BaseController
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
+ // 有开单时补全无单客户行,便于与隔天负金额行一并展示
|
|
|
foreach ($customList as $key => $custom) {
|
|
|
$customId = $custom['id'] ?? 0;
|
|
|
if (isset($list[$customId]) == false) {
|
|
|
@@ -3393,6 +3300,7 @@ class OrderController extends BaseController
|
|
|
'actPrice' => 0,
|
|
|
'num' => 0,
|
|
|
'carton' => 0,
|
|
|
+ 'cartonNum' => 0,
|
|
|
'pack' => 0,
|
|
|
'freight' => 0,
|
|
|
'tkPrice' => 0,
|
|
|
@@ -3400,8 +3308,45 @@ class OrderController extends BaseController
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
- $list = array_values($list);
|
|
|
}
|
|
|
+
|
|
|
+ // 隔天售后:按通过日扣实际金额、计入退款;无当日开单也建负行;订单笔数不减
|
|
|
+ $fwdMap = NextDayRefundClass::sumAmountGroupByCustom($mainId, $currentStartTime, $currentEndTime);
|
|
|
+ $nextDayDeduct = '0.00';
|
|
|
+ foreach ($fwdMap as $cid => $amt) {
|
|
|
+ if (bccomp((string)$amt, '0', 2) == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!isset($list[$cid])) {
|
|
|
+ $list[$cid] = [
|
|
|
+ 'id' => $cid,
|
|
|
+ 'name' => $customList[$cid]['name'] ?? '未命名',
|
|
|
+ 'mobile' => $customList[$cid]['mobile'] ?? '0',
|
|
|
+ 'actPrice' => 0,
|
|
|
+ 'num' => 0,
|
|
|
+ 'carton' => 0,
|
|
|
+ 'cartonNum' => 0,
|
|
|
+ 'pack' => 0,
|
|
|
+ 'freight' => 0,
|
|
|
+ 'tkPrice' => 0,
|
|
|
+ 'orderPrice' => 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $list[$cid]['actPrice'] = bcsub((string)$list[$cid]['actPrice'], (string)$amt, 2);
|
|
|
+ // 退款列含隔天通过金额,便于与实际金额对照
|
|
|
+ $list[$cid]['tkPrice'] = bcadd((string)$list[$cid]['tkPrice'], (string)$amt, 2);
|
|
|
+ $totalActPrice = bcsub((string)$totalActPrice, (string)$amt, 2);
|
|
|
+ $totalTkPrice = bcadd((string)$totalTkPrice, (string)$amt, 2);
|
|
|
+ $nextDayDeduct = bcadd($nextDayDeduct, (string)$amt, 2);
|
|
|
+ }
|
|
|
+ // 隔天仅退款并入「仅退款」合计(当天仅退款已在开单循环统计)
|
|
|
+ $totalOnlyTkPrice = bcadd(
|
|
|
+ (string)$totalOnlyTkPrice,
|
|
|
+ NextDayRefundClass::sumMoneyOnlyAmountByMainAndTime($mainId, $currentStartTime, $currentEndTime),
|
|
|
+ 2
|
|
|
+ );
|
|
|
+
|
|
|
+ $list = array_values($list);
|
|
|
if ($export == 1) {
|
|
|
if (empty($list)) {
|
|
|
util::fail('没有数据需要导出');
|
|
|
@@ -3423,6 +3368,7 @@ class OrderController extends BaseController
|
|
|
'totalTkPrice' => $totalTkPrice,
|
|
|
//增加项
|
|
|
'totalOnlyTkPrice' => $totalOnlyTkPrice,
|
|
|
+ 'nextDayDeduct' => floatval($nextDayDeduct),
|
|
|
]);
|
|
|
}
|
|
|
|