123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace App\Http\Controllers\Member;
- use App\Http\Controllers\AdminBaseController;
- use App\Http\Requests\MemberCreateRequest;
- use App\Http\Requests\MemberUpdateRequest;
- use App\Models\Level;
- use App\Models\Member;
- use App\Repositories\Eloquent\MemberRepositoryEloquent;
- use App\Servers\MemberServer;
- use App\Validators\MemberValidator;
- /**
- * Class MembersController.
- *
- * @package namespace App\Http\Controllers;
- */
- class MembersController extends AdminBaseController
- {
- /**
- * @var MemberRepositoryEloquent
- */
- protected $repository;
- /**
- * @var MemberValidator
- */
- protected $validator;
- /**
- * MembersController constructor.
- *
- * @param MemberRepositoryEloquent $repository
- * @param MemberValidator $validator
- */
- public function __construct(MemberRepositoryEloquent $repository, MemberValidator $validator)
- {
- parent::__construct($repository, $validator);
- }
- /**
- * 数据检索
- */
- public function _indexScopeQuery()
- {
- $where = [];
- $search = explode(";", request()->input('search', ""));
- $start = $end = null;
- $fieldSearchable = $this->repository->getFieldsSearchable();
- foreach ($search as $value) {
- if (!empty($value)) {
- list($one, $tow) = explode(":", $value);
- if (!empty($fieldSearchable[$one])) {
- if ($fieldSearchable[$one] == 'like') $tow = "%{$tow}%";
- $where[] = [$one, $fieldSearchable[$one], $tow];
- } elseif ($one == 'start') {
- $start = $tow . " 00:00:00";
- } elseif ($one == 'end') {
- $end = $tow . " 23:59:59";
- } else {
- continue;
- }
- }
- }
- return function ($query) use ($where, $start, $end) {
- if ($start) $where[] = ['created_at', '>=', $start];
- if ($end) $where[] = ['created_at', '<=', $end];
- if ($where) {
- $query->where($where);
- }
- };
- }
- /**
- * 数据更新
- */
- protected function _indexPost($data)
- {
- foreach ($data as $value){
- $value->{'level_name'}=Level::where('id',$value->{'level_id'})->value('name')?:'L0';
- }
- return $data;
- }
- /**
- * 修改数据组建
- * @param $id
- * @return array
- */
- function _editGet($id)
- {
- $model = $this->repository->find($id);
- $level_list = $this->getLevelList($model->{'level_id'});
- return ['model' => $model, 'levelList' => json_encode($level_list, JSON_UNESCAPED_SLASHES)];
- }
- function _updatePost($request, $id)
- {
- $level_id = request()->input('level_id', '0');
- return Member::where('id', $id)->update(['level_id' => $level_id,'is_auto' => 0]);
- }
- /**
- * 获取层级菜单组件
- * @return array
- */
- private function getLevelList($level = '0')
- {
- $option = [
- 'checked' => $level . '',
- 'attr' => [
- [
- 'value' => '0',
- 'label' => "L0",
- 'disabled' => false,
- 'notice' => '*'
- ],
- ]
- ];
- $levels=Level::select(['id','name'])->get();
- foreach ($levels as $level){
- $option['attr'][]=[
- 'value' => $level->{'id'}.'',
- 'label' => $level->{'name'},
- 'disabled' => false,
- 'notice' => '*'
- ];
- }
- return $option;
- }
- function selectAll()
- {
- return view('admins.members.all');
- }
- function getUserIds(){
- $user_ids=Member::where('is_del',0)->pluck('id')->toArray();
- return $this->success('获取数据成功','',$user_ids);
- }
- }
|