where( array('id' => $id) )->find();
return $forms_data;
}
/**
* @author cy 2021-05-25
* @desc 通过条件获取表单信息
* @param $condition
* @return mixed
*/
public function getFormsByWhere($condition){
$forms_data = M('lionfish_comshop_forms')->where($condition)->find();
return $forms_data;
}
/**
* @author cy 2021-04-30
* @desc 表单类型名称
* @param $form_type
* @return string
*/
public function getFormTypeName($form_type){
$form_type_text = "";
switch ($form_type){
case 'goods':
$form_type_text = '商品表单';
break;
case 'order':
$form_type_text = '下单表单';
break;
case 'apply':
$form_type_text = '申请表单';
break;
}
return $form_type_text;
}
/**
* @author cy 2021-05-19
* @desc 获取已收集的表单数
* @param $form_id
* @return mixed
*/
public function getFormInfoCountByFormId($form_id){
$count = M('lionfish_comshop_form_info')->where( array('form_id' => $form_id) )->count();
return $count;
}
/**
* @author cy 2021-05-25
* @desc 删除表单信息
* @param $form_id
* @return mixed
*/
public function deleteForm($form_id){
$result = [];
$res = M('lionfish_comshop_forms')->where( array('id' => $form_id) )->delete();
if($res !== false){
$result['code'] = 1;
}else{
$result['code'] = 0;
$result['message'] = '删除失败';
}
return $result;
}
public function queryList($gpc){
$page = isset($gpc['page']) ? intval($gpc['page']) : 1;
$page = max(1, $page);
$page_size = 10;
$keyword = $gpc['keyword'];
$type = $gpc['type'];
$is_ajax = $gpc['is_ajax'];
$template = $gpc['template'];
$is_ajax = !empty($is_ajax) ? intval($is_ajax) : 0;
$condition = " ";
if(!empty( $keyword )){
$keyword = trim($keyword);
$condition .= " and form_name like '%".$keyword."%'";
}
if(!empty($type)){
$condition .= " and form_type = '".$type."'";
}
$sql = 'SELECT * FROM ' . C('DB_PREFIX') . 'lionfish_comshop_forms WHERE 1 ' . $condition .
' order by id desc' .' limit ' . (($page - 1) * $page_size) . ',' . $page_size;
$list = M()->query($sql);
$total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX').'lionfish_comshop_forms WHERE 1 ' . $condition );
$total = $total_arr[0]['count'];
$ret_html = "
表单名称 |
表单类型 |
操作 |
";
foreach ($list as &$value) {
$value['form_type_name'] = $this->getFormTypeName($value['form_type']);
$ret_html .= '';
$ret_html .= ' '. $value['form_name'].' | ';
$ret_html .= ' '.$this->getFormTypeName($value['form_type']).' | ';
if ( isset($template) && $template == 'mult' ) {
$ret_html.=' 选择 | ';
}else{
$ret_html.=' 选择 | ';
}
$ret_html .= '
';
}
$pager = pagination($total, $page, $page_size,'',$context = array('before' => 5, 'after' => 4, 'isajax' => 1));
if( $is_ajax == 1 )
{
return ['html' => $ret_html, 'pager' => $pager ];
}else{
return ['list' => $list, 'pager' => $pager ];
}
}
public function getDataList($gpc){
$page = isset($gpc['page']) ? intval($gpc['page']) : 1;
$page_size = 10;
//会员昵称
$keyword = $gpc['keyword'];
//表单id
$id = $gpc['id'];
$condition = " and f.form_id = ".$id;
$sqlcondition = "";
if (!empty( $keyword )) {
$keyword = trim($keyword);
$condition .= ' AND (locate('.$keyword.',m.username) > 0 ) and f.user_id > 0 ';
$sqlcondition .= ' left join ' . C('DB_PREFIX') . 'lionfish_comshop_member m on m.member_id = f.user_id ';
}
$sql = 'SELECT f.* FROM ' . C('DB_PREFIX') . 'lionfish_comshop_form_info as f '.$sqlcondition.' WHERE 1 ' . $condition .
' order by f.id desc' .' limit ' . (($page - 1) * $page_size) . ',' . $page_size;
$list = M()->query($sql);
$total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX').'lionfish_comshop_form_info as f '.$sqlcondition.' WHERE 1 ' . $condition );
$total = $total_arr[0]['count'];
if( !empty($list) )
{
foreach( $list as $k=>$item )
{
$member_info = M('lionfish_comshop_member')->where( array('member_id' => $item['user_id'] ) )->find();
if(!empty($member_info)){
$list[$k]['username'] = $member_info['username'];
}
$list[$k]['addtime'] = date('Y-m-d H:i:s',$item['addtime']);
$list[$k]['form_type_name'] = $this->getFormTypeName($item['form_type']);
}
}
$pager = pagination2($total, $page, $page_size);
//表单信息
$form_data = $this->getFormsById($id);
$need_data = ['list' => $list, 'pager' => $pager, 'form_info'=>$form_data ];
return $need_data;
}
/**
* @author cy 2021-05-26
* @desc 获取已收集的表单数据列表
* @param $form_id
* @return mixed
*/
public function getFormInfoListByFormId($form_id){
$form_info_list = M('lionfish_comshop_form_info')->where(array('form_id' => $form_id))->select();
return $form_info_list;
}
/**
* @author cy 2021-05-26
* @desc 获取已收集的表单数据项列表
* @param $form_id
* @return mixed
*/
public function getFormItemListByFormId($form_id){
$form_item_list = M('lionfish_comshop_form_item')->where(array('form_id' => $form_id))->order('id asc')->select();
return $form_item_list;
}
/**
* @author cy 2021-05-26
* @desc 获取导出表单数据列表
* @param $form_id
* @return array
*/
public function getExportFormDataList($form_id){
$need_data = [];
//万能表单数据
$form_data = $this->getFormsById($form_id);
$title_list = [];
$form_list = $this->getFormInfoListByFormId($form_id);
if(!empty($form_list)){
foreach($form_list as $k=>$v){
$form_list[$k]['addtime'] = date('Y-m-d H:i:s',$v['addtime']);
$form_item_list = $this->getFormItemListByFormId($v['id']);
if(!empty($form_item_list)){
foreach($form_item_list as $ik=>$iv){
if(!in_array($iv['item_name'],$title_list) && $iv['type'] != 'image'){
array_push($title_list,$iv['item_name']);
}
$form_list[$k][$iv['item_name']] = $iv['item_val'];
}
}
$member_info = M('lionfish_comshop_member')->where( array('member_id' => $v['user_id'] ) )->find();
if(!empty($member_info)){
$form_list[$k]['username'] = $member_info['username'];
}else{
$form_list[$k]['username'] = "";
}
}
}
$need_data['form_list'] = $form_list;
$need_data['title_list'] = $title_list;
$need_data['form_data'] = $form_data;
return $need_data;
}
/**
* @author cy 2021-05-24
* @desc 添加万能表单
* @return array
*/
public function addOrUpdateForm()
{
$_GPC = I('request.');
$id = $_GPC['id'];
//表单名称
$form_name = trim($_GPC['form_name']);
//表单类型
$form_type = trim($_GPC['form_type']);
if( empty($form_name))
{
return ['code' => 0, 'message' => '请填写表单名称'];
}
if( empty($form_type))
{
return ['code' => 0, 'message' => '请选择表单类型'];
}
$condition = " 1=1 ";
if(!empty($id)){
$condition .= " and id != ".$id;
}
$condition .= " and form_name = '".$form_name."' ";
$forms_data = $this->getFormsByWhere($condition);
if(!empty($forms_data)){
return ['code' => 0, 'message' => '表单名称已存在,请修改'];
}
$title_array = [];
$random_code_list = trim($_GPC['random_code']);
if(!empty($random_code_list) && count($random_code_list) > 0){
foreach($random_code_list as $k=>$v){
$title = request()->input('title_'.$v, '');
$title_array[] = trim($title);
}
}
$title_list = array_unique($title_array);
if(count($title_list) < count($title_array)){
return ['code' => 0, 'message' => '标题不能重复'];
}
$form_content = $this->getFormContent();
$form_data = array();
$form_data['form_name'] = $form_name;
$form_data['form_type'] = $form_type;
$form_data['form_content'] = $form_content;
if( $id > 0 )
{
M('lionfish_comshop_forms')->where( array('id' => $id) )->save($form_data);
}else{
$form_data['addtime'] = time();
$id = M('lionfish_comshop_forms')->add($form_data);
}
return ['code' => 1];
}
/**
* @author 获取万能表单项数据
* @return string
*/
public function getFormContent(){
$content = "";
$content_array = [];
$random_code_list = I('request.random_code');
if(!empty($random_code_list) && count($random_code_list) > 0){
foreach($random_code_list as $k=>$v){
$content_array[$k] = $this->getFormItemValue($v);
}
$content = serialize($content_array);
}
return $content;
}
/**
* @author cy 2021-05-11
* @desc 获取万能表单项信息
* @param $random_code
* @return array
*/
public function getFormItemValue($random_code){
$form_data = [];
$_GPC = I('request.');
$form_type = $_GPC['form_type_'.$random_code];
$form_data['type'] = $form_type;
$form_data['random_code'] = $random_code;
if($form_type == 'image'){//图片
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//最大上传数量
$max_count = $_GPC['max_count_'.$random_code];
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['max_count'] = $max_count;
}else if($form_type == 'text'){//单行文本
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//提示
$hint = $_GPC['hint_'.$random_code];
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['hint'] = $hint;
}else if($form_type == 'textarea'){//多行文本
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//提示
$hint = $_GPC['hint_'.$random_code];
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['hint'] = $hint;
}else if($form_type == 'select'){//下拉选项
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//提示
$hint = $_GPC['hint_'.$random_code];
//选项
$option_array = [];
$option_vals = $_GPC['option_val_'.$random_code];
if(!empty($option_vals) && count($option_vals) > 0){
foreach($option_vals as $pk=>$pv){
$option_array[$pk] = $pv;
}
}
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['hint'] = $hint;
$form_data['option_val'] = $option_array;
}else if($form_type == 'radio'){//单选
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//选项
$option_array = [];
$option_vals = $_GPC['option_val_'.$random_code];
if(!empty($option_vals) && count($option_vals) > 0){
foreach($option_vals as $pk=>$pv){
$option_array[$pk] = $pv;
}
}
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['option_val'] = $option_array;
}else if($form_type == 'checked'){//多选
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//选项
$option_array = [];
$option_vals = $_GPC['option_val_'.$random_code];
if(!empty($option_vals) && count($option_vals) > 0){
foreach($option_vals as $pk=>$pv){
$option_array[$pk] = $pv;
}
}
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['option_val'] = $option_array;
}else if($form_type == 'area'){//地区
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//提示语
$hint = $_GPC['hint_'.$random_code];
//填写条件
$area_type = $_GPC['area_type_'.$random_code];
//默认省份
$province_id = $_GPC['province_id_'.$random_code];
//默认城市
$city_id = $_GPC['city_id_'.$random_code];
//默认区
$country_id = $_GPC['country_id_'.$random_code];
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['hint'] = $hint;
$form_data['area_type'] = $area_type;
$form_data['province_id'] = $province_id;
$form_data['city_id'] = $city_id;
$form_data['country_id'] = $country_id;
}else if($form_type == 'date'){//日期
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//提示语
$hint = $_GPC['hint_'.$random_code];
//日期默认类型
$date_type = $_GPC['date_type_'.$random_code];
//指定日期
$appoint_date = $_GPC['appoint_date_'.$random_code];
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['hint'] = $hint;
$form_data['date_type'] = $date_type;
$form_data['appoint_date'] = $appoint_date;
}else if($form_type == 'date_range'){//日期范围
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//开始日期类型
$begin_date_type = $_GPC['begin_date_type_'.$random_code];
//开始日期提示语
$begin_hint = $_GPC['begin_hint_'.$random_code];
//开始日期指定日期
$begin_appoint_date = $_GPC['begin_appoint_date_'.$random_code];
//结束日期类型
$end_date_type = $_GPC['end_date_type_'.$random_code];
//结束日期提示语
$end_hint = $_GPC['end_hint_'.$random_code];
//结束日期指定日期
$end_appoint_date = $_GPC['end_appoint_date_'.$random_code];
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['begin_date_type'] = $begin_date_type;
$form_data['begin_hint'] = $begin_hint;
$form_data['begin_appoint_date'] = $begin_appoint_date;
$form_data['end_date_type'] = $end_date_type;
$form_data['end_hint'] = $end_hint;
$form_data['end_appoint_date'] = $end_appoint_date;
}else if($form_type == 'idcard'){//身份证号码
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//提示
$hint = $_GPC['hint_'.$random_code];
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['hint'] = $hint;
}else if($form_type == 'time'){//时间
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//提示
$hint = $_GPC['hint_'.$random_code];
//时间类型
$time_type = $_GPC['time_type_'.$random_code];
//指定时间
$appoint_time = $_GPC['appoint_time_'.$random_code];
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['hint'] = $hint;
$form_data['time_type'] = $time_type;
$form_data['appoint_time'] = $appoint_time;
}else if($form_type == 'time_range'){//时间范围
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//开始时间类型
$begin_time_type = $_GPC['begin_time_type_'.$random_code];
//开始指定时间
$begin_appoint_time = $_GPC['begin_appoint_time_'.$random_code];
//开始时间提示语
$begin_hint = $_GPC['begin_hint_'.$random_code];
//开始时间类型
$end_time_type = $_GPC['end_time_type_'.$random_code];
//开始指定时间
$end_appoint_time = $_GPC['end_appoint_time_'.$random_code];
//开始时间提示语
$end_hint = $_GPC['end_hint_'.$random_code];
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['begin_time_type'] = $begin_time_type;
$form_data['begin_appoint_time'] = $begin_appoint_time;
$form_data['begin_hint'] = $begin_hint;
$form_data['end_time_type'] = $end_time_type;
$form_data['end_appoint_time'] = $end_appoint_time;
$form_data['end_hint'] = $end_hint;
}else if($form_type == 'telephone'){//手机号码
//标题
$title = $_GPC['title_'.$random_code];
//说明
$remark = $_GPC['remark_'.$random_code];
//提示
$hint = $_GPC['hint_'.$random_code];
$form_data['title'] = $title;
$form_data['remark'] = $remark;
$form_data['hint'] = $hint;
}
//是否必填
$required = $_GPC['required_'.$random_code];
if($required == 'on'){//必填
$required = 1;
}else{
$required = 0;
}
$form_data['required'] = $required;
return $form_data;
}
/**
* @author cy 2021-05-24
* @desc 获取表单项内容
* @param $type
* @return array
*/
public function getFormItem($type){
$need_data = [];
$item_li = "";
$phone_item = "";
$random_code = random(10,false);
if($type == 'image'){
$item_li = '
';
$phone_item = '';
}else if($type == 'text'){
$item_li = '
';
$phone_item = '';
}else if($type == 'textarea'){
$item_li = '
';
$phone_item = '';
}else if($type == 'select'){
$item_li = '
';
$phone_item = '';
}else if($type == 'radiao'){
$item_li = '
';
$phone_item = '';
}else if($type == 'checked'){
$item_li = '
';
$phone_item = '';
}else if($type == 'area'){
$item_li = '
';
$phone_item = '';
}else if($type == 'date'){
$item_li = '
';
$phone_item = '';
}else if($type == 'date_range'){
$item_li = '
';
$phone_item = '';
}else if($type == 'idcard'){
$item_li = '
';
$phone_item = '';
}else if($type == 'time'){
$item_li = '
';
$phone_item = '';
}else if($type == 'time_range'){
$item_li = '
';
$phone_item = '';
}else if($type == 'telephone'){
$item_li = '
';
$phone_item = '';
}
$need_data['item_li'] = $item_li;
$need_data['phone_item'] = $phone_item;
$need_data['random_code'] = $random_code;
return $need_data;
}
/**
* @author cy 2021-05-24
* @desc 获取万能表单信息
* @param $item
* @return array
*/
public function setFormsContent($item){
$form_content = unserialize( $item['form_content'] );
$item_li = "";
$phone_item = "";
if(!empty($form_content) && count($form_content) > 0){
foreach($form_content as $k=>$v){
$random_code = random(10,false);
$required = $v['required'];
$type = $v['type'];
if($type == 'image'){//图片
$title = $v['title'];
$remark = $v['remark'];
$max_count = $v['max_count'];
$item_li = $item_li. '
';
$phone_item = $phone_item . '';
}else if($type == 'text'){//单行文本
$title = $v['title'];
$remark = $v['remark'];
$hint = $v['hint'];
$item_li = $item_li . '
';
$phone_item = $phone_item. '';
}else if($type == 'textarea'){//多行文本
$title = $v['title'];
$remark = $v['remark'];
$hint = $v['hint'];
$item_li = $item_li . '
';
$phone_item = $phone_item.'
'.$title.'';
if($required == 1){
$phone_item = $phone_item.'*';
}else{
$phone_item = $phone_item.'*';
}
$phone_item = $phone_item.'
'.$remark.'
';
}else if($type == 'select'){//下拉选项
$title = $v['title'];
$remark = $v['remark'];
$hint = $v['hint'];
$option_val = $v['option_val'];
$item_li = $item_li.'
';
$phone_item = $phone_item. '';
}else if($type == 'radio'){//单选
$title = $v['title'];
$remark = $v['remark'];
$option_val = $v['option_val'];
$item_li = $item_li.'
';
$phone_item = $phone_item.'';
}else if($type == 'checked'){//多选
$title = $v['title'];
$remark = $v['remark'];
$option_val = $v['option_val'];
$item_li = $item_li.'
';
$phone_item = $phone_item.'';
}else if($type == 'area'){//地区
$title = $v['title'];
$remark = $v['remark'];
$hint = $v['hint'];
$area_type = $v['area_type'];
$province_id = $v['province_id'];
$city_id = $v['city_id'];
$country_id = $v['country_id'];
$address = "";
if($province_id != '请选择省份'){
$address = $address . $province_id;
}
if($city_id != '请选择城市'){
$address = $address . $city_id;
}
if($country_id != '请选择区域'){
$address = $address . $country_id;
}
$item_li = $item_li.'
';
if($required == 1){
$item_li = $item_li.'';
}else{
$item_li = $item_li.'';
}
$item_li = $item_li.'
';
$phone_item = $phone_item. '';
}else if($type == 'date'){//日期
$title = $v['title'];
$remark = $v['remark'];
$hint = $v['hint'];
$date_type = $v['date_type'];
$appoint_date = $v['appoint_date'];
$item_li = $item_li.'
';
$phone_item = $phone_item.'';
}else if($type == 'date_range'){
$title = $v['title'];
$remark = $v['remark'];
$begin_date_type = $v['begin_date_type'];
$begin_hint = $v['begin_hint'];
$begin_appoint_date = $v['begin_appoint_date'];
$end_date_type = $v['end_date_type'];
$end_hint = $v['end_hint'];
$end_appoint_date = $v['end_appoint_date'];
$item_li = $item_li.'
';
$phone_item = $phone_item.'';
}else if($type == 'idcard'){
$title = $v['title'];
$remark = $v['remark'];
$hint = $v['hint'];
$item_li = $item_li . '
';
$phone_item = $phone_item.'';
}else if($type == 'time'){
$title = $v['title'];
$remark = $v['remark'];
$hint = $v['hint'];
$time_type = $v['time_type'];
$appoint_time = $v['appoint_time'];
$item_li = $item_li. '
';
$phone_item = $phone_item.'';
}else if($type == 'time_range'){
$title = $v['title'];
$remark = $v['remark'];
$begin_time_type = $v['begin_time_type'];
$begin_hint = $v['begin_hint'];
$begin_appoint_time = $v['begin_appoint_time'];
$end_time_type = $v['end_time_type'];
$end_hint = $v['end_hint'];
$end_appoint_time = $v['end_appoint_time'];
$item_li = $item_li . '
';
$phone_item = $phone_item .'';
}else if($type == 'telephone'){
$title = $v['title'];
$remark = $v['remark'];
$hint = $v['hint'];
$item_li = $item_li.'
';
$phone_item = $phone_item.'';
}
}
}
$item_li = $item_li . '
';
$need_data = ['item_li' => $item_li,'phone_item' => $phone_item];
return $need_data;
}
}
?>