MemberinterestsRepository.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\user;
  12. use app\common\dao\user\MemberInterestsDao;
  13. use app\common\dao\user\UserBrokerageDao;
  14. use app\common\repositories\BaseRepository;
  15. use FormBuilder\Factory\Elm;
  16. use think\exception\ValidateException;
  17. use think\facade\Route;
  18. /**
  19. * @mixin UserBrokerageDao
  20. */
  21. class MemberinterestsRepository extends BaseRepository
  22. {
  23. const TYPE_FREE = 1;
  24. //付费会员
  25. const TYPE_SVIP = 2;
  26. const HAS_TYPE_PRICE = 1;
  27. const HAS_TYPE_SIGN = 2;
  28. const HAS_TYPE_PAY = 3;
  29. const HAS_TYPE_SERVICE = 4;
  30. const HAS_TYPE_MEMBER = 5;
  31. const HAS_TYPE_COUPON = 6;
  32. //签到收益
  33. const INTERESTS_TYPE = [
  34. 1 => ['label'=> '会员特价', 'msg' => ''],
  35. 2 => ['label'=> '签到返利' , 'msg' => '红包米倍数' ],
  36. 3 => ['label'=> '消费返利' , 'msg' => '红包米倍数' ],
  37. 4 => ['label'=> '专属客服' , 'msg' => '' ],
  38. 5 => ['label'=> '经验翻倍' , 'msg' => '经验翻倍' ],
  39. 6 => ['label'=> '会员优惠券', 'msg' => ''],
  40. ];
  41. public function __construct(MemberInterestsDao $dao)
  42. {
  43. $this->dao = $dao;
  44. }
  45. public function getList(array $where, int $page, int $limit)
  46. {
  47. $query = $this->dao->getSearch($where);
  48. $count = $query->count();
  49. $list = $query->page($page, $limit)->select();
  50. return compact('count','list');
  51. }
  52. public function getSvipInterestVal($has_type)
  53. {
  54. return max(((float)$this->dao->query(['status' => 1])->where('has_type', $has_type)->where('type', 2)->value('value')) ?: 0, 0);
  55. }
  56. public function form(?int $id = null, $type = self::TYPE_FREE)
  57. {
  58. $formData = [];
  59. if ($id) {
  60. $data = $this->dao->get($id);
  61. if (!$data) throw new ValidateException('数据不存在');
  62. $form = Elm::createForm(Route::buildUrl('systemUserMemberInterestsUpdate', ['id' => $id])->build());
  63. $formData = $data->toArray();
  64. } else {
  65. $form = Elm::createForm(Route::buildUrl('systemUserMemberInterestsCreate')->build());
  66. }
  67. $rules = [
  68. Elm::input('name', '权益名称')->required(),
  69. Elm::input('info', '权益简介')->required(),
  70. Elm::frameImage('pic', '图标', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=pic&type=1')
  71. ->value($formData['pic'] ?? '')
  72. ->modal(['modal' => false])
  73. ->width('896px')
  74. ->height('480px'),
  75. Elm::select('brokerage_level', '会员级别')->options(function () use($type){
  76. $options = app()->make(UserBrokerageRepository::class)->options(['type' => $type])->toArray();
  77. return $options;
  78. }),
  79. ];
  80. $form->setRule($rules);
  81. return $form->setTitle(is_null($id) ? '添加权益' : '编辑权益')->formData($formData);
  82. }
  83. public function getInterestsByLevel(int $type, $level = 0)
  84. {
  85. if ($type == self::TYPE_FREE) {
  86. $list = $this->dao->getSearch(['type' => $type])->select();
  87. foreach ($list as $item) {
  88. $item['status'] = 0;
  89. if ($item['brokerage_level'] <= $level) {
  90. $item['status'] = 1;
  91. }
  92. }
  93. } else {
  94. $list = $this->dao->getSearch(['type' => $type,'status' => 1])->select();
  95. }
  96. return $list;
  97. }
  98. public function svipForm(int $id)
  99. {
  100. $data = $this->dao->get($id);
  101. if (!$data) throw new ValidateException('数据不存在');
  102. $form = Elm::createForm(Route::buildUrl('systemUserSvipInterestsUpdate', ['id' => $id])->build());
  103. $formData = $data->toArray();
  104. $rules = [
  105. Elm::select('has_type', '权益名称')->options(function(){
  106. foreach (self::INTERESTS_TYPE as $k => $v) {
  107. $res[] = ['value' => $k, 'label' => $v['label']];
  108. }
  109. return $res;
  110. })->disabled(true),
  111. Elm::input('name', '展示名称')->required(),
  112. Elm::input('info', '权益简介')->required(),
  113. Elm::frameImage('pic', '未开通图标', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=pic&type=1')
  114. ->value($formData['pic'] ?? '')->required()
  115. ->modal(['modal' => false])
  116. ->width('896px')
  117. ->height('480px'),
  118. Elm::frameImage('on_pic', '已开通图标', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=on_pic&type=1')
  119. ->value($formData['on_pic'] ?? '')->required()
  120. ->modal(['modal' => false])
  121. ->width('896px')
  122. ->height('480px'),
  123. Elm::input('link', '跳转内部链接'),
  124. ];
  125. $msg = self::INTERESTS_TYPE[$formData['has_type']]['msg'];
  126. if ($msg) $rules[] = Elm::number('value',$msg,0);
  127. $form->setRule($rules);
  128. return $form->setTitle('编辑会员权益')->formData($formData);
  129. }
  130. }