UserLabelLogic.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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\user;
  20. use app\common\{
  21. model\UserLabel,
  22. model\UserLabelIndex
  23. };
  24. /**
  25. * 标签逻辑层
  26. * Class UserLabelLogic
  27. * @package app\adminapi\logic\user
  28. */
  29. class UserLabelLogic
  30. {
  31. /**
  32. * @notes 新增用户标签
  33. * @param array $params
  34. * @return bool
  35. * @author cjhao
  36. * @date 2021/7/28 17:43
  37. */
  38. public function add(array $params)
  39. {
  40. $userLable = new UserLabel();
  41. $userLable->name = $params['name'];
  42. $userLable->remark = $params['remark'];
  43. $userLable->label_type = $params['label_type'];
  44. $userLable->save();
  45. return true;
  46. }
  47. /**
  48. * @notes 标签详情
  49. * @param int $id
  50. * @return array
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. * @author cjhao
  55. * @date 2021/7/28 17:58
  56. */
  57. public function detail(int $id)
  58. {
  59. return UserLabel::field('id,name,remark,label_type')->find($id)->toArray();
  60. }
  61. /**
  62. * @notes 编辑用户标签
  63. * @param array $params
  64. * @return bool
  65. * @author cjhao
  66. * @date 2021/7/28 17:47
  67. */
  68. public function edit(array $params)
  69. {
  70. $updateData = [
  71. 'id' => $params['id'],
  72. 'name' => $params['name'],
  73. 'remark' => $params['remark'],
  74. 'label_type' => $params['label_type'],
  75. ];
  76. UserLabel::update($updateData);
  77. return true;
  78. }
  79. /**
  80. * @notes 删除标签
  81. * @param int $ids
  82. * @return bool
  83. * @author cjhao
  84. * @date 2021/7/28 18:36
  85. */
  86. public function del(array $ids)
  87. {
  88. UserLabel::destroy($ids);
  89. UserLabelIndex::where(['label_id'=>$ids])->delete();
  90. return UserLabel::destroy($ids);
  91. }
  92. }