statsDataCtrl.js 17 KB

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