返回数据

This commit is contained in:
liu 2024-03-18 16:51:59 +08:00
parent d5d6b6d038
commit 0b901ef84e

View File

@ -12,9 +12,11 @@
namespace app\common\repositories\store\order;
use app\common\dao\store\order\StoreOrderDao;
use app\common\dao\system\financial\FinancialDao;
use app\common\dao\system\financial\FinancialRecordDao;
use app\common\Enum;
use app\common\model\store\order\StoreGroupOrder;
use app\common\model\store\order\StoreGroupOrderOther;
use app\common\model\store\order\StoreOrder;
use app\common\model\store\order\StoreRefundOrder;
use app\common\model\store\product\ProductAttrValue;
@ -2591,6 +2593,13 @@ class StoreOrderRepository extends BaseRepository
return $data;
}
public function beginMerchant($mer_id)
{
$merchant = Merchant::getDB()->where('mer_id',$mer_id)->value('mer_name');
return compact('merchant');
}
public function dealGoodsList($where,$money,$merId)
@ -2834,6 +2843,167 @@ class StoreOrderRepository extends BaseRepository
public function financialVoucher(StoreGroupOrder $groupOrder, $is_combine = 0, $subOrders = [])
{
$groupOrder->append(['user']);
//修改订单状态
Db::startTrans();
try {
$time = date('Y-m-d H:i:s');
$groupOrder->paid = 1;
$groupOrder->pay_time = $time;
$groupOrder->is_combine = $is_combine;
$orderStatus = [];
$groupOrder->append(['orderList.orderProduct']);
$flag = true;
$finance = [];
$profitsharing = [];
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
$financeSn = $financialRecordRepository->getSn();
$userMerchantRepository = app()->make(UserMerchantRepository::class);
$storeOrderProfitsharingRepository = app()->make(StoreOrderProfitsharingRepository::class);
$uid = $groupOrder->uid;
$i = 1;
$isVipCoupon = app()->make(StoreGroupOrderRepository::class)->isVipCoupon($groupOrder);
//订单记录
$storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
$svipDiscount = 0;
$financeDao = new FinancialDao();
foreach ($groupOrder->orderList as $_k => $order) {
if($groupOrder->order_extend){
if($order->order_extend){
$order_extend=$order->order_extend;
}else{
$order_extend=[];
}
$order_extend['corporate_voucher']=$groupOrder->order_extend;
$order->order_extend=json_encode($order_extend,true);
}
$order->paid = 1;
$order->pay_time = $time;
$svipDiscount = bcadd($order->svip_discount, $svipDiscount, 2);
if (isset($subOrders[$order->order_sn])) {
$order->transaction_id = $subOrders[$order->order_sn]['transaction_id'];
}
$presell = false;
// 订单的类型 0 发货 1 自提
if ($order->order_type == 1 && $order->status != 10) {
$order->verify_code = $this->verifyCode();
}
$order->save();
$orderStatus[] = [
'order_id' => $order->order_id,
'order_sn' => $order->order_sn,
'type' => $storeOrderStatusRepository::TYPE_ORDER,
'change_message' => '订单支付成功',
'change_type' => $storeOrderStatusRepository::ORDER_STATUS_PAY_SUCCCESS,
'uid' => $order->uid,
'nickname' => $order->user->nickname,
'user_type' => $storeOrderStatusRepository::U_TYPE_USER,
];
$financeDao->order = $order;
$financeDao->user = $groupOrder->user;
$financialType = $presell ? 'order_presell' : 'order';
// 平台收入流水账单数据
$financeDao->platformIn($order->total_price, $financialType);
if ($order->consumption_money > 0) {
// 平台支出优惠金额
$financeDao->platformOut($order->consumption_money, 'platform_consumption');
}
$_payPrice = bcsub($order->pay_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2);
$orderValidAmount = bcsub($order->total_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2);
if ($presell) {
if (isset($order->orderProduct[0]['cart_info']['presell_extension_one']) && $order->orderProduct[0]['cart_info']['presell_extension_one'] > 0) {
$_payPrice = bcadd($_payPrice, $order->orderProduct[0]['cart_info']['presell_extension_one'], 2);
}
if (isset($order->orderProduct[0]['cart_info']['presell_extension_two']) && $order->orderProduct[0]['cart_info']['presell_extension_two'] > 0) {
$_payPrice = bcadd($_payPrice, $order->orderProduct[0]['cart_info']['presell_extension_two'], 2);
}
}
// 平台支出推广费
$promoter = $order->merchant->promoter();
$promoterCommission = bcmul($orderValidAmount, 0.003, 2);
if (!empty($promoter) && $promoterCommission > 0) {
$financeDao->user = $promoter;
$financeDao->platformOut($promoterCommission, 'commission_to_promoter');
}
// 平台收入手续费
$financeDao->user = $groupOrder->user;
$commission_rate = bcdiv((string)$order['commission_rate'],'100',6);
$platformCommission = bcmul($orderValidAmount, (string)$commission_rate, 2);
if ($commission_rate > 0 && $platformCommission > 0) {
$orderValidAmount = bcsub($orderValidAmount, $platformCommission, 2);
if ($promoterCommission > 0 && !empty($promoter)) {
$platformCommission = bcsub($platformCommission, $promoterCommission, 2);
}
$financeDao->platformIn($platformCommission, 'commission_to_platform', $order['mer_id']);
}
if (!$presell) {
//押金计算
if ($orderValidAmount > 0) {
/** @var MerchantRepository $merchantRepo */
$merchantRepo = app()->make(MerchantRepository::class);
$merchantRepo->merId = $order['mer_id'];
$merchantRepo->forceMargin = false;
[$orderValidAmount, $financeDao] = $merchantRepo->deductDeposit($orderValidAmount, $order, $financeDao);
}
// 商户收入金额
$financeDao->platformOut($orderValidAmount, 'merchant_order', $order['mer_id']);
if (!$is_combine) {
app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $orderValidAmount);
}
// if (!$is_combine) {
// app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $_payPrice);
// }
//短信 订单通知商户
$mer_phone=Db::name('merchant')->where('mer_id',$order->mer_id)->value('mer_phone');
if($mer_phone){
Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'phone' => $mer_phone,'orderId'=>$order->order_id,'id'=>0]);//短信通知
}
}
$userMerchantRepository->updatePayTime($uid, $order->mer_id, $order->pay_price);
SwooleTaskService::merchant('notice', [
'type' => 'new_order',
'data' => [
'title' => '新订单',
'message' => '您有一个新的订单',
'id' => $order->order_id
]
], $order->mer_id);
}
$this->giveIntegral($groupOrder);
$financialRecordRepository->insertAll($finance);
$storeOrderStatusRepository->batchCreateLog($orderStatus);
$groupOrder->save();
Db::commit();
return true;
} catch (\Exception $e) {
Log::error('财务点击支付失败'.$e->getMessage());
// 回滚事务
Db::rollback();
return false;
}
}
}