Browse Source

validator

master
ZLW-PC\Administrator 7 years ago
parent
commit
e1d77b6a9e
  1. 13
      app/Http/Controllers/Admin/ArticleController.php
  2. 11
      app/Http/Controllers/Admin/SlideController.php
  3. 31
      app/Http/Controllers/Admin/UserWithdrawController.php
  4. 2
      app/Http/Controllers/Weixin/IndexController.php
  5. 24
      app/Http/Model/Slide.php
  6. 93
      app/Http/Requests/ArticleRequest.php
  7. 32
      resources/views/admin/UserWithdraw/index.blade.php
  8. 2
      resources/views/admin/order/index.blade.php
  9. 13
      resources/views/admin/slide/add.blade.php
  10. 11
      resources/views/admin/slide/edit.blade.php
  11. 6
      resources/views/admin/slide/index.blade.php
  12. 1
      routes/web.php

13
app/Http/Controllers/Admin/ArticleController.php

@ -3,6 +3,9 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
use Illuminate\Http\Request;
use App\Http\Requests\ArticleRequest;
use Validator;
class ArticleController extends CommonController
{
@ -78,6 +81,16 @@ class ArticleController extends CommonController
public function add()
{
$validate = new ArticleRequest();
$validator = Validator::make($_REQUEST, $validate->getSceneRules('add'), $validate->getSceneRulesMessages());
if ($validator->fails())
{
//$validator->errors()->first();
//$validator->errors()->all();
error_jump('参数错误');
}
$data = '';
if(!empty($_REQUEST["catid"])){$data['catid'] = $_REQUEST["catid"];}else{$data['catid'] = 0;}

11
app/Http/Controllers/Admin/SlideController.php

@ -3,6 +3,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
use App\Http\Model\Slide;
class SlideController extends CommonController
{
@ -13,8 +14,16 @@ class SlideController extends CommonController
public function index()
{
$data['posts'] = parent::pageList('slide', '', [['is_show', 'asc'], ['rank', 'desc']]);
$data['posts'] = parent::pageList('slide', '', [['is_show', 'asc'], ['listorder', 'asc']]);
if($data['posts'])
{
foreach($data['posts'] as $k=>$v)
{
$data['posts'][$k]->type_text = Slide::getTypeText(array('type'=>$v->type));
}
}
return view('admin.slide.index', $data);
}

31
app/Http/Controllers/Admin/UserWithdrawController.php

@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
use App\Http\Model\UserWithdraw;
use App\Common\ReturnData;
class UserWithdrawController extends CommonController
{
@ -54,4 +55,34 @@ class UserWithdrawController extends CommonController
error_jump('修改失败!');
}
}
public function changeStatus()
{
if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
unset($_POST["_token"]);
if(!isset($_POST["type"])){return ReturnData::create(ReturnData::PARAMS_ERROR);}
$user_withdraw = DB::table('user_withdraw')->where(['id'=>$id,'status'=>0])->first();
if(!$user_withdraw){return ReturnData::create(ReturnData::PARAMS_ERROR);}
//0拒绝,1成功
if($_POST["type"]==0)
{
$data['status'] = 4;
}
elseif($_POST["type"]==1)
{
$data['status'] = 2;
}
if(!isset($data)){$res = DB::table('user_withdraw')->where('id', $id)->update($data);}
if(!isset($res)){return ReturnData::create(ReturnData::SYSTEM_FAIL);}
return ReturnData::create(ReturnData::SUCCESS);
}
}

2
app/Http/Controllers/Weixin/IndexController.php

@ -19,7 +19,7 @@ class IndexController extends CommonController
}
//首页
public function index()
public function index(Request $request)
{
//分享到首页,把推荐id存下来
if(isset($_REQUEST['invite_code']) && !empty($_REQUEST['invite_code']))

24
app/Http/Model/Slide.php

@ -80,4 +80,28 @@ class Slide extends Model
return true;
}
//获取显示平台文字:0pc,1weixin,2app,3wap
public static function getTypeText($where)
{
$res = '';
if($where['type'] === 0)
{
$res = 'pc';
}
elseif($where['type'] === 1)
{
$res = 'weixin';
}
elseif($where['type'] === 2)
{
$res = 'app';
}
elseif($where['type'] === 3)
{
$res = 'wap';
}
return $res;
}
}

93
app/Http/Requests/ArticleRequest.php

@ -0,0 +1,93 @@
<?php
namespace App\Http\Requests;
use Illuminate\Http\Request;
class ArticleRequest extends Request
{
//总的验证规则
protected $rules = [
'id' => 'required|integer',
'title' => 'required|max:150',
'typeid' => 'required|integer',
'click' => 'required|integer',
];
//总的自定义错误信息
protected $messages = [
'title.max' => '标题不能大于150个字',
'title.required' => '必须填写标题',
'typeid.required' => '类目ID必填',
'typeid.integer' => '栏目ID必须为数字',
'click.integer' => '点击必须为数字',
'id.required' => 'ID必填',
'id.integer' => 'ID必须为数字',
];
//场景验证规则
protected $scene = [
'add' => ['title','typeid','click'],
'edit' => ['title','typeid'],
'del' => ['id'],
];
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true; //修改为true
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return $this->rules;
}
/**
* 获取被定义验证规则的错误消息.
*
* @return array
*/
public function messages()
{
return $this->messages;
}
//获取场景验证规则
public function getSceneRules($name, $fields = null)
{
$res = array();
if(!isset($this->scene[$name]))
{
return false;
}
$scene = $this->scene[$name];
if($fields != null && is_array($fields))
{
$scene = $fields;
}
foreach($scene as $k=>$v)
{
if(isset($this->rules[$v])){$res[$v] = $this->rules[$v];}
}
return $res;
}
//获取场景验证规则自定义错误信息
public function getSceneRulesMessages()
{
return $this->messages;
}
}

32
resources/views/admin/UserWithdraw/index.blade.php

@ -26,9 +26,39 @@
<td>账号:<?php echo $row->account;if($row->bank_name){echo '<br>银行名称:'.$row->bank_name;}if($row->bank_place){echo '<br>开户行:'.$row->bank_place;} ?></td>
<td><?php echo date('Y-m-d H:i:s',$row->add_time); ?></td>
<td><?php echo $row->status_text; ?></td>
<td><a href="">成功</a>&nbsp;<a href="">拒绝</a></td>
<td><?php if($row->status==0){ ?><a href="javascript:change_status(<?php echo $row->id; ?>,'1');">成功</a>&nbsp;<a href="javascript:change_status(<?php echo $row->id; ?>,'0');">拒绝</a><?php } ?></td>
</tr><?php }} ?>
</tbody></table></div><!-- 表格结束 --></form><!-- 表单结束 -->
<nav aria-label="Page navigation">{{ $posts->links() }}</nav>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/layer/layer.js"></script>
<script>
function change_status(id,type)
{
//询问框
layer.confirm('您确定要执行此操作吗?', {
btn: ['确定','取消'] //按钮
}, function(){
var url = window.location.href;
$.post('<?php echo route('admin_userwithdraw_change_status'); ?>',{id:id,type:type},function(res){
if(res.code==0)
{
location.href = url;
}
else
{
}
//提示层
layer.msg(res.msg,{
time: 20000, //2s后自动关闭
});
});
}, function(){
});
}
</script>
@endsection

2
resources/views/admin/order/index.blade.php

@ -32,7 +32,7 @@
<div style="clear:both;"></div>
</div>
<div class="table-responsive"><table class="table table-striped table-hover">
<div class="table-responsive"><table class="table table-hover">
<thead><tr>
<th>订单编号SN-ID</th>
<th>支付信息</th>

13
resources/views/admin/slide/add.blade.php

@ -22,6 +22,15 @@
<input type="radio" value='1' name="target" />&nbsp;_self
</td>
</tr>
<tr>
<td align="right">显示平台:</td>
<td>
<input type="radio" value='0' name="type" checked />&nbsp;pc&nbsp;&nbsp;
<input type="radio" value='1' name="type" />&nbsp;weixin&nbsp;&nbsp;
<input type="radio" value='2' name="type" />&nbsp;app&nbsp;&nbsp;
<input type="radio" value='3' name="type" />&nbsp;wap
</td>
</tr>
<tr>
<td align="right">是否显示:</td>
<td>
@ -32,13 +41,13 @@
<tr>
<td align="right">排序:</td>
<td>
<input name="rank" type="text" id="rank" value="" size="3" />
<input name="listorder" type="text" id="listorder" value="50" size="3" />
</td>
</tr>
<tr>
<td align="right">所属的组:</td>
<td>
<input name="group_id" type="text" id="group_id" value="" size="3" />
<input name="group_id" type="text" id="group_id" value="0" size="3" />
</td>
</tr>
<tr>

11
resources/views/admin/slide/edit.blade.php

@ -22,6 +22,15 @@
<input type="radio" value='1' name="target" <?php if(isset($post['target']) && $post['target']==1){echo 'checked';} ?> />&nbsp;_self
</td>
</tr>
<tr>
<td align="right">显示平台:</td>
<td>
<input type="radio" value='0' name="type" <?php if(isset($post['type']) && $post['type']==0){echo 'checked';} ?> />&nbsp;pc&nbsp;&nbsp;
<input type="radio" value='1' name="type" <?php if(isset($post['type']) && $post['type']==1){echo 'checked';} ?> />&nbsp;weixin&nbsp;&nbsp;
<input type="radio" value='2' name="type" <?php if(isset($post['type']) && $post['type']==2){echo 'checked';} ?> />&nbsp;app&nbsp;&nbsp;
<input type="radio" value='3' name="type" <?php if(isset($post['type']) && $post['type']==3){echo 'checked';} ?> />&nbsp;wap
</td>
</tr>
<tr>
<td align="right">是否显示:</td>
<td>
@ -32,7 +41,7 @@
<tr>
<td align="right">排序:</td>
<td>
<input name="rank" type="text" id="rank" value="<?php echo $post['rank']; ?>" size="3" />
<input name="listorder" type="text" id="listorder" value="<?php echo $post['listorder']; ?>" size="3" />
</td>
</tr>
<tr>

6
resources/views/admin/slide/index.blade.php

@ -6,19 +6,23 @@
<form name="listarc"><div class="table-responsive"><table class="table table-hover">
<thead><tr class="info">
<th>ID</th>
<th>图片</th>
<th>标题</th>
<th>链接网址</th>
<th>显示平台</th>
<th>排序</th>
<th>是否显示</th>
<th>管理</th>
</tr></thead>
<tbody>
<?php if($posts){foreach($posts as $row){ ?><tr>
<td><?php echo $row->id; ?></td>
<td><img style="<?php if(empty($row->pic) || !imgmatch($row->pic)){ echo "display:none;"; } ?>" src="<?php if(imgmatch($row->pic)){echo $row->pic;} ?>" width="90" height="60"></td>
<td><?php echo $row->title; ?></td>
<td><?php echo $row->url; ?></td>
<td><?php echo $row->rank; ?></td>
<td><font color="red"><?php echo $row->type_text; ?></font></td>
<td><?php echo $row->listorder; ?></td>
<td><?php if($row->is_show==0){echo "";}else{echo "<font color=red>否</font>";} ?></td>
<td><a href="/fladmin/slide/edit?id=<?php echo $row->id; ?>">修改</a> | <a onclick="delconfirm('/fladmin/slide/del?id=<?php echo $row->id; ?>')" href="javascript:;">删除</a></td>
</tr><?php }} ?>

1
routes/web.php

@ -365,6 +365,7 @@ Route::group(['prefix' => 'fladmin', 'namespace' => 'Admin', 'middleware' => ['w
Route::get('/userwithdraw', 'UserWithdrawController@index')->name('admin_userwithdraw');
Route::get('/userwithdraw/edit', 'UserWithdrawController@edit')->name('admin_userwithdraw_edit');
Route::post('/userwithdraw/doedit', 'UserWithdrawController@doedit')->name('admin_userwithdraw_doedit');
Route::post('/userwithdraw/change_status', 'UserWithdrawController@changeStatus')->name('admin_userwithdraw_change_status');
//管理员管理
Route::get('/admin', 'AdminController@index')->name('admin_admin');
Route::get('/admin/add', 'AdminController@add')->name('admin_admin_add');

Loading…
Cancel
Save