MemberRightServices.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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\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 MemberRightDao $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(400630);
  54. if (!$id) throw new AdminException(100100);
  55. if (!$data['title'] || !$data['show_title']) throw new AdminException(400631);
  56. if (!$data['image']) throw new AdminException(400632);
  57. if (mb_strlen($data['show_title']) > 6) throw new AdminException(400755);
  58. if (mb_strlen($data['explain']) > 8) throw new AdminException(400752);
  59. switch ($data['right_type']) {
  60. case "integral":
  61. if (!$data['number']) throw new AdminException(400633);
  62. if ($data['number'] < 0) throw new AdminException(400634);
  63. $save['number'] = abs($data['number']);
  64. break;
  65. case "express" :
  66. if (!$data['number']) throw new AdminException(400635);
  67. if ($data['number'] < 0) throw new AdminException(400636);
  68. $save['number'] = abs($data['number']);
  69. break;
  70. case "sign" :
  71. if (!$data['number']) throw new AdminException(400637);
  72. if ($data['number'] < 0) throw new AdminException(400638);
  73. $save['number'] = abs($data['number']);
  74. break;
  75. case "offline" :
  76. if (!$data['number']) throw new AdminException(400639);
  77. if ($data['number'] < 0) throw new AdminException(400640);
  78. $save['number'] = abs($data['number']);
  79. }
  80. $save['show_title'] = $data['show_title'];
  81. $save['image'] = $data['image'];
  82. $save['status'] = $data['status'];
  83. $save['sort'] = $data['sort'];
  84. //TODO $save没有使用
  85. return $this->dao->update($id, $data);
  86. }
  87. /**
  88. * 获取单条信息
  89. * @param array $where
  90. * @return array|bool|\think\Model|null
  91. * @throws \think\db\exception\DataNotFoundException
  92. * @throws \think\db\exception\DbException
  93. * @throws \think\db\exception\ModelNotFoundException
  94. */
  95. public function getOne(array $where)
  96. {
  97. if (!$where) return false;
  98. return $this->dao->getOne($where);
  99. }
  100. /**
  101. * 查看某权益是否开启
  102. * @param $rightType
  103. * @return bool
  104. */
  105. public function getMemberRightStatus($rightType)
  106. {
  107. if (!$rightType) return false;
  108. $status = $this->dao->value(['right_type' => $rightType], 'status');
  109. if ($status) return true;
  110. return false;
  111. }
  112. }