formaccountinfo.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. #include "formaccountinfo.h"
  2. #include "ui_formaccountinfo.h"
  3. #include "respgetservertime.h"
  4. #include "respencrypt.h"
  5. #include "respgetuserblance.h"
  6. #include "sncdatabase.h"
  7. //#include "dialogbindsystem.h"
  8. FormAccountInfo::FormAccountInfo(QWidget *parent) :
  9. QWidget(parent),
  10. ui(new Ui::FormAccountInfo)
  11. {
  12. ui->setupUi(this);
  13. initVariables();
  14. initUI();
  15. }
  16. FormAccountInfo::~FormAccountInfo()
  17. {
  18. m_wool->abort();
  19. m_ssows->abort();
  20. m_movie->stop();
  21. delete m_movie;
  22. delete m_ssows;
  23. delete m_wool;
  24. delete ui;
  25. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  26. <<"FormWool.FormAccountInfo Destroyed.";
  27. }
  28. void FormAccountInfo::setAccountInfo(QMap<QString, QString> info)
  29. {
  30. m_account = info;
  31. QString ssoHash = info.value("ssohash");
  32. QString userCode = info.value("usercode");
  33. if(!ssoHash.isEmpty())
  34. {
  35. setAccountAreaUI(LoginOk);
  36. }
  37. else
  38. {
  39. if(userCode.isEmpty())
  40. {
  41. setAccountAreaUI(NotLogin);
  42. }
  43. else
  44. {
  45. setAccountAreaUI(LoginError);
  46. }
  47. }
  48. }
  49. void FormAccountInfo::initVariables()
  50. {
  51. m_wool = new WSWool();
  52. m_ssows = new WSSSO();
  53. m_movie = new QMovie(":/working.gif");
  54. m_movie->start();
  55. }
  56. void FormAccountInfo::initUI()
  57. {
  58. //初始化背景效果
  59. ui->widgetBackground->setProperty("class","silverbg");
  60. //初始化登录后显示的账户相关信息区域的样式
  61. ui->pushButtonCharge->setProperty("class","small-red-bg");
  62. ui->pushButtonLogin->setProperty("class","txt-green");
  63. ui->pushButtonBind->setProperty("class","txt-green-bold");
  64. ui->pushButtonRefreshUserState->setProperty("class","txt-green");
  65. ui->pushButtonPay->setProperty("class","txt-green-bold");
  66. ui->labelToPay->setStyleSheet("color:red");
  67. setAccountAreaUI(NotLogin);
  68. }
  69. void FormAccountInfo::setAccountAreaUI(AccountLoginState state)
  70. {
  71. switch(state)
  72. {
  73. case LoginOk:
  74. ui->labelTip->setText("");
  75. ui->widgetAccountInfo->setVisible(true);
  76. ui->pushButtonLogin->setVisible(false);
  77. ui->labelTip2->setText("");
  78. ui->labelTip3->setText("");
  79. ui->widgetDefault->setVisible(false);
  80. refreshAccountInfo();
  81. break;
  82. case NotLogin:
  83. ui->labelTip->setText("您需要");
  84. ui->widgetAccountInfo->setVisible(false);
  85. ui->pushButtonLogin->setVisible(true);
  86. ui->pushButtonBind->setVisible(false);
  87. ui->labelTip2->setText("才可以使用该功能!");
  88. ui->widgetDefault->setVisible(true);
  89. ui->labelTip3->setText("");
  90. break;
  91. case NotBind:
  92. ui->labelTip->setText("尚未开通");
  93. ui->widgetAccountInfo->setVisible(false);
  94. ui->pushButtonLogin->setVisible(false);
  95. ui->pushButtonBind->setVisible(true);
  96. ui->labelTip2->setText("防薅羊毛检测服务!请点击此处[ ");
  97. ui->widgetDefault->setVisible(true);
  98. ui->labelTip3->setText(" ]");
  99. break;
  100. case LoginError:
  101. ui->labelTip->setText("防薅羊毛检测服务无法连接!");
  102. ui->widgetAccountInfo->setVisible(false);
  103. ui->pushButtonLogin->setVisible(false);
  104. ui->pushButtonBind->setVisible(false);
  105. ui->widgetDefault->setVisible(true);
  106. ui->labelTip2->setText("");
  107. ui->labelTip3->setText("");
  108. break;
  109. }
  110. changeImage(state);
  111. }
  112. void FormAccountInfo::changeImage(AccountLoginState state)
  113. {
  114. m_state = state;
  115. QPixmap pixamp(":/service_state.png");
  116. int nHeight = pixamp.height();
  117. int nWidth = pixamp.width()/4;
  118. ui->labelStateImage->setPixmap(pixamp.copy(QRect(state * nWidth , 0, nWidth, nHeight)));
  119. }
  120. void FormAccountInfo::refreshAccountInfo()
  121. {
  122. bool succeed =false;
  123. QString userHash = m_account.value("ssohash");
  124. ui->labelStateImage->setMovie(m_movie);
  125. QString json = m_wool->GetUserBalance(userHash);
  126. changeImage(m_state);
  127. RespGetUserBlance response (json);
  128. if(response.getRtnCode()==1){
  129. ui->labelGiftBalance->setText("¥" + response.getGiftMoney());
  130. ui->labelUserBlance->setText("¥" + response.getBlance());
  131. ui->labelValidNum->setText(response.getValidNum());
  132. ui->labelToPay->setText("待付金额:¥" + response.getToPayMoney());
  133. if(response.getToPayMoney()>response.getBlance())
  134. emit blanceOut();
  135. else
  136. emit blanceIn();
  137. // if(response.getToPayMoney().toDouble()==0)
  138. // {
  139. // ui->labelToPay->setVisible(false);
  140. // ui->pushButtonPay->setVisible(false);
  141. // }
  142. // else
  143. // {
  144. // ui->labelToPay->setVisible(true);
  145. // ui->pushButtonPay->setVisible(true);
  146. // }
  147. succeed = true;
  148. }
  149. if(!succeed)
  150. {
  151. ui->labelGiftBalance->setText("N/A");
  152. ui->labelUserBlance->setText("N/A");
  153. ui->labelValidNum->setText("N/A");
  154. ui->labelToPay->setText("待付金额:N/A");
  155. }
  156. }
  157. void FormAccountInfo::on_pushButtonLogin_clicked()
  158. {
  159. emit buttonLoginClick();
  160. }
  161. void FormAccountInfo::on_pushButtonCharge_clicked()
  162. {
  163. QString ssoHash = m_account.value("ssohash");
  164. if(ssoHash.isEmpty())
  165. {
  166. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  167. return;
  168. }
  169. if(!checkLastClickTime(sender()))
  170. return ;
  171. QString json = m_ssows->encrypt(ssoHash);
  172. RespEncrypt resp1(json);
  173. QString data = resp1.getEncryptData();
  174. json = m_ssows->getServerTime();
  175. RespGetServerTime resp2(json);
  176. QString authCode;
  177. QByteArray ba;
  178. QString str = SNCDataBase::getAuthCodeUrl().arg(resp2.getServerTime().mid(0,16));
  179. ba = QCryptographicHash::hash ( str.toAscii(), QCryptographicHash::Md5 );
  180. authCode.append(ba.toHex());
  181. QString url = SNCDataBase::getSSOPayUrl() + "?s=mf&r="+authCode+"&u="+data+"&p=zxcz_wool";
  182. QDesktopServices::openUrl(QUrl(url));
  183. }
  184. void FormAccountInfo::on_pushButtonRefreshUserState_clicked()
  185. {
  186. QString userHash = m_account.value("ssohash");
  187. if(userHash.isEmpty())
  188. {
  189. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  190. return;
  191. }
  192. if(!checkLastClickTime(sender()))
  193. return ;
  194. setCursor(Qt::WaitCursor);
  195. refreshAccountInfo();
  196. setCursor(Qt::ArrowCursor);
  197. }
  198. void FormAccountInfo::onDataUpdated()
  199. {
  200. refreshAccountInfo();
  201. }
  202. bool FormAccountInfo::checkLastClickTime(QObject *button)
  203. {
  204. QPushButton *btn = qobject_cast<QPushButton*>(button);
  205. QDateTime lasttime = m_clickTime.value(btn->objectName());
  206. if(!lasttime.isNull())
  207. {
  208. if(lasttime.addSecs(30)>QDateTime::currentDateTime())
  209. {
  210. QMessageBox::critical(this,"提示","您不可以频繁点击!",QMessageBox::Ok);
  211. return false;
  212. }
  213. }
  214. m_clickTime.insert(btn->objectName(),QDateTime::currentDateTime());
  215. return true;
  216. }
  217. void FormAccountInfo::on_pushButtonPay_clicked()
  218. {
  219. QString userHash = m_account.value("ssohash");
  220. if(userHash.isEmpty())
  221. {
  222. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  223. return;
  224. }
  225. if(!checkLastClickTime(sender()))
  226. return ;
  227. QString json = m_ssows->encrypt(userHash);
  228. RespEncrypt resp1(json);
  229. QString data = resp1.getEncryptData();
  230. json = m_ssows->getServerTime();
  231. RespGetServerTime resp2(json);
  232. QString authCode;
  233. QByteArray ba;
  234. QString str = SNCDataBase::getAuthCodeUrl().arg(resp2.getServerTime().mid(0,16));
  235. ba = QCryptographicHash::hash ( str.toAscii(), QCryptographicHash::Md5 );
  236. authCode.append(ba.toHex());
  237. QString url = SNCDataBase::getSSOPayUrl() + "?s=mf&r="+authCode+"&u="+data+"&p=fk_wool";
  238. QDesktopServices::openUrl(QUrl(url));
  239. }
  240. void FormAccountInfo::on_pushButtonBind_clicked()
  241. {
  242. /*
  243. DialogBindSystem dialog(this);
  244. QString ssoHash = m_account.value("ssohash");
  245. QString syscode = "";
  246. if(m_clientID=="sskh")
  247. {
  248. syscode = "1";
  249. }
  250. else if(m_clientID=="mykh")
  251. {
  252. syscode = "2";
  253. }
  254. dialog.setSysRegInfo(syscode,ssoHash);
  255. dialog.exec();
  256. if(dialog.serviceIsOpen())
  257. {
  258. // refreshSrvInfo();
  259. // WSSSO sso2;
  260. // QString json = sso2.getSysAccount(syscode,this->userHash);
  261. // RespGetSysAccount response2(json);
  262. // if(response2.getRtnCode() == 1)
  263. // {
  264. // QMap<QString,QString> shunshiInfo,mingyuanInfo;
  265. // if(syscode=="1")
  266. // {
  267. // shunshiInfo.insert("usercode",response2.getUserCode());
  268. // shunshiInfo.insert("userpwd",response2.getUserPwd());
  269. // emit updateShunShiAccount(shunshiInfo);
  270. // }
  271. // else if(syscode=="2")
  272. // {
  273. // mingyuanInfo.insert("usercode",response2.getUserCode());
  274. // mingyuanInfo.insert("userpwd",response2.getUserPwd());
  275. // emit updateMingYuanAccount(mingyuanInfo);
  276. // }
  277. // }
  278. }
  279. */
  280. }