jingcai-php/app/Admin/Forms/ShopBalanceForm.php

53 lines
1.5 KiB
PHP

<?php
namespace App\Admin\Forms;
use App\Exceptions\JingCaiException;
use App\Model\ShopAgent;
use App\Model\Seller\Shop;
use App\Service\SellerWalletService;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Arr;
use Log;
class ShopBalanceForm extends Form implements LazyRenderable
{
use LazyWidget;
public function handle(array $input)
{
if (empty($input)){
return $this->response()->alert()->error("设置失败1");
}else{
$balance_cash = data_get($input,'balance_cash',0);
$shop = Shop::where('id',$input['id'])->first();
if (empty($shop)){
return $this->response()->alert()->error("设置失败2");
}
try {
SellerWalletService::adminRecharge($shop->id,auth('admin')->user()->id, $balance_cash);
} catch (JingCaiException $exception) {
return $this->response()->alert()->error($exception->getMessage());
}
return $this->response()->success("设置成功")->refresh();
}
}
public function form()
{
$shop_id = $this->payload['id'];
$shops = Shop::where('id',$shop_id)->first();
$this->display('shop_name','店铺名称')->with(function ($item)use($shops){
return $shops['name'];
});
$this->text('balance_cash','店铺余额');
$this->hidden('id')->value($shop_id);
}
}