123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php namespace App\Http\Controllers\Admin;
- use App\Models\PayCity as Model;
- use App\Models\City;
- /**
- * banner管理
- *
- * @author 刘相欣
- *
- */
- class PayCity extends Auth{
-
- protected function _initialize(){
- parent::_initialize();
- $this->assign('breadcrumb1','营销管理');
- $this->assign('breadcrumb2','支付地区');
- }
- /**
- * 列表页
- *
- * */
- public function index(Model $Model, City $City){
- // 查询用户
- $list = $Model->query()->get();
- foreach($list as &$value){
- if( $value['city_ids'] ) {
- // 解析数组
- $cityids = explode(',',$value['city_ids']);
- // 获取城市
- foreach ($cityids as $kk=>$vv) {
- // 获取值
- $vv = $City->getOne($vv,'name');
- // 获取城市名
- $cityids[$kk] = $vv;
- }
- // 城市列表
- $value['city_ids'] = implode('、',$cityids);
- }
- }
- // 分配数据
- $this->assign('list',$list);
- $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
- // 加载模板
- return $this->fetch();
- }
- /**
- * 修改
- *
- * */
- public function edit(Model $Model, City $City){
- // 接受参数
- $id = request('id',0);
- // 查询数据
- $oldData = $Model->query()->find($id);
- // 如果是没有数据
- if( !$oldData ) return $this->error('查无数据');
- // 修改
- if(request()->isMethod('post')){
- // 组合数据
- $cityIds = request('city_ids',[]);
- $data['city_ids'] = implode(',',$cityIds);
- // 写入
- $result = $Model->edit($id,$data);
- // 提示新增失败
- if( !$result ) return json_send(['code'=>'error','msg'=>'修改失败']);
- // 记录行为
- $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,$data);
- // 告知结果
- return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
- }
- // 获取城市ID
- $oldData['city_ids'] = explode(',',$oldData['city_ids']);
- // 获取列表
- $cityList = $City->getCityList();
- // 分配数据
- $this->assign('oldData',$oldData);
- $this->assign('cityList',$cityList);
- $this->assign('crumbs','修改');
- // 加载模板
- return $this->fetch();
- }
- /**
- * 状态
- *
- * */
- public function set_status( Model $Model){
- // 接收参数
- $id = request('id',0);
- $status = request('status',0);
- // 查询数据
- $result = $Model->edit($id,['status'=>$status]);
- // 提示新增失败
- if( !$result ) return json_send(['code'=>'error','msg'=>'设置失败']);
- // 记录行为
- $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,[],['status'=>$status]);
- // 告知结果
- return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
- }
- }
|