diff --git a/app/Common/StatementType.php b/app/Common/StatementType.php index 496a9ea..8507135 100644 --- a/app/Common/StatementType.php +++ b/app/Common/StatementType.php @@ -23,6 +23,9 @@ class StatementType /** @var int 退款 */ const REFUND = 6; + /** @var int 交易金 */ + const DEPOSIT = 7; + public static function array(): array { return [ @@ -32,6 +35,7 @@ class StatementType self::WITHDRAWAL => '提现', self::WITHDRAWAL_CAT => '提现手续费', self::REFUND => '退款', + self::DEPOSIT => '扣交易金', ]; } } diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index f903bcd..bfd6644 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -12,6 +12,7 @@ use App\Models\AgentSetting; use App\Models\Coupon; use App\Models\OrderProductItem; use App\Models\Product; +use App\Models\SystemSetting; use App\Models\User; use App\Models\Order; use EasyWeChat\Factory; @@ -213,11 +214,12 @@ class OrderController extends Controller 'agent_cloud_price' => $ap->agentCloudProduct->price ?? 0, 'prepay_price ' => $prepayPrice ?? 0, 'prepay_timeout' => $prepayTimeout ?? 0, + 'service_persons' => SystemSetting::val('single', 'price') ]); //存入订单产品表 $supplier_product_info = Product::whereIn('id', $product_ids) - ->orderBy('id')->get(['id AS product_id', 'supplier_id', 'price'])->toArray(); + ->orderBy('id')->get(['id AS product_id', 'supplier_id', 'price','service_persons'])->toArray(); $order_id = $order->id; $agent_id = $this->agent_id; diff --git a/app/Http/Controllers/Api/VerificationController.php b/app/Http/Controllers/Api/VerificationController.php index 768830c..f7416fa 100644 --- a/app/Http/Controllers/Api/VerificationController.php +++ b/app/Http/Controllers/Api/VerificationController.php @@ -68,11 +68,11 @@ class VerificationController extends Controller DB::beginTransaction(); try { //最后批量插入 - $adminCreate = $statementCreate = []; + $statementCreate = []; $cost = 0; //如果有地接价格 分帐给地接 if ($order->guide_price > 0) { - $guidePrice = $order->guide_price; + //$guidePrice = $order->guide_price; $cost = bcadd($cost, $order->guide_price, 6); //成本价 加上地接价格 $statementCreate[] = $service->createByOrder( @@ -84,34 +84,34 @@ class VerificationController extends Controller 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) ->with('supplier') ->select('*') - ->selectRaw('sum(price) as sum_price') + ->selectRaw('sum(price) as sum_price,sum(service_persons) as sum_persons') ->groupBy('supplier_id') ->get(); foreach ($orderItem as $v) { @@ -135,33 +135,52 @@ class VerificationController extends Controller 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(); + + //处理交易金 + 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->save(); } @@ -170,62 +189,62 @@ class VerificationController extends Controller //成本价 加上地接价格 $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->balance = bcadd($agent->balance, $agentPrice, 6); $agent->save(); - } - if (!empty($adminCreate)) { - $order->statementAdmin()->createMany($adminCreate); - } + //} + //if (!empty($adminCreate)) { + // $order->statementAdmin()->createMany($adminCreate); + //} if (!empty($statementCreate)) { $order->statement()->createMany($statementCreate); diff --git a/database/migrations/2021_09_18_110418_update_order_table_0917_table.php b/database/migrations/2021_09_18_110418_update_order_table_0917_table.php new file mode 100644 index 0000000..0bf8b1b --- /dev/null +++ b/database/migrations/2021_09_18_110418_update_order_table_0917_table.php @@ -0,0 +1,38 @@ +decimal('single_price') + ->default(0) + ->comment('下单时的单人头交易费'); + }); + + Schema::table('order_product_items', function (Blueprint $table) { + $table->integer('service_persons') + ->default(0) + ->comment('涉及人数'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}