Group.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\service\users;
  10. use app\admin\service\Service;
  11. use app\common\models\users\UsersGroup as UsersGroupModel;
  12. class Group extends Service {
  13. /**
  14. * 获取列表数据
  15. * @param $data
  16. * @return array
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\DbException
  19. * @throws \think\db\exception\ModelNotFoundException
  20. */
  21. public static function getList($data){
  22. $count = UsersGroupModel::count();
  23. $result = UsersGroupModel::page($data["page"]??1,$data["limit"]??10)->order("id","desc")->select()->toArray();
  24. return [ "count"=>$count, "data"=>$result ];
  25. }
  26. /**
  27. * 详情
  28. * @param $id
  29. * @return array[]
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public static function detail($id){
  35. return ["data"=>UsersGroupModel::where("id",$id)->find()??[]];
  36. }
  37. /**
  38. * 保存数据
  39. * @param $data
  40. * @return bool
  41. */
  42. public static function save($data){
  43. if(UsersGroupModel::where("id",$data["id"])->count()){
  44. UsersGroupModel::where("id",$data["id"])->save($data);
  45. }else{
  46. UsersGroupModel::create($data);
  47. }
  48. return true;
  49. }
  50. /**
  51. * 删除
  52. * @param $id
  53. * @return bool
  54. */
  55. public static function delete($id){
  56. return UsersGroupModel::where("id",$id)->delete();
  57. }
  58. }