123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- package controller
- import (
- . "app.yhyue.com/moapp/jybase/api"
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/encrypt"
- "app.yhyue.com/moapp/jypkg/ent/util"
- "fmt"
- "github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/util/gconv"
- "github.com/pkg/errors"
- "jyOrderManager/internal/jyutil"
- "jyOrderManager/internal/model"
- "log"
- "time"
- )
- // InvoiceQuery 发票查询
- func InvoiceUpload(r *ghttp.Request) {
- rData, err := func() (interface{}, error) {
- var param model.InvoiceUploadParams
- err := gconv.Struct(r.GetBody(), ¶m)
- if err != nil {
- return nil, errors.Wrap(err, "数据校验异常")
- }
- data := make(map[string]interface{})
- orderInfo, _ := g.DB().GetOne(r.Context(), "SELECT create_time,product_type,user_mail,pay_money,create_time,signing_subject,applybill_status FROM dataexport_order WHERE order_code = ?", param.OrderCode)
- if orderInfo.IsEmpty() {
- return nil, errors.New("订单不存在")
- }
- if common.ObjToString(orderInfo.Map()["signing_subject"]) == "h02" {
- return nil, errors.New("签约主体为拓普")
- }
- data["order_code"] = param.OrderCode
- data["invoice_order_code"] = param.OrderCode
- data["invoice_money"] = param.AllMoney
- data["address_url"] = param.AddressUrl
- data["invoice_order_money"] = param.Money
- data["invoice_number"] = param.InvoiceNumber
- data["billing_time"] = param.BillingTime
- data["create_time"] = time.Now().Unix()
- data["invoicing_entity"] = param.SigningSubject
- data["invoice_variety"] = param.InvoiceVariety
- data["invoice_content"] = param.InvoiceContent
- data["invoice_type"] = param.InvoiceType
- data["company_name"] = param.CompanyName
- data["taxpayer_identnum"] = param.TaxpayerIdentnum
- data["delivery_address"] = param.DeliveryAddress
- data["phone"] = param.Phone
- data["bank_name"] = param.BankName
- data["bank_account"] = param.BankAccount
- data["remark"] = param.Remark
- data["mail"] = param.Email
- data["company_phone"] = param.CompanyPhone
- data["operator"] = jyutil.GetUserMsgFromCtx(r.Context()).EntUserName
- data["operable_time"] = time.Now().Format("2006-01-02 15:04:05")
- data["source"] = 3
- data["invoice_status"] = 1
- log.Println("发票上传参数", data, param.Id)
- if param.Id == "" {
- onlyIdentifying := fmt.Sprintf("%s%s%s", "aa", time.Now().Format("150405"), common.GetRandom(4))
- data["only_Identifying"] = onlyIdentifying
- data["user_id"] = orderInfo.Map()["user_id"]
- data["product_type"] = orderInfo.Map()["product_type"]
- g.DB().Save(r.Context(), "invoice", data)
- g.DB().Update(r.Context(), "dataexport_order", map[string]interface{}{
- "applybill_status": 2,
- }, map[string]interface{}{
- "order_code": param.OrderCode,
- })
- } else {
- g.DB().Update(r.Context(), "invoice", data, map[string]interface{}{
- "id": encrypt.SE.Decode4Hex(param.Id),
- })
- g.DB().Update(r.Context(), "dataexport_order", map[string]interface{}{
- "applybill_status": 2,
- }, map[string]interface{}{
- "order_code": param.OrderCode,
- })
- }
- return nil, nil
- }()
- if err != nil {
- g.Log().Errorf(r.Context(), "发票查询异常 %v", err)
- }
- r.Response.WriteJson(NewResult(rData, err))
- }
- func InvoiceAmount(orderCode string) (invoicedMoney int64) {
- invoicedInfo := util.Mysql.SelectBySql(fmt.Sprintf("SELECT invoice_order_money,only_Identifying FROM invoice WHERE order_code = '%s' and invoice_status>=0", orderCode))
- if invoicedInfo != nil && len(*invoicedInfo) > 0 {
- onlyMap := make(map[string]int64)
- for _, m := range *invoicedInfo {
- if m["only_Identifying"] != nil { //过滤换票过程中的数据
- onlyMap[common.InterfaceToStr(m["only_Identifying"])] = common.Int64All(m["invoice_order_money"])
- } else {
- invoicedMoney += common.Int64All(m["invoice_order_money"])
- }
- }
- if len(onlyMap) > 0 {
- for _, i := range onlyMap {
- invoicedMoney += i
- }
- }
- }
- return
- }
|