|
@@ -9,10 +9,14 @@ use Hyperf\DbConnection\Db;
|
|
use App\Model\GlobalTableField;
|
|
use App\Model\GlobalTableField;
|
|
use App\Model\GlobalTableFieldType;
|
|
use App\Model\GlobalTableFieldType;
|
|
use App\Model\GlobalTableFieldValue;
|
|
use App\Model\GlobalTableFieldValue;
|
|
|
|
+use Hyperf\Di\Annotation\Inject;
|
|
|
|
+use Hyperf\Redis\Redis;
|
|
#[RpcService(name: "FormService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
#[RpcService(name: "FormService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
class FormService implements FormServiceInterface
|
|
class FormService implements FormServiceInterface
|
|
{
|
|
{
|
|
|
|
|
|
|
|
+ #[Inject]
|
|
|
|
+ protected Redis $redis;
|
|
/**
|
|
/**
|
|
* 添加全局表单
|
|
* 添加全局表单
|
|
* @param array $data
|
|
* @param array $data
|
|
@@ -32,6 +36,8 @@ class FormService implements FormServiceInterface
|
|
Db::connection('global')->statement("CREATE TABLE IF NOT EXISTS `{$data['table']}` (
|
|
Db::connection('global')->statement("CREATE TABLE IF NOT EXISTS `{$data['table']}` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`title` varchar(255) DEFAULT NULL,
|
|
`title` varchar(255) DEFAULT NULL,
|
|
|
|
+ `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
|
|
+ `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
PRIMARY KEY (`id`)
|
|
PRIMARY KEY (`id`)
|
|
)");
|
|
)");
|
|
//给GlobalTableField表初始化数据
|
|
//给GlobalTableField表初始化数据
|
|
@@ -59,7 +65,31 @@ class FormService implements FormServiceInterface
|
|
'admin_display' => 1,
|
|
'admin_display' => 1,
|
|
'home_display' => 1,
|
|
'home_display' => 1,
|
|
'disable_del' => 1,
|
|
'disable_del' => 1,
|
|
- ]
|
|
|
|
|
|
+ ],
|
|
|
|
+ [
|
|
|
|
+ 'table_id' => $id,
|
|
|
|
+ 'field_name' => 'updated_at',
|
|
|
|
+ 'title' => '更新时间',
|
|
|
|
+ 'field_type' => '1',
|
|
|
|
+ 'length' => 255,
|
|
|
|
+ 'sort' => 999,
|
|
|
|
+ 'is_check' => 1,
|
|
|
|
+ 'admin_display' => 1,
|
|
|
|
+ 'home_display' => 0,
|
|
|
|
+ 'disable_del' => 1,
|
|
|
|
+ ],
|
|
|
|
+ [
|
|
|
|
+ 'table_id' => $id,
|
|
|
|
+ 'field_name' => 'created_at',
|
|
|
|
+ 'title' => '创建时间',
|
|
|
|
+ 'field_type' => '1',
|
|
|
|
+ 'length' => 255,
|
|
|
|
+ 'sort' => 1000,
|
|
|
|
+ 'is_check' => 1,
|
|
|
|
+ 'admin_display' => 1,
|
|
|
|
+ 'home_display' => 0,
|
|
|
|
+ 'disable_del' => 1,
|
|
|
|
+ ],
|
|
|
|
|
|
]);
|
|
]);
|
|
|
|
|
|
@@ -183,6 +213,7 @@ class FormService implements FormServiceInterface
|
|
$fields = GlobalTableField::from('global_table_field as a')
|
|
$fields = GlobalTableField::from('global_table_field as a')
|
|
->join('global_table_field_type as b', 'a.field_type', '=', 'b.id')
|
|
->join('global_table_field_type as b', 'a.field_type', '=', 'b.id')
|
|
->where('a.table_id', $data['id'])
|
|
->where('a.table_id', $data['id'])
|
|
|
|
+ ->whereNotIn('a.field_name',['id','created_at','updated_at'])
|
|
->orderBy('a.sort', 'asc')
|
|
->orderBy('a.sort', 'asc')
|
|
->select(
|
|
->select(
|
|
// global_table_field 所有字段
|
|
// global_table_field 所有字段
|
|
@@ -295,6 +326,21 @@ class FormService implements FormServiceInterface
|
|
try {
|
|
try {
|
|
//查询global库的表GlobalTableField模型中table_id为$data['id']的数据条件为admin_display=1的数据
|
|
//查询global库的表GlobalTableField模型中table_id为$data['id']的数据条件为admin_display=1的数据
|
|
$globalTableFields = GlobalTableField::where(['table_id'=>$data['id'],'admin_display'=>1])->get();
|
|
$globalTableFields = GlobalTableField::where(['table_id'=>$data['id'],'admin_display'=>1])->get();
|
|
|
|
+ $globalTableFields->transform(function ($field) {
|
|
|
|
+ $optionValue = [];
|
|
|
|
+ $optionStr = trim((string) $field->option);
|
|
|
|
+ if (!empty($optionStr)) {
|
|
|
|
+ $options = explode("\n", $optionStr);
|
|
|
|
+ foreach ($options as $option) {
|
|
|
|
+ $parts = explode('|', $option);
|
|
|
|
+ if (count($parts) === 2) {
|
|
|
|
+ $optionValue[$parts[1]] = $parts[0];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $field->option_value = $optionValue;
|
|
|
|
+ return $field;
|
|
|
|
+ });
|
|
|
|
|
|
//查询global库的表GlobalTable模型中id为$data['id']的数据
|
|
//查询global库的表GlobalTable模型中id为$data['id']的数据
|
|
$globalTable = GlobalTable::where('id',$data['id'])->first();
|
|
$globalTable = GlobalTable::where('id',$data['id'])->first();
|
|
@@ -415,6 +461,21 @@ class FormService implements FormServiceInterface
|
|
$query->where('id',$data['id']);
|
|
$query->where('id',$data['id']);
|
|
$dataInfo = $query->first();
|
|
$dataInfo = $query->first();
|
|
$globalTableField = GlobalTableField::where(['table_id'=>$data['table_id']])->get();
|
|
$globalTableField = GlobalTableField::where(['table_id'=>$data['table_id']])->get();
|
|
|
|
+ $globalTableField->transform(function ($field) {
|
|
|
|
+ $optionValue = [];
|
|
|
|
+ $optionStr = trim((string) $field->option);
|
|
|
|
+ if (!empty($optionStr)) {
|
|
|
|
+ $options = explode("\n", $optionStr);
|
|
|
|
+ foreach ($options as $option) {
|
|
|
|
+ $parts = explode('|', $option);
|
|
|
|
+ if (count($parts) === 2) {
|
|
|
|
+ $optionValue[$parts[1]] = $parts[0];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $field->option_value = $optionValue;
|
|
|
|
+ return $field;
|
|
|
|
+ });
|
|
$return = [
|
|
$return = [
|
|
'data'=>$dataInfo,
|
|
'data'=>$dataInfo,
|
|
'tableFields'=>$globalTableField->toArray(),
|
|
'tableFields'=>$globalTableField->toArray(),
|
|
@@ -424,4 +485,88 @@ class FormService implements FormServiceInterface
|
|
return Result::error('查询失败:' . $e->getMessage());
|
|
return Result::error('查询失败:' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * 查询网站下表单自定义字段
|
|
|
|
+ */
|
|
|
|
+ public function getWebGlobalTableFieldList(array $data): array
|
|
|
|
+ {
|
|
|
|
+ try {
|
|
|
|
+ $globalTable = GlobalTable::where('id',$data['table_id'])->first();
|
|
|
|
+ $fields = GlobalTableField::from('global_table_field as a')
|
|
|
|
+ ->join('global_table_field_type as b', 'a.field_type', '=', 'b.id')
|
|
|
|
+ ->where('a.table_id', $data['table_id'])
|
|
|
|
+ ->where('a.field_name',"<>",'id')
|
|
|
|
+ ->where('a.home_display', 1)
|
|
|
|
+ ->orderBy('a.sort', 'asc')
|
|
|
|
+ ->select(
|
|
|
|
+ // global_table_field 所有字段
|
|
|
|
+ 'a.*',
|
|
|
|
+ // global_table_field_type 字段
|
|
|
|
+ 'b.type_name',
|
|
|
|
+ 'b.type_name_alias',
|
|
|
|
+ 'b.field_type as type_definition'
|
|
|
|
+ )
|
|
|
|
+ ->get();
|
|
|
|
+
|
|
|
|
+ $config = new \EasySwoole\VerifyCode\Config();
|
|
|
|
+ $code = new \EasySwoole\VerifyCode\VerifyCode($config);
|
|
|
|
+ $img_code = '';
|
|
|
|
+ $characters = '0123456789';
|
|
|
|
+ $charLength = strlen($characters);
|
|
|
|
+ for ($i = 0; $i < 4; $i++) {
|
|
|
|
+ $img_code .= $characters[rand(0, $charLength - 1)];
|
|
|
|
+ }
|
|
|
|
+ //重写验证码
|
|
|
|
+ $result = $code->DrawCode((string)$img_code);
|
|
|
|
+ $img_code = $result->getImageCode();
|
|
|
|
+ var_dump("验证码:",$img_code);
|
|
|
|
+ $code_uniqid = uniqid("code");
|
|
|
|
+ //写入缓存 用于其他方法验证 并且设置过期时间
|
|
|
|
+ $this->redis->set($code_uniqid,$img_code,60000);
|
|
|
|
+ $rep = [
|
|
|
|
+ 'fields' => $fields,
|
|
|
|
+ 'table'=>$globalTable,
|
|
|
|
+ ];
|
|
|
|
+ if($globalTable->is_code){
|
|
|
|
+ $rep['code']['code_uniqid'] = $code_uniqid;
|
|
|
|
+ $rep['code']['img'] = $result->getImageBase64();
|
|
|
|
+ }
|
|
|
|
+ return Result::success($rep);
|
|
|
|
+ }catch (\Throwable $e){
|
|
|
|
+ return Result::error('查询失败:' . $e->getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * web端创建数据
|
|
|
|
+ * @param array $data
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function addWebGlobalTableData(array $data): array
|
|
|
|
+ {
|
|
|
|
+ try {
|
|
|
|
+ $globalTable = GlobalTable::where('id',$data['otherData']['table_id'])->first();
|
|
|
|
+ if($globalTable->is_code){
|
|
|
|
+ if(empty($data['otherData']['code'])){
|
|
|
|
+ return Result::error('请输入验证码');
|
|
|
|
+ }
|
|
|
|
+ $code = $this->redis->get($data['otherData']['code_uniqid']);
|
|
|
|
+ if(empty($code)){
|
|
|
|
+ return Result::error('验证码已过期');
|
|
|
|
+ }
|
|
|
|
+ if($data['otherData']['code'] != $code){
|
|
|
|
+ return Result::error('验证码错误');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(empty($globalTable)){
|
|
|
|
+ return Result::error('表单不存在');
|
|
|
|
+ }
|
|
|
|
+ $query = Db::connection('global')->table($globalTable->table);
|
|
|
|
+
|
|
|
|
+ $query->insert($data['data']);
|
|
|
|
+ return Result::success([]);
|
|
|
|
+ }catch (\Throwable $e){
|
|
|
|
+ return Result::error('添加失败:' . $e->getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|