page($param['page'] , $param['limit'])->order('addtime desc')->select()->toArray(); $column = array_column($list , 'id'); $tid = SpellgroupTeam::where('spellgroup_id','in',$column)->group('spellgroup_id')->column('count(spellgroup_id)','spellgroup_id'); $uid = SpellgroupJoin::where('spellgroup_id','in',$column)->group('spellgroup_id')->column('count(spellgroup_id)','spellgroup_id'); foreach($list as &$item){ $item['end'] = $item['start_date'] <= date('Y-m-d') ? 1 : 0; $item['team_num'] = isset($tid[$item['id']]) ? $tid[$item['id']] : 0; $item['join_user_num'] = isset($uid[$item['id']]) ? $uid[$item['id']] : 0; } $count = ModelSpellgroup::where($where)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']); } //团队列表 public function team_list() { $request = request(); $param = Request::only(['page', 'limit', 'keyword','team_num','status']); $where[] = ['root_id', '=', $request->employee->root_id]; if (!empty($param['status'])) { $where[] = ['status', '=', $param['status']]; } if (!empty($param['keyword'])) { $eids = Employee::where([['root_id','=',$request->employee->root_id],['state','=','在职'],['uid','>',0],['name','like','%'.trim($param['keyword']).'%']])->column('id'); $where[] = ['employee_id','in',$eids]; } if (!empty($param['team_num'])) { $where[] = ['number', '=', $param['team_num']]; } $list= SpellgroupTeam::with(['user'=>function($query){ $query->field('id,nickname,phone'); },'employee'=>function($query){ $query->field('id,name'); }]) ->where($where) ->page($param['page'] , $param['limit']) ->order('open_time desc') ->select() ->toArray(); foreach($list as $key=>$val){ $list[$key]['end_time']=date('Y-m-d H:i:s',$val['end_time']); } $count = SpellgroupTeam::where($where)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']); } //查看团队成员 public function sel_team_detail() { $request = request(); $param = Request::only(['id']); $team_data=SpellgroupTeam::where('id',$param['id'])->find(); $join_list=SpellgroupJoin::with(['user']) ->where('team_id',$param['id']) ->field('join_uid,addtime,is_heads') ->order('is_heads desc addtime asc') ->select() ->ToArray(); View::assign('list', $join_list); View::assign('team_data', $team_data); return View::fetch(); //return json(['code' => 0, 'data' => $team_data, 'msg' => '获取成功']); } /** * 添加视图 */ public function add() { $request = request(); $group_data=ModelSpellgroup::where('root_id',$request->employee->root_id)->find(); View::assign('data', $group_data); return View::fetch(); } //设置拼团 public function set() { $request = request(); $group_data=ModelSpellgroup::where([['root_id','=',$request->employee->root_id]])->findOrEmpty(); $group_data->team_ok_type=!empty($group_data->team_ok_type)?$group_data->team_ok_type:'队员交定后'; View::assign('data', $group_data); return View::fetch(); } /** * 添加活动 */ public function addSave() { $request = request(); $data = Request::only(['id', 'content', 'hour', 'cover', 'number','heads_reward_type','heads_reward_cont1','heads_reward_cont2','team_member_cont','team_ok_type']); //var_dump($data); //exit; if($data['heads_reward_type']==1){ $data['heads_reward_cont']=$data['heads_reward_cont1']; } if($data['heads_reward_type']==2){ $data['heads_reward_cont']=$data['heads_reward_cont2']; } $group_data=ModelSpellgroup::where('root_id',$request->employee->root_id)->find(); if(empty($group_data)){ $data['root_id']=$request->employee->root_id; (new ModelSpellgroup())->save($data); return json(['code' => 0, 'msg' => '添加成功']); }else{ $ms=$group_data->save($data); if($ms){ return json(['code' => 0, 'msg' => '修改成功']); }else{ return json(['code' => 1, 'msg' => '修改失败']); } } } /** * 修改视图 */ public function edit($id) { $edit = (new ModelSpellgroup())->find($id); View::assign('data', $edit); return View::fetch(); } /** * 修改保存活动 */ public function editSave() { $data = Request::only(['id', 'title', 'content', 'hour', 'cover', 'number']); $obj = (new ModelSpellgroup())->find($data['id']); if (empty($obj)) return json(['code' => 1, 'msg' => '数据不存在']); if ($obj['start_date'] <= date('Y-m-d')) return json(['code' => 1, 'msg' => '活动已开始,不支持编辑']); //更新队伍记录的拼团人数 if($obj['number'] != $data['number']) SpellgroupTeam::where('spellgroup_id',$data['id'])->update(['number'=>$data['number']]); $obj->save($data); return json(['code' => 0, 'msg' => '修改成功']); } /** * 活动领取列表 */ public function receive($id , $tid = 0) { if (!Request::isAjax()) { View::assign('id',$id); View::assign('tid',$tid); return View::fetch(); } $param = Request::only(['id','page', 'limit', 'keyword' , 'tid']); $where[] = ['spellgroup_id','=',$id]; if(!empty($param['keyword'])) { $where[] = ['phone', 'like', '%' . $param['keyword'] . '%']; } if(!empty($param['tid'])) { $where[] = ['team_id', '=', $param['tid']]; } $data = SpellgroupJoin::with(['user'])->where($where)->page($param['page'] , $param['limit'])->field('id,join_uid,phone,status')->order('addtime desc')->select(); $count = SpellgroupJoin::where($where)->count(); return json(['code' => 0 , 'data'=>$data , 'count'=>$count , 'msg' => '获取成功']); } /* * 团队列表 */ public function team($id,$hour) { if (!Request::isAjax()) { View::assign('id',$id); View::assign('hour',$hour); return View::fetch(); } $param = Request::only(['id','hour', 'page', 'limit']); $data = SpellgroupTeam::where('spellgroup_id',$param['id'])->page($param['page'] , $param['limit'])->order('open_time desc')->select()->toArray(); $tid = array_column($data,'id'); $user = SpellgroupJoin::with(['user'])->where('team_id','in',$tid)->field('join_uid,team_id')->select()->toArray(); foreach($data as &$item) { $item['end'] = date('Y-m-d h:i:s', strtotime($item['open_time'])+($param['hour']*3600)); $item['headimgurl'] = []; foreach($user as $v) { if($item['id'] == $v['team_id']) $item['headimgurl'][] = $v['headimgurl']; } } $count = SpellgroupTeam::where('spellgroup_id',$param['id'])->count(); return json(['code' => 0 , 'data'=>$data , 'count'=>$count , 'msg' => '获取成功']); } /* * 富文本图片 */ public function imgUpload() { $bindUrl = config('app.ali_oss_bindurl'); $data = [ 'src' => 'http://' . $bindUrl . '/' . Request::param('file'), 'title' => '' ]; return json(['code' => 0, 'msg' => '', 'data' => $data]); } }