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.
425 lines
18 KiB
425 lines
18 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers\v3;
|
|
|
|
use App\Admin\Common\Auth;
|
|
use App\Admin\Repositories\v3\Store;
|
|
use App\Models\LanzuMmInfo;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
use App\Models\LanzuMmInfo as MminfoModel;
|
|
use App\Models\v3\Market as MarketModel;
|
|
use App\Admin\Common\StoreQrCode;
|
|
use App\Models\v3\Store as StoreModel;
|
|
use App\Models\v3\User as UserModel;
|
|
use App\Models\v3\Category as CategoryModel;
|
|
use App\Models\LanzuUserBalance as UserBalanceModel;
|
|
use App\Models\v3\StoreUsers as StoreUsersModel;
|
|
use App\Admin\Actions\Grid\v3\StoreSetTime;
|
|
use App\Admin\Renderable\StoreBalance;
|
|
|
|
class StoreController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
$user = Admin::user();
|
|
$builder = new Store();
|
|
if ($user->isRole('lanzu_mm')) {
|
|
//如果登陆角色为市场经理,获取市场经理id
|
|
$mm = LanzuMmInfo::where(['admin_user_id' => $user->id])->first();
|
|
$builder = StoreModel::where(['mm_user_id' => $mm->user_id]);
|
|
}elseif ($user->isRole('market_service')){
|
|
//如果登陆角色为市场服务站,获取市场id
|
|
$marketId = Auth::getMarket();
|
|
$builder = StoreModel::where('market_id',$marketId);
|
|
}
|
|
return Grid::make($builder, function (Grid $grid) {
|
|
// 查询市场
|
|
$marketList = MarketModel::getMarketArray();
|
|
// 查询一级分类
|
|
// $categoryList = CategoryModel::getArray([['parent_id','=',0]]);
|
|
|
|
$grid->id->sortable();
|
|
$grid->logo_url->image('',50);
|
|
$grid->name->width('12%');
|
|
|
|
// 可看店铺余额权限
|
|
if($this->storeBalanceCan()){
|
|
$grid->column('user_id','余额')->display(function($userId){
|
|
$userId = $this->user_id;
|
|
$balance = 0;
|
|
if($userId > 0){
|
|
$moneyType = 5;// 商户类型
|
|
$balance = UserBalanceModel::getBalance($userId, $moneyType);
|
|
}
|
|
return $balance;
|
|
})->modal(function($modal){
|
|
$name = $this->name;
|
|
$modal->title($name.'的余额明细');
|
|
$table = StoreBalance::make(['user_id'=>$this->user_id]);
|
|
return $table;
|
|
});
|
|
}
|
|
|
|
$grid->market_id->display(function ($marketId) use($marketList){
|
|
return isset($marketList[$marketId]) ? $marketList[$marketId] : '';
|
|
});
|
|
// $grid->mm_user_id->display(function ($mmUserId){
|
|
// $mmUser = MminfoModel::getMmInfo($mmUserId,'name');
|
|
// return empty($mmUser) ? '' : $mmUser->name;
|
|
// });
|
|
$grid->store_applet_img->display(function($appletImg){
|
|
$id = $this->id;
|
|
$oldPath = 'https://img.lanzu.vip/addons/zh_cjdianc/data/code_store_img/wx_store_'.$id.'.jpg';
|
|
$path = empty($appletImg) ? $oldPath : config('filesystems.disks.oss.img_host').'/'.$appletImg;
|
|
$img = "<img src='$path' data-action='preview-img' style='max-width:50px;max-height:200px;cursor:pointer' class='img img-thumbnail'/>";
|
|
|
|
return $img;
|
|
});
|
|
|
|
$grid->cash_code_img->display(function($appletImg){
|
|
$id = $this->id;
|
|
$oldPath = 'https://img.lanzu.vip/addons/zh_cjdianc/data/code_pay_img/wx_pay_'.$id.'.jpg'.config('filesystems.disks.oss.store_image_resize');
|
|
$path = empty($appletImg) ? $oldPath : config('filesystems.disks.oss.img_host').'/'.$appletImg;
|
|
$img = "<img src='$path' data-action='preview-img' style='max-width:50px;max-height:200px;cursor:pointer' class='img img-thumbnail'/>";
|
|
|
|
return $img;
|
|
});
|
|
|
|
$grid->is_operation->switch();
|
|
$grid->is_open->switch();
|
|
|
|
$grid->actions([new StoreSetTime()]);
|
|
// 搜索
|
|
$grid->filter(function (Grid\Filter $filter) use($marketList){
|
|
$filter->equal('id');
|
|
$filter->like('name');
|
|
if (!(Admin::user()->isRole('market_service'))){
|
|
$filter->equal('market_id')->select($marketList);
|
|
}
|
|
});
|
|
$grid->model()->orderBy('id','desc');
|
|
// 每页10条
|
|
$grid->paginate(10);
|
|
|
|
// $grid->disableDeleteButton();
|
|
if (Admin::user()->isRole('market_service')){
|
|
//如果是市场服务站角色,关闭编辑,删除按钮操作
|
|
$grid->disableDeleteButton();
|
|
$grid->disableEditButton();
|
|
$grid->disableCreateButton();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new Store(), function (Show $show) {
|
|
|
|
$show->row(function (Show\Row $show) {
|
|
$show->width(6)->id;
|
|
$show->width(6)->mm_user_id->as(function ($mmUserId){
|
|
$item = MminfoModel::getMmInfo($mmUserId,'name');
|
|
return empty($item) ? '' : $item->name;
|
|
});
|
|
$show->width(6)->market_id->as(function ($marketId){
|
|
$item = MarketModel::getMarketInfo($marketId,'name');
|
|
return empty($item) ? '' : $item->name;
|
|
});
|
|
$show->width(6)->name;
|
|
$show->width(6)->logo->image();
|
|
$show->width(6)->user_id->as(function ($userId){
|
|
$item = UserModel::getUserInfo($userId,'nick_name');
|
|
return empty($item) ? '' : $item->nick_name;
|
|
});
|
|
$show->width(6)->admin_id->as(function ($userId){
|
|
$item = UserModel::getUserInfo($userId,'nick_name');
|
|
return empty($item) ? '' : $item->nick_name;
|
|
});
|
|
$show->width(6)->business_license->image();
|
|
$show->width(6)->zm_img->image();
|
|
$show->width(6)->fm_img->image();
|
|
|
|
$show->store_applet_img->width(6)->image();
|
|
$show->cash_code_img->width(6)->image();
|
|
$show->width(6)->category_id->as(function ($categoryId){
|
|
$item = CategoryModel::getInfo($categoryId,'title');
|
|
return empty($item) ? '' : $item->title;
|
|
});
|
|
$show->width(6)->tel;
|
|
$show->width(6)->link_name;
|
|
$show->width(6)->link_tel;
|
|
$show->width(6)->time1;
|
|
$show->width(6)->time2;
|
|
$show->width(6)->time3;
|
|
$show->width(6)->time4;
|
|
});
|
|
$show->row(function (Show\Row $show) {
|
|
$show->width(6)->announcement;
|
|
$show->width(6)->address;
|
|
$show->width(6)->coordinates;
|
|
|
|
$show->width(6)->is_rest_text;
|
|
$show->width(6)->is_open_text;
|
|
$show->width(6)->sort;
|
|
// $show->width(6)->environment;
|
|
$show->width(6)->expire_time;
|
|
$show->width(6)->loudspeaker_imei;
|
|
});
|
|
|
|
$show->panel()->tools(function ($tools) {
|
|
|
|
$tools->disableDelete();
|
|
|
|
});
|
|
$show->disableEditButton();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new Store(), function (Form $form) {
|
|
// $userId = $form->model()->user_id;
|
|
$adminId = $form->model()->admin_id;
|
|
// 查询市场经理
|
|
// $mmList = MminfoModel::getMmInfoArray();
|
|
// 查询市场
|
|
$marketList = MarketModel::getMarketArray();
|
|
// 查询一级分类
|
|
$categoryList = CategoryModel::getArray([['parent_id','=',0]]);
|
|
// 用户
|
|
// $userList = UserModel::getUserArray();
|
|
// 已绑定店铺的用户
|
|
// $userHas = StoreModel::pluck('admin_id')->toArray();
|
|
|
|
// foreach($userList as $ku => $uv){
|
|
// if($ku != 0 && in_array($ku,$userHas) && !in_array($adminId,$userHas)){
|
|
// unset($userList[$ku]);
|
|
// }
|
|
// }
|
|
|
|
$form->column(6, function (Form $form) use($marketList,$categoryList){
|
|
$form->hidden('id');
|
|
$form->text('mm_user_id')->type('number')->default(0)->attribute('min', 0)->placeholder('市场经理懒ID')->width(4)->help('市场经理的懒ID');
|
|
|
|
$form->select('market_id')->required()->options($marketList)->help('谨慎选择所属市场,添加成功后不能修改所属市场,因为会影响商品所属市场!');
|
|
|
|
$form->select('category_id')->options($categoryList);
|
|
$form->text('name')->required()->maxLength(50);
|
|
if($form->isCreating()){
|
|
$form->image('logo')->autoUpload()->retainable()->required();
|
|
}else{
|
|
$form->image('logo')->autoUpload()->required();
|
|
}
|
|
$form->mobile('tel');
|
|
$form->text('link_name')->required();
|
|
$form->mobile('link_tel')->required();
|
|
$form->number('sort');
|
|
$form->switch('is_operation')
|
|
->customFormat(function ($v) {
|
|
return $v == 1 ? 1 : 0;
|
|
})
|
|
->saving(function ($v) {
|
|
return $v == 1 ? 1 : 0;
|
|
});
|
|
$form->hidden('is_rest');
|
|
$form->switch('is_open')
|
|
->customFormat(function ($v) {
|
|
return $v == 1 ? 1 : 0;
|
|
})
|
|
->saving(function ($v) {
|
|
return $v == 1 ? 1 : 0;
|
|
});
|
|
$form->text('address')->required();
|
|
});
|
|
$form->column(6, function (Form $form) {
|
|
if($form->isCreating()){
|
|
$form->image('business_license')->autoUpload()->retainable()->required();
|
|
$form->image('zm_img')->autoUpload()->retainable()->required();
|
|
$form->image('fm_img')->autoUpload()->retainable()->required();
|
|
}else{
|
|
$form->image('business_license')->autoUpload()->required();
|
|
$form->image('zm_img')->autoUpload()->required();
|
|
$form->image('fm_img')->autoUpload()->required();
|
|
}
|
|
$form->text('admin_id')->type('number')->required()->default(0)->attribute('min', 0)->placeholder('管理员懒ID')->width(4);
|
|
$form->text('user_id')->type('number')->required()->default(0)->attribute('min', 0)->placeholder('提现用户懒ID')->width(4);
|
|
// $form->number('admin_id')->default(0)->required()->min(0)->placeholder('管理员懒ID');
|
|
// $form->number('user_id')->default(0)->required()->min(0)->placeholder('提现用户懒ID');
|
|
$form->time('time1','时间段一开始')->required()->format('HH:mm');
|
|
$form->time('time2','时间段一结束')->required()->format('HH:mm')->rules('after:time1',['after'=>'选择的时间必须比时间段一开始时间晚']);
|
|
$form->time('time3','时间段二开始')->format('HH:mm');
|
|
$form->time('time4','时间段二结束')->format('HH:mm');
|
|
// $form->timeRange('time1','time2','营业时间段一')->required();->rules('after:time2',['after'=>'选择的时间必须比时间段一结束时间晚'])
|
|
// $form->timeRange('time3','time4','营业时间段二')->rules('after:time2',['after'=>'选择的时间必须比时间段一结束时间大']);
|
|
});
|
|
$form->column(12, function (Form $form) {
|
|
$form->map('lat','lng','地址');
|
|
$form->textarea('introduction')->required();
|
|
$form->textarea('announcement')->default('');
|
|
$form->multipleImage('environment')->autoUpload()->default('');
|
|
});
|
|
|
|
// $form->text('coordinates')->width(4)
|
|
// ->placeholder('输入 经纬度,如: 108.281552,22.83731')
|
|
// ->help("通过网址 <a href='https://lbs.amap.com/console/show/picker' target='_blank'>https://lbs.amap.com/console/show/picker</a> 获取经纬度");
|
|
$form->saving(function(Form $form){
|
|
$id = $form->getKey();
|
|
$adminId = $form->input('admin_id');
|
|
$marketId = $form->input('market_id');
|
|
$isOperation = $form->input('is_operation');
|
|
|
|
$time1 = $form->input('time1');
|
|
$time2 = $form->input('time2');
|
|
$time3 = $form->input('time3');
|
|
$time4 = $form->input('time4');
|
|
|
|
if($isOperation !== null){
|
|
$form->is_rest = $isOperation == 1 ? 0 : 1;
|
|
}
|
|
|
|
if(!empty($time1) && !empty($time2) && (!empty($time3) || !empty($time4))){
|
|
if($time3 && empty($time4)){
|
|
return $form->error('请选择时间段二的结束时间!');
|
|
}else if($time4 && empty($time3)){
|
|
return $form->error('请选择时间段二的开始时间!');
|
|
}else if(str_replace(':', '', $time3) <= str_replace(':', '', $time2)){
|
|
return $form->error('时间段二的开始时间 必须大于 时间段一的结束时间!');
|
|
}else if(str_replace(':', '', $time4) <= str_replace(':', '', $time3)){
|
|
return $form->error('时间段二的结束时间 必须大于 时间段二的开始时间!');
|
|
}
|
|
}
|
|
|
|
if($form->isEditing() && !empty($marketId) && $marketId != $form->model()->market_id){
|
|
return $form->error('不能更换市场,会影响店铺下商品所属市场!');
|
|
}
|
|
if(!empty($adminId)){
|
|
$user = UserModel::getUserInfo($adminId,'id');
|
|
if(empty($user)){
|
|
return $form->error('管理员不存在');
|
|
}
|
|
$storeM = StoreModel::select('id')->where('admin_id',$adminId);
|
|
if($form->isEditing()){
|
|
$storeM->where([['id','<>',$id?$id:0]]);
|
|
}
|
|
|
|
$store = $storeM->first();
|
|
if(!empty($store)){
|
|
return $form->error('管理员已经绑定了店铺');
|
|
}
|
|
}
|
|
$form->deleteInput('is_operation');
|
|
});
|
|
$form->saved(function (Form $form){
|
|
$id = $form->getKey();
|
|
|
|
$store = StoreModel::find($id);
|
|
|
|
// 添加商户钱包
|
|
$userBalance = UserBalanceModel::where([
|
|
['user_type','=',5],
|
|
['source_id','=',$id]
|
|
])->first();
|
|
|
|
if(empty($userBalance)){
|
|
$userBalance = new UserBalanceModel();
|
|
$userBalance->user_type = 5;
|
|
$userBalance->source_id = $id;
|
|
$userBalance->save();
|
|
}
|
|
|
|
if($form->isCreating() && !empty($id)){
|
|
$qrCode = new StoreQrCode();
|
|
// 生成小程序码 店铺
|
|
$sRes = $qrCode->SetStoreWeChatCode($id);
|
|
|
|
// 生成二维码 收银
|
|
$pRes = $qrCode->SetPayWeChatCode($id);
|
|
|
|
// 保存图片
|
|
$store->store_applet_img = $sRes['status'] ? $sRes['path'] : '';
|
|
$cashImg = $pRes['status'] ? $pRes['path'] : '';
|
|
// 保存剪裁图片
|
|
$store->cash_code_img = $cashImg.config('filesystems.disks.oss.store_image_resize');
|
|
$store->save();
|
|
|
|
//店长账号
|
|
$storeUsersInfo = StoreUsersModel::where('store_id',$id)->where('user_category',1)->first();
|
|
if(empty($storeUsersInfo)){
|
|
$storeUsersModel = new StoreUsersModel();
|
|
$storeUsersModel->store_id = $id;
|
|
$storeUsersModel->username = $form->link_tel;
|
|
$storeUsersModel->join_ip = $_SERVER['SERVER_NAME'];
|
|
$storeUsersModel->user_category = 1;
|
|
$storeUsersModel->register_type = 4;
|
|
$storeUsersModel->status = 2;
|
|
$storeUsersModel->salt = $this->random(8);
|
|
$storeUsersModel->password = $this->stringHash(substr($form->link_tel,-6),$storeUsersModel->salt);
|
|
$storeUsersModel->remark = '入驻店铺注册';
|
|
$storeUsersModel->save();
|
|
}
|
|
}
|
|
});
|
|
|
|
$form->disableResetButton();
|
|
$form->disableViewCheck();
|
|
$form->disableEditingCheck();
|
|
$form->disableCreatingCheck();
|
|
$form->disableDeleteButton();
|
|
});
|
|
}
|
|
|
|
public function stringHash($password, $salt) {
|
|
$authkey = config('admin.setting.authkey');
|
|
$password = "{$password}-{$salt}-{$authkey}";
|
|
return sha1($password);
|
|
}
|
|
/**
|
|
* 字符串
|
|
*/
|
|
public function random($length, $numeric = false) {
|
|
$seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
|
|
$seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
|
|
if ($numeric) {
|
|
$hash = '';
|
|
} else {
|
|
$hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64);
|
|
--$length;
|
|
}
|
|
$max = strlen($seed) - 1;
|
|
for ($i = 0; $i < $length; ++$i) {
|
|
$hash .= $seed[mt_rand(0, $max)];
|
|
}
|
|
|
|
return $hash;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
protected function storeBalanceCan(): bool
|
|
{
|
|
$user = Admin::user();
|
|
return $user->can('store_balance');
|
|
}
|
|
}
|