Browse Source

Merge remote-tracking branch 'origin/master'

master
李可松 4 years ago
parent
commit
67a06a38d9
  1. 32
      app/Admin/Extensions/Grid/Withdrawal.php
  2. 33
      app/AdminAgent/Controllers/WithdrawalAlipayController.php
  3. 34
      app/AdminAgent/Controllers/WithdrawalBankController.php
  4. 33
      app/AdminGuide/Controllers/WithdrawalAlipayController.php
  5. 34
      app/AdminGuide/Controllers/WithdrawalBankController.php
  6. 33
      app/AdminSupplier/Controllers/WithdrawalAlipayController.php
  7. 34
      app/AdminSupplier/Controllers/WithdrawalBankController.php
  8. 4
      app/Common/StatementType.php
  9. 163
      app/Http/Controllers/Api/VerificationController.php
  10. 2
      app/Models/Order.php
  11. 5
      app/Models/Statement.php
  12. 5
      app/Models/Withdrawal.php
  13. 30
      app/Service/WithdrawalService.php
  14. 18
      app/Traits/StatementTraits.php
  15. 32
      database/migrations/2021_09_16_151024_update_statement_table.php

32
app/Admin/Extensions/Grid/Withdrawal.php

@ -2,15 +2,19 @@
namespace App\Admin\Extensions\Grid;
use App\Common\ProductStatus;
use App\Common\StatementType;
use App\Models\Agent;
use App\Models\Guide;
use App\Models\Product;
use App\Models\Supplier;
use App\Service\WithdrawalService;
use App\Traits\DemandTraits;
use App\Traits\StatementTraits;
use App\Traits\WithdrawalTraits;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid\RowAction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* 供应商审核
@ -64,6 +68,7 @@ class Withdrawal extends RowAction
public function handle(Request $request)
{
DB::beginTransaction();
try {
if ($request->action == 1) {
//同意打款
@ -84,9 +89,30 @@ class Withdrawal extends RowAction
}
$user = $user->where('id', $withdrawal->user_id)->lockForUpdate()->first();
$user->balance = bcadd($user->balance,$withdrawal->price,6);
//退回提现的钱和手续费
$user->balance = bcadd($user->balance,bcadd($withdrawal->cut_price,$withdrawal->price,6),6);
$user->save();
//流水
$service = new WithdrawalService();
//退余额
$service->create(
$withdrawal->price,
StatementType::REFUND,
Admin::user()->id,
$withdrawal->user_type,
$withdrawal->id,
StatementTraits::$type[1]
);
//退手续费
$service->create(
$withdrawal->cut_price,
StatementType::REFUND,
Admin::user()->id,
$withdrawal->user_type,
$withdrawal->id,
StatementTraits::$type[1]
);
} elseif ($request->action == 3) {
//确认打款
$withdrawal = \App\Models\Withdrawal::find($this->getKey());
@ -94,7 +120,7 @@ class Withdrawal extends RowAction
}
$withdrawal->save();
DB::commit();
return $this->response()->success("操作成功")->refresh();
} catch (\Exception $e) {
return $this->response()->error($e->getMessage());

33
app/AdminAgent/Controllers/WithdrawalAlipayController.php

@ -9,6 +9,7 @@ use App\Models\SystemSetting;
use App\Models\Withdrawal;
use App\Service\WithdrawalService;
use App\Traits\DemandTraits;
use App\Traits\StatementTraits;
use App\Traits\WithdrawalTraits;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
@ -64,32 +65,38 @@ class WithdrawalAlipayController extends AdminController
if ($total > $user->balance) {
return $form->response()->error('余额不足,本次提现需花费'.bcadd($total,0,2).'(含手续费),当前可用余额为' . $user->balance);
}
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[0];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[0];
$withdrawal->save();
//提现扣钱流水
$service = new WithdrawalService();
$service->create(
bcmul($form->price, -1, 6),
StatementType::WITHDRAWAL,
Admin::user()->id,
DemandTraits::$col[0]
DemandTraits::$col[0],
$withdrawal->id,
StatementTraits::$type[1]
);
//提现手续费流水
$service->create(
bcmul($cutPrice, -1, 6),
StatementType::WITHDRAWAL_CAT,
Admin::user()->id,
DemandTraits::$col[0]
DemandTraits::$col[0],
$withdrawal->id,
StatementTraits::$type[1]
);
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[0];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[0];
$withdrawal->save();
$form->withdrawal_id = $withdrawal->id;
$form->deleteInput('price');

34
app/AdminAgent/Controllers/WithdrawalBankController.php

@ -9,6 +9,7 @@ use App\Models\SystemSetting;
use App\Models\Withdrawal;
use App\Service\WithdrawalService;
use App\Traits\DemandTraits;
use App\Traits\StatementTraits;
use App\Traits\WithdrawalTraits;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
@ -65,34 +66,39 @@ class WithdrawalBankController extends AdminController
if ($total > $user->balance) {
return $form->response()->error('余额不足,本次提现需花费'.bcadd($total,0,2).'(含手续费),当前可用余额为' . $user->balance);
}
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[0];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[1];
$withdrawal->save();
//提现扣钱流水
$service = new WithdrawalService();
$service->create(
bcmul($form->price, -1, 6),
StatementType::WITHDRAWAL,
Admin::user()->id,
DemandTraits::$col[0]
DemandTraits::$col[0],
$withdrawal->id,
StatementTraits::$type[1]
);
//提现手续费流水
$service->create(
bcmul($cutPrice, -1, 6),
StatementType::WITHDRAWAL_CAT,
Admin::user()->id,
DemandTraits::$col[0]
DemandTraits::$col[0],
$withdrawal->id,
StatementTraits::$type[1]
);
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[0];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[1];
$withdrawal->save();
$form->withdrawal_id = $withdrawal->id;
$form->deleteInput('price');
DB::commit();

33
app/AdminGuide/Controllers/WithdrawalAlipayController.php

@ -10,6 +10,7 @@ use App\Models\SystemSetting;
use App\Models\Withdrawal;
use App\Service\WithdrawalService;
use App\Traits\DemandTraits;
use App\Traits\StatementTraits;
use App\Traits\WithdrawalTraits;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
@ -65,32 +66,38 @@ class WithdrawalAlipayController extends AdminController
if ($total > $user->balance) {
return $form->response()->error('余额不足,本次提现需花费'.bcadd($total,0,2).'(含手续费),当前可用余额为' . $user->balance);
}
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[2];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[0];
$withdrawal->save();
//提现扣钱流水
$service = new WithdrawalService();
$service->create(
bcmul($form->price, -1, 6),
StatementType::WITHDRAWAL,
Admin::user()->id,
DemandTraits::$col[2]
DemandTraits::$col[2],
$withdrawal->id,
StatementTraits::$type[1]
);
//提现手续费流水
$service->create(
bcmul($cutPrice, -1, 6),
StatementType::WITHDRAWAL_CAT,
Admin::user()->id,
DemandTraits::$col[2]
DemandTraits::$col[2],
$withdrawal->id,
StatementTraits::$type[1]
);
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[2];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[0];
$withdrawal->save();
$form->withdrawal_id = $withdrawal->id;
$form->deleteInput('price');

34
app/AdminGuide/Controllers/WithdrawalBankController.php

@ -10,6 +10,7 @@ use App\Models\SystemSetting;
use App\Models\Withdrawal;
use App\Service\WithdrawalService;
use App\Traits\DemandTraits;
use App\Traits\StatementTraits;
use App\Traits\WithdrawalTraits;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
@ -67,34 +68,39 @@ class WithdrawalBankController extends AdminController
if ($total > $user->balance) {
return $form->response()->error('余额不足,本次提现需花费'.bcadd($total,0,2).'(含手续费),当前可用余额为' . $user->balance);
}
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[2];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[1];
$withdrawal->save();
//提现扣钱流水
$service = new WithdrawalService();
$service->create(
bcmul($form->price, -1, 6),
StatementType::WITHDRAWAL,
Admin::user()->id,
DemandTraits::$col[2]
DemandTraits::$col[2],
$withdrawal->id,
StatementTraits::$type[1]
);
//提现手续费流水
$service->create(
bcmul($cutPrice, -1, 6),
StatementType::WITHDRAWAL_CAT,
Admin::user()->id,
DemandTraits::$col[2]
DemandTraits::$col[2],
$withdrawal->id,
StatementTraits::$type[1]
);
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[2];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[1];
$withdrawal->save();
$form->withdrawal_id = $withdrawal->id;
$form->deleteInput('price');
DB::commit();

33
app/AdminSupplier/Controllers/WithdrawalAlipayController.php

@ -10,6 +10,7 @@ use App\Models\SystemSetting;
use App\Models\Withdrawal;
use App\Service\WithdrawalService;
use App\Traits\DemandTraits;
use App\Traits\StatementTraits;
use App\Traits\WithdrawalTraits;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
@ -65,32 +66,38 @@ class WithdrawalAlipayController extends AdminController
if ($total > $user->balance) {
return $form->response()->error('余额不足,本次提现需花费'.bcadd($total,0,2).'(含手续费),当前可用余额为' . $user->balance);
}
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[1];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[0];
$withdrawal->save();
//提现扣钱流水
$service = new WithdrawalService();
$service->create(
bcmul($form->price, -1, 6),
StatementType::WITHDRAWAL,
Admin::user()->id,
DemandTraits::$col[1]
DemandTraits::$col[1],
$withdrawal->id,
StatementTraits::$type[1]
);
//提现手续费流水
$service->create(
bcmul($cutPrice, -1, 6),
StatementType::WITHDRAWAL_CAT,
Admin::user()->id,
DemandTraits::$col[1]
DemandTraits::$col[1],
$withdrawal->id,
StatementTraits::$type[1]
);
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[1];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[0];
$withdrawal->save();
$form->withdrawal_id = $withdrawal->id;
$form->deleteInput('price');

34
app/AdminSupplier/Controllers/WithdrawalBankController.php

@ -10,6 +10,7 @@ use App\Models\SystemSetting;
use App\Models\Withdrawal;
use App\Service\WithdrawalService;
use App\Traits\DemandTraits;
use App\Traits\StatementTraits;
use App\Traits\WithdrawalTraits;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
@ -67,34 +68,39 @@ class WithdrawalBankController extends AdminController
if ($total > $user->balance) {
return $form->response()->error('余额不足,本次提现需花费'.bcadd($total,0,2).'(含手续费),当前可用余额为' . $user->balance);
}
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[1];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[1];
$withdrawal->save();
//提现扣钱流水
$service = new WithdrawalService();
$service->create(
bcmul($form->price, -1, 6),
StatementType::WITHDRAWAL,
Admin::user()->id,
DemandTraits::$col[1]
DemandTraits::$col[0],
$withdrawal->id,
StatementTraits::$type[1]
);
//提现手续费流水
$service->create(
bcmul($cutPrice, -1, 6),
StatementType::WITHDRAWAL_CAT,
Admin::user()->id,
DemandTraits::$col[1]
DemandTraits::$col[0],
$withdrawal->id,
StatementTraits::$type[1]
);
$user->balance = bcsub($user->balance, $total, 6);
$user->save();
$withdrawal = new Withdrawal();
$withdrawal->user_id = Admin::user()->id;
$withdrawal->user_type = DemandTraits::$col[1];
$withdrawal->price = request('price', 0);
$withdrawal->cut_price = $cutPrice;
//$withdrawal->pay_id = $form->getKey();
$withdrawal->pay_type = WithdrawalTraits::$userType[1];
$withdrawal->save();
$form->withdrawal_id = $withdrawal->id;
$form->deleteInput('price');
DB::commit();

4
app/Common/StatementType.php

@ -20,6 +20,9 @@ class StatementType
/** @var int 提现手续费 */
const WITHDRAWAL_CAT = 5;
/** @var int 退款 */
const REFUND = 6;
public static function array(): array
{
return [
@ -28,6 +31,7 @@ class StatementType
self::ORDER => '订单结算',
self::WITHDRAWAL => '提现',
self::WITHDRAWAL_CAT => '提现手续费',
self::REFUND => '退款',
];
}
}

163
app/Http/Controllers/Api/VerificationController.php

@ -14,8 +14,10 @@ use App\Models\OrderProductItem;
use App\Models\User;
use App\Common\OrderStatus;
use App\Service\SmsService;
use App\Service\WithdrawalService;
use App\Traits\DemandTraits;
use App\Traits\SmsTraits;
use App\Traits\StatementTraits;
use EasyWeChat\Factory;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
@ -40,12 +42,12 @@ class VerificationController extends Controller
return $this->error('订单不存在或订单状态不允许核销');
}
//$mobile = User::where('id', $this->user_id)->value('mobile');
//
//$checkMobile = Product::query()->whereIn('id', explode(',', $order->product_ids))->where('verify_mobile', $mobile)->doesntExist();
//if ($checkMobile) {
// return $this->error('对不起,你没有核销权限,请联系管理员');
//}
$mobile = User::where('id', $this->user_id)->value('mobile');
$checkMobile = Product::query()->whereIn('id', explode(',', $order->product_ids))->where('verify_mobile', $mobile)->doesntExist();
if ($checkMobile) {
return $this->error('对不起,你没有核销权限,请联系管理员');
}
$order->status = OrderStatus::SUCCESS;
if ($order->save()) {
@ -72,6 +74,7 @@ class VerificationController extends Controller
public function fund($order)
{
$service = new WithdrawalService();
DB::beginTransaction();
try {
//最后批量插入
@ -82,13 +85,14 @@ class VerificationController extends Controller
$guidePrice = $order->guide_price;
$cost = bcadd($cost, $order->guide_price, 6);
//成本价 加上地接价格
$statementCreate[] = [
'price' => $order->guide_price,
'type' => StatementType::ORDER,
'user_id' => $order->guide->id,
'user_type' => DemandTraits::$col[2],
'order_id' => $order->id
];
$statementCreate[] = $service->createByOrder(
$order->guide_price,
StatementType::ORDER,
$order->guide->id,
DemandTraits::$col[2],
$order->id,
StatementTraits::$type[0]
);
//抽成
if ($order->guide->rate > 0) {
//计算抽成金额
@ -96,21 +100,22 @@ class VerificationController extends Controller
$cutPrice = $guideCut > 0 ? bcdiv($guideCut, 100, 6) : 0;
//总后台抽成流水
if ($cutPrice > 0) {
$adminCreate[] = [
'price' => $cutPrice,
'type' => StatementType::CUT,
'cut_user_id' => $order->guide->id,
'cut_user_type' => DemandTraits::$col[2],
'order_id' => $order->id
];
$adminCreate[] = $service->createByOrderFormAdmin(
$cutPrice,
StatementType::CUT,
$order->guide->id,
DemandTraits::$col[2],
$order->id,
);
//地接被抽成流水
$statementCreate[] = [
'price' => bcmul($cutPrice, -1, 2),
'type' => StatementType::CUT,
'user_id' => $order->guide->id,
'user_type' => DemandTraits::$col[2],
'order_id' => $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);
@ -131,13 +136,14 @@ class VerificationController extends Controller
$cost = bcadd($cost, $v->sum_price, 6);
$supplierPrice = $v->sum_price;
$statementCreate[] = [
'price' => $v->sum_price,
'type' => StatementType::ORDER,
'user_id' => $v->supplier_id,
'user_type' => DemandTraits::$col[1],
'order_id' => $order->id
];
$statementCreate[] = $service->createByOrder(
$v->sum_price,
StatementType::ORDER,
$v->supplier_id,
DemandTraits::$col[1],
$order->id,
StatementTraits::$type[0]
);
if ($v->supplier->rate > 0) {
//计算抽成金额
@ -145,21 +151,22 @@ class VerificationController extends Controller
$cutPrice = $supplierCut > 0 ? bcdiv($supplierCut, 100, 6) : 0;
if ($cutPrice > 0) {
//总后台抽成流水
$adminCreate[] = [
'price' => $cutPrice,
'type' => StatementType::CUT,
'cut_user_id' => $v->supplier_id,
'cut_user_type' => DemandTraits::$col[1],
'order_id' => $order->id
];
$adminCreate[] = $service->createByOrderFormAdmin(
$cutPrice,
StatementType::CUT,
$v->supplier_id,
DemandTraits::$col[1],
$order->id,
);
//供应商被抽成流水
$statementCreate[] = [
'price' => bcmul($cutPrice, -1, 6),
'type' => StatementType::CUT,
'user_id' => $v->supplier_id,
'user_type' => DemandTraits::$col[1],
'order_id' => $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);
}
@ -174,13 +181,14 @@ class VerificationController extends Controller
$agentPrice = bcsub($order->price, $cost, 2);
if ($agentPrice > 0) {
$statementCreate[] = [
'price' => $agentPrice,
'type' => StatementType::ORDER,
'user_id' => $order->agent_id,
'user_type' => DemandTraits::$col[0],
'order_id' => $order->id
];
$statementCreate[] = $service->createByOrder(
$agentPrice,
StatementType::ORDER,
$order->agent_id,
DemandTraits::$col[0],
$order->id,
StatementTraits::$type[0]
);
//抽成
if ($order->agent->rate > 0) {
@ -190,40 +198,41 @@ class VerificationController extends Controller
//总后台抽成流水
if ($cutPrice > 0) {
$adminCreate[] = [
'price' => $cutPrice,
'type' => StatementType::CUT,
'cut_user_id' => $order->agent->id,
'cut_user_type' => DemandTraits::$col[0],
'order_id' => $order->id
];
$adminCreate[] = $service->createByOrderFormAdmin(
$cutPrice,
StatementType::CUT,
$order->agent->id,
DemandTraits::$col[0],
$order->id,
);
//代理商被抽成流水
$statementCreate[] = [
'price' => bcmul($cutPrice, -1, 6),
'type' => StatementType::CUT,
'user_id' => $order->agent->id,
'user_type' => DemandTraits::$col[0],
'order_id' => $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[] = [
'price' => bcmul($chargePrice, -1, 6),
'type' => StatementType::CHARGE,
'user_id' => $order->agent_id,
'user_type' => DemandTraits::$col[0],
'order_id' => $order->id
];
$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();
}
//dd($adminCreate,$guideCreate);
if (!empty($adminCreate)) {
$order->statementAdmin()->createMany($adminCreate);
}

2
app/Models/Order.php

@ -131,6 +131,6 @@ class Order extends BaseModel
public function statement()
{
return $this->hasMany(Statement::class,'order_id','id');
return $this->morphMany(Statement::class,'access');
}
}

5
app/Models/Statement.php

@ -17,4 +17,9 @@ class Statement extends Model
{
return $this->morphTo();
}
public function access()
{
return $this->morphTo();
}
}

5
app/Models/Withdrawal.php

@ -22,4 +22,9 @@ class Withdrawal extends Model
{
return $this->morphTo();
}
public function statement()
{
return $this->morphMany(Statement::class,'access');
}
}

30
app/Service/WithdrawalService.php

@ -10,14 +10,40 @@ use App\Traits\DemandTraits;
class WithdrawalService
{
public function create($price,$type,$userId,$userType,$orderId = '')
//提现流水
public function create($price,$type,$userId,$userType,$accessId,$accessType)
{
Statement::query()->create([
'price' => $price,
'type' => $type,
'user_id' => $userId,
'user_type' => $userType,
'order_id' => $orderId ?? ''
'access_id' => $accessId,
'access_type' => $accessType,
]);
}
//订单流水 暂时放一起
public function createByOrder($price,$type,$userId,$userType,$accessId,$accessType)
{
return [
'price' => $price,
'type' => $type,
'user_id' => $userId,
'user_type' => $userType,
'access_id' => $accessId,
'access_type' => $accessType,
];
}
public function createByOrderFormAdmin($price,$type,$userId,$userType,$orderId)
{
return [
'price' => $price,
'type' => $type,
'cut_user_id' => $userId,
'cut_user_type' => $userType,
'order_id' => $orderId,
];
}
}

18
app/Traits/StatementTraits.php

@ -0,0 +1,18 @@
<?php
namespace App\Traits;
trait StatementTraits
{
public static $type = [
'App\Models\Order',
'App\Models\Withdrawal',
];
public static $TypeText = [
'App\Models\Order' => '订单',
'App\Models\Withdrawal' => '提现',
];
}

32
database/migrations/2021_09_16_151024_update_statement_table.php

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class UpdateStatementTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('statement', function (Blueprint $table) {
$table->string('access_type')->index()->default('')->comment('关联类型 目前有订单 和提现')->after('user_type');
$table->integer('access_id')->index()->default(0)->comment('关联')->after('user_type');
$table->dropColumn('order_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
Loading…
Cancel
Save