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.

MemberShipServices.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\services\user\member;
  3. use app\dao\user\member\MemberShipDao;
  4. use app\services\BaseServices;
  5. use crmeb\exceptions\AdminException;
  6. use think\exception\ValidateException;
  7. /**
  8. * Class MemberShipServices
  9. * @package app\services\user\member
  10. * @method value(array $where, ?string $field)
  11. */
  12. class MemberShipServices extends BaseServices
  13. {
  14. public function __construct(MemberShipDao $memberShipDao)
  15. {
  16. $this->dao = $memberShipDao;
  17. }
  18. /**
  19. * 获取单个付费会员信息
  20. * @param int $id
  21. * @param string $field
  22. * @return array|\think\Model
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\DbException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. */
  27. public function getMemberInfo(int $id, string $field = '*')
  28. {
  29. $member = $this->dao->getOne(['id' => $id, 'is_del' => 0], $field);
  30. if (!$member) {
  31. throw new ValidateException('该会员类型不存在或已删除');
  32. }
  33. return $member;
  34. }
  35. /**
  36. * 后台获取会员类型
  37. * @param array $where
  38. * @return array
  39. */
  40. public function getSearchList(array $where = [])
  41. {
  42. [$page, $limit] = $this->getPageValue();
  43. $list = $this->dao->getSearchList($where, $page, $limit);
  44. $count = $this->dao->count($where);
  45. return compact('list', 'count');
  46. }
  47. /**
  48. * 获取会员卡api接口
  49. * @return mixed
  50. */
  51. public function getApiList(array $where)
  52. {
  53. return $this->dao->getApiList($where);
  54. }
  55. /**
  56. * 卡类型编辑保存
  57. * @param int $id
  58. * @param array $data
  59. */
  60. public function save(int $id, array $data)
  61. {
  62. if (!$data['type']) throw new AdminException("会员卡类型缺失");
  63. if ($data['type'] == "ever") {
  64. $data['vip_day'] = -1;
  65. } else {
  66. if (!$data['vip_day']) throw new AdminException("请填写体验天数");
  67. if ($data['vip_day'] < 0) throw new AdminException("体验天数不能为负数");
  68. }
  69. if ($data['type'] == "free") {
  70. // $data['price'] = 0.00;
  71. $data['pre_price'] = 0.00;
  72. } else {
  73. if ($data['pre_price'] == 0 || $data['price'] == 0) throw new AdminException("请填写价格");
  74. }
  75. if ($data['pre_price'] < 0 || $data['price'] < 0) throw new AdminException("价格不能为负数");
  76. if ($data['pre_price'] > $data['price']) throw new AdminException("优惠价不能大于原价");
  77. if ($id) {
  78. return $this->dao->update($id, $data);
  79. } else {
  80. return $this->dao->save($data);
  81. }
  82. }
  83. /**
  84. * 获取卡会员天数
  85. * @param array $where
  86. * @return mixed
  87. */
  88. public function getVipDay(array $where)
  89. {
  90. return $this->dao->value($where, 'vip_day');
  91. }
  92. /**
  93. * 修改会员类型状态
  94. * @param $id
  95. * @param $is_del
  96. * @return bool
  97. */
  98. public function setStatus($id, $is_del)
  99. {
  100. $res = $this->dao->update($id, ['is_del' => $is_del]);
  101. if ($res) return true;
  102. return false;
  103. }
  104. /**
  105. * 查询会员类型select
  106. * @return array
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\DbException
  109. * @throws \think\db\exception\ModelNotFoundException
  110. */
  111. public function getShipSelect()
  112. {
  113. $menus = [];
  114. foreach ($this->dao->getSearchList(['is_del' => 0], 0, 0, ['id', 'title']) as $menu) {
  115. $menus[] = ['value' => $menu['id'], 'label' => $menu['title']];
  116. }
  117. return $menus;
  118. }
  119. }