company_contract.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. package company
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. type CompanyContract struct {
  9. CompanyContractId int `orm:"column(company_contract_id);pk" description:"客户合同id"`
  10. ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  11. ProductId int `description:"产品id"`
  12. ProductName string `description:"产品名称"`
  13. CompanyId int `description:"客户id"`
  14. CompanyProductId int `description:"客户产品id"`
  15. ContractCode string `description:"合同编码"`
  16. StartDate string `description:"合同开始时间"`
  17. EndDate string `description:"合同结束时间"`
  18. Money float64 `description:"合同金额"`
  19. PayMethod string `description:"支付方式"`
  20. PayChannel string `description:"支付渠道"`
  21. ImgUrl string `description:"合同图片,多个用#隔开"`
  22. CreateTime time.Time `description:"合同创建时间"`
  23. ModifyTime time.Time `description:"合同修改时间"`
  24. Status int `description:"状态"`
  25. Source string `description:"合同来源,枚举值:上传附件、系统合同,默认上传附件"`
  26. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  27. RaiPackageType int `description:"权益套餐类型: 0-无; 1-70w大套餐; 2-45w大套餐"`
  28. RaiContractType string `description:"权益合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  29. SellerIdInit int `description:"销售id"`
  30. SellerNameInit string `description:"销售名称"`
  31. ShareSellerInit string `description:"共享销售员"`
  32. ShareSellerIdInit int `description:"共享销售员id"`
  33. SellerIdLast int `description:"合同到期之前最后所属销售id"`
  34. SellerNameLast string `description:"合同到期之前最后所属销售名称"`
  35. ShareSellerLast string `description:"合同到期之前最后所属共享销售员"`
  36. ShareSellerIdLast int `description:"合同到期之前最后所属共享销售员id"`
  37. }
  38. // 新增客户合同
  39. func AddCompanyContract(item *CompanyContract) (lastId int64, err error) {
  40. o := orm.NewOrm()
  41. lastId, err = o.Insert(item)
  42. return
  43. }
  44. func GetCompanyContractByCompanyId(companyId int) (items []*CompanyContract, err error) {
  45. o := orm.NewOrm()
  46. sql := `SELECT * FROM company_contract WHERE company_id =? ORDER BY modify_time DESC `
  47. _, err = o.Raw(sql, companyId).QueryRows(&items)
  48. return
  49. }
  50. func GetCompanyContractCode() (companyCode string, err error) {
  51. var num int
  52. o := orm.NewOrm()
  53. sql := `SELECT COUNT(1) AS num FROM company_contract`
  54. err = o.Raw(sql).QueryRow(&num)
  55. if err != nil {
  56. return
  57. }
  58. companyCode = "HZ" + time.Now().Format("20060102") + fmt.Sprintf("%03d", num)
  59. return
  60. }
  61. type CompanyContractPermission struct {
  62. Id int `orm:"column(id);pk" description:"客户合同id"`
  63. CompanyId int `description:"客户id"`
  64. CompanyContractId int `description:"合同id"`
  65. ChartPermissionId int `description:"权限id"`
  66. IsUpgrade int `description:"是否升级,1是,0否"`
  67. ExpensiveYx int `description:"权益研选: 0-3w; 1-5w"`
  68. StartDate string `description:"开始日期"`
  69. EndDate string `description:"结束日期"`
  70. CreateTime time.Time `description:"创建时间"`
  71. ModifyTime time.Time `description:"修改时间"`
  72. ContractType string `description:"签约合同时,当前行业类型:枚举值:'行业新签','行业续约'"`
  73. PermissionName string `description:"权限名称"`
  74. Points float64 `description:"研选扣点包点数"`
  75. }
  76. // 新增客户合同
  77. func AddCompanyContractPermission(item *CompanyContractPermission) (err error) {
  78. o := orm.NewOrm()
  79. _, err = o.Insert(item)
  80. return
  81. }
  82. // MultiAddCompanyContractPermission 批量新增客户合同权限
  83. func MultiAddCompanyContractPermission(items []*CompanyContractPermission) (err error) {
  84. if len(items) == 0 {
  85. return
  86. }
  87. o := orm.NewOrm()
  88. _, err = o.InsertMulti(len(items), items)
  89. return
  90. }
  91. type CompanyContractPermissionLog struct {
  92. Id int `orm:"column(id);pk" description:"客户合同id"`
  93. CompanyId int `description:"客户id"`
  94. CompanyContractId int `description:"合同id"`
  95. ChartPermissionId string `description:"权限id"`
  96. StartDate string `description:"开始日期"`
  97. EndDate string `description:"结束日期"`
  98. CreateTime time.Time `description:"创建时间"`
  99. ModifyTime time.Time `description:"修改时间"`
  100. LogCreateTime time.Time
  101. }
  102. // 新增客户合同
  103. func AddCompanyContractPermissionLog(item *CompanyContractPermissionLog) (err error) {
  104. o := orm.NewOrm()
  105. _, err = o.Insert(item)
  106. return
  107. }
  108. // MultiAddCompanyContractPermissionLog 批量新增客户合同权限日志
  109. func MultiAddCompanyContractPermissionLog(items []*CompanyContractPermissionLog) (err error) {
  110. if len(items) == 0 {
  111. return
  112. }
  113. o := orm.NewOrm()
  114. _, err = o.InsertMulti(len(items), items)
  115. return
  116. }
  117. func GetCompanyContractPermissionCheck(companyId, permissionId int) (count int, err error) {
  118. o := orm.NewOrm()
  119. sql := `SELECT COUNT(1) AS count FROM company_contract_permission AS a WHERE a.company_id=? AND a.chart_permission_id=? `
  120. err = o.Raw(sql, companyId, permissionId).QueryRow(&count)
  121. return
  122. }
  123. func GetCompanyContractPermissionCheckByContractId(companyId, companyContractId, permissionId int) (count int, err error) {
  124. o := orm.NewOrm()
  125. sql := `SELECT COUNT(1) AS count FROM company_contract_permission AS a WHERE a.company_id=? AND company_contract_id=? AND a.chart_permission_id=? `
  126. err = o.Raw(sql, companyId, companyContractId, permissionId).QueryRow(&count)
  127. return
  128. }
  129. // GetCompanyContractPermissionByCompanyContractId 根据合同ID获取开通的权限
  130. func GetCompanyContractPermissionByCompanyContractId(companyContractId int) (items []*CompanyContractPermission, err error) {
  131. o := orm.NewOrm()
  132. sql := `SELECT * FROM company_contract_permission WHERE company_contract_id =? ORDER BY modify_time DESC `
  133. _, err = o.Raw(sql, companyContractId).QueryRows(&items)
  134. return
  135. }
  136. // 根据合同id集合字符串获取权限列表数据
  137. type CompanyContractPermissionName struct {
  138. Id int `orm:"column(id);pk" description:"客户合同id"`
  139. CompanyId int `description:"客户id"`
  140. CompanyContractId int `description:"合同id"`
  141. ChartPermissionId int `description:"权限id"`
  142. ChartPermissionName string `description:"权限名称"`
  143. PermissionName string `description:"权限名称"`
  144. PermissionRemark string `description:"权限备注"`
  145. ClassifyName string `description:"权限分类名称"`
  146. StartDate string `description:"开始日期"`
  147. EndDate string `description:"结束日期"`
  148. CreateTime time.Time `json:"-" description:"创建时间"`
  149. ModifyTime time.Time `json:"-" description:"修改时间"`
  150. IsUpgrade int `description:"是否升级,1是,0否"`
  151. }
  152. // 根据企业客户id获取已经审核通过的合同列表
  153. func GetCompanyContractListByCompanyId(companyId int, condition string, pars []interface{}) (items []*CompanyContract, err error) {
  154. o := orm.NewOrm()
  155. sql := `SELECT * FROM company_contract WHERE company_id =? `
  156. if condition != "" {
  157. sql += condition
  158. }
  159. sql += " ORDER BY modify_time DESC"
  160. _, err = o.Raw(sql, companyId, pars).QueryRows(&items)
  161. return
  162. }
  163. // 根据合同Id集合获取合同的权限列表
  164. func GetCompanyContractPermissionListByContractIds(companyContractIds string) (list []*CompanyContractPermissionName, err error) {
  165. o := orm.NewOrm()
  166. sql := `SELECT a.*,b.permission_name,b.remark permission_remark,b.chart_permission_name,b.classify_name FROM company_contract_permission AS a left join chart_permission b on a.chart_permission_id = b.chart_permission_id WHERE company_contract_id in (` + companyContractIds + `) `
  167. _, err = o.Raw(sql).QueryRows(&list)
  168. return
  169. }
  170. // GetCompanyContractDetailByCompanyContractId 根据客户合同id获取合同信息
  171. func GetCompanyContractDetailByCompanyContractId(companyContractId int) (item *CompanyContract, err error) {
  172. o := orm.NewOrm()
  173. sql := `SELECT * FROM company_contract WHERE company_contract_id =? ORDER BY modify_time DESC `
  174. err = o.Raw(sql, companyContractId).QueryRow(&item)
  175. return
  176. }
  177. // GetCompanyContractPermissionListByContractId 根据合同Id获取合同的权限列表
  178. func GetCompanyContractPermissionListByContractId(companyContractId int) (list []*CompanyContractPermissionName, err error) {
  179. o := orm.NewOrm()
  180. sql := `SELECT a.*,b.chart_permission_name,b.classify_name FROM company_contract_permission AS a left join chart_permission b on a.chart_permission_id = b.chart_permission_id WHERE company_contract_id =? `
  181. _, err = o.Raw(sql, companyContractId).QueryRows(&list)
  182. return
  183. }
  184. func GetCompanyContractUpgradePermissionCheckByContractId(companyId, companyContractId, permissionId, isUpgrade int) (count int, err error) {
  185. o := orm.NewOrm()
  186. sql := `SELECT COUNT(1) AS count FROM company_contract_permission AS a WHERE a.company_id=? AND company_contract_id=? AND a.chart_permission_id=? AND a.is_upgrade=? `
  187. err = o.Raw(sql, companyId, companyContractId, permissionId, isUpgrade).QueryRow(&count)
  188. return
  189. }
  190. type CompanyContractResp struct {
  191. CompanyContractId int `orm:"column(company_contract_id);pk" description:"客户合同id"`
  192. ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  193. ProductId int `description:"产品id"`
  194. ProductName string `description:"产品名称"`
  195. CompanyId int `description:"客户id"`
  196. CompanyProductId int `description:"客户产品id"`
  197. ContractCode string `description:"合同编码"`
  198. StartDate string `description:"合同开始时间"`
  199. EndDate string `description:"合同结束时间"`
  200. Money float64 `description:"合同金额"`
  201. PayMethod string `description:"支付方式"`
  202. PayChannel string `description:"支付渠道"`
  203. ImgUrl string `description:"合同图片,多个用#隔开"`
  204. CreateTime time.Time `description:"合同创建时间"`
  205. ModifyTime time.Time `description:"合同修改时间"`
  206. Status int `description:"状态"`
  207. Source string `description:"合同来源,枚举值:上传附件、系统合同,默认上传附件"`
  208. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  209. RaiPackageType int `description:"权益套餐类型: 0-无; 1-70w大套餐; 2-45w大套餐"`
  210. PermissionName string `description:"权限名"`
  211. }
  212. // 获取合同列表
  213. func GetCompanyContractList(condition string, pars []interface{}) (items []*CompanyContractResp, err error) {
  214. o := orm.NewOrm()
  215. sql := `SELECT * FROM company_contract WHERE 1 = 1 `
  216. if condition != "" {
  217. sql += condition
  218. }
  219. _, err = o.Raw(sql, pars).QueryRows(&items)
  220. return
  221. }
  222. // 获取合同对应的权限列表
  223. func GetCompanyContractPermissionList(condition string, pars []interface{}) (items []*CompanyContractPermission, err error) {
  224. o := orm.NewOrm()
  225. sql := `SELECT * FROM company_contract_permission WHERE 1 = 1 `
  226. if condition != "" {
  227. sql += condition
  228. }
  229. _, err = o.Raw(sql, pars).QueryRows(&items)
  230. return
  231. }
  232. // UpdateCompanyContractPermissionMulti 批量修改
  233. func UpdateCompanyContractPermissionMulti(items []*CompanyContractPermission) (err error) {
  234. o, err := orm.NewOrm().Begin()
  235. if err != nil {
  236. return
  237. }
  238. defer func() {
  239. if err == nil {
  240. o.Commit()
  241. } else {
  242. o.Rollback()
  243. }
  244. }()
  245. //批量修改
  246. p, err := o.Raw("UPDATE company_contract_permission SET permission_name = ? ,contract_type = ? WHERE id = ?").Prepare()
  247. if err != nil {
  248. return
  249. }
  250. defer func() {
  251. _ = p.Close() // 别忘记关闭 statement
  252. }()
  253. for _, v := range items {
  254. _, err = p.Exec(v.PermissionName, v.ContractType, v.Id)
  255. if err != nil {
  256. return
  257. }
  258. }
  259. return
  260. }
  261. // 通过ID获取详情
  262. func GetCompanyContracDetail(condition string, pars []interface{}) (item *CompanyContractResp, err error) {
  263. o := orm.NewOrm()
  264. sql := `SELECT * FROM company_contract WHERE 1= 1 ` + condition
  265. err = o.Raw(sql, pars).QueryRow(&item)
  266. return
  267. }
  268. // 通过ID获取详情
  269. func GetCompanyContracList(condition string, pars []interface{}) (items []*CompanyContractResp, err error) {
  270. o := orm.NewOrm()
  271. sql := `SELECT * FROM company_contract WHERE 1= 1 ` + condition
  272. _, err = o.Raw(sql, pars).QueryRows(&items)
  273. return
  274. }
  275. type GetCompanyContractDetailResp struct {
  276. Detail *CompanyContractResp
  277. }
  278. type GetCompanyContractDetailListResp struct {
  279. List []*CompanyContractResp
  280. }
  281. // UpdateCompanyContractPackageDifference 更改合同与上一份合同金额对比信息
  282. func UpdateCompanyContractPackageDifference(packageDifference string, companyContractId int) (err error) {
  283. o := orm.NewOrm()
  284. sql := `UPDATE company_contract SET package_difference = ? WHERE company_contract_id=? `
  285. _, err = o.Raw(sql, packageDifference, companyContractId).Exec()
  286. return
  287. }
  288. // 更新合同类型
  289. func UpdateCompanyContractType(contractType string, companyContractId int) (err error) {
  290. o := orm.NewOrm()
  291. sql := `UPDATE company_contract SET contract_type = ? WHERE company_contract_id=? `
  292. _, err = o.Raw(sql, contractType, companyContractId).Exec()
  293. return
  294. }
  295. // GetLastContractListByEndDate 通过最近一份合同的日期获取早于该合同的最晚一份合同
  296. func GetLastContractListByEndDate(companyId, productId int, endDate string) (item *CompanyContract, err error) {
  297. o := orm.NewOrm()
  298. sql := "SELECT * FROM company_contract where company_id = ? AND product_id= ? AND end_date < ? AND status = 1 ORDER BY end_date desc"
  299. err = o.Raw(sql, companyId, productId, endDate).QueryRow(&item)
  300. return
  301. }
  302. // 获取权益近一年是否有新签合同
  303. func GetCompanyContractCountRaiByLastYear(companyId int, startDate string) (count int, err error) {
  304. o := orm.NewOrm()
  305. sql := `SELECT COUNT(1) AS total FROM company_contract AS a WHERE product_id = 2 AND rai_contract_type = '新签合同' AND company_id = ? AND start_date > ? `
  306. err = o.Raw(sql, companyId, startDate).QueryRow(&count)
  307. return
  308. }
  309. // UpdateCompanyContractRaiContractType 更新某些合同权益的标识,为新签合同
  310. func UpdateCompanyContractRaiContractTypeInit(companyContractId string) (err error) {
  311. o := orm.NewOrm()
  312. sql := `UPDATE company_contract SET rai_contract_type = '新签合同' WHERE company_contract_id IN (` + companyContractId + `) `
  313. _, err = o.Raw(sql).Exec()
  314. return
  315. }
  316. // UpdateCompanyContractCompanyAscribeId 更改权益未续约归因
  317. func UpdateCompanyContractCompanyAscribeId(companyAscribId, companyContractId int) (err error) {
  318. o := orm.NewOrm()
  319. sql := `UPDATE company_contract SET company_ascribe_id = ? WHERE company_contract_id=? `
  320. _, err = o.Raw(sql, companyAscribId, companyContractId).Exec()
  321. return
  322. }
  323. // GetFirstContractRai 权益获取第一份合同
  324. func GetFirstContractRai(companyId int) (item *CompanyContract, err error) {
  325. o := orm.NewOrm()
  326. sql := " SELECT * FROM company_contract WHERE company_id = ? AND product_id= 2 AND status = 1 ORDER BY start_date ASC LIMIT 1 "
  327. err = o.Raw(sql, companyId).QueryRow(&item)
  328. return
  329. }
  330. // 更新合同类型
  331. func UpdateCompanyContractTypeinit16_1_01(share_seller_init string, share_seller_id_init, companyId int) (err error) {
  332. o := orm.NewOrm()
  333. sql := `UPDATE company_contract SET share_seller_init = ? , share_seller_id_init = ? WHERE company_id = ? AND product_id= 2 `
  334. _, err = o.Raw(sql, share_seller_init, share_seller_id_init, companyId).Exec()
  335. return
  336. }
  337. // 更新合同类型
  338. func UpdateCompanyContractTypeinit16_1_02(seller_name_init string, seller_id_init, company_contract_id int) (err error) {
  339. o := orm.NewOrm()
  340. sql := `UPDATE company_contract SET seller_name_init = ? , seller_id_init = ? WHERE company_contract_id = ? AND product_id= 2 `
  341. _, err = o.Raw(sql, seller_name_init, seller_id_init, company_contract_id).Exec()
  342. return
  343. }
  344. // 合同未生效更新对应销售的信息
  345. func UpdateCompanyContractSellerNotEffective(sellerId, shareSellerInit int, sellerName, shareSeller string, companyContractId int) (err error) {
  346. o := orm.NewOrm()
  347. sql := `UPDATE company_contract SET seller_id_init = ? , seller_name_init = ? ,
  348. share_seller_id_init = ? , share_seller_init = ? ,
  349. seller_id_last = ? , seller_name_last = ? ,
  350. share_seller_id_last = ? , share_seller_last= ?
  351. WHERE company_contract_id = ? AND product_id= 2 `
  352. _, err = o.Raw(sql, sellerId, sellerName, shareSellerInit, shareSeller, sellerId, sellerName, shareSellerInit, shareSeller, companyContractId).Exec()
  353. return
  354. }
  355. // 合同未到期更新对应销售的信息
  356. func UpdateCompanyContractSellerUnexpired(sellerId, shareSellerInit int, sellerName, shareSeller string, companyContractId int) (err error) {
  357. o := orm.NewOrm()
  358. sql := `UPDATE company_contract SET
  359. seller_id_last = ? ,
  360. seller_name_last = ? ,
  361. share_seller_id_last = ? ,
  362. share_seller_last= ? WHERE company_contract_id = ? AND product_id= 2 `
  363. _, err = o.Raw(sql, sellerId, sellerName, shareSellerInit, shareSeller, companyContractId).Exec()
  364. return
  365. }
  366. type CompanyContractRespInit struct {
  367. MaxCompanyContractId int
  368. CompanyContractId int `orm:"column(company_contract_id);pk" description:"客户合同id"`
  369. ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  370. ProductId int `description:"产品id"`
  371. ProductName string `description:"产品名称"`
  372. CompanyId int `description:"客户id"`
  373. CompanyProductId int `description:"客户产品id"`
  374. ContractCode string `description:"合同编码"`
  375. StartDate string `description:"合同开始时间"`
  376. EndDate string `description:"合同结束时间"`
  377. Money float64 `description:"合同金额"`
  378. PayMethod string `description:"支付方式"`
  379. PayChannel string `description:"支付渠道"`
  380. ImgUrl string `description:"合同图片,多个用#隔开"`
  381. CreateTime time.Time `description:"合同创建时间"`
  382. ModifyTime time.Time `description:"合同修改时间"`
  383. Status int `description:"状态"`
  384. Source string `description:"合同来源,枚举值:上传附件、系统合同,默认上传附件"`
  385. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  386. RaiPackageType int `description:"权益套餐类型: 0-无; 1-70w大套餐; 2-45w大套餐"`
  387. PermissionName string `description:"权限名"`
  388. }
  389. // 通过ID获取详情
  390. func GetCompanyContracListInit(condition string, pars []interface{}) (items []*CompanyContractRespInit, err error) {
  391. o := orm.NewOrm()
  392. sql := `SELECT
  393. MAX( company_contract_id ) AS max_company_contract_id,
  394. COUNT(a.company_id) AS cc ,
  395. a.*
  396. FROM
  397. company_contract a
  398. JOIN company b ON a.company_id = b.company_id
  399. JOIN company_product c ON a.company_id = c.company_id
  400. AND a.product_id = c.product_id
  401. WHERE
  402. 1 = 1 -- AND b.company_name LIKE "%上海亘%"
  403. AND c.product_id = 2 -- AND b.company_name LIKE "%上海亘%"
  404. AND c.product_id = 2
  405. AND a.not_renewal_hide = 0
  406. AND a.STATUS = 1
  407. AND c.STATUS NOT IN ( "永续", "正式", "关闭" )
  408. AND a.company_contract_id NOT IN (SELECT company_contract_id FROM company_contract_no_renewed_ascribe )
  409. GROUP BY
  410. a.company_id
  411. ` + condition
  412. _, err = o.Raw(sql, pars).QueryRows(&items)
  413. return
  414. }
  415. // 通过ID获取详情
  416. func GetCompanyContracListInit_CRM_16_1(condition string, pars []interface{}) (items []*CompanyContractRespInit, err error) {
  417. o := orm.NewOrm()
  418. sql := `SELECT
  419. a.*
  420. FROM
  421. company_contract a
  422. JOIN company b ON a.company_id = b.company_id
  423. JOIN company_product c ON a.company_id = c.company_id
  424. AND a.product_id = c.product_id
  425. WHERE
  426. 1 = 1 -- AND b.company_name LIKE "%上海亘%"
  427. AND c.product_id = 2 -- AND b.company_name LIKE "%上海亘%"
  428. AND c.product_id = 2
  429. AND a.not_renewal_hide = 0
  430. AND a.STATUS = 1
  431. AND c.STATUS NOT IN ( "永续", "正式", "关闭" )
  432. AND a.company_contract_id NOT IN (SELECT company_contract_id FROM company_contract_no_renewed_ascribe )
  433. ` + condition
  434. _, err = o.Raw(sql, pars).QueryRows(&items)
  435. return
  436. }
  437. // 合同未生效更新对应销售的信息
  438. func UpdateCompanyContracthide(companyContractId []string) (err error) {
  439. o := orm.NewOrm()
  440. sql := `UPDATE company_contract SET not_renewal_hide = 1
  441. WHERE company_contract_id IN (` + strings.Join(companyContractId, ",") + `) `
  442. _, err = o.Raw(sql).Exec()
  443. return
  444. }