62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Forms;
|
|
|
|
use App\Services\DistributeService;
|
|
use App\Models\OrderProfit;
|
|
use Dcat\Admin\Contracts\LazyRenderable;
|
|
use Dcat\Admin\Traits\LazyWidget;
|
|
use Dcat\Admin\Widgets\Form;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Enums\PayWay;
|
|
|
|
class ProfitSuccessForm extends Form implements LazyRenderable
|
|
{
|
|
use LazyWidget;
|
|
/**
|
|
* Handle the form request.
|
|
*
|
|
* @param array $input
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle(array $input)
|
|
{
|
|
$ids = explode(',', $input['ids']);
|
|
$list = OrderProfit::whereIn('id', $ids)->whereNotIn('status', [1, 2])->get()->groupBy('user_id');
|
|
$way = $input['pay_way'];
|
|
$service = new DistributeService();
|
|
foreach($list as $id => $items) {
|
|
try {
|
|
DB::beginTransaction();
|
|
if ($way === PayWay::WxpayTransfer->value) {
|
|
$service->wechatTransfers($items);
|
|
} else if ($way === PayWay::Offline->value) {
|
|
$service->success($items, $input);
|
|
}
|
|
DB::commit();
|
|
} catch (\Exception $e) {
|
|
DB::rollBack();
|
|
return $this->response()->error($e->getMessage());
|
|
}
|
|
}
|
|
return $this->response()->success('操作成功')->refresh();
|
|
}
|
|
|
|
/**
|
|
* Build a form here.
|
|
*/
|
|
public function form()
|
|
{
|
|
$this->hidden('ids')->attribute('id', 'order-profit-ids');
|
|
$this->datetime('paid_at')->value(now());
|
|
$this->radio('pay_way')->options([
|
|
PayWay::Offline->value => PayWay::Offline->text(),
|
|
PayWay::WxpayTransfer->value => PayWay::WxpayTransfer->text()
|
|
])->default(PayWay::Offline->value);
|
|
$this->text('pay_no');
|
|
|
|
$this->disableResetButton();
|
|
}
|
|
}
|