|
@@ -0,0 +1,116 @@
|
|
|
+package pay
|
|
|
+
|
|
|
+import (
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "jfw/config"
|
|
|
+ "jfw/public"
|
|
|
+ "log"
|
|
|
+ qutil "qfw/util"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "github.com/go-xweb/xweb"
|
|
|
+)
|
|
|
+
|
|
|
+//订单结构
|
|
|
+type Order struct {
|
|
|
+ *xweb.Action
|
|
|
+ buyStatus xweb.Mapper `xweb:"/front/vipsubscribe/buyStatus"` //获取用户已购买
|
|
|
+ createOrder xweb.Mapper `xweb:"/front/vipsubscribe/createOrder"` //创建订单
|
|
|
+}
|
|
|
+
|
|
|
+//获取已购买选项
|
|
|
+func (this *Order) BuyStatus() {
|
|
|
+ userid := qutil.ObjToString(this.GetSession("userId"))
|
|
|
+ r := map[string]interface{}{"success": false}
|
|
|
+ if userid != "" {
|
|
|
+ m, ok := public.MQFW.FindById("user", userid, `{"i_vipstatus":1,"o_area":1,"a_buyerindustry":1}`)
|
|
|
+ if ok && len(*m) > 0 {
|
|
|
+ r["success"] = true
|
|
|
+ r["area"] = qutil.ObjToMap((*m)["o_area"])
|
|
|
+ r["industry"] = (*m)["a_buyerindustry"]
|
|
|
+ //r["industry"] = qutil.obj (*m)["a_buyerindustry"]
|
|
|
+ r["vipStatus"] = qutil.IntAll((*m)["i_vipstatus"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.ServeJson(r)
|
|
|
+}
|
|
|
+
|
|
|
+//去支付
|
|
|
+func (this *Order) CreateOrder() {
|
|
|
+ area := qutil.ObjToMap(this.GetString("area"))
|
|
|
+ industry := strings.Split(this.GetString("industry"), ",")
|
|
|
+ date := this.GetString("date")
|
|
|
+ payWay := this.GetString("payWay")
|
|
|
+ userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
+ openId := qutil.ObjToString(this.GetSession("s_m_openid"))
|
|
|
+ ok, str := func() (bool, string) {
|
|
|
+ //数据校验
|
|
|
+ date_count, date_unit, err := checkReqDate(date)
|
|
|
+ if err != nil {
|
|
|
+ return false, err.Error()
|
|
|
+ }
|
|
|
+ log.Println(area, industry, date, payWay)
|
|
|
+ //插入订单表
|
|
|
+ mog_id := public.MQFW.Save("subvip_select", map[string]interface{}{
|
|
|
+ "o_area": area, //地区(对象)
|
|
|
+ "a_industry": industry, //行业(数组)
|
|
|
+ "s_userid": userId,
|
|
|
+ "s_openid": openId,
|
|
|
+ "i_cyclecount": date_count, //时长
|
|
|
+ "i_cycleunit": date_unit, //单位
|
|
|
+ "i_comeintime": time.Now().Unix(),
|
|
|
+ })
|
|
|
+ if mog_id == "" {
|
|
|
+ return false, "创建订单出错"
|
|
|
+ }
|
|
|
+ //计算价格
|
|
|
+ totalfee := 1
|
|
|
+ //创建订单
|
|
|
+ tradeno, ret := public.WxStruct.CreatePrepayOrder(config.Sysconfig["weixinrpc"].(string), "e", this.IP(), openId, "", totalfee)
|
|
|
+ if ret == nil {
|
|
|
+ return false, "创建微信订单出错"
|
|
|
+ }
|
|
|
+ log.Println(tradeno, ret)
|
|
|
+ //存入订单表
|
|
|
+
|
|
|
+ //返回订单支付字符串
|
|
|
+ return true, ""
|
|
|
+ }()
|
|
|
+
|
|
|
+ this.ServeJson(map[string]interface{}{
|
|
|
+ "success": ok,
|
|
|
+ "Str": str,
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+//查询订单是否支付
|
|
|
+func (this *Order) IsPaySuccess() {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//cycleunit(1:年 2:月)
|
|
|
+//cyclecount 数字长度
|
|
|
+func checkReqDate(dateStr string) (cyclecount, cycleunit int, err error) {
|
|
|
+ if strings.HasSuffix(dateStr, "年") {
|
|
|
+ cycleunit = 1
|
|
|
+ dateStr = strings.Replace(dateStr, "年", "", -1)
|
|
|
+ cyclecount, err = strconv.Atoi(dateStr)
|
|
|
+ if cyclecount > 3 && err == nil {
|
|
|
+ err = errors.New(fmt.Sprintf("日期%s返回超出最大值", dateStr))
|
|
|
+ }
|
|
|
+ return
|
|
|
+ } else if strings.HasSuffix(dateStr, "月") {
|
|
|
+ cycleunit = 1
|
|
|
+ dateStr = strings.Replace(dateStr, "个月", "", -1)
|
|
|
+ cyclecount, err = strconv.Atoi(dateStr)
|
|
|
+ if cyclecount > 12 && err == nil {
|
|
|
+ err = errors.New(fmt.Sprintf("日期%s范围超出最大值", dateStr))
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return -1, -1, errors.New(fmt.Sprintf("日期%s格式化出错", dateStr))
|
|
|
+}
|