common.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. //请求同意调用
  2. function $DoPost(url, param = {}, callback, async = true) {
  3. $.ajax({
  4. url: url + "?t=" + new Date().getTime(),
  5. type: "POST",
  6. data: param,
  7. async: async,
  8. dataType: "json",
  9. success: function (r) {
  10. callback(r)
  11. if (r.error || r.errMsg) {
  12. var errTip = r.error || r.errMsg;
  13. weui.toast(errTip, {
  14. duration: 2000,
  15. className: 'custom-toast',
  16. });
  17. }
  18. }
  19. })
  20. }
  21. //获取url参数
  22. function getParam(name) {
  23. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  24. var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
  25. var context = "";
  26. if (r != null)
  27. context = r[2];
  28. reg = null;
  29. r = null;
  30. return context == null || context == "" || context == "undefined" ? "" : context;
  31. }
  32. //省份 城市 分类
  33. function getAreaClassArr_index(area) {
  34. let cityArr = [];//城市
  35. let provinceArr = [];//省份
  36. for (var i in area) {
  37. let citys = area[i]
  38. if (citys.length > 0) {
  39. cityArr = cityArr.concat(citys);
  40. provinceArr.push(i + "(" + cityArr.join("、") + ")")
  41. } else {
  42. if (i == "全国") {
  43. continue
  44. }
  45. provinceArr.push(i)
  46. }
  47. }
  48. return SortArr(provinceArr)
  49. }
  50. //省份 城市 分类
  51. function getAreaClassArr(area) {
  52. let cityArr = [];//城市
  53. let provinceArr = [];//省份
  54. for (var i in area) {
  55. let citys = area[i]
  56. if (citys.length > 0) {
  57. cityArr = cityArr.concat(citys);
  58. } else {
  59. if (i == "全国") {
  60. continue
  61. }
  62. provinceArr.push(i)
  63. }
  64. }
  65. return [SortArr(provinceArr), SortArr(cityArr)]
  66. }
  67. //对数组进行排序(拼音)
  68. function SortArr(arr) {
  69. arr = arr.sort(function compareFunction(item1, item2) {
  70. return item1.localeCompare(item2);
  71. });
  72. return arr
  73. }
  74. //购买设置
  75. function getBuySet(area, industry) {
  76. if (industry[0] === "全部行业") industry = [];
  77. if (area["全国"]) area = {};
  78. //计算地区数量
  79. var buyset = {
  80. "areacount": -1, //省份数量
  81. "buyerclasscount": -1,
  82. "citys": { //购买省份中城市数量
  83. }
  84. };
  85. //行业
  86. if (industry.length != 0) {
  87. buyset.buyerclasscount = industry.length
  88. }
  89. //地区
  90. if (!$.isEmptyObject(area)) {
  91. buyset.areacount = 0;
  92. for (var i in area) {
  93. let citys = area[i];
  94. if (citys.length === 0) {
  95. buyset.areacount++
  96. } else {
  97. buyset.citys[i] = citys.length
  98. }
  99. }
  100. }
  101. return buyset
  102. }
  103. /* vip订阅价格
  104. area:地区 {}
  105. industry:行业 []
  106. time[count,unit] count:时间长度 unit 1:年 2:月
  107. price 价格表
  108. return 价格(单位:分)
  109. */
  110. function getsubVipOrderPrice(area, industry, t, price) {
  111. return getsubVipOrderPriceBybuyset(getBuySet(area, industry), t, price)
  112. }
  113. var priceData;
  114. //根据购买设置 获取支付金额
  115. function getsubVipOrderPriceBybuyset(buyset, t, price) {
  116. if (!price) {
  117. if (priceData) {
  118. price = priceData
  119. } else {
  120. $DoPost("/subscribepay/vipsubscribe/getPrice", {}, function (r) {
  121. if (r) {
  122. price = r;
  123. priceData = price;
  124. } else {
  125. weui.toast("加载价格异常", {
  126. duration: 2000,
  127. className: 'custom-toast',
  128. });
  129. }
  130. }, false)
  131. }
  132. }
  133. var vipbuyset = JSON.parse(JSON.stringify(buyset));
  134. if (!$.isEmptyObject(vipbuyset.citys)) {
  135. for (var i in vipbuyset.citys) {
  136. if(vipbuyset.citys[i]>price.cityMaxCount){
  137. vipbuyset.areacount++
  138. delete vipbuyset.citys[i]
  139. }
  140. }
  141. }
  142. console.log(vipbuyset)
  143. //当省份数量大于price.ProvinceMaxCount 按照全国计算
  144. if (vipbuyset.areacount > price.provinceMaxCount) {
  145. vipbuyset.areacount = -1
  146. }
  147. //当行业数量大于price.buyerClassMaxCount按照全行业
  148. if (vipbuyset.buyerclasscount > price.buyerClassMaxCount) {
  149. vipbuyset.buyerclasscount = -1
  150. }
  151. if (t[0] > price.monthMaxCount && t[1] === 2) t[0] = 10;//月份十个月以上价格一样
  152. if (vipbuyset.areacount === -1) {//计算全国套餐价格
  153. if (vipbuyset.buyerclasscount === 1) return getSetMealPrice(0, 1, t[1], price) * t[0] / 100; //全国1行业套餐
  154. if (vipbuyset.buyerclasscount === 0) return getSetMealPrice(0, 0, t[1], price) * t[0] / 100; //全国全行业套餐
  155. return getSetMealPrice(0, vipbuyset.buyerclasscount, t[1], price) * t[0] / 100 //全国多行业套餐
  156. }
  157. //var final_price = vipbuyset.areacount * getSetMealPrice(1, vipbuyset.buyerclasscount, t[1], price) * t[0];//计算省份价格
  158. var final_price = 0;//计算省份价格
  159. for (var i in vipbuyset.citys) {
  160. var thisPrice = 0;
  161. if (vipbuyset.citys[i] === 1) {//单城市
  162. thisPrice = getSetMealPrice(2, vipbuyset.buyerclasscount, t[1], price) * t[0];
  163. } else {//多城市
  164. if (vipbuyset.buyerclasscount === 0 || vipbuyset.buyerclasscount === 1) {//多城市 单行业
  165. if (vipbuyset.citys[i] > price.cityMaxCount) {
  166. vipbuyset.areacount++;
  167. } else {
  168. thisPrice = vipbuyset.citys[i] * getSetMealPrice(2, vipbuyset.buyerclasscount, t[1], price) * t[0];
  169. }
  170. } else {//多城市 多行业
  171. //var industry_Price = price.buyerClassPrice * vipbuyset.buyerclasscount;
  172. //var city_Price = price.cityPrice * vipbuyset.citys[i];
  173. //thisPrice = (industry_Price + city_Price) * t[0];
  174. if (vipbuyset.citys[i] > price.cityMaxCount) {
  175. vipbuyset.areacount++;
  176. } else {
  177. thisPrice = getSetMealPrice(2, vipbuyset.buyerclasscount, t[1], price) * vipbuyset.citys[i] * t[0];
  178. // if (t[1] === 1) thisPrice *= 10 //年的价格是月价格的10倍
  179. }
  180. }
  181. }
  182. final_price += thisPrice;
  183. }
  184. final_price += vipbuyset.areacount * getSetMealPrice(1, vipbuyset.buyerclasscount, t[1], price) * t[0]
  185. return final_price / 100
  186. }
  187. //获取套餐价格
  188. //c(city) 全国:0 省:1 市:2
  189. //iCount(industry) 全行业:-1 其他:多个行业
  190. //u(unit) 年:1 月:2
  191. function getSetMealPrice(c, iCount, u, price) {
  192. var t = u === 2; //是否是月单位
  193. switch (c) {
  194. case 0:
  195. if (iCount === -1) {
  196. if (t) return price.month.allProvince_allBuyerClass; //1月全国全行业
  197. return price.year.allProvince_allBuyerClass; //1年全国全行业
  198. } else {
  199. if (t) return price.month.allProvince_oneBuyerClass * iCount; //1月全国icount个行业
  200. return price.year.allProvince_oneBuyerClass * iCount; //1年全国icount个行业
  201. }
  202. case 1:
  203. if (iCount === -1) {
  204. if (t) return price.month.oneProvince_allBuyerClass; //1月1省全行业
  205. return price.year.oneProvince_allBuyerClass //1年1省全行业
  206. } else {
  207. if (t) return price.month.oneProvince_oneBuyerClass * iCount; //1月1省icount个行业
  208. return price.year.oneProvince_oneBuyerClass * iCount //1年1省icount个行业
  209. }
  210. default:
  211. if (iCount === -1) {
  212. if (t) return price.month.oneCity_allBuyerClass; //1月1市全行业
  213. return price.year.oneCity_allBuyerClass //1年1市全行业
  214. } else {
  215. if (t) return price.month.oneCity_oneBuyerClass * iCount; //1月1市icount个行业
  216. return price.year.oneCity_oneBuyerClass * iCount //1年1市icount个行业
  217. }
  218. }
  219. }
  220. //查看用户是否有未执行的订单
  221. function checkOrder(wz) {
  222. var flag = false;
  223. $.ajax({
  224. type: 'post',
  225. url: '/subscribepay/afterPay/checkOrder?t=' + new Date().getTime(),
  226. data: {},
  227. async: false,
  228. dataType: 'json',
  229. success: function (r) {
  230. flag = r.flag;
  231. if (r.flag) {
  232. if (wz != 1) {
  233. weui.toast('订单尚未到期', {
  234. duration: 3000,
  235. className: 'custom-toast',
  236. callback: function () {
  237. console.log('close')
  238. }
  239. });
  240. }
  241. }
  242. }
  243. });
  244. return flag
  245. }