MembersController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace App\Http\Controllers\Member;
  3. use App\Http\Controllers\AdminBaseController;
  4. use App\Http\Requests\MemberCreateRequest;
  5. use App\Http\Requests\MemberUpdateRequest;
  6. use App\Models\Level;
  7. use App\Models\Member;
  8. use App\Repositories\Eloquent\MemberRepositoryEloquent;
  9. use App\Servers\MemberServer;
  10. use App\Validators\MemberValidator;
  11. /**
  12. * Class MembersController.
  13. *
  14. * @package namespace App\Http\Controllers;
  15. */
  16. class MembersController extends AdminBaseController
  17. {
  18. /**
  19. * @var MemberRepositoryEloquent
  20. */
  21. protected $repository;
  22. /**
  23. * @var MemberValidator
  24. */
  25. protected $validator;
  26. /**
  27. * MembersController constructor.
  28. *
  29. * @param MemberRepositoryEloquent $repository
  30. * @param MemberValidator $validator
  31. */
  32. public function __construct(MemberRepositoryEloquent $repository, MemberValidator $validator)
  33. {
  34. parent::__construct($repository, $validator);
  35. }
  36. /**
  37. * 数据检索
  38. */
  39. public function _indexScopeQuery()
  40. {
  41. $where = [];
  42. $search = explode(";", request()->input('search', ""));
  43. $start = $end = null;
  44. $fieldSearchable = $this->repository->getFieldsSearchable();
  45. foreach ($search as $value) {
  46. if (!empty($value)) {
  47. list($one, $tow) = explode(":", $value);
  48. if (!empty($fieldSearchable[$one])) {
  49. if ($fieldSearchable[$one] == 'like') $tow = "%{$tow}%";
  50. $where[] = [$one, $fieldSearchable[$one], $tow];
  51. } elseif ($one == 'start') {
  52. $start = $tow . " 00:00:00";
  53. } elseif ($one == 'end') {
  54. $end = $tow . " 23:59:59";
  55. } else {
  56. continue;
  57. }
  58. }
  59. }
  60. return function ($query) use ($where, $start, $end) {
  61. if ($start) $where[] = ['created_at', '>=', $start];
  62. if ($end) $where[] = ['created_at', '<=', $end];
  63. if ($where) {
  64. $query->where($where);
  65. }
  66. };
  67. }
  68. /**
  69. * 数据更新
  70. */
  71. protected function _indexPost($data)
  72. {
  73. foreach ($data as $value){
  74. $value->{'level_name'}=Level::where('id',$value->{'level_id'})->value('name')?:'L0';
  75. }
  76. return $data;
  77. }
  78. /**
  79. * 修改数据组建
  80. * @param $id
  81. * @return array
  82. */
  83. function _editGet($id)
  84. {
  85. $model = $this->repository->find($id);
  86. $level_list = $this->getLevelList($model->{'level_id'});
  87. return ['model' => $model, 'levelList' => json_encode($level_list, JSON_UNESCAPED_SLASHES)];
  88. }
  89. function _updatePost($request, $id)
  90. {
  91. $level_id = request()->input('level_id', '0');
  92. return Member::where('id', $id)->update(['level_id' => $level_id,'is_auto' => 0]);
  93. }
  94. /**
  95. * 获取层级菜单组件
  96. * @return array
  97. */
  98. private function getLevelList($level = '0')
  99. {
  100. $option = [
  101. 'checked' => $level . '',
  102. 'attr' => [
  103. [
  104. 'value' => '0',
  105. 'label' => "L0",
  106. 'disabled' => false,
  107. 'notice' => '*'
  108. ],
  109. ]
  110. ];
  111. $levels=Level::select(['id','name'])->get();
  112. foreach ($levels as $level){
  113. $option['attr'][]=[
  114. 'value' => $level->{'id'}.'',
  115. 'label' => $level->{'name'},
  116. 'disabled' => false,
  117. 'notice' => '*'
  118. ];
  119. }
  120. return $option;
  121. }
  122. function selectAll()
  123. {
  124. return view('admins.members.all');
  125. }
  126. function getUserIds(){
  127. $user_ids=Member::where('is_del',0)->pluck('id')->toArray();
  128. return $this->success('获取数据成功','',$user_ids);
  129. }
  130. }