Эх сурвалжийг харах

feat:多次下载同一附件

wangshan 3 жил өмнө
parent
commit
7de398241c

+ 53 - 53
src/jfw/modules/app/src/web/templates/weixin/wxinfocontent.html

@@ -1289,26 +1289,59 @@
                           // 是新超级订阅用户
                           if (window.viper) {
                             // 有下载次数
-                            if (window.fileNum <= 0) {
-                              // 次数用完提醒联系客服
-                              vant.Dialog.confirm({
-                                message: '您本月查看机会已消耗完毕,如需下载更多附件,请前往充值。',
-                                showCancelButton: true,
-                                confirmButtonText: '立即充值',
-                                confirmButtonColor: '#2ABDD1',
-                                className: 'custom-dialog',
-                                width: 303
-
-                              }).then(() => {
-                                location.href = '/jyapp/filePack/createOrder'
-                              })
-                              .catch(() => {})
-                              return
-                            }else{
+                            $.ajax({
+                                type: 'post',
+                                url: '/jypay/resourcePack/consumePack',
+                                data: {
+                                    productName: '附件下载包',
+                                    platform: 'APP',
+                                    fileName: $(this).find('a').text(),
+                                    id: id,
+                                    title: title
+                                },
+                                success: function (r) {
+                                  if (r&&r.r&&r.r.code){
+                                    // 次数用完提醒联系客服
+                                      vant.Dialog.confirm({
+                                        message: '您本月查看机会已消耗完毕,如需下载更多附件,请前往充值。',
+                                        showCancelButton: true,
+                                        confirmButtonText: '立即充值',
+                                        confirmButtonColor: '#2ABDD1',
+                                        className: 'custom-dialog',
+                                        width: 303
+        
+                                      }).then(() => {
+                                        location.href = '/jyapp/filePack/createOrder'
+                                      })
+                                      .catch(() => {})
+                                      return
+                                  }else if (r && r.m === '' && r.r) {
+                                        var url = r.r.downUrl
+                                        if (url){
+                                          if (!r.r.isExists){
+                                            window.fileNum = window.fileNum - 1;
+                                            $('.file-count').html($('.file-count').text()-1)
+                                          }
+                                            if(mySysIsIos()){
+                                                iosShow(url)
+                                            } else {
+                                                location.href = url
+                                            }
+                                        } else {
+                                            EasyAlert.show('获取附件地址失败');
+                                        }
+                                    } else {
+                                        EasyAlert.show(r.m || '获取附件地址失败');
+                                    }
+                                }
+                            })
+                            
+                            //if (window.fileNum <= 0) {
+                            //}else{
                               //window.fileNum = window.fileNum - 1;
-                              gotoFilePageOfVip($(this).find('a').text())
-                              return
-                            }
+                              //gotoFilePageOfVip($(this).find('a').text())
+                              //return
+                            //}
                           } else {
                             // 老超级订阅用户 提醒升级
                             vant.Dialog.confirm({
@@ -1356,40 +1389,7 @@
             }
         });
     }
-    //浏览附件
-    function gotoFilePageOfVip (name) {
-        $.ajax({
-            type: 'post',
-            url: '/jypay/resourcePack/consumePack',
-            data: {
-                productName: '附件下载包',
-                platform: 'APP',
-                fileName: name,
-                id: id,
-                title: title
-            },
-            success: function (r) {
-                if (r && r.m === '' && r.r) {
-                    var url = r.r.downUrl
-                    if (url){
-                      if (!r.r.isExists){
-                        window.fileNum = window.fileNum - 1;
-                        $('.file-count').html($('.file-count').text()-1)
-                      }
-                        if(mySysIsIos()){
-                            iosShow(url)
-                        } else {
-                            location.href = url
-                        }
-                    } else {
-                        EasyAlert.show('获取附件地址失败');
-                    }
-                } else {
-                    EasyAlert.show(r.m || '获取附件地址失败');
-                }
-            }
-        })
-    }
+  
     function gotoFilePage(name){
       $.ajax({
             type:'post',

+ 11 - 8
src/jfw/modules/subscribepay/src/entity/basePack.go

@@ -4,6 +4,7 @@ import (
 	"config"
 	"fmt"
 	"log"
+	. "mongodb"
 	qutil "qfw/util"
 	"qfw/util/jy"
 	"qfw/util/redis"
@@ -12,7 +13,7 @@ import (
 )
 
 // 默认消费
-func (this *UseBalanceStruct) defaultConsume() (r map[string]interface{}, m string) {
+func (this *UseBalanceStruct) defaultConsume() (r map[string]interface{}, m string, c int) {
 	r, rerr := this.UseBalance()
 	if rerr != nil {
 		m = fmt.Sprintf("消费异常:%s", rerr.Error())
@@ -21,7 +22,7 @@ func (this *UseBalanceStruct) defaultConsume() (r map[string]interface{}, m stri
 }
 
 //附件下载消费 fui:免费赠送已使用次数;pui:付费权限已使用次数
-func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string) {
+func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string, c int) {
 	_fileName := this.Remarks["fileName"].(string)
 	_id := this.Remarks["id"].(string)
 	BaseMsg := jy.GetBigVipUserBaseMsg(this.UserId, util.Mysql, util.MQFW)
@@ -43,8 +44,8 @@ func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string)
 	} else if BaseMsg.VipStatus > 0 {
 		isExists := false
 		//查询当月附件下载历史记录-如是已下载过的附件不再扣除次数
-		if id := this.FindJyConsumePackRecord(); id != "" && this.Remarks["downUrl"] != nil {
-			log.Println("id:", id)
+		id := this.FindJyConsumePackRecord()
+		if id != "" && this.Remarks["downUrl"] != nil {
 			if util.MQFW.UpdateById(jyCC, id, map[string]interface{}{
 				"$set": map[string]interface{}{
 					"l_updateDate": time.Now().Unix(),
@@ -98,6 +99,7 @@ func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string)
 					m = "获取附件异常"
 				}
 			} else {
+				c = -1
 				m = "该用户下载权限当前月已用完"
 			}
 		}
@@ -107,6 +109,7 @@ func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string)
 			//免费用户下载后取消下载权限
 			redis.PutKV(fmt.Sprintf(jy.PowerCacheFileKey, this.UserId), -1)
 		} else {
+			c = -1
 			m = "该用户没有下载权限"
 		}
 	}
@@ -133,7 +136,7 @@ func (this *UseBalanceStruct) FindJyConsumePackRecord() string {
 	} else {
 		log.Println("查询附件下载日志异常:", this.UserId)
 	}
-	return qutil.ObjToString((*res)["_id"])
+	return BsonIdToSId((*res)["_id"])
 }
 
 //保存日志
@@ -184,13 +187,13 @@ func fileAttachRpc(fileName, id string) (r map[string]interface{}) {
 }
 
 //消费
-func JyConsumePack(userId, product, platform string, remarks map[string]interface{}) (r map[string]interface{}, m string) {
+func JyConsumePack(userId, product, platform string, remarks map[string]interface{}) (r map[string]interface{}, m string, c int) {
 	CStruct := InitUseBalance(userId, product, product, "", "", nil, remarks, 1, platform)
 	switch product {
 	case "附件下载包":
-		r, m = CStruct.fileConsume()
+		r, m, c = CStruct.fileConsume()
 	default:
-		r, m = CStruct.defaultConsume()
+		r, m, c = CStruct.defaultConsume()
 	}
 	return
 }

+ 5 - 2
src/jfw/modules/subscribepay/src/service/basePack.go

@@ -32,10 +32,13 @@ func (this *ResourcePack) ConsumePack() {
 			"fileName": this.GetString("fileName"),                             //附件名称
 			"id":       qutil.DecodeArticleId2ByCheck(this.GetString("id"))[0], //详情页id
 		}
-		Ret, Msg := entity.JyConsumePack(userId, productName, platform, remarks)
-		if Msg != "" {
+		Ret, Msg, Code := entity.JyConsumePack(userId, productName, platform, remarks)
+		if Msg != "" && Code == 0 {
 			return nil, fmt.Sprintf("%s 使用异常:%s", productName, Msg)
 		}
+		if Code < 0 {
+			Ret = map[string]interface{}{"code": Code}
+		}
 		return Ret, ""
 	}()
 	if errMsg != "" {

+ 19 - 22
src/web/templates/pc/biddetail_rec.html

@@ -3485,7 +3485,24 @@ function fromwhere(text){
   		  },
 		  success:function(data){
         if(data){
-          if ((data.m && data.m!="")||data.r["downUrl"]==undefined||data.r["downUrl"]==""){
+          if (data.r&&data.r.code){
+            // 次数用完提醒去充值
+						bidVue.$confirm('您本月查看机会已消耗完毕,如需下载更多附件,请前往充值。', {
+							showClose:false,
+							center: true,
+							confirmButtonText: '立即充值',
+							customClass: 'custom-alert',
+							showCancelButton: true,
+							confirmButtonClass: 'custom-confirm-btn',
+							cancelButtonClass: 'custom-cancel-btn',
+							cancelButtonText: '取消'
+						}).then(function(data){
+              location.href = '/swordfish/page_big_pc/free/filePack/buy'
+						}).catch(function(){
+							//$('.open-customer').trigger('click')
+							//$('body').trigger('click')
+						});
+          }else if ((data.m && data.m!="")||data.r["downUrl"]==undefined||data.r["downUrl"]==""){
             bidVue.$confirm('附件下载异常,请前往联系客服。', {
 							showClose:false,
 							center: true,
@@ -3584,27 +3601,7 @@ function fromwhere(text){
 					if (window.vipStatus > 0) {
 						// 是新超级订阅用户
 						if (window.viper) {
-							// 有下载次数
-							if (window.fileNum > 0 ) {
-								cjdyDownload(fname)
-							} else {
-								// 次数用完提醒联系客服
-								bidVue.$confirm('您本月查看机会已经消耗完毕,如需要更多服务,请前往联系客服。', {
-									showClose:false,
-									center: true,
-									confirmButtonText: '取消',
-									customClass: 'custom-alert',
-									showCancelButton: true,
-									confirmButtonClass: 'custom-cancel-btn',
-									cancelButtonClass: 'custom-confirm-btn',
-									cancelButtonText: '联系客服'
-								}).then(function(data){
-
-								}).catch(function(){
-									$('.open-customer').trigger('click')
-									$('body').trigger('click')
-								});
-							}
+              cjdyDownload(fname)
 						} else {
 							// 老超级订阅用户 提醒升级
 							bidVue.$alert('对不起,暂无权限,您可升级超级订阅解锁附件下载', '升级超级订阅', {

+ 48 - 48
src/web/templates/weixin/wxinfocontent_rec.html

@@ -1793,26 +1793,55 @@ function andownload() {
                     if (window.vipStatus>0){
                       //超级订阅新用户
                       if(window.viper){
+                        $.ajax({
+                            type: 'post',
+                            url: '/jypay/resourcePack/consumePack',
+                            data: {
+                                productName: '附件下载包',
+                                platform: 'WX',
+                                fileName: $(this).find('a').text(),
+                                id: id,
+                                title: title
+                            },
+                            success: function (r) {
+                                if (r&&r.r&&r.r.code){
+                                  vant.Dialog.confirm({
+                                    message: '您本月查看机会已消耗完毕,如需下载更多附件,请前往充值。',
+                                    showCancelButton: true,
+                                        confirmButtonText: '立即充值',
+                                    confirmButtonColor: '#2ABDD1',
+                                    className: 'custom-dialog',
+                                    width: 303
+        
+                                  }).then(() => {
+                                        location.href = '/swordfish/filePack/createOrder'
+                                  })
+                                  .catch(() => {})
+                                  return
+                                }else if (r && r.m === '' && r.r) {
+                                  var url = r.r.downUrl
+                                  if (url){
+                                    if (!r.r.isExists){
+                                      window.fileNum = window.fileNum - 1;
+                                      $('.file-count').html($('.file-count').text()-1)
+                                    }
+              						          location.href = url
+                                  } else {
+                                      EasyAlert.show('获取附件地址失败');
+                                  }
+                              } else {
+                                  EasyAlert.show(r.m || '获取附件地址失败');
+                              }
+                            }
+                        })
                         // 次数用完提醒联系客服
-                        if (window.fileNum<=0){
-                          vant.Dialog.confirm({
-                            message: '您本月查看机会已消耗完毕,如需下载更多附件,请前往充值。',
-                            showCancelButton: true,
-                                confirmButtonText: '立即充值',
-                            confirmButtonColor: '#2ABDD1',
-                            className: 'custom-dialog',
-                            width: 303
-
-                          }).then(() => {
-                                location.href = '/swordfish/filePack/createOrder'
-                          })
-                          .catch(() => {})
-                          return
-                        }else{
+                        //if (window.fileNum<=0){
+                          
+                        //}else{
                           //window.fileNum = window.fileNum - 1;
-                          gotoFilePageOfVip($(this).find('a').text())
-                          return
-                        }
+                         // gotoFilePageOfVip($(this).find('a').text())
+                        //  return
+                        //}
                       }else{
                         //超级订阅老用户  提醒升级
                         vant.Dialog.confirm({
@@ -1863,36 +1892,7 @@ function andownload() {
         }
     });
 }
-//浏览附件
-    function gotoFilePageOfVip (name) {
-        $.ajax({
-            type: 'post',
-            url: '/jypay/resourcePack/consumePack',
-            data: {
-                productName: '附件下载包',
-                platform: 'WX',
-                fileName: name,
-                id: id,
-                title: title
-            },
-            success: function (r) {
-                if (r && r.m === '' && r.r) {
-                    var url = r.r.downUrl
-                    if (url){
-                      if (!r.r.isExists){
-                        window.fileNum = window.fileNum - 1;
-                        $('.file-count').html($('.file-count').text()-1)
-                      }
-						          location.href = url
-                    } else {
-                        EasyAlert.show('获取附件地址失败');
-                    }
-                } else {
-                    EasyAlert.show(r.m || '获取附件地址失败');
-                }
-            }
-        })
-    }
+
 function gotoFilePage(name){
   $.ajax({
         type:'post',