|
@@ -122,128 +122,130 @@ func (this *Invoice) Addinvoice() error {
|
|
|
pos := qutil.IntAllDef(last, 0)
|
|
|
locks[pos].Lock()
|
|
|
defer locks[pos].Unlock()
|
|
|
- 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,pay_way,pay_money", "")
|
|
|
+ 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,pay_way,pay_money,is_backstage_order,billingMode", "")
|
|
|
if u != nil {
|
|
|
- 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)
|
|
|
- }
|
|
|
- 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
|
|
|
- }
|
|
|
- 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
|
|
|
- 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,
|
|
|
- }
|
|
|
- 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 {
|
|
|
+ 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)
|
|
|
}
|
|
|
- util.Mysql.Insert(dbname, data)
|
|
|
- if !util.Mysql.Update("dataexport_order", map[string]interface{}{"order_code": order_code, "user_id": userId}, dataexport_data) {
|
|
|
- invoice_status = -1
|
|
|
+ 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
|
|
|
}
|
|
|
- } else {
|
|
|
- util.Mysql.Update(dbname, map[string]interface{}{
|
|
|
- "order_code": order_code,
|
|
|
- "user_id": userId,
|
|
|
- "invoice_changed": 0,
|
|
|
- }, data)
|
|
|
- }
|
|
|
- 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
|
|
|
+ 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
|
|
|
+ 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,
|
|
|
+ }
|
|
|
+ if applyBill_type == "单位" {
|
|
|
+ body["custName"] = applyBill_company
|
|
|
} 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
|
|
|
- }
|
|
|
+ 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
|
|
|
}
|
|
|
- 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")
|
|
|
+ util.Mysql.Insert(dbname, data)
|
|
|
+ if !util.Mysql.Update("dataexport_order", map[string]interface{}{"order_code": order_code, "user_id": userId}, dataexport_data) {
|
|
|
+ invoice_status = -1
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ util.Mysql.Update(dbname, map[string]interface{}{
|
|
|
+ "order_code": order_code,
|
|
|
+ "user_id": userId,
|
|
|
+ "invoice_changed": 0,
|
|
|
+ }, data)
|
|
|
+ }
|
|
|
+ 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")
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|