AgriculturalMachineryServiceCategoryLogic.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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\adminapi\logic\agricultural_machinery;
  15. use app\common\enum\YesNoEnum;
  16. use app\common\logic\BaseLogic;
  17. use app\common\model\article\ArticleCate;
  18. use app\common\model\agricultural_machinery\AgriculturalMachineryServiceCategory;
  19. /**
  20. * 农耕分类管理逻辑
  21. * Class ArticleCateLogic
  22. * @package app\adminapi\logic\article
  23. */
  24. class AgriculturalMachineryServiceCategoryLogic extends BaseLogic
  25. {
  26. /**
  27. * @notes 添加农耕分类
  28. * @param array $params
  29. * @author heshihu
  30. * @date 2022/2/18 10:17
  31. */
  32. public static function add(array $params)
  33. {
  34. AgriculturalMachineryServiceCategory::create([
  35. 'name' => $params['name'],
  36. 'status' => $params['status'] ?? 1,
  37. 'sort' => $params['sort'] ?? 0
  38. ]);
  39. }
  40. /**
  41. * @notes 编辑农耕分类
  42. * @param array $params
  43. * @return bool
  44. * @author heshihu
  45. * @date 2022/2/21 17:50
  46. */
  47. public static function edit(array $params) : bool
  48. {
  49. try {
  50. AgriculturalMachineryServiceCategory::update([
  51. 'id' => $params['id'],
  52. 'name' => $params['name'],
  53. 'status' => $params['status'] ?? 1,
  54. 'sort' => $params['sort'] ?? 0
  55. ]);
  56. return true;
  57. } catch (\Exception $e) {
  58. self::setError($e->getMessage());
  59. return false;
  60. }
  61. }
  62. /**
  63. * @notes 删除农耕分类
  64. * @param array $params
  65. * @author heshihu
  66. * @date 2022/2/21 17:52
  67. */
  68. public static function delete(array $params)
  69. {
  70. AgriculturalMachineryServiceCategory::destroy($params['id']);
  71. }
  72. /**
  73. * @notes 查看农耕分类详情
  74. * @param $params
  75. * @return array
  76. * @author heshihu
  77. * @date 2022/2/21 17:54
  78. */
  79. public static function detail($params) : array
  80. {
  81. return AgriculturalMachineryServiceCategory::findOrEmpty($params['id'])->toArray();
  82. }
  83. /**
  84. * @notes 更改农耕分类状态
  85. * @param array $params
  86. * @return bool
  87. * @author heshihu
  88. * @date 2022/2/21 18:04
  89. */
  90. public static function updateStatus(array $params)
  91. {
  92. AgriculturalMachineryServiceCategory::update([
  93. 'id' => $params['id'],
  94. 'status' => $params['status']
  95. ]);
  96. return true;
  97. }
  98. /**
  99. * @notes 有效农耕分类数据
  100. * @return array
  101. * @throws \think\db\exception\DataNotFoundException
  102. * @throws \think\db\exception\DbException
  103. * @throws \think\db\exception\ModelNotFoundException
  104. * @author 段誉
  105. * @date 2022/10/13 10:53
  106. */
  107. public static function getValidCateData()
  108. {
  109. return AgriculturalMachineryServiceCategory::where(['status' => YesNoEnum::YES])
  110. ->field('id,name')
  111. ->order(['sort' => 'desc', 'id' => 'desc'])
  112. ->select()
  113. ->toArray();
  114. }
  115. }