Adwords.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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\green\controller;
  9. use app\green\model\GreenAdwords;
  10. use app\green\model\GreenCategory;
  11. use think\facade\Request;
  12. class Adwords extends Common{
  13. public function initialize() {
  14. parent::initialize();
  15. $this->ads = new GreenAdwords();
  16. $this->assign('pathMaps', [['name'=>'图标管理','url'=>url("adwords/index")]]);
  17. }
  18. /**
  19. * 列表
  20. */
  21. public function index($group){
  22. $condition = [];
  23. $condition['group'] = $group;
  24. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  25. $view['lists'] = $this->ads->where($condition)->order('sort desc,id desc')->paginate(20);
  26. $view['pathMaps'] = [['name'=>'广告管理','url'=>url("adwords/index",['group' => $group])]];
  27. $view['group'] = $group;
  28. return view('index',$view);
  29. }
  30. /**
  31. * 添加
  32. */
  33. public function add(){
  34. if(request()->isAjax()){
  35. $data = [
  36. 'group' => input('post.group/s', '', 'htmlspecialchars'),
  37. 'open_type' => input('post.open_type/s', '', 'htmlspecialchars'),
  38. 'title' => input('post.title/s', '', 'htmlspecialchars'),
  39. 'link' => input('post.link/s', '', 'htmlspecialchars'),
  40. 'picture' => input('post.picture/s', '', 'htmlspecialchars'),
  41. 'member_miniapp_id' => $this->member_miniapp_id,
  42. ];
  43. $validate = $this->validate($data,'Adwords.add');
  44. if(true !== $validate){
  45. return enjson(0,$validate);
  46. }
  47. $result = $this->ads->edit($data);
  48. if($result){
  49. return enjson(200,'操作成功',['url'=>url('adwords/index',['group' => $data['group']])]);
  50. }else{
  51. return enjson(0,'操作失败');
  52. }
  53. }else{
  54. $view['lists'] = GreenCategory::where(['member_miniapp_id' => $this->member_miniapp_id,'parent_id' => 0])->select();
  55. $view['group'] = Request::param('group');
  56. return view()->assign($view);
  57. }
  58. }
  59. //编辑
  60. public function edit(){
  61. if(request()->isAjax()){
  62. $data = [
  63. 'id' => input('post.id/s'),
  64. 'group' => input('post.group/s'),
  65. 'open_type' => input('post.open_type/s','','htmlspecialchars'),
  66. 'title' => input('post.title/s'),
  67. 'link' => input('post.link/s'),
  68. 'picture' => input('post.picture/s'),
  69. 'member_miniapp_id' => $this->member_miniapp_id,
  70. ];
  71. $validate = $this->validate($data,'adwords.edit');
  72. if(true !== $validate){
  73. return enjson(0,$validate);
  74. }
  75. $result = $this->ads->edit($data);
  76. if($result){
  77. return enjson(200,'操作成功',['url'=>url('adwords/index',['group' => $data['group']])]);
  78. }else{
  79. return enjson(0,'操作失败');
  80. }
  81. }else{
  82. $id = input('get.id/d');
  83. $view['info'] = $this->ads->get($id);
  84. $view['lists'] = GreenCategory::where(['member_miniapp_id' => $this->member_miniapp_id,'parent_id' => 0])->select();
  85. return view()->assign($view);
  86. }
  87. }
  88. //删除
  89. public function delete(){
  90. $id = input('get.id/d');
  91. $condition = [];
  92. $condition['id'] = $id;
  93. $result = $this->ads->where($this->mini_program)->where($condition)->delete();
  94. if($result){
  95. return enjson(200,'操作成功');
  96. }else{
  97. return enjson(403,'操作失败');
  98. }
  99. }
  100. /**
  101. * 排序
  102. */
  103. public function sort(){
  104. if(request()->isAjax()){
  105. $data = [
  106. 'sort' => input('post.sort/d'),
  107. 'id' => input('post.id/d'),
  108. ];
  109. $validate = $this->validate($data,'adwords.sort');
  110. if(true !== $validate){
  111. return enjson(0,$validate);
  112. }
  113. $result = $this->ads->save(['sort'=>$data['sort']],['member_miniapp_id' => $this->member_miniapp_id,'id' =>$data['id']]);
  114. if($result){
  115. return enjson(200,'操作成功');
  116. }else{
  117. return enjson(0,'操作失败');
  118. }
  119. }
  120. }
  121. }