jingcai-php/app/Admin/Controllers/ShopController.php

145 lines
5.2 KiB
PHP
Executable File

<?php
namespace App\Admin\Controllers;
use App\Admin\Forms\ShopBalanceForm;
use App\Model\Lottery;
use App\Model\Seller\Seller;
use App\Model\Seller\ShopBill;
use Dcat\Admin\Grid;
use Dcat\Admin\Form;
use App\Model\Seller\Shop;
use App\Model\ShopAgent;
use App\Admin\Forms\ShopAgentForm;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Content;
use Illuminate\Http\Request;
class ShopController extends AdminController
{
protected $title='店铺管理';
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
return Grid::make(Shop::class, function (Grid $grid) {
$grid->model()->with('agentSeller')->orderBy('id', 'desc');
$grid->column('id','店铺ID');
$grid->column('shop_sn','店铺编号');
$grid->column('status','店铺状态')->using(Shop::SHOP_STATUS)->label([
'default' => 'red', // 设置默认颜色,不设置则默认为 default
1 => 'blue'
]);;
$grid->column('name','店铺名称');
$grid->column('agent_seller_id','平台代理人ID')->modal(function (Grid\Displayers\Modal $modal){
// 标题
$modal->title('设置平台代理人');
// 自定义图标
$modal->icon('feather icon-edit');
// 传递当前行字段值
return ShopAgentForm::make()->payload(['id' => $this->id]);
});
$grid->column('agentSeller','平台代理人')->display(function($item) {
return $item ? $item->name ."</br>". ($item->phone) : '';
});
$grid->column('balance','店铺余额')->modal(function (Grid\Displayers\Modal $modal){
// 标题
$modal->title('店铺充值');
// 自定义图标
$modal->icon('feather icon-edit');
// 传递当前行字段值
return ShopBalanceForm::make()->payload(['id' => $this->id]);
});
$grid->column('seller_name','店主名称');
$grid->column('seller_phone','店铺联系电话');
$grid->column('seller_wechat','店铺微信');
$grid->column('addr','店铺地址');
$grid->column('announcement','店铺公告')->width('200');
$grid->column('created_at','创建时间');
$grid->fixColumns(-2);
$grid->filter(function($filter){
$filter->panel();
$filter->equal('status','店铺状态')->select(Shop::SHOP_STATUS);
$filter->equal('agent_seller_id','平台代理人')->select(Seller::pluck('phone','id'));
$filter->like('shop_sn','店铺编号');
$filter->like('name','店铺名称');
$filter->like('seller_name','店主名称');
});
$grid->disableViewButton();
// $grid->disableEditButton();
$grid->disableDeleteButton();
$grid->scrollbarX();//数据展开
// $grid->disableActions();
// $grid->disableRowSelector();
});
}
protected function form()
{
return Form::make(new Shop(), function (Form $form) {
$form->hidden('shop_sn');
$form->text('name','店铺名称')->required();
$form->text('seller_name','店主名称')->required();
$form->text('seller_phone','店主联系电话')->required();
$form->text('seller_wechat','店主微信')->required();
$form->text('addr','店铺地址')->required();
$form->text('announcement','店铺公告')->required();
$form->text('ali_face_app_auth_token','支付宝授权Token')->help('请谨慎操作');
$form->radio('status','店铺状态')->options(Shop::SHOP_STATUS)->required();
$form->divider();
$form->saving(function($form) {
if (!$form->model()->id) {
$form->shop_sn = Shop::generateShopSn();
Lottery::openAllLottery($form->model()->id);
}
});
$form->footer(function($footer) {
// 去掉`查看`checkbox
$footer->disableViewCheck();
// 去掉`继续编辑`checkbox
$footer->disableEditingCheck();
});
});
}
public function compareBill(Request $request, Content $content) {
$shopId = $request->input('shop_id');
$shopSn = $request->input('shop_sn');
if ($shopSn) {
$shop = Shop::where('shop_sn', $shopSn)->first();
$shopId = $shop->id;
}
$type = ShopBill::TYPE_INCR;
$bills = ShopBill::where('type', $type)
->where('shop_id', $shopId)
->get();
$total = collect($bills)->sum('money');
$shops = Shop::pluck('name','id')->toArray();
return $content->title('对店铺加款对账')
->body(view('admin.compare_bill', [
'data' => $bills,
'total' => $total,
'shops' => $shops,
'shopId' => $shopId,
]));
}
}