zhangchuanxing il y a 2 jours
Parent
commit
5ec14de52e
2 fichiers modifiés avec 51 ajouts et 0 suppressions
  1. 44 0
      models/company/company_approval.go
  2. 7 0
      models/company/user_product.go

+ 44 - 0
models/company/company_approval.go

@@ -334,7 +334,50 @@ func TryOutToFormalByWxUser(companyId, productId, sellerId, companyApprovalId, c
 			return
 		}
 	} else {
+		itemuserProductDetail := new(UserProduct)
+		sql = ` SELECT * FROM user_product AS a WHERE user_id = ?  AND  product_id =  ? `
+		err = o.Raw(sql, userId, productId).QueryRow(&itemuserProductDetail)
+		if err != nil {
+			return
+		}
+
+		updateStartDateTime, tmpErr := time.Parse(utils.FormatDate, itemuserProductDetail.StartDate)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+
+		updateEndDateTime, tmpErr := time.Parse(utils.FormatDate, itemuserProductDetail.EndDate)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
 
+		//校验原始数据中的开始日期是否小于合同内的开始日期,如果小于,那么变更为原先的合同开始日期
+		tmpStartDate, tmpErr := time.Parse(utils.FormatDate, startDate)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		if tmpStartDate.Before(updateStartDateTime) {
+			updateStartDateTime = tmpStartDate
+		}
+
+		//校验原始数据中的结束日期是否大于合同内的结束日期,如果大于,那么变更为原先的合同结束日期
+		tmpEndDate, tmpErr := time.Parse(utils.FormatDate, endDate)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		if tmpEndDate.After(updateEndDateTime) {
+			updateEndDateTime = tmpEndDate
+		}
+
+		sql = `UPDATE user_product SET status='正式', start_date=?, end_date=?,modify_time=NOW() WHERE WHERE user_id = ?  AND  product_id =  ? `
+		_, err = to.Raw(sql, updateStartDateTime, updateEndDateTime, userId, productId).Exec()
+		if err != nil {
+			return
+		}
 	}
 
 	sql = `UPDATE company_approval SET approve_status='已审批',approve_time=NOW(),modify_time=NOW() WHERE company_approval_id=? AND company_id=? AND product_id=? `
@@ -342,6 +385,7 @@ func TryOutToFormalByWxUser(companyId, productId, sellerId, companyApprovalId, c
 	if err != nil {
 		return
 	}
+
 	items := make([]*UserReportPermission, 0)
 	sql = `SELECT * FROM user_report_permission WHERE company_id=? AND product_id=? `
 	_, err = to.Raw(sql, companyId, productId).QueryRows(&items)

+ 7 - 0
models/company/user_product.go

@@ -55,3 +55,10 @@ func GetUserProductByUserIds(userIds []int) (items []*UserProduct, err error) {
 	_, err = o.Raw(sql, userIds).QueryRows(&items)
 	return
 }
+
+func GetUserProductDetailByProductIdUserId(userId, productId int) (item *UserProduct, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM user_product AS a WHERE user_id = ?  AND  product_id =  ? `
+	err = o.Raw(sql, userId, productId).QueryRow(&item)
+	return
+}