MemberShipServices.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\user\member;
  12. use app\dao\user\MemberShipDao;
  13. use app\services\BaseServices;
  14. use crmeb\exceptions\AdminException;
  15. /**
  16. * Class MemberShipServices
  17. * @package app\services\user
  18. */
  19. class MemberShipServices extends BaseServices
  20. {
  21. public function __construct(MemberShipDao $memberShipDao)
  22. {
  23. $this->dao = $memberShipDao;
  24. }
  25. /**后台获取会员类型
  26. * @param array $where
  27. * @return array
  28. */
  29. public function getSearchList(array $where = [])
  30. {
  31. [$page, $limit] = $this->getPageValue();
  32. $list = $this->dao->getSearchList($where, $page, $limit);
  33. $count = $this->dao->count($where);
  34. return compact('list', 'count');
  35. }
  36. /**获取会员卡api接口
  37. * @return mixed
  38. */
  39. public function getApiList(array $where)
  40. {
  41. return $this->dao->getApiList($where);
  42. }
  43. /** 卡类型编辑保存
  44. * @param int $id
  45. * @param array $data
  46. */
  47. public function save(int $id, array $data)
  48. {
  49. if (!$data['title']) throw new AdminException(400641);
  50. if (!$data['type']) throw new AdminException(400642);
  51. if ($data['type'] == "ever") {
  52. $data['vip_day'] = -1;
  53. } else {
  54. if (!$data['vip_day']) throw new AdminException(400643);
  55. if ($data['vip_day'] < 0) throw new AdminException(400644);
  56. }
  57. if ($data['type'] == "free") {
  58. $data['pre_price'] = 0.00;
  59. } else {
  60. if ($data['pre_price'] == 0 || $data['price'] == 0) throw new AdminException(400645);
  61. }
  62. if ($data['pre_price'] < 0 || $data['price'] < 0) throw new AdminException(400646);
  63. if ($data['pre_price'] > $data['price']) throw new AdminException(400647);
  64. if ($id){
  65. return $this->dao->update($id, $data);
  66. }else{
  67. return $this->dao->save($data);
  68. }
  69. }
  70. /**获取卡会员天数
  71. * @param array $where
  72. * @return mixed
  73. */
  74. public function getVipDay(array $where)
  75. {
  76. return $this->dao->value($where, 'vip_day');
  77. }
  78. /**
  79. * 修改会员类型状态
  80. * @param $id
  81. * @param $is_del
  82. * @return bool
  83. */
  84. public function setStatus($id, $is_del)
  85. {
  86. $res = $this->dao->update($id, ['is_del' => $is_del]);
  87. if ($res) return true;
  88. return false;
  89. }
  90. }