ServiceLabel.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\system\controller;
  4. use app\BaseController;
  5. use app\model\api\ServiceLabel as LabelModel;
  6. use app\Request;
  7. use library\services\UtilService;
  8. // +----------------------------------------------------------------------
  9. // | [ WE CAN DO IT MORE SIMPLE ]
  10. // +----------------------------------------------------------------------
  11. // | Copyright (c) 2018-2020 rights reserved.
  12. // +----------------------------------------------------------------------
  13. // | [ 服务标签管理 ]
  14. // +----------------------------------------------------------------------
  15. // | Date: 2020-09-06 21:53
  16. // +----------------------------------------------------------------------
  17. class ServiceLabel extends BaseController{
  18. /**
  19. * 标签列表
  20. * @param Request $request
  21. * @return type
  22. */
  23. public function list(Request $request) {
  24. $post = UtilService::getMore([
  25. ['page',1],
  26. ['pageSize', 50],
  27. ['title',''],
  28. ['status',''],
  29. ],$request);
  30. $data = (new LabelModel)->getList($post);
  31. return app('json')->success([
  32. 'list' => $data["list"],
  33. 'pageCount' => $data["totalCount"],
  34. 'pageSize' => $data["pageSize"],
  35. 'page' => $data["page"],
  36. ]);
  37. }
  38. /**
  39. * 标签添加
  40. */
  41. public function add(Request $request){
  42. $post = UtilService::getMore([
  43. ['id','0'],
  44. ['title','','empty','请输入标签名称'],
  45. ['seq','0'],
  46. ['type','common'],
  47. ['status','1']
  48. ],$request);
  49. $id = $post["id"];
  50. unset($post["id"]);
  51. $r=0;
  52. if(empty($id) || $id=="0"){
  53. $r = (new LabelModel)->insert($post);
  54. }else{
  55. $r = (new LabelModel)->where("id",$id)->update($post);
  56. }
  57. if($r){
  58. return app('json')->success("数据保存成功");
  59. }else{
  60. return app('json')->fail("数据保存失败");
  61. }
  62. }
  63. /**
  64. * 标签删除
  65. * @param Request $request
  66. */
  67. public function del(Request $request) {
  68. [$id] = UtilService::getMore([
  69. ['id',0,'empty','参数错误']
  70. ],$request,true);
  71. $bool = (new LabelModel)->where("id",$id)->delete();
  72. return app('json')->success("分类删除成功");
  73. }
  74. }