Files
DBService/StoredProcedure/StoredProcedure.cpp
T
2026-07-09 11:27:59 +08:00

1991 lines
58 KiB
C++

#include <stdio.h>
#include "ProCommon.h"
#include "ServerInner.h"
#include "Databases.h"
#include "StoredProcedure.h"
#include "debug.h"
#define MAX_LENGTH 1024
#define MID_LENGTH 128
#define MIN_LENGTH 16
#define DTYPE_STYLETEMP 0
#define DTYPE_STYLEFILE 1
//全局变量
Databases g_DB;
string& replace_all(string& src, const string& old_value, const string& new_value) {
// 每次重新定位起始位置,防止上轮替换后的字符串形成新的old_value
for (string::size_type pos(0); pos != string::npos; pos += new_value.length()) {
if ((pos = src.find(old_value, pos)) != string::npos) {
src.replace(pos, old_value.length(), new_value);
}
else break;
}
return src;
}
void FreeRow( MYSQL_ROW& row, int nCol )
{
for( int i=0; i<nCol; i++ )
delete[] row[i];
delete[] row;
row = NULL;
}
void TruncUTF8( char* buf, int size )
{
if( strlen(buf) < size )
return;
unsigned char* bytes = (unsigned char*)buf;
for( int i=size-2; i>=0; i-- ){
if( bytes[i] <= 0x7F ){ //1字节
bytes[i+1] = 0;
return;
}
else if( bytes[i] >= 0xC0 && bytes[i] <= 0xDF ){ //2字节
if( i+2 < size )
bytes[i+2] = 0;
else
bytes[i] = 0;
return;
}
else if( bytes[i] >= 0xE0 && bytes[i] <= 0xEF ){ //3字节
if( i+3 < size )
bytes[i+3] = 0;
else
bytes[i] = 0;
return;
}
else if( bytes[i] >= 0xF0 && bytes[i] <= 0xF7 ){ //4字节
if( i+4 < size )
bytes[i+4] = 0;
else
bytes[i] = 0;
return;
}
else if( bytes[i] >= 0xF8 && bytes[i] <= 0xFB ){ //5字节
if( i+5 < size )
bytes[i+5] = 0;
else
bytes[i] = 0;
return;
}
else if( bytes[i] >= 0xFC && bytes[i] <= 0xFD ){ //6字节
if( i+6 < size )
bytes[i+6] = 0;
else
bytes[i] = 0;
return;
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//函数名: DB_InitDatabases
//功 能: 初始化数据库
//输 入:
//原型:void DB_InitDatabases()
//返 回: 无
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//INIT_DATABASES
int DB_InitDatabases(char *chHost, char *chUser, char *chPassword)
{
char* database = "music";
printf("主机名:%s\t数据库名:%s",chHost, database);
int ret = g_DB.ConnectDatabases(chHost,chUser,chPassword,database);
// printf("主机名:%s\t用户名:%s\t密码:%s\t数据库名:%s",chHost,chUser,chPassword,"music_man");
// int ret = g_DB.ConnectDatabases(chHost,chUser,chPassword,"music_man");
if( ret != 0 ){
printf("--连接失败!\n");
// OutputDebugString(" --连接失败!\n");
return -1;
}
printf("--连接成功!\n");
// OutputDebugString("--连接成功!\n");
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//函数名: DB_Release
//功 能: 释放资源,关闭数据库连接
//输 入:
//原型:int DB_Release()
//返 回:
//①成功返回0
//②失败返回-1
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//RELEASE
int DB_Release()
{
g_DB.CloseMysql();
// OutputDebugString("已断开连接!\n");
printf("数据库断开连接!\n");
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//--函数名: DB_GetPath
//--功 能: 获取相关目录的绝对路径
//--输 入:
//-/chPathStyle: 调用时定义char[256]用于接收风格路径;
//-/chPathWeb: 调用时定义char[256]用于接收网站路径;
// chPathMusic: 调用时定义char[256]用于接收上传音乐路径;
//--返 回: 成功返回 0 失败 -1
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int DB_GetPath(char *chPathStyle, char *chPathWeb, char* chPathMusic)
{
MYSQL_ROW acceptR = NULL;
if(chPathStyle){
string strCall = "CALL Prc_getPath('style',@path)";
int fNum = g_DB.CallPro(strCall.c_str(),"SELECT @path", &acceptR);
if( fNum<0 )
return -1;
if( acceptR ){
strcpy(chPathStyle,acceptR[0]);
FreeRow( acceptR, fNum );
}
}
if(chPathWeb){
string strCall = "CALL Prc_getPath('web',@path)";
int fNum = g_DB.CallPro(strCall.c_str(),"SELECT @path", &acceptR );
if( fNum<0 )
return -1;
if( acceptR ){
strcpy(chPathWeb,acceptR[0]);
FreeRow( acceptR, fNum );
}
}
if(chPathMusic){
string strCall = "CALL Prc_getPath('music',@path)";
int fNum = g_DB.CallPro(strCall.c_str(),"SELECT @path", &acceptR );
if( fNum<0 )
return -1;
if( acceptR ){
strcpy(chPathMusic,acceptR[0]);
FreeRow( acceptR, fNum );
}
}
return 0;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_CleanVipLog
//--功 能: 清理VIP登录表
//--输 入:
//--返 回: 成功返回 0 失败 -1
//-----------------------------------------------------------------------------------------------------------------------------
int DB_CleanVipLog()
{
string strCall = "CALL Prc_cleanVipLog()";
g_DB.CallPro(strCall.c_str(), NULL, NULL);
// OutputDebugString("--清除VIP LOG!\n");
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//函数名: DB_GetClientUpdataFlag
//功 能: 检查版本更新
//输 入:
// iClientType: Client类型(软件内部编号)
// chCltVersion: Client版本号;
// idDevice: 设备号
//原型:int DB_GetClientUpdataFlag(char*chCltVersion)
//返 回: 如果强制更新,返回0;如果有更新但不是强制更新,返回1;如果是最新版本,返回2;调用失败返回-1;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int DB_GetClientUpdateFlag(int iClientType, TVERSION* clientVersion, char *idDevice)
{
char strCall[4096];
sprintf( strCall,"%s%d,%d,%d,%d,%d%s","CALL Prc_app_getStatus(", iClientType,
clientVersion->majorVersion, clientVersion->minorVersion,
clientVersion->modifyVersion, clientVersion->buildVersion,
",@impose,@idApp)");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,"SELECT @impose,@idApp", &acceptR);
if( fNum<0 )
return -1;
//MYSQL_ROW acceptR = g_DB.GetRecord();
int ret = -1, idApp = 0;
if( acceptR ){
ret = atoi(acceptR[0]);
idApp = atoi(acceptR[1]);
FreeRow( acceptR, fNum );
}
if( ret>=0 ){
sprintf(strCall, "%s%d%s","CALL Prc_statistics_1(", iClientType, ",'mofang_access', 1)");
g_DB.CallPro(strCall, NULL, NULL);
//g_DB.CallPro(strCall.c_str(), "SELECT @ret" );
// if( idApp>0 && (iClientType<=e_Ac_iOS || iClientType==e_Pro_Windows) && strlen(idDevice)>0 ){
// sprintf( strCall, "%s%d,'%s'%s","CALL Prc_app_statistics(", idApp, idDevice, ")" );
// g_DB.CallPro(strCall, NULL, NULL);
// }
}
//1表示强制 0 有更新但不是强制2 已经是最新版本 -1非法版本
switch( ret )
{
case -1:return 3; //非法版本号
case 1: return 2; //强制更新
case 0: return 1; //选择更新
case 2: return 0; //最新版本
}
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//函数名: DB_GetStyleUpdataNumber
//功 能: 更新的表单个数
//输 入:
// chCltTime 客户端上次更新时间
// UpdataNum 最新更新时间
//返 回: 成功0,失败返回-1
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//GET_LIST_NUM
int DB_GetStyleUpdateNumber(int chCltTime, int *UpdataNum)
{
char strCall[4096];
sprintf( strCall, "%s%d%s","CALL Prc_getNewStyleTotal(",chCltTime,",@new_style_total)");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,"SELECT @new_style_total", &acceptR);
if( fNum<0 )
return -1;
if( acceptR ){
*UpdataNum = atoi(acceptR[0]);
FreeRow( acceptR, fNum );
}
return 0;
}
//-----------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_PhoneCheck
//--功 能: 短信验证
//--输 入:
// idDevice: 设备号
// strPhone: 手机号
// strCode: 验证码
//--返 回: 成功返回0;验证失败返回1;函数调用失败返回 -1
//------------------------------------------------------------------------------------------------------------------------------
int DB_PhoneCheck( char* idDevice, char* strPhone, char* strCode )
{
char strCall[4096];
sprintf( strCall,"%s'%s','%s','%s'%s","CALL Prc_user_checkPhone(",idDevice,strPhone,strCode,",@ret)");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,"SELECT @ret", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int ret = 0;
if( acceptR[0][0]=='1' ){
ret = 1;
}
FreeRow( acceptR, fNum );
return ret;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//--函数名: DB_Register
//--功 能: 软件用户注册
//--输 入:
//-/user:用户名
//-/password:密码
// isEmailOrMobile 捆绑邮箱或手机号 1=邮箱 2=手机号
// idUser 用户ID
// 返回strNickName用户昵称
// iClientType 客户端类型
//--返 回: 成功返回0;用户名已存在返回1;函数调用失败返回 -1;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int DB_Register(char *user, char *password, int isEmailOrMobile, int& idUser, char* strNickName, int iClientType)
{
char strCall[4096];
MYSQL_ROW acceptR = NULL;
sprintf( strCall, "%s%s','%s',%d%s","CALL Prc_user_register('", user, password, isEmailOrMobile, ",@iduser,@nickname)" );
int fNum = g_DB.CallPro(strCall,"SELECT @iduser,@nickname", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int ret = 0;
idUser = atoi( acceptR[0] );
//用户名已存在
if( idUser==0 ){
ret = 1;
}
else{
strcpy( strNickName, acceptR[1] );
sprintf( strCall, "%s%d%s","CALL Prc_statistics_1(", iClientType, ",'register', 1)");
g_DB.CallPro(strCall, NULL, NULL);
sprintf( strCall, "%s%d%s","CALL Prc_statistics_1(", iClientType, ",'login_usersum', 1)");
g_DB.CallPro(strCall, NULL, NULL);
sprintf( strCall, "%s%d%s","CALL Prc_statistics_1(", iClientType, ",'login', 1)");
g_DB.CallPro(strCall, NULL, NULL);
}
FreeRow( acceptR, fNum );
return ret;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//函数名: DB_Login
//功 能: 登陆验证
//输 入:
//-/user:用户名
//-/password:密码
// idDevice: 设备号
//-/chUserMsg:接收帐户信息
// strNickName用户昵称
// strIconFile:用户头像文件名
// iClientType 客户端类型
//返 回: 成功0,失败返回-1
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int DB_Login(char *user, char *password, char *idDevice, TACCOUNTINFO *stUserMsg,
char* strNickName, char* strIconFile, int iClientType )
{
char strCall[4096];
sprintf( strCall, "%s'%s','%s','%s'%s","CALL Prc_user_getInfo(",user,password,idDevice,",@login,@UserInfo,@TodayLogged)");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,"SELECT @login,@UserInfo,@TodayLogged", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int ret = 0;
//帐号不存在
if(acceptR[0][0]=='0'){
ret = 2;
}//密码错误
else if(acceptR[0][0]=='3'){
ret = 1;
}//设备超限
else if(acceptR[0][0]=='4'){
ret = 3;
}//账户已删除
else if(acceptR[0][0]=='2'){
ret = 4;
}//账户已冻结
else if(acceptR[0][0]=='5'){
ret = 5;
}
if( ret!=0 ){
FreeRow( acceptR, fNum );
return ret;
}
int n = 0;
char *tokenPtr=strtok(acceptR[1],"|");
while(tokenPtr!=NULL)
{//循环去块
n++;
switch(n)
{
case 1:stUserMsg->ID = atoi(tokenPtr);
break;
case 3:stUserMsg->balance = atoi(tokenPtr);
break;
case 4:stUserMsg->authority = atoi(tokenPtr);
break;
case 6: stUserMsg->vipPeriod = atoi(tokenPtr);
break;
case 2:
if(strNickName && ( strlen(tokenPtr)>1 || tokenPtr[0]!=' ' ) ){
strcpy( strNickName, tokenPtr );
}
break;
case 5:
if( strIconFile && ( strlen(tokenPtr)>0 ) ){
strcpy( strIconFile, tokenPtr );
}
break;
default:
break;
}
tokenPtr=strtok(NULL,"|");
}
//int TodayLogged = atoi(acceptR[2]);
if( acceptR[2][0]=='0' ){
sprintf( strCall, "%s%d%s","CALL Prc_statistics_1(", iClientType, ",'login_usersum', 1)");
g_DB.CallPro(strCall, NULL, NULL);
}
sprintf( strCall, "%s%d%s","CALL Prc_statistics_1(", iClientType, ",'login', 1)");
g_DB.CallPro(strCall, NULL, NULL);
FreeRow( acceptR, fNum );
return 0;
}
//-----------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_Logoff
//--功 能: 用户注销
//--输 入:
//-/idUser:用户号
// idDevice: 设备号
//--返 回: 成功返回0
//------------------------------------------------------------------------------------------------------------------------------
int DB_Logoff( int idUser, char *idDevice )
{
char strCall[4096];
sprintf( strCall, "%s%d,'%s'%s","CALL Prc_user_logoff(", idUser, idDevice,")");
g_DB.CallPro(strCall, NULL, NULL);
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//函数名: DB_Verify
//功 能: 保存鉴权
//输 入:
//原 型: int DB_Verify(int nUserID, int dwStyleID[],int nStyleID,double dStyleOriginPrice[],double dStyleCurrentPrice[], double *dBalance);
//返 回: 成功0,失败返回-1
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//USER_SAVED
int DB_Verify(int nUserID, int dwStyleID[],int nStyleID,int aStyleOriginCost[],int aStyleCurrentCost[], int *pBalance)
{
char strCall[4096];
sprintf( strCall, "%s%d%s","CALL Prc_getUserBalance(",nUserID,",@user_balance)");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,"SELECT @user_balance", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int ret = 0;
if(!strcmp(acceptR[0],"-1"))
ret = 2;
else
*pBalance = atoi(acceptR[0]);
FreeRow( acceptR, fNum );
if( ret!=0 )
return ret;
for( int i = 0; i < nStyleID; i++ ) {
//strCall.Format("%s%d%s", "CALL prc_style_getCost(", dwStyleID[i], ",0,@style_cost)");
sprintf( strCall, "%s%d,%d,%s","CALL prc_style_getCost(", dwStyleID[i], nUserID, "0,@style_cost)");
fNum = g_DB.CallPro(strCall,"SELECT @style_cost", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int cost = atoi(acceptR[0]);
if( cost<0 ){//风格无效
aStyleOriginCost[i] = aStyleCurrentCost[i] = -1;
}
else{
aStyleOriginCost[i] = aStyleCurrentCost[i] = cost;
sprintf( strCall, "%s%d%s","CALL Prc_statistics_1(", 0, ",'accompany_use', 1)");
g_DB.CallPro(strCall, NULL, NULL);
}
FreeRow( acceptR, fNum );
}
//检查无效的风格ID
for(int i = 0; i < nStyleID; i++){
if( (int)(aStyleOriginCost[i])== -1 )
return 3;
}
//计算本次交易总价
int nTotal = 0;
for(int i = 0; i < nStyleID; i++){
nTotal += aStyleCurrentCost[i];
}
//余额不足
if(nTotal > *pBalance){
return 1;
}
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//函数名: DB_Purchase
//功 能: 购买支付
//输 入:
//原 型: int DB_Purchase(char*user,char*password, int a[],int num, double *dBalance, int iapType)
//返 回: 成功0,失败返回-1
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int DB_Purchase(int nUserID, int dwStyleID[],int nStyleID, int *pBalance, int iapType)
{
char strCall[4096];
MYSQL_ROW acceptR = NULL;
if( iapType==0 ){
//验证用户取得余额
sprintf( strCall, "%s%d%s","CALL Prc_getUserBalance(",nUserID,",@user_balance)");
int fNum = g_DB.CallPro(strCall,"SELECT @user_balance", &acceptR );
if( fNum<0 || !acceptR )
return -1;
//MYSQL_ROW acceptR = g_DB.GetRecord();
int ret = 0;
int nUserBlance = -1;
if(!strcmp(acceptR[0],"-1"))
ret = 2;
else
nUserBlance = atoi(acceptR[0]);
FreeRow( acceptR, fNum );
if( ret!=0 )
return ret;
//计算交易总价
int ntol = 0;
for(int i = 0; i < nStyleID; i++)
{
sprintf( strCall, "%s%d,%d,%s","CALL prc_style_getCost(", dwStyleID[i], nUserID, "1,@style_cost)");
fNum = g_DB.CallPro(strCall,"SELECT @style_cost", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int cost = atoi(acceptR[0]);
if( cost<0 ){//风格无效
ret = 3;
}
else{
ntol += cost;
}
FreeRow( acceptR, fNum );
if( ret!=0 )
return ret;
}
//余额不足,返回
if(ntol > nUserBlance){
return 1;
}
else{
sprintf( strCall, "%s%d,%d%s","CALL Prc_user_confirmPayment(", nUserID, ntol, ",@balance)");
fNum = g_DB.CallPro(strCall, "SELECT @balance", &acceptR );
if( fNum<0 || !acceptR )
return -1;
int balance = atoi(acceptR[0]);
if( balance==-1 )
ret = 1;
else if( balance==-2 )
ret = 2;
else
*pBalance = balance;
FreeRow( acceptR, fNum );
if( ret!=0 )
return ret;
}
}
return 0;
}
int DB_GetClientTypeNumber()
{
string strCall = "CALL Prc_getClientNumber(@ver_total)";
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall.c_str(),"SELECT @ver_total", &acceptR);
if( fNum<0 )
return -1;
int ret = 0;
if( acceptR ){
ret = atoi(acceptR[0]);
FreeRow( acceptR, fNum );
}
return ret;
}
int DB_GetClientVersion(TCLIENTVERSION aVersion[], int nArraySize)
{
string strCall = "CALL Prc_getClientVersions(@ver_total,@ver_msg)";
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall.c_str(),"SELECT @ver_total,@ver_msg", &acceptR);
if( fNum<0 || !acceptR )
return -1;
nArraySize = atoi(acceptR[0]);
char *tokenPtr=strtok(acceptR[1],"|");
char chCT[MIN_LENGTH];
char chMV[MIN_LENGTH];
char chNV[MIN_LENGTH];
char chDV[MIN_LENGTH];
char chBV[MIN_LENGTH];
char chFS[MIN_LENGTH];
char chTD[MIN_LENGTH];
char chDN[MAX_LENGTH];
int nAcml = 0;
while(tokenPtr!=NULL)
{//循环去块
sscanf(tokenPtr,"%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],",
chCT,chMV,chNV,chDV,chBV,chFS,chTD,chDN);
int nMajVer=atoi(chMV), nMinVer=atoi(chNV), nModVer=atoi(chDV), nBuiVer=atoi(chBV);
aVersion[nAcml].iClientType = atoi(chCT);
aVersion[nAcml].swInfo.version.majorVersion = nMajVer;
aVersion[nAcml].swInfo.version.minorVersion = nMinVer;
aVersion[nAcml].swInfo.version.modifyVersion = nModVer;
aVersion[nAcml].swInfo.version.buildVersion = nBuiVer;
aVersion[nAcml].swInfo.nFileSize = atoi(chFS);
int year, month, day;
sscanf( chTD, "%d-%d-%d", &year, &month, &day );
aVersion[nAcml].swInfo.tIssueDate =MAKELONG( MAKEWORD(day, month), year );
sprintf( aVersion[nAcml].swInfo.strDescribe,
"Latest Version\n%s\n[%d.%d.%d.%d] - %d.%d.%d\n%s\n%s\n",
"----------------------------------------------------------",
nMajVer,nMinVer,nModVer,nBuiVer, year, month, day,
"----------------------------------------------------------",
chDN );
tokenPtr=strtok(NULL,"|");
nAcml++;
if(nArraySize == nAcml)
break;
}
FreeRow( acceptR, fNum );
return 0;
}
//------------------------------------------
//--函数名: DB_InsertStyle
//--功 能: 新增风格数据
//--输 入:
// iType 新增类型,0=待审核,1=发布
// pInfo 风格信息
//--返回:成功返回风格ID,失败返回-1
int DB_InsertStyle(int iType, TMAKESTYLEINFO* pInfo )
{
int ret = 0, state=0, score=0;
if( iType==DTYPE_STYLEFILE ){
state = 1;
score = 800;
}
char strCall[4096];
sprintf( strCall, "%s(%d,'%s','%s',%d,'%s',%d,%d,%d,%d,%d,%d,%s)",
"CALL Prc_style_addInfo",
state, pInfo->detail.strStyleName, pInfo->detail.strDescription, pInfo->detail.idAuthor, pInfo->detail.strAuthor,
pInfo->detail.iTimesignature, pInfo->detail.iTempo, pInfo->price, pInfo->cost, score, state,
"@insertId");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,"SELECT @insertId", &acceptR);
if( fNum<0 )
return -1;
if( acceptR ){
ret = atoi( acceptR[0] );
FreeRow( acceptR, fNum );
}
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_InsertShareStyle
//--功 能: 新增分享风格数据
//--输 入:
// pInfo 风格信息
//--返回:成功返回风格ID,失败返回-1
//------------------------------------------------------------------------------------------------------------------------------
int DB_InsertShareStyle( TSTYLESHARE* pInfo )
{
int ret = 0;
char strCall[4096];
sprintf( strCall, "%s('%s','%s',%d,'%s',%d,%d,%d,%s)",
"CALL Prc_style_addShare",
pInfo->strStyleName, pInfo->strDescription, pInfo->idAuthor, pInfo->strAuthor,
pInfo->iTimesignature, pInfo->iTempo, pInfo->score, "@insertId");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,"SELECT @insertId", &acceptR);
if( fNum<0 )
return -1;
if( acceptR ){
ret = atoi( acceptR[0] );
FreeRow( acceptR, fNum );
}
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_UpdateStyle
//--功 能: 修改风格数据
//--输 入:
//--pStyleInfo 风格信息
//--返回:成功返回0,失败返回-1
//------------------------------------------------------------------------------------------------------------------------------
int DB_UpdateStyle( UINT idStyle, TMAKESTYLEINFO* pInfo )
{
int ret = 0;
string strType, strIntroBars, strEndingBars, strRecomChords,
strTracks[4];
char buf[20];
for( int i=0; i<sizeof(pInfo->detail.type) && pInfo->detail.type[i]>=0; i++ ){
if( i>0 ){
strType += ",";
}
sprintf(buf, "%d", pInfo->detail.type[i]);
strType += buf;//itoa( pInfo->detail.type[i], buf, 10 );
}
for( int i=0; i<sizeof(pInfo->detail.aIntroBars) && pInfo->detail.aIntroBars[i]>0; i++ ){
if( i>0 ){
strIntroBars += ",";
}
sprintf(buf, "%d", pInfo->detail.aIntroBars[i]);
strIntroBars += buf;//itoa( pInfo->detail.aIntroBars[i], buf, 10 );
}
for( int i=0; i<sizeof(pInfo->detail.aEndingBars) && pInfo->detail.aEndingBars[i]>0; i++ ){
if( i>0 ){
strEndingBars += ",";
}
sprintf(buf, "%d", pInfo->detail.aEndingBars[i]);
strEndingBars += buf;//itoa( pInfo->detail.aEndingBars[i], buf, 10 );
}
for( int i=0; i<sizeof(pInfo->detail.chordRecom) && pInfo->detail.chordRecom[i]>=0; i++ ){
if( i>0 ){
strRecomChords += ",";
}
sprintf(buf, "%d", pInfo->detail.chordRecom[i]);
strRecomChords += buf;//itoa( pInfo->detail.chordRecom[i], buf, 10 );
}
/*
for( s=0; s<4; s++ ){
for( i=0; i<8; i++ ){
if( i>0 ){
strProgs[s] += ";";
}
for( int j=0; j<3 && pInfo->detail.progs[s][i][j]>=0; j++ ){
if( j>0 ){
strProgs[s] += ",";
}
strProgs[s] += itoa( pInfo->detail.progs[s][i][j], buf, 10 );
}
}
}
*/
for( int s=0; s<4; s++ ){
for( int i=0; i<8; i++ ){
if( i>0 ){
strTracks[s] += ";";
}
for( int j=0; j<16 && pInfo->detail.tracks[s][i][j].no>=0; j++ ){
if( j>0 ){
strTracks[s] += ",";
}
sprintf( buf, "%01X%02X%02X", pInfo->detail.tracks[s][i][j].no,
pInfo->detail.tracks[s][i][j].prog,
pInfo->detail.tracks[s][i][j].vol );
strTracks[s] += buf;
}
}
}
char strCall[8192];
sprintf( strCall, "%s(%d,'%s','%s','%s','%s','%s','%s','%s','%s',%s)",
"CALL Prc_style_updateInfo", idStyle, strType.c_str(), strIntroBars.c_str(), strEndingBars.c_str(),
strRecomChords.c_str(), strTracks[0].c_str(), strTracks[1].c_str(), strTracks[2].c_str(), strTracks[3].c_str(),
"@ret");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,"SELECT @ret", &acceptR);
if( fNum<0 )
return -1;
if( acceptR ){
ret = atoi( acceptR[0] );
FreeRow( acceptR, fNum );
}
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_GetStyleUpdataList
//--功 能: 获取风格更新数目
//--输 入:
//iClientType: 客户端类型,<3为伴奏魔方,4=Checker
//tUpdateDate: 更新时间点,如"2012-02-01" (高16位表示年 接下来饿8位表示月 低8位表示日),返回最新更新时间
//UpdataNum:调用时定义 int 变量 用于接收检测到的更新总数
//aUpdate: 返回的列表数据,内部分配,外部释放
//--返 回: 成功返回0; 失败返回-1;
//------------------------------------------------------------------------------------------------------------------------------
int DB_GetStyleUpdateList(int iClientType, int* tUpdateDate, int *nListSize, TSTYLEUPDATE0 aUpdate[] )
{
int fNum = -1;
MYSQL_ROW acceptR = NULL;
// CString strCall, strProc, strDate, strList;
char strCall[4096];
if( iClientType!=e_SM_Checker ){
sprintf( strCall, "%s(%d,%s)", "CALL Prc_style_getUpdateList", *tUpdateDate, //strDate,
"@list_size, @last_date, @style_list" );
fNum = g_DB.CallPro(strCall, "SELECT @list_size, @last_date, @style_list", &acceptR);
}
else{
sprintf( strCall, "%s(%s)", "CALL Prc_getStyleTempList", "@size, @list" );
fNum = g_DB.CallPro(strCall, "SELECT @size, @list", &acceptR);
}
if( fNum<0 )
return -1;
int ind = 0;
int nSize = 0;
if( acceptR ){
nSize = atoi(acceptR[ind++]);
if( iClientType!=e_SM_Checker ){
*tUpdateDate = atoi(acceptR[ind++]);
}
if( nSize>0 ){
char *tokenPtr=strtok(acceptR[ind],"|");
int i=0;
while( tokenPtr != NULL && i<*nListSize ){
int id, price, cost, score;
sscanf( tokenPtr, "%d,%d,%d,%d", &id, &price, &cost, &score );
aUpdate[i].idStyle = id;
aUpdate[i].price = 0;
aUpdate[i].cost = cost;
aUpdate[i].score = score;
tokenPtr = strtok( NULL, "|" );
i++;
}
}
FreeRow( acceptR, fNum );
}
*nListSize = nSize;
return 0;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_GetStyleUpdataListNew
//--功 能: 获取风格更新数目
//--输 入:
//tUpdateDate: 更新时间点,如"2012-02-01" (高16位表示年 接下来饿8位表示月 低8位表示日),返回最新更新时间
//UpdataNum:调用时定义 int 变量 用于接收检测到的更新总数
//aUpdate: 返回的列表数据,内部分配,外部释放
//--返 回: 成功返回0; 失败返回-1;
//------------------------------------------------------------------------------------------------------------------------------
int DB_GetStyleUpdateListNew(int* tUpdateDate, int *nListSize, TSTYLEUPDATE aUpdate[] )
{
int fNum = -1;
MYSQL_ROW acceptR = NULL;
// CString strCall, strProc, strDate, strList;
char strCall[4096];
sprintf( strCall, "%s(%d,%s)", "CALL Prc_style_getUpdateList", *tUpdateDate, "@list_size, @last_date, @style_list" );
fNum = g_DB.CallPro(strCall, "SELECT @list_size, @last_date, @style_list", &acceptR);
if( fNum<0 )
return -1;
int ind = 0;
int nSize = 0;
if( acceptR ){
nSize = atoi(acceptR[ind++]);
*tUpdateDate = atoi(acceptR[ind++]);
if( nSize>0 ){
char *tokenPtr=strtok(acceptR[ind],"|");
int i=0;
while( tokenPtr != NULL && i<*nListSize ){
int id, paid, cost, score;
sscanf( tokenPtr, "%d,%d,%d,%d", &id, &paid, &cost, &score );
aUpdate[i].idStyle = id;
aUpdate[i].paid = paid;
aUpdate[i].cost = cost;
aUpdate[i].score = score;
tokenPtr = strtok( NULL, "|" );
i++;
}
nSize = i;
}
FreeRow( acceptR, fNum );
}
*nListSize = nSize;
return 0;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_GetShareUpdataList
//--功 能: 获取分享风格更新数目
//--输 入:
//tUpdateDate: 更新时间点,如"2012-02-01" (高16位表示年 接下来饿8位表示月 低8位表示日),返回最新更新时间
//UpdataNum:调用时定义 int 变量 用于接收检测到的更新总数
//aUpdate: 返回的列表数据,内部分配,外部释放
//--返 回: 成功返回0; 失败返回-1;
//------------------------------------------------------------------------------------------------------------------------------
int DB_GetShareUpdateList(int* tUpdateDate, int *nListSize, TSHAREUPDATE aUpdate[] )
{
int fNum = -1;
MYSQL_ROW acceptR = NULL;
// CString strCall, strProc, strDate, strList;
char strCall[4096];
sprintf( strCall, "%s(%d,%s)", "CALL Prc_style_getShareUpdateList", *tUpdateDate, //strDate,
"@list_size, @last_date, @style_list" );
fNum = g_DB.CallPro(strCall, "SELECT @list_size, @last_date, @style_list", &acceptR);
if( fNum<0 )
return -1;
int ind = 0;
int nSize = 0;
if( acceptR ){
nSize = atoi(acceptR[ind++]);
*tUpdateDate = atoi(acceptR[ind++]);
if( nSize>0 ){
char *tokenPtr=strtok(acceptR[ind],"|");
int i=0;
while( tokenPtr != NULL && i<*nListSize ){
int id, score;
sscanf( tokenPtr, "%d,%d", &id, &score );
aUpdate[i].idStyle = id;
aUpdate[i].score = score;
tokenPtr = strtok( NULL, "|" );
i++;
}
nSize = i;
}
FreeRow( acceptR, fNum );
}
*nListSize = nSize;
return 0;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_GetCheckUpdateList
//--功 能: 获取待审核风格更新数目
//--输 入:
//tUpdateDate: 更新时间点,如"2012-02-01" (高16位表示年 接下来饿8位表示月 低8位表示日),返回最新更新时间
//UpdataNum:调用时定义 int 变量 用于接收检测到的更新总数
//aUpdate: 返回的列表数据,内部分配,外部释放
//--返 回: 成功返回0; 失败返回-1;
//------------------------------------------------------------------------------------------------------------------------------
int DB_GetCheckUpdateList(int* tUpdateDate, int *nListSize, TCHECKUPDATE aUpdate[] )
{
int fNum = -1;
MYSQL_ROW acceptR = NULL;
// CString strCall, strProc, strDate, strList;
char strCall[4096];
sprintf( strCall, "%s(%d,%s)", "CALL Prc_style_getCheckUpdateList", *tUpdateDate, "@list_size, @last_date, @style_list" );
fNum = g_DB.CallPro(strCall, "SELECT @list_size, @last_date, @style_list", &acceptR);
if( fNum<0 )
return -1;
int ind = 0;
int nSize = 0;
if( acceptR ){
nSize = atoi(acceptR[ind++]);
*tUpdateDate = atoi(acceptR[ind++]);
if( nSize>0 ){
char *tokenPtr=strtok(acceptR[ind],"|");
int i=0;
while( tokenPtr != NULL && i<*nListSize ){
int id, cost;
sscanf( tokenPtr, "%d,%d", &id, &cost );
aUpdate[i].idStyle = id;
aUpdate[i].cost = cost;
tokenPtr = strtok( NULL, "|" );
i++;
}
nSize = i;
}
FreeRow( acceptR, fNum );
}
*nListSize = nSize;
return 0;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_CheckStyleInfo
//--功 能: 确认风格信息有效性
//--输 入:
//iType: 风格类型 1=发布风格 2=临时风格 3=共享风格
//idStyle: 风格ID
//--返 回: 成功返回0; 失败返回-1;无效返回 -2
//------------------------------------------------------------------------------------------------------------------------------
int DB_CheckStyleInfo(int iType, int idStyle )
{
if( idStyle==0 ){
return -2;
}
char strCall[4096];
sprintf( strCall, "%s(%d, %d, %s)", "CALL Prc_style_checkInfo", iType, idStyle, "@state" );
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall, "SELECT @state", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int ret = atoi( acceptR[0] );
FreeRow( acceptR, fNum );
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_GetStyleInfoNew
//--功 能: 获取风格信息
//--输 入:
//iClientType: 客户端类型,<3为伴奏魔方,4=Checker
//idStyle: 风格ID
//pInfo:返回风格信息
//--返 回: 成功返回0; 失败返回-1; 无效的ID -2
//------------------------------------------------------------------------------------------------------------------------------
int DB_GetStyleInfoNew(int iClientType, int idStyle, TSTYLEDETAIL* pInfo )
{
int iTable = iClientType==e_SM_Checker ? 0 : 1;
char strCall[4096];
sprintf( strCall, "%s(%d, %d, %s)", "CALL Prc_style_getInfoNew", iTable, idStyle,
"@State, @StyleName, @SDescription, @AuthorID, @AuthorName, @Timesignature, @Tempo, @Type, @VarNum, @FillNum, @IntroNum, @EndingNum, @IntroBars, @EndingBars, @VarTrack, @FillTrack, @IntroTrack, @EndingTrack" );
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,
"SELECT @State, @StyleName, @SDescription, @AuthorID, @AuthorName, @Timesignature, @Tempo, @Type, @VarNum, @FillNum, @IntroNum, @EndingNum, @IntroBars, @EndingBars, @VarTrack, @FillTrack, @IntroTrack, @EndingTrack",
&acceptR);
if( fNum<0 || !acceptR )
return -1;
int ret = 0,
state = atoi(acceptR[0]);
if( iTable==0 && state!=0 || iTable==1 && state!=1 ){
ret = -2;
}
else if( pInfo ){
strcpy( pInfo->strStyleName, acceptR[1] );
strcpy( pInfo->strDescription, acceptR[2] );
pInfo->idAuthor = atoi( acceptR[3] );
strcpy( pInfo->strAuthor, acceptR[4] );
pInfo->iTimesignature = atoi( acceptR[5] );
pInfo->iTempo = atoi( acceptR[6] );
int i;
char *tokenPtr=NULL;
tokenPtr=strtok(acceptR[7],",");
for( i=0; tokenPtr!=NULL; i++ ){
pInfo->type[i] = atoi( tokenPtr );
tokenPtr = strtok( NULL, "," );
}
for( i=0; i<4; i++ ){
pInfo->nSegNum[i] = atoi( acceptR[8+i] );
}
tokenPtr=strtok(acceptR[12],",");
for( i=0; tokenPtr!=NULL; i++ ){
pInfo->aIntroBars[i] = atoi( tokenPtr );
tokenPtr = strtok( NULL, "," );
}
tokenPtr=strtok(acceptR[13],",");
for( i=0; tokenPtr!=NULL; i++ ){
pInfo->aEndingBars[i] = atoi( tokenPtr );
tokenPtr = strtok( NULL, "," );
}
for( int s=0; s<4; s++ ){
char strTracks[8][256];
int num = 0;
tokenPtr=strtok(acceptR[14+s],";");
while( tokenPtr!=NULL ){
strcpy( strTracks[num++], tokenPtr );
tokenPtr = strtok( NULL, ";" );
}
int nMaj = pInfo->nSegNum[s] & 0x0F;
for( i=0; i<num; i++ ){
int sn = i;
if( s>=2 && i>=nMaj ){
sn = i - nMaj + 4;
}
char *tkn2 = strtok( strTracks[i], "," );
for( int j=0; tkn2!=NULL; j++ ){
int no, prog, vol;
sscanf( tkn2, "%1X%2X%2X", &no, &prog, &vol );
pInfo->tracks[s][sn][j].no = no;
pInfo->tracks[s][sn][j].prog = prog;
pInfo->tracks[s][sn][j].vol = vol;
tkn2 = strtok(NULL, ",");
}
}
}
}
FreeRow( acceptR, fNum );
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_GetRecomStyleIDs
//--功 能: 获取推荐风格ID列表
//--输 入:
//idCount:调用时定义 int 变量 用于接收检测到的id总数
//lstID:返回的列表数据,外部分配,外部释放
//--返 回: 成功返回0; 失败返回-1;
//------------------------------------------------------------------------------------------------------------------------------
int DB_GetRecomStyleIDs( int* idCount, int lstID[] )
{
MYSQL_ROW acceptR = NULL;
char strCall[4096];
sprintf( strCall, "%s(%s)", "CALL Prc_getStyleRecomList", "@list" );
int fNum = g_DB.CallPro(strCall, "SELECT @list", &acceptR);
if( fNum<0 )
return -1;
//MYSQL_ROW acceptR = g_DB.GetRecord();
int nSize = 0;
if( acceptR ){
char *tokenPtr=strtok(acceptR[0],",");
while( tokenPtr != NULL && nSize<*idCount ){
int id = atoi( tokenPtr );
lstID[nSize++] = id;
tokenPtr = strtok( NULL, "," );
}
FreeRow( acceptR, fNum );
}
*idCount = nSize;
return 0;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_CheckUserAuthority
//--功 能: 获取用户权限
//--输 入:
//idUser:用户ID
//anthority:查询权限 0=上传歌曲
//--返 回: 无权限返回0; 失败返回-1;有权限返回非零值
//------------------------------------------------------------------------------------------------------------------------------
int DB_CheckUserAuthority( int idUser, int authority )
{
char strCall[4096];
sprintf( strCall, "%s(%d,%d,%s)", "CALL Prc_user_checkAuthority", idUser, authority,"@result" );
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall, "SELECT @result", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int ret = atoi( acceptR[0] );
FreeRow( acceptR, fNum );
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_SetStyleCheck
//--功 能: 设置风格审核结果
//--输 入:
// idChecker: 审核者ID
// idStyle: 临时风格ID
// score: 评分 0=未通过
// strMsg: 审核信息,审核通过时忽略
//--返 回: 成功返回发布风格ID,失败返回-1,已审核返回-2
//------------------------------------------------------------------------------------------------------------------------------
int DB_SetStyleCheck( int idUser, int idStyle, int score, char* strMsg )
{
char strCall[4096];
sprintf( strCall, "%s(%d,%d,%d,'%s',%s)", "CALL Prc_style_setCheck", idStyle, idUser, score, strMsg, "@result" );
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall, "SELECT @result", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int ret = atoi( acceptR[0] );
FreeRow( acceptR, fNum );
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_GetCommonQnA
//--功 能: 查询常见问题
//--输 入:
// dtUpdate 最后更新时间
// listSize 输入问题个数
// listQA 返回问题数组
//--返 回: 成功返回问题个数,失败返回-1
//------------------------------------------------------------------------------------------------------------------------------
int DB_GetCommonQnA( int dtUpdate, int nListSize, TQNAITEM listQA[] )
{
MYSQL_ROW acceptR = NULL;
char strCall[4096];
sprintf( strCall, "%s(%d,%s)", "CALL Prc_qa_getCommonList", dtUpdate, "@list" );
int fNum = g_DB.CallPro(strCall, "SELECT @list", &acceptR);
if( fNum<0 )
return -1;
//MYSQL_ROW acceptR = g_DB.GetRecord();
int nSize = 0, lstID[1000], nRetSize = nListSize;
if( acceptR ){
char *tokenPtr=strtok(acceptR[0],",");
while( tokenPtr != NULL ){
int id = atoi( tokenPtr );
lstID[nSize++] = id;
tokenPtr = strtok( NULL, "," );
}
FreeRow( acceptR, fNum );
}
for( int i=0; i<nSize; i++ ){
sprintf( strCall, "%s(%d, %d, %s)", "CALL Prc_qa_getItem", lstID[i], dtUpdate,
"@idUser, @iClient, @iState, @dtUpdate, @sQuestion, @sAnswer" );
fNum = g_DB.CallPro(strCall, "SELECT @idUser, @iClient, @iState, @dtUpdate, @sQuestion, @sAnswer", &acceptR );
if( fNum<0 )
return -1;
if( acceptR ){
int state = atoi(acceptR[2]);
bool bFound = false;
for( int j=0; j<nListSize; j++ ){
if( listQA[j].id==lstID[i] ){
listQA[j].idUser = atoi(acceptR[0]);
memset( listQA[j].iClientType, -1, sizeof(int)*8 );
char *tokenPtr=strtok(acceptR[1],",");
for( int k=0; k<8 && tokenPtr!=NULL; k++ ){
listQA[j].iClientType[k] = atoi( tokenPtr );
tokenPtr = strtok( NULL, "," );
}
//listQA[j].iClientType = atoi(acceptR[1]);
listQA[j].dtUpdate = atoi(acceptR[3]);
listQA[j].state = state;
if( state==5 ){
listQA[j].strQuestion[0] = '\0';
listQA[j].strAnswer[0] = '\0';
}
else{
strcpy( listQA[j].strQuestion, acceptR[4] );
if( acceptR[5] )
strcpy( listQA[j].strAnswer, acceptR[5] );
else
listQA[j].strAnswer[0] = '\0';
}
bFound = true;
break;
}
}
if( !bFound ){ //新增问题
listQA[nRetSize].id = lstID[i];
listQA[nRetSize].idUser = atoi(acceptR[0]);
//memset( listQA[j].iClientType, -1, sizeof(int)*8 );
char *tokenPtr=strtok(acceptR[1],",");
for( int k=0; tokenPtr!=NULL; k++ ){
listQA[nRetSize].iClientType[k] = atoi( tokenPtr );
tokenPtr = strtok( NULL, "," );
}
//listQA[nRetSize].iClientType = atoi(acceptR[1]);
listQA[nRetSize].state = state;
listQA[nRetSize].dtUpdate = atoi(acceptR[3]);
if( state==5 ){
listQA[nRetSize].strQuestion[0] = '\0';
listQA[nRetSize].strAnswer[0] = '\0';
}
else{
strcpy( listQA[nRetSize].strQuestion, acceptR[4] );
if( acceptR[5] )
strcpy( listQA[nRetSize].strAnswer, acceptR[5] );
else
listQA[nRetSize].strAnswer[0] = '\0';
}
nRetSize++;
}
FreeRow( acceptR, fNum );
}
}
return nRetSize;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_GetUserQnA
//--功 能: 查询用户提问
//--输 入:
// idNum 待查询ID个数
// idList 待查询ID
// idUser 用户ID
// iClientType 客户端类型
// dtUpdate 更新时间
// listSize 输入listQA大小
// listQA 返回问题列表
//--返 回: 成功返回问题个数,失败返回-1
//------------------------------------------------------------------------------------------------------------------------------
int DB_GetUserQnA( int idNum, int idList[], int idUser, int iClientType, int dtUpdate,
int nListSize, TQNAITEM listQA[] )
{
int nSize, lstID[1000], nRetSize=0;
for( nSize=0; nSize<idNum; nSize++ ){
lstID[nSize] = idList[nSize];
}
char strCall[4096];
MYSQL_ROW acceptR = NULL;
if( idUser>0 ){
sprintf( strCall, "%s(%d,%d,%d,%s)", "CALL Prc_qa_getUserList", idUser, iClientType, dtUpdate, "@list" );
int fNum = g_DB.CallPro(strCall, "SELECT @list", &acceptR);
if( fNum<0 )
return -1;
if( acceptR ){
char *tokenPtr=strtok(acceptR[0],",");
while( tokenPtr != NULL ){
int id = atoi( tokenPtr );
lstID[nSize++] = id;
tokenPtr = strtok( NULL, "," );
}
FreeRow( acceptR, fNum );
}
}
for( int i=0; i<nSize && i<nListSize; i++ ){
sprintf( strCall, "%s(%d, %d, %s)", "CALL Prc_qa_getItem", lstID[i], dtUpdate,
"@idUser, @iClient, @iState, @dtUpdate, @sQuestion, @sAnswer" );
int fNum = g_DB.CallPro(strCall,"SELECT @idUser, @iClient, @iState, @dtUpdate, @sQuestion, @sAnswer", &acceptR );
if( fNum<0 )
return -1;
if( acceptR ){
int state = atoi(acceptR[2]);
listQA[nRetSize].id = lstID[i];
listQA[nRetSize].idUser = atoi(acceptR[0]);
//listQA[nRetSize].iClientType = atoi(acceptR[1]);
//listQA[nRetSize].state = state;
listQA[nRetSize].dtUpdate = atoi(acceptR[3]);
listQA[nRetSize].state = state;
if( state==3 ){
listQA[nRetSize].state = 5;
}
if( listQA[nRetSize].state!=5 ){
if( acceptR[4] ){
TruncUTF8(acceptR[4], sizeof(tQnAItem::strQuestion));
strcpy( listQA[nRetSize].strQuestion, acceptR[4] );
}
if( (state==4 || state==6) && acceptR[5] ){
TruncUTF8(acceptR[5], sizeof(tQnAItem::strAnswer));
strcpy( listQA[nRetSize].strAnswer, acceptR[5] );
}
}
nRetSize++;
FreeRow( acceptR, fNum );
}
}
return nRetSize;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_SubmitQuestion
//--功 能: 提交问题
//--输 入:
// idUser: 提交者ID
// iClientType: 客户端类型
// strMsg: 提交信息
// strVersion: 客户端版本
//--返 回: 成功返回问题ID,失败返回-1
//------------------------------------------------------------------------------------------------------------------------------
int DB_SubmitQuestion( int idUser, int iClientType, char* strMsg, char* strVersion )
{
string strReplaced = strMsg;
// strReplaced.Replace( "'", "''" );
// strReplaced.Replace( "\\", "\\\\" );
strReplaced = replace_all( strReplaced, "'", "''" );
strReplaced = replace_all( strReplaced, "\\", "\\\\" );
char strCall[4096];
sprintf( strCall, "%s(%d,%d,'%s','%s',%s)", "CALL Prc_qa_addItem", idUser, iClientType, strReplaced.c_str(), strVersion, "@idQnA" );
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall, "SELECT @idQnA", &acceptR );
if( fNum<0 || !acceptR )
return -1;
int idQnA = atoi( acceptR[0] );
FreeRow( acceptR, fNum );
return idQnA;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_InsertSong
//--功 能: 新增上传歌曲
//--输 入:
//--idUser 用户号
//--pInfo 歌曲信息
//--nSongSize 歌曲文件大小
//--path 歌曲文件路径
//--strCover 缺省封面
//--location 文件存放盘符,空不填写
//--返回:成功返回歌曲ID,失败返回0
//------------------------------------------------------------------------------------------------------------------------------
int DB_InsertSong(int idUser, int iClientType, TSONGINFO0* pInfo, int nSongSize, char* path, char* strCover, char* location )
{
int ret = 0, i, iSex;
string strMusicType, strStyleIDs, arrStr[7];
arrStr[0] = pInfo->strSongName,
arrStr[1] = pInfo->strDescription,
arrStr[2] = pInfo->strSinger,
arrStr[3] = pInfo->strOriginal,
arrStr[4] = pInfo->strLyricist,
arrStr[5] = pInfo->strComposer,
arrStr[6] = pInfo->strArranger;
for( i=0; i<7; i++ ){
arrStr[i] = replace_all( arrStr[i], "'", "''" );
arrStr[i] = replace_all( arrStr[i], "\\", "\\\\" );
}
char buf[20];
for( i=0; i<sizeof(pInfo->iMusicStyle); i++ ){
if( pInfo->iMusicStyle[i]<0 ){
break;
}
else{
if( i>0 ){
strMusicType += ",";
}
sprintf(buf, "%d", pInfo->iMusicStyle[i]);
strMusicType += buf;// itoa( pInfo->iMusicStyle[i], buf, 10 );
}
}
for( i=0; i<sizeof(pInfo->aStyleIDs)/sizeof(UINT); i++ ){
if( pInfo->aStyleIDs[i]==0 ){
break;
}
else{
if( i>0 ){
strStyleIDs += ",";
}
sprintf(buf, "%d", pInfo->aStyleIDs[i]);
strStyleIDs += buf;// itoa( pInfo->aStyleIDs[i], buf, 10 );
}
}
iSex = pInfo->iSingerType==0 ? 5 : pInfo->iSingerType;
char strCall[4096];
sprintf( strCall, "%s(%d, %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', %d, %d, '%s', %s)",
"CALL Prc_song_addInfo",
idUser, iClientType, pInfo->iCreation, arrStr[0].c_str(), arrStr[1].c_str(), iSex,
arrStr[2].c_str(), arrStr[3].c_str(), arrStr[4].c_str(), arrStr[5].c_str(), arrStr[6].c_str(),
pInfo->iTS, pInfo->iTempo, strMusicType.c_str(), strStyleIDs.c_str(), path, nSongSize,
pInfo->iSubmit, location, "@insertId, @strCover");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall, "SELECT @insertId, @strCover", &acceptR);
if( fNum<0 )
return 0;
if( acceptR ){
ret = atoi( acceptR[0] );
strcpy( strCover, acceptR[1] );
FreeRow( acceptR, fNum );
}
if( ret!=0 ){
sprintf( strCall, "%s%d%s","CALL Prc_statistics_1(", iClientType, ",'music_upload', 1)");
g_DB.CallPro(strCall, NULL, NULL);
}
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_GetNotice
//--功 能: 查询系统公告或用户通知
//--输 入:
// listSize 输入通知个数
// listNotece 返回通知数组
// idUser 查询用户号
//--返 回: 成功返回公告个数,失败返回-1
//------------------------------------------------------------------------------------------------------------------------------
int DB_GetNotice( int nListSize, TNOTICEITEM listNotice[], UINT idUser )
{
char strCall[4096];
if( idUser )
sprintf( strCall, "%s(%d, %s)", "CALL Prc_notice_getUserList", idUser, "@list" );
else
sprintf( strCall, "%s(%s)", "CALL Prc_notice_getPublicList", "@list" );
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall, "SELECT @list", &acceptR);
if( fNum<0 || !acceptR)
return -1;
int nSize=0;
char *tokenPtr=strtok(acceptR[0],",");
while( tokenPtr != NULL && nSize<nListSize ){
int id = atoi( tokenPtr );
listNotice[nSize++].id = id;
tokenPtr = strtok( NULL, "," );
}
FreeRow( acceptR, fNum );
for( int i=0; i<nSize; i++ ){
if( idUser )
sprintf( strCall, "%s(%d, %s)", "CALL Prc_notice_getUserItem", listNotice[i].id,
"@iType, @sTitle, @sContent" );
else
sprintf( strCall, "%s(%d, %s)", "CALL Prc_notice_getPublicItem", listNotice[i].id,
"@iType, @sTitle, @sContent" );
fNum = g_DB.CallPro(strCall, "SELECT @iType, @sTitle, @sContent", &acceptR );
if( fNum<0 || !acceptR)
return -1;
listNotice[i].iType = atoi(acceptR[0]);
TruncUTF8(acceptR[1], sizeof(tNoticeItem::strTitle));
strcpy( listNotice[i].strTitle, acceptR[1] );
if( acceptR[2] ){
TruncUTF8(acceptR[2], sizeof(tNoticeItem::strContent));
strcpy( listNotice[i].strContent, acceptR[2] );
}
else
listNotice[i].strContent[0] = '\0';
FreeRow( acceptR, fNum );
}
return nSize;
}
int DB_CheckPayment(int iClientType, UINT idUser, int iOperation, int nStyleCount, UINT aStyleID[], int aCost[], int *pBalance, int *pFee)
{
char strCall[4096];
sprintf( strCall, "%s%d%s","CALL Prc_user_getBalance(", idUser, ",@user_balance,@user_vip)");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,"SELECT @user_balance,@user_vip", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int ret = 0;
if(!strcmp(acceptR[0],"-1"))
ret = 2;
else
*pBalance = atoi(acceptR[0]);
bool bVip = false;
if( strcmp(acceptR[1],"0") ){
bVip = true;
}
FreeRow( acceptR, fNum );
//计算功能费
if( bVip ){
*pFee = 0;
}
else if( iOperation<=(e_PO_Pay4Basic|e_PO_Pay4Compose) ){
*pFee = PAY_BASIC;
}
else if( iOperation & e_PO_Pay4Midi ){
if( iOperation & e_PO_Pay4Compose )
*pFee = PAY_MIDICOMPOSE;
else
*pFee = PAY_MIDITRANS;
}
else{
*pFee = 0;
if( iOperation & e_PO_Pay4Audios )
*pFee += PAY_MULTIAUDIO;
if( iOperation & e_PO_Pay4Fonts )
*pFee += PAY_MULTIFONT;
}
/*
*pFee = bVip ? 0 : ((iOperation & e_PO_Pay4Midi)
? ( (iOperation & e_PO_Pay4Compose) ? PAY_MIDICOMPOSE : PAY_MIDITRANS )
: PAY_BASIC ); //功能费
*/
if( ret!=0 || iOperation!=0 && !( iOperation & e_PO_Pay4Compose ) )
return ret;
for( int i = 0; i < nStyleCount; i++ )
{
sprintf( strCall, "%s%d,%d,%s","CALL prc_style_getCost(", aStyleID[i], idUser, "0,@style_cost)");
fNum = g_DB.CallPro(strCall,"SELECT @style_cost", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int cost = atoi(acceptR[0]);
if( cost>0 && bVip )
aCost[i] = (int)(cost * 0.8 + 0.5);
else
aCost[i] = cost;
FreeRow( acceptR, fNum );
if( cost>=0 ){//风格使用计数
sprintf( strCall, "%s%d%s","CALL Prc_statistics_1(", iClientType, ",'accompany_use', 1)");
g_DB.CallPro(strCall, NULL, NULL);
}
}
return 0;
}
int DB_ConfirmPayment(int iClientType, UINT idUser, int iOperation, int nStyleCount, UINT dwStyleID[],
int nPaidCount, UINT dwPaidID[], int *pBalance)
{
char strCall[4096];
sprintf( strCall, "%s%d%s","CALL Prc_user_getBalance(",idUser,",@user_balance,@user_vip)");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,"SELECT @user_balance, @user_vip", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int ret = 0;
if(!strcmp(acceptR[0],"-1"))
ret = 2;
else
*pBalance = atoi(acceptR[0]);
bool bVip = false;
if( strcmp(acceptR[1],"0")){
bVip = true;
}
FreeRow( acceptR, fNum );
if( ret!=0 )
return ret;
//计算功能费
int nTotal = 0;
if( !bVip ){
if( iOperation<=(e_PO_Pay4Basic|e_PO_Pay4Compose) ){
nTotal = PAY_BASIC;
}
else if( iOperation & e_PO_Pay4Midi ){
if( iOperation & e_PO_Pay4Compose )
nTotal = PAY_MIDICOMPOSE;
else
nTotal = PAY_MIDITRANS;
}
else{
if( iOperation & e_PO_Pay4Audios )
nTotal += PAY_MULTIAUDIO;
if( iOperation & e_PO_Pay4Fonts )
nTotal += PAY_MULTIFONT;
}
}
UINT nChargeCount(0), nChargeSum(0), aChargeIDs[80];
if( iOperation==0 || iOperation & e_PO_Pay4Compose ){
for( int i = 0; i < nStyleCount; i++ )
{
bool bPaid = false;
for( int j=0; j<nPaidCount; j++ ){
if( dwStyleID[i]==dwPaidID[j] ){
bPaid = true;
break;
}
}
if( bPaid )
continue;
sprintf( strCall, "%s%d,%d,%s","CALL prc_style_getCost(", dwStyleID[i], idUser, "1,@style_cost)");
fNum = g_DB.CallPro(strCall,"SELECT @style_cost", &acceptR);
if( fNum<0 || !acceptR )
return -1;
int cost = atoi(acceptR[0]);
FreeRow( acceptR, fNum );
if( cost<0 ){//风格无效
return 3;
}
else if( cost>0 ){
aChargeIDs[nChargeCount++] = dwStyleID[i];
if( bVip )
cost = (int)(cost * 0.8 + 0.5);
nChargeSum += cost;
nTotal += cost;
}
}
}
//余额不足
if(nTotal > *pBalance){
return 1;
}
else if( nTotal>0 ){
sprintf( strCall, "%s%d,%d%s","CALL Prc_user_confirmPayment(", idUser, nTotal, ",@balance)");
fNum = g_DB.CallPro(strCall, "SELECT @balance", &acceptR );
if( fNum<0 || !acceptR )
return -1;
int balance = atoi(acceptR[0]);
FreeRow( acceptR, fNum );
if( balance==-1 )
return 1;
else if( balance==-2 )
return 2;
else{
char strIDs[640] = "";
if( nChargeSum>0 ){
sprintf( strCall, "%s%d%s%d%s","CALL Prc_statistics_1(", iClientType, ",'accompany_consume',", nChargeSum, ")");
g_DB.CallPro(strCall, NULL, NULL);
for( int i=0; i<nChargeCount; i++ ){
sprintf( strCall, "%s%d,%d,%d%s","CALL Prc_style_countSellNew(", aChargeIDs[i], idUser, 80, ")");
g_DB.CallPro(strCall, NULL, NULL);
char buff[16];
sprintf( buff, "%d", aChargeIDs[i] );
strcat( strIDs, buff );
if( i<nChargeCount-1 ){
strcat( strIDs, "," );
}
}
}
int op = ( iOperation & e_PO_Pay4Midi ) ? -5 : -4;
sprintf( strCall, "%s%d%s%d%s%d%s%s%s", "CALL Pre_user_consume(", idUser, ",", op, ",", nTotal, ",'", strIDs, "')");
g_DB.CallPro(strCall, NULL, NULL);
sprintf( strCall, "%s%d%s%d%s","CALL Prc_statistics_1(", iClientType, ",'consume',", nTotal, ")");
g_DB.CallPro(strCall, NULL, NULL);
*pBalance = balance;
}
}
return 0;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_StyleScore
//--功 能: 风格评分
//--输 入:
// iTYpe 风格类型 1=发布风格 2=临时风格 3=共享风格
// idStyle:风格ID
// pScore:风格当前评分
// bGet:获取/设置
//--返 回: 错误号
//------------------------------------------------------------------------------------------------------------------------------
int DB_StyleScore( int iType, UINT idStyle, int *pScore, bool bGet )
{
int ret = 0;
char strCall[4096];
if( bGet ){
sprintf( strCall, "%s%d,%d%s","CALL Prc_style_getScore(",iType,idStyle,",@score)");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,"SELECT @score", &acceptR);
if( fNum<0 || !acceptR )
return -1;
if(!strcmp(acceptR[0],"-1"))
ret = 1;
else
*pScore = atoi(acceptR[0]);
FreeRow( acceptR, fNum );
}
else{
sprintf( strCall, "%s%d,%d,%d%s", "CALL Prc_style_setScore(",iType,idStyle,*pScore,")" );
ret = g_DB.CallPro(strCall, NULL, NULL);
}
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------
//--函数名: DB_GetWebURL
//--功 能: 获取网络地址
//--输 入:
//-/iPage: 请求页面编号
// strURL: 接收网络地址
//--返 回: 成功返回0
//------------------------------------------------------------------------------------------------------------------------------
int DB_GetWebURL( int iPage, char *strURL )
{
char strCall[4096];
sprintf( strCall, "CALL %s(%d,%s)","Prc_getWebURL",iPage,"@url");
MYSQL_ROW acceptR = NULL;
int fNum = g_DB.CallPro(strCall,"SELECT @url", &acceptR);
if( fNum<0 || !acceptR )
return -1;
strcpy(strURL, acceptR[0]);
FreeRow( acceptR, fNum );
// DebugPrint("web URL: %s", strURL);
return 0;
}