SecurityCategoryServices.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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\SecurityCodeRecordDao;
  13. use app\dao\user\SecurityCategoryDao;
  14. use app\services\BaseServices;
  15. use crmeb\exceptions\AdminException;
  16. /**
  17. * Class MemberRightServices
  18. * @package app\services\user
  19. */
  20. class SecurityCategoryServices extends BaseServices
  21. {
  22. /**
  23. * MemberCardServices constructor.
  24. * @param securityCategoryDao $securityCategoryDao
  25. */
  26. public function __construct(SecurityCategoryDao $securityCategoryDao)
  27. {
  28. $this->dao = $securityCategoryDao;
  29. }
  30. /**
  31. * @param array $where
  32. * @return array
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. */
  37. public function getSearchList(array $where = [])
  38. {
  39. [$page, $limit] = $this->getPageValue();
  40. $list = $this->dao->getSearchList($where, $page, $limit);
  41. $count = $this->dao->count($where);
  42. return compact('list', 'count');
  43. }
  44. /**
  45. * 编辑保存
  46. * @param int $id
  47. * @param array $data
  48. */
  49. public function save(int $id, array $data)
  50. {
  51. if (!$data['point']) throw new AdminException(400630);
  52. if (!$data['name'] || !$data['price']) throw new AdminException(400631);
  53. //TODO $save没有使用
  54. if ($id>0) {
  55. $data['update_time'] = time();
  56. return $this->dao->update($id, $data);
  57. } else {
  58. $data['add_time'] = time();
  59. $data['status'] = 1;
  60. return $this->dao->save($data);
  61. }
  62. }
  63. /**
  64. * 列表操作
  65. * @param int $id
  66. * @param array $data
  67. */
  68. public function setValue(int $id, array $data)
  69. {
  70. if (!is_numeric($id) || !$id) throw new AdminException(100100);
  71. if (!isset($data['field']) || !isset($data['value']) || !$data['field']) throw new AdminException(100100);
  72. $this->dao->update($id, [$data['field'] => $data['value']]);
  73. }
  74. /**
  75. * 获取单条信息
  76. * @param array $where
  77. * @return array|bool|\think\Model|null
  78. * @throws \think\db\exception\DataNotFoundException
  79. * @throws \think\db\exception\DbException
  80. * @throws \think\db\exception\ModelNotFoundException
  81. */
  82. public function getOne(array $where)
  83. {
  84. if (!$where) return false;
  85. return $this->dao->getOne($where);
  86. }
  87. /**
  88. * 查看某权益是否开启
  89. * @param $rightType
  90. * @return bool
  91. */
  92. public function getMemberRightStatus($rightType)
  93. {
  94. if (!$rightType) return false;
  95. $status = $this->dao->value(['right_type' => $rightType], 'status');
  96. if ($status) return true;
  97. return false;
  98. }
  99. }