Browse Source

Merge branch 'dev4.6.2.6' of http://192.168.3.207:8080/qmx/jy into dev4.6.2.6

zhangxinlei1996 3 years ago
parent
commit
591685b533

+ 104 - 37
src/jfw/modules/app/src/web/templates/frontRouter/coupon/free/selectCoupon.html

@@ -126,46 +126,92 @@
           var arr1 = []
           var arr2 = []
           var checkedId = utils.getParam('checkedId')
+          var course = utils.getParam('coures')
+          var courseId = utils.getParam('pId')
           this.listLoaded = false
-          $.ajax({
-            type:'POST',
-            url:'/jyCoupon/showCoupons',
-            data:{
-              pId: utils.getParam('pId'),
-              price: parseInt(utils.getParam('price')*100)
-            },
-            success:function(res) {
-              if (res.data && res.data.length > 0) {
-                _this.getTextByProducts(res.data)
-                res.data.forEach(function(v) {
-                  v.isOpen = false;
-                  v.isChecked = false;
-                  v.lotteryBeginDate = v.lotteryBeginDate.replace(/\-/g,'.')
-                  v.lotteryEndDate = v.lotteryEndDate.replace(/\-/g,'.')
-                  if (v.available) {
-                    if(v.userLotteryId == checkedId) {
-                      v.isChecked = true
-                      _this.selectCoupon = v
-                    }
-                    arr1.push(v)
-                  } else {
-                    arr2.push(v)
+          if(course == 'online') {
+            this.listLoaded = true
+            $.ajax({
+              type: 'GET',
+              url: '/OnlineCourses/course/findCourseLottery',
+              data: {
+                userId: '123454',
+                _id: courseId
+              },
+              success: function(res) {
+                let arrRes = []
+                res.result.forEach(item => {
+                  let resultObj = {
+                    "lotteryId": item.LotteryId,
+                    "lotteryAttribute": item.lotteryType=='0'?"满减券":"折扣券",
+                    "lotteryBeginDate": item.lotteryBeginDate,
+                    "lotteryEndDate": item.lotteryendDate,
+                    "products": [
+                      {
+                        "name": item.productNames,
+                        "url": "",
+                        "describe": "",
+                        "code": 0
+                      }
+                    ],
+                    "available": true,
+                    "full": item.full/100,
+                    "reduce": item.reduce/100,
+                    "userLotteryId": "4756485a",
+                    "disCount": item.discount * 10,
+                    'isChecked': false
                   }
+                  arrRes.push(resultObj)
                 })
-                _this.usableCoupon = arr1;
-                _this.disabledCoupon = arr2;
-                _this.allCoupon = res.data;
-              } else {
-                console.log('没有优惠券')
+                _this.getTextByProducts(arrRes, res.optimalLottery)
+                _this.allCoupon  = arrRes
+                _this.usableCoupon = arrRes
+              },
+              error: function(err) {
+                console.log(err)
               }
-            },
-            complete: function() {
-              _this.listLoaded = true
-            },
-            error:function(err) {
-              console.log(err)
-            }
-          })
+            })
+          } else {
+            $.ajax({
+              type:'POST',
+              url:'/jyCoupon/showCoupons',
+              data:{
+                pId: utils.getParam('pId'),
+                price: parseInt(utils.getParam('price')*100)
+              },
+              success:function(res) {
+                if (res.data && res.data.length > 0) {
+                  _this.getTextByProducts(res.data)
+                  res.data.forEach(function(v) {
+                    v.isOpen = false;
+                    v.isChecked = false;
+                    v.lotteryBeginDate = v.lotteryBeginDate.replace(/\-/g,'.')
+                    v.lotteryEndDate = v.lotteryEndDate.replace(/\-/g,'.')
+                    if (v.available) {
+                      if(v.userLotteryId == checkedId) {
+                        v.isChecked = true
+                        _this.selectCoupon = v
+                      }
+                      arr1.push(v)
+                    } else {
+                      arr2.push(v)
+                    }
+                  })
+                  _this.usableCoupon = arr1;
+                  _this.disabledCoupon = arr2;
+                  _this.allCoupon = res.data;
+                } else {
+                  console.log('没有优惠券')
+                }
+              },
+              complete: function() {
+                _this.listLoaded = true
+              },
+              error:function(err) {
+                console.log(err)
+              }
+            })
+          }
         },
         parentFn: function (obj) {
           // console.log('父组件接收:' + JSON.stringify(obj))
@@ -177,7 +223,28 @@
           history.back()
         },
         // 处理数组对象转字符串
-        getTextByProducts: function (arr) {
+        getTextByProducts: function (arr, opt) {
+          let course = utils.getParam('coures')
+          let $selectcoupon = sessionStorage.getItem('$select-coupon')
+          if($selectcoupon) {
+            $selectcoupon = JSON.parse($selectcoupon)
+          }
+          if(course) {
+            let _this = this
+            arr.forEach(function(s) {
+              if($selectcoupon) {
+                if(s.lotteryId == $selectcoupon.lotteryId) {
+                  s.isChecked = true
+                  _this.parentFn(s)
+                }
+              } else {
+                if(s.lotteryId == opt.LotteryId) {
+                  s.isChecked = true
+                  _this.parentFn(s)
+                }
+              }
+            })
+          }
           arr.forEach(function(s) {
             var newArr = [];
             if(s.products) {

+ 51 - 6
src/jfw/modules/subscribepay/src/entity/jyCourseOnlineStruct.go

@@ -5,6 +5,7 @@ import (
 	"errors"
 	"fmt"
 	"log"
+	"math"
 	. "mongodb"
 	"pay"
 	qutil "qfw/util"
@@ -82,11 +83,13 @@ func (this *jyCourseOnline) PayCallBack(param *CallBackParam) bool {
 
 //生成订单
 func (this *jyCourseOnline) NewOrder(param frpc.JyPayOrderParam) (ordercode string, err error) {
+	log.Println("p:--------", param)
 	productSign, ok := pay.PayWayAndSign["onlineCourse"][param.PayWay]
 	// 获取分销口令
 	disWordStr := ""
+	userid := param.Userid
 	// 查询用户携带的分销口令
-	userfilter, ok := util.MQFW.FindById("user", param.Userid, "")
+	userfilter, ok := util.MQFW.FindById("user", userid, "")
 	log.Println("用户查询结果:", ok, userfilter)
 	if ok && userfilter != nil {
 		startTime := qutil.Int64All((*userfilter)["startTime"])
@@ -109,14 +112,36 @@ func (this *jyCourseOnline) NewOrder(param frpc.JyPayOrderParam) (ordercode stri
 	}
 	//插入数据库
 	now := time.Now()
-	ordercode = pay.GetOrderCode(param.Userid)
+	ordercode = pay.GetOrderCode(userid)
 	detailByte, marshalErr := json.Marshal(param.Detail)
 	if marshalErr != nil {
 		err = marshalErr
 		return
 	}
+	original_price, discount_price := param.Price, 0 //原价,优惠价格
+	totalfee := param.Price
+	lotteryId := param.LotteryId
+	userLotteryId := "" //使用的卡券
+	if lotteryId != "" {
+		lotteryId = qutil.SE.Encode2Hex(lotteryId)
+		products := param.UseProduct
+		full_price, reduce_price, discount, userLotteryId_ := util.GetCouponInfo(userid, lotteryId, products)
+		userLotteryId = userLotteryId_
+		if full_price <= totalfee {
+			if discount == 100 { //满减
+				totalfee = totalfee - reduce_price
+				discount_price = reduce_price
+			} else { //满折
+				disCount_int := int(math.Ceil(discount * 100))
+				discount_price = totalfee - totalfee*disCount_int/1000
+				totalfee = totalfee * disCount_int / 1000
+			}
+		} else {
+			userLotteryId = ""
+		}
+	}
 	insertMap := map[string]interface{}{
-		"order_money":    param.Price,
+		"order_money":    totalfee,
 		"order_status":   0,
 		"user_openid":    param.Openid,
 		"prepay_id":      prepayid,
@@ -126,13 +151,14 @@ func (this *jyCourseOnline) NewOrder(param frpc.JyPayOrderParam) (ordercode stri
 		"product_type":   "中标必听课",
 		"create_time":    qutil.FormatDate(&now, qutil.Date_Full_Layout),
 		"prepay_time":    qutil.FormatDate(&now, qutil.Date_Full_Layout),
-		"original_price": param.Price,
+		"original_price": original_price,
 		"filter_id":      qutil.If(param.Detail != nil && param.Detail["_id"] != nil, param.Detail["_id"], ""), //课程id
 		"pay_way":        param.PayWay,
-		"user_id":        param.Userid,
+		"user_id":        userid,
 		"filter":         string(detailByte), //订单详情
 		"dis_word":       disWordStr,         //分销口令
-
+		"discount_price": discount_price,
+		"d_relation_id":  userLotteryId,
 	}
 	if param.Phone != "" {
 		insertMap["user_phone"] = param.Phone
@@ -143,6 +169,15 @@ func (this *jyCourseOnline) NewOrder(param frpc.JyPayOrderParam) (ordercode stri
 		err = errors.New("订单插入失败")
 		return
 	}
+	//绑定卡卷
+	if userLotteryId != "" && lotteryId != "" {
+		go func(userId, userLotteryId, order_code string) {
+			phone, nickname := util.GetMyPhoneAndName(userId)
+			if !util.UpdateCouponState(userId, userLotteryId, nickname, phone, order_code, "中标必听课", "", 3, 0) {
+				log.Println(fmt.Sprintf("单号%s-绑定失败-卡卷%s", order_code, userLotteryId))
+			}
+		}(userid, userLotteryId, ordercode)
+	}
 	return
 }
 
@@ -193,6 +228,16 @@ func (this *jyCourseOnline) CloseOrder(ordercode string) error {
 	}, map[string]interface{}{
 		"order_status": -2,
 	}) {
+		res := util.Mysql.FindOne("dataexport_order", map[string]interface{}{
+			"order_status": ordercode,
+		}, "id,order_code,create_time,pay_way,out_trade_no,prepay_time,order_status,discount_price,d_relation_id,user_id,filter,product_type", "")
+		user_id := qutil.ObjToString((*res)["user_id"])
+		userLotteryId := qutil.ObjToString((*res)["d_relation_id"])
+		go func(userId, userLotteryId, order_code string) {
+			if !util.UpdateCouponState(userId, userLotteryId, "", "", order_code, qutil.ObjToString((*res)["product_type"]), "0", 0, 1) {
+				log.Println(fmt.Sprintf("单号%s-解绑失败-卡卷%s", order_code, userLotteryId))
+			}
+		}(user_id, userLotteryId, ordercode)
 		return errors.New(fmt.Sprintf("%s关闭订单更新数据库出错", ordercode))
 	}
 	return nil

+ 13 - 0
src/jfw/modules/subscribepay/src/pay/util.go

@@ -151,6 +151,19 @@ var (
 		"省份订阅包":          areaPackMap,
 	}
 	varOrderCode *orderCode
+
+	ProductType = map[string]string{
+		"subvip":         "VIP订阅",
+		"entniche":       "企业商机管理",
+		"dataexport":     "历史数据",
+		"datareport":     "数据报告",
+		"onlineCourse":   "中标必听课",
+		"member":         "大会员",
+		"aiForecastPack": "大会员-AI中标预测包",
+		"integral":       "剑鱼币",
+		"dataPack":       "数据流量包",
+		"areaPack":       "省份订阅包",
+	}
 )
 
 type orderCode struct {

+ 62 - 0
src/jfw/modules/subscribepay/src/service/commonAction.go

@@ -1,6 +1,7 @@
 package service
 
 import (
+	. "api"
 	"config"
 	"encoding/base64"
 	"encoding/json"
@@ -33,6 +34,8 @@ type CommonAction struct {
 	isPaySuccess         xweb.Mapper `xweb:"/isPaySuccess"`                //是否支付成功
 	deleteOrder          xweb.Mapper `xweb:"/deleteOrder"`                 //删除订单
 	applyInvoice         xweb.Mapper `xweb:"/applyInvoice"`                //申请发票
+	//公共创建订单
+	order xweb.Mapper `xweb:"/create/(.*)/order"`
 }
 
 //----------------------------申请发票------------------------------------
@@ -416,3 +419,62 @@ func (this *CommonAction) SaveTransferAccounts() {
 	}
 	this.ServeJson(r.Format())
 }
+
+func (this *CommonAction) Order(types string) {
+	userid, _ := this.GetSession("userId").(string)
+	rData, errMsg := func() (interface{}, error) {
+		if pay.ProductType[types] == "" {
+			return nil, fmt.Errorf("未知类型")
+		}
+		//参数接收
+		infoMap := map[string]interface{}{}
+		if string(this.Body()) == "" {
+			return nil, fmt.Errorf("无效参数")
+		}
+		body := xweb.FilterXSS(string(this.Body()))
+		//接收参数
+		json.Unmarshal([]byte(body), &infoMap)
+		if len(infoMap) == 0 {
+			return nil, fmt.Errorf("缺失参数")
+		}
+		orderCode := pay.GetOrderCode()
+		nickname := qutil.ObjToString(this.GetSession("s_nickname"))
+		openId := qutil.ObjToString(this.GetSession("s_m_openid"))
+		now := time.Now()
+		//TODO 金额计算
+		totalfee := 0              //订单价格
+		original_price := totalfee //原价
+		discount_price := 0        //优惠价格
+		//TODO 卡券相关
+		userLotteryId := "" //卡券id
+		//TODO 过滤判断 是否符合下单条件
+
+		insertM := map[string]interface{}{
+			"order_money":    totalfee,
+			"order_status":   0,
+			"service_status": 0,
+			"user_nickname":  nickname,
+			"user_openid":    openId,
+			"user_phone":     this.GetString("order_phone"),
+			"order_code":     orderCode,
+			"product_type":   pay.ProductType[types],
+			"create_time":    qutil.FormatDate(&now, qutil.Date_Full_Layout),
+			"original_price": original_price,
+			"user_id":        userid,
+			"discount_price": discount_price,
+			"d_relation_id":  userLotteryId,
+		}
+		filter := map[string]interface{}{}
+		filterStr, _ := json.Marshal(filter)
+		insertM["filter"] = string(filterStr)
+		orderid := util.Mysql.Insert("dataexport_order", insertM)
+		if orderid <= 0 {
+			return nil, fmt.Errorf("创建订单异常")
+		}
+		return orderid, nil
+	}()
+	if errMsg != nil {
+		log.Printf("%s %s CreateOrder 异常:%s\n", userid, types, errMsg.Error())
+	}
+	this.ServeJson(NewResult(rData, errMsg))
+}

+ 1 - 0
src/web/staticres/common-module/coupon/css/pay-order-template.css

@@ -211,6 +211,7 @@
   display: flex;
   align-items: center;
   padding: .16rem 0 .24rem;
+  text-align: left;
 }
 .order-template .order-service .service-checkbox{
   width: .36rem;

+ 14 - 3
src/web/staticres/common-module/coupon/js/coupon-template.js

@@ -111,6 +111,7 @@ Vue.component('coupon-list', {
       var isVip = this.vipStatus; // 是否是超级订阅用户
       var isSingleVip = this.getSinglePro(str, '超级订阅'); // 是否单超级订阅优惠券
       var isSingleAreaPack = this.getSinglePro(str, '省份订阅包'); // 是否单省份订阅包优惠券
+      var isSingleCourse = this.getSinglePro(str, 'jyxsapp'); // 是否单省份订阅包优惠券
       if (isWeiXinBrowser) {
         // 是否单超级订阅优惠券
         if (isSingleVip) {
@@ -126,6 +127,8 @@ Vue.component('coupon-list', {
           } else {
             location.href = '/areaPack/wx/page/buy?couponId=' + id
           }
+        } else if (isSingleCourse) {
+          location.href = '/jyxsapp/';
         } else {
           location.href = '/weixin/frontPage/coupon/free/selectProduct?couponId=' + id;
         }
@@ -142,6 +145,8 @@ Vue.component('coupon-list', {
           } else {
             location.href = '/jyapp/areaPack/page/buy?couponId=' + id
           }
+        } else if (isSingleCourse) {
+          location.href = '/jyxsapp/?source=app_kongkim'
         } else {
           location.href = '/jyapp/frontPage/coupon/free/selectProduct?couponId=' + id;
         }
@@ -150,9 +155,15 @@ Vue.component('coupon-list', {
     // 判断是否适用单产品
     getSinglePro: function(productionList, str) {
       if(!productionList) return
-      var result = productionList.every(function(item){
-        return item.name.indexOf(str) > -1
-      })
+      if(str == 'jyxsapp') {
+        var result = productionList.every(function(item){
+          return item.url.indexOf(str) > -1
+        })
+      } else {
+        var result = productionList.every(function(item){
+          return item.name.indexOf(str) > -1
+        })
+      }
       return result
     },
     // 判断是否是超级订阅用户

+ 80 - 3
src/web/staticres/common-module/coupon/js/pay-order-template.js

@@ -37,6 +37,15 @@ var couponTem = {
           giftName: {
             type: String,
             default: ''
+          },
+          // 线上课程跳转到优惠券页面调不同的接口
+          course: {
+            type: String,
+            default: ''
+          },
+          couponobj: {
+            type: Object,
+            default: {}
           }
         }
       }
@@ -138,6 +147,64 @@ var couponTem = {
       </div>
     </div>  
   `,
+  watch: {
+    'config.couponobj' (newval) {
+      if(this.config.type === 'course') {
+        var _this = this;
+        this.coupon.list = []
+        this.coupon.type = ''
+        this.coupon.value = 0
+        this.coupon.discount = 10
+        this.coupon.checkedId = ''
+        var couponStorage = JSON.parse(sessionStorage.getItem(this.sessionStorageKey)) || null;
+        var arr = [];
+        console.log(couponStorage, 'couponStorage')
+        if (couponStorage) {
+          arr.push(couponStorage)
+          this.cacheSelectedCoupon = couponStorage
+          this.coupon.list = arr;
+          this.coupon.type = couponStorage.lotteryAttribute;
+          this.coupon.checkedId = couponStorage.userLotteryId;
+          this.coupon.userLotteryId = couponStorage.userLotteryId;
+          this.coupon.lotteryId = couponStorage.lotteryId
+
+          if (couponStorage.lotteryAttribute === '满减券') {
+            this.coupon.value = couponStorage.reduce;
+          } else if (couponStorage.lotteryAttribute === '折扣券') {
+            this.coupon.discount = couponStorage.disCount;
+
+            var price = this.config.initPrice
+            if (this.useDisPrice) {
+              price = this.config.disPrice
+            }
+            this.coupon.value = Number(price*((100 - this.coupon.discount * 10) / 100)).toFixed(2);
+          }
+          console.log('券后价:', this.realPrice)
+          this.$emit('update-coupon',this.coupon)
+        } else {
+          if (newval.result && newval.result.length != 0) {
+            if(newval.optimalLottery.lotteryType == '0') {
+              this.coupon.type = '满减券'
+              this.coupon.value = newval.optimalLottery.reduce / 100
+            } else {
+              this.coupon.type = '折扣券'
+              this.coupon.value = newval.optimalLottery.reduce / 100
+              this.coupon.discount = newval.optimalLottery.discount
+              let price = this.config.initPrice
+              if (this.useDisPrice) {
+                price = this.config.disPrice
+              }
+              this.coupon.value = Number(price*((100 - newval.optimalLottery.discount * 10 * 10) / 100)).toFixed(2);
+            }
+            this.coupon.list = newval.result
+            this.coupon.lotteryId = newval.optimalLottery.LotteryId
+          } else {
+            this.config.disPrice = this.config.initPrice
+          }
+        }
+      }
+    }
+  },
   mounted() {
     this.$emit('mounted')
   },
@@ -150,7 +217,7 @@ var couponTem = {
       }
     },
     useDisPrice: function () {
-      return this.config.type === 'dataExport' || this.config.type === 'dataPack'
+      return this.config.type === 'dataExport' || this.config.type === 'dataPack' || this.config.type === 'course'
     },
     realPrice: function () {
       if (this.useDisPrice) {
@@ -179,10 +246,19 @@ var couponTem = {
       var pId = this.getProductId();
       var price = this.useDisPrice ? this.config.disPrice : this.config.initPrice;
       var checkedId = this.coupon.checkedId;
+      var courseId = this.config.courseId
       if (isWeiXinBrowser) {
-        location.href = '/weixin/frontPage/coupon/free/selectCoupon?pId=' + pId + '&price=' + price + '&checkedId=' + checkedId;
+        if (this.config.course == 'online') {
+          location.href = '/weixin/frontPage/coupon/free/selectCoupon?pId=' + courseId + '&price=' + price + '&checkedId=' + checkedId + '&coures=' + 'online';
+        } else {
+          location.href = '/weixin/frontPage/coupon/free/selectCoupon?pId=' + pId + '&price=' + price + '&checkedId=' + checkedId;
+        }
       } else {
-        location.href = '/jyapp/frontPage/coupon/free/selectCoupon?pId=' + pId + '&price=' + price + '&checkedId=' + checkedId;
+        if(this.config.course == 'online') {
+          location.href = '/jyapp/frontPage/coupon/free/selectCoupon?pId=' + courseId + '&price=' + price + '&checkedId=' + checkedId + '&coures=' + 'online';
+        } else {
+          location.href = '/jyapp/frontPage/coupon/free/selectCoupon?pId=' + pId + '&price=' + price + '&checkedId=' + checkedId;
+        }
       }
       // 通知父组件,父组件可通过save事件进行存储数据等操作
       this.$emit('save')
@@ -200,6 +276,7 @@ var couponTem = {
     },
     // 阅读协议点击事件
     toLinks: function(link) {
+      sessionStorage.setItem('nopay', 'nopay')
       this.$emit('leave')
       if (link.url) {
         location.href = link.url

+ 125 - 37
src/web/templates/frontRouter/wx/coupon/free/selectCoupon.html

@@ -139,46 +139,113 @@
           var arr1 = []
           var arr2 = []
           var checkedId = utils.getParam('checkedId')
+          var course = utils.getParam('coures')
+          var courseId = utils.getParam('pId')
           this.listLoaded = false
-          $.ajax({
-            type:'POST',
-            url:'/jyCoupon/showCoupons',
-            data:{
-              pId: utils.getParam('pId'),
-              price: parseInt(utils.getParam('price')*100)
-            },
-            success:function(res) {
-              if (res.data && res.data.length > 0) {
-                _this.getTextByProducts(res.data)
-                res.data.forEach(function(v) {
-                  v.isOpen = false;
-                  v.isChecked = false;
-                  v.lotteryBeginDate = v.lotteryBeginDate.replace(/\-/g,'.')
-                  v.lotteryEndDate = v.lotteryEndDate.replace(/\-/g,'.')
-                  if (v.available) {
-                    if(v.userLotteryId == checkedId) {
-                      v.isChecked = true
-                      _this.selectCoupon = v
-                    }
-                    arr1.push(v)
-                  } else {
-                    arr2.push(v)
+          if(course == 'online') {
+            this.listLoaded = true
+            $.ajax({
+              type: 'GET',
+              url: '/OnlineCourses/course/findCourseLottery',
+              data: {
+                userId: '123454',
+                _id: courseId
+              },
+              success: function(res) {
+                console.log(res)
+                let arrRes = []
+                res.result.forEach(item => {
+                  let resultObj = {
+                    "lotteryId": item.LotteryId,
+                    "lotteryAttribute": item.lotteryType=='0'?"满减券":"折扣券",
+                    "lotteryBeginDate": item.lotteryBeginDate,
+                    "lotteryEndDate": item.lotteryendDate,
+                    "products": [
+                      {
+                        "name": item.productNames,
+                        "url": "",
+                        "describe": "",
+                        "code": 0
+                      }
+                    ],
+                    "available": true,
+                    "full": item.full/100,
+                    "reduce": item.reduce/100,
+                    "userLotteryId": "4756485a",
+                    "disCount": item.discount * 10,
+                    'isChecked': false
                   }
+                  arrRes.push(resultObj)
                 })
-                _this.usableCoupon = arr1;
-                _this.disabledCoupon = arr2;
-                _this.allCoupon = res.data
-              } else {
-                console.log('没有优惠券')
+                _this.getTextByProducts(arrRes, res.optimalLottery)
+                _this.allCoupon = arrRes
+                _this.usableCoupon = arrRes
+              },
+              error: function(err) {
+                console.log(err)
               }
-            },
-            complete: function() {
-              _this.listLoaded = true
-            },
-            error:function(err) {
-              console.log(err)
-            }
-          })
+            })
+            // let results = [
+            //   {
+            //     "LotteryId": 497,
+            //     "discount": 0.5,
+            //     "full": 20000,
+            //     "lotteryBeginDate": "2021-12-07",
+            //     "lotteryType": 1,
+            //     "lotteryendDate": "2021-12-18",
+            //     "reduce": 0
+            //   },
+            //   {
+            //     "LotteryId": 70,
+            //     "discount": 0,
+            //     "full": 40000,
+            //     "lotteryBeginDate": "2021-04-12",
+            //     "lotteryType": 0,
+            //     "lotteryendDate": "2021-12-12",
+            //     "reduce": 400
+            //   }
+            // ]
+          } else {
+            $.ajax({
+              type:'POST',
+              url:'/jyCoupon/showCoupons',
+              data:{
+                pId: utils.getParam('pId'),
+                price: parseInt(utils.getParam('price')*100)
+              },
+              success:function(res) {
+                if (res.data && res.data.length > 0) {
+                  _this.getTextByProducts(res.data)
+                  res.data.forEach(function(v) {
+                    v.isOpen = false;
+                    v.isChecked = false;
+                    v.lotteryBeginDate = v.lotteryBeginDate.replace(/\-/g,'.')
+                    v.lotteryEndDate = v.lotteryEndDate.replace(/\-/g,'.')
+                    if (v.available) {
+                      if(v.userLotteryId == checkedId) {
+                        v.isChecked = true
+                        _this.selectCoupon = v
+                      }
+                      arr1.push(v)
+                    } else {
+                      arr2.push(v)
+                    }
+                  })
+                  _this.usableCoupon = arr1;
+                  _this.disabledCoupon = arr2;
+                  _this.allCoupon = res.data
+                } else {
+                  console.log('没有优惠券')
+                }
+              },
+              complete: function() {
+                _this.listLoaded = true
+              },
+              error:function(err) {
+                console.log(err)
+              }
+            })
+          }
         },
         parentFn: function (obj) {
           // console.log('父组件接收:' + JSON.stringify(obj))
@@ -189,7 +256,28 @@
           history.back()
         },
         // 处理数组对象转字符串
-        getTextByProducts: function (arr) {
+        getTextByProducts: function (arr, opt) {
+          let course = utils.getParam('coures')
+          let $selectcoupon = sessionStorage.getItem('$select-coupon')
+          if($selectcoupon) {
+            $selectcoupon = JSON.parse($selectcoupon)
+          }
+          if(course) {
+            let _this = this
+            arr.forEach(function(s) {
+              if($selectcoupon) {
+                if(s.lotteryId == $selectcoupon.lotteryId) {
+                  s.isChecked = true
+                  _this.parentFn(s)
+                }
+              } else {
+                if(s.lotteryId == opt.LotteryId) {
+                  s.isChecked = true
+                  _this.parentFn(s)
+                }
+              }
+            })
+          }
           arr.forEach(function(s) {
             var newArr = [];
             if(s.products) {