WeibanQrcode.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Http\Requests\Admin\WeiBan\Qrcode as Request;
  3. use App\Models\WeiBan\Qrcode as Model;
  4. use App\Models\City;
  5. /**
  6. * 微伴二维码
  7. *
  8. * @author 刘相欣
  9. *
  10. */
  11. class WeibanQrcode extends Auth{
  12. protected function _initialize(){
  13. parent::_initialize();
  14. $this->assign('breadcrumb1','客户管理');
  15. $this->assign('breadcrumb2','客服二维码');
  16. }
  17. /**
  18. * 首页列表
  19. *
  20. * */
  21. public function index(Model $Model){
  22. // 接受参数
  23. $name = request('name','');
  24. // 查询条件
  25. $map = [];
  26. // 编码ID
  27. if( $name ) $map[] = ['name','=',$name];
  28. // 查询数据
  29. $list = $Model->query()->where($map)->orderByDesc('id')->paginate(request('limit',config('page_num',10)))->appends(request()->all());
  30. // 循环处理数据
  31. foreach ($list as $key => $value) {
  32. // id转编号
  33. $value['thumb'] = $value['thumb'] ? path_compat($value['thumb']) : '';
  34. // 重组
  35. $list[$key] = $value;
  36. }
  37. // 分配数据
  38. $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
  39. $this->assign('list', $list);
  40. // 加载模板
  41. return $this->fetch();
  42. }
  43. /**
  44. * 添加
  45. *
  46. * */
  47. public function add( Request $request, Model $Model,City $City){
  48. if( request()->isMethod('post') ){
  49. // 验证参数
  50. $request->scene('add')->validate();
  51. // 组合数据
  52. $data['name'] = request('name','');
  53. $data['thumb'] = request('thumb','');
  54. $cityIds = request('city_ids',[]);
  55. $data['city_ids'] = implode(',',$cityIds);
  56. // 写入
  57. $id = $Model->add($data);
  58. // 提示新增失败
  59. if( !$id ) return json_send(['code'=>'error','msg'=>'新增失败']);
  60. // 记录行为
  61. $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,1,[],$data);
  62. // 告知结果
  63. return json_send(['code'=>'success','msg'=>'新增成功','action'=>'add']);
  64. }
  65. // 获取列表
  66. $cityList = $City->getCityList();
  67. // 分配数据
  68. $this->assign('cityList',$cityList);
  69. $this->assign('crumbs','新增');
  70. // 加载模板
  71. return $this->fetch();
  72. }
  73. /**
  74. * 编辑
  75. *
  76. * */
  77. public function edit( Request $request, Model $Model,City $City){
  78. if(request()->isMethod('post')){
  79. // 验证参数
  80. $request->scene('edit')->validate();
  81. // 组合数据
  82. $id = request('id',0);
  83. $data['name'] = request('name','');
  84. $data['thumb'] = request('thumb','');
  85. $cityIds = request('city_ids',[]);
  86. $data['city_ids'] = implode(',',$cityIds);
  87. // 写入
  88. $result = $Model->edit($id,$data);
  89. // 提示新增失败
  90. if( !$result ) return json_send(['code'=>'error','msg'=>'修改失败']);
  91. // 记录行为
  92. $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,[],$data);
  93. // 告知结果
  94. return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
  95. }
  96. // 接收参数
  97. $id = request('id',0);
  98. // 查询数据
  99. $oldData = $Model->where(['id'=>$id])->first();
  100. // 如果是没有数据
  101. if( !$oldData ) return $this->error('查无数据');
  102. // 获取城市ID
  103. $oldData['city_ids'] = explode(',',$oldData['city_ids']);
  104. // 获取列表
  105. $cityList = $City->getCityList();
  106. // 分配数据
  107. $this->assign('oldData',$oldData);
  108. $this->assign('cityList',$cityList);
  109. $this->assign('crumbs','修改');
  110. // 加载模板
  111. return $this->fetch();
  112. }
  113. /**
  114. * 状态
  115. *
  116. * */
  117. public function set_status( Request $request, Model $Model ){
  118. // 验证参数
  119. $request->scene('set_status')->validate();
  120. // 接收参数
  121. $id = request('id',0);
  122. $status = request('status',0);
  123. // 查询数据
  124. $result = $Model->edit($id,['status'=>$status]);
  125. // 提示新增失败
  126. if( !$result ) return json_send(['code'=>'error','msg'=>'设置失败']);
  127. // 记录行为
  128. $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,[],['status'=>$status]);
  129. // 告知结果
  130. return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
  131. }
  132. }