Example #1
0
 /**
  * 写文件日志
  * @param string $content
  * @param string $fileName 文件名,可加入路径,eg:grlend/201111
  * @param string $ext 扩展名
  */
 public static function write($content, $fileName = '', $ext = 'txt')
 {
     if (empty($fileName)) {
         $fileName = date("Ymd") . $ext;
     }
     $fileName = __ROOT__ . '/Log/' . $fileName . '.' . $ext;
     if (dirExists(dirname($fileName))) {
         file_put_contents($fileName, date("Y/m/d H:i:s") . '----' . PHP_EOL . $content . PHP_EOL, FILE_APPEND);
     }
 }
Example #2
0
/**
 * 开启sql debug时纪录数据库操作
 * @param string $sql
 * @param string $error
 */
function sqlDebugLog($sql, $error = '')
{
    $fileName = __ROOT__ . "/Log/database/sql_" . date("Ymd") . '.txt';
    if (dirExists(dirname($fileName))) {
        file_put_contents($fileName, date("Y/m/d H:i:s") . '----' . PHP_EOL . $sql . PHP_EOL . $error . PHP_EOL, FILE_APPEND);
    }
}
 /**
  * 记录成功支付日志(文件)
  * @param str $info
  */
 private function successPayLog($return_msg, $info)
 {
     $path = __ROOT__ . '/Log/successPayLog/' . date('Ymd') . '/';
     if (dirExists($path)) {
         file_put_contents($path . "log.txt", date("Y-m-d H:i:s") . "-----------" . PHP_EOL . $info . PHP_EOL . '-----------' . PHP_EOL . '结果:' . $return_msg . PHP_EOL . '------------------ ' . PHP_EOL, FILE_APPEND);
     }
 }
Example #4
0
 /**
  * 获取微信media并保存
  * @param str $mediaID  media_id
  * @param str $path 目录
  * @return bool
  */
 public static function getWechatMedia($mediaID, $savePath = null)
 {
     if (empty($savePath)) {
         $savePath = 'order/' . time() . '_' . rand(1000, 9999) . ".jpg";
     }
     $weObj = new \System\lib\Wechat\Wechat(\System\Entrance::config("WEIXIN_CONFIG"));
     $media = $weObj->getMedia($mediaID);
     if (!$media) {
         return false;
     }
     $temPath = '../TempImg/';
     //临时保存路径
     if (!dirExists($temPath)) {
         return false;
     }
     $fileName = basename($savePath);
     /* $fileName=basename($savePath);
        $checkPath=str_replace($fileName, '', $savePath);
        if(!dirExists($checkPath)) return false; */
     if (!file_put_contents($temPath . $fileName, $media)) {
         return false;
     }
     //生成压缩图片
     $image = new \System\lib\Image\Image($temPath . $fileName);
     $img1 = $image->size();
     $return['img1']['path'] = $temPath . $fileName;
     $return['img1']['width'] = $img1[0];
     $return['img1']['heigh'] = $img1[1];
     //200*200缩略图
     $img2Path = $temPath . str_replace('.', '_thumb200.', $fileName);
     $image->thumb(200, 10000)->save($img2Path);
     $img2 = $image->size();
     $return['img2']['path'] = $img2Path;
     $return['img2']['width'] = $img2[0];
     $return['img2']['heigh'] = $img2[1];
     //360*360缩略图
     $img3Path = $temPath . str_replace('.', '_thumb360.', $fileName);
     $image->open($temPath . $fileName);
     $image->thumb(360, 10000)->save($img3Path);
     $img3 = $image->size();
     $return['img3']['path'] = $img3Path;
     $return['img3']['width'] = $img3[0];
     $return['img3']['heigh'] = $img3[1];
     //dump($return);
     //上传
     foreach ($return as $key => $a) {
         $upload = httpPost(\System\Entrance::config('IMG_UPLOAD'), ['file' => new \CURLFile(realpath($a['path'])), 'savePath' => dirname($savePath) . '/', 'saveName' => basename($a['path'])], true);
         //dump($upload);
         $upload = json_decode($upload, true);
         if (!($upload && $upload['result'] == true)) {
             return false;
         }
         unlink($a['path']);
         $return[$key]['path'] = $upload['path'];
     }
     return $return;
 }
 public function index()
 {
     function convertTableToClass($table)
     {
         $array = explode("_", $table);
         for ($i = 0; isset($array[$i]); $i++) {
             $array[$i] = ucfirst($array[$i]);
         }
         return implode("", $array);
     }
     $DB = empty($_GET['DB']) ? 'DB_MASTER' : $_GET['DB'];
     $conn = \System\database\Database::openConnection($DB);
     $result_table = $conn->query("SHOW TABLES");
     $tables = array();
     while (true) {
         $row = mysqli_fetch_row($result_table);
         if ($row) {
             $tables[] = $row[0];
         } else {
             break;
         }
     }
     mysqli_free_result($result_table);
     foreach ($tables as $table) {
         $result = $conn->query("SHOW COLUMNS FROM {$table}");
         //$className = convertTableToClass($table);
         $className = $table;
         //$string = "<?php class $className extends BaseTable{" . PHP_EOL . "protected function initTable(){ \$this->fields=[" . PHP_EOL;
         $string = "static public function initTable(){ " . PHP_EOL . "\t\treturn [" . PHP_EOL;
         $ai = null;
         if ($result) {
             while ($row = $result->fetch_row()) {
                 $type = 'i';
                 //默认为字符串
                 if (strpos($row[5], "auto_increment") !== false) {
                     $ai = $row[0];
                 }
                 if (strpos($row[1], "int") !== false) {
                     $type = "i";
                 } else {
                     if (strpos($row[1], "char") !== false || strpos($row[1], "date") !== false || strpos($row[1], "text") !== false) {
                         $type = "s";
                     } else {
                         if (strpos($row[1], "decimal") !== false || strpos($row[1], "float") !== false || strpos($row[1], "double") !== false) {
                             $type = "d";
                         }
                     }
                 }
                 $string .= "\t\t\t'{$row['0']}'=> ['type' => '{$type}', 'value' => null]," . PHP_EOL;
             }
             mysqli_free_result($result);
         } else {
             echo $table;
         }
         $string .= "\t\t];" . PHP_EOL . "\t}";
         //"\$this->tableName = '$table';" . PHP_EOL . "\$this->AIField = '$ai';" . PHP_EOL . "}";
         $string2 = "static public function AIField(){ " . PHP_EOL . "\t\treturn '{$ai}';" . PHP_EOL . '	}';
         $filename = "../AppMain/data/{$DB}/{$className}.class.php";
         if (file_exists($filename)) {
             unlink($filename);
         }
         $create = true;
         $source = "<?php" . PHP_EOL . 'namespace AppMain\\data\\' . $DB . ';' . PHP_EOL . "class {$className} {" . PHP_EOL . '	' . $string . PHP_EOL . '	' . $string2 . PHP_EOL . "}" . PHP_EOL;
         if (!dirExists(dirname($filename))) {
             die('创建目录失败!');
         }
         if (file_put_contents($filename, $source)) {
             echo '<p>' . $table . ($create ? '生成类成功' : '修改类成功') . '</p>';
         }
     }
 }