|
@@ -194,10 +194,6 @@ func (this *Invoice) Addinvoice() error {
|
|
|
phone_num := this.GetString("phone_num")
|
|
|
code := strings.ToUpper(this.GetString("id_num")) //纳税人识别号
|
|
|
isSys, _ := this.GetBool("isSys")
|
|
|
- newPrice, _ := this.GetFloat("price")
|
|
|
- if newPrice <= 0 {
|
|
|
- return errors.New("金额不能为0")
|
|
|
- }
|
|
|
jsonData := ReturnJson{}
|
|
|
invoice_status := -1 //发票表开票失败
|
|
|
updata_status := false //更新表状态
|
|
@@ -209,152 +205,139 @@ func (this *Invoice) Addinvoice() error {
|
|
|
u := util.Mysql.FindOne("dataexport_order", map[string]interface{}{"order_code": order_code, "user_id": userId, "applyBill_status": map[string]interface{}{"ne": 2}}, "order_money,product_type,order_channel,pay_way,pay_money,is_backstage_order,billingMode", "")
|
|
|
if u != nil {
|
|
|
//后端代用户下单支持开票 order_channel = xdqd04
|
|
|
- //if qutil.IntAll((*u)["billingMode"]) == 1 && (qutil.IntAll((*u)["is_backstage_order"]) != 1 || qutil.InterfaceToStr((*u)["order_channel"]) == "xdqd04") {
|
|
|
- //获取此订单开票中与已开票的订单金额
|
|
|
- var (
|
|
|
- oldPrices, prices float64
|
|
|
- )
|
|
|
- oldData := util.Mysql.SelectBySql(fmt.Sprintf(`SELECT SUM(invoice_money) as invoice_money FROM %s WHERE order_code = '%s' and user_id = '%s' and invoice_status in (0,1)`, dbname, order_code, userId))
|
|
|
- if oldData != nil && len(*oldData) > 0 {
|
|
|
- oldPrices = qutil.Float64All((*oldData)[0]["invoice_money"])
|
|
|
- }
|
|
|
- //公对公转账 账单金额可以修改 开发票应取实付金额 pay_money
|
|
|
- //微信支付宝支付 pay_money为订单金额减去微信or支付包红包
|
|
|
- if qutil.ObjToString((*u)["pay_way"]) == "transferAccounts" {
|
|
|
- prices = qutil.Float64All((*u)["pay_money"]) / float64(100)
|
|
|
- } else {
|
|
|
- prices = qutil.Float64All((*u)["order_money"]) / float64(100)
|
|
|
- }
|
|
|
- if prices < oldPrices+newPrice {
|
|
|
- log.Println("开票金额已查出订单实际金额")
|
|
|
- jsonData["invoice_status"] = -3
|
|
|
- this.ServeJson(jsonData)
|
|
|
- return nil
|
|
|
- }
|
|
|
- price = strconv.FormatFloat(newPrice, 'f', -1, 64)
|
|
|
- product_name = (*u)["product_type"].(string)
|
|
|
- applyBill_status = 1
|
|
|
- data := make(map[string]interface{})
|
|
|
- dataexport_data := make(map[string]interface{})
|
|
|
- dataexport_data["applyBill_status"] = applyBill_status
|
|
|
- if applyBill_type == "个人" {
|
|
|
- dataexport_data["applyBill_type"] = 0
|
|
|
- data["taxpayer_identnum"] = ""
|
|
|
- data["company_name"] = ""
|
|
|
- dataexport_data["applyBill_taxnum"] = ""
|
|
|
- dataexport_data["applybill_company"] = ""
|
|
|
- } else {
|
|
|
- data["taxpayer_identnum"] = code
|
|
|
- data["company_name"] = applyBill_company
|
|
|
- dataexport_data["applyBill_taxnum"] = code
|
|
|
- dataexport_data["applybill_company"] = applyBill_company
|
|
|
- dataexport_data["applyBill_type"] = 1
|
|
|
- }
|
|
|
- dataexport_data["user_mail"] = my_email
|
|
|
- data["product_type"] = product_name
|
|
|
- data["order_code"] = order_code
|
|
|
- data["mail"] = my_email
|
|
|
- data["phone"] = phone_num
|
|
|
- data["invoice_type"] = applyBill_type
|
|
|
- data["invoice_changed"] = 0
|
|
|
- data["create_time"] = time.Now().Unix()
|
|
|
- data["user_id"] = userId
|
|
|
- data["invoice_status"] = 0
|
|
|
- data["invoice_money"] = price
|
|
|
- var orders = []map[string]interface{}{}
|
|
|
- var items = []map[string]interface{}{}
|
|
|
- item := map[string]interface{}{
|
|
|
- "name": product_name,
|
|
|
- "code": config.InvoiceConfig.Code,
|
|
|
- "yhzcbs": config.InvoiceConfig.Tax_policy,
|
|
|
- "lineType": config.InvoiceConfig.Invoice_nature,
|
|
|
- "taxRate": config.InvoiceConfig.Tax_rate,
|
|
|
- "taxPrice": price,
|
|
|
- "totalAmount": price,
|
|
|
- "quantity": "1",
|
|
|
- }
|
|
|
- items = append(items, item)
|
|
|
- order := map[string]interface{}{
|
|
|
- "billNo": order_code,
|
|
|
- "items": items,
|
|
|
- }
|
|
|
- orders = append(orders, order)
|
|
|
- client := &http.Client{}
|
|
|
- body := map[string]interface{}{
|
|
|
- "Swno": order_code,
|
|
|
- "custType": "03",
|
|
|
- "orders": orders,
|
|
|
- "custTaxNo": code,
|
|
|
- "phone": phone_num,
|
|
|
- "billDate": NowFormat(Date_Full_Layout), //单据日期 格式:yyyy-MM-dd HH:mm:ss
|
|
|
- }
|
|
|
-
|
|
|
- if applyBill_type == "单位" {
|
|
|
- body["custName"] = applyBill_company
|
|
|
- } else {
|
|
|
- body["custName"] = applyBill_type
|
|
|
- }
|
|
|
- //发送请求之前插入数据,防止请求时间过长
|
|
|
- if !isSys {
|
|
|
- status := util.Mysql.Find(dbname, map[string]interface{}{"order_code": order_code, "user_id": userId}, "", "create_time", 0, 0)
|
|
|
- if len(*status) > 0 {
|
|
|
- return nil
|
|
|
+ if qutil.IntAll((*u)["billingMode"]) == 1 && (qutil.IntAll((*u)["is_backstage_order"]) != 1 || qutil.InterfaceToStr((*u)["order_channel"]) == "xdqd04") {
|
|
|
+ var prices float64
|
|
|
+ //公对公转账 账单金额可以修改 开发票应取实付金额 pay_money
|
|
|
+ //微信支付宝支付 pay_money为订单金额减去微信or支付包红包
|
|
|
+ if qutil.ObjToString((*u)["pay_way"]) == "transferAccounts" {
|
|
|
+ prices = qutil.Float64All((*u)["pay_money"]) / float64(100)
|
|
|
+ } else {
|
|
|
+ prices = qutil.Float64All((*u)["order_money"]) / float64(100)
|
|
|
}
|
|
|
- if i := util.Mysql.Insert(dbname, data); i > 0 {
|
|
|
- invoice_status = 0
|
|
|
+ price = strconv.FormatFloat(prices, 'f', -1, 64)
|
|
|
+ product_name = (*u)["product_type"].(string)
|
|
|
+ applyBill_status = 1
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ dataexport_data := make(map[string]interface{})
|
|
|
+ dataexport_data["applyBill_status"] = applyBill_status
|
|
|
+ if applyBill_type == "个人" {
|
|
|
+ dataexport_data["applyBill_type"] = 0
|
|
|
+ data["taxpayer_identnum"] = ""
|
|
|
+ data["company_name"] = ""
|
|
|
+ dataexport_data["applyBill_taxnum"] = ""
|
|
|
+ dataexport_data["applybill_company"] = ""
|
|
|
+ } else {
|
|
|
+ data["taxpayer_identnum"] = code
|
|
|
+ data["company_name"] = applyBill_company
|
|
|
+ dataexport_data["applyBill_taxnum"] = code
|
|
|
+ dataexport_data["applybill_company"] = applyBill_company
|
|
|
+ dataexport_data["applyBill_type"] = 1
|
|
|
}
|
|
|
- if !util.Mysql.Update("dataexport_order", map[string]interface{}{"order_code": order_code, "user_id": userId}, dataexport_data) {
|
|
|
- invoice_status = -1
|
|
|
+ dataexport_data["user_mail"] = my_email
|
|
|
+ data["product_type"] = product_name
|
|
|
+ data["order_code"] = order_code
|
|
|
+ data["mail"] = my_email
|
|
|
+ data["phone"] = phone_num
|
|
|
+ data["invoice_type"] = applyBill_type
|
|
|
+ data["invoice_changed"] = 0
|
|
|
+ data["create_time"] = time.Now().Unix()
|
|
|
+ data["user_id"] = userId
|
|
|
+ data["invoice_status"] = 0
|
|
|
+ data["invoice_money"] = price
|
|
|
+ var orders = []map[string]interface{}{}
|
|
|
+ var items = []map[string]interface{}{}
|
|
|
+ item := map[string]interface{}{
|
|
|
+ "name": product_name,
|
|
|
+ "code": config.InvoiceConfig.Code,
|
|
|
+ "yhzcbs": config.InvoiceConfig.Tax_policy,
|
|
|
+ "lineType": config.InvoiceConfig.Invoice_nature,
|
|
|
+ "taxRate": config.InvoiceConfig.Tax_rate,
|
|
|
+ "taxPrice": price,
|
|
|
+ "totalAmount": price,
|
|
|
+ "quantity": "1",
|
|
|
}
|
|
|
- } else {
|
|
|
- if ok := util.Mysql.Update(dbname, map[string]interface{}{
|
|
|
- "order_code": order_code,
|
|
|
- "user_id": userId,
|
|
|
- "invoice_changed": 0,
|
|
|
- }, data); ok {
|
|
|
- invoice_status = 0
|
|
|
+ items = append(items, item)
|
|
|
+ order := map[string]interface{}{
|
|
|
+ "billNo": order_code,
|
|
|
+ "items": items,
|
|
|
}
|
|
|
- }
|
|
|
- if config.InvoiceConfig.Third_party_switch {
|
|
|
- b, _ := json.Marshal(body)
|
|
|
- buffer := bytes.NewBuffer(b)
|
|
|
- request, _ := http.NewRequest("POST", config.InvoiceConfig.Invoice_interface_address+"/Invoice/Add", buffer)
|
|
|
- response, err := client.Do(request)
|
|
|
- if err == nil {
|
|
|
- res, err := ioutil.ReadAll(response.Body)
|
|
|
- if err != nil {
|
|
|
+ orders = append(orders, order)
|
|
|
+ client := &http.Client{}
|
|
|
+ body := map[string]interface{}{
|
|
|
+ "Swno": order_code,
|
|
|
+ "custType": "03",
|
|
|
+ "orders": orders,
|
|
|
+ "custTaxNo": code,
|
|
|
+ "phone": phone_num,
|
|
|
+ "billDate": NowFormat(Date_Full_Layout), //单据日期 格式:yyyy-MM-dd HH:mm:ss
|
|
|
+ }
|
|
|
+
|
|
|
+ if applyBill_type == "单位" {
|
|
|
+ body["custName"] = applyBill_company
|
|
|
+ } else {
|
|
|
+ body["custName"] = applyBill_type
|
|
|
+ }
|
|
|
+ //发送请求之前插入数据,防止请求时间过长
|
|
|
+ if !isSys {
|
|
|
+ status := util.Mysql.Find(dbname, map[string]interface{}{"order_code": order_code, "user_id": userId}, "", "create_time", 0, 0)
|
|
|
+ if len(*status) > 0 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ if i := util.Mysql.Insert(dbname, data); i > 0 {
|
|
|
+ invoice_status = 0
|
|
|
+ }
|
|
|
+ if !util.Mysql.Update("dataexport_order", map[string]interface{}{"order_code": order_code, "user_id": userId}, dataexport_data) {
|
|
|
invoice_status = -1
|
|
|
- } else {
|
|
|
- resMap := qutil.ObjToMap(string(res))
|
|
|
- if *resMap != nil {
|
|
|
- if qutil.IntAll((*resMap)["code"]) == 0 { //开票成功
|
|
|
- invoice_status = 1
|
|
|
- jsonData["invoice_status"] = invoice_status
|
|
|
- } else if qutil.IntAll((*resMap)["code"]) == 2 { //开票中
|
|
|
- // log.Println("开票中")
|
|
|
- invoice_status = 0
|
|
|
- jsonData["invoice_status"] = invoice_status
|
|
|
- } else { //开票失败
|
|
|
- // log.Println("开票失败")
|
|
|
- invoice_status = -1
|
|
|
- jsonData["invoice_status"] = invoice_status
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ok := util.Mysql.Update(dbname, map[string]interface{}{
|
|
|
+ "order_code": order_code,
|
|
|
+ "user_id": userId,
|
|
|
+ "invoice_changed": 0,
|
|
|
+ }, data); ok {
|
|
|
+ invoice_status = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if config.InvoiceConfig.Third_party_switch {
|
|
|
+ b, _ := json.Marshal(body)
|
|
|
+ buffer := bytes.NewBuffer(b)
|
|
|
+ request, _ := http.NewRequest("POST", config.InvoiceConfig.Invoice_interface_address+"/Invoice/Add", buffer)
|
|
|
+ response, err := client.Do(request)
|
|
|
+ if err == nil {
|
|
|
+ res, err := ioutil.ReadAll(response.Body)
|
|
|
+ if err != nil {
|
|
|
+ invoice_status = -1
|
|
|
+ } else {
|
|
|
+ resMap := qutil.ObjToMap(string(res))
|
|
|
+ if *resMap != nil {
|
|
|
+ if qutil.IntAll((*resMap)["code"]) == 0 { //开票成功
|
|
|
+ invoice_status = 1
|
|
|
+ jsonData["invoice_status"] = invoice_status
|
|
|
+ } else if qutil.IntAll((*resMap)["code"]) == 2 { //开票中
|
|
|
+ // log.Println("开票中")
|
|
|
+ invoice_status = 0
|
|
|
+ jsonData["invoice_status"] = invoice_status
|
|
|
+ } else { //开票失败
|
|
|
+ // log.Println("开票失败")
|
|
|
+ invoice_status = -1
|
|
|
+ jsonData["invoice_status"] = invoice_status
|
|
|
+ }
|
|
|
+ }
|
|
|
+ defer response.Body.Close()
|
|
|
+ resData := (*resMap)["data"].(map[string]interface{})
|
|
|
+ update_status := util.Mysql.Update(dbname, map[string]interface{}{"order_code": order_code}, map[string]interface{}{
|
|
|
+ "invoice_serialnum": resData["swno"],
|
|
|
+ "invoice_code": resData["fpdm"],
|
|
|
+ "invoice_number": resData["fphm"],
|
|
|
+ "url": resData["path"],
|
|
|
+ "invoice_status": invoice_status,
|
|
|
+ })
|
|
|
+ if !update_status {
|
|
|
+ log.Println("order_ocde:", order_code+"update fail")
|
|
|
}
|
|
|
- }
|
|
|
- defer response.Body.Close()
|
|
|
- resData := (*resMap)["data"].(map[string]interface{})
|
|
|
- update_status := util.Mysql.Update(dbname, map[string]interface{}{"order_code": order_code}, map[string]interface{}{
|
|
|
- "invoice_serialnum": resData["swno"],
|
|
|
- "invoice_code": resData["fpdm"],
|
|
|
- "invoice_number": resData["fphm"],
|
|
|
- "url": resData["path"],
|
|
|
- "invoice_status": invoice_status,
|
|
|
- })
|
|
|
- if !update_status {
|
|
|
- log.Println("order_ocde:", order_code+"update fail")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //}
|
|
|
}
|
|
|
} else {
|
|
|
if invoice_status != 1 {
|