root_id], ['employee_id', '>', 0]])->group('employee_id')->column('employee_id'); $where = [ ['id', 'in', $eid], ['grant_id', '>', 0], ['root_id', '=', $this->root_id] ]; // 运营人员列表 $employee = Employee::where($where)->field(['id', 'opt_name as name'])->select()->toArray(); View::assign('employee', $employee); return View::fetch(); } $param = Request::only(['page', 'limit', 'keyword', 'date', 'employee_id']); $where = [ ['del', '=', 0], ['root_id', '=', $this->root_id] ]; if (!empty($param['date'])) { $dates = explode(' - ', $param['date']); $where[] = ['start_date', '<=', "$dates[0]"]; $where[] = ['end_date', '>=', "$dates[1]"]; } if (!empty($param['keyword'])) { $where[] = ['title', 'like', '%' . $param['keyword'] . '%']; } if (!empty($param['employee_id'])) { $where[] = ['employee_id', '=', $param['employee_id']]; } $list = ModelActivity::with(['employee'])->where($where)->page($param['page'], $param['limit'])->field('*,end_date timestate')->order('addtime desc')->select()->toArray(); $aids = []; foreach ($list as &$val) { $val['arr_qrcode_employee_id'] = []; if (!empty($val['qrcode_employee_id'])) { $allid = explode(',', $val['qrcode_employee_id']); $val['arr_qrcode_employee_id'] = $allid; foreach ($allid as $k => $v) { $aids[] = $v; } } } $qrcode = Employee::where([['id', 'in', array_unique($aids)]])->column('name', 'id'); //$qrcode = Employee::where([['id', 'in', array_column($list, 'qrcode_employee_id')]])->column('name', 'id'); foreach ($list as $k => $v) { $qrcode_name = ''; foreach ($qrcode as $r => $e) { if (in_array($r, $v['arr_qrcode_employee_id'])) { $qrcode_name .= $e . ','; } } $list[$k]['qrcode_name'] = isset($qrcode_name) ? trim($qrcode_name, ',') : ''; } $count = ModelActivity::where($where)->count(); //邀约客户 if ($list) { $aids = array_column($list, 'id'); $v_where[] = ['state', 'in', CustomerVisitLog::changeState('预约活动', 'chaos')]; $v_where[] = ['aid', 'in', $aids]; $footprints = CustomerVisitLog::withJoin('customer')->where([ ['customer_visit_log.state', 'in', CustomerVisitLog::changeState('预约活动', 'chaos')], ['customer_visit_log.aid', 'in', $aids] ])->group('customer_visit_log.aid,customer_visit_log.customer_id')->column('customer_visit_log.aid as aid,customer_visit_log.customer_id as customer_id'); $arr = []; foreach ($footprints as $k => $v) { $arr[$v['aid']] = isset($arr[$v['aid']]) ? $arr[$v['aid']] += 1 : 1; } $group = ActivityCollor::where([['aid','in',array_column($list,'id')],['type','=',1]])->group('aid')->column('count(*)','aid'); $collor = ActivityCollor::where([['aid','in',array_column($list,'id')],['type','=',0]])->group('aid')->column('count(*)','aid'); $material = ActivityMaterial::where([['aid','in',array_column($list,'id')]])->group('aid')->column('count(*)','aid'); foreach ($list as $k => $v) { $list[$k]['user_count'] = isset($arr[$v['id']]) ? $arr[$v['id']] : 0; $list[$k]['start_date'] = str_replace('-','/',$v['start_date']); $list[$k]['end_date'] = str_replace('-','/',$v['end_date']); $list[$k]['activity_sign_count'] = isset($group[$v['id']]) ? $group[$v['id']] : 0; $list[$k]['collect_count'] = isset($collor[$v['id']]) ? $collor[$v['id']] : 0; $list[$k]['material_count'] = isset($material[$v['id']]) ? $material[$v['id']] : 0; } } return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']); } /** * 添加视图 */ public function add() { if (request()->isAjax()) return $this->addActivity(); $root_id = $this->root_id; //扫码人员 $employee = Employee::where([['uid', '>', 0], ['state', '=', '在职'], ['root_id', '=', $root_id]])->column('id,name'); View::assign('employee', $employee); return View::fetch(); } /** * 添加活动 */ public function addActivity() { $data = Request::only(['title', 'content', 'type', 'cover', 'money', 'start_date', 'end_date', 'wxmch', 'cate', 'poster', 'address','qrcode','introduce']); $data['root_id'] = $this->root_id; $data['employee_id'] = $this->employee_id; if ($data['start_date'] > $data['end_date']) return json(['code' => 1, 'msg' => '开始日期需在结束日期之前']); ModelActivity::insert($data); return json(['code' => 0, 'msg' => '添加成功']); } /** * 编辑 */ public function editActivity() { $data = Request::only(['title', 'content', 'type', 'cover', 'money', 'start_date', 'end_date', 'wxmch', 'cate', 'poster', 'address','qrcode','introduce']); $id = input('id',0); $info = ModelActivity::where([['id','=',$id]])->findOrEmpty(); if($info->isEmpty()) return json(['code' => 1, 'msg' => '编辑失败','data'=>'编辑失败']); foreach ($data as $key => $value) { $info->$key = $value; } $info->save(); return json(['code' => 0, 'msg' => '添加成功']); } /** * 修改视图 */ public function edit($id) { $edit = (new ModelActivity())->where([ 'id' => $id, 'root_id' => $this->root_id ])->find(); $edit->coverc = $edit->getData('cover'); $edit->posterc = $edit->getData('poster'); View::assign('data', $edit); $root_id = $this->root_id; //扫码人员 $employee = Employee::where([['uid', '>', 0], ['state', '=', '在职'], ['root_id', '=', $root_id]])->column('id,name'); View::assign('employee', $employee); return View::fetch(); } /* * 富文本图片 */ public function imgUpload() { $bindUrl = config('app.ali_oss_bindurl'); $data = [ 'src' => 'http://' . $bindUrl . '/' . Request::param('file'), 'title' => '' ]; return json(['code' => 0, 'msg' => '', 'data' => $data]); } /* * 上传素材 */ public function upload_material($id) { View::assign('id', $id); return View::fetch(); } /* * 上传素材 */ public function source_material($id) { View::assign('id', $id); return View::fetch(); } /* * 素材列表 */ public function materialList($id) { $data = Request::only(['page'=>0,'limit'=>10]); $list = ActivityMaterial::where([['aid','=',$id],['root_id','=',0]])->order('id desc')->page((int)$data['page'],(int)$data['limit'])->select()->toArray(); $count = ActivityMaterial::where([['aid','=',$id],['root_id','=',0]])->count(); return json(['code' => 0, 'msg' => '', 'data' => $list,'count'=>$count]); } /* * 删除素材 */ public function materialDel($id) { ActivityMaterial::where([['id','=',$id],['root_id','=',0]])->delete(); return json(['code' => 0, 'msg' => '删除成功', 'data' =>'删除成功']); } /* * 上传素材 * type=0图 1视频 */ public function materialAdd($id) { $data = Request::only(['type'=>0,'urls'=>'']); $save = []; $arr = $data['urls'] ? explode(',',$data['urls']) : []; foreach ($arr as $value) { $save[] = [ 'aid'=>$id, 'type'=>$data['type'], 'url'=>$value, 'root_id'=>0 ]; } ActivityMaterial::insertAll($save); return json(['code' => 0, 'msg' => '保存成功', 'data' =>'保存成功']); } }