YzPermission.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 02/03/2017
  6. * Time: 18:28
  7. */
  8. namespace app\common\models\user;
  9. use app\common\models\BaseModel;
  10. use Illuminate\Database\Eloquent\SoftDeletes;
  11. class YzPermission extends BaseModel
  12. {
  13. const TYPE_USER = 1;
  14. const TYPE_ROLE = 2;
  15. const TYPE_ACCOUNT = 3;
  16. public $table = 'yz_permission';
  17. public $timestamps = false;
  18. protected $guarded = [''];
  19. /*
  20. * 通过操作员ID获得操作员个人所有操作权限
  21. *
  22. * @param int $userId
  23. *
  24. * @return object */
  25. public static function gerUserPermissonByUserId($userId)
  26. {
  27. return static::where('type', '=', static::TYPE_USER)->where('item_id', $userId)->first();
  28. }
  29. /*
  30. * 添加操作员权限 或 添加角色权限 多条数据同时写入
  31. *
  32. * @param array $data
  33. *
  34. * @return result */
  35. public static function insertYzPermission(array $data = [])
  36. {
  37. return static::insert($data);
  38. }
  39. /*
  40. * 通过操作员ID删除操作员所有权限
  41. *
  42. * @param int $userId
  43. *
  44. * @return result */
  45. public static function deleteUserPermissionByUserId($userId)
  46. {
  47. return static::where('type', '=', static::TYPE_USER)->where('item_id', $userId)->delete();
  48. }
  49. /**
  50. * Delete role permissions by roleId
  51. *
  52. * @param int $roleId
  53. * @return \mysqli_result
  54. */
  55. public static function deleteRolePermission($roleId)
  56. {
  57. return static::where('type', '=', static::TYPE_ROLE)->where('item_id', $roleId)->delete();
  58. }
  59. }