调试平台手续费分润退款
This commit is contained in:
parent
f273ebaafa
commit
7d9aaeda1e
@ -15,23 +15,25 @@ namespace app\common\repositories\system\merchant;
|
|||||||
|
|
||||||
|
|
||||||
use app\common\dao\system\merchant\MerchantDao;
|
use app\common\dao\system\merchant\MerchantDao;
|
||||||
|
use app\common\dao\system\serve\ServeOrderDao;
|
||||||
use app\common\model\store\order\StoreOrder;
|
use app\common\model\store\order\StoreOrder;
|
||||||
use app\common\model\store\product\ProductReply;
|
use app\common\model\store\product\ProductReply;
|
||||||
use app\common\model\system\merchant\Merchant;
|
use app\common\model\system\merchant\Merchant;
|
||||||
use app\common\repositories\BaseRepository;
|
use app\common\repositories\BaseRepository;
|
||||||
use app\common\repositories\store\coupon\StoreCouponRepository;
|
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||||
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
||||||
|
use app\common\repositories\store\order\StoreOrderRepository;
|
||||||
use app\common\repositories\store\product\ProductCopyRepository;
|
use app\common\repositories\store\product\ProductCopyRepository;
|
||||||
use app\common\repositories\store\product\ProductRepository;
|
use app\common\repositories\store\product\ProductRepository;
|
||||||
use app\common\repositories\store\product\SpuRepository;
|
use app\common\repositories\store\product\SpuRepository;
|
||||||
use app\common\repositories\store\shipping\ShippingTemplateRepository;
|
use app\common\repositories\store\shipping\ShippingTemplateRepository;
|
||||||
use app\common\repositories\store\StoreCategoryRepository;
|
use app\common\repositories\store\StoreCategoryRepository;
|
||||||
use app\common\repositories\system\attachment\AttachmentRepository;
|
use app\common\repositories\system\attachment\AttachmentRepository;
|
||||||
|
use app\common\repositories\system\serve\ServeOrderRepository;
|
||||||
use app\common\repositories\user\UserBillRepository;
|
use app\common\repositories\user\UserBillRepository;
|
||||||
use app\common\repositories\user\UserRelationRepository;
|
use app\common\repositories\user\UserRelationRepository;
|
||||||
use app\common\repositories\user\UserVisitRepository;
|
use app\common\repositories\user\UserVisitRepository;
|
||||||
use app\common\repositories\wechat\RoutineQrcodeRepository;
|
use app\common\repositories\wechat\RoutineQrcodeRepository;
|
||||||
use crmeb\jobs\AutoMarginJob;
|
|
||||||
use crmeb\jobs\ClearMerchantStoreJob;
|
use crmeb\jobs\ClearMerchantStoreJob;
|
||||||
use crmeb\services\QrcodeService;
|
use crmeb\services\QrcodeService;
|
||||||
use crmeb\services\UploadService;
|
use crmeb\services\UploadService;
|
||||||
@ -691,7 +693,35 @@ class MerchantRepository extends BaseRepository
|
|||||||
'mer_id' => $this->merId,
|
'mer_id' => $this->merId,
|
||||||
'financial_record_sn' => $financeSn . $index
|
'financial_record_sn' => $financeSn . $index
|
||||||
];
|
];
|
||||||
Queue::push(AutoMarginJob::class, ['merId' => $this->merId, 'margin' => $margin, 'orderId' => $order['order_id']]);
|
|
||||||
|
$orderInfo = [
|
||||||
|
'type_id' => $merchant['type_id'],
|
||||||
|
'is_margin' => $merchant['is_margin'],
|
||||||
|
'margin' => $margin,
|
||||||
|
];
|
||||||
|
$values = [
|
||||||
|
'status' => 1,
|
||||||
|
'is_del' => 0,
|
||||||
|
'mer_id' => $merchant['mer_id'],
|
||||||
|
'type' => ServeOrderRepository::TYPE_MARGIN,
|
||||||
|
'meal_id'=> $merchant['type_id'],
|
||||||
|
'pay_type' => ServeOrderRepository::PAY_TYPE_BALANCE,
|
||||||
|
'order_info' => json_encode($orderInfo,JSON_UNESCAPED_UNICODE),
|
||||||
|
'pay_price' => $margin,
|
||||||
|
'store_order_id' => $order['order_id'],
|
||||||
|
];
|
||||||
|
$values['order_sn'] = app()->make(StoreOrderRepository::class)->getNewOrderId('cs');
|
||||||
|
$values['pay_time'] = date('y_m-d H:i:s', time());
|
||||||
|
if (!app()->make(ServeOrderDao::class)->create($values)) {
|
||||||
|
throw new \Exception('serve_order 保存出错');
|
||||||
|
}
|
||||||
|
$merchant->paid_margin = bcadd($margin, $merchant->paid_margin, 2);
|
||||||
|
$merchant->ot_margin = $merchant->paid_margin;
|
||||||
|
$merchant->is_margin = MerchantRepository::PaidMargin;
|
||||||
|
if ($merchant->save() === false) {
|
||||||
|
throw new \Exception('merchant 保存出错');
|
||||||
|
}
|
||||||
|
|
||||||
return [$income, $finance, true];
|
return [$income, $finance, true];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,95 +27,107 @@ class paySuccessOrder
|
|||||||
$this->event = $event;
|
$this->event = $event;
|
||||||
$this->finance = [];
|
$this->finance = [];
|
||||||
$this->index = 1;
|
$this->index = 1;
|
||||||
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
|
Db::startTrans();
|
||||||
$this->financeSn = $financialRecordRepository->getSn();
|
try {
|
||||||
$merchant = Merchant::find($event['order']['mer_id']);
|
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
|
||||||
|
$this->financeSn = $financialRecordRepository->getSn();
|
||||||
|
$merchant = Merchant::find($event['order']['mer_id']);
|
||||||
|
|
||||||
if (!$merchant || $merchant['street_id'] == 0) {
|
if (!$merchant || $merchant['street_id'] == 0) {
|
||||||
Log::error('商户地址不存在');
|
throw new \Exception('商户地址不存在', 200);
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->streetId = $merchant['street_id'];
|
|
||||||
|
|
||||||
$commission_rate = ($event['order']['commission_rate'] / 100);
|
|
||||||
//该笔订单平台总手续费
|
|
||||||
$this->totalAmount = bcmul((string)$event['order']['total_price'], (string)$commission_rate, 2);
|
|
||||||
$this->remain = $this->totalAmount;
|
|
||||||
|
|
||||||
//镇团队佣金
|
|
||||||
$this->calculate(Merchant::TypeTownServer, 'commission_to_town_rate');
|
|
||||||
//村团队佣金
|
|
||||||
$this->calculate(Merchant::TypeVillageServer, 'commission_to_village_rate');
|
|
||||||
//小组服务团队佣金
|
|
||||||
$this->calculate(Merchant::TypeTeamServer, 'commission_to_service_team_rate');
|
|
||||||
|
|
||||||
//订单购物详情表是否有云仓数据
|
|
||||||
$orderProduct = Db::name('store_order_product')
|
|
||||||
->where('order_id', $event['order']['order_id'])
|
|
||||||
->where('is_refund', 0)
|
|
||||||
->whereIn('source', [StoreCartDao::SOURCE_STORE_CLOUD, StoreCartDao::SOURCE_CLOUD])
|
|
||||||
->group('source_id')
|
|
||||||
->column('source,source_id,sum(product_price) total');
|
|
||||||
foreach ($orderProduct as $item) {
|
|
||||||
$this->totalAmount = bcmul((string)$item['total'], (string)$commission_rate, 2);
|
|
||||||
if ($this->totalAmount <= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
$this->streetId = $merchant['street_id'];
|
||||||
|
|
||||||
//入口商户佣金
|
$commission_rate = ($event['order']['commission_rate'] / 100);
|
||||||
$entryMerId = $item['source_id'];
|
//该笔订单平台总手续费
|
||||||
$entryMerchant = app()->make(MerchantDao::class)->get($entryMerId);
|
$this->totalAmount = bcmul((string)$event['order']['total_price'], (string)$commission_rate, 2);
|
||||||
if ($entryMerchant['type_id'] == Merchant::TypeStore) {
|
$this->remain = $this->totalAmount;
|
||||||
$merchantRate = systemConfig('commission_to_merchant_rate');
|
|
||||||
$merchantAmount = bcmul($this->totalAmount, (string)($merchantRate / 100), 2);
|
//镇团队佣金
|
||||||
if ($merchantAmount > 0) {
|
$this->calculate(Merchant::TypeTownServer, 'commission_to_town_rate');
|
||||||
$this->remain = bcsub($this->remain, $merchantAmount, 2);
|
//村团队佣金
|
||||||
$this->finance[] = [
|
$this->calculate(Merchant::TypeVillageServer, 'commission_to_village_rate');
|
||||||
'order_id' => $this->event['order']['order_id'],
|
//小组服务团队佣金
|
||||||
'order_sn' => $this->event['order']['order_sn'],
|
$this->calculate(Merchant::TypeTeamServer, 'commission_to_service_team_rate');
|
||||||
'user_info' => $this->event['order']->user->nickname,
|
|
||||||
'user_id' => $this->event['order']['uid'],
|
//订单购物详情表是否有云仓数据
|
||||||
'financial_type' => 'commission_to_entry_merchant',
|
$orderProduct = Db::name('store_order_product')
|
||||||
'financial_pm' => 1,
|
->where('order_id', $event['order']['order_id'])
|
||||||
'type' => 1,
|
->where('is_refund', 0)
|
||||||
'number' => $merchantAmount,
|
->whereIn('source', [StoreCartDao::SOURCE_STORE_CLOUD, StoreCartDao::SOURCE_CLOUD])
|
||||||
'mer_id' => $entryMerId,
|
->group('source_id')
|
||||||
'financial_record_sn' => $this->financeSn . $this->index
|
->column('source,source_id,sum(product_price) total');
|
||||||
];
|
foreach ($orderProduct as $item) {
|
||||||
$this->index++;
|
$this->totalAmount = bcmul((string)$item['total'], (string)$commission_rate, 2);
|
||||||
/** @var MerchantRepository $merchantRepo */
|
if ($this->totalAmount <= 0) {
|
||||||
$merchantRepo = app()->make(MerchantRepository::class);
|
continue;
|
||||||
$merchantRepo->merId = $entryMerId;
|
}
|
||||||
$merchantRepo->forceMargin = true;
|
|
||||||
[$merchantAmount, $this->finance, $increase] = $merchantRepo->autoMargin($merchantAmount, $event['order'], $this->finance, $this->financeSn, $this->index);
|
//入口商户佣金
|
||||||
if ($increase) {
|
$entryMerId = $item['source_id'];
|
||||||
$this->index++;
|
$entryMerchant = app()->make(MerchantDao::class)->get($entryMerId);
|
||||||
}
|
if ($entryMerchant['type_id'] == Merchant::TypeStore) {
|
||||||
|
$merchantRate = systemConfig('commission_to_merchant_rate');
|
||||||
|
$merchantAmount = bcmul($this->totalAmount, (string)($merchantRate / 100), 2);
|
||||||
if ($merchantAmount > 0) {
|
if ($merchantAmount > 0) {
|
||||||
app()->make(MerchantRepository::class)->addLockMoney($entryMerId, 'order', $event['order']['order_id'], (float)$merchantAmount);
|
$this->remain = bcsub($this->remain, $merchantAmount, 2);
|
||||||
|
$this->finance[] = [
|
||||||
|
'order_id' => $this->event['order']['order_id'],
|
||||||
|
'order_sn' => $this->event['order']['order_sn'],
|
||||||
|
'user_info' => $this->event['order']->user->nickname,
|
||||||
|
'user_id' => $this->event['order']['uid'],
|
||||||
|
'financial_type' => 'commission_to_entry_merchant',
|
||||||
|
'financial_pm' => 1,
|
||||||
|
'type' => 1,
|
||||||
|
'number' => $merchantAmount,
|
||||||
|
'mer_id' => $entryMerId,
|
||||||
|
'financial_record_sn' => $this->financeSn . $this->index
|
||||||
|
];
|
||||||
|
$this->index++;
|
||||||
|
/** @var MerchantRepository $merchantRepo */
|
||||||
|
$merchantRepo = app()->make(MerchantRepository::class);
|
||||||
|
$merchantRepo->merId = $entryMerId;
|
||||||
|
$merchantRepo->forceMargin = true;
|
||||||
|
[$merchantAmount, $this->finance, $increase] = $merchantRepo->autoMargin($merchantAmount, $event['order'], $this->finance, $this->financeSn, $this->index);
|
||||||
|
if ($increase) {
|
||||||
|
$this->index++;
|
||||||
|
}
|
||||||
|
if ($merchantAmount > 0) {
|
||||||
|
app()->make(MerchantRepository::class)->addLockMoney($entryMerId, 'order', $event['order']['order_id'], (float)$merchantAmount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//云仓佣金
|
||||||
|
$this->calculate(Merchant::TypeCloudWarehouse, 'commission_to_cloud_rate');
|
||||||
}
|
}
|
||||||
|
|
||||||
//云仓佣金
|
//平台佣金
|
||||||
$this->calculate(Merchant::TypeCloudWarehouse, 'commission_to_cloud_rate');
|
$this->finance[] = [
|
||||||
|
'order_id' => $this->event['order']['order_id'],
|
||||||
|
'order_sn' => $this->event['order']['order_sn'],
|
||||||
|
'user_info' => $this->event['order']->user->nickname,
|
||||||
|
'user_id' => $this->event['order']['uid'],
|
||||||
|
'financial_type' => 'commission_to_platform',
|
||||||
|
'financial_pm' => 1,
|
||||||
|
'type' => 1,
|
||||||
|
'number' => $this->remain,
|
||||||
|
'mer_id' => 0,
|
||||||
|
'financial_record_sn' => $this->financeSn . $this->index
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$financialRecordRepository->insertAll($this->finance)) {
|
||||||
|
throw new \Exception('财务流水保存出错');
|
||||||
|
}
|
||||||
|
Db::commit();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
if ($e->getCode() == 200) {
|
||||||
|
Db::commit();
|
||||||
|
} else {
|
||||||
|
Db::rollback();
|
||||||
|
}
|
||||||
|
Log::error('', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//平台佣金
|
|
||||||
$this->finance[] = [
|
|
||||||
'order_id' => $this->event['order']['order_id'],
|
|
||||||
'order_sn' => $this->event['order']['order_sn'],
|
|
||||||
'user_info' => $this->event['order']->user->nickname,
|
|
||||||
'user_id' => $this->event['order']['uid'],
|
|
||||||
'financial_type' => 'commission_to_platform',
|
|
||||||
'financial_pm' => 1,
|
|
||||||
'type' => 1,
|
|
||||||
'number' => $this->remain,
|
|
||||||
'mer_id' => 0,
|
|
||||||
'financial_record_sn' => $this->financeSn . $this->index
|
|
||||||
];
|
|
||||||
|
|
||||||
$financialRecordRepository->insertAll($this->finance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function calculate($type, $field)
|
public function calculate($type, $field)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user