Adver.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\system\controller;
  4. use app\BaseController;
  5. use app\model\api\AdverPage;
  6. use app\model\api\Advert;
  7. use app\model\api\Upsource;
  8. use app\Request;
  9. use library\services\UtilService;
  10. use library\utils\Qiniu;
  11. // +----------------------------------------------------------------------
  12. // | [ WE CAN DO IT MORE SIMPLE ]
  13. // +----------------------------------------------------------------------
  14. // | Copyright (c) 2018-2020 rights reserved.
  15. // +----------------------------------------------------------------------
  16. // | [ 广告管理 ]
  17. // +----------------------------------------------------------------------
  18. // | Date: 2020-09-06 21:53
  19. // +----------------------------------------------------------------------
  20. class Adver extends BaseController{
  21. /**
  22. * 分类列表数据
  23. */
  24. public function page(Request $request){
  25. [$cate_name,$pid,$is_show] = UtilService::getMore([
  26. ['cate_name',''],
  27. ['pid','0'],
  28. ['is_show','0']
  29. ],$request,true);
  30. $menuMenu = new AdverPage();
  31. $menus = $menuMenu->getArMenu($cate_name,$pid,$is_show);
  32. return app('json')->success($menus);
  33. }
  34. /**
  35. * 获取树级分类
  36. */
  37. public function page_tree() {
  38. $menuAr = (new AdverPage())->order("sort","desc")->select()->toArray();
  39. $data = sort_list_tier($menuAr, '顶级', 'pid', 'id');
  40. return app('json')->success($data);
  41. }
  42. /**
  43. * 获取详情栏目数据
  44. */
  45. public function page_info(Request $request){
  46. [$id] = UtilService::getMore([
  47. ['id',0,'empty','参数错误']
  48. ],$request,true);
  49. $data = (new AdverPage())->find(compact('id'))->toArray();
  50. return app('json')->success($data);
  51. }
  52. /**
  53. * 保存数据
  54. */
  55. public function page_save(Request $request){
  56. $post = UtilService::getMore([
  57. ['cate_name','','empty','商品分类'],
  58. ['pid','0'],
  59. ['sort','0'],
  60. ['id','0'],
  61. ['type','1'],
  62. ['max_count',0],
  63. ['json','[]'],
  64. ['mono','']
  65. ],$request);
  66. (new AdverPage())->savePage($post);
  67. return app('json')->success("数据保存成功");
  68. }
  69. /**
  70. * 栏目删除
  71. * @param Request $request
  72. */
  73. public function page_del(Request $request) {
  74. [$id] = UtilService::getMore([
  75. ['id',0,'empty','参数错误']
  76. ],$request,true);
  77. $bool = (new AdverPage())->delAdver($id);
  78. return app('json')->success("栏目删除成功");
  79. }
  80. public function list(Request $request) {
  81. $pageSize = 50;
  82. [$page,$page_id,$title,$sassid] = UtilService::getMore(
  83. [
  84. ['page',1],
  85. ['page_id','0'],
  86. ['title',''],
  87. ['sassid','0']
  88. ],$request,true
  89. );
  90. $where = compact('page_id','title','sassid');
  91. list($pageCount,$data) = (new Advert)
  92. ->getList($page,$where,$pageSize,'id desc');
  93. return app('json')->success([
  94. 'list' => $data,
  95. 'pageCount' => $pageCount,
  96. 'pageSize' => $pageSize,
  97. 'page' => $page
  98. ]);
  99. }
  100. /**
  101. * 获取详情栏目数据
  102. */
  103. public function info(Request $request){
  104. [$id] = UtilService::getMore([
  105. ['id',0,'empty','参数错误']
  106. ],$request,true);
  107. $data = (new Advert())->find(compact('id'))->toArray();
  108. return app('json')->success($data);
  109. }
  110. /**
  111. * 保存数据
  112. */
  113. public function save(Request $request){
  114. $post = UtilService::getMore([
  115. ['title','','empty','广告'],
  116. ['page_id','0'],
  117. ['sort','0'],
  118. ['sex',0],
  119. ['id','0'],
  120. ['text',''],
  121. ['url',''],
  122. ['code',''],
  123. ['img',''],
  124. ['data',''],
  125. ['is_show','0']
  126. ],$request);
  127. (new Advert())->savePage($post);
  128. return app('json')->success("数据保存成功");
  129. }
  130. /**
  131. * 栏目删除
  132. * @param Request $request
  133. */
  134. public function del(Request $request) {
  135. [$id] = UtilService::getMore([
  136. ['id',0,'empty','参数错误']
  137. ],$request,true);
  138. $bool = (new Advert)->where("id",$id)->delete();
  139. return app('json')->success("栏目删除成功");
  140. }
  141. public function upsourceList(Request $request) {
  142. $post = UtilService::getMore([
  143. ['page',1],
  144. ['pageSize', 50],
  145. ['title',''],
  146. ['type',''],
  147. ['status',''],
  148. ],$request);
  149. $data = (new Upsource)->getListData($post);
  150. return app('json')->success([
  151. 'list' => $data["list"],
  152. 'pageCount' => $data["totalCount"],
  153. 'pageSize' => $data["pageSize"],
  154. 'page' => $data["page"],
  155. ]);
  156. }
  157. public function upsourceSave(Request $request){
  158. $post = UtilService::getMore([
  159. ['id',''],
  160. ['url',''],
  161. ['title',''],
  162. ['type','img'],
  163. ],$request);
  164. $id = $post["id"];
  165. unset($post["id"]);
  166. $r=0;
  167. if(empty($id) || $id=="0"){
  168. $post["time"] = time();
  169. $post["status"] = 1;
  170. $r = (new Upsource)->insert($post);
  171. }else{
  172. $r = (new Upsource)->where("id",$id)->update($post);
  173. }
  174. if($r){
  175. return app('json')->success("数据保存成功");
  176. }else{
  177. return app('json')->fail("数据保存失败");
  178. }
  179. }
  180. /**
  181. * 删除资源图片
  182. * @param Request $request
  183. */
  184. public function upsourceDel(Request $request){
  185. $post = UtilService::getMore([
  186. ['id','',"empty","参数错误"],
  187. ],$request);
  188. $data = (new Upsource)->where("id",$post["id"])->find();
  189. if(empty($data)){
  190. return app('json')->fail("数据错误");
  191. }
  192. // $qiniu = new Qiniu;
  193. // $qiniu->
  194. (new Upsource)->where("id",$post["id"])->update(["is_del"=>1]);
  195. return app('json')->success("删除成功");
  196. }
  197. }