remotepackconfig.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. #include "remotepackconfig.h"
  2. #include "globalinfo.h"
  3. RemotePackConfig::RemotePackConfig(QObject *parent) : QObject(parent)
  4. {
  5. connect(&_request,&HttpRequest::result,this,&RemotePackConfig::result);
  6. parsefUNS.insert("A1000100",[this](const QJsonObject & obj){this->_config.jitai = this->getConfigStringList(obj);});
  7. parsefUNS.insert("A1000101",[this](const QJsonObject & obj){this->_config.dangchegongbanci = this->getConfigStringList(obj);});
  8. parsefUNS.insert("A1000102",[this](const QJsonObject & obj){this->_config.daBaoGongBanCi = this->getConfigStringList(obj);});
  9. parsefUNS.insert("A1000103",[this](const QJsonObject & obj){this->_config.xiangzhong = this->getConfigStringDouble(obj);});
  10. parsefUNS.insert("A1000104",[this](const QJsonObject & obj){this->_config.tongZhong = this->getConfigStringDouble(obj);});
  11. parsefUNS.insert("A1000105",[this](const QJsonObject & obj){this->_config.guanse = this->getConfigStringList(obj);});
  12. parsefUNS.insert("A1000106",[this](const QJsonObject & obj){this->_config.nianxiang = this->getConfigStringList(obj);});
  13. parsefUNS.insert("A1000107",[this](const QJsonObject & obj){this->_config.zhixiang = this->getConfigStringList(obj);});
  14. parsefUNS.insert("A1000108",[this](const QJsonObject & obj){this->_config.mashu = this->getConfigStringInt(obj);});
  15. parsefUNS.insert("A1000109",[this](const QJsonObject & obj){this->_config.cheZhong = this->getConfigStringList(obj);});
  16. parsefUNS.insert("A1000110",[this](const QJsonObject & obj){this->_config.gangHao = this->getConfigStringList(obj);});
  17. parsefUNS.insert("A1000111",[this](const QJsonObject & obj){this->_config.xiangHaoXianShiGuiZe = this->getConfigInt(obj);});
  18. parsefUNS.insert("A1000112",[this](const QJsonObject & obj){this->_config.daBaoRuku = this->getConfigBool(obj);});
  19. parsefUNS.insert("A1000113",[this](const QJsonObject & obj){this->_config.daBaoRiQiXianShiFangShi = this->getConfigInt(obj);});
  20. parsefUNS.insert("A2000200",[this](const QJsonObject & obj){this->_config.ziDongDushu = this->getConfigBool(obj);});
  21. parsefUNS.insert("A2000201",[this](const QJsonObject & obj){this->_config.buDingZhongDaBaoXianzhi = this->getConfigBool(obj);});
  22. parsefUNS.insert("A2000202",[this](const QJsonObject & obj){this->_config.dingZhongDaBaoXianZhiKaiQi = this->getConfigBool(obj);});
  23. parsefUNS.insert("A2000203",[this](const QJsonObject & obj){this->_config.jiTaiBangDingMaDan = this->getConfigBool(obj);});
  24. parsefUNS.insert("A2000204",[this](const QJsonObject & obj){this->_config.morenTongZhongGUDing = this->getConfigBool(obj);});
  25. parsefUNS.insert("A2000205",[this](const QJsonObject & obj){this->_config.morenXiandhiMaoZhong = this->getConfigBool(obj);});
  26. parsefUNS.insert("A2000206",[this](const QJsonObject & obj){this->_config.morenDaYinRuKuMadan = this->getConfigBool(obj);});
  27. parsefUNS.insert("A2000207",[this](const QJsonObject & obj){this->_config.morenBudingZhongMaoZhongXianZhi = this->getConfigBool(obj);});
  28. parsefUNS.insert("A2000208",[this](const QJsonObject & obj){this->_config.daBaoZhuangLeiXingGuiZeKaiQi = this->getConfigBool(obj);});
  29. parsefUNS.insert("A2000209",[this](const QJsonObject & obj){this->_config.daBaoZhuangMaoZhongXianZhiKaiQi = this->getConfigBool(obj);});
  30. parsefUNS.insert("A2000210",[this](const QJsonObject & obj){this->_config.ziDongDaBaoKaiQi = this->getConfigBool(obj);});
  31. parsefUNS.insert("A2000211",[this](const QJsonObject & obj){this->_config.pingBanZiDongTongBuShuJu = this->getConfigBool(obj);});
  32. parsefUNS.insert("A2000212",[this](const QJsonObject & obj){
  33. auto jingdu = this->daBaoJingDu(obj);
  34. this->_config.chengZhongJIngDu = jingdu.first;
  35. this->_config.chengZhongJingDuMode = jingdu.second;
  36. });
  37. // parsefUNS.insert("A2000213",[this](const QJsonObject & obj){this->_config.buDingZhongTongShuFanWei = this->getConfigpAIR(obj);});
  38. // parsefUNS.insert("A2000214",[this](const QJsonObject & obj){this->_config.dingZhongTongShuFanwei = this->getConfigpAIR(obj);});
  39. parsefUNS.insert("A2000215",[this](const QJsonObject & obj){this->_config.morenRuKuMaDanFenShu = this->getConfigInt(obj);});
  40. // parsefUNS.insert("A2000216",[this](const QJsonObject & obj){this->_config.buDingZhongXianZhiFanWei = this->getConfigpAIR(obj);});
  41. parsefUNS.insert("A2000217",[this](const QJsonObject & obj){this->_config.daBaoZhuangDaYinXiangDanFenShu = this->getConfigInt(obj);});
  42. parsefUNS.insert("A2000218",[this](const QJsonObject & obj){this->_config.daBaoZhuangMaoZhongFanWei = this->getConfigInt(obj);});
  43. parsefUNS.insert("A2000219",[this](const QJsonObject & obj){this->_config.ziDongDaBaoXiangZhongFanWei = this->getConfigInt(obj);});
  44. parsefUNS.insert("A2000220",[this](const QJsonObject & obj){this->_config.zidongDaBaoMaoZhongFanWei = this->getConfigInt(obj);});
  45. parsefUNS.insert("A3000300",[this](const QJsonObject & obj){this->_config.morenDaYinHuaMaDan = this->getConfigInt(obj);});
  46. parsefUNS.insert("A3000301",[this](const QJsonObject & obj){this->_config.morenXiaoShouXianShiJinE = this->getConfigInt(obj);});
  47. parsefUNS.insert("A3000302",[this](const QJsonObject & obj){this->_config.morenDayinXiaoShouMinXidan = this->getConfigInt(obj);});
  48. parsefUNS.insert("A3000303",[this](const QJsonObject & obj){this->_config.morenDaYinXIaoShouDan = this->getConfigInt(obj);});
  49. parsefUNS.insert("A3000304",[this](const QJsonObject & obj){this->_config.morenXianShiQianKuan = this->getConfigInt(obj);});
  50. parsefUNS.insert("A3000305",[this](const QJsonObject & obj){this->_config.xiaoShouEJingDu = this->getConfigInt(obj);});
  51. //TODO:http://doc.vanlai.net:3001/web/#/1?page_id=57 补全剩下
  52. //http://erp.itwsw.cn/#/packageCon
  53. }
  54. QList<DIYPackConfig> RemotePackConfig::getDiys(const QJsonObject & data)
  55. {
  56. // TODO:
  57. QJsonArray value_array = data["value"].toArray();
  58. DIYPackConfig DTYConfig;
  59. QList<DIYPackConfig> DTYConfigList;
  60. for(int i = 0;i<value_array.size();i++){
  61. QJsonObject obj = value_array.at(i).toObject();
  62. DTYConfig.type = obj["packaging_type"].toInt();
  63. DTYConfig.danDianXiaXian = obj["danding_lower_limit"].toInt();
  64. DTYConfig.danDianShangXian = obj["danding_upper_limit"].toInt();
  65. DTYConfig.jingZhongXiaXian = obj["net_weight_lower_limit"].toInt();
  66. DTYConfig.jingZhongShangXian = obj["net_weight_upper_limit"].toInt();
  67. DTYConfigList.append(DTYConfig);
  68. }
  69. return DTYConfigList;
  70. }
  71. QList<POYPackConfig> RemotePackConfig::getPoys(const QJsonObject & data)
  72. {
  73. // TODO:
  74. QJsonArray value_array = data["value"].toArray();
  75. POYPackConfig POYConfig;
  76. QList<POYPackConfig> POYConfigList;
  77. for(int i = 0;i<value_array.size();i++){
  78. QJsonObject obj = value_array.at(i).toObject();
  79. POYConfig.type = obj["packaging_type"].toInt();
  80. POYConfig.jingZhongXiaXian = obj["net_weight_lower_limit"].toInt();
  81. POYConfig.jingZhongShangXian = obj["net_weight_upper_limit"].toInt();
  82. POYConfigList.append(POYConfig);
  83. }
  84. return POYConfigList;
  85. }
  86. void RemotePackConfig::refConfig()
  87. {
  88. getDdengji = false;
  89. GlobalInfo * glo = GlobalInfo::this_();
  90. // _aid = QString::number(body["user_id"].toInt());
  91. // _token = body["access_token"].toString();
  92. _request.setUserToken(QString::number( glo->user().accountId) ,glo->user().acessToken);
  93. QString url = glo->config().configUrl;
  94. _request.get(url);
  95. }
  96. void RemotePackConfig::result(int code, const QJsonObject & body)
  97. {
  98. int ecode = body.value("code").toInt(404);
  99. if(ecode != 200){
  100. emit configUpdateError(ecode,body.value("message").toString(""));
  101. return;
  102. }
  103. if(!getDdengji){
  104. QJsonArray object = body.value("data").toArray();
  105. for(int i = 0; i < object.size(); ++ i){
  106. QJsonObject obj = object.at(i).toObject();
  107. QString key = obj.value("key").toString();
  108. auto handle = parsefUNS.value(key,[](const QJsonObject &){});
  109. handle(obj);
  110. }
  111. emit configUpdate(_config);
  112. refDengJiList();
  113. } else {
  114. // TODO: 解析等级列表
  115. QJsonArray object = body.value("data").toArray();
  116. DengJiConfigItem dengJiConfig;
  117. for(int i = 0; i<object.size();i++){
  118. QJsonObject obj = object.at(i).toObject();
  119. dengJiConfig.id = obj.value("level_id").toInt();
  120. dengJiConfig.value = obj.value("name").toString();
  121. dengJiConfig.isEnable = obj.value("is_disable").toBool();
  122. dengji.append(dengJiConfig);
  123. }
  124. emit dengJIConfigUp(dengji);
  125. }
  126. }
  127. void RemotePackConfig::refDengJiList()
  128. {
  129. getDdengji = true;
  130. // todo: http://doc.vanlai.net:3001/web/#/1?page_id=35
  131. QString url = GlobalInfo::this_()->config().baseUrl+"/v1/level/list";
  132. _request.setUserToken(QString::number(GlobalInfo::this_()->user().accountId),GlobalInfo::this_()->user().acessToken);
  133. _request.get(url);
  134. }
  135. bool RemotePackConfig::getConfigBool(const QJsonObject & data)
  136. {
  137. QJsonArray value_array = data.value("value").toArray();
  138. int vSize = value_array.size();
  139. QString select;
  140. for(int i = 0; i < vSize; ++i){
  141. QJsonValue value_content = value_array.at(i);
  142. if(value_content.isObject()){
  143. QJsonObject value_object = value_content.toObject();
  144. if(value_object.value("selected").toBool(false)){
  145. select = value_object.value("name").toString();
  146. }
  147. }
  148. }
  149. // select = select.trimmed();
  150. if(select.contains("是") || select.contains("yes",Qt::CaseInsensitive))
  151. return true;
  152. return false;
  153. }
  154. QStringList RemotePackConfig::getConfigStringList(const QJsonObject & data)
  155. {
  156. QJsonArray value_array = data.value("value").toArray();
  157. QStringList list;
  158. int vSize = value_array.size();
  159. for(int i = 0; i < vSize; ++i){
  160. QJsonValue value_content = value_array.at(i);
  161. if(value_content.isObject()){
  162. QJsonObject value_object = value_content.toObject();
  163. list.append(value_object.value("value").toString());
  164. }
  165. }
  166. return list;
  167. }
  168. int RemotePackConfig::getConfigInt(const QJsonObject & data)
  169. {
  170. QJsonArray value_array = data.value("value").toArray();
  171. int list;
  172. int vSize = value_array.size();
  173. for(int i = 0; i < vSize; ++i){
  174. QJsonValue value_content = value_array.at(i);
  175. if(value_content.isObject()){
  176. QJsonObject value_object = value_content.toObject();
  177. if(value_content.isObject()){
  178. QJsonObject value_object = value_content.toObject();
  179. if(value_object.value("selected").toBool(false)){
  180. list = value_object.value("value").toInt();
  181. }
  182. }
  183. }
  184. }
  185. return list;
  186. }
  187. QPair<int,int> getConfigpAIR(const QJsonObject & data)
  188. {
  189. QJsonArray value_array = data.value("value").toArray();
  190. QPair<int,int> list;
  191. int vSize = value_array.size();
  192. bool frist = true;
  193. for(int i = 0; i < vSize; ++i){
  194. QJsonObject value_object = value_array.at(i).toObject();
  195. if(value_object.value("selected").toBool(false)){
  196. if(frist) {
  197. list.first = value_object.value("value").toInt();
  198. frist = false;
  199. } else {
  200. list.second = value_object.value("value").toInt();
  201. }
  202. }
  203. }
  204. return list;
  205. }
  206. QPair<int,int> RemotePackConfig::daBaoJingDu(const QJsonObject & data)
  207. {
  208. QJsonArray value_array = data.value("value").toArray();
  209. QPair<int,int> list;
  210. int vSize = value_array.size();
  211. bool frist = true;
  212. for(int i = 0; i < vSize; ++i){
  213. QJsonValue value_content = value_array.at(i);
  214. auto ary = value_content.toArray();
  215. for(int j = 0; j < ary.size(); ++j){
  216. QJsonObject value_object = ary.at(j).toObject();
  217. if(value_object.value("selected").toBool(false)){
  218. if(frist) {
  219. list.first = value_object.value("value").toInt();
  220. frist = false;
  221. } else {
  222. list.second = value_object.value("value").toInt();
  223. }
  224. }
  225. }
  226. }
  227. return list;
  228. }
  229. QList<double> RemotePackConfig::getConfigStringDouble(const QJsonObject & data)
  230. {
  231. QJsonArray value_array = data.value("value").toArray();
  232. QList<double> list;
  233. int vSize = value_array.size();
  234. for(int i = 0; i < vSize; ++i){
  235. QJsonValue value_content = value_array.at(i);
  236. if(value_content.isObject()){
  237. QJsonObject value_object = value_content.toObject();
  238. list.append(value_object.value("value").toDouble());
  239. }
  240. }
  241. return list;
  242. }
  243. QList<int> RemotePackConfig::getConfigStringInt(const QJsonObject & data)
  244. {
  245. QJsonArray value_array = data.value("value").toArray();
  246. QList<int> list;
  247. int vSize = value_array.size();
  248. for(int i = 0; i < vSize; ++i){
  249. QJsonValue value_content = value_array.at(i);
  250. if(value_content.isObject()){
  251. QJsonObject value_object = value_content.toObject();
  252. list.append(value_object.value("value").toInt());
  253. }
  254. }
  255. return list;
  256. }