123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- //请求同意调用
- function $DoPost(url, param = {}, callback, async = true) {
- $.ajax({
- url: url + "?t=" + new Date().getTime(),
- type: "POST",
- data: param,
- async: async,
- dataType: "json",
- success: function (r) {
- callback(r)
- if (r.error || r.errMsg) {
- var errTip = r.error || r.errMsg;
- weui.toast(errTip, {
- duration: 2000,
- className: 'custom-toast',
- });
- }
- }
- })
- }
- //获取url参数
- function getParam(name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
- var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
- var context = "";
- if (r != null)
- context = r[2];
- reg = null;
- r = null;
- return context == null || context == "" || context == "undefined" ? "" : context;
- }
- //省份 城市 分类
- function getAreaClassArr_index(area) {
- let cityArr = [];//城市
- let provinceArr = [];//省份
- for (var i in area) {
- let citys = area[i]
- if (citys.length > 0) {
- cityArr = cityArr.concat(citys);
- provinceArr.push(i + "(" + cityArr.join("、") + ")")
- } else {
- if (i == "全国") {
- continue
- }
- provinceArr.push(i)
- }
- }
- return SortArr(provinceArr)
- }
- //省份 城市 分类
- function getAreaClassArr(area) {
- let cityArr = [];//城市
- let provinceArr = [];//省份
- for (var i in area) {
- let citys = area[i]
- if (citys.length > 0) {
- cityArr = cityArr.concat(citys);
- } else {
- if (i == "全国") {
- continue
- }
- provinceArr.push(i)
- }
- }
- return [SortArr(provinceArr), SortArr(cityArr)]
- }
- //对数组进行排序(拼音)
- function SortArr(arr) {
- arr = arr.sort(function compareFunction(item1, item2) {
- return item1.localeCompare(item2);
- });
- return arr
- }
- //购买设置
- function getBuySet(area, industry) {
- if (industry[0] === "全部行业") industry = [];
- if (area["全国"]) area = {};
- //计算地区数量
- var buyset = {
- "areacount": -1, //省份数量
- "buyerclasscount": -1,
- "citys": { //购买省份中城市数量
- }
- };
- //行业
- if (industry.length != 0) {
- buyset.buyerclasscount = industry.length
- }
- //地区
- if (!$.isEmptyObject(area)) {
- buyset.areacount = 0;
- for (var i in area) {
- let citys = area[i];
- if (citys.length === 0) {
- buyset.areacount++
- } else {
- buyset.citys[i] = citys.length
- }
- }
- }
- return buyset
- }
- /* vip订阅价格
- area:地区 {}
- industry:行业 []
- time[count,unit] count:时间长度 unit 1:年 2:月
- price 价格表
- return 价格(单位:分)
- */
- function getsubVipOrderPrice(area, industry, t, price) {
- return getsubVipOrderPriceBybuyset(getBuySet(area, industry), t, price)
- }
- var priceData;
- //根据购买设置 获取支付金额
- function getsubVipOrderPriceBybuyset(buyset, t, price) {
- if (!price) {
- if (priceData) {
- price = priceData
- } else {
- $DoPost("/subscribepay/vipsubscribe/getPrice", {}, function (r) {
- if (r) {
- price = r;
- priceData = price;
- } else {
- weui.toast("加载价格异常", {
- duration: 2000,
- className: 'custom-toast',
- });
- }
- }, false)
- }
- }
- var vipbuyset = JSON.parse(JSON.stringify(buyset));
-
- if (!$.isEmptyObject(vipbuyset.citys)) {
- for (var i in vipbuyset.citys) {
- if(vipbuyset.citys[i]>price.cityMaxCount){
- vipbuyset.areacount++
- delete vipbuyset.citys[i]
- }
- }
- }
- console.log(vipbuyset)
- //当省份数量大于price.ProvinceMaxCount 按照全国计算
- if (vipbuyset.areacount > price.provinceMaxCount) {
- vipbuyset.areacount = -1
- }
- //当行业数量大于price.buyerClassMaxCount按照全行业
- if (vipbuyset.buyerclasscount > price.buyerClassMaxCount) {
- vipbuyset.buyerclasscount = -1
- }
- if (t[0] > price.monthMaxCount && t[1] === 2) t[0] = 10;//月份十个月以上价格一样
- if (vipbuyset.areacount === -1) {//计算全国套餐价格
- if (vipbuyset.buyerclasscount === 1) return getSetMealPrice(0, 1, t[1], price) * t[0] / 100; //全国1行业套餐
- if (vipbuyset.buyerclasscount === 0) return getSetMealPrice(0, 0, t[1], price) * t[0] / 100; //全国全行业套餐
- return getSetMealPrice(0, vipbuyset.buyerclasscount, t[1], price) * t[0] / 100 //全国多行业套餐
- }
- //var final_price = vipbuyset.areacount * getSetMealPrice(1, vipbuyset.buyerclasscount, t[1], price) * t[0];//计算省份价格
- var final_price = 0;//计算省份价格
- for (var i in vipbuyset.citys) {
- var thisPrice = 0;
- if (vipbuyset.citys[i] === 1) {//单城市
- thisPrice = getSetMealPrice(2, vipbuyset.buyerclasscount, t[1], price) * t[0];
- } else {//多城市
- if (vipbuyset.buyerclasscount === 0 || vipbuyset.buyerclasscount === 1) {//多城市 单行业
- if (vipbuyset.citys[i] > price.cityMaxCount) {
- vipbuyset.areacount++;
- } else {
- thisPrice = vipbuyset.citys[i] * getSetMealPrice(2, vipbuyset.buyerclasscount, t[1], price) * t[0];
- }
- } else {//多城市 多行业
- //var industry_Price = price.buyerClassPrice * vipbuyset.buyerclasscount;
- //var city_Price = price.cityPrice * vipbuyset.citys[i];
- //thisPrice = (industry_Price + city_Price) * t[0];
- if (vipbuyset.citys[i] > price.cityMaxCount) {
- vipbuyset.areacount++;
- } else {
- thisPrice = getSetMealPrice(2, vipbuyset.buyerclasscount, t[1], price) * vipbuyset.citys[i] * t[0];
- // if (t[1] === 1) thisPrice *= 10 //年的价格是月价格的10倍
- }
- }
- }
- final_price += thisPrice;
- }
- final_price += vipbuyset.areacount * getSetMealPrice(1, vipbuyset.buyerclasscount, t[1], price) * t[0]
- return final_price / 100
- }
- //获取套餐价格
- //c(city) 全国:0 省:1 市:2
- //iCount(industry) 全行业:-1 其他:多个行业
- //u(unit) 年:1 月:2
- function getSetMealPrice(c, iCount, u, price) {
- var t = u === 2; //是否是月单位
- switch (c) {
- case 0:
- if (iCount === -1) {
- if (t) return price.month.allProvince_allBuyerClass; //1月全国全行业
- return price.year.allProvince_allBuyerClass; //1年全国全行业
- } else {
- if (t) return price.month.allProvince_oneBuyerClass * iCount; //1月全国icount个行业
- return price.year.allProvince_oneBuyerClass * iCount; //1年全国icount个行业
- }
- case 1:
- if (iCount === -1) {
- if (t) return price.month.oneProvince_allBuyerClass; //1月1省全行业
- return price.year.oneProvince_allBuyerClass //1年1省全行业
- } else {
- if (t) return price.month.oneProvince_oneBuyerClass * iCount; //1月1省icount个行业
- return price.year.oneProvince_oneBuyerClass * iCount //1年1省icount个行业
- }
- default:
- if (iCount === -1) {
- if (t) return price.month.oneCity_allBuyerClass; //1月1市全行业
- return price.year.oneCity_allBuyerClass //1年1市全行业
- } else {
- if (t) return price.month.oneCity_oneBuyerClass * iCount; //1月1市icount个行业
- return price.year.oneCity_oneBuyerClass * iCount //1年1市icount个行业
- }
- }
- }
- //查看用户是否有未执行的订单
- function checkOrder(wz) {
- var flag = false;
- $.ajax({
- type: 'post',
- url: '/subscribepay/afterPay/checkOrder?t=' + new Date().getTime(),
- data: {},
- async: false,
- dataType: 'json',
- success: function (r) {
- flag = r.flag;
- if (r.flag) {
- if (wz != 1) {
- weui.toast('订单尚未到期', {
- duration: 3000,
- className: 'custom-toast',
- callback: function () {
- console.log('close')
- }
- });
- }
- }
- }
- });
- return flag
- }
|