Account_group.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Models;
  3. use DB;
  4. class Account_group extends BaseModel {
  5. protected $table = "account_group";
  6. public $timestamps = false;
  7. protected function getList($where='',$limit=20){
  8. $data=$this->orderBy('sort','desc');
  9. if(is_array($where)&&count($where)>0){
  10. $data=$data->where($where);
  11. }
  12. $data=$data->paginate($limit);
  13. return $data->toArray();
  14. }
  15. protected function addGroup($data){
  16. if(($res=$this->checkCode($data['group_code'],$data['group_name'])) < 0 ){
  17. return $res;
  18. }
  19. if(!isset($data['create_at'])){
  20. $data['create_at']=date('Y-m-d H:i:s');
  21. }
  22. if(!isset($data['identity'])){
  23. $data['identity']=UUID();
  24. }
  25. $resd=$this->insert($data);
  26. if(!$resd){
  27. return -240002;
  28. }
  29. return 1;
  30. }
  31. //检测重复
  32. protected function checkCode($code,$name){
  33. $res=$this->where('group_code',$code)->orWhere('group_name',$name)->first();
  34. if($res){
  35. return -240001;
  36. }
  37. return 1;
  38. }
  39. protected function getGroups($ids){
  40. $data=$this->whereIn('id',$ids)->get();
  41. if(!$data){
  42. return -240004;
  43. }
  44. return $data->toArray();
  45. }
  46. protected function getInfoById($id){
  47. $data=$this->where('group_code',$id)->first();
  48. if(!$data){
  49. return -240001;
  50. }
  51. return $data->toArray();
  52. }
  53. protected function getAllInfo(){
  54. $data=$this->orderBy('group_code','asc')->get();
  55. if(!$data){
  56. return array();
  57. }
  58. return $data->toArray();
  59. }
  60. }