Type.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 栏目类型
  7. */
  8. namespace app\citys\controller;
  9. use app\citys\controller\Common;
  10. use app\citys\model\CitysType;
  11. use app\citys\model\Citys;
  12. class Type extends Common{
  13. public function initialize() {
  14. parent::initialize();
  15. $this->assign('pathMaps',[['name'=>'信息分类','url'=>url("citys/type/index")]]);
  16. }
  17. /**
  18. * 列表
  19. */
  20. public function index(){
  21. $view['lists'] = CitysType::where(['member_miniapp_id' => $this->member_miniapp_id])->order('sort desc,id desc')->paginate(20);
  22. return view()->assign($view);
  23. }
  24. /**
  25. * 添加
  26. */
  27. public function add(){
  28. if(request()->isAjax()){
  29. $data = [
  30. 'member_miniapp_id' => $this->member_miniapp_id,
  31. 'title' => $this->request->param('title/s'),
  32. 'endtips' => $this->request->param('endtips/s'),
  33. 'phone' => $this->request->param('phone/f'),
  34. 'price' => $this->request->param('price/f'),
  35. 'sort' => $this->request->param('sort/d'),
  36. ];
  37. $validate = $this->validate($data,'Cate.type');
  38. if(true !== $validate){
  39. return json(['code'=>0,'msg'=>$validate]);
  40. }
  41. $result = CitysType::edit($data);
  42. if($result){
  43. return json(['code'=>200,'url'=>url('citys/cate/index'),'msg'=>'操作成功']);
  44. }else{
  45. return json(['code'=>0,'msg'=>'操作失败']);
  46. }
  47. }else{
  48. return view();
  49. }
  50. }
  51. //编辑
  52. public function edit(){
  53. if(request()->isAjax()){
  54. $data = [
  55. 'id' => $this->request->param('id/s'),
  56. 'title' => $this->request->param('title/s'),
  57. 'endtips' => $this->request->param('endtips/s'),
  58. 'phone' => $this->request->param('phone/f'),
  59. 'price' => $this->request->param('price/f'),
  60. 'sort' => $this->request->param('sort/d'),
  61. ];
  62. $validate = $this->validate($data,'Cate.type');
  63. if(true !== $validate){
  64. return json(['code'=>0,'msg'=>$validate]);
  65. }
  66. $result = CitysType::edit($data);
  67. if($result){
  68. return enjson(200,['url'=>url('citys/type/index')]);
  69. }else{
  70. return enjson(0);
  71. }
  72. }else{
  73. $view['id'] = $this->request->param('id/d',0);
  74. $view['info']= CitysType::where($this->mini_program)->where(['id' => $view['id']])->find();
  75. return view('edit',$view);
  76. }
  77. }
  78. /**
  79. * 排序
  80. */
  81. public function sort(){
  82. if(request()->isAjax()){
  83. $data = [
  84. 'sort' => $this->request->param('sort/d'),
  85. 'id' => $this->request->param('id/d'),
  86. ];
  87. $validate = $this->validate($data,'Cate.sort');
  88. if(true !== $validate){
  89. return json(['code'=>0,'msg'=>$validate]);
  90. }
  91. $result = CitysType::update(['sort'=>$data['sort'],'id' => $data['id']]);
  92. if($result){
  93. return enjson(200);
  94. }else{
  95. return enjson(0);
  96. }
  97. }
  98. }
  99. //删除
  100. public function delete(){
  101. $id = $this->request->param('id/d');
  102. $info = citys::where(['type_id' => $id])->count();
  103. if($info){
  104. return enjson(0,'删除失败,栏目中还包含内容');
  105. }
  106. $result = CitysType::where(['id'=>$id,'member_miniapp_id' => $this->member_miniapp_id])->delete();
  107. if($result){
  108. return enjson(200);
  109. }else{
  110. return enjson(0);
  111. }
  112. }
  113. }