diff --git a/app/Admin/Controllers/DealerEarningController.php b/app/Admin/Controllers/DealerEarningController.php index de4ed3a1..63756e31 100644 --- a/app/Admin/Controllers/DealerEarningController.php +++ b/app/Admin/Controllers/DealerEarningController.php @@ -81,6 +81,11 @@ class DealerEarningController extends AdminController return $this->payer_id ? $this->payer?->phone : '公司'; }); // $grid->column('pay_info'); + $grid->column('pay_way')->using(DealerEarningModel::$payWayText)->label([ + DealerEarningModel::PAY_WAY_WALLET=>'warning', + DealerEarningModel::PAY_WAY_OFFLINE=>'danger', + 'none'=>'#b3b9bf', + ]); $grid->column('pay_at'); // $grid->column('pay_image'); @@ -151,6 +156,11 @@ class DealerEarningController extends AdminController $show->field('payer.phone', '打款人')->as(function () { return $this->payer_id ? $this->payer?->phone : '公司'; }); + $show->field('pay_way', '支付方式')->using(DealerEarningModel::$payWayText)->dot([ + DealerEarningModel::PAY_WAY_WALLET=>'warning', + DealerEarningModel::PAY_WAY_OFFLINE=>'danger', + 'none'=>'#b3b9bf', + ]); $show->field('pay_image')->image(); // $show->field('pay_info'); $show->field('pay_at'); diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/EarningController.php b/app/Endpoint/Api/Http/Controllers/Dealer/EarningController.php index 5059c041..dd027fad 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/EarningController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/EarningController.php @@ -30,13 +30,13 @@ class EarningController extends Controller $user = $request->user(); switch ($cate) { case 'pending':// - $query = $user->dealerPayEarnings()->onlyPending()->whereNotNull('settle_at'); + $query = $user->dealerPayEarnings()->with('user')->onlyPending()->whereNotNull('settle_at'); break; case 'paid': $query = $user->dealerEarnings()->onlyPaid()->whereNotNull('settle_at'); break; default://全部 - $query = DealerEarning::where(function ($q) use ($user) { + $query = DealerEarning::with('user')->where(function ($q) use ($user) { return $q->where('user_id', $user->id)->orWhere('payer_id', $user->id); }); break; @@ -56,7 +56,7 @@ class EarningController extends Controller public function show($id, Request $request) { $user = $request->user(); - $earning = DealerEarning::where(function ($q) use ($user) { + $earning = DealerEarning::with(['user', 'user.userInfo'])->where(function ($q) use ($user) { return $q->where('user_id', $user->id)->orWhere('payer_id', $user->id); })->with('earningable')->findOrFail($id); return DealerEarningResource::make($earning); @@ -90,10 +90,10 @@ class EarningController extends Controller 'pay_password' => '支付密码', ]); - $payWay = $input['pay_way'] ?? 'offline'; + $payWay = $input['pay_way'] ?? DealerEarning::PAY_WAY_OFFLINE; if ( - $payWay === 'wallet' && + $payWay === DealerEarning::PAY_WAY_WALLET && !$user->wallet?->verifyPassword($input['pay_password']) ) { throw new PayPasswordIncorrectException(); @@ -103,7 +103,7 @@ class EarningController extends Controller try { DB::beginTransaction(); switch ($payWay) { - case 'wallet': + case DealerEarning::PAY_WAY_WALLET: //支付余额 $walletService = new WalletService(); @@ -129,14 +129,16 @@ class EarningController extends Controller $earning->update([ 'status' => DealerEarningStatus::Completed, + 'pay_way' => DealerEarning::PAY_WAY_WALLET, 'pay_info' => $earning->getPayInfo(), 'pay_at' => now(), ]); break; - case 'offline': + case DealerEarning::PAY_WAY_OFFLINE: $earning->update([ 'status' => DealerEarningStatus::Paid, + 'pay_way' => DealerEarning::PAY_WAY_OFFLINE, 'pay_info' => $earning->getPayInfo(), 'pay_image'=> $input['pay_image'], 'pay_at' => now(), diff --git a/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningResource.php b/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningResource.php index 243153e2..fa00dfa2 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningResource.php @@ -27,11 +27,16 @@ class DealerEarningResource extends JsonResource 'status' => $this->status_format, 'status_name' => $this->status_name, 'remark' => $this->remark, + 'pay_way' => $this->pay_way ?? '', 'pay_info' => $this->getPayInfo(), 'pay_image' => $this->pay_image, 'pay_at' => $this->pay_at?->toDateTimeString(), 'is_payer' => $this->payer_id ? ($this->payer_id == $request->user()->id) : false, 'purchase_subsidy_logs' => $purchaseSubsidyLogs ? DealerEarningSubsidyLogResource::collection($purchaseSubsidyLogs) : null, + 'beneficiary' => $this->user ? [ + 'nickname' => $this->user->userInfo?->nickname ?? '', + 'phone'=>$this->user->phone ?? '', + ] : null, ]; } } diff --git a/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningSimpleResource.php b/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningSimpleResource.php index d8ae05c1..adbc0265 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningSimpleResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningSimpleResource.php @@ -22,6 +22,7 @@ class DealerEarningSimpleResource extends JsonResource 'status' => $this->status_format, 'status_name' => $this->status_name, 'is_payer' => $this->payer_id ? ($this->payer_id == $request->user()->id) : false, + 'beneficiary_phone' => $this->user?->phone ?? '', // 'settle_at' ]; } diff --git a/app/Models/DealerEarning.php b/app/Models/DealerEarning.php index 5a9548bb..93765683 100644 --- a/app/Models/DealerEarning.php +++ b/app/Models/DealerEarning.php @@ -18,6 +18,9 @@ class DealerEarning extends Model 'status' => DealerEarningStatus::Pending, ]; + public const PAY_WAY_WALLET = 'wallet'; // 余额 + public const PAY_WAY_OFFLINE = 'offline'; // 线下支付 + protected $casts = [ 'lvl' => DealerLvl::class, 'status' => DealerEarningStatus::class, @@ -42,6 +45,12 @@ class DealerEarning extends Model 'settle_at', 'status', 'remark', + 'pay_way', + ]; + + public static $payWayText = [ + self::PAY_WAY_WALLET => '余额支付', + self::PAY_WAY_OFFLINE => '线下打款', ]; public function user() diff --git a/database/migrations/2022_02_23_104107_add_pay_way_to_dealer_earnings_table.php b/database/migrations/2022_02_23_104107_add_pay_way_to_dealer_earnings_table.php new file mode 100644 index 00000000..e8b642f7 --- /dev/null +++ b/database/migrations/2022_02_23_104107_add_pay_way_to_dealer_earnings_table.php @@ -0,0 +1,34 @@ +string('pay_way')->nullable()->comment('1线下打款,2余额'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('dealer_earnings', function (Blueprint $table) { + // + $table->dropColumn('pay_way'); + }); + } +} diff --git a/resources/lang/zh_CN/dealer-earning.php b/resources/lang/zh_CN/dealer-earning.php index 5cc89b99..d48b704f 100644 --- a/resources/lang/zh_CN/dealer-earning.php +++ b/resources/lang/zh_CN/dealer-earning.php @@ -27,6 +27,7 @@ return [ 'status_format' => '状态', 'remark' => '备注', 'pay_image' => '打款凭证', + 'pay_way'=>'支付方式', ], 'options' => [ ],