测试部分的model

This commit is contained in:
474420502 2024-04-10 17:30:12 +08:00
parent ad3c959586
commit fbef5d56a7
13 changed files with 1497 additions and 622 deletions

View File

@ -9,7 +9,7 @@ import (
)
func TestGenModel(t *testing.T) {
genModel := sql_generator.NewGenModel().WithOpenSqlDriver("mysql", "php:aFk3i4Dj#76!4sd@tcp(47.243.100.6:3306)/zunxinfinance?charset=utf8mb4&timeout=3s")
genModel := sql_generator.NewGenModel().WithOpenSqlDriver("mysql", "zunxinfinance:brTziKHKhsCxTcJmA#2@tcp(192.168.3.99:3307)/zunxinfinance?charset=utf8mb4")
genModel.WithGenFileDir("../model")
genModel.GenWithLogics()
}

View File

@ -1,6 +1,8 @@
package model
import (
"strings"
"gorm.io/gorm"
)
@ -9,3 +11,292 @@ type KillaraCustomerModel struct {
db *gorm.DB
TableName string // 表名
}
func (m *KillaraCustomerModel) InsertCustomer(customer *KillaraCustomer) (uint64, error) {
if err := m.db.Model(&KillaraCustomer{}).Create(customer).Error; err != nil {
return 0, err
}
return *customer.CustomerId, nil
}
func (m *KillaraCustomerModel) UpdateCustomer(customer *KillaraCustomer) error {
return m.db.Model(&KillaraCustomer{}).Where("customer_id = ?", customer.CustomerId).Updates(customer).Error
}
func (m *KillaraCustomerModel) DeleteCustomer(customer *KillaraCustomer) error {
return m.db.Where("customer_id = ?", customer.CustomerId).Delete(&KillaraCustomer{}).Error
}
func (m *KillaraCustomerModel) GetCustomer(customerID uint64) (*KillaraCustomer, error) {
var customer KillaraCustomer
err := m.db.Where("customer_id = ? AND status = 1", customerID).First(&customer).Error
return &customer, err
}
func (m *KillaraCustomerModel) CheckTelephoneExists(telephone string) (bool, error) {
// var count int64
// err := m.db.Model(&KillaraCustomer{}).Where("telephone = ?", telephone).Count(&count).Error
err := m.db.Model(&KillaraCustomer{}).Where("telephone = ?", telephone).First(nil).Error
if err == gorm.ErrRecordNotFound {
return false, nil
}
return err != nil, err
}
func (m *KillaraCustomerModel) CheckEmailExists(email string) (bool, error) {
// var count int64
err := m.db.Model(&KillaraCustomer{}).Where("email = ?", email).First(nil).Error
if err == gorm.ErrRecordNotFound {
return false, nil
}
return err != nil, err
}
func (m *KillaraCustomerModel) GetCustomerByCode(code string) (*KillaraCustomer, error) {
var customer KillaraCustomer
err := m.db.Where("code = ? AND status = 1", code).First(&customer).Error
if err == gorm.ErrRecordNotFound {
return nil, nil
}
return &customer, err
}
func (m *KillaraCustomerModel) GetCustomerByTelephone(telephone string) (*KillaraCustomer, error) {
var customer KillaraCustomer
err := m.db.Where("telephone = ? AND status = 1", telephone).Order("customer_id").First(&customer).Error
if err == gorm.ErrRecordNotFound {
return nil, nil
}
return &customer, err
}
func (m *KillaraCustomerModel) GetCustomerByTelephoneForBackEnd(telephone string) (*KillaraCustomer, error) {
var customer KillaraCustomer
err := m.db.Where("telephone = ?", telephone).First(&customer).Error
if err == gorm.ErrRecordNotFound {
return nil, nil
}
return &customer, err
}
func (m *KillaraCustomerModel) GetCustomerByEmailForBackEnd(email string) (*KillaraCustomer, error) {
var customer KillaraCustomer
err := m.db.Where("email = ?", email).First(&customer).Error
if err == gorm.ErrRecordNotFound {
return nil, nil
}
return &customer, err
}
func (m *KillaraCustomerModel) GetCustomerForBackEnd(customerID uint64) (*KillaraCustomer, error) {
var customer KillaraCustomer
err := m.db.Where("customer_id = ?", customerID).First(&customer).Error
if err == gorm.ErrRecordNotFound {
return nil, nil
}
return &customer, err
}
func (m *KillaraCustomerModel) GetCustomersForBackEndForAutocomplete(data map[string]interface{}) ([]*KillaraCustomer, error) {
var customers []*KillaraCustomer
query := m.db.Model(&KillaraCustomer{})
// 过滤客户 ID
if filterParents, ok := data["filter_parents"]; ok {
if parentIDs, ok := filterParents.([]uint64); ok && len(parentIDs) > 0 {
query = query.Where("customer_id IN (?)", parentIDs)
}
}
// 构建模糊搜索条件
conditions := make([]interface{}, 0)
if filterTelephone, ok := data["filter_telephone"].(string); ok && filterTelephone != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, telephone) > 0", filterTelephone))
}
if filterEmail, ok := data["filter_email"].(string); ok && filterEmail != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, email) > 0", filterEmail))
}
if filterNickname, ok := data["filter_nickname"].(string); ok && filterNickname != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, nickname) > 0", filterNickname))
}
if len(conditions) > 0 {
query = query.Where(strings.Join(make([]string, len(conditions)), " OR "), conditions...)
}
// 排序和分页
query = query.Order("customer_id DESC")
if start, ok := data["start"].(int); ok && start > 0 {
query = query.Offset(start)
}
if limit, ok := data["limit"].(int); ok && limit > 0 {
query = query.Limit(limit)
} else {
query = query.Limit(10)
}
err := query.Find(&customers).Error
if err == gorm.ErrRecordNotFound {
return nil, nil
}
return customers, err
}
func (m *KillaraCustomerModel) GetCustomersForBackEnd(data map[string]interface{}) ([]*KillaraCustomer, error) {
var customers []*KillaraCustomer
query := m.db.Model(&KillaraCustomer{})
conditions := make([]interface{}, 0)
if filterType, ok := data["filter_type"]; ok {
conditions = append(conditions, m.db.Where("`type` = ?", filterType))
}
if filterRealname, ok := data["filter_realname"].(string); ok && filterRealname != "" {
conditions = append(conditions, m.db.Where("`realname` = ?", filterRealname))
}
if filterCode, ok := data["filter_code"].(string); ok && filterCode != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, code) > 0", filterCode))
}
if filterTelephone, ok := data["filter_telephone"].(string); ok && filterTelephone != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, telephone) > 0", filterTelephone))
}
if filterEmail, ok := data["filter_email"].(string); ok && filterEmail != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, email) > 0", filterEmail))
}
if filterNickname, ok := data["filter_nickname"].(string); ok && filterNickname != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, nickname) > 0", filterNickname))
}
if filterName, ok := data["filter_name"].(string); ok && filterName != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, name) > 0", filterName))
}
if filterStatus, ok := data["filter_status"]; ok {
conditions = append(conditions, m.db.Where("`status` = ?", filterStatus))
}
if filterDisableA, ok := data["filter_disable_a"]; ok {
conditions = append(conditions, m.db.Where("`disable_a` = ?", filterDisableA))
}
if filterParentID, ok := data["filter_parent_id"]; ok {
conditions = append(conditions, m.db.Where("`parent_id` = ?", filterParentID))
}
if filterParents, ok := data["filter_parents"]; ok {
if parentIDs, ok := filterParents.([]uint64); ok && len(parentIDs) > 0 {
conditions = append(conditions, m.db.Where("`parent_id` IN (?)", parentIDs))
}
}
if filterInsertDate, ok := data["filter_insert_date"].(string); ok && filterInsertDate != "" {
conditions = append(conditions, m.db.Where("DATE(`insert_date`) = ?", filterInsertDate))
}
if len(conditions) > 0 {
query = query.Where(strings.Join(make([]string, len(conditions)), " AND "), conditions...)
}
if sort, ok := data["sort"].(string); ok && sort != "" {
order := "DESC"
if sortOrder, ok := data["order"].(string); ok {
order = sortOrder
}
query = query.Order(sort + " " + order)
}
if start, ok := data["start"].(int); ok && start > 0 {
query = query.Offset(start)
}
if limit, ok := data["limit"].(int); ok && limit > 0 {
query = query.Limit(limit)
} else {
query = query.Limit(10)
}
err := query.Find(&customers).Error
if err == gorm.ErrRecordNotFound {
return nil, nil
}
return customers, err
}
func (m *KillaraCustomerModel) GetTotalCustomersForBackEnd(data map[string]interface{}) (int64, error) {
var count int64
query := m.db.Model(&KillaraCustomer{})
var conditions []interface{}
if filterType, ok := data["filter_type"]; ok {
conditions = append(conditions, m.db.Where("`type` = ?", filterType))
}
if filterRealname, ok := data["filter_realname"].(string); ok && filterRealname != "" {
conditions = append(conditions, m.db.Where("`realname` = ?", filterRealname))
}
if filterCode, ok := data["filter_code"].(string); ok && filterCode != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, code) > 0", filterCode))
}
if filterTelephone, ok := data["filter_telephone"].(string); ok && filterTelephone != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, telephone) > 0", filterTelephone))
}
if filterEmail, ok := data["filter_email"].(string); ok && filterEmail != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, email) > 0", filterEmail))
}
if filterNickname, ok := data["filter_nickname"].(string); ok && filterNickname != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, nickname) > 0", filterNickname))
}
if filterName, ok := data["filter_name"].(string); ok && filterName != "" {
conditions = append(conditions, m.db.Where("LOCATE(?, name) > 0", filterName))
}
if filterStatus, ok := data["filter_status"]; ok {
conditions = append(conditions, m.db.Where("`status` = ?", filterStatus))
}
if filterDisableA, ok := data["filter_disable_a"]; ok {
conditions = append(conditions, m.db.Where("`disable_a` = ?", filterDisableA))
}
if filterParentID, ok := data["filter_parent_id"]; ok {
conditions = append(conditions, m.db.Where("`parent_id` = ?", filterParentID))
}
if filterParents, ok := data["filter_parents"]; ok {
if parentIDs, ok := filterParents.([]uint64); ok && len(parentIDs) > 0 {
conditions = append(conditions, m.db.Where("`parent_id` IN (?)", parentIDs))
}
}
if filterInsertDate, ok := data["filter_insert_date"].(string); ok && filterInsertDate != "" {
conditions = append(conditions, m.db.Where("DATE(`insert_date`) = ?", filterInsertDate))
}
if len(conditions) > 0 {
query = query.Where(strings.Join(make([]string, len(conditions)), " AND "), conditions...)
}
err := query.Count(&count).Error
if err == gorm.ErrRecordNotFound {
return 0, nil
}
return count, err
}

View File

@ -0,0 +1,11 @@
package model
import (
"gorm.io/gorm"
)
type KillaraStockLocalHistoryModel struct {
// fields ...
db *gorm.DB
TableName string // 表名
}

View File

@ -0,0 +1,11 @@
package model
import (
"gorm.io/gorm"
)
type KillaraStockLocalModel struct {
// fields ...
db *gorm.DB
TableName string // 表名
}

View File

@ -0,0 +1,11 @@
package model
import (
"gorm.io/gorm"
)
type KillaraStockTimeModel struct {
// fields ...
db *gorm.DB
TableName string // 表名
}

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,10 @@ import (
"gorm.io/gorm"
)
func init() {
ModelInit("zunxinfinance:brTziKHKhsCxTcJmA#2@tcp(192.168.3.99:3307)/zunxinfinance?charset=utf8mb4&timeout=10s&parseTime=true")
}
func ModelInit(mysqlDNS string) {
db, err := gorm.Open(mysql.Open(mysqlDNS))
if err != nil {

441
php_model/Customer.php Normal file
View File

@ -0,0 +1,441 @@
<?php
/**
* 用户
*/
class Model_Customer_Customer
{
/**
* 禁止A仓交易12
*/
const DISABLE_A_NO = 2;
const TYPE_2 = 2;
private $_customerTable;
private $_customerDeviceTable;
private $_customerDeviceLogTable;
public $db;
public function __construct()
{
$this->db = \system\engine\Registry::get('db');
$config = \system\engine\Registry::get('config');
$this->_customerTable = $config->database->prefix
. 'customer';
$this->_customerDeviceTable = $config->database->prefix
. 'customer_device';
$this->_customerDeviceLogTable = $config->database->prefix
. 'customer_device_log';
}
public function insertCustomer($data)
{
$this->db->insert($this->_customerTable, $data);
$customer_id = $this->db->lastInsertId();
return $customer_id;
}
public function updateCustomer($customer_id, $data)
{
$where = $this->db->quoteInto('customer_id = ?', $customer_id);
$this->db->update($this->_customerTable, $data, $where);
}
public function deleteCustomer($customer_id)
{
$where = $this->db->quoteInto('customer_id = ?', $customer_id);
$this->db->delete($this->_customerTable, $where);
}
public function getCustomer($customer_id)
{
return $this->db->fetchRow("SELECT * FROM " . $this->_customerTable . ' WHERE status = 1 AND customer_id = ' . $this->db->quote($customer_id));
}
public function insertCustomerDevice($data)
{
$this->db->insert($this->_customerDeviceTable, $data);
}
public function insertCustomerDeviceLog($data)
{
$this->db->insert($this->_customerDeviceLogTable, $data);
}
public function checkTelephoneExists($telephone)
{
$result = $this->db->fetchOne('SELECT customer_id FROM ' . $this->_customerTable
. ' WHERE telephone = ' . $this->db->quote($telephone));
if ($result) {
return TRUE;
} else {
return FALSE;
}
}
public function checkEmailExists($email)
{
$result = $this->db->fetchOne('SELECT customer_id FROM ' . $this->_customerTable
. ' WHERE email = ' . $this->db->quote($email));
if ($result) {
return TRUE;
} else {
return FALSE;
}
}
public function getCustomerByCode($code)
{
return $this->db->fetchRow('SELECT * FROM ' . $this->_customerTable . ' WHERE status = 1 and code = ' . $this->db->quote($code));
}
public function getCustomerByTelephone($telephone)
{
return $this->db->fetchRow('SELECT * FROM ' . $this->_customerTable .
' WHERE status = 1 AND telephone = ' . $this->db->quote($telephone) .
' ORDER BY customer_id');
}
public function lockTable()
{
$this->db->query('LOCK TABLE ' . $this->_customerTable . ' WRITE');
}
public function unLockTable()
{
$this->db->query('UNLOCK TABLES');
}
/*
* 后台使用的方法
*/
public function getTotalCustomersForBackEnd($data)
{
$sql = 'SELECT COUNT(*) AS total FROM ' . $this->_customerTable;
$implode = array();
if (!empty($data['filter_type'])) {
$implode[] = '`type` = ' . $this->db->quote($data['filter_type']);
}
if (!empty($data['filter_realname'])) {
$implode[] = '`realname` = ' . $this->db->quote($data['filter_realname']);
}
if (!empty($data['filter_code'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_code']) . ', code) > 0';
}
if (!empty($data['filter_telephone'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_telephone']) . ', telephone) > 0';
}
if (!empty($data['filter_email'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_email']) . ', email) > 0';
}
if (!empty($data['filter_nickname'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_nickname']) . ', nickname) > 0';
}
if (!empty($data['filter_name'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_name']) . ', name) > 0';
}
if (!empty($data['filter_status'])) {
$implode[] = '`status` = ' . $this->db->quote($data['filter_status']);
}
if (!empty($data['filter_disable_a'])) {
$implode[] = '`disable_a` = ' . $this->db->quote($data['filter_disable_a']);
}
if (!empty($data['filter_parent_id'])) {
$implode[] = '`parent_id` = ' . $this->db->quote($data['filter_parent_id']);
}
if (!empty($data['filter_parent_id'])) {
$implode[] = '`parent_id` = ' . $this->db->quote($data['filter_parent_id']);
}
if (!empty($data['filter_parents']) && count($data['filter_parents']) != 0) {
$implode[] = '`parent_id` IN (' . implode(',', $data['filter_parents']) . ')';
}
if (!empty($data['filter_insert_date'])) {
$implode[] = 'DATE(`insert_date`) = ' . $this->db->quote($data['filter_insert_date']);
}
if (count($implode) != 0) {
$sql .= ' WHERE ' . implode(' AND ', $implode);
}
return $this->db->fetchOne($sql);
}
public function getCustomersForBackEnd($data)
{
$sql = 'SELECT * FROM ' . $this->_customerTable;
$implode = array();
if (!empty($data['filter_type'])) {
$implode[] = '`type` = ' . $this->db->quote($data['filter_type']);
}
if (!empty($data['filter_realname'])) {
$implode[] = '`realname` = ' . $this->db->quote($data['filter_realname']);
}
if (!empty($data['filter_code'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_code']) . ', code) > 0';
}
if (!empty($data['filter_telephone'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_telephone']) . ', telephone) > 0';
}
if (!empty($data['filter_email'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_email']) . ', email) > 0';
}
if (!empty($data['filter_nickname'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_nickname']) . ', nickname) > 0';
}
if (!empty($data['filter_name'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_name']) . ', name) > 0';
}
if (!empty($data['filter_status'])) {
$implode[] = '`status` = ' . $this->db->quote($data['filter_status']);
}
if (!empty($data['filter_disable_a'])) {
$implode[] = '`disable_a` = ' . $this->db->quote($data['filter_disable_a']);
}
if (!empty($data['filter_parent_id'])) {
$implode[] = '`parent_id` = ' . $this->db->quote($data['filter_parent_id']);
}
if (!empty($data['filter_parent_id'])) {
$implode[] = '`parent_id` = ' . $this->db->quote($data['filter_parent_id']);
}
if (!empty($data['filter_parents']) && count($data['filter_parents']) != 0) {
$implode[] = '`parent_id` IN (' . implode(',', $data['filter_parents']) . ')';
}
if (!empty($data['filter_insert_date'])) {
$implode[] = 'DATE(`insert_date`) = ' . $this->db->quote($data['filter_insert_date']);
}
if (count($implode) != 0) {
$sql .= ' WHERE ' . implode(' AND ', $implode);
}
if (!empty($data['sort'])) {
$sql .= ' ORDER BY ' . $data['sort'] . ' ';
if (!empty($data['order'])) {
$sql .= $data['order'];
} else {
$sql .= 'DESC';
}
}
if (!empty($data['start']) || !empty($data['limit'])) {
$sql .= ' LIMIT';
if (!empty($data['start'])) {
$sql .= ' ' . $data['start'] . ',';
}
if (!empty($data['limit'])) {
$sql .= ' ' . $data['limit'];
} else {
$sql .= ' 10';
}
}
return $this->db->fetchAll($sql);
}
public function getCustomerByTelephoneForBackEnd($telephone)
{
return $this->db->fetchRow('SELECT * FROM ' . $this->_customerTable . ' WHERE telephone = ' . $this->db->quote($telephone));
}
public function getCustomerByEmailForBackEnd($email)
{
return $this->db->fetchRow('SELECT * FROM ' . $this->_customerTable . ' WHERE email = ' . $this->db->quote($email));
}
public function getCustomerForBackEnd($customer_id)
{
$sql = "SELECT * FROM " . $this->_customerTable . ' WHERE customer_id = '
. $this->db->quote($customer_id);
return $this->db->fetchRow($sql);
}
public function getCustomersForBackEndForAutocomplete($data)
{
$sql = 'SELECT * FROM ' . $this->_customerTable . ' WHERE 1';
if (!empty($data['filter_parents']) && count($data['filter_parents']) != 0) {
$sql .= ' AND `customer_id` IN (' . implode(',', $data['filter_parents']) . ')';
}
$implode = array();
if (!empty($data['filter_telephone'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_telephone']) . ', telephone) > 0';
}
if (!empty($data['filter_email'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_email']) . ', email) > 0';
}
if (!empty($data['filter_nickname'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_nickname']) . ', nickname) > 0';
}
if (!empty($data['filter_name'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_name']) . ', name) > 0';
}
if (!empty($data['filter_code'])) {
$implode[] = 'LOCATE(' . $this->db->quote($data['filter_code']) . ', code) > 0';
}
if (count($implode) != 0) {
$sql .= ' AND (' . implode(' OR ', $implode) . ')';
}
$sql .= ' ORDER BY';
if (!empty($data['sort'])) {
$sql .= ' ' . $data['sort'];
if (!empty($data['order'])) {
$sql .= ' ' . $data['order'];
}
} else {
$sql .= ' customer_id DESC';
}
if (!empty($data['start']) || !empty($data['limit'])) {
$sql .= ' LIMIT';
if (!empty($data['start'])) {
$sql .= ' ' . $data['start'] . ',';
}
if (!empty($data['limit'])) {
$sql .= ' ' . $data['limit'];
} else {
$sql .= ' 10';
}
}
return $this->db->fetchAll($sql);
}
public function getFullParents($parent_id)
{
$parents = array();
$customer = $this->getCustomer($parent_id);
if ($customer) {
$parents[] = array(
'customer_id' => $customer['customer_id'],
'telephone' => $customer['telephone'],
'name' => $customer['name'],
'nickname' => $customer['nickname'],
'email' => $customer['email'],
);
if (!empty($customer['parent_id'])) {
$temp = $this->getFullParents($customer['parent_id']);
if (count($temp) != 0) {
$parents = array_merge($parents, $temp);
}
}
}
return $parents;
}
public function getFullParentsFromSelf($customer_id)
{
$customer = $this->getCustomer($customer_id);
if ($customer && !empty($customer['parent_id'])) {
$parents = $this->getFullParents($customer['parent_id']);
} else {
$parents = array();
}
return $parents;
}
public function getFullChildren($parent_id)
{
$temp = array();
$children = $this->getCustomersForBackEnd(array(
'filter_parent_id' => $parent_id
));
if (count($children) != 0) {
foreach ($children as $child) {
$temp[] = array(
'customer_id' => $child['customer_id'],
'telephone' => $child['telephone'],
'name' => $child['name'],
'nickname' => $child['nickname'],
);
$temp = array_merge($temp, $this->getFullChildren($child['customer_id']));
}
}
return $temp;
}
public function getFullChildrenWithSelf($customer_id)
{
$customer = $this->getCustomer($customer_id);
$parents = array();
if ($customer) {
$parents[] = array(
'customer_id' => $customer['customer_id'],
'telephone' => $customer['telephone'],
'name' => $customer['name'],
'nickname' => $customer['nickname'],
);
$parents = array_merge($parents, $this->getFullChildren($customer['customer_id']));
}
return $parents;
}
}

View File

@ -7,3 +7,5 @@
3. 链接太长
4. 日志设计不完善。
5. 没事务回滚
6. 电话号码和邮件不是唯一, 帐号表数据可能混乱
7. 表没建索引, 数量上去, 性能立马下降

View File

@ -4,7 +4,6 @@ import (
"log"
"github.com/gin-gonic/gin"
"github.com/iapologizewhenimwrong/Vestmore_GO/model"
"github.com/iapologizewhenimwrong/Vestmore_GO/server/app/internal/handlers/account"
"github.com/iapologizewhenimwrong/Vestmore_GO/server/app/internal/handlers/actions"
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/cors"
@ -27,8 +26,6 @@ func AppV1_0(ctx *gin.Context) {
func main() {
log.SetFlags(log.Llongfile)
model.ModelInit("php:aFk3i4Dj#76!4sd@tcp(47.243.100.6:3306)/zunxinfinance?charset=utf8mb4&timeout=10s")
r := gin.Default()
cors.SetCors(r)

36
test/gorm_test.go Normal file
View File

@ -0,0 +1,36 @@
package vertmore_test
import (
"log"
"testing"
"github.com/iapologizewhenimwrong/Vestmore_GO/model"
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/basic"
)
func TestCaseInsert(t *testing.T) {
c, err := model.Models.KillaraCustomerModel.GetCustomer(1)
if err != nil {
panic(err)
}
log.Printf("%#v", c)
c.CustomerId = nil
c.Email = basic.StringPtr("474420502@qq.com")
model.Models.KillaraCustomerModel.InsertCustomer(c)
}
func TestUpdate(t *testing.T) {
c, err := model.Models.KillaraCustomerModel.GetCustomer(6)
if err != nil {
panic(err)
}
uc := &model.KillaraCustomer{}
uc.CustomerId = c.CustomerId
uc.Email = basic.StringPtr("474420502@gmail.com")
log.Println(model.Models.KillaraCustomerModel.UpdateCustomer(uc))
}
func TestExist(t *testing.T) {
log.Println(model.Models.KillaraCustomerModel.CheckEmailExists("474420502@gmail.com"))
log.Println(model.Models.KillaraCustomerModel.CheckEmailExists("474420502@qq.com"))
}

5
utils/basic/ptr_type.go Normal file
View File

@ -0,0 +1,5 @@
package basic
func StringPtr(src string) *string {
return &src
}

1
utils/vsql/tools.go Normal file
View File

@ -0,0 +1 @@
package vsql