GrantLogic.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\logics;
  3. use app\model\Employee;
  4. use app\model\Grant;
  5. use app\model\User;
  6. class GrantLogic
  7. {
  8. public static function grantlist(){
  9. $list = Grant::select();
  10. return $list;
  11. }
  12. public static function grantselectorlist(){
  13. $list = Grant::field('id,name')->select();
  14. return $list;
  15. }
  16. public static function save($data){
  17. $obj = new Grant();
  18. $obj->save($data);
  19. return $obj;
  20. }
  21. public static function get($id){
  22. return Grant::find($id)->toArray();
  23. }
  24. public static function update($data){
  25. $id = $data['grant_id'];
  26. unset($data['grant_id']);
  27. return Grant::where('id', $id)->update($data);
  28. }
  29. ///
  30. public static function getUserPermissions($openid)
  31. {
  32. if($openid == 'adminopenid'){
  33. $grant = Grant::find(1);
  34. return $grant->permission;
  35. }else{
  36. $currentUser = User::where('openid', $openid)->find();
  37. if(!$currentUser) return false;
  38. $employee = Employee::where('uid', $currentUser->id)->find();
  39. if(!$employee) return false;
  40. $grant = Grant::find($employee->grant_id);
  41. return $grant->permission;
  42. }
  43. }
  44. public static function delete($id){
  45. if(Employee::where(['grant_id' => $id])->count() > 0){
  46. return 'in_use';
  47. }else{
  48. return Grant::find($id)->delete();
  49. }
  50. }
  51. }