|
|
@ -68,11 +68,11 @@ class VerificationController extends Controller |
|
|
DB::beginTransaction(); |
|
|
DB::beginTransaction(); |
|
|
try { |
|
|
try { |
|
|
//最后批量插入
|
|
|
//最后批量插入
|
|
|
$adminCreate = $statementCreate = []; |
|
|
|
|
|
|
|
|
$statementCreate = []; |
|
|
$cost = 0; |
|
|
$cost = 0; |
|
|
//如果有地接价格 分帐给地接
|
|
|
//如果有地接价格 分帐给地接
|
|
|
if ($order->guide_price > 0) { |
|
|
if ($order->guide_price > 0) { |
|
|
$guidePrice = $order->guide_price; |
|
|
|
|
|
|
|
|
//$guidePrice = $order->guide_price;
|
|
|
$cost = bcadd($cost, $order->guide_price, 6); |
|
|
$cost = bcadd($cost, $order->guide_price, 6); |
|
|
//成本价 加上地接价格
|
|
|
//成本价 加上地接价格
|
|
|
$statementCreate[] = $service->createByOrder( |
|
|
$statementCreate[] = $service->createByOrder( |
|
|
@ -84,34 +84,34 @@ class VerificationController extends Controller |
|
|
StatementTraits::$type[0] |
|
|
StatementTraits::$type[0] |
|
|
); |
|
|
); |
|
|
//抽成
|
|
|
//抽成
|
|
|
if ($order->guide->rate > 0) { |
|
|
|
|
|
//计算抽成金额
|
|
|
|
|
|
$guideCut = bcmul($order->guide_price, $order->guide->rate, 6); |
|
|
|
|
|
$cutPrice = $guideCut > 0 ? bcdiv($guideCut, 100, 6) : 0; |
|
|
|
|
|
//总后台抽成流水
|
|
|
|
|
|
if ($cutPrice > 0) { |
|
|
|
|
|
$adminCreate[] = $service->createByOrderFormAdmin( |
|
|
|
|
|
$cutPrice, |
|
|
|
|
|
StatementType::CUT, |
|
|
|
|
|
$order->guide->id, |
|
|
|
|
|
DemandTraits::$col[2], |
|
|
|
|
|
$order->id, |
|
|
|
|
|
); |
|
|
|
|
|
//地接被抽成流水
|
|
|
|
|
|
$statementCreate[] = $service->createByOrder( |
|
|
|
|
|
bcmul($cutPrice, -1, 2), |
|
|
|
|
|
StatementType::CUT, |
|
|
|
|
|
$order->guide->id, |
|
|
|
|
|
DemandTraits::$col[2], |
|
|
|
|
|
$order->id, |
|
|
|
|
|
StatementTraits::$type[0] |
|
|
|
|
|
); |
|
|
|
|
|
$guidePrice = bcsub($order->guide_price, $cutPrice, 6); |
|
|
|
|
|
$guide = Guide::query()->where('id', $order->guide->id)->lockForUpdate()->first(); |
|
|
|
|
|
$guide->balance = bcadd($guide->balance, $guidePrice, 6); |
|
|
|
|
|
$guide->save(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//if ($order->guide->rate > 0) {
|
|
|
|
|
|
// //计算抽成金额
|
|
|
|
|
|
// $guideCut = bcmul($order->guide_price, $order->guide->rate, 6);
|
|
|
|
|
|
// $cutPrice = $guideCut > 0 ? bcdiv($guideCut, 100, 6) : 0;
|
|
|
|
|
|
// //总后台抽成流水
|
|
|
|
|
|
// if ($cutPrice > 0) {
|
|
|
|
|
|
// $adminCreate[] = $service->createByOrderFormAdmin(
|
|
|
|
|
|
// $cutPrice,
|
|
|
|
|
|
// StatementType::CUT,
|
|
|
|
|
|
// $order->guide->id,
|
|
|
|
|
|
// DemandTraits::$col[2],
|
|
|
|
|
|
// $order->id,
|
|
|
|
|
|
// );
|
|
|
|
|
|
// //地接被抽成流水
|
|
|
|
|
|
// $statementCreate[] = $service->createByOrder(
|
|
|
|
|
|
// bcmul($cutPrice, -1, 2),
|
|
|
|
|
|
// StatementType::CUT,
|
|
|
|
|
|
// $order->guide->id,
|
|
|
|
|
|
// DemandTraits::$col[2],
|
|
|
|
|
|
// $order->id,
|
|
|
|
|
|
// StatementTraits::$type[0]
|
|
|
|
|
|
// );
|
|
|
|
|
|
// $guidePrice = bcsub($order->guide_price, $cutPrice, 6);
|
|
|
|
|
|
// $guide = Guide::query()->where('id', $order->guide->id)->lockForUpdate()->first();
|
|
|
|
|
|
// $guide->balance = bcadd($guide->balance, $guidePrice, 6);
|
|
|
|
|
|
// $guide->save();
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//分账给供应商
|
|
|
//分账给供应商
|
|
|
@ -119,7 +119,7 @@ class VerificationController extends Controller |
|
|
->where('order_id', $order->id) |
|
|
->where('order_id', $order->id) |
|
|
->with('supplier') |
|
|
->with('supplier') |
|
|
->select('*') |
|
|
->select('*') |
|
|
->selectRaw('sum(price) as sum_price') |
|
|
|
|
|
|
|
|
->selectRaw('sum(price) as sum_price,sum(service_persons) as sum_persons') |
|
|
->groupBy('supplier_id') |
|
|
->groupBy('supplier_id') |
|
|
->get(); |
|
|
->get(); |
|
|
foreach ($orderItem as $v) { |
|
|
foreach ($orderItem as $v) { |
|
|
@ -135,33 +135,52 @@ class VerificationController extends Controller |
|
|
StatementTraits::$type[0] |
|
|
StatementTraits::$type[0] |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if ($v->supplier->rate > 0) { |
|
|
|
|
|
//计算抽成金额
|
|
|
|
|
|
$supplierCut = bcmul($v->sum_price, $v->supplier->rate, 6); |
|
|
|
|
|
$cutPrice = $supplierCut > 0 ? bcdiv($supplierCut, 100, 6) : 0; |
|
|
|
|
|
if ($cutPrice > 0) { |
|
|
|
|
|
//总后台抽成流水
|
|
|
|
|
|
$adminCreate[] = $service->createByOrderFormAdmin( |
|
|
|
|
|
$cutPrice, |
|
|
|
|
|
StatementType::CUT, |
|
|
|
|
|
$v->supplier_id, |
|
|
|
|
|
DemandTraits::$col[1], |
|
|
|
|
|
$order->id, |
|
|
|
|
|
); |
|
|
|
|
|
//供应商被抽成流水
|
|
|
|
|
|
$statementCreate[] = $service->createByOrder( |
|
|
|
|
|
bcmul($cutPrice, -1, 6), |
|
|
|
|
|
StatementType::CUT, |
|
|
|
|
|
$v->supplier_id, |
|
|
|
|
|
DemandTraits::$col[1], |
|
|
|
|
|
$order->id, |
|
|
|
|
|
StatementTraits::$type[0] |
|
|
|
|
|
); |
|
|
|
|
|
$supplierPrice = bcsub($supplierPrice, $cutPrice, 6); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//if ($v->supplier->rate > 0) {
|
|
|
|
|
|
// //计算抽成金额
|
|
|
|
|
|
// $supplierCut = bcmul($v->sum_price, $v->supplier->rate, 6);
|
|
|
|
|
|
// $cutPrice = $supplierCut > 0 ? bcdiv($supplierCut, 100, 6) : 0;
|
|
|
|
|
|
// if ($cutPrice > 0) {
|
|
|
|
|
|
// //总后台抽成流水
|
|
|
|
|
|
// $adminCreate[] = $service->createByOrderFormAdmin(
|
|
|
|
|
|
// $cutPrice,
|
|
|
|
|
|
// StatementType::CUT,
|
|
|
|
|
|
// $v->supplier_id,
|
|
|
|
|
|
// DemandTraits::$col[1],
|
|
|
|
|
|
// $order->id,
|
|
|
|
|
|
// );
|
|
|
|
|
|
// //供应商被抽成流水
|
|
|
|
|
|
// $statementCreate[] = $service->createByOrder(
|
|
|
|
|
|
// bcmul($cutPrice, -1, 6),
|
|
|
|
|
|
// StatementType::CUT,
|
|
|
|
|
|
// $v->supplier_id,
|
|
|
|
|
|
// DemandTraits::$col[1],
|
|
|
|
|
|
// $order->id,
|
|
|
|
|
|
// StatementTraits::$type[0]
|
|
|
|
|
|
// );
|
|
|
|
|
|
// $supplierPrice = bcsub($supplierPrice, $cutPrice, 6);
|
|
|
|
|
|
//
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
$supplier = Supplier::query()->where('id', $v->supplier_id)->lockForUpdate()->first(); |
|
|
$supplier = Supplier::query()->where('id', $v->supplier_id)->lockForUpdate()->first(); |
|
|
|
|
|
|
|
|
|
|
|
//处理交易金
|
|
|
|
|
|
if ($order->single_price > 0) { |
|
|
|
|
|
//计算交易金
|
|
|
|
|
|
$deposit = bcmul($order->single_price,$v->sum_persons,6); |
|
|
|
|
|
//流水
|
|
|
|
|
|
$statementCreate[] = $service->createByOrder( |
|
|
|
|
|
$deposit, |
|
|
|
|
|
StatementType::DEPOSIT, |
|
|
|
|
|
$v->supplier_id, |
|
|
|
|
|
DemandTraits::$col[1], |
|
|
|
|
|
$order->id, |
|
|
|
|
|
StatementTraits::$type[0] |
|
|
|
|
|
); |
|
|
|
|
|
//扣
|
|
|
|
|
|
$supplierPrice = bcsub($supplierPrice,$deposit,6); |
|
|
|
|
|
$supplier->balance = bcadd($supplier->deposit_used, $supplierPrice, 6); |
|
|
|
|
|
$supplier->balance = bcsub($supplier->deposit_frozen, $supplierPrice, 6); |
|
|
|
|
|
} |
|
|
$supplier->balance = bcadd($supplier->balance, $supplierPrice, 6); |
|
|
$supplier->balance = bcadd($supplier->balance, $supplierPrice, 6); |
|
|
$supplier->save(); |
|
|
$supplier->save(); |
|
|
} |
|
|
} |
|
|
@ -170,62 +189,62 @@ class VerificationController extends Controller |
|
|
//成本价 加上地接价格
|
|
|
//成本价 加上地接价格
|
|
|
$agentPrice = bcsub($order->price, $cost, 2); |
|
|
$agentPrice = bcsub($order->price, $cost, 2); |
|
|
|
|
|
|
|
|
if ($agentPrice > 0) { |
|
|
|
|
|
$statementCreate[] = $service->createByOrder( |
|
|
|
|
|
$agentPrice, |
|
|
|
|
|
StatementType::ORDER, |
|
|
|
|
|
$order->agent_id, |
|
|
|
|
|
DemandTraits::$col[0], |
|
|
|
|
|
$order->id, |
|
|
|
|
|
StatementTraits::$type[0] |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
//抽成
|
|
|
|
|
|
if ($order->agent->rate > 0) { |
|
|
|
|
|
//计算抽成金额
|
|
|
|
|
|
$agentCut = bcmul($agentPrice, $order->agent->rate, 6); |
|
|
|
|
|
$cutPrice = $agentCut > 0 ? bcdiv($agentCut, 100, 6) : 0; |
|
|
|
|
|
|
|
|
|
|
|
//总后台抽成流水
|
|
|
|
|
|
if ($cutPrice > 0) { |
|
|
|
|
|
$adminCreate[] = $service->createByOrderFormAdmin( |
|
|
|
|
|
$cutPrice, |
|
|
|
|
|
StatementType::CUT, |
|
|
|
|
|
$order->agent->id, |
|
|
|
|
|
DemandTraits::$col[0], |
|
|
|
|
|
$order->id, |
|
|
|
|
|
); |
|
|
|
|
|
//代理商被抽成流水
|
|
|
|
|
|
$statementCreate[] = $service->createByOrder( |
|
|
|
|
|
bcmul($cutPrice, -1, 6), |
|
|
|
|
|
StatementType::CUT, |
|
|
|
|
|
$order->agent->id, |
|
|
|
|
|
DemandTraits::$col[0], |
|
|
|
|
|
$order->id, |
|
|
|
|
|
StatementTraits::$type[0] |
|
|
|
|
|
); |
|
|
|
|
|
$agentPrice = bcsub($agentPrice, $cutPrice, 6); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$statementCreate[] = $service->createByOrder( |
|
|
|
|
|
$agentPrice, |
|
|
|
|
|
StatementType::ORDER, |
|
|
|
|
|
$order->agent_id, |
|
|
|
|
|
DemandTraits::$col[0], |
|
|
|
|
|
$order->id, |
|
|
|
|
|
StatementTraits::$type[0] |
|
|
|
|
|
); |
|
|
|
|
|
//
|
|
|
|
|
|
////抽成
|
|
|
|
|
|
//if ($order->agent->rate > 0) {
|
|
|
|
|
|
// //计算抽成金额
|
|
|
|
|
|
// $agentCut = bcmul($agentPrice, $order->agent->rate, 6);
|
|
|
|
|
|
// $cutPrice = $agentCut > 0 ? bcdiv($agentCut, 100, 6) : 0;
|
|
|
|
|
|
//
|
|
|
|
|
|
// //总后台抽成流水
|
|
|
|
|
|
// if ($cutPrice > 0) {
|
|
|
|
|
|
// $adminCreate[] = $service->createByOrderFormAdmin(
|
|
|
|
|
|
// $cutPrice,
|
|
|
|
|
|
// StatementType::CUT,
|
|
|
|
|
|
// $order->agent->id,
|
|
|
|
|
|
// DemandTraits::$col[0],
|
|
|
|
|
|
// $order->id,
|
|
|
|
|
|
// );
|
|
|
|
|
|
// //代理商被抽成流水
|
|
|
|
|
|
// $statementCreate[] = $service->createByOrder(
|
|
|
|
|
|
// bcmul($cutPrice, -1, 6),
|
|
|
|
|
|
// StatementType::CUT,
|
|
|
|
|
|
// $order->agent->id,
|
|
|
|
|
|
// DemandTraits::$col[0],
|
|
|
|
|
|
// $order->id,
|
|
|
|
|
|
// StatementTraits::$type[0]
|
|
|
|
|
|
// );
|
|
|
|
|
|
// $agentPrice = bcsub($agentPrice, $cutPrice, 6);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//扣除微信支付手续费
|
|
|
//扣除微信支付手续费
|
|
|
$chargePrice = bcmul($order->price, 0.006, 6); |
|
|
|
|
|
$statementCreate[] = $service->createByOrder( |
|
|
|
|
|
bcmul($chargePrice, -1, 6), |
|
|
|
|
|
StatementType::CHARGE, |
|
|
|
|
|
$order->agent_id, |
|
|
|
|
|
DemandTraits::$col[0], |
|
|
|
|
|
$order->id, |
|
|
|
|
|
StatementTraits::$type[0] |
|
|
|
|
|
); |
|
|
|
|
|
$agentPrice = bcsub($agentPrice, $chargePrice, 6); |
|
|
|
|
|
|
|
|
//$chargePrice = bcmul($order->price, 0.006, 6);
|
|
|
|
|
|
//$statementCreate[] = $service->createByOrder(
|
|
|
|
|
|
// bcmul($chargePrice, -1, 6),
|
|
|
|
|
|
// StatementType::CHARGE,
|
|
|
|
|
|
// $order->agent_id,
|
|
|
|
|
|
// DemandTraits::$col[0],
|
|
|
|
|
|
// $order->id,
|
|
|
|
|
|
// StatementTraits::$type[0]
|
|
|
|
|
|
//);
|
|
|
|
|
|
//$agentPrice = bcsub($agentPrice, $chargePrice, 6);
|
|
|
$agent = Agent::query()->where('id', $order->agent->id)->lockForUpdate()->first(); |
|
|
$agent = Agent::query()->where('id', $order->agent->id)->lockForUpdate()->first(); |
|
|
$agent->balance = bcadd($agent->balance, $agentPrice, 6); |
|
|
$agent->balance = bcadd($agent->balance, $agentPrice, 6); |
|
|
$agent->save(); |
|
|
$agent->save(); |
|
|
} |
|
|
|
|
|
if (!empty($adminCreate)) { |
|
|
|
|
|
$order->statementAdmin()->createMany($adminCreate); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
//if (!empty($adminCreate)) {
|
|
|
|
|
|
// $order->statementAdmin()->createMany($adminCreate);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
if (!empty($statementCreate)) { |
|
|
if (!empty($statementCreate)) { |
|
|
$order->statement()->createMany($statementCreate); |
|
|
$order->statement()->createMany($statementCreate); |
|
|
|