123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace App\Admin\Controllers\Lottery;
- use App\Http\Controllers\Controller;
- use App\Models\LotteryWin;
- use Encore\Admin\Facades\Admin as userAdmin;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Illuminate\Http\Request;
- class WinController extends Controller
- {
- use HasResourceActions;
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- return $content
- ->header('中奖列表')
- ->description('')
- ->body(view('admin.lottery.win')->with(['grid' => $this->grid()]));
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $status = ['', '未领奖', '已领奖'];
- $grid = new Grid(new LotteryWin);
- $grid->model()->orderBy('status', 'ASC')->orderBy('created_at','DESC');
- $grid->model();
- $grid->id('ID');
- $grid->column('member.mobile', '手机号');
- $grid->column('member.email', '邮箱号');
- $grid->column('prize_name', '奖品名称');
- $grid->created_at('中奖时间');
- $grid->out_at('核销时间');
- $grid->status('状态')->display(function () use ($status) {
- return $status[$this->status];
- });
- $grid->actions(function ($actions) {
- if ($actions->row['status'] == 1) {
- $actions->append('<button data-id="'.$actions->row['id'].'" class="btn btn-primary btn-xs write-off" title="核销" >核销</button>');
- }
- });
- $grid->filter(function ($filter) {
- $filter->where(function ($query) {
- $query->whereHas('member', function ($query) {
- $query->where('email', 'like', "%{$this->input}%")->orWhere('mobile', 'like', "%{$this->input}%");
- });
- }, '手机/邮箱');
- $filter->equal('status', '状态')->select([
- 1 => '未领奖',
- 2 => '已领奖',
- ]);
- });
- return $grid;
- }
- /**
- * return json
- */
- public function writeoff(Request $request)
- {
- $id = $request->input('id');
- $info = LotteryWin::find($id);
- $info->status = 2;
- $info->out_at = date('Y-m-d H:i:s');
- $info->save();
- return response()->json([]);
- }
- }
|