mainCtrl.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //mainCtrl.cpp TCHAT_MESSAGE_STRU
  2. #include "stdafx.h"
  3. ///////////////////////////////////////////////////////////////////////////////
  4. #include "mainCtrl.h"
  5. #include "mysqldata.h"
  6. #include "LYFZSendMsg.h"
  7. extern CString g_mainpath;
  8. extern CDatabase g_db;
  9. CStringArray g_baduserarray;
  10. /*
  11. 移动:
  12. 139,138,137,136,135,134,159,158,152,151,150,157,188,187,144
  13. 联通:
  14. 130,131,132,155,156,186,185
  15. 电信:
  16. 133,153,189,180
  17. */
  18. //------------------------------------------------------------------------------
  19. // Remark by Jeff;
  20. // 函数:CheckPhoneType
  21. // 描述:判断手机号属于哪个运营商的;
  22. // 参数:
  23. // phoneno: 欲判断的手机号;
  24. //
  25. // 返回:返回0表示移动; 1表示联通; 2表示电信; 3表示小灵通; -1表示未知的;
  26. //
  27. // 注意:
  28. //
  29. //------------------------------------------------------------------------------
  30. int CheckPhoneType(CString phoneno)
  31. {
  32. int i;
  33. if(phoneno.IsEmpty ())return -1;
  34. for( i=0; i<phoneno.GetLength (); i++)
  35. {
  36. if(phoneno.GetAt (i)<'0'||phoneno.GetAt (i)>'9')return -1;
  37. }
  38. if(phoneno.GetAt (0)=='1')
  39. {
  40. if(phoneno.GetLength ()!=11)
  41. return -1;
  42. int mobile[]={139,138,137,136,135,134,159,158,152,151,150,157,188,187,144,182,147,183,184,178};
  43. int unicom[]={130,131,132,155,156,186,185,176};
  44. int telecom[]={133,153,189,180,181,177};
  45. for(i=0; i<sizeof(mobile)/sizeof(int); i++)
  46. {
  47. if(mobile[i]==atoi(phoneno.Left (3)))
  48. {
  49. return 0;
  50. }
  51. }
  52. for(i=0; i<sizeof(unicom)/sizeof(int); i++)
  53. {
  54. if(unicom[i]==atoi(phoneno.Left (3)))
  55. {
  56. return 1;
  57. }
  58. }
  59. for(i=0; i<sizeof(telecom)/sizeof(int); i++)
  60. {
  61. if(telecom[i]==atoi(phoneno.Left (3)))
  62. {
  63. return 2;
  64. }
  65. }
  66. return -1;
  67. }
  68. /* else if(phoneno.GetAt (0)=='0')
  69. {
  70. if(phoneno.GetLength ()>=10 && phoneno.GetLength ()<=12)
  71. {
  72. return 3;
  73. }
  74. }*/
  75. return -1;
  76. }
  77. //------------------------------------------------------------------------------------------
  78. // Remark by Jeff: 2014.09.21
  79. // 函数:GetCount
  80. // 描述:指定短信内容和手机号,计算出要发送的短信条数;
  81. // 参数:
  82. // phones: 以逗号分隔的手机号串;
  83. // content: 短信内容;
  84. //
  85. // 返回:短信条数;
  86. //
  87. // 注意:
  88. //
  89. //------------------------------------------------------------------------------------------
  90. int GetCount(CString phones, CString content)
  91. {
  92. // 1.首先分析出短信内容会被拆分成多少条短信发送;
  93. int nNumberOfTextMsg = 0; // 短信条数;
  94. int nWCharLen = ::MultiByteToWideChar(CP_ACP,0,content,-1,NULL,0); // Jeff.无论constent是否空,MultiByteToWideChar返回结果都>=1;
  95. // 魔数MSG_LENGTH = 67:
  96. // 当短信字符数超过70时,短信服务商会分为两部分;
  97. // 1.将前67个字符为一条短信;
  98. // 2.将67后的为另一部分,若仍大于70,再次执行1;
  99. // 3.若短信小于等于70,则为一条短信;
  100. nNumberOfTextMsg = nWCharLen / 67;
  101. if (nWCharLen % 67 > 2 ) ++nNumberOfTextMsg;
  102. // 2.其次解析手机字符串,获取手机数量;(不考虑小灵通,通用使用67字符截断短信)
  103. int nCountOfMobile = 0;
  104. int nIndex = 0;
  105. do
  106. {
  107. nIndex = phones.Find(",");
  108. if (nIndex != -1)
  109. {
  110. if ( nIndex == 11 && CheckPhoneType(phones.Left(nIndex)) != -1) // Jeff,CheckPhoneType返回-1表示未知手机类型;
  111. ++nCountOfMobile;
  112. phones = phones.Mid(nIndex+1);
  113. }
  114. else
  115. {
  116. if ( phones.GetLength() == 11 && CheckPhoneType(phones) != -1)
  117. ++nCountOfMobile;
  118. }
  119. } while (nIndex != -1);
  120. return nNumberOfTextMsg *= nCountOfMobile;
  121. }
  122. int GetBalance(CString account)
  123. {
  124. CString count1="";
  125. CString count2="";
  126. CString count3="";
  127. try
  128. {
  129. CRecordset myset(&g_db);
  130. #ifdef SQLSERVER_VERSION
  131. CString sql="select sum(cast([count] as float)) as cot from recharge where account='"+account+"'";
  132. #else
  133. CString sql="select sum([count]) as cot from recharge where account='"+account+"'";
  134. #endif
  135. myset.Open (CRecordset::forwardOnly, sql);
  136. if(!myset.IsEOF())
  137. myset.GetFieldValue ("cot", count1);
  138. myset.Close();
  139. #ifdef SQLSERVER_VERSION
  140. sql="select sum(cast([msgcount] as float)) as cot from sendreg where account='"+account+"'";
  141. #else
  142. sql="select sum([msgcount]) as cot from sendreg where account='"+account+"'";
  143. #endif
  144. myset.Open (CRecordset::forwardOnly, sql);
  145. if(!myset.IsEOF())
  146. myset.GetFieldValue ("cot", count2);
  147. myset.Close();
  148. #ifdef SQLSERVER_VERSION
  149. sql="select sum(cast([msgcount2] as float)) as cot from sendreg where account='"+account+"'";
  150. #else
  151. sql="select sum([msgcount2]) as cot from sendreg where account='"+account+"'";
  152. #endif
  153. myset.Open (CRecordset::forwardOnly, sql);
  154. if(!myset.IsEOF())
  155. myset.GetFieldValue ("cot", count3);
  156. myset.Close();
  157. return atoi(count1)-atoi(count2);
  158. }
  159. catch(...)
  160. {
  161. return -1;
  162. }
  163. }
  164. BOOL g_bWork=0;