You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MemberRightServices.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\services\user\member;
  3. use app\dao\user\member\MemberRightDao;
  4. use app\services\BaseServices;
  5. use crmeb\exceptions\AdminException;
  6. /**
  7. * Class MemberRightServices
  8. * @package app\services\user\member
  9. */
  10. class MemberRightServices extends BaseServices
  11. {
  12. /**
  13. * MemberRightServices constructor.
  14. * @param MemberRightDao $memberRightDao
  15. */
  16. public function __construct(MemberRightDao $memberRightDao)
  17. {
  18. $this->dao = $memberRightDao;
  19. }
  20. /**
  21. * @param array $where
  22. * @return array
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\DbException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. */
  27. public function getSearchList(array $where = [])
  28. {
  29. [$page, $limit] = $this->getPageValue();
  30. $list = $this->dao->getSearchList($where, $page, $limit);
  31. foreach ($list as &$item) {
  32. $item['image'] = set_file_url($item['image']);
  33. }
  34. $count = $this->dao->count($where);
  35. return compact('list', 'count');
  36. }
  37. /**
  38. * 编辑保存
  39. * @param int $id
  40. * @param array $data
  41. */
  42. public function save(int $id, array $data)
  43. {
  44. if (!$data['right_type']) throw new AdminException("会员权益类型缺失");
  45. if (!$id) throw new AdminException("id参数缺失");
  46. if (!$data['title'] || !$data['show_title']) throw new AdminException("请设置权益名称");
  47. if (!$data['image']) throw new AdminException("请上传会员权益图标");
  48. switch ($data['right_type']) {
  49. case "integral":
  50. if (!$data['number']) throw new AdminException("请设置返还积分倍数");
  51. if ($data['number'] < 0) throw new AdminException("返还积分倍数不能为负数");
  52. $save['number'] = abs($data['number']);
  53. break;
  54. case "express" :
  55. if (!$data['number']) throw new AdminException("请设置运费折扣");
  56. if ($data['number'] < 0) throw new AdminException("运费折扣不能为负数");
  57. $save['number'] = abs($data['number']);
  58. break;
  59. case "sign" :
  60. if (!$data['number']) throw new AdminException("请设置签到积分倍数");
  61. if ($data['number'] < 0) throw new AdminException("签到积分倍数不能为负数");
  62. $save['number'] = abs($data['number']);
  63. break;
  64. case "offline" :
  65. if (!$data['number']) throw new AdminException("请设置线下付款折扣");
  66. if ($data['number'] < 0) throw new AdminException("线下付款不能为负数");
  67. $save['number'] = abs($data['number']);
  68. }
  69. $save['show_title'] = $data['show_title'];
  70. $save['image'] = $data['image'];
  71. $save['status'] = $data['status'];
  72. $save['sort'] = $data['sort'];
  73. return $this->dao->update($id, $data);
  74. }
  75. /**
  76. * 获取单条信息
  77. * @param array $where
  78. * @param string $field
  79. * @return array|false|\think\Model|null
  80. * @throws \think\db\exception\DataNotFoundException
  81. * @throws \think\db\exception\DbException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. */
  84. public function getOne(array $where, string $field = '*')
  85. {
  86. if (!$where) return false;
  87. return $this->dao->getOne($where, $field);
  88. }
  89. /**
  90. * 查看某权益是否开启
  91. * @param $rightType
  92. * @return bool
  93. */
  94. public function getMemberRightStatus($rightType)
  95. {
  96. if (!$rightType) return false;
  97. $status = $this->dao->value(['right_type' => $rightType], 'status');
  98. if ($status) return true;
  99. return false;
  100. }
  101. }