table('pc_activity_registration')->where($parameter)->count(); $result = $zzt_db->table('pc_activity_registration')->where($parameter)->order('id desc')->page($page,$this->page_num)->field('id,title,people_num,people_num_now,pic,is_del,start_time,end_time,create_time')->select(); if(!$pd){ $result['num'] = $num; $result['data'] = $result; return $this->msg($result); } $this->assign([ 'result' => $result, 'num' => $num, ]); return $this->fetch(); } public function del_action() { $data = input('post.'); $zzt_db = Db::connect('zzt_db'); $result = $zzt_db->table('pc_activity_registration')->where(['id'=>$data['id']])->update(['is_del'=>$data['is_del']]); if($result){ return $this->msg([]); }else{ return $this->msg(10002); } } // 智照团添加表单 public function add_form2() { return $this->fetch(); } // 智照团添加表单 public function add_form_action() { $data = input('post.'); // dump($data); // die; $zzt_db = Db::connect('zzt_db'); $result = $zzt_db->table('pc_activity_registration')->insert([ 'title'=>$data['title'], 'people_num'=>$data['people_num'], 'start_time'=>$data['s_time'], 'end_time'=>$data['e_time'], 'text_content'=>$data['content'], 'form_content'=>json_encode($data['form_data']), 'pic'=>$data['cover_image'], 'is_only_once'=>$data['is_only_once'], 'create_time'=>date('Y-m-d H:i:s') ]); if($result){ return $this->msg([]); }else{ return $this->msg(10002); } } // 智照团修改表单 public function edit_form() { $data = input(); $zzt_db = Db::connect('zzt_db'); $result = $zzt_db->table('pc_activity_registration')->where(['id'=>$data['id']])->field('id,title,people_num,start_time,end_time,text_content,form_content,pic,is_only_once')->find(); $pic = $zzt_db->table('pc_pic_manage')->where(['id'=>$result['pic']])->field('id,url_data')->find(); $result['pic_url'] = $pic['url_data']; // dump($result); // die; $this->assign([ 'result' => $result, ]); return $this->fetch(); } // 智照团修改表单 public function edit_form_action() { $data = input('post.'); // dump($data); // die; $zzt_db = Db::connect('zzt_db'); $people_num = $zzt_db->table('pc_activity_registration_log')->where(['par_id'=>$data['id']])->count(); if($people_num>0){ $yz_data = $zzt_db->table('pc_activity_registration')->where(['id'=>$data['id']])->field('id,form_content,people_num')->find(); if($yz_data['form_content'] != json_encode($data['form_data'])){ return $this->msg(10002,'已有人报名,不可修改表单项目'); } if($yz_data['people_num'] > $data['people_num']){ return $this->msg(10002,'已有人报名,请不要缩减报名人数'); } } $result = $zzt_db->table('pc_activity_registration') ->where(['id'=>$data['id']]) ->update([ 'title'=>$data['title'], 'people_num'=>$data['people_num'], 'start_time'=>$data['s_time'], 'end_time'=>$data['e_time'], 'text_content'=>$data['content'], 'form_content'=>json_encode($data['form_data']), 'pic'=>$data['cover_image'], 'is_only_once'=>$data['is_only_once'], ]); if($result){ return $this->msg([]); }else{ return $this->msg(10002); } } // 下载报名人员 public function down_data_action(){ $data = input(); $zzt_db = Db::connect('zzt_db'); $down_data = $zzt_db->table('pc_activity_registration_log')->where(['par_id'=>$data['id']])->select(); $activity_registration_data = $zzt_db->table('pc_activity_registration')->where(['id'=>$data['id']])->field('id,title,form_content')->find(); if($activity_registration_data){ $activity_registration_data['form_content'] = json_decode($activity_registration_data['form_content'],true); }else{ return $this->msg(10002,'未找到对应活动'); } $config = $activity_registration_data; // 构建表头 $header = ['序号', '会员电话']; // 添加表单字段名称到表头 foreach ($config['form_content'] as $field) { $header[] = $field['name']; } if(count($down_data) > 0){ foreach ($down_data as $key => $value) { $down_data[$key]['content'] = json_decode($value['content'],true); } $userData = $down_data; // 初始化结果数组 $result = []; $result[] = $header; // 处理每条用户数据 foreach ($userData as $index => $user) { $row = []; // 序号(使用数组索引+1,或者用用户数据中的id) $row[] = $index + 1; // 会员电话处理:如果不是手机号格式,显示"非会员用户" $tel = $user['tel']; if (!preg_match('/^1[3-9]\d{9}$/', $tel)) { $row[] = "非会员用户"; } else { $row[] = $tel; } // 处理每个表单字段的值 foreach ($config['form_content'] as $configField) { $fieldName = $configField['name']; $fieldType = $configField['type']; $fieldValue = ''; // 在用户数据中查找对应的字段值 foreach ($user['content'] as $userField) { if ($userField['name'] === $fieldName) { $fieldValue = $userField['value']; // 如果是checkbox类型,替换"CH1"为逗号 if ($fieldType === 'checkbox') { $fieldValue = str_replace('CH1', ',', $fieldValue); } break; } } $row[] = $fieldValue; } $result[] = $row; } }else{ // 初始化结果数组 $result = []; $result[] = $header; } $excel = new \app\download\controller\Excel(); $excel->export($result, $activity_registration_data['title']); } }