12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace app\logics;
- use app\model\Employee;
- use app\model\Grant;
- use app\model\User;
- class GrantLogic
- {
- public static function grantlist(){
- $list = Grant::select();
- return $list;
- }
- public static function grantselectorlist(){
- $list = Grant::field('id,name')->select();
- return $list;
- }
- public static function save($data){
- $obj = new Grant();
- $obj->save($data);
- return $obj;
- }
- public static function get($id){
- return Grant::find($id)->toArray();
- }
- public static function update($data){
- $id = $data['grant_id'];
- unset($data['grant_id']);
- return Grant::where('id', $id)->update($data);
- }
- ///
- public static function getUserPermissions($openid)
- {
- if($openid == 'adminopenid'){
- $grant = Grant::find(1);
- return $grant->permission;
- }else{
- $currentUser = User::where('openid', $openid)->find();
- if(!$currentUser) return false;
- $employee = Employee::where('uid', $currentUser->id)->find();
- if(!$employee) return false;
- $grant = Grant::find($employee->grant_id);
- return $grant->permission;
- }
- }
- public static function delete($id){
- if(Employee::where(['grant_id' => $id])->count() > 0){
- return 'in_use';
- }else{
- return Grant::find($id)->delete();
- }
- }
- }
|