AgriculturalMachineryServiceCategoryLogic.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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\ServiceCategory as 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. 'type' => $params['type'],
  37. 'status' => $params['status'] ?? 1,
  38. 'sort' => $params['sort'] ?? 0
  39. ]);
  40. }
  41. /**
  42. * @notes 编辑农耕分类
  43. * @param array $params
  44. * @return bool
  45. * @author heshihu
  46. * @date 2022/2/21 17:50
  47. */
  48. public static function edit(array $params) : bool
  49. {
  50. try {
  51. AgriculturalMachineryServiceCategory::update([
  52. 'id' => $params['id'],
  53. 'name' => $params['name'],
  54. 'status' => $params['status'] ?? 1,
  55. 'sort' => $params['sort'] ?? 0
  56. ]);
  57. return true;
  58. } catch (\Exception $e) {
  59. self::setError($e->getMessage());
  60. return false;
  61. }
  62. }
  63. /**
  64. * @notes 删除农耕分类
  65. * @param array $params
  66. * @author heshihu
  67. * @date 2022/2/21 17:52
  68. */
  69. public static function delete(array $params)
  70. {
  71. AgriculturalMachineryServiceCategory::destroy($params['id']);
  72. }
  73. /**
  74. * @notes 查看农耕分类详情
  75. * @param $params
  76. * @return array
  77. * @author heshihu
  78. * @date 2022/2/21 17:54
  79. */
  80. public static function detail($params) : array
  81. {
  82. return AgriculturalMachineryServiceCategory::findOrEmpty($params['id'])->toArray();
  83. }
  84. /**
  85. * @notes 更改农耕分类状态
  86. * @param array $params
  87. * @return bool
  88. * @author heshihu
  89. * @date 2022/2/21 18:04
  90. */
  91. public static function updateStatus(array $params)
  92. {
  93. AgriculturalMachineryServiceCategory::update([
  94. 'id' => $params['id'],
  95. 'status' => $params['status']
  96. ]);
  97. return true;
  98. }
  99. /**
  100. * @notes 有效农耕分类数据
  101. * @return array
  102. * @throws \think\db\exception\DataNotFoundException
  103. * @throws \think\db\exception\DbException
  104. * @throws \think\db\exception\ModelNotFoundException
  105. * @author 段誉
  106. * @date 2022/10/13 10:53
  107. */
  108. public static function getValidCateData($get)
  109. {
  110. $list = AgriculturalMachineryServiceCategory::where(['status' => YesNoEnum::YES,'type'=>$get['type']])
  111. ->field('id,name')
  112. ->order(['sort' => 'desc', 'id' => 'desc'])
  113. ->select()
  114. ->toArray();
  115. return $list;
  116. }
  117. }