|
@@ -143,15 +143,9 @@ func ApplyServiceUpdate(companyId, productId, sellerId, companyContractId int, s
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- sql := `UPDATE company_product SET status='正式',start_date=?,end_date=?,modify_time=NOW() WHERE company_id=? AND product_id=? `
|
|
|
- _, err = o.Raw(sql, startDate, endDate, companyId, productId).Exec()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
//合同权限变更
|
|
|
items := make([]*models.CompanyReportPermission, 0)
|
|
|
- sql = `SELECT * FROM company_report_permission WHERE company_id=? AND product_id=? `
|
|
|
+ sql := `SELECT * FROM company_report_permission WHERE company_id=? AND product_id=? `
|
|
|
_, err = o.Raw(sql, companyId, productId).QueryRows(&items)
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -160,6 +154,18 @@ func ApplyServiceUpdate(companyId, productId, sellerId, companyContractId int, s
|
|
|
//已存在的权限map
|
|
|
nowCompanyReportPermissionMap := make(map[int]*models.CompanyReportPermission)
|
|
|
|
|
|
+ //产品服务的开始、结束日期(非产品权限)
|
|
|
+ updateStartDate := startDate
|
|
|
+ updateStartDateTime, err := time.Parse(utils.FormatDate, updateStartDate)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ updateEndDate := endDate
|
|
|
+ updateEndDateTime, err := time.Parse(utils.FormatDate, updateEndDate)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
for _, pv := range items {
|
|
|
cpLog := new(models.CompanyPermissionLog)
|
|
|
cpLog.CompanyId = companyId
|
|
@@ -175,6 +181,26 @@ func ApplyServiceUpdate(companyId, productId, sellerId, companyContractId int, s
|
|
|
|
|
|
//将权限插入到已存在的权限map中
|
|
|
nowCompanyReportPermissionMap[pv.ChartPermissionId] = pv
|
|
|
+
|
|
|
+ //校验原始数据中的开始日期是否小于合同内的开始日期,如果小于,那么变更为原先的合同开始日期
|
|
|
+ tmpStartDate, tmpErr := time.Parse(utils.FormatDate, pv.StartDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if tmpStartDate.Before(updateStartDateTime) {
|
|
|
+ updateStartDateTime = tmpStartDate
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验原始数据中的结束日期是否大于合同内的结束日期,如果大于,那么变更为原先的合同结束日期
|
|
|
+ tmpEndDate, tmpErr := time.Parse(utils.FormatDate, pv.EndDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if tmpEndDate.After(updateEndDateTime) {
|
|
|
+ updateEndDateTime = tmpEndDate
|
|
|
+ }
|
|
|
}
|
|
|
//删除所有权限
|
|
|
//sql = `DELETE FROM company_report_permission WHERE company_id=? AND product_id=? `
|
|
@@ -183,6 +209,13 @@ func ApplyServiceUpdate(companyId, productId, sellerId, companyContractId int, s
|
|
|
// return
|
|
|
//}
|
|
|
|
|
|
+ //更新客户产品信息
|
|
|
+ sql = `UPDATE company_product SET status='正式',start_date=?,end_date=?,modify_time=NOW() WHERE company_id=? AND product_id=? `
|
|
|
+ _, err = o.Raw(sql, updateStartDateTime, updateEndDateTime, companyId, productId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
contractPermission := make([]*company_contract.CompanyContractPermission, 0)
|
|
|
sql = `SELECT * FROM company_contract_permission WHERE company_contract_id=? AND company_id=? `
|
|
|
_, err = o.Raw(sql, companyContractId, companyId).QueryRows(&contractPermission)
|