You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
4.1 KiB
121 lines
4.1 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Common\Auth;
|
|
use App\Admin\Common\Images;
|
|
use App\Admin\Repositories\LanzuCsInfo;
|
|
|
|
use App\Models\AdminUsers;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
use \App\Models\LanzuCsInfo as modelCsInfo;
|
|
class LanzuCsInfoController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new LanzuCsInfo(), function (Grid $grid) {
|
|
$user = Admin::user();
|
|
if ($user->isRole('lanzu_cs')){//如何是社区站点角色登陆,则只能看到自己的信息
|
|
$grid->model()->where('admin_user_id', $user->id);
|
|
$grid->disableDeleteButton();
|
|
$grid->disableEditButton();
|
|
}
|
|
$grid->id->sortable();
|
|
$grid->name;
|
|
$grid->phone;
|
|
$grid->amount('可提现金额');
|
|
$grid->column('qrcode_path','二维码')->image('',50,50);
|
|
$grid->status('状态')->using(['禁用', '启用']);
|
|
$grid->address;
|
|
$grid->created_at->display(function ($time){
|
|
return date('Y-m-d H:i',$time);
|
|
});
|
|
$grid->disableViewButton();
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->equal('id');
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new LanzuCsInfo(), function (Show $show) {
|
|
$show->id;
|
|
$show->name;
|
|
$show->phone;
|
|
$show->address;
|
|
$show->admin_user_id;
|
|
$show->status;
|
|
$show->created_at;
|
|
$show->updated_at;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new LanzuCsInfo(), function (Form $form) {
|
|
$form->display('id');
|
|
$form->text('name','名称')->required();
|
|
$form->text('user_id','用户ID')->required();
|
|
$form->mobile('phone')->required();
|
|
$form->text('address','社区地址')->required();
|
|
$form->radio('status', '状态')->options(['禁用', '启用'])->default(1);
|
|
$form->saved(function (Form $form,$cid){
|
|
$model = new modelCsInfo();
|
|
if ($form->isCreating()) {
|
|
//>>1.添加登录帐号
|
|
$res = Auth::addAdminUser($form,$model,$cid,'lanzu_cs');
|
|
if ($res==-1){
|
|
return $form->error('该手机号作为登陆帐号已存在!');
|
|
}elseif ($res==-2){
|
|
return $form->error('添加失败!');
|
|
}
|
|
|
|
//>>2.生成小程序二维码
|
|
$cs = $model->find($cid);
|
|
$aid = $cs->admin_user_id;
|
|
$images = new Images();
|
|
$param= "p=index&sid={$aid}";
|
|
$path= 'zh_cjdianc/pages/Liar/loginindex';
|
|
$qrcode = $images->createQrCode($param,$path);
|
|
$fileName = 'public/upload/' .'qrcode'.'/'. date('Y') . '/' . date('m-d') . '/' . rand(100000000000000,999999999999999).'.png';
|
|
$result = $images->uploadOss($qrcode,$fileName);
|
|
if ($result==true){
|
|
//>>3.保存二维码路径
|
|
$cs->qrcode_path = $fileName;
|
|
$cs->save();
|
|
}
|
|
} else {
|
|
//>>4.编辑时同步登陆帐号状态
|
|
$adu = new AdminUsers();
|
|
$id = $form->getKey();
|
|
$row = $model::find($id);
|
|
$ad = $adu->find($row->admin_user_id);
|
|
$ad->status = $form->status;
|
|
$ad->save();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|