7 changed files with 216 additions and 18 deletions
-
39app/Admin/Common/Type.php
-
63app/Admin/Controllers/v3/StoreController.php
-
99app/Admin/Renderable/StoreBalance.php
-
17app/Admin/Repositories/CommonEmpty.php
-
2app/Models/FinancialRecord.php
-
9app/Models/v3/Store.php
-
5resources/lang/zh-CN/store.php
@ -0,0 +1,99 @@ |
|||||
|
<?php |
||||
|
namespace App\Admin\Renderable; |
||||
|
|
||||
|
use Dcat\Admin\Grid; |
||||
|
use App\Admin\Common\Type; |
||||
|
use App\Admin\Repositories\CommonEmpty; |
||||
|
use Dcat\Admin\Grid\LazyRenderable; |
||||
|
use App\Models\FinancialRecord; |
||||
|
|
||||
|
class StoreBalance extends LazyRenderable |
||||
|
{ |
||||
|
protected $title = '商户余额明细'; |
||||
|
|
||||
|
public function grid(): Grid |
||||
|
{ |
||||
|
// 获取外部传递的参数
|
||||
|
$userId = $this->user_id ?? 0; |
||||
|
$model = FinancialRecord::getFinancialRecordModel($userId); |
||||
|
if(!$model){ |
||||
|
return Grid::make(new CommonEmpty(), function (Grid $grid) { |
||||
|
$grid->column('id','商 户 未 绑 定 提 现 用 户 懒 ID !'); |
||||
|
$grid->disableRowSelector(); |
||||
|
$grid->disableActions(); |
||||
|
$grid->disablePagination(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
return Grid::make($model, function (Grid $grid) { |
||||
|
$grid->column('id','ID'); |
||||
|
$grid->column('user_type','账户类型')->display(function($userType){ |
||||
|
$item = Type::USER_TYPE_LIST[$userType] ?? ''; |
||||
|
return $item; |
||||
|
}); |
||||
|
$grid->column('money_type','流水类型')->display(function($moneyType){ |
||||
|
$item = Type::MONEY_TYPE_LIST[$moneyType] ?? ''; |
||||
|
return $item; |
||||
|
}); |
||||
|
|
||||
|
$grid->column('money','金额'); |
||||
|
$grid->column('current_balance','账户余额'); |
||||
|
$grid->column('comment','描述'); |
||||
|
$grid->column('status','状态') |
||||
|
->using( |
||||
|
FinancialRecord::$status |
||||
|
) |
||||
|
->label( |
||||
|
config('label.status_label') |
||||
|
); |
||||
|
$grid->column('created_at')->display(function($createdAt){ |
||||
|
return date('Y-m-d H:i:s',$createdAt); |
||||
|
}); |
||||
|
// 搜索
|
||||
|
$grid->filter(function (Grid\Filter $filter){ |
||||
|
$userTypeList = Type::USER_TYPE_LIST; |
||||
|
$moneyTypeList = Type::MONEY_TYPE_LIST; |
||||
|
$sourceTYpeList = Type::SOURCE_TYPE_LIST; |
||||
|
unset($userTypeList[0],$moneyTypeList[0]); |
||||
|
|
||||
|
$filter->equal('id','流水表ID')->width(3); |
||||
|
$filter->equal('user_id','账户ID')->width(3); |
||||
|
$filter->equal('current_balance','账户余额')->width(3); |
||||
|
|
||||
|
$filter->equal('money','流水金额')->width(3); |
||||
|
$filter->equal('source_id','关联流水ID')->width(3); |
||||
|
|
||||
|
$filter->equal('money_type','流水类型')->select($userTypeList)->width(4); |
||||
|
$filter->equal('user_type','账户类型')->select($moneyTypeList)->width(4); |
||||
|
$filter->equal('source_type','关联类型')->select($sourceTYpeList)->width(4); |
||||
|
|
||||
|
$filter->whereBetween('created_at',function($q){ |
||||
|
$start = $this->input['start'] ?? null; |
||||
|
$end = $this->input['end'] ?? null; |
||||
|
if($start !== null){ |
||||
|
$q->where('created_at','>=',strtotime($start)); |
||||
|
} |
||||
|
if($end !== null){ |
||||
|
$q->where('created_at','<=',strtotime($end)); |
||||
|
} |
||||
|
})->datetime()->width(7); |
||||
|
}); |
||||
|
$grid->model()->orderBy('id','desc'); |
||||
|
// 每页10条
|
||||
|
$grid->paginate(10); |
||||
|
|
||||
|
$grid->disableActions(); |
||||
|
$grid->disableRowSelector(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public function default() |
||||
|
{ |
||||
|
// 获取外部传递的参数
|
||||
|
$userId = $this->payload['user_id'] ?? 0; |
||||
|
|
||||
|
return [ |
||||
|
'user_id' => $userId, |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
<?php |
||||
|
namespace App\Admin\Repositories; |
||||
|
|
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Repositories\Repository; |
||||
|
|
||||
|
class CommonEmpty extends Repository |
||||
|
{ |
||||
|
/** |
||||
|
* 模型创建失败时返回空使用空数据仓库 |
||||
|
*/ |
||||
|
public function get(Grid\Model $model) |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue