Auth.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 权限管理
  7. */
  8. namespace app\fastshop\model;
  9. use think\Model;
  10. class Auth extends Model{
  11. protected $pk = 'id';
  12. protected $table = 'ai_fastshop_auth';
  13. //添加或编辑
  14. public static function edit($param){
  15. $data['types'] = trim($param['types']);
  16. $info = self::where(['member_miniapp_id' => $param['member_miniapp_id'],'member_id' => $param['id']])->find();
  17. if(empty($info)){
  18. $data['member_id'] = $param['id'];
  19. $data['member_miniapp_id'] = $param['member_miniapp_id'];
  20. return self::insert($data);
  21. }else{
  22. return self::where(['id' => $info->id])->update($data);
  23. }
  24. }
  25. /**
  26. * 是否有权限
  27. * @param int $uid
  28. * @return void
  29. */
  30. public static function getAuth(int $uid,int $types){
  31. $auth = self::where(['member_id' => $uid])->field('types')->find();
  32. if(empty($auth)){
  33. return true;
  34. }
  35. if ($auth->types > 0) {
  36. return $auth->types == $types ? true : false;
  37. }
  38. return true;
  39. }
  40. }