|
@@ -0,0 +1,99 @@
|
|
|
+package controller
|
|
|
+
|
|
|
+import (
|
|
|
+ . "app.yhyue.com/moapp/jybase/api"
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "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"
|
|
|
+ "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["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["operator"] = jyutil.GetUserMsgFromCtx(r.Context()).EntUserId
|
|
|
+ data["source"] = 3
|
|
|
+ data["invoice_status"] = 1
|
|
|
+ if param.Id == 0 {
|
|
|
+ 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": 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
|
|
|
+}
|