statsDataCtrl.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. define([ 'app/app' ], function(app) {
  2. //在售商品信息统计
  3. app.register.controller('statsDataCtrl', ['$scope', 'Goods', 'toaster', 'ComponentActive', 'BrandActive', 'CommonCountAPI', 'User', '$http', '$q', 'Loading', function($scope, Goods, toaster, ComponentActive, BrandActive, CommonCountAPI, User, $http, $q, Loading) {
  4. $scope.dateArea = 'oneMonth';
  5. var _formatDate = function (date, fmt) {
  6. if (!date) {
  7. return null;
  8. }
  9. if (typeof date === 'string') {
  10. date = new Date(Date.parse(date.replace(/-/g, '/')));
  11. }
  12. var o = {
  13. 'M+': date.getMonth() + 1, // 月份
  14. 'd+': date.getDate(), // 日
  15. 'h+': date.getHours(), // 小时
  16. 'm+': date.getMinutes(), // 分
  17. 's+': date.getSeconds(), // 秒
  18. 'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
  19. 'S': date.getMilliseconds() // 毫秒
  20. }
  21. if (/(y+)/.test(fmt)) {
  22. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
  23. }
  24. for (var k in o) {
  25. if (new RegExp('(' + k + ')').test(fmt)) {
  26. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
  27. }
  28. }
  29. return fmt;
  30. };
  31. var _getClearDay = function (date) {
  32. return new Date(_formatDate(date, 'yyyy-MM-dd')).getTime() - 8 * 60 * 60 * 1000
  33. };
  34. var currentTime = _getClearDay(new Date());
  35. $scope.startDate = new Date(currentTime - 30 * 24 * 60 * 60 * 1000);
  36. $scope.endDate = new Date(currentTime + 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 59 * 1000);
  37. $scope.startFormatDate = _formatDate($scope.startDate, 'yyyy-MM-dd');
  38. $scope.endFormatDate = _formatDate($scope.endDate, 'yyyy-MM-dd');
  39. var addStartDate = new Date($scope.startDate.getTime() + 24 * 60 * 60 * 1000)
  40. var addEndDate = new Date($scope.endDate.getTime() + 24 * 60 * 60 * 1000)
  41. $scope.addStartFormatDate = _formatDate(addStartDate, 'yyyy-MM-dd');
  42. $scope.addEndFormatDate = _formatDate(addEndDate, 'yyyy-MM-dd');
  43. $scope.setFilters = function (type, val) {
  44. $scope[type] = val;
  45. if (type == 'dateArea') {
  46. // 时间筛选
  47. var currentTime = _getClearDay(new Date());
  48. var endDate = new Date(currentTime + 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 59 * 1000);
  49. if (val == 'oneMonth') {
  50. $scope.startDate = new Date(currentTime - 30 * 24 * 60 * 60 * 1000 - 24 * 60 * 60 * 1000);
  51. $scope.endDate = endDate;
  52. } else if (val == 'threeMonth') {
  53. $scope.startDate = new Date(currentTime - 3 * 30 * 24 * 60 * 60 * 1000 - 24 * 60 * 60 * 1000);
  54. $scope.endDate = endDate;
  55. } else if (val == 'sixMonth') {
  56. $scope.startDate = new Date(currentTime - 6 * 30 * 24 * 60 * 60 * 1000 - 24 * 60 * 60 * 1000);
  57. $scope.endDate = endDate;
  58. }
  59. }
  60. if (val != 'autoMonth') {
  61. initData();
  62. } else {
  63. $scope.startDate = null;
  64. $scope.endDate = null;
  65. }
  66. };
  67. $scope.condition = [];
  68. var start = {
  69. open : false
  70. };
  71. var end = {
  72. open : false
  73. };
  74. $scope.condition.push(start);
  75. $scope.condition.push(end);
  76. // 打开日期选择框
  77. $scope.openDatePicker = function($event, item, openParam) {
  78. $event.preventDefault();
  79. $event.stopPropagation();
  80. openParam == 0 ? $scope.condition[1].open = false : $scope.condition[0].open = false;
  81. item[openParam].open = !item[openParam].open;
  82. };
  83. $scope.onDateCondition = function (bool) {
  84. var startTime = $scope.startDate ? $scope.startDate.getTime() : null;
  85. var endTime = $scope.endDate ? $scope.endDate.getTime() : null;
  86. if (startTime && endTime && startTime > endTime) {
  87. if (bool == 1) {
  88. toaster.pop('info', '起始时间不能大于结束时间');
  89. $scope.startDate = null;
  90. } else {
  91. toaster.pop('info', '结束时间不能小于起始时间');
  92. $scope.endDate = null;
  93. }
  94. }
  95. if ($scope.endDate && bool == 2) {
  96. $scope.endDate = new Date($scope.endDate.getFullYear(), $scope.endDate.getMonth(), $scope.endDate.getDate())
  97. $scope.endDate = new Date($scope.endDate.getTime() + 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 59 * 1000);
  98. }
  99. initData();
  100. };
  101. var getSeekInfo = function (commonUrl) {
  102. // 询价信息
  103. var defer = $q.defer();
  104. $http({
  105. method: 'get',
  106. dataType: 'json',
  107. url: commonUrl + '/inquiry/public/getInquiryCountData',
  108. params: {startDate: $scope.startFormatDate, endDate: $scope.endFormatDate}
  109. }).success(function (data) {
  110. defer.resolve(data);
  111. }).error(function (err) {
  112. defer.reject(err);
  113. });
  114. return defer.promise;
  115. }
  116. var getAddEnUserCount = function (ssoUrl) {
  117. // 新增企业用户数
  118. var defer = $q.defer();
  119. $http({
  120. method: 'get',
  121. dataType: 'json',
  122. url: ssoUrl + '/api/userspace/inputTime/count/apps',
  123. params: {start: $scope.addStartFormatDate, end: $scope.addEndFormatDate, fromApps:'mall,b2b'}
  124. }).success(function (data) {
  125. defer.resolve(data);
  126. }).error(function (err) {
  127. defer.reject(err);
  128. });
  129. return defer.promise;
  130. }
  131. var getAddUserCount = function (ssoUrl) {
  132. // 新增个人用户
  133. var defer = $q.defer();
  134. $http({
  135. method: 'get',
  136. dataType: 'json',
  137. url: ssoUrl + '/api/user/inputTime/count/apps',
  138. params: {start: $scope.addStartFormatDate, end: $scope.addEndFormatDate, fromApps:'mall,b2b'}
  139. }).success(function (data) {
  140. defer.resolve(data);
  141. }).error(function (err) {
  142. defer.reject(err);
  143. });
  144. return defer.promise;
  145. }
  146. var getNoLoginInfo = function (ssoUrl) {
  147. // 半年未登录用户数
  148. var defer = $q.defer();
  149. $http({
  150. method: 'get',
  151. dataType: 'json',
  152. url: ssoUrl + '/api/user/count/notlgoin/month',
  153. params: {start: $scope.addStartFormatDate, end: $scope.addEndFormatDate, months: '6,12,24'}
  154. }).success(function (data) {
  155. defer.resolve(data);
  156. }).error(function (err) {
  157. defer.reject(err);
  158. });
  159. return defer.promise;
  160. }
  161. var getProductData = function () {
  162. // 上传产品个数
  163. var defer = $q.defer();
  164. Goods.getProductsCmp({fromDate: $scope.startDate.getTime(), toDate: $scope.endDate.getTime()}, function (data) {
  165. defer.resolve(data.data);
  166. }, function (err) {
  167. defer.reject(err);
  168. toaster.pop('error', '数据获取失败,请重试')
  169. });
  170. return defer.promise;
  171. }
  172. // 获取帐户中心数据和询价接口数据
  173. var getAllData = function (addStartFormatDate, addEndFormatDate, startFormatDate, endFormatDate) {
  174. var defer = $q.defer();
  175. User.isDevOrProd(null, function (data) {
  176. var ssoUrl = data.data == 'success' ? 'https://sso.ubtob.com' : 'http://192.168.253.6:32323',
  177. // uasUrl = data.data == 'success' ? 'http://uas.ubtob.com' : 'http://192.168.253.12:9000/b2b-test',
  178. commonUrl = data.data == 'success' ? 'https://api-inquiry.usoftchina.com' : 'http://218.17.158.219:24000';
  179. defer.resolve([
  180. getSeekInfo(commonUrl),
  181. getAddEnUserCount(ssoUrl),
  182. getAddUserCount(ssoUrl),
  183. getNoLoginInfo(ssoUrl),
  184. getProductData()
  185. ]);
  186. }, function (response) {
  187. toaster.pop('error', '获取运行环境失败');
  188. defer.reject(response);
  189. });
  190. return defer.promise;
  191. };
  192. // 获取不同时间阶段的相关数据
  193. var initData = function () {
  194. var addStartDate = new Date($scope.startDate.getTime() + 24 * 60 * 60 * 1000),
  195. addEndDate = new Date($scope.endDate.getTime() + 24 * 60 * 60 * 1000);
  196. $scope.addStartFormatDate = _formatDate(addStartDate, 'yyyy-MM-dd');
  197. $scope.addEndFormatDate = _formatDate(addEndDate, 'yyyy-MM-dd');
  198. $scope.startFormatDate = _formatDate($scope.startDate, 'yyyy-MM-dd');
  199. $scope.endFormatDate = _formatDate($scope.endDate, 'yyyy-MM-dd');
  200. $q.all([getAllData()]).then(function (resolve) {
  201. Loading.show();
  202. $q.all(resolve[0]).then(function (dataListResolve) {
  203. $scope.inquiryData = dataListResolve[0];
  204. $scope.newAddUserSpaceData = dataListResolve[1].content;
  205. $scope.newAddUserData = dataListResolve[2].content;
  206. $scope.monthLogoData = dataListResolve[3];
  207. $scope.productsCount = dataListResolve[4];
  208. Loading.hide();
  209. }, function (dataListReject) {
  210. console.log(dataListReject);
  211. Loading.hide();
  212. })
  213. }, function (reject) {
  214. console.log(reject);
  215. })
  216. };
  217. initData();
  218. Goods.getAllCmp({}, function (data) {
  219. angular.forEach(data, function(value) {
  220. switch(value.item) {
  221. case '规格书':
  222. $scope.start1 = value.count;
  223. break;
  224. case '品牌':
  225. $scope.start2 = value.count;
  226. break;
  227. case '现货':
  228. $scope.start3 = value.count;
  229. break;
  230. case '当前器件总数':
  231. $scope.start4 = value.count;
  232. break;
  233. case '本月新增器件数':
  234. $scope.start5 = value.count;
  235. break;
  236. case '上月新增器件数':
  237. $scope.start6 = value.count;
  238. break;
  239. case '本月新增品牌数':
  240. $scope.start7 = value.count;
  241. break;
  242. case '当前类目总数':
  243. $scope.start8 = value.count;
  244. break;
  245. case '本月更新器件数':
  246. $scope.start9 = value.count;
  247. break;
  248. case '库存合计':
  249. $scope.start10 = value.count;
  250. break;
  251. case '在售商品品牌数量':
  252. $scope.start11 = value.count;
  253. break;
  254. case '在售商品类目数量':
  255. $scope.start12 = value.count;
  256. break;
  257. case '在售商品型号数量':
  258. $scope.start13 = value.count;
  259. break;
  260. case '含税金额合计(RMB)':
  261. $scope.start14 = value.count;
  262. break;
  263. case '未税金额合计(RMB)':
  264. $scope.start15 = value.count;
  265. break;
  266. case '上年交易金额':
  267. $scope.start16 = value.count;
  268. break;
  269. case '本年交易金额':
  270. $scope.start17 = value.count;
  271. break;
  272. case '上月器件总数':
  273. $scope.start18 = value.count;
  274. break;
  275. case '上月品牌总数':
  276. $scope.start19 = value.count;
  277. break;
  278. case '上月开通店铺数量':
  279. $scope.start20 = value.count;
  280. break;
  281. case '上个月用户注册量':
  282. $scope.start21 = value.count;
  283. break;
  284. case '上个月企业注册量':
  285. $scope.start22 = value.count;
  286. break;
  287. case '供应商总数':
  288. $scope.start23 = value.count;
  289. break;
  290. case '店铺总数':
  291. $scope.start24 = value.count;
  292. break;
  293. case '本月新增店铺数':
  294. $scope.start25 = value.count;
  295. break;
  296. case '上月新增店铺数':
  297. $scope.start26 = value.count;
  298. break;
  299. case '优软云个人用户数':
  300. $scope.start27 = value.count;
  301. break;
  302. case '注册总数量':
  303. $scope.start28 = value.count;
  304. break;
  305. case '当月注册数量':
  306. $scope.start29 = value.count;
  307. break;
  308. case '上月注册汇总':
  309. $scope.start30 = value.count;
  310. break;
  311. case '手机UU用户数':
  312. $scope.start31 = value.count;
  313. break;
  314. }
  315. });
  316. }, function(res) {
  317. toaster.pop('error', '提示', '获取数据失败,请刷新页面')
  318. })
  319. }]);
  320. });