dever 6 năm trước cách đây
commit
4762fcb211
5 tập tin đã thay đổi với 619 bổ sung0 xóa
  1. 246 0
      database/info.php
  2. 180 0
      database/user.php
  3. 110 0
      database/user_answer.php
  4. 8 0
      index.php
  5. 75 0
      src/Api.php

+ 246 - 0
database/info.php

@@ -0,0 +1,246 @@
+<?php
+
+$type = array
+(
+	# 小于10无需选项
+	1 => '单行输入框',
+	2 => '多行输入框',
+	3 => '城市选择框',
+	4 => '单图片上传',
+	5 => '多图片上传',
+
+	# 大于10需要选项
+	11 => '单选框',
+	12 => '多选框',
+);
+
+$must = array
+(
+	1 => '必填',
+	2 => '选填',
+);
+
+$content_type = array
+(
+	1 => '需要用户选择',
+	2 => '需要用户输入',
+);
+
+$match = array
+(
+	1 => '所有字符',
+	2 => '中文',
+	3 => '中文+英文',
+	4 => '中文+英文+数字',
+	5 => '英文',
+	6 => '英文+数字',
+	7 => '手机',
+	8 => '邮箱',
+);
+
+$id = Dever::input('search_option_product_id');
+$name = '';
+if ($id > 0) {
+	$info = Dever::db('service/product')->one($id);
+	$name = $info['name'] . '-';
+}
+
+return array
+(
+	# 表名
+	'name' => 'info',
+	# 显示给用户看的名称
+	'lang' => $name . '问卷管理',
+	'order' => 100,
+	'menu' => false,
+	# 数据结构
+	'struct' => array
+	(
+	
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'search'	=> 'order',
+			//'list'		=> true,
+		),
+
+		'page_number'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '页号',
+			'default' 	=> '1',
+			'desc' 		=> '请输入页号',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+			'order'		=> 'asc',
+			'edit'		=> true,
+		),
+
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '序号',
+			'default' 	=> '1',
+			'desc' 		=> '请输入序号',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+			'order'		=> 'asc',
+			'edit'		=> true,
+		),
+
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-200',
+			'name' 		=> '标题',
+			'default' 	=> '',
+			'desc' 		=> '标题',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'info'		=> array
+		(
+			'type' 		=> 'varchar-800',
+			'name' 		=> '描述',
+			'default' 	=> '',
+			'desc' 		=> '描述',
+			'match' 	=> 'option',
+			'update'	=> 'textarea',
+		),
+
+		'product_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '产品',
+			'default' 	=> '',
+			'desc' 		=> '产品',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'hidden',
+			'value'		=> Dever::input('search_option_product_id')
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '问卷类型',
+			'default' 	=> '1',
+			'desc' 		=> '问卷类型',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $type,
+			'search'	=> 'select',
+			'update'	=> 'radio',
+			'list'		=> true,
+			'control'	=> 'type',
+		),
+
+		'must'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '是否必填',
+			'default' 	=> '1',
+			'desc' 		=> '是否必填',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $must,
+			'update'	=> 'select',
+			'list'		=> true,
+			'edit'		=> true,
+		),
+
+		'match'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '验证规则',
+			'default' 	=> '1',
+			'desc' 		=> '验证规则',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $match,
+			//'update'	=> 'select',
+			'show'		=> 'type=1,2',
+		),
+
+		'content'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '选项设置',
+			'default' 	=> '',
+			'desc' 		=> '选项设置',
+			'match' 	=> 'is_string',
+			'show'		=> 'type=11,12',
+			'update'	=> array
+			(
+				array
+				(
+					'col'		=> 'score',
+					'name' 		=> '选项分数-用于计算最终结果,暂时可以不填',
+					'default' 	=> '0',
+					'desc' 		=> '选项分数',
+					'match' 	=> 'is_string',
+					'update'	=> 'text',
+				),
+
+				array
+				(
+					'col'		=> 'ctype',
+					'name' 		=> '选项类型',
+					'default' 	=> '1',
+					'desc' 		=> '选项类型',
+					'match' 	=> 'is_numeric',
+					'option' 	=> $content_type,
+					'update'	=> 'radio',
+					'control'	=> 'ctype',
+				),
+
+				array
+				(
+					'col'		=> 'title',
+					'name' 		=> '选项标题',
+					'default' 	=> '',
+					'desc' 		=> '请输入选项标题',
+					'match' 	=> 'option',
+					'update'	=> 'text',
+				),
+				
+				array
+				(
+					'col'		=> 'pic',
+					'name' 		=> '选项图片',
+					'default' 	=> '',
+					'desc' 		=> '选项图片',
+					'match' 	=> 'option',
+					'update'	=> 'image',
+					'key' 		=> '1',
+					'show'		=> 'ctype=1',
+				),
+			),
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '申请时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'search'	=> 'date',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+);

+ 180 - 0
database/user.php

@@ -0,0 +1,180 @@
+<?php
+
+$status = array
+(
+	1 => '未开始',
+	2 => '正在答题',
+	3 => '中止答题',//也算完成
+	4 => '完成答题',
+);
+
+return array
+(
+	# 表名
+	'name' => 'user',
+	# 显示给用户看的名称
+	'lang' => '用户参与表',
+	# 是否显示在后台菜单
+	'menu' => false,
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'order'		=> 'desc',
+			'list'		=> true,
+		),
+
+		'product_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '产品',
+			'default' 	=> '',
+			'desc' 		=> '产品',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'hidden',
+			'value'		=> Dever::input('search_option_product_id')
+		),
+
+		'uid'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '用户',
+			'default' 	=> '',
+			'desc' 		=> '用户id',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			//'list'		=> '{uid} > 0 ? Dever::load("passport/user-one#name", {uid}) : "匿名用户"',
+		),
+
+		'score'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '当前得分',
+			'default' 	=> '0',
+			'desc' 		=> '当前得分',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'times'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '答题次数',
+			'default' 	=> '0',
+			'desc' 		=> '答题次数',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'index'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '答题进度',
+			'default' 	=> '0',
+			'desc' 		=> '答题进度',
+			'match' 	=> 'option',
+			'update'	=> 'textarea',
+			'list'		=> true,
+		),
+
+		'status'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '答题状态',
+			'default' 	=> '1',
+			'desc' 		=> '答题状态',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'radio',
+			'option'	=> $status,
+			'control'	=> 'type',
+			'list'		=> true,
+		),
+
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '更新时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			//'insert'	=> true,
+			'search'	=> 'date',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'manage' => array
+	(
+		'insert' => false,
+		'edit' => false,
+		'delete' => false,
+	),
+
+	'request' => array
+	(
+		# 获取最新一条的用户信息
+		'get' => array
+		(
+			# 匹配的正则或函数 选填项
+			'where' => array
+			(
+				'uid' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'one',
+			'order' => array('times' => 'desc', 'id' => 'desc'),
+			'col' => '*',
+		),
+
+		# 获取已完成记录
+		'getFinish' => array
+		(
+			# 匹配的正则或函数 选填项
+			'where' => array
+			(
+				'status' => array('yes', '>='),
+				'exam_id' => 'yes',
+				'uid' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'one',
+			'order' => array('times' => 'desc', 'id' => 'desc'),
+			'col' => 'times,status',
+		),
+
+		# 获取未完成记录
+		'getUnFinish' => array
+		(
+			# 匹配的正则或函数 选填项
+			'where' => array
+			(
+				'status' => array('yes', '<'),
+				'exam_id' => 'yes',
+				'uid' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'one',
+			'col' => '*',
+		),
+	)
+);

+ 110 - 0
database/user_answer.php

@@ -0,0 +1,110 @@
+<?php
+return array
+(
+	# 表名
+	'name' => 'user_answer',
+	# 显示给用户看的名称
+	'lang' => '用户答题记录',
+	# 是否显示在后台菜单
+	'menu' => false,
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'order'		=> 'desc',
+			'list'		=> true,
+		),
+
+		'uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '用户',
+			'default' 	=> '',
+			'desc' 		=> '用户',
+			'match' 	=> 'is_numeric',
+			'list'		=> true,
+		),
+
+		'info_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '问卷标题',
+			'default' 	=> '',
+			'desc' 		=> '问卷标题',
+			'match' 	=> 'is_numeric',
+			'list'		=> true,
+		),
+
+		'score'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '本题得分',
+			'default' 	=> '0',
+			'desc' 		=> '本题得分',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'value'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '内容',
+			'default' 	=> '',
+			'desc' 		=> '内容',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'search'	=> 'date',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'manage' => array
+	(
+		
+	),
+
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'uid' => 'yes',
+				'info_id' => 'yes',
+				'user_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'col' => 'info_id,uid,user_id,id|info_id',
+		),
+	)
+);

+ 8 - 0
index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'survey');
+define('DEVER_APP_LANG', '调查问卷');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 10);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-tree-deciduous');
+include(DEVER_APP_PATH . '../boot.php');

+ 75 - 0
src/Api.php

@@ -0,0 +1,75 @@
+<?php
+
+namespace Survey\Src;
+
+use Dever;
+
+class Api
+{
+	/**
+	 * 获取问卷信息
+	 *
+	 * @return mixed
+	 */
+	public function get($uid, $product_id, $page_number = false)
+	{
+		if ($product_id <= 0) {
+			Dever::alert('请传入正确的产品id');
+		}
+
+		$user = Dever::db('survey/user')->one(array('uid' => $uid, 'product_id' => $product_id));
+		if (!$user) {
+			$user['uid'] = $uid;
+			$user['index'] = 1;
+			$user['product_id'] = $product_id;
+			$user['status'] = 2;
+			$user['id'] = Dever::db('survey/user')->insert($user);
+		}
+
+		$result['user'] = $user;
+		if ($page_number > 0) {
+			$user['index'] = $page_number;
+		}
+		$result['info'] = Dever::db('survey/info')->state(array('product_id' => $product_id, 'page_number' => $user['index']));
+
+		if ($result['info']) {
+			foreach ($result['info'] as $k => $v) {
+				$answer = Dever::db('survey/user_answer')->one(array('info_id' => $v['id'], 'uid' => $uid));
+				if ($answer) {
+					$result['info'][$k]['answer'] = $answer['value'];
+				} else {
+					$result['info'][$k]['answer'] = '';
+				}
+			}
+		}
+
+		return $result;
+	}
+
+	/**
+	 * 提交问卷信息
+	 *
+	 * @return mixed
+	 */
+	public function submit($uid, $product_id, $page_number, $survey_id, $survey_answer)
+	{
+		if ($page_number > 0) {
+			Dever::db('survey/user')->update(array('uid' => $uid, 'index' => $page_number));
+		}
+		if ($survey_id && $survey_answer) {
+			$survey_id = explode('||', $survey_id);
+			$survey_answer = explode('||', $survey_answer);
+			foreach ($survey_id as $k => $v) {
+				$answer = Dever::db('survey/user_answer')->one(array('info_id' => $v, 'uid' => $uid));
+
+				if ($answer) {
+					Dever::db('survey/user_answer')->update(array('where_id' => $answer['id'], 'value' => $survey_answer[$k]));
+				} else {
+					Dever::db('survey/user_answer')->insert(array('info_id' => $v, 'uid' => $uid, 'value' => $survey_answer[$k]));
+				}
+			}
+		}
+
+		return true;
+	}
+}