InstitutionalService.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\ActionLogModel;
  13. use App\Models\InstitutionalModel;
  14. use App\Services\BaseService;
  15. use App\Services\RedisService;
  16. /**
  17. * 制度参数管理-服务类
  18. * @author laravel开发员
  19. * @since 2020/11/11
  20. * @package App\Services\Common
  21. */
  22. class InstitutionalService extends BaseService
  23. {
  24. // 静态对象
  25. protected static $instance = null;
  26. /**
  27. * 构造函数
  28. * @author laravel开发员
  29. * @since 2020/11/11
  30. */
  31. public function __construct()
  32. {
  33. $this->model = new InstitutionalModel();
  34. }
  35. /**
  36. * 静态入口
  37. * @return static|null
  38. */
  39. public static function make()
  40. {
  41. if (!self::$instance) {
  42. self::$instance = (new static());
  43. }
  44. return self::$instance;
  45. }
  46. /**
  47. * 获取列表
  48. * @param $params 参数
  49. * @param int $pageSize 分页大小:默认 15
  50. * @return array
  51. */
  52. public function getDataList($params, $pageSize = 10, $field = [])
  53. {
  54. $query = $this->getQuery($params);
  55. $list = $query->select($field ? $field : ['a.*'])
  56. ->orderBy('a.id','desc')
  57. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  58. $list = $list ? $list->toArray() : [];
  59. if ($list) {
  60. foreach ($list['data'] as &$item) {
  61. $item['create_time'] = datetime($item['create_time'],'Y-m-d H:i:s');
  62. }
  63. }
  64. return [
  65. 'pageSize' => $pageSize,
  66. 'total' => isset($list['total']) ? $list['total'] : 0,
  67. 'list' => isset($list['data']) ? $list['data'] : []
  68. ];
  69. }
  70. /**
  71. * 查询构造
  72. * @param $params
  73. * @return \Illuminate\Database\Eloquent\Builder
  74. */
  75. public function getQuery($params)
  76. {
  77. $where = ['a.mark' => 1];
  78. return $this->model->from('institutional as a')
  79. ->where($where)
  80. ->where(function ($query) use ($params) {
  81. $kw = isset($params['keyword']) ? trim($params['keyword']) : '';
  82. if ($kw) {
  83. $query->where('a.name', 'like', "%{$params['keyword']}%");
  84. }
  85. })
  86. ->where(function ($query) use($params){
  87. $type = isset($params['type'])? $params['type'] : 0;
  88. if ($type) {
  89. $query->where('a.type', $type);
  90. }
  91. $status = isset($params['status'])? $params['status'] : 0;
  92. if (is_array($status)) {
  93. $query->whereIn('a.status', $status);
  94. } else if($status){
  95. $query->where('a.status', $status);
  96. }
  97. });
  98. }
  99. /**
  100. * 质押轮次奖励参数
  101. * @param $round 轮次
  102. * @return array|mixed
  103. */
  104. public function getAwardByRound($round)
  105. {
  106. $cacheKey = "caches:config:institutional_round_{$round}";
  107. $data = RedisService::get($cacheKey);
  108. if($data){
  109. return $data;
  110. }
  111. $data = $this->model->where('condition_num','<=', $round)
  112. ->where(['type'=>2,'status'=>1,'mark'=>1])
  113. ->select(['id','name','type','condition_num as round','value','status'])
  114. ->orderBy('condition_num','desc')
  115. ->first();
  116. $data = $data? $data->toArray() : [];
  117. if($data){
  118. RedisService::set($cacheKey, $data, 300, 600);
  119. }
  120. return $data;
  121. }
  122. /**
  123. * 推荐奖励制度参数
  124. * @return array|mixed
  125. */
  126. public function getAwardByFloor()
  127. {
  128. $cacheKey = "caches:config:institutional_floor";
  129. $data = RedisService::get($cacheKey);
  130. if($data){
  131. return $data;
  132. }
  133. $data = $this->model->where('floor','>', 0)
  134. ->where(['type'=>1,'status'=>1,'mark'=>1])
  135. ->select(['id','name','type','floor','value','status'])
  136. ->orderBy('floor','asc')
  137. ->get()
  138. ->keyBy('floor');
  139. $data = $data? $data->toArray() : [];
  140. if($data){
  141. RedisService::set($cacheKey, $data, 300, 600);
  142. }
  143. return $data;
  144. }
  145. /**
  146. * 修改
  147. * @return array
  148. */
  149. public function edit()
  150. {
  151. ActionLogModel::setTitle("修改设置制度参数");
  152. ActionLogModel::record();
  153. return parent::edit(); // TODO: Change the autogenerated stub
  154. }
  155. }