Ejemplo n.º 1
0
Archivo: User.php Proyecto: hejxing/jt
 /**
  * 生成保存的键名
  *
  * @param string $token
  * @return string
  */
 protected static function genSeed($token = null)
 {
     if ($token === null) {
         $token = Helper::uuid();
     }
     self::$token = $token;
     return static::$tokenPrefix . self::$token;
 }
Ejemplo n.º 2
0
Archivo: Model.php Proyecto: hejxing/jt
 /**
  * 生成插入记录用的属性列表
  *
  * @throws \ErrorException
  */
 private function genInsertNames()
 {
     if (!isset($this->sqlCollect['data'])) {
         return;
     }
     $data = $this->sqlCollect['data'];
     $fields = [];
     $this->insertId = null;
     foreach (static::$columns as $name => $column) {
         //将属性名与字段名进行映射
         $field = $name;
         if (isset($column['field'])) {
             //if(isset($data[$column['field']])){
             //	//TODO: 仍使用了字段名,给出警告,应该使用属性
             //	$field = $column['field'];
             //}
             $fields[] = $column['field'];
         } else {
             $fields[] = $field;
         }
         if (!isset($data[$field])) {
             if (isset($column['default'])) {
                 $data[$field] = $column['default'];
             } elseif (isset($column['at'])) {
                 $data[$field] = Bootstrap::$now;
             } elseif ($column['type'] === 'uuid' && isset($column['primary'])) {
                 $data[$field] = \jt\utils\Helper::uuid([], '-');
             } elseif (isset($column['increment'])) {
                 //自增类型
                 \array_pop($fields);
                 continue;
             } elseif (isset($column['require'])) {
                 Error::fatal('InsertToDataBaseRequire', "表 [{$this->table}] 此项 [{$name}] 不允许为空");
             } else {
                 $type = isset($column['type']) ? $column['type'] : '';
                 switch ($type) {
                     case 'numeric':
                         $data[$field] = 0;
                         break;
                     case 'bool':
                         $data[$field] = 0;
                         break;
                     default:
                         $data[$field] = '';
                 }
             }
         }
         if (isset($column['primary'])) {
             $this->insertId = $data[$field];
         }
         $this->data[] = $this->checkData($data[$field], $column, $name);
     }
     //TODO: 记录丢弃的数据
     //TODO: 数据完整性检查
     //TODO: 验证数据
     $placeholders = array_fill(0, count(static::$columns), '?');
     $this->preSql .= ' (' . implode(',', $fields) . ') VALUES (' . implode(',', $placeholders) . ')';
 }