|
@@ -402,6 +402,113 @@ func FreezeToTryOut(companyId, productId, sellerId, companyApprovalId, applyUser
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// FreezeToTryOutXClassRai 权益冻结转X类试用
|
|
|
+func FreezeToTryOutXClassRai(companyId, productId, sellerId, companyApprovalId, applyUserId int, sellerName, productName string) (newCompanyReportPermissionList []*CompanyReportPermission, startDate, endDate string, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ to, err := o.Begin()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ tmpErr := to.Rollback()
|
|
|
+ if tmpErr != nil {
|
|
|
+ go alarm_msg.SendAlarmMsg("FreezeToTryOutXClassRai 事务回滚失败,Err:"+tmpErr.Error(), 3)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ err = to.Commit()
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ startDate = time.Now().Format(utils.FormatDate)
|
|
|
+ endDate = time.Now().AddDate(0, 3, 0).Format(utils.FormatDate)
|
|
|
+
|
|
|
+ sellerItem, err := system.GetSysAdminById(applyUserId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新用户产品状态
|
|
|
+ sql := `UPDATE company_product SET status='永续',is_suspend=0,approve_status='已审批',freeze_start_date=null,freeze_end_date=null,
|
|
|
+ start_date=?,end_date=?,seller_id=?,seller_name=?,group_id=?,department_id=?,modify_time=NOW(),try_stage=1 WHERE company_id=? AND product_id=? `
|
|
|
+ _, err = to.Raw(sql, startDate, endDate, sellerItem.AdminId, sellerItem.RealName, sellerItem.GroupId, sellerItem.DepartmentId, companyId, productId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //更新用户状态
|
|
|
+ sql = `UPDATE company SET type=5,last_updated_time=NOW() WHERE company_id=? `
|
|
|
+ _, err = to.Raw(sql, companyId).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=? `
|
|
|
+ _, err = to.Raw(sql, companyApprovalId, companyId, productId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询该用户所有产品权限,并把当前数据做日志(允许添加不修改的数据)
|
|
|
+ items := make([]*CompanyReportPermission, 0)
|
|
|
+ sql = `SELECT * FROM company_report_permission WHERE company_id=? AND product_id=? `
|
|
|
+ _, err = to.Raw(sql, companyId, productId).QueryRows(&items)
|
|
|
+ for _, pv := range items {
|
|
|
+ cpLog := new(CompanyPermissionLog)
|
|
|
+ cpLog.CompanyId = companyId
|
|
|
+ cpLog.ChartPermissionId = pv.ChartPermissionId
|
|
|
+ cpLog.CreateTime = time.Now()
|
|
|
+ cpLog.SysUserId = sellerId
|
|
|
+ cpLog.SysUserName = sellerName
|
|
|
+ cpLog.StartDate = pv.StartDate
|
|
|
+ cpLog.EndDate = pv.EndDate
|
|
|
+ cpLog.ProductId = productId
|
|
|
+ cpLog.ProductName = pv.ProductName
|
|
|
+ go AddCompanyPermissionLog(cpLog)
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询原先是否已经存在权限,如果有权限了,那么需要先删除原有的权限
|
|
|
+ count, _ := GetCompanyReportPermissionCount(companyId, productId)
|
|
|
+ if count > 0 {
|
|
|
+ sql := ` DELETE FROM company_report_permission WHERE company_id=? AND product_id=? `
|
|
|
+ _, err = to.Raw(sql, companyId, productId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取需要试用的权限
|
|
|
+ delayPermissionItems, tmpErr := GetDelayPermissionItems(companyId, companyApprovalId)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ status := `永续`
|
|
|
+ for _, v := range delayPermissionItems {
|
|
|
+ tmpCompanyReportPermission := &CompanyReportPermission{
|
|
|
+ //CompanyReportPermissionId: 0,
|
|
|
+ CompanyId: companyId,
|
|
|
+ ReportPermissionId: v.ChartPermissionId,
|
|
|
+ CreatedTime: time.Now(),
|
|
|
+ LastUpdatedTime: time.Now(),
|
|
|
+ ChartPermissionId: v.ChartPermissionId,
|
|
|
+ StartDate: v.StartDate,
|
|
|
+ EndDate: v.EndDate,
|
|
|
+ ProductId: productId,
|
|
|
+ ProductName: productName,
|
|
|
+ //CompanyContractId: companyContractId,
|
|
|
+ Status: status,
|
|
|
+ ModifyTime: time.Now(),
|
|
|
+ //IsUpgrade: pv.IsUpgrade,
|
|
|
+ }
|
|
|
+ newId, tmpErr := to.Insert(tmpCompanyReportPermission)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ tmpCompanyReportPermission.CompanyReportPermissionId = newId
|
|
|
+ newCompanyReportPermissionList = append(newCompanyReportPermissionList, tmpCompanyReportPermission)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// TryOutDelay 试用延期
|
|
|
func TryOutDelay(companyId, productId, sellerId, companyApprovalId int, sellerName, endDate, productName string) (newCompanyReportPermissionList []*CompanyReportPermission, newEndDate string, err error) {
|
|
|
o := orm.NewOrm()
|