|
@@ -1,178 +1,178 @@
|
|
|
package service
|
|
|
|
|
|
import (
|
|
|
- "encoding/base64"
|
|
|
- "encoding/json"
|
|
|
- "errors"
|
|
|
- "fmt"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/config"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/entity"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/pay"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/util"
|
|
|
- "log"
|
|
|
- "net/rpc"
|
|
|
- "regexp"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
+ "encoding/base64"
|
|
|
+ "encoding/json"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/config"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/entity"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/pay"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/util"
|
|
|
+ "log"
|
|
|
+ "net/rpc"
|
|
|
+ "regexp"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
|
|
|
- . "app.yhyue.com/moapp/jybase/api"
|
|
|
- qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
- . "app.yhyue.com/moapp/jybase/date"
|
|
|
- "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- elastic "app.yhyue.com/moapp/jybase/esv1"
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/xweb"
|
|
|
- . "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
- "github.com/SKatiyar/qr"
|
|
|
- "go.mongodb.org/mongo-driver/bson"
|
|
|
+ . "app.yhyue.com/moapp/jybase/api"
|
|
|
+ qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
+ . "app.yhyue.com/moapp/jybase/date"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ elastic "app.yhyue.com/moapp/jybase/esv1"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/xweb"
|
|
|
+ . "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ "github.com/SKatiyar/qr"
|
|
|
+ "go.mongodb.org/mongo-driver/bson"
|
|
|
)
|
|
|
|
|
|
//付费公用方法
|
|
|
type CommonAction struct {
|
|
|
- *xweb.Action
|
|
|
- getwxSdkSign xweb.Mapper `xweb:"/wx/getwxSdkSign"` //微信js参数
|
|
|
- getDomain xweb.Mapper `xweb:"/getDomain"` //微信js参数
|
|
|
- getCommonOrderPrice xweb.Mapper `xweb:"/common/getOrderPrice"` //获取订单价格
|
|
|
- getCommonPayParam xweb.Mapper `xweb:"/common/getPayParam"` //公共获取支付方法
|
|
|
- saveTransferAccounts xweb.Mapper `xweb:"/common/saveTransferAccounts"` //公共对公转账接口
|
|
|
- isPaySuccess xweb.Mapper `xweb:"/isPaySuccess"` //是否支付成功
|
|
|
- deleteOrder xweb.Mapper `xweb:"/deleteOrder"` //删除订单
|
|
|
- applyInvoice xweb.Mapper `xweb:"/applyInvoice"` //申请发票
|
|
|
- sendMailNote xweb.Mapper `xweb:"/sendMailNote/(.*)"` //发送附件邮件通知
|
|
|
- createorder xweb.Mapper `xweb:"/common/createorder"` //创建订单公共方法
|
|
|
+ *xweb.Action
|
|
|
+ getwxSdkSign xweb.Mapper `xweb:"/wx/getwxSdkSign"` //微信js参数
|
|
|
+ getDomain xweb.Mapper `xweb:"/getDomain"` //微信js参数
|
|
|
+ getCommonOrderPrice xweb.Mapper `xweb:"/common/getOrderPrice"` //获取订单价格
|
|
|
+ getCommonPayParam xweb.Mapper `xweb:"/common/getPayParam"` //公共获取支付方法
|
|
|
+ saveTransferAccounts xweb.Mapper `xweb:"/common/saveTransferAccounts"` //公共对公转账接口
|
|
|
+ isPaySuccess xweb.Mapper `xweb:"/isPaySuccess"` //是否支付成功
|
|
|
+ deleteOrder xweb.Mapper `xweb:"/deleteOrder"` //删除订单
|
|
|
+ applyInvoice xweb.Mapper `xweb:"/applyInvoice"` //申请发票
|
|
|
+ sendMailNote xweb.Mapper `xweb:"/sendMailNote/(.*)"` //发送附件邮件通知
|
|
|
+ createorder xweb.Mapper `xweb:"/common/createorder"` //创建订单公共方法
|
|
|
}
|
|
|
|
|
|
var pdfNameReg = regexp.MustCompilePOSIX(`[^//]*\.pdf`)
|
|
|
|
|
|
func (this *CommonAction) GetDomain() {
|
|
|
- this.ServeJson(NewResult(map[string]interface{}{
|
|
|
- "web": config.Config.WebDomain,
|
|
|
- "app": config.Config.AppDomain,
|
|
|
- "wx": config.Config.WxDomain,
|
|
|
- }, nil))
|
|
|
+ this.ServeJson(NewResult(map[string]interface{}{
|
|
|
+ "web": config.Config.WebDomain,
|
|
|
+ "app": config.Config.AppDomain,
|
|
|
+ "wx": config.Config.WxDomain,
|
|
|
+ }, nil))
|
|
|
}
|
|
|
|
|
|
func (this *CommonAction) SendMailNote(mailType string) {
|
|
|
- userId, _ := this.GetSession("userId").(string)
|
|
|
- rData, errMsg := func() (interface{}, error) {
|
|
|
- downurl := this.GetString("downurl")
|
|
|
- userMail := this.GetString("email")
|
|
|
- if downurl == "" || userMail == "" {
|
|
|
- return nil, fmt.Errorf("缺少字段")
|
|
|
- }
|
|
|
- //mailShowName := "附件"
|
|
|
- detail := "您好,您的附件已发送到您的邮箱,请查收!"
|
|
|
- mail_title := "剑鱼标讯"
|
|
|
- switch mailType {
|
|
|
- case "projectPdfFile":
|
|
|
- mail_title = "项目报告"
|
|
|
- detail = "您好,您的“%s”项目报告已发送到您的邮箱,请查收!"
|
|
|
- projectName, pid := "", ""
|
|
|
- strArr := pdfNameReg.FindStringSubmatch(downurl)
|
|
|
- if len(strArr) != 1 {
|
|
|
- return nil, fmt.Errorf("发送异常")
|
|
|
- }
|
|
|
- if arr := strings.Split(strings.ReplaceAll(strArr[0], ".pdf", ""), "_"); len(arr) != 0 {
|
|
|
- pid = arr[0]
|
|
|
- }
|
|
|
+ userId, _ := this.GetSession("userId").(string)
|
|
|
+ rData, errMsg := func() (interface{}, error) {
|
|
|
+ downurl := this.GetString("downurl")
|
|
|
+ userMail := this.GetString("email")
|
|
|
+ if downurl == "" || userMail == "" {
|
|
|
+ return nil, fmt.Errorf("缺少字段")
|
|
|
+ }
|
|
|
+ //mailShowName := "附件"
|
|
|
+ detail := "您好,您的附件已发送到您的邮箱,请查收!"
|
|
|
+ mail_title := "剑鱼标讯"
|
|
|
+ switch mailType {
|
|
|
+ case "projectPdfFile":
|
|
|
+ mail_title = "项目报告"
|
|
|
+ detail = "您好,您的“%s”项目报告已发送到您的邮箱,请查收!"
|
|
|
+ projectName, pid := "", ""
|
|
|
+ strArr := pdfNameReg.FindStringSubmatch(downurl)
|
|
|
+ if len(strArr) != 1 {
|
|
|
+ return nil, fmt.Errorf("发送异常")
|
|
|
+ }
|
|
|
+ if arr := strings.Split(strings.ReplaceAll(strArr[0], ".pdf", ""), "_"); len(arr) != 0 {
|
|
|
+ pid = arr[0]
|
|
|
+ }
|
|
|
|
|
|
- if pid != "" {
|
|
|
- res := elastic.Get("projectset", "projectset", fmt.Sprintf(`{"query": {"bool": {"must": [{"term": {"_id": "%s"}}]}},"_source":["projectname"],"from": 0,"size": 1}`, pid))
|
|
|
- if res != nil && len(*res) == 1 {
|
|
|
- projectName, _ = (*res)[0]["projectname"].(string)
|
|
|
- }
|
|
|
- }
|
|
|
- detail = fmt.Sprintf("您好,您的“%s”项目报告已发送到您的邮箱,请查收!", projectName)
|
|
|
- }
|
|
|
- if !(strings.HasPrefix(downurl, "https://") || strings.HasPrefix(downurl, "http://")) {
|
|
|
- downurl = config.Config.WebDomain + downurl
|
|
|
- }
|
|
|
- mailContent := fmt.Sprintf(config.ExConf.Mail_attach_common_attachment, detail, downurl)
|
|
|
- //用户发送邮件
|
|
|
- sendOk := false
|
|
|
- if userMail != "" {
|
|
|
- if sendOk = util.SendRetryMail(config.ExConf.Mail_retry, userMail, mail_title, mailContent, "", nil, config.GmailAuth); sendOk {
|
|
|
- log.Printf("DataExportPack SendMailNote 地址%s:邮箱%s邮件发送成功!", downurl, userMail)
|
|
|
- } else {
|
|
|
- sendErr := fmt.Sprintf("DataExportPack SendMailNote%s:邮箱%s邮件发送失败", downurl, userMail)
|
|
|
- log.Printf("%s DataExportPack SendMailNote 发送邮件失败 %v\n", userId, sendErr)
|
|
|
- }
|
|
|
- }
|
|
|
- return sendOk, nil
|
|
|
- }()
|
|
|
- if errMsg != nil {
|
|
|
- log.Printf("%s DataExportPack SendExportMail 异常:%s\n", userId, errMsg.Error())
|
|
|
- }
|
|
|
- this.ServeJson(NewResult(rData, errMsg))
|
|
|
+ if pid != "" {
|
|
|
+ res := elastic.Get("projectset", "projectset", fmt.Sprintf(`{"query": {"bool": {"must": [{"term": {"_id": "%s"}}]}},"_source":["projectname"],"from": 0,"size": 1}`, pid))
|
|
|
+ if res != nil && len(*res) == 1 {
|
|
|
+ projectName, _ = (*res)[0]["projectname"].(string)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ detail = fmt.Sprintf("您好,您的“%s”项目报告已发送到您的邮箱,请查收!", projectName)
|
|
|
+ }
|
|
|
+ if !(strings.HasPrefix(downurl, "https://") || strings.HasPrefix(downurl, "http://")) {
|
|
|
+ downurl = config.Config.WebDomain + downurl
|
|
|
+ }
|
|
|
+ mailContent := fmt.Sprintf(config.ExConf.Mail_attach_common_attachment, detail, downurl)
|
|
|
+ //用户发送邮件
|
|
|
+ sendOk := false
|
|
|
+ if userMail != "" {
|
|
|
+ if sendOk = util.SendRetryMail(config.ExConf.Mail_retry, userMail, mail_title, mailContent, "", nil, config.GmailAuth); sendOk {
|
|
|
+ log.Printf("DataExportPack SendMailNote 地址%s:邮箱%s邮件发送成功!", downurl, userMail)
|
|
|
+ } else {
|
|
|
+ sendErr := fmt.Sprintf("DataExportPack SendMailNote%s:邮箱%s邮件发送失败", downurl, userMail)
|
|
|
+ log.Printf("%s DataExportPack SendMailNote 发送邮件失败 %v\n", userId, sendErr)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sendOk, nil
|
|
|
+ }()
|
|
|
+ if errMsg != nil {
|
|
|
+ log.Printf("%s DataExportPack SendExportMail 异常:%s\n", userId, errMsg.Error())
|
|
|
+ }
|
|
|
+ this.ServeJson(NewResult(rData, errMsg))
|
|
|
}
|
|
|
|
|
|
//----------------------------申请发票------------------------------------
|
|
|
func (d *CommonAction) ApplyInvoice() error {
|
|
|
- var applyBill_status int
|
|
|
- var order_code, applyBill_company, applyBill_taxnum, applyBill_type string
|
|
|
- var updateBl bool = false
|
|
|
- order_code = d.GetString("order_code")
|
|
|
- //获取数据
|
|
|
- applyBill_type = d.GetString("demo-radio") //个人 单位
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "order_code": order_code,
|
|
|
- }
|
|
|
- my_email, product := "", ""
|
|
|
- product_type := util.Mysql.FindOne("dataexport_order", queryMap, "product_type", "")
|
|
|
- if product_type != nil {
|
|
|
- product = qutil.ObjToString((*product_type)["product_type"])
|
|
|
- }
|
|
|
- if product == "VIP订阅" {
|
|
|
- //获取开发票时 用户所绑定的邮箱 user--s_myemail
|
|
|
- email, _ := util.MQFW.FindOneByField("user", bson.M{"_id": StringTOBsonId(qutil.ObjToString(d.GetSession("userId")))}, `{"s_myemail":1}`)
|
|
|
- if len(*email) > 0 {
|
|
|
- my_email = qutil.ObjToString((*email)["s_myemail"])
|
|
|
- }
|
|
|
- }
|
|
|
- if applyBill_type == "个人" {
|
|
|
- applyBill_status = 1
|
|
|
- if product == "VIP订阅" && my_email != "" {
|
|
|
- updateBl = util.Mysql.Update("dataexport_order", queryMap, map[string]interface{}{"applyBill_status": applyBill_status, "user_mail": my_email})
|
|
|
- } else {
|
|
|
- updateBl = util.Mysql.Update("dataexport_order", queryMap, map[string]interface{}{"applyBill_status": applyBill_status})
|
|
|
- }
|
|
|
- } else if applyBill_type == "单位" {
|
|
|
- applyBill_status = 1 //状态
|
|
|
- applyBill_company = d.GetString("applyBill_company") //公司名
|
|
|
- applyBill_taxnum = d.GetString("applyBill_taxnum") //纳税人识别号
|
|
|
- if product == "VIP订阅" && my_email != "" {
|
|
|
- updateBl = util.Mysql.Update("dataexport_order", queryMap, map[string]interface{}{
|
|
|
- "applyBill_company": applyBill_company,
|
|
|
- "applyBill_taxnum": applyBill_taxnum,
|
|
|
- "applyBill_status": applyBill_status,
|
|
|
- "applyBill_type": 1,
|
|
|
- "user_mail": my_email,
|
|
|
- }) //修改操作
|
|
|
- } else {
|
|
|
- updateBl = util.Mysql.Update("dataexport_order", queryMap, map[string]interface{}{
|
|
|
- "applyBill_company": applyBill_company,
|
|
|
- "applyBill_taxnum": applyBill_taxnum,
|
|
|
- "applyBill_status": applyBill_status,
|
|
|
- "applyBill_type": 1,
|
|
|
- }) //修改操作
|
|
|
- }
|
|
|
- }
|
|
|
- //判断条件
|
|
|
- if updateBl {
|
|
|
- go func() {
|
|
|
- orderdata := util.Mysql.FindOne("dataexport_order", map[string]interface{}{
|
|
|
- "order_code": order_code,
|
|
|
- }, "id,filter,user_mail,user_phone,product_type,data_spec,filter_id,order_code,data_count,order_status,order_money,out_trade_no,applybill_type,applybill_company,applybill_taxnum,user_openid,create_time,pay_time,pay_way,pay_money,vip_starttime,vip_endtime,user_id,vip_type", "")
|
|
|
- tt := time.Now()
|
|
|
- pay_time := FormatDate(&tt, Date_Full_Layout)
|
|
|
- entity.SendMailToBJFinance(orderdata, pay_time, "", 2, config.GmailAuth)
|
|
|
- }()
|
|
|
- }
|
|
|
- d.ServeJson(map[string]interface{}{
|
|
|
- "flag": updateBl,
|
|
|
- })
|
|
|
- return nil
|
|
|
+ var applyBill_status int
|
|
|
+ var order_code, applyBill_company, applyBill_taxnum, applyBill_type string
|
|
|
+ var updateBl bool = false
|
|
|
+ order_code = d.GetString("order_code")
|
|
|
+ //获取数据
|
|
|
+ applyBill_type = d.GetString("demo-radio") //个人 单位
|
|
|
+ queryMap := map[string]interface{}{
|
|
|
+ "order_code": order_code,
|
|
|
+ }
|
|
|
+ my_email, product := "", ""
|
|
|
+ product_type := util.Mysql.FindOne("dataexport_order", queryMap, "product_type", "")
|
|
|
+ if product_type != nil {
|
|
|
+ product = qutil.ObjToString((*product_type)["product_type"])
|
|
|
+ }
|
|
|
+ if product == "VIP订阅" {
|
|
|
+ //获取开发票时 用户所绑定的邮箱 user--s_myemail
|
|
|
+ email, _ := util.MQFW.FindOneByField("user", bson.M{"_id": StringTOBsonId(qutil.ObjToString(d.GetSession("userId")))}, `{"s_myemail":1}`)
|
|
|
+ if len(*email) > 0 {
|
|
|
+ my_email = qutil.ObjToString((*email)["s_myemail"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if applyBill_type == "个人" {
|
|
|
+ applyBill_status = 1
|
|
|
+ if product == "VIP订阅" && my_email != "" {
|
|
|
+ updateBl = util.Mysql.Update("dataexport_order", queryMap, map[string]interface{}{"applyBill_status": applyBill_status, "user_mail": my_email})
|
|
|
+ } else {
|
|
|
+ updateBl = util.Mysql.Update("dataexport_order", queryMap, map[string]interface{}{"applyBill_status": applyBill_status})
|
|
|
+ }
|
|
|
+ } else if applyBill_type == "单位" {
|
|
|
+ applyBill_status = 1 //状态
|
|
|
+ applyBill_company = d.GetString("applyBill_company") //公司名
|
|
|
+ applyBill_taxnum = d.GetString("applyBill_taxnum") //纳税人识别号
|
|
|
+ if product == "VIP订阅" && my_email != "" {
|
|
|
+ updateBl = util.Mysql.Update("dataexport_order", queryMap, map[string]interface{}{
|
|
|
+ "applyBill_company": applyBill_company,
|
|
|
+ "applyBill_taxnum": applyBill_taxnum,
|
|
|
+ "applyBill_status": applyBill_status,
|
|
|
+ "applyBill_type": 1,
|
|
|
+ "user_mail": my_email,
|
|
|
+ }) //修改操作
|
|
|
+ } else {
|
|
|
+ updateBl = util.Mysql.Update("dataexport_order", queryMap, map[string]interface{}{
|
|
|
+ "applyBill_company": applyBill_company,
|
|
|
+ "applyBill_taxnum": applyBill_taxnum,
|
|
|
+ "applyBill_status": applyBill_status,
|
|
|
+ "applyBill_type": 1,
|
|
|
+ }) //修改操作
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断条件
|
|
|
+ if updateBl {
|
|
|
+ go func() {
|
|
|
+ orderdata := util.Mysql.FindOne("dataexport_order", map[string]interface{}{
|
|
|
+ "order_code": order_code,
|
|
|
+ }, "id,filter,user_mail,user_phone,product_type,data_spec,filter_id,order_code,data_count,order_status,order_money,out_trade_no,applybill_type,applybill_company,applybill_taxnum,user_openid,create_time,pay_time,pay_way,pay_money,vip_starttime,vip_endtime,user_id,vip_type", "")
|
|
|
+ tt := time.Now()
|
|
|
+ pay_time := FormatDate(&tt, Date_Full_Layout)
|
|
|
+ entity.SendMailToBJFinance(orderdata, pay_time, "", 2, config.GmailAuth)
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ d.ServeJson(map[string]interface{}{
|
|
|
+ "flag": updateBl,
|
|
|
+ })
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -180,129 +180,129 @@ func (d *CommonAction) ApplyInvoice() error {
|
|
|
根据 id+openid 删除
|
|
|
*/
|
|
|
func (d *CommonAction) DeleteOrder() error {
|
|
|
- if userId := d.GetSession("userId"); userId != nil {
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "id": d.GetString("id"),
|
|
|
- "user_id": userId.(string),
|
|
|
- }
|
|
|
- flag := false
|
|
|
- order := util.Mysql.FindOne(tableName_order, queryMap, "filter,product_type,pay_way,out_trade_no,prepay_time,order_status,order_code,discount_price,d_relation_id,user_id", "")
|
|
|
- if order != nil {
|
|
|
- if qutil.IntAll((*order)["order_status"]) == 0 && qutil.ObjToString((*order)["pay_way"]) != "transferAccounts" { //未支付状态下 删除订单需要先关闭订单
|
|
|
- flag = pay.CloseDataExportOrder(qutil.ObjToString((*order)["pay_way"]), qutil.ObjToString((*order)["out_trade_no"]), qutil.ObjToString((*order)["prepay_time"]))
|
|
|
- //未支付 非对公转账
|
|
|
- //卡卷取消绑定
|
|
|
- userLotteryId := qutil.ObjToString((*order)["d_relation_id"])
|
|
|
- if userLotteryId != "" {
|
|
|
- productType := 0 //商品类型0普通的1线上课程
|
|
|
- if product_type := qutil.ObjToString((*order)["product_type"]); product_type == "中标必听课" {
|
|
|
- productType = 1
|
|
|
- }
|
|
|
- discountId := ""
|
|
|
- var filter map[string]interface{}
|
|
|
- //关闭未支付订单
|
|
|
- if err := json.Unmarshal([]byte(qutil.ObjToString((*order)["filter"])), &filter); err != nil {
|
|
|
- log.Println("filter.json.Unmarshal出错", err)
|
|
|
- } else {
|
|
|
- if filter["discountId"] != nil {
|
|
|
- discountId = strconv.Itoa(qutil.IntAll(filter["discountId"]))
|
|
|
- }
|
|
|
- }
|
|
|
- order_code := qutil.ObjToString((*order)["order_code"])
|
|
|
- user_id := qutil.ObjToString((*order)["user_id"])
|
|
|
- go func(userId, userLotteryId, order_code string) {
|
|
|
- if !util.UpdateCouponState(userId, userLotteryId, qutil.ObjToString(d.GetSession("s_nickname")), qutil.ObjToString(d.GetSession("phone")), order_code, qutil.ObjToString((*order)["product_type"]), discountId, 0, productType) {
|
|
|
- log.Println(fmt.Sprintf("单号%s-解绑失败-卡卷%s", order_code, userLotteryId))
|
|
|
- }
|
|
|
- }(user_id, userLotteryId, order_code)
|
|
|
- }
|
|
|
- } else {
|
|
|
- flag = true
|
|
|
- }
|
|
|
- }
|
|
|
- if flag {
|
|
|
- now := time.Now()
|
|
|
- flag = util.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"del_status": 1, "del_time": FormatDate(&now, Date_Full_Layout)})
|
|
|
- }
|
|
|
- d.ServeJson(map[string]interface{}{"success": flag})
|
|
|
- }
|
|
|
- return nil
|
|
|
+ if userId := d.GetSession("userId"); userId != nil {
|
|
|
+ queryMap := map[string]interface{}{
|
|
|
+ "id": d.GetString("id"),
|
|
|
+ "user_id": userId.(string),
|
|
|
+ }
|
|
|
+ flag := false
|
|
|
+ order := util.Mysql.FindOne(tableName_order, queryMap, "filter,product_type,pay_way,out_trade_no,prepay_time,order_status,order_code,discount_price,d_relation_id,user_id", "")
|
|
|
+ if order != nil {
|
|
|
+ if qutil.IntAll((*order)["order_status"]) == 0 && qutil.ObjToString((*order)["pay_way"]) != "transferAccounts" { //未支付状态下 删除订单需要先关闭订单
|
|
|
+ flag = pay.CloseDataExportOrder(qutil.ObjToString((*order)["pay_way"]), qutil.ObjToString((*order)["out_trade_no"]), qutil.ObjToString((*order)["prepay_time"]))
|
|
|
+ //未支付 非对公转账
|
|
|
+ //卡卷取消绑定
|
|
|
+ userLotteryId := qutil.ObjToString((*order)["d_relation_id"])
|
|
|
+ if userLotteryId != "" {
|
|
|
+ productType := 0 //商品类型0普通的1线上课程
|
|
|
+ if product_type := qutil.ObjToString((*order)["product_type"]); product_type == "中标必听课" {
|
|
|
+ productType = 1
|
|
|
+ }
|
|
|
+ discountId := ""
|
|
|
+ var filter map[string]interface{}
|
|
|
+ //关闭未支付订单
|
|
|
+ if err := json.Unmarshal([]byte(qutil.ObjToString((*order)["filter"])), &filter); err != nil {
|
|
|
+ log.Println("filter.json.Unmarshal出错", err)
|
|
|
+ } else {
|
|
|
+ if filter["discountId"] != nil {
|
|
|
+ discountId = strconv.Itoa(qutil.IntAll(filter["discountId"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ order_code := qutil.ObjToString((*order)["order_code"])
|
|
|
+ user_id := qutil.ObjToString((*order)["user_id"])
|
|
|
+ go func(userId, userLotteryId, order_code string) {
|
|
|
+ if !util.UpdateCouponState(userId, userLotteryId, qutil.ObjToString(d.GetSession("s_nickname")), qutil.ObjToString(d.GetSession("phone")), order_code, qutil.ObjToString((*order)["product_type"]), discountId, 0, productType) {
|
|
|
+ log.Println(fmt.Sprintf("单号%s-解绑失败-卡卷%s", order_code, userLotteryId))
|
|
|
+ }
|
|
|
+ }(user_id, userLotteryId, order_code)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ flag = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if flag {
|
|
|
+ now := time.Now()
|
|
|
+ flag = util.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"del_status": 1, "del_time": FormatDate(&now, Date_Full_Layout)})
|
|
|
+ }
|
|
|
+ d.ServeJson(map[string]interface{}{"success": flag})
|
|
|
+ }
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
func (p *CommonAction) IsPaySuccess() {
|
|
|
- defer qutil.Catch()
|
|
|
- code := p.GetString("code")
|
|
|
- userId, _ := p.GetSession("userId").(string)
|
|
|
- if code != "" || userId != "" {
|
|
|
- data := util.Mysql.FindOne("dataexport_order", map[string]interface{}{
|
|
|
- "order_code": code,
|
|
|
- "user_id": userId,
|
|
|
- }, "order_status,pay_time,user_mail,pay_way,pay_money,filter", "")
|
|
|
- if data != nil && qutil.IntAll((*data)["order_status"]) == 1 {
|
|
|
- t, _ := time.ParseInLocation(Date_Full_Layout, qutil.ObjToString((*data)["pay_time"]), time.Local)
|
|
|
- p.ServeJson(map[string]interface{}{
|
|
|
- "success": true,
|
|
|
- "email": qutil.ObjToString((*data)["user_mail"]),
|
|
|
- "payTime": t.Unix(),
|
|
|
- "pay_way": (*data)["pay_way"],
|
|
|
- "price": (*data)["pay_money"],
|
|
|
- "filter": (*data)["filter"],
|
|
|
- "orderCode": code,
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- p.ServeJson(map[string]interface{}{
|
|
|
- "success": false,
|
|
|
- })
|
|
|
+ defer qutil.Catch()
|
|
|
+ code := p.GetString("code")
|
|
|
+ userId, _ := p.GetSession("userId").(string)
|
|
|
+ if code != "" || userId != "" {
|
|
|
+ data := util.Mysql.FindOne("dataexport_order", map[string]interface{}{
|
|
|
+ "order_code": code,
|
|
|
+ "user_id": userId,
|
|
|
+ }, "order_status,pay_time,user_mail,pay_way,pay_money,filter", "")
|
|
|
+ if data != nil && qutil.IntAll((*data)["order_status"]) == 1 {
|
|
|
+ t, _ := time.ParseInLocation(Date_Full_Layout, qutil.ObjToString((*data)["pay_time"]), time.Local)
|
|
|
+ p.ServeJson(map[string]interface{}{
|
|
|
+ "success": true,
|
|
|
+ "email": qutil.ObjToString((*data)["user_mail"]),
|
|
|
+ "payTime": t.Unix(),
|
|
|
+ "pay_way": (*data)["pay_way"],
|
|
|
+ "price": (*data)["pay_money"],
|
|
|
+ "filter": (*data)["filter"],
|
|
|
+ "orderCode": code,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ p.ServeJson(map[string]interface{}{
|
|
|
+ "success": false,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
func (d *CommonAction) GetwxSdkSign() {
|
|
|
- var sign []string
|
|
|
- url := d.GetString("url")
|
|
|
- if url != "" {
|
|
|
- sign = SignJSSDK(url)
|
|
|
- }
|
|
|
- nickname, _ := d.Session().Get("s_nickname").(string)
|
|
|
- avatar, _ := d.Session().Get("s_avatar").(string)
|
|
|
- openid := encrypt.SE.EncodeString(qutil.ObjToString(d.GetSession("s_m_openid")))
|
|
|
- d.ServeJson(map[string]interface{}{
|
|
|
- "wxsdk": sign,
|
|
|
- "wxDomain": config.Config.WxDomain,
|
|
|
- "nickname": nickname,
|
|
|
- "avatar": avatar,
|
|
|
- "openid": openid,
|
|
|
- })
|
|
|
+ var sign []string
|
|
|
+ url := d.GetString("url")
|
|
|
+ if url != "" {
|
|
|
+ sign = SignJSSDK(url)
|
|
|
+ }
|
|
|
+ nickname, _ := d.Session().Get("s_nickname").(string)
|
|
|
+ avatar, _ := d.Session().Get("s_avatar").(string)
|
|
|
+ openid := encrypt.SE.EncodeString(qutil.ObjToString(d.GetSession("s_m_openid")))
|
|
|
+ d.ServeJson(map[string]interface{}{
|
|
|
+ "wxsdk": sign,
|
|
|
+ "wxDomain": config.Config.WxDomain,
|
|
|
+ "nickname": nickname,
|
|
|
+ "avatar": avatar,
|
|
|
+ "openid": openid,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
func SignJSSDK(url string) []string {
|
|
|
- qutil.Catch()
|
|
|
- var signature []string
|
|
|
- var key = "wxsignature_" + url
|
|
|
- if ret := redis.Get("other", key); ret != nil {
|
|
|
- if d, err := json.Marshal(ret); err == nil {
|
|
|
- json.Unmarshal(d, &signature)
|
|
|
- }
|
|
|
- }
|
|
|
- if signature == nil || len(signature) == 0 {
|
|
|
- qutil.Try(func() {
|
|
|
- client, err := rpc.DialHTTP("tcp", config.Config.Weixinrpc)
|
|
|
- defer client.Close()
|
|
|
- if err != nil {
|
|
|
- log.Println(err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- err = client.Call("WeiXinRpc.GetJSInterfaceParam", url, &signature)
|
|
|
- if err != nil {
|
|
|
- log.Println(err.Error())
|
|
|
- }
|
|
|
- }, func(e interface{}) {})
|
|
|
- if signature == nil || len(signature) != 4 || signature[3] == "" {
|
|
|
- signature = []string{"", "", "", ""}
|
|
|
- } else {
|
|
|
- redis.Put("other", key, signature, 90*60)
|
|
|
- }
|
|
|
- }
|
|
|
- return signature
|
|
|
+ qutil.Catch()
|
|
|
+ var signature []string
|
|
|
+ var key = "wxsignature_" + url
|
|
|
+ if ret := redis.Get("other", key); ret != nil {
|
|
|
+ if d, err := json.Marshal(ret); err == nil {
|
|
|
+ json.Unmarshal(d, &signature)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if signature == nil || len(signature) == 0 {
|
|
|
+ qutil.Try(func() {
|
|
|
+ client, err := rpc.DialHTTP("tcp", config.Config.Weixinrpc)
|
|
|
+ defer client.Close()
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = client.Call("WeiXinRpc.GetJSInterfaceParam", url, &signature)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err.Error())
|
|
|
+ }
|
|
|
+ }, func(e interface{}) {})
|
|
|
+ if signature == nil || len(signature) != 4 || signature[3] == "" {
|
|
|
+ signature = []string{"", "", "", ""}
|
|
|
+ } else {
|
|
|
+ redis.Put("other", key, signature, 90*60)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return signature
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -311,25 +311,25 @@ param
|
|
|
orderCode 订单号
|
|
|
*/
|
|
|
func (this *CommonAction) GetCommonOrderPrice() {
|
|
|
- orderCode := this.GetString("orderCode")
|
|
|
- userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
- r := func() *entity.FuncResult {
|
|
|
- query := map[string]interface{}{
|
|
|
- "user_id": userId,
|
|
|
- "order_code": orderCode,
|
|
|
- }
|
|
|
- oData := util.Mysql.FindOne("dataexport_order", query, "order_money", "")
|
|
|
- if oData == nil || len(*oData) == 0 {
|
|
|
- return &entity.FuncResult{false, errors.New("未知订单"), nil}
|
|
|
- }
|
|
|
- return &entity.FuncResult{true, nil, map[string]interface{}{
|
|
|
- "price": (*oData)["order_money"],
|
|
|
- }}
|
|
|
- }()
|
|
|
- if r.Err != nil {
|
|
|
- log.Printf("%s GetCommonOrderPrice err:%v\n", userId, r.Err.Error())
|
|
|
- }
|
|
|
- this.ServeJson(r.Format())
|
|
|
+ orderCode := this.GetString("orderCode")
|
|
|
+ userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
+ r := func() *entity.FuncResult {
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "user_id": userId,
|
|
|
+ "order_code": orderCode,
|
|
|
+ }
|
|
|
+ oData := util.Mysql.FindOne("dataexport_order", query, "order_money", "")
|
|
|
+ if oData == nil || len(*oData) == 0 {
|
|
|
+ return &entity.FuncResult{false, errors.New("未知订单"), nil}
|
|
|
+ }
|
|
|
+ return &entity.FuncResult{true, nil, map[string]interface{}{
|
|
|
+ "price": (*oData)["order_money"],
|
|
|
+ }}
|
|
|
+ }()
|
|
|
+ if r.Err != nil {
|
|
|
+ log.Printf("%s GetCommonOrderPrice err:%v\n", userId, r.Err.Error())
|
|
|
+ }
|
|
|
+ this.ServeJson(r.Format())
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -340,84 +340,84 @@ payway 支付方式
|
|
|
dotype 产品类型
|
|
|
*/
|
|
|
func (this *CommonAction) GetCommonPayParam() {
|
|
|
- orderCode := this.GetString("orderCode")
|
|
|
- userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
- payway_req := this.GetString("payway")
|
|
|
- r := func() *entity.FuncResult {
|
|
|
- query := map[string]interface{}{
|
|
|
- "user_id": userId,
|
|
|
- "order_code": orderCode,
|
|
|
- "order_status": 0,
|
|
|
- }
|
|
|
- oData := util.Mysql.FindOne("dataexport_order", query, "id,code_url,prepay_time,pay_way,order_money,product_type,out_trade_no,course_status", "")
|
|
|
- if oData == nil || len(*oData) == 0 {
|
|
|
- return &entity.FuncResult{false, errors.New("未知订单"), nil}
|
|
|
- }
|
|
|
- //对公转账审核中
|
|
|
- if qutil.IntAll((*oData)["course_status"]) == 2 || qutil.IntAll((*oData)["course_status"]) == 4 {
|
|
|
- return &entity.FuncResult{false, errors.New("转账审核中,请勿重复支付"), nil}
|
|
|
- }
|
|
|
- payParam := qutil.ObjToString((*oData)["code_url"])
|
|
|
- payway := qutil.ObjToString((*oData)["pay_way"])
|
|
|
- totalfee := qutil.IntAll((*oData)["order_money"])
|
|
|
- //上次订单支付串是否可用
|
|
|
- if prepayTime, err := time.ParseInLocation(Date_Full_Layout, qutil.ObjToString((*oData)["prepay_time"]), time.Local); err == nil && payParam != "" {
|
|
|
- if time.Now().Before(prepayTime.Add(time.Hour * 2)) { //支付串未过期
|
|
|
- if payway == payway_req {
|
|
|
- if payParam != "" {
|
|
|
- return &entity.FuncResult{true, nil, map[string]interface{}{
|
|
|
- "orderCode": orderCode,
|
|
|
- "res": payParam,
|
|
|
- "price": totalfee,
|
|
|
- "timeout": prepayTime.Unix() + 2*60*60 - time.Now().Unix(),
|
|
|
- "payWay": payway}}
|
|
|
- }
|
|
|
- } else {
|
|
|
- //关闭之前支付串(防止重复支付)
|
|
|
- if !pay.CloseOrder(qutil.ObjToString((*oData)["out_trade_no"]), payway) {
|
|
|
- log.Printf("GetCommonPayParam 关闭订单%s出错\n", orderCode)
|
|
|
- return &entity.FuncResult{false, errors.New("支付方式切换异常"), nil}
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //重新生成支付串
|
|
|
- productFlag, ok := pay.PayWayAndSign[qutil.ObjToString((*oData)["product_type"])][payway_req]
|
|
|
- if !ok {
|
|
|
- return &entity.FuncResult{false, errors.New("未知支付类型:" + payway_req), nil}
|
|
|
- }
|
|
|
- tradeno, prepayid, payParam, err := pay.CreateOrderPay(totalfee, productFlag, this.IP(), qutil.ObjToString(this.GetSession("s_m_openid")), payway_req, orderCode)
|
|
|
- if err != nil {
|
|
|
- return &entity.FuncResult{false, errors.New(fmt.Sprintf("创建支付失败[%v]", err)), nil}
|
|
|
- }
|
|
|
- //更新订单表
|
|
|
- now := time.Now()
|
|
|
- ok = util.Mysql.Update("dataexport_order", query, map[string]interface{}{
|
|
|
- "code_url": payParam,
|
|
|
- "prepay_time": FormatDate(&now, Date_Full_Layout),
|
|
|
- "out_trade_no": tradeno,
|
|
|
- "prepay_id": prepayid,
|
|
|
- "pay_way": payway_req,
|
|
|
- })
|
|
|
- if !ok {
|
|
|
- return &entity.FuncResult{false, errors.New("数据库操作异常"), nil}
|
|
|
- }
|
|
|
- return &entity.FuncResult{true, nil, map[string]interface{}{
|
|
|
- "orderCode": orderCode,
|
|
|
- "res": payParam,
|
|
|
- "price": totalfee,
|
|
|
- "timeout": 2 * 60 * 60,
|
|
|
- "payWay": payway_req}}
|
|
|
- }()
|
|
|
- if r.Err != nil {
|
|
|
- log.Printf("%s GetCommonPayParam err:%v\n", userId, r.Err.Error())
|
|
|
- }
|
|
|
- if payway_req == "wx_pc" && r.Data["res"] != nil {
|
|
|
- rEncode, _ := qr.Encode(qutil.ObjToString(r.Data["res"]), qr.M)
|
|
|
- pngdat := rEncode.PNG()
|
|
|
- r.Data["res"] = base64.StdEncoding.EncodeToString(pngdat)
|
|
|
- }
|
|
|
- this.ServeJson(r.Format())
|
|
|
+ orderCode := this.GetString("orderCode")
|
|
|
+ userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
+ payway_req := this.GetString("payway")
|
|
|
+ r := func() *entity.FuncResult {
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "user_id": userId,
|
|
|
+ "order_code": orderCode,
|
|
|
+ "order_status": 0,
|
|
|
+ }
|
|
|
+ oData := util.Mysql.FindOne("dataexport_order", query, "id,code_url,prepay_time,pay_way,order_money,product_type,out_trade_no,course_status", "")
|
|
|
+ if oData == nil || len(*oData) == 0 {
|
|
|
+ return &entity.FuncResult{false, errors.New("未知订单"), nil}
|
|
|
+ }
|
|
|
+ //对公转账审核中
|
|
|
+ if qutil.IntAll((*oData)["course_status"]) == 2 || qutil.IntAll((*oData)["course_status"]) == 4 {
|
|
|
+ return &entity.FuncResult{false, errors.New("转账审核中,请勿重复支付"), nil}
|
|
|
+ }
|
|
|
+ payParam := qutil.ObjToString((*oData)["code_url"])
|
|
|
+ payway := qutil.ObjToString((*oData)["pay_way"])
|
|
|
+ totalfee := qutil.IntAll((*oData)["order_money"])
|
|
|
+ //上次订单支付串是否可用
|
|
|
+ if prepayTime, err := time.ParseInLocation(Date_Full_Layout, qutil.ObjToString((*oData)["prepay_time"]), time.Local); err == nil && payParam != "" {
|
|
|
+ if time.Now().Before(prepayTime.Add(time.Hour * 2)) { //支付串未过期
|
|
|
+ if payway == payway_req {
|
|
|
+ if payParam != "" {
|
|
|
+ return &entity.FuncResult{true, nil, map[string]interface{}{
|
|
|
+ "orderCode": orderCode,
|
|
|
+ "res": payParam,
|
|
|
+ "price": totalfee,
|
|
|
+ "timeout": prepayTime.Unix() + 2*60*60 - time.Now().Unix(),
|
|
|
+ "payWay": payway}}
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //关闭之前支付串(防止重复支付)
|
|
|
+ if !pay.CloseOrder(qutil.ObjToString((*oData)["out_trade_no"]), payway) {
|
|
|
+ log.Printf("GetCommonPayParam 关闭订单%s出错\n", orderCode)
|
|
|
+ return &entity.FuncResult{false, errors.New("支付方式切换异常"), nil}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //重新生成支付串
|
|
|
+ productFlag, ok := pay.PayWayAndSign[qutil.ObjToString((*oData)["product_type"])][payway_req]
|
|
|
+ if !ok {
|
|
|
+ return &entity.FuncResult{false, errors.New("未知支付类型:" + payway_req), nil}
|
|
|
+ }
|
|
|
+ tradeno, prepayid, payParam, err := pay.CreateOrderPay(totalfee, productFlag, this.IP(), qutil.ObjToString(this.GetSession("s_m_openid")), payway_req, orderCode)
|
|
|
+ if err != nil {
|
|
|
+ return &entity.FuncResult{false, errors.New(fmt.Sprintf("创建支付失败[%v]", err)), nil}
|
|
|
+ }
|
|
|
+ //更新订单表
|
|
|
+ now := time.Now()
|
|
|
+ ok = util.Mysql.Update("dataexport_order", query, map[string]interface{}{
|
|
|
+ "code_url": payParam,
|
|
|
+ "prepay_time": FormatDate(&now, Date_Full_Layout),
|
|
|
+ "out_trade_no": tradeno,
|
|
|
+ "prepay_id": prepayid,
|
|
|
+ "pay_way": payway_req,
|
|
|
+ })
|
|
|
+ if !ok {
|
|
|
+ return &entity.FuncResult{false, errors.New("数据库操作异常"), nil}
|
|
|
+ }
|
|
|
+ return &entity.FuncResult{true, nil, map[string]interface{}{
|
|
|
+ "orderCode": orderCode,
|
|
|
+ "res": payParam,
|
|
|
+ "price": totalfee,
|
|
|
+ "timeout": 2 * 60 * 60,
|
|
|
+ "payWay": payway_req}}
|
|
|
+ }()
|
|
|
+ if r.Err != nil {
|
|
|
+ log.Printf("%s GetCommonPayParam err:%v\n", userId, r.Err.Error())
|
|
|
+ }
|
|
|
+ if payway_req == "wx_pc" && r.Data["res"] != nil {
|
|
|
+ rEncode, _ := qr.Encode(qutil.ObjToString(r.Data["res"]), qr.M)
|
|
|
+ pngdat := rEncode.PNG()
|
|
|
+ r.Data["res"] = base64.StdEncoding.EncodeToString(pngdat)
|
|
|
+ }
|
|
|
+ this.ServeJson(r.Format())
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -430,202 +430,195 @@ dotype 产品类型
|
|
|
var imgReg = regexp.MustCompile(".*.(gif|jpeg|png|jpg)$")
|
|
|
|
|
|
func (this *CommonAction) SaveTransferAccounts() {
|
|
|
- orderCode := this.GetString("orderCode")
|
|
|
- transferV := this.GetString("transferV")
|
|
|
- userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
- productType := ""
|
|
|
- r := func() *entity.FuncResult {
|
|
|
- if !imgReg.MatchString(transferV) {
|
|
|
- return &entity.FuncResult{false, errors.New("上传图片异常"), nil}
|
|
|
- }
|
|
|
- query := map[string]interface{}{"order_code": orderCode, "user_id": userId}
|
|
|
- rSearch := util.Mysql.FindOne("dataexport_order", query, "order_status,product_type,filter,course_status,out_trade_no,pay_way", "")
|
|
|
- if rSearch == nil || len(*rSearch) == 0 {
|
|
|
- return &entity.FuncResult{false, errors.New("未查到订单数据"), nil}
|
|
|
- }
|
|
|
- if !(qutil.IntAll((*rSearch)["order_status"]) == 0 && (qutil.IntAll((*rSearch)["course_status"]) == 0 || qutil.IntAll((*rSearch)["course_status"]) == 1 || qutil.IntAll((*rSearch)["course_status"]) == 3)) {
|
|
|
- return &entity.FuncResult{false, errors.New("操作异常"), nil}
|
|
|
- }
|
|
|
- productType = qutil.ObjToString((*rSearch)["product_type"])
|
|
|
- if !(productType == "招投标课程" || productType == "大会员") {
|
|
|
- return &entity.FuncResult{false, errors.New("非法请求"), nil}
|
|
|
- }
|
|
|
- //保存更新filter
|
|
|
- filterStr := qutil.ObjToString((*rSearch)["filter"])
|
|
|
- mapTmp := map[string]interface{}{}
|
|
|
- if json.Unmarshal([]byte(filterStr), &mapTmp) != nil || len(mapTmp) == 0 {
|
|
|
- return &entity.FuncResult{false, errors.New("存储失败"), nil}
|
|
|
- }
|
|
|
- mapTmp["transferV"] = transferV
|
|
|
- mapTmp["transferVTime"] = time.Now().Format(Date_Full_Layout)
|
|
|
+ orderCode := this.GetString("orderCode")
|
|
|
+ transferV := this.GetString("transferV")
|
|
|
+ userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
+ productType := ""
|
|
|
+ r := func() *entity.FuncResult {
|
|
|
+ if !imgReg.MatchString(transferV) {
|
|
|
+ return &entity.FuncResult{false, errors.New("上传图片异常"), nil}
|
|
|
+ }
|
|
|
+ query := map[string]interface{}{"order_code": orderCode, "user_id": userId}
|
|
|
+ rSearch := util.Mysql.FindOne("dataexport_order", query, "order_status,product_type,filter,course_status,out_trade_no,pay_way", "")
|
|
|
+ if rSearch == nil || len(*rSearch) == 0 {
|
|
|
+ return &entity.FuncResult{false, errors.New("未查到订单数据"), nil}
|
|
|
+ }
|
|
|
+ if !(qutil.IntAll((*rSearch)["order_status"]) == 0 && (qutil.IntAll((*rSearch)["course_status"]) == 0 || qutil.IntAll((*rSearch)["course_status"]) == 1 || qutil.IntAll((*rSearch)["course_status"]) == 3)) {
|
|
|
+ return &entity.FuncResult{false, errors.New("操作异常"), nil}
|
|
|
+ }
|
|
|
+ productType = qutil.ObjToString((*rSearch)["product_type"])
|
|
|
+ if !(productType == "招投标课程" || productType == "大会员") {
|
|
|
+ return &entity.FuncResult{false, errors.New("非法请求"), nil}
|
|
|
+ }
|
|
|
+ //保存更新filter
|
|
|
+ filterStr := qutil.ObjToString((*rSearch)["filter"])
|
|
|
+ mapTmp := map[string]interface{}{}
|
|
|
+ if json.Unmarshal([]byte(filterStr), &mapTmp) != nil || len(mapTmp) == 0 {
|
|
|
+ return &entity.FuncResult{false, errors.New("存储失败"), nil}
|
|
|
+ }
|
|
|
+ mapTmp["transferV"] = transferV
|
|
|
+ mapTmp["transferVTime"] = time.Now().Format(Date_Full_Layout)
|
|
|
|
|
|
- finalStr, err := json.Marshal(mapTmp)
|
|
|
- if err != nil || string(filterStr) == "" {
|
|
|
- return &entity.FuncResult{false, errors.New("存储失败"), nil}
|
|
|
- }
|
|
|
- //保存更新filter--end
|
|
|
+ finalStr, err := json.Marshal(mapTmp)
|
|
|
+ if err != nil || string(filterStr) == "" {
|
|
|
+ return &entity.FuncResult{false, errors.New("存储失败"), nil}
|
|
|
+ }
|
|
|
+ //保存更新filter--end
|
|
|
|
|
|
- saveFlag := util.Mysql.Update("dataexport_order", query, map[string]interface{}{
|
|
|
- "course_status": 2, //公对公转账审核中----
|
|
|
- "pay_way": "transferAccounts",
|
|
|
- "filter": string(finalStr),
|
|
|
- })
|
|
|
+ saveFlag := util.Mysql.Update("dataexport_order", query, map[string]interface{}{
|
|
|
+ "course_status": 2, //公对公转账审核中----
|
|
|
+ "pay_way": "transferAccounts",
|
|
|
+ "filter": string(finalStr),
|
|
|
+ })
|
|
|
|
|
|
- if !saveFlag {
|
|
|
- return &entity.FuncResult{false, errors.New("保存失败"), nil}
|
|
|
- }
|
|
|
- go func() {
|
|
|
- entity.SendMailToOperation(1, orderCode, productType, config.GmailAuth)
|
|
|
- //关闭之前支付串(防止重复支付)
|
|
|
- if qutil.ObjToString((*rSearch)["pay_way"]) != "" {
|
|
|
- if !pay.CloseOrder(qutil.ObjToString((*rSearch)["out_trade_no"]), qutil.ObjToString((*rSearch)["pay_way"])) {
|
|
|
- log.Printf("SaveTransferAccounts 关闭订单%s出错\n", orderCode)
|
|
|
- }
|
|
|
- }
|
|
|
- }()
|
|
|
- return &entity.FuncResult{true, nil, nil}
|
|
|
- }()
|
|
|
- if r.Err != nil {
|
|
|
- log.Printf("%s SaveTransferAccounts [%s ,%s] err:%v\n", userId, orderCode, transferV, r.Err.Error())
|
|
|
- }
|
|
|
- this.ServeJson(r.Format())
|
|
|
+ if !saveFlag {
|
|
|
+ return &entity.FuncResult{false, errors.New("保存失败"), nil}
|
|
|
+ }
|
|
|
+ go func() {
|
|
|
+ entity.SendMailToOperation(1, orderCode, productType, config.GmailAuth)
|
|
|
+ //关闭之前支付串(防止重复支付)
|
|
|
+ if qutil.ObjToString((*rSearch)["pay_way"]) != "" {
|
|
|
+ if !pay.CloseOrder(qutil.ObjToString((*rSearch)["out_trade_no"]), qutil.ObjToString((*rSearch)["pay_way"])) {
|
|
|
+ log.Printf("SaveTransferAccounts 关闭订单%s出错\n", orderCode)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ return &entity.FuncResult{true, nil, nil}
|
|
|
+ }()
|
|
|
+ if r.Err != nil {
|
|
|
+ log.Printf("%s SaveTransferAccounts [%s ,%s] err:%v\n", userId, orderCode, transferV, r.Err.Error())
|
|
|
+ }
|
|
|
+ this.ServeJson(r.Format())
|
|
|
}
|
|
|
|
|
|
func (this *CommonAction) Createorder() {
|
|
|
- userid, _ := this.GetSession("userId").(string)
|
|
|
- rData, errMsg := func() (interface{}, error) {
|
|
|
- //参数接收
|
|
|
- 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("无效参数")
|
|
|
- }
|
|
|
- //产品类型
|
|
|
- product, _ := infoMap["product"].(string)
|
|
|
- if !config.Config.Product[product] {
|
|
|
- return nil, fmt.Errorf("请求产品类型有误")
|
|
|
- }
|
|
|
- productId := strconv.Itoa(qutil.IntAll(infoMap["productId"]))
|
|
|
+ userid, _ := this.GetSession("userId").(string)
|
|
|
+ rData, errMsg := func() (interface{}, error) {
|
|
|
+ //参数接收
|
|
|
+ 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("无效参数")
|
|
|
+ }
|
|
|
+ //产品类型
|
|
|
+ product, _ := infoMap["product"].(string)
|
|
|
+ if !config.Config.Product[product] {
|
|
|
+ return nil, fmt.Errorf("请求产品类型有误")
|
|
|
+ }
|
|
|
+ productId := strconv.Itoa(qutil.IntAll(infoMap["productId"]))
|
|
|
|
|
|
- //
|
|
|
- data, _ := infoMap["data"].(map[string]interface{})
|
|
|
- if len(data) <= 0 {
|
|
|
- return nil, fmt.Errorf("无效参数")
|
|
|
- }
|
|
|
- log.Println(infoMap)
|
|
|
+ //
|
|
|
+ data, _ := infoMap["data"].(map[string]interface{})
|
|
|
+ if len(data) <= 0 {
|
|
|
+ return nil, fmt.Errorf("无效参数")
|
|
|
+ }
|
|
|
+ log.Println(infoMap)
|
|
|
|
|
|
- //校验
|
|
|
- if err := entity.JyCommonOrderStruct.RequestCheck(product, data, this.Session()); err != "" {
|
|
|
- return nil, fmt.Errorf(err)
|
|
|
- }
|
|
|
+ //校验
|
|
|
+ if err := entity.JyCommonOrderStruct.RequestCheck(product, data, this.Session()); err != "" {
|
|
|
+ return nil, fmt.Errorf(err)
|
|
|
+ }
|
|
|
|
|
|
- //获取卡券相关
|
|
|
- lotteryId := qutil.ObjToString(data["lotteryId"]) //卡卷信息的id
|
|
|
- i_discountId := qutil.IntAll(data["discountId"]) //赠品相关
|
|
|
- discountId := strconv.Itoa(i_discountId)
|
|
|
+ //获取卡券相关
|
|
|
+ lotteryId := qutil.ObjToString(data["lotteryId"]) //卡卷信息的id
|
|
|
+ i_discountId := qutil.IntAll(data["discountId"]) //赠品相关
|
|
|
+ discountId := strconv.Itoa(i_discountId)
|
|
|
|
|
|
- inserMap, msg := entity.JyCommonOrderStruct.InserMap(product, productId, userid, lotteryId, discountId, data, this.Session())
|
|
|
- //错误信息
|
|
|
- if msg != "" {
|
|
|
- return nil, fmt.Errorf(msg)
|
|
|
- }
|
|
|
- now := time.Now()
|
|
|
- distributionChannel, orderChannel := util.GetJyOrderChannel(inserMap.DisWord, this.Header("User-Agent"))
|
|
|
- entId := qutil.Int64All(this.GetSession("entId"))
|
|
|
- buy_subject := 1
|
|
|
- if entId > 0 {
|
|
|
- buy_subject = 2
|
|
|
- }
|
|
|
- insertM := map[string]interface{}{
|
|
|
- "order_money": inserMap.OrderMoney,
|
|
|
- "order_status": inserMap.OrderStatus,
|
|
|
- "service_status": inserMap.ServiceStatus,
|
|
|
- "user_phone": inserMap.UserPhone,
|
|
|
- "order_code": inserMap.OrderCode,
|
|
|
- "product_type": product,
|
|
|
- "create_time": FormatDate(&now, Date_Full_Layout),
|
|
|
- "original_price": inserMap.OriginalPrice,
|
|
|
- "user_id": userid,
|
|
|
- "filter": inserMap.Filter,
|
|
|
- "discount_price": inserMap.DiscountPrice,
|
|
|
- "d_relation_id": inserMap.DrelationId,
|
|
|
- "data_spec": inserMap.DataSpec,
|
|
|
- "user_mail": inserMap.UserMail,
|
|
|
- "data_count": inserMap.DataCount,
|
|
|
- "filter_publishtime": inserMap.FilterPublishtime,
|
|
|
- "filter_keys": inserMap.FilterKeys,
|
|
|
- "download_url": inserMap.DownloadUrl,
|
|
|
- "dis_word": inserMap.DisWord,
|
|
|
- "distribution_channel": distributionChannel, //销售渠道
|
|
|
- "order_channel": orderChannel, //下单渠道
|
|
|
- "audit_status": 3, //默认审核通过
|
|
|
- "buy_subject": buy_subject,
|
|
|
- "ent_id": entId,
|
|
|
- }
|
|
|
+ inserMap, msg := entity.JyCommonOrderStruct.InserMap(product, productId, userid, lotteryId, discountId, data, this.Session())
|
|
|
+ //错误信息
|
|
|
+ if msg != "" {
|
|
|
+ return nil, fmt.Errorf(msg)
|
|
|
+ }
|
|
|
+ now := time.Now()
|
|
|
+ distributionChannel, orderChannel := util.GetJyOrderChannel(inserMap.DisWord, this.Header("User-Agent"))
|
|
|
+ insertM := map[string]interface{}{
|
|
|
+ "order_money": inserMap.OrderMoney,
|
|
|
+ "order_status": inserMap.OrderStatus,
|
|
|
+ "service_status": inserMap.ServiceStatus,
|
|
|
+ "user_phone": inserMap.UserPhone,
|
|
|
+ "order_code": inserMap.OrderCode,
|
|
|
+ "product_type": product,
|
|
|
+ "create_time": FormatDate(&now, Date_Full_Layout),
|
|
|
+ "original_price": inserMap.OriginalPrice,
|
|
|
+ "user_id": userid,
|
|
|
+ "filter": inserMap.Filter,
|
|
|
+ "discount_price": inserMap.DiscountPrice,
|
|
|
+ "d_relation_id": inserMap.DrelationId,
|
|
|
+ "data_spec": inserMap.DataSpec,
|
|
|
+ "user_mail": inserMap.UserMail,
|
|
|
+ "data_count": inserMap.DataCount,
|
|
|
+ "filter_publishtime": inserMap.FilterPublishtime,
|
|
|
+ "filter_keys": inserMap.FilterKeys,
|
|
|
+ "download_url": inserMap.DownloadUrl,
|
|
|
+ "dis_word": inserMap.DisWord,
|
|
|
+ "distribution_channel": distributionChannel, //销售渠道
|
|
|
+ "order_channel": orderChannel, //下单渠道
|
|
|
+ "audit_status": 3, //默认审核通过
|
|
|
+ }
|
|
|
|
|
|
- if openId := qutil.ObjToString(this.GetSession("s_m_openid")); openId != "" {
|
|
|
- insertM["user_openid"] = openId
|
|
|
- }
|
|
|
+ if openId := qutil.ObjToString(this.GetSession("s_m_openid")); openId != "" {
|
|
|
+ insertM["user_openid"] = openId
|
|
|
+ }
|
|
|
|
|
|
- if nickname := qutil.ObjToString(this.GetSession("s_nickname")); nickname != "" {
|
|
|
- insertM["user_nickname"] = nickname
|
|
|
- }
|
|
|
+ if nickname := qutil.ObjToString(this.GetSession("s_nickname")); nickname != "" {
|
|
|
+ insertM["user_nickname"] = nickname
|
|
|
+ }
|
|
|
|
|
|
- if inserMap.VipStartTime != "" && inserMap.VipEndTime != "" {
|
|
|
- insertM["vip_starttime"] = inserMap.VipStartTime
|
|
|
- insertM["vip_endtime"] = inserMap.VipEndTime
|
|
|
- }
|
|
|
- if inserMap.PrepayTime != "" {
|
|
|
- insertM["prepay_time"] = inserMap.PrepayTime
|
|
|
- }
|
|
|
- if inserMap.OutTradeNo != "" {
|
|
|
- insertM["out_trade_no"] = inserMap.OutTradeNo
|
|
|
- }
|
|
|
- if inserMap.PayWay != "" {
|
|
|
- insertM["pay_way"] = inserMap.PayWay
|
|
|
- }
|
|
|
- if inserMap.PrepayId != "" {
|
|
|
- insertM["prepay_id"] = inserMap.PrepayId
|
|
|
- }
|
|
|
- if inserMap.CodeUrl != "" {
|
|
|
- insertM["code_url"] = inserMap.CodeUrl
|
|
|
- }
|
|
|
- if inserMap.FilterId != "" {
|
|
|
- insertM["filter_id"] = inserMap.FilterId
|
|
|
- }
|
|
|
- if inserMap.VipType != 0 {
|
|
|
- insertM["vip_type"] = inserMap.VipType
|
|
|
- }
|
|
|
- if inserMap.ExpirationTime != "" {
|
|
|
- insertM["expiration_time"] = inserMap.ExpirationTime
|
|
|
- }
|
|
|
- orderid := util.Mysql.Insert("dataexport_order", insertM)
|
|
|
- //审核轨迹
|
|
|
- util.Mysql.Insert("audit_records", map[string]interface{}{
|
|
|
- "operator": "-",
|
|
|
- "create_time": NowFormat(Date_Full_Layout),
|
|
|
- "operator_type": 1,
|
|
|
- "audit_status": 3,
|
|
|
- "order_code": inserMap.OrderCode,
|
|
|
- "audit_type": 2,
|
|
|
- })
|
|
|
- if orderid <= 0 {
|
|
|
- return nil, fmt.Errorf("创建订单异常")
|
|
|
- }
|
|
|
- if i_discountId > 0 {
|
|
|
- util.FindUserLotteryId(userid, orderid, i_discountId)
|
|
|
- }
|
|
|
- rdata := map[string]interface{}{"order_code": inserMap.OrderCode, "needPay": !inserMap.UnNeedPay}
|
|
|
- return rdata, nil
|
|
|
- }()
|
|
|
- if errMsg != nil {
|
|
|
- log.Printf("%s CreateOrder 异常:%s\n", userid, errMsg.Error())
|
|
|
- }
|
|
|
- //创建完订单后更新卡券信息
|
|
|
- this.ServeJson(NewResult(rData, errMsg))
|
|
|
+ if inserMap.VipStartTime != "" && inserMap.VipEndTime != "" {
|
|
|
+ insertM["vip_starttime"] = inserMap.VipStartTime
|
|
|
+ insertM["vip_endtime"] = inserMap.VipEndTime
|
|
|
+ }
|
|
|
+ if inserMap.PrepayTime != "" {
|
|
|
+ insertM["prepay_time"] = inserMap.PrepayTime
|
|
|
+ }
|
|
|
+ if inserMap.OutTradeNo != "" {
|
|
|
+ insertM["out_trade_no"] = inserMap.OutTradeNo
|
|
|
+ }
|
|
|
+ if inserMap.PayWay != "" {
|
|
|
+ insertM["pay_way"] = inserMap.PayWay
|
|
|
+ }
|
|
|
+ if inserMap.PrepayId != "" {
|
|
|
+ insertM["prepay_id"] = inserMap.PrepayId
|
|
|
+ }
|
|
|
+ if inserMap.CodeUrl != "" {
|
|
|
+ insertM["code_url"] = inserMap.CodeUrl
|
|
|
+ }
|
|
|
+ if inserMap.FilterId != "" {
|
|
|
+ insertM["filter_id"] = inserMap.FilterId
|
|
|
+ }
|
|
|
+ if inserMap.VipType != 0 {
|
|
|
+ insertM["vip_type"] = inserMap.VipType
|
|
|
+ }
|
|
|
+ if inserMap.ExpirationTime != "" {
|
|
|
+ insertM["expiration_time"] = inserMap.ExpirationTime
|
|
|
+ }
|
|
|
+ orderid := util.Mysql.Insert("dataexport_order", insertM)
|
|
|
+ //审核轨迹
|
|
|
+ util.Mysql.Insert("audit_records", map[string]interface{}{
|
|
|
+ "operator": "-",
|
|
|
+ "create_time": NowFormat(Date_Full_Layout),
|
|
|
+ "operator_type": 1,
|
|
|
+ "audit_status": 3,
|
|
|
+ "order_code": inserMap.OrderCode,
|
|
|
+ "audit_type": 2,
|
|
|
+ })
|
|
|
+ if orderid <= 0 {
|
|
|
+ return nil, fmt.Errorf("创建订单异常")
|
|
|
+ }
|
|
|
+ if i_discountId > 0 {
|
|
|
+ util.FindUserLotteryId(userid, orderid, i_discountId)
|
|
|
+ }
|
|
|
+ rdata := map[string]interface{}{"order_code": inserMap.OrderCode, "needPay": !inserMap.UnNeedPay}
|
|
|
+ return rdata, nil
|
|
|
+ }()
|
|
|
+ if errMsg != nil {
|
|
|
+ log.Printf("%s CreateOrder 异常:%s\n", userid, errMsg.Error())
|
|
|
+ }
|
|
|
+ //创建完订单后更新卡券信息
|
|
|
+ this.ServeJson(NewResult(rData, errMsg))
|
|
|
}
|