MemberRightServices.php 4.3 KB

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