PayCity.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Models\PayCity as Model;
  3. use App\Models\City;
  4. /**
  5. * banner管理
  6. *
  7. * @author 刘相欣
  8. *
  9. */
  10. class PayCity extends Auth{
  11. protected function _initialize(){
  12. parent::_initialize();
  13. $this->assign('breadcrumb1','营销管理');
  14. $this->assign('breadcrumb2','支付地区');
  15. }
  16. /**
  17. * 列表页
  18. *
  19. * */
  20. public function index(Model $Model, City $City){
  21. // 查询用户
  22. $list = $Model->query()->get();
  23. foreach($list as &$value){
  24. if( $value['city_ids'] ) {
  25. // 解析数组
  26. $cityids = explode(',',$value['city_ids']);
  27. // 获取城市
  28. foreach ($cityids as $kk=>$vv) {
  29. // 获取值
  30. $vv = $City->getOne($vv,'name');
  31. // 获取城市名
  32. $cityids[$kk] = $vv;
  33. }
  34. // 城市列表
  35. $value['city_ids'] = implode('、',$cityids);
  36. }
  37. }
  38. // 分配数据
  39. $this->assign('list',$list);
  40. $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
  41. // 加载模板
  42. return $this->fetch();
  43. }
  44. /**
  45. * 修改
  46. *
  47. * */
  48. public function edit(Model $Model, City $City){
  49. // 接受参数
  50. $id = request('id',0);
  51. // 查询数据
  52. $oldData = $Model->query()->find($id);
  53. // 如果是没有数据
  54. if( !$oldData ) return $this->error('查无数据');
  55. // 修改
  56. if(request()->isMethod('post')){
  57. // 组合数据
  58. $cityIds = request('city_ids',[]);
  59. $data['city_ids'] = implode(',',$cityIds);
  60. // 写入
  61. $result = $Model->edit($id,$data);
  62. // 提示新增失败
  63. if( !$result ) return json_send(['code'=>'error','msg'=>'修改失败']);
  64. // 记录行为
  65. $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,$data);
  66. // 告知结果
  67. return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
  68. }
  69. // 获取城市ID
  70. $oldData['city_ids'] = explode(',',$oldData['city_ids']);
  71. // 获取列表
  72. $cityList = $City->getCityList();
  73. // 分配数据
  74. $this->assign('oldData',$oldData);
  75. $this->assign('cityList',$cityList);
  76. $this->assign('crumbs','修改');
  77. // 加载模板
  78. return $this->fetch();
  79. }
  80. /**
  81. * 状态
  82. *
  83. * */
  84. public function set_status( Model $Model){
  85. // 接收参数
  86. $id = request('id',0);
  87. $status = request('status',0);
  88. // 查询数据
  89. $result = $Model->edit($id,['status'=>$status]);
  90. // 提示新增失败
  91. if( !$result ) return json_send(['code'=>'error','msg'=>'设置失败']);
  92. // 记录行为
  93. $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,[],['status'=>$status]);
  94. // 告知结果
  95. return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
  96. }
  97. }