Adwords.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\ais\controller;
  9. use app\ais\model\AisAdwords;
  10. use app\common\facade\WechatProgram;
  11. use think\facade\Request;
  12. class Adwords extends Common{
  13. public function initialize() {
  14. parent::initialize();
  15. $this->assign('pathMaps', [['name'=>'广告管理','url'=>'javascript:;']]);
  16. }
  17. /**
  18. * 列表
  19. */
  20. public function index($group){
  21. $condition = [];
  22. $condition['group'] = $group;
  23. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  24. $view['lists'] = AisAdwords::where($condition)->order('sort desc,id desc')->paginate(20);
  25. $view['pathMaps'] = [['name'=>'广告管理','url'=>url("adwords/index",['group' => $group])]];
  26. $view['group'] = $group;
  27. return view('index',$view);
  28. }
  29. //编辑
  30. public function edit(){
  31. if(request()->isAjax()){
  32. $data = [
  33. 'id' => Request::param('id/d',0),
  34. 'group' => Request::param('group/s'),
  35. 'open_type' => Request::param('open_type/s','','htmlspecialchars'),
  36. 'title' => Request::param('title/s'),
  37. 'link' => Request::param('link/s'),
  38. 'picture' => Request::param('picture/s'),
  39. 'member_miniapp_id' => $this->member_miniapp_id,
  40. ];
  41. $validate = $this->validate($data,'adwords.edit');
  42. if(true !== $validate){
  43. return json(['code'=>0,'msg'=>$validate]);
  44. }
  45. $result = AisAdwords::edit($data);
  46. if($result){
  47. return json(['code'=>200,'url'=>url('adwords/index',['group' => $data['group']]),'msg'=>'操作成功']);
  48. }else{
  49. return json(['code'=>0,'msg'=>'操作失败']);
  50. }
  51. }else{
  52. $view['info'] = AisAdwords::where($this->mini_program)->where(['id' => Request::param('id/d', 0)])->find();
  53. if($this->member_miniapp->miniapp->is_openapp == 0){
  54. $list = WechatProgram::isTypes($this->member_miniapp_id)->code->getPage();
  55. }else{
  56. $list = ['errcode' => 1];
  57. }
  58. $view['list'] = $list;
  59. $view['group'] = Request::param('group');
  60. return view()->assign($view);
  61. }
  62. }
  63. //删除
  64. public function delete(int $id){
  65. $result = AisAdwords::where($this->mini_program)->where(['id' => $id])->delete();
  66. if($result){
  67. return enjson(200);
  68. }else{
  69. return enjson(0,'删除失败');
  70. }
  71. }
  72. /**
  73. * 排序
  74. */
  75. public function sort(){
  76. if(request()->isAjax()){
  77. $data = [
  78. 'sort' => $this->request->param('sort/d'),
  79. 'id' => $this->request->param('id/d'),
  80. ];
  81. $validate = $this->validate($data,'Category.sort');
  82. if(true !== $validate){
  83. return json(['code'=>0,'msg'=>$validate]);
  84. }
  85. $result = AisAdwords::update(['sort'=>$data['sort']],['member_miniapp_id' => $this->member_miniapp_id,'id' =>$data['id']]);
  86. if($result){
  87. return enjson(200);
  88. }else{
  89. return enjson(0);
  90. }
  91. }
  92. }
  93. }