JobsLogic.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\tenantapi\logic\dept;
  15. use app\common\enum\YesNoEnum;
  16. use app\common\logic\BaseLogic;
  17. use app\common\model\dept\TenantJobs;
  18. /**
  19. * 岗位管理逻辑
  20. * Class JobsLogic
  21. * @package app\tenantapi\logic\dept
  22. */
  23. class JobsLogic extends BaseLogic
  24. {
  25. /**
  26. * @notes 新增岗位
  27. * @param array $params
  28. * @author 段誉
  29. * @date 2022/5/26 9:58
  30. */
  31. public static function add(array $params)
  32. {
  33. TenantJobs::create([
  34. 'name' => $params['name'],
  35. 'code' => $params['code'],
  36. 'sort' => $params['sort'] ?? 0,
  37. 'status' => $params['status'],
  38. 'remark' => $params['remark'] ?? '',
  39. ]);
  40. }
  41. /**
  42. * @notes 编辑岗位
  43. * @param array $params
  44. * @return bool
  45. * @author 段誉
  46. * @date 2022/5/26 9:58
  47. */
  48. public static function edit(array $params) : bool
  49. {
  50. try {
  51. TenantJobs::update([
  52. 'name' => $params['name'],
  53. 'code' => $params['code'],
  54. 'sort' => $params['sort'] ?? 0,
  55. 'status' => $params['status'],
  56. 'remark' => $params['remark'] ?? '',
  57. ], ['id' => $params['id']]);
  58. return true;
  59. } catch (\Exception $e) {
  60. self::setError($e->getMessage());
  61. return false;
  62. }
  63. }
  64. /**
  65. * @notes 删除岗位
  66. * @param array $params
  67. * @author 段誉
  68. * @date 2022/5/26 9:59
  69. */
  70. public static function delete(array $params)
  71. {
  72. TenantJobs::destroy($params['id']);
  73. }
  74. /**
  75. * @notes 获取岗位详情
  76. * @param $params
  77. * @return array
  78. * @author 段誉
  79. * @date 2022/5/26 9:59
  80. */
  81. public static function detail($params) : array
  82. {
  83. return TenantJobs::findOrEmpty($params['id'])->toArray();
  84. }
  85. /**
  86. * @notes 岗位数据
  87. * @return array
  88. * @throws \think\db\exception\DataNotFoundException
  89. * @throws \think\db\exception\DbException
  90. * @throws \think\db\exception\ModelNotFoundException
  91. * @author 段誉
  92. * @date 2022/10/13 10:30
  93. */
  94. public static function getAllData()
  95. {
  96. return TenantJobs::where(['status' => YesNoEnum::YES])
  97. ->order(['sort' => 'desc', 'id' => 'desc'])
  98. ->select()
  99. ->toArray();
  100. }
  101. }