sponsor_list = ActivitySponsor::getSponsorName(); $this->title = '列表'; $where = []; $where[] = ['f.is_deleted','=',0]; if($title = input('title')) $where[] = ['f.title','like','%'.$title.'%']; if($sponsor_id = input('sponsor_id')) $where[] = ['f.sponsor_id','=',$sponsor_id]; $query = $this->_query($this->table)->alias('f') ->field('f.*') ->where($where) ->order('sort desc,f.id desc')->page(); } /** * 添加 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function add() { $this->title = '添加'; $this->_form($this->table, 'form'); } /** * 编辑 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function edit() { $this->title = '编辑'; $this->_form($this->table, 'form'); } /** * 删除 * @auth true * @throws \think\Exception * @throws \think\exception\PDOException */ public function del() { \app\common\model\Activity::where('id',input('id'))->update(['is_deleted'=>1]); \app\common\model\Activity::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'activity'); $this->success('删除成功'); } /** * 批量删除 * @auth true * @throws \think\Exception * @throws \think\exception\PDOException */ public function remove() { $ids = input('id'); foreach (explode(',',$ids) as $id) { \app\common\model\Activity::where('id',$id)->update(['is_deleted'=>1]); \app\common\model\Activity::esAdd($id); \app\common\model\TopSearch::saveData($id,'activity'); } $this->success('删除成功'); } /** * 表单数据处理 * @param array $data */ protected function _form_filter(&$data) { $all_area = ChinaArea::where('level','<=',3)->select(); $this->all_area = make_tree($all_area); // 文章列表 $this->article_list =\app\common\model\ArticleIntro::with('itemChildren') ->field('id,title') ->where(['is_deleted'=>0])->order('id asc') ->select()->toArray(); // 视频 $this->video_list = \app\common\model\VideoIntro::with('videoArr') ->where(['is_deleted'=>0])->order('id desc') ->select()->toArray(); // 资料 $this->datum_list = DatumIntro::with('urlArr') ->where(['is_deleted'=>0])->order('id desc') ->select()->toArray(); $this->sponsor_list = ActivitySponsor::getList(); $this->template_list = ActivityTemplate::getList(); if ($this->request->isGet() && $this->request->action() == 'add') { $this->isAddMode = 1; $this->ladder = []; } if ($this->request->isGet() && $this->request->action() == 'edit') { $this->isAddMode = 0; $this->ladder = ActivityPrice::gePriceList($data['id']); } if($this->request->isPost()) { list($post) = [$this->request->post()]; if(!empty($post['phone'])) { $user_id = User::where('phone|email',$post['phone'])->value('id'); if(!$user_id) $this->error('账号未注册'); $data['user_id'] = $user_id; }else{ $data['user_id'] = ''; } if(!$post['release_time']) $data['release_time'] = date("Y-m-d H:i:s"); if($data['hot_nm'] != $data['hot_num_old']) $data['hot_time'] = date("Y-m-d H:i:s"); //郵箱 和短信 if($this->request->action()== 'edit' && isset($data['push_switch']) && $data['push_switch'] == 1) { //\app\common\model\Activity::activityChange($data['id'],$data['title'],['end_time'=>$data['end_time'],'start_time'=>$data['start_time'],'address'=>$data['address']]); $before_act = \app\common\model\Activity::where('id',$data['id'])->find()->toArray(); // 活动时间变更 if(($before_act['start_time'] != $data['start_time'] || $before_act['end_time'] != $data['end_time']) && $before_act['address'] == $data['address'] ) { \app\common\model\Activity::activityChange($data['id'],$data['title'],['end_time'=>$data['end_time'],'start_time'=>$data['start_time'],'address'=>$data['address']]); //变更通知 // $all_list = ActivityApplyItem::where(['act_id'=>$data['id'],'sh_status'=>1,'is_hx'=>0])->group('phone')->select(); // // foreach ($all_list as $k => $v){ // UserMessage::sendUserMessage($v['user_id'],'activity',2,1,0,$v['act_id'],'活动时间变更',$v['act_id']); // } } // 活动地址变更 else if($before_act['start_time'] == $data['start_time'] && $before_act['end_time'] == $data['end_time'] && $before_act['address'] != $data['address']){ \app\common\model\Activity::activityChange($data['id'],$data['title'],['end_time'=>$data['end_time'],'start_time'=>$data['start_time'],'address'=>$data['address']]); //变更通知 // $all_list = ActivityApplyItem::where(['act_id'=>$data['id'],'sh_status'=>1,'is_hx'=>0])->group('phone')->select(); // foreach ($all_list as $k => $v){ // UserMessage::sendUserMessage($v['user_id'],'activity',2,1,0,$v['act_id'],'活动地址变更',$v['act_id']); // } } // 活动地址与时间变更 else if($before_act['start_time'] != $data['start_time'] || $before_act['end_time'] != $data['end_time'] || $before_act['address'] != $data['address'] ) { \app\common\model\Activity::activityChange($data['id'],$data['title'],['end_time'=>$data['end_time'],'start_time'=>$data['start_time'],'address'=>$data['address']]); //变更通知 // $all_list = ActivityApplyItem::where(['act_id'=>$data['id'],'sh_status'=>1,'is_hx'=>0])->group('phone')->select(); // foreach ($all_list as $k => $v){ // UserMessage::sendUserMessage($v['user_id'],'activity',2,1,0,$v['act_id'],'活动时间地址变更',$v['act_id']); // } } } if($this->request->action()== 'add'){ $data['status'] = 0; } //定时热搜 if(!$post['hot_nm']){ $post['hot_nm'] = 0; } if(isset($post['id'])){ $info = \app\common\model\Activity::where('id',$data['id'])->find(); if(($post['regular_hot_end_time'] && $post['hot_target_num'] && $info['regular_hot_end_time'] != $post['regular_hot_end_time']) || ($info['hot_nm'] != $post['hot_nm'] && $post['regular_hot_end_time'] && $post['hot_target_num'])){ $data['regular_hot_start_time'] = date("Y-m-d H:i:s"); $startdate = strtotime($data['regular_hot_start_time']); $enddate = strtotime($post['regular_hot_end_time']); $diff_seconds = ($enddate-$startdate)/60; $min_num = ceil($diff_seconds/10); $hot_num = $post['hot_target_num'] - $post['hot_nm']; $num = ceil($hot_num/$min_num); if($num < 0){ $num = 0; } $data['regular_num'] = $num; } }else{ if($post['regular_hot_end_time'] && $post['hot_target_num']){ $data['regular_hot_start_time'] = date("Y-m-d H:i:s"); $startdate = strtotime($data['regular_hot_start_time']); $enddate = strtotime($post['regular_hot_end_time']); $diff_seconds = ($enddate-$startdate)/60; $min_num = ceil($diff_seconds/10); $hot_num = $post['hot_target_num'] - $post['hot_nm']; $num = ceil($hot_num/$min_num); if($num < 0){ $num = 0; } $data['regular_num'] = $num; } } if(!$post['regular_hot_end_time']){ unset($data['regular_hot_end_time']); } //定时热搜end }else{ if (!empty($data)){ $data['covers'] = $data['cover']; } } } /** * 报名记录 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function apply() { $id = $this->request->get('act_id'); $name = $this->request->get('name'); $phone = $this->request->get('phone'); $this->title = '报名记录'; $where = []; $where[]= ['a.act_id','=' ,$id]; $where[]= ['a.is_deleted','=' ,0]; // $where[]= ['a.status','=' ,1]; if($name) $where[]= ['a.name','like' ,'%'.$name.'%']; if($phone) $where[]= ['a.phone','like' ,'%'.$phone.'%']; $query = $this->_query('activity_apply') ->alias('a') ->field('a.*,u.name user_name,u.headimg,u.phone') ->where($where) ->leftJoin('store_member u','u.id = a.user_id') ->order('a.id desc')->page(); $this->fetch(); } /** * 上架 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function up() { \app\common\model\Activity::where('id',input('id'))->update(['status'=>1]); \app\common\model\Activity::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'activity'); $this->success('已上架!'); } /** * 下架 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function down() { \app\common\model\Activity::where('id',input('id'))->update(['status'=>0]); \app\common\model\Activity::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'activity'); $this->success('已下架!'); } /** * 取消 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function cancel() { \app\common\model\Activity::where('id',input('id'))->update(['status'=>2]); \app\common\model\Activity::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'activity'); \app\common\model\Activity::activityCancel(input('id')); $this->success('已取消!'); } public function export(){ $id = $this->request->get('act_id'); $name = $this->request->get('name'); $phone = $this->request->get('phone'); $this->title = '报名记录'; $where = []; $where[]= ['a.act_id','=' ,$id]; $where[]= ['a.is_deleted','=' ,0]; $where[]= ['a.status','=' ,1]; $where[]= ['a.status','=' ,1]; if($name) $where[]= ['a.name','like' ,'%'.$name.'%']; if($phone) $where[]= ['a.phone','like' ,'%'.$phone.'%']; $data =Db::name('activity_apply') ->alias('a') ->field('a.*,u.name user_name,u.headimg') ->where($where) ->leftJoin('store_member u','u.id = a.user_id') ->order('a.id desc')->select(); if(empty($data)) $this->error('暂无可以导出的数据'); foreach ($data as $k=>&$v) { } $field=array( 'A' => array('order_no', '订单号'), 'B' => array('name', '联系人'), 'C' => array('phone', '电话'), 'D' => array('money','订单金额'), 'E' => array('num','人数'), 'F' => array('email','邮箱'), 'G' => array('create_at', '时间'), ); $this->phpExcelList($field,$data,'报名列表'); } public function phpExcelList($field=[],$list=[],$title='文件'){ $PHPExcel=new \PHPExcel(); $PHPSheet=$PHPExcel->getActiveSheet(); $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称 foreach($list as $key=>$value) { foreach($field as $k=>$v){ if($key == 0){ $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]); } $i=$key+2; $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]); } } $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件, header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格 header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称 header('Cache-Control: max-age=0'); //禁止缓存 $PHPWriter->save("php://output"); //输出到浏览器 } protected function _form_result(&$id) { list($post,$ladder_data) = [$this->request->post(),[]]; foreach (array_keys($post['ladder_title']) as $key) { $ladder_price = sprintf('%.2f',$post['ladder_price'][$key]); $sub_money = sprintf('%.2f',$post['sub_money'][$key]); if(!isset($post['stock'][$key])){ $post['stock'][$key] = intval($post['ladder_num'][$key]); } if($sub_money > $ladder_price) $sub_money = $ladder_price; array_push($ladder_data, [ 'act_id' => $id, 'ladder_id' => $post['ladder_id'][$key], 'ladder_title' => $post['ladder_title'][$key], 'is_sh' => intval($post['is_sh'][$key]), 'ladder_num' => intval($post['ladder_num'][$key]), 'stock' => intval($post['stock'][$key]), 'fill_num' => intval($post['fill_num'][$key]), 'ladder_status' => intval($post['ladder_status'][$key]), 'ladder_price' => $ladder_price, 'sub_money' => $sub_money, 'ladder_remark' => $post['ladder_remark'][$key], ]); } ActivityPrice::priceSet($id,$ladder_data); \app\common\model\Activity::esAdd($id); \app\common\model\TopSearch::saveData($id,'activity'); // 站內信和極光 if(isset($post['push_switch']) && $post['push_switch'] == 1) \app\common\service\Activity::activityChange($id); $this->success('操作成功', 'javascript:history.back()'); } }