dever 2 年之前
父节点
当前提交
1fe197635d
共有 2 个文件被更改,包括 166 次插入7 次删除
  1. 134 0
      database/code.php
  2. 32 7
      src/Code.php

+ 134 - 0
database/code.php

@@ -0,0 +1,134 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'code',
+	# 显示给用户看的名称
+	'lang' => '小程序码',
+	'order' => 100,
+	'menu'	=> false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			//'list'		=> true,
+		),
+
+		'project_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '项目ID',
+			'default' 	=> '',
+			'desc' 		=> '请输入项目',
+			'match' 	=> 'is_numeric',
+			'list'		=> 'Dever::load("token/project-one#name", {project_id})',
+		),
+
+		'file'		=> array
+		(
+			'type' 		=> 'varchar-2000',
+			'name' 		=> '文件地址',
+			'default' 	=> '',
+			'desc' 		=> '文件地址',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'filename'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '生成文件名',
+			'default' 	=> '',
+			'desc' 		=> '生成文件名',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+		
+		'path'		=> array
+		(
+			'type' 		=> 'varchar-2000',
+			'name' 		=> '小程序路径',
+			'default' 	=> '',
+			'desc' 		=> '小程序路径',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'send'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '小程序传参',
+			'default' 	=> '',
+			'desc' 		=> '小程序传参',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'width'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '宽度',
+			'default' 	=> '',
+			'desc' 		=> '宽度',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'env'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '环境',
+			'default' 	=> '',
+			'desc' 		=> '环境',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'mdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '生成时间',
+			'default' 	=> '',
+			'desc' 		=> '生成时间',
+			'match' 	=> 'option',
+		),
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '更新时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			'default' 	=> '',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'manage' => array
+	(
+		
+	),
+);

+ 32 - 7
src/Code.php

@@ -18,7 +18,7 @@ class Code
         $param['param'] = Dever::input('send');
         $filename = Dever::input('filename');
         $param['width'] = Dever::input('width', 200);
-        $param['is_hyaline'] = true;
+        $param['is_hyaline'] = false;
         $param['env_version'] = 'release';
         $update = Dever::input('update', 2);
 
@@ -50,19 +50,43 @@ class Code
             $filename = md5($param['param']);
         }
 
-        $wechat = new Wechat($project, 'wechat_applet');
+        $where['project_id'] = $project;
+        $where['filename'] = $filename;
+        $where['path'] = $param['path'];
+        $where['send'] = $param['param'];
+        $code = Dever::db('wechat_applet/code')->find($where);
+        if (!$code) {
+            $update = 1;
+        } elseif ($update == 2) {
+            return $code['file'] . '?v=' . time();
+        }
+        
+        if ($update == 1) {
+            $wechat = new Wechat($project, 'wechat_applet');
 
-        $data = $wechat->curl('code', $param, true);
+            $data = $wechat->curl('code', $param, true);
 
-        if ($data) {
-            $upload = Dever::load('upload/save')->copy('content,' . $data, 1, false, '', 'png', $filename);
-            if (isset($upload['url'])) {
-                return $upload['url'] . '?v=' . time();
+            if ($data) {
+                $upload = Dever::load('upload/save')->copy('content,' . $data, 1, false, '', 'png', $filename);
+                if (isset($upload['url'])) {
+                    $where['file'] = $upload['url'];
+                    $where['width'] = $param['width'];
+                    $where['env'] = $param['env_version'];
+                    if ($code) {
+                        $where['where_id'] = $code['id'];
+                        Dever::db('wechat_applet/code')->update($where);
+                    } else {
+                        Dever::db('wechat_applet/code')->insert($where);
+                    }
+                    
+                    return $upload['url'] . '?v=' . time();
+                }
             }
         }
 
         return false;
 
+        /*
         $file = Dever::pathDay('upload/applet/code', false) . $project . '_' . md5($param['path'] . '_' . $param['param'] . '_' . $param['width']) . '.jpg';
 
         if (!is_file($file) || $update == 1) {
@@ -83,5 +107,6 @@ class Code
         $file = Dever::pic($file);
 
         return $file;
+        */
     }
 }