修复问题
This commit is contained in:
parent
1cc04fb1ca
commit
a38670d601
@ -62,8 +62,8 @@ return [
|
|||||||
'pay_success_micro_pay' => [\crmeb\listens\pay\OrderMicroPaySuccessListen::class],
|
'pay_success_micro_pay' => [\crmeb\listens\pay\OrderMicroPaySuccessListen::class],
|
||||||
'pay_success_presell' => [\crmeb\listens\pay\PresellPaySuccessListen::class],
|
'pay_success_presell' => [\crmeb\listens\pay\PresellPaySuccessListen::class],
|
||||||
'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class],
|
'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class],
|
||||||
'community_address'=>[\app\listener\CommunityAddress::class],
|
// 'community_address'=>[\app\listener\CommunityAddress::class],
|
||||||
// 'order.paySuccess'=>[\app\listener\OrderPaySuccess::class],
|
'order.paySuccessOrder'=>[\app\listener\paySuccessOrder::class],
|
||||||
'product.create'=>[\app\listener\ProductCreate::class],
|
'product.create'=>[\app\listener\ProductCreate::class],
|
||||||
'product.sell'=>[\app\listener\CloudProduct::class], //商品上下架
|
'product.sell'=>[\app\listener\CloudProduct::class], //商品上下架
|
||||||
],
|
],
|
||||||
|
104
app/listener/paySuccessOrder.php
Normal file
104
app/listener/paySuccessOrder.php
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
declare (strict_types=1);
|
||||||
|
|
||||||
|
namespace app\listener;
|
||||||
|
|
||||||
|
use app\common\model\system\merchant\Merchant;
|
||||||
|
use app\common\repositories\system\merchant\FinancialRecordRepository;
|
||||||
|
use app\common\repositories\system\merchant\MerchantRepository;
|
||||||
|
use crmeb\jobs\AutoMarginJob;
|
||||||
|
use think\facade\Db;
|
||||||
|
use think\facade\Log;
|
||||||
|
use think\facade\Queue;
|
||||||
|
|
||||||
|
class paySuccessOrder
|
||||||
|
{
|
||||||
|
|
||||||
|
public function handle($event)
|
||||||
|
{
|
||||||
|
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
|
||||||
|
$financeSn = $financialRecordRepository->getSn();
|
||||||
|
$merchant = Merchant::find($event['order']['mer_id']);
|
||||||
|
|
||||||
|
if (!$merchant || $merchant['street_id'] == 0) {
|
||||||
|
Log::error('商户地址不存在');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//小组服务团队mer_id
|
||||||
|
$mer_id = Db::name('merchant')->where('type_id', 14)
|
||||||
|
->where('street_id', $merchant['street_id'])
|
||||||
|
->where('status', 1)
|
||||||
|
->where('mer_state', 1)
|
||||||
|
->field('mer_id')->find();
|
||||||
|
//订单购物详情表是否有云仓数据
|
||||||
|
$store_order_product_price = Db::name('store_order_product')->where('order_id', $event['order']['order_id'])
|
||||||
|
->where('is_refund', 0)->where('source', 101)->sum('product_price');
|
||||||
|
if ($store_order_product_price > 0) {
|
||||||
|
$source_id = Db::name('store_order_product')->where('order_id', $event['order']['order_id'])->where('is_refund', 0)->where('source', 101)->value('source_id');
|
||||||
|
$commission_rate = ($event['order']['commission_rate'] / 100);
|
||||||
|
//订单购物详情表云仓数据手续费
|
||||||
|
$_order_rate = bcmul((string)$store_order_product_price, (string)$commission_rate, 2);
|
||||||
|
$this->autoMargin($source_id, $_order_rate, $event['order'], $financeSn);
|
||||||
|
}
|
||||||
|
$nickname=Db::name('nickname')->where('uid',$event['order']['uid'])->value('nickname');
|
||||||
|
//小组服务团队
|
||||||
|
$GroupServiceTeam=bcmul($event['_order_rate'], "0.2", 2);
|
||||||
|
//镇管理人员
|
||||||
|
$TownshipManagement=bcmul($event['_order_rate'], "0.2", 2);
|
||||||
|
$finance[] = [
|
||||||
|
'order_id' => $event['order']['order_id'],
|
||||||
|
'order_sn' => $event['order']['order_sn'],
|
||||||
|
'user_info' => $nickname,
|
||||||
|
'user_id' => $event['order']['uid'],
|
||||||
|
'financial_type' => 'group_service_team',
|
||||||
|
'financial_pm' => 1,
|
||||||
|
'type' => 1,
|
||||||
|
'number' => $GroupServiceTeam,
|
||||||
|
'mer_id' => $event['order']['mer_id'],
|
||||||
|
'financial_record_sn' => $financeSn . 0
|
||||||
|
];
|
||||||
|
$finance[] = [
|
||||||
|
'order_id' => $event['order']['order_id'],
|
||||||
|
'order_sn' => $event['order']['order_sn'],
|
||||||
|
'user_info' => $nickname,
|
||||||
|
'user_id' => $event['order']['uid'],
|
||||||
|
'financial_type' => 'group_service_team',
|
||||||
|
'financial_pm' => 1,
|
||||||
|
'type' => 1,
|
||||||
|
'number' => $TownshipManagement,
|
||||||
|
'mer_id' => $event['order']['mer_id'],
|
||||||
|
'financial_record_sn' => $financeSn . 0
|
||||||
|
];
|
||||||
|
app()->make(MerchantRepository::class)->addLockMoney($mer_id, 'order', $event['order']['order_id'], $GroupServiceTeam);
|
||||||
|
app()->make(MerchantRepository::class)->addLockMoney($mer_id, 'order', $event['order']['order_id'], $TownshipManagement);
|
||||||
|
|
||||||
|
$financialRecordRepository->insertAll($finance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function autoMargin($mer_id, $income, $order, $financeSn)
|
||||||
|
{
|
||||||
|
$merchant = Merchant::find($mer_id);
|
||||||
|
//商户保证金未完全缴纳且设置了自动扣除比例
|
||||||
|
if ($merchant['margin'] > $merchant['paid_margin'] && $merchant['auto_margin_rate'] > 0 && $merchant['auto_margin_rate'] <= 100) {
|
||||||
|
$margin = bcmul($income, (string)$merchant['auto_margin_rate'], 2);
|
||||||
|
$margin = min(bcsub($merchant['margin'], $merchant['paid_margin'], 2), $margin);
|
||||||
|
$income = max(bcsub($income, $margin, 2), 0);
|
||||||
|
$finance[] = [
|
||||||
|
'order_id' => $order->order_id,
|
||||||
|
'order_sn' => $order->order_sn,
|
||||||
|
'user_info' => $order->user->nickname,
|
||||||
|
'user_id' => $order->uid,
|
||||||
|
'financial_type' => 'cloud_merchant_auto_margin',
|
||||||
|
'financial_pm' => 1,
|
||||||
|
'type' => 1,
|
||||||
|
'number' => $margin,
|
||||||
|
'mer_id' => $order->mer_id,
|
||||||
|
'financial_record_sn' => $financeSn . 0
|
||||||
|
];
|
||||||
|
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
|
||||||
|
$financialRecordRepository->insertAll($finance);
|
||||||
|
Queue::push(AutoMarginJob::class, ['merId' => $order->mer_id, 'margin' => $margin]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user