InfoCategoryLogic.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\logic\info;
  20. use app\common\enum\DefaultEnum;
  21. use app\common\enum\YesNoEnum;
  22. use app\common\model\InfoCategory;
  23. class InfoCategoryLogic
  24. {
  25. /**
  26. * @notes 添加分类
  27. * @param $params
  28. * @return bool
  29. * @author ljj
  30. * @date 2021/7/14 5:00
  31. */
  32. public function add($params)
  33. {
  34. $InfoCategory = new InfoCategory;
  35. $InfoCategory->type = $params['type'];
  36. $InfoCategory->name = $params['name'] ?? '';
  37. $InfoCategory->sort = (isset($params['sort']) && !empty($params['sort'])) ? $params['sort'] : 50;
  38. $InfoCategory->is_show = $params['is_show'] ?? YesNoEnum::YES;
  39. return $InfoCategory->save();
  40. }
  41. /**
  42. * @notes 删除分类
  43. * @param $params
  44. * @return bool
  45. * @author ljj
  46. * @date 2021/7/15 10:37
  47. */
  48. public function del($params)
  49. {
  50. return InfoCategory::destroy($params['id']);
  51. }
  52. /**
  53. * @notes 编辑分类
  54. * @param $params
  55. * @return bool
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\DbException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. * @author ljj
  60. * @date 2021/7/15 11:05
  61. */
  62. public function edit($params)
  63. {
  64. $InfoCategory = InfoCategory::find($params['id']);
  65. $InfoCategory->type = $params['type'];
  66. $InfoCategory->name = $params['name'] ?? '';
  67. $InfoCategory->sort = (isset($params['sort']) && !empty($params['sort'])) ? $params['sort'] : 1;
  68. $InfoCategory->is_show = $params['is_show'] ?? YesNoEnum::YES;
  69. return $InfoCategory->save();
  70. }
  71. /**
  72. * @notes 修改分类状态
  73. * @param $params
  74. * @return bool
  75. * @throws \think\db\exception\DataNotFoundException
  76. * @throws \think\db\exception\DbException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. * @author ljj
  79. * @date 2021/7/15 11:41
  80. */
  81. public function status($params)
  82. {
  83. $InfoCategory = InfoCategory::find($params['id']);
  84. $InfoCategory->is_show = $params['is_show'];
  85. return $InfoCategory->save();
  86. }
  87. /**
  88. * @notes 查看分类详情
  89. * @param $params
  90. * @return array
  91. * @throws \think\db\exception\DataNotFoundException
  92. * @throws \think\db\exception\DbException
  93. * @throws \think\db\exception\ModelNotFoundException
  94. * @author ljj
  95. * @date 2021/7/19 4:45 下午
  96. */
  97. public function detail($params)
  98. {
  99. return InfoCategory::find($params['id'])->toArray();
  100. }
  101. }