company_product.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_task/utils"
  5. "time"
  6. )
  7. type CompanyOperationRecord struct {
  8. Id int `orm:"column(id);pk"`
  9. CompanyId int `description:"客户id"`
  10. CompanyName string `description:"客户名称"`
  11. SysUserId int `description:"操作者id"`
  12. SysRealName string `description:"操作者名称"`
  13. Remark string `description:"备注"`
  14. Operation string `description:"操作"`
  15. CreateTime time.Time `description:"操作时间"`
  16. ProductId int `description:"产品id"`
  17. ProductName string `description:"产品名称"`
  18. ApproveUserId int `description:"审批人id"`
  19. ApproveRealName string `description:"审批人姓名"`
  20. ApproveContent string `description:"审批人内容"`
  21. ApproveRemark string `description:"审批人内容"`
  22. Status string `description:"状态"`
  23. }
  24. // 新增操作记录
  25. func AddCompanyOperationRecord(item *CompanyOperationRecord) (lastId int64, err error) {
  26. o := orm.NewOrm()
  27. lastId, err = o.Insert(item)
  28. return
  29. }
  30. func CompanyFreeze(companyId, productId int) (companyReportPermissionList []*CompanyReportPermission, err error) {
  31. o := orm.NewOrm()
  32. freezeStartDate := time.Now().Format(utils.FormatDate)
  33. freezeEndDate := time.Now().AddDate(0, 3, 0).Format(utils.FormatDate)
  34. //FICC客户冻结期为六个月
  35. if productId == 1 {
  36. freezeEndDate = time.Now().AddDate(0, 6, 0).Format(utils.FormatDate)
  37. }
  38. // 权益客户 冻结期 改为两个月
  39. if productId == 2 {
  40. freezeEndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  41. }
  42. //客户产品 状态 变更
  43. sql := `UPDATE company_product SET status='冻结',is_formal=0,is_suspend=0,freeze_time=NOW(),modify_time=NOW(),start_date=?,end_date=?,freeze_start_date=?,freeze_end_date=?,try_stage=1 WHERE company_id=? AND product_id=? `
  44. _, err = o.Raw(sql, freezeStartDate, freezeEndDate, freezeStartDate, freezeEndDate, companyId, productId).Exec()
  45. if err != nil {
  46. return
  47. }
  48. //客户产品权限 状态 变更
  49. //获取需要变更的 客户产品权限
  50. oldPermissionEndDate := time.Now().AddDate(0, 0, -1).Format(utils.FormatDate)
  51. sql = `SELECT *
  52. FROM company_report_permission
  53. WHERE status='试用' AND end_date<=? AND company_id=? AND product_id=? `
  54. total, err := o.Raw(sql, oldPermissionEndDate, companyId, productId).QueryRows(&companyReportPermissionList)
  55. if err != nil {
  56. return
  57. }
  58. if total > 0 {
  59. sql = `UPDATE company_report_permission SET status='关闭',modify_time=NOW()
  60. WHERE status='试用' AND end_date<=? AND company_id=? AND product_id=? `
  61. _, err = o.Raw(sql, oldPermissionEndDate, companyId, productId).Exec()
  62. if err != nil {
  63. return
  64. }
  65. }
  66. //客户状态变更
  67. sql = `UPDATE company SET type=3,last_updated_time=NOW(),start_date=?,end_date=? WHERE company_id=? `
  68. _, err = o.Raw(sql, freezeStartDate, freezeEndDate, companyId).Exec()
  69. return
  70. }
  71. func CompanyFreezeRai(companyId, productId int) (companyReportPermissionList []*CompanyReportPermission, err error) {
  72. if productId != 2 {
  73. return
  74. }
  75. o := orm.NewOrm()
  76. freezeStartDate := time.Now().Format(utils.FormatDate)
  77. freezeEndDate := time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  78. //客户产品 状态 变更
  79. sql := `UPDATE company_product SET status='冻结',is_formal=0,is_suspend=0,freeze_time=NOW(),modify_time=NOW(),start_date=?,end_date=?,freeze_start_date=?,freeze_end_date=?,try_stage=1 WHERE company_id=? AND product_id=? `
  80. _, err = o.Raw(sql, freezeStartDate, freezeEndDate, freezeStartDate, freezeEndDate, companyId, productId).Exec()
  81. if err != nil {
  82. return
  83. }
  84. //客户产品权限 状态 变更
  85. //获取需要变更的 客户产品权限
  86. oldPermissionEndDate := time.Now().AddDate(0, 0, -1).Format(utils.FormatDate)
  87. sql = `SELECT *
  88. FROM company_report_permission
  89. WHERE status='正式' AND end_date<=? AND company_id=? AND product_id=? `
  90. total, err := o.Raw(sql, oldPermissionEndDate, companyId, productId).QueryRows(&companyReportPermissionList)
  91. if err != nil {
  92. return
  93. }
  94. if total > 0 {
  95. sql = `UPDATE company_report_permission SET status='关闭',modify_time=NOW()
  96. WHERE status='正式' AND end_date<=? AND company_id=? AND product_id=? `
  97. _, err = o.Raw(sql, oldPermissionEndDate, companyId, productId).Exec()
  98. if err != nil {
  99. return
  100. }
  101. }
  102. //客户状态变更
  103. sql = `UPDATE company SET type=3,last_updated_time=NOW(),start_date=?,end_date=? WHERE company_id=? `
  104. _, err = o.Raw(sql, freezeStartDate, freezeEndDate, companyId).Exec()
  105. return
  106. }
  107. func CompanyFreezeXClassRai(companyId, productId int) (companyReportPermissionList []*CompanyReportPermission, err error) {
  108. o := orm.NewOrm()
  109. freezeStartDate := time.Now().Format(utils.FormatDate)
  110. freezeEndDate := time.Now().AddDate(0, 3, 0).Format(utils.FormatDate)
  111. //FICC客户冻结期由三个月改为两个月
  112. //if productId == 1 {
  113. // freezeEndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  114. //}
  115. // 权益客户 冻结期 改为两个月
  116. if productId == 2 {
  117. freezeEndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  118. }
  119. //客户产品 状态 变更
  120. sql := `UPDATE company_product SET status='冻结',is_formal=0,is_suspend=0,freeze_time=NOW(),modify_time=NOW(),start_date=?,end_date=?,freeze_start_date=?,freeze_end_date=?,try_stage=1 WHERE company_id=? AND product_id=? `
  121. _, err = o.Raw(sql, freezeStartDate, freezeEndDate, freezeStartDate, freezeEndDate, companyId, productId).Exec()
  122. if err != nil {
  123. return
  124. }
  125. //客户产品权限 状态 变更
  126. //获取需要变更的 客户产品权限
  127. oldPermissionEndDate := time.Now().AddDate(0, 0, -1).Format(utils.FormatDate)
  128. sql = `SELECT *
  129. FROM company_report_permission
  130. WHERE status='永续' AND end_date<=? AND company_id=? AND product_id=? `
  131. total, err := o.Raw(sql, oldPermissionEndDate, companyId, productId).QueryRows(&companyReportPermissionList)
  132. if err != nil {
  133. return
  134. }
  135. if total > 0 {
  136. sql = `UPDATE company_report_permission SET status='关闭',modify_time=NOW()
  137. WHERE status='永续' AND end_date<=? AND company_id=? AND product_id=? `
  138. _, err = o.Raw(sql, oldPermissionEndDate, companyId, productId).Exec()
  139. if err != nil {
  140. return
  141. }
  142. }
  143. //客户状态变更
  144. sql = `UPDATE company SET type=3,last_updated_time=NOW(),start_date=?,end_date=? WHERE company_id=? `
  145. _, err = o.Raw(sql, freezeStartDate, freezeEndDate, companyId).Exec()
  146. return
  147. }
  148. func CompanyLoss(companyId, productId int) (err error) {
  149. o := orm.NewOrm()
  150. //客户产品状态变更
  151. sql := `UPDATE company_product SET status='流失',is_formal=0,loss_time=NOW(),modify_time=NOW(),lose_reason='冻结到期系统自动流失',try_stage=1,todo_status="无任务",todo_create_time=null,todo_approve_time=null,todo_modify_time=null,todo_end_time=null WHERE company_id=? AND product_id=? `
  152. _, err = o.Raw(sql, companyId, productId).Exec()
  153. if err != nil {
  154. return
  155. }
  156. // 将历史的任务给标记删除掉
  157. sql = `UPDATE company_todo SET is_delete=1,modify_time=NOW() WHERE company_id=? AND product_id=? AND is_delete = 0 `
  158. _, err = o.Raw(sql, companyId, productId).Exec()
  159. if err != nil {
  160. return
  161. }
  162. //客户状态变更
  163. sql = `UPDATE company SET type=3,last_updated_time=NOW() WHERE company_id=? `
  164. _, err = o.Raw(sql, companyId).Exec()
  165. if err != nil {
  166. return
  167. }
  168. return
  169. }
  170. // 正式转试用
  171. func CompanyTryOut(companyId, productId int) (companyReportPermissionList []*CompanyReportPermission, err error) {
  172. o := orm.NewOrm()
  173. startDate := time.Now().Format(utils.FormatDate)
  174. endDate := time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  175. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  176. endDate = time.Now().AddDate(0, 1, 0).Format(utils.FormatDate) // 权益客户试用期改为1个月。 需求池 1035
  177. }
  178. //客户产品 状态 变更
  179. sql := `UPDATE company_product SET status='试用',start_date=?,end_date=?,modify_time=NOW(),try_out_time=NOW(),renewal_reason="",package_type=0,try_stage=1 WHERE company_id=? AND product_id=? `
  180. _, err = o.Raw(sql, startDate, endDate, companyId, productId).Exec()
  181. if err != nil {
  182. return
  183. }
  184. //客户产品权限 状态 变更
  185. //获取需要变更的 客户产品权限
  186. oldPermissionEndDate := time.Now().AddDate(0, 0, -1).Format(utils.FormatDate)
  187. sql = `SELECT *
  188. FROM company_report_permission
  189. WHERE status='正式' AND end_date<=? AND company_id=? AND product_id=? `
  190. total, err := o.Raw(sql, oldPermissionEndDate, companyId, productId).QueryRows(&companyReportPermissionList)
  191. if err != nil {
  192. return
  193. }
  194. if total > 0 {
  195. sql = `UPDATE company_report_permission SET status='试用',start_date=?,end_date=?,modify_time=NOW()
  196. WHERE status='正式' AND end_date<=? AND company_id=? AND product_id=? `
  197. _, err = o.Raw(sql, startDate, endDate, oldPermissionEndDate, companyId, productId).Exec()
  198. if err != nil {
  199. return
  200. }
  201. }
  202. //客户状态变更
  203. sql = `UPDATE company SET type=2,last_updated_time=NOW(),start_date=?,end_date=? WHERE company_id=? `
  204. _, err = o.Raw(sql, startDate, endDate, companyId).Exec()
  205. return
  206. }
  207. // 权益正式转X类试用(永续)
  208. func CompanyTryOutXClassRai(companyId, productId int) (companyReportPermissionList []*CompanyReportPermission, err error) {
  209. o := orm.NewOrm()
  210. startDate := time.Now().Format(utils.FormatDate)
  211. endDate := time.Now().AddDate(0, 3, 0).Format(utils.FormatDate)
  212. //客户产品 状态 变更
  213. sql := `UPDATE company_product SET status='永续',start_date=?,end_date=?,modify_time=NOW(),try_out_time=NOW(),renewal_reason="",package_type=0,try_stage=1 WHERE company_id=? AND product_id=? `
  214. _, err = o.Raw(sql, startDate, endDate, companyId, productId).Exec()
  215. if err != nil {
  216. return
  217. }
  218. //客户产品权限 状态 变更
  219. //获取需要变更的 客户产品权限
  220. oldPermissionEndDate := time.Now().AddDate(0, 0, -1).Format(utils.FormatDate)
  221. sql = `SELECT *
  222. FROM company_report_permission
  223. WHERE status='正式' AND end_date<=? AND company_id=? AND product_id=? `
  224. total, err := o.Raw(sql, oldPermissionEndDate, companyId, productId).QueryRows(&companyReportPermissionList)
  225. if err != nil {
  226. return
  227. }
  228. if total > 0 {
  229. sql = `UPDATE company_report_permission SET status='永续',start_date=?,end_date=?,modify_time=NOW()
  230. WHERE status='正式' AND end_date<=? AND company_id=? AND product_id=? `
  231. _, err = o.Raw(sql, startDate, endDate, oldPermissionEndDate, companyId, productId).Exec()
  232. if err != nil {
  233. return
  234. }
  235. }
  236. //客户状态变更
  237. sql = `UPDATE company SET type=5,last_updated_time=NOW(),start_date=?,end_date=? WHERE company_id=? `
  238. _, err = o.Raw(sql, startDate, endDate, companyId).Exec()
  239. return
  240. }
  241. func GetCompanyOldDataSync() (items []*Company, err error) {
  242. sql := `SELECT * FROM company WHERE company_id NOT IN(
  243. SELECT company_id FROM company_product
  244. )
  245. AND company_id<>1 `
  246. o := orm.NewOrm()
  247. _, err = o.Raw(sql).QueryRows(&items)
  248. return
  249. }
  250. type CompanyProduct struct {
  251. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  252. CompanyId int `description:"客户id"`
  253. ProductId int `description:"产品id"`
  254. ProductName string `description:"产品名称"`
  255. CompanyName string `description:"客户名称"`
  256. Source string `description:"来源"`
  257. Reasons string `description:"新增理由"`
  258. Status string `description:"客户状态"`
  259. IndustryId int `description:"行业id"`
  260. IndustryName string `description:"行业名称"`
  261. SellerId int `description:"销售id"`
  262. SellerName string `description:"销售名称"`
  263. GroupId int `description:"销售分组id"`
  264. DepartmentId int `description:"销售部门id"`
  265. IsSuspend int `description:"1:暂停,0:启用"`
  266. SuspendTime time.Time `description:"暂停启用时间"`
  267. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  268. FreezeTime time.Time `description:"冻结时间"`
  269. Remark string `description:"备注信息"`
  270. CreateTime time.Time `description:"创建时间"`
  271. ModifyTime time.Time `description:"修改时间"`
  272. StartDate string `description:"开始日期"`
  273. EndDate string `description:"结束日期"`
  274. ContractEndDate string `description:"合同结束日期"`
  275. LoseReason string `description:"流失原因"`
  276. LossTime time.Time `description:"流失时间"`
  277. CompanyType string `description:"客户类型"`
  278. OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
  279. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  280. ViewTotal int `description:"总阅读次数"`
  281. RoadShowTotal int `description:"累计路演次数"`
  282. LastViewTime time.Time `description:"最后一次阅读时间"`
  283. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  284. IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"`
  285. TodoStatus string `description:"任务处理状态;枚举值:'无任务','未完成','已完成'"`
  286. TodoCreateTime time.Time `description:"任务创建时间"`
  287. TodoApproveTime time.Time `description:"任务审批时间"`
  288. TryStage int `description:"试用客户子标签:1未分类、2 推进、3 跟踪、4 预备"`
  289. }
  290. // GetCompanyProduct 获取产品详情
  291. func GetCompanyProduct(companyId int, productId int) (companyProduct *CompanyProduct, err error) {
  292. o := orm.NewOrm()
  293. sql := `SELECT *
  294. FROM company_product WHERE company_id= ? AND product_id = ? `
  295. err = o.Raw(sql, companyId, productId).QueryRow(&companyProduct)
  296. return
  297. }
  298. // 新增客户产品
  299. func AddCompanyProduct(item *CompanyProduct) (newId int64, err error) {
  300. o := orm.NewOrm()
  301. newId, err = o.Insert(item)
  302. return
  303. }
  304. type Sellers struct {
  305. AdminId int `description:"销售id"`
  306. RealName string `description:"销售姓名"`
  307. Email string `description:"销售邮箱"`
  308. OpenId string `description:"销售openid"`
  309. Mobile string `description:"销售电话"`
  310. RoleTypeCode string `description:"角色编码"`
  311. }
  312. func GetSellers() (items []*Sellers, err error) {
  313. o := orm.NewOrm()
  314. sql := `SELECT a.real_name,a.email,c.open_id,a.mobile,b.mobile,a.role_type_code,a.admin_id
  315. FROM admin AS a
  316. LEFT JOIN wx_user AS b ON a.mobile=b.mobile
  317. LEFT JOIN user_record AS c ON b.user_id=c.user_id
  318. WHERE role_type_code IN('ficc_seller','ficc_group','ficc_team','rai_seller','rai_group')
  319. and (
  320. (a.email != "") or ( c.open_id<>'' and c.create_platform=1)
  321. )`
  322. _, err = o.Raw(sql).QueryRows(&items)
  323. return
  324. }
  325. func GetSellersOpenId() (items []*Sellers, err error) {
  326. o := orm.NewOrm()
  327. sql := `SELECT a.real_name,a.email,a.open_id,a.mobile,a.role_type_code,a.admin_id
  328. FROM admin AS a
  329. WHERE role_type_code IN('ficc_seller','ficc_group','ficc_team','rai_seller','rai_group')
  330. and (
  331. (a.email != "") or ( a.open_id<>'')
  332. )`
  333. _, err = o.Raw(sql).QueryRows(&items)
  334. return
  335. }
  336. func GetRemindCompany(sellerId int, endDate string) (items []*CompanyProduct, err error) {
  337. o := orm.NewOrm()
  338. sql := ` SELECT b.end_date,b.contract_end_date,a.company_id,a.company_name,b.status,b.seller_id,b.seller_name FROM
  339. company a
  340. INNER JOIN company_product AS b ON a.company_id = b.company_id
  341. WHERE
  342. (b.seller_id = ? OR b.share_seller_id =?)
  343. AND (
  344. ( b.contract_end_date = ? AND b.status = "正式" ) OR (b.end_date = ? AND b.status = "试用")
  345. ) ORDER BY b.status DESC `
  346. _, err = o.Raw(sql, sellerId, sellerId, endDate, endDate).QueryRows(&items)
  347. return
  348. }
  349. // GetAllCompanyProduct 获取所有客户产品列表(永续、正式、试用、冻结)
  350. func GetAllCompanyProduct() (items []*CompanyProduct, err error) {
  351. o := orm.NewOrm()
  352. sql := ` SELECT * from company_product WHERE status in ("永续","正式","试用","冻结") `
  353. _, err = o.Raw(sql).QueryRows(&items)
  354. return
  355. }
  356. // AddCompanyProductTryOutDayTotal 将客户产品的试用天数+1
  357. func AddCompanyProductTryOutDayTotal(companyId, productId int) (err error) {
  358. o := orm.NewOrm()
  359. sql := `UPDATE company_product
  360. SET
  361. try_out_day_total = try_out_day_total+1
  362. WHERE company_id = ? AND product_id = ?`
  363. _, err = o.Raw(sql, companyId, productId).Exec()
  364. return
  365. }
  366. type CompanyProductItem struct {
  367. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  368. CompanyId int `description:"客户id"`
  369. ProductId int `description:"产品id"`
  370. ProductName string `description:"产品名称"`
  371. CompanyName string `description:"客户名称"`
  372. Source string `description:"来源"`
  373. Reasons string `description:"新增理由"`
  374. Status string `description:"客户状态"`
  375. IndustryId int `description:"行业id"`
  376. IndustryName string `description:"行业名称"`
  377. SellerId int `description:"销售id"`
  378. SellerName string `description:"销售名称"`
  379. GroupId int `description:"销售分组id"`
  380. DepartmentId int `description:"销售部门id"`
  381. IsSuspend int `description:"1:暂停,0:启用"`
  382. SuspendTime time.Time `description:"暂停启用时间"`
  383. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  384. FreezeTime time.Time `description:"冻结时间"`
  385. Remark string `description:"备注信息"`
  386. CreateTime time.Time `description:"创建时间"`
  387. ModifyTime time.Time `description:"修改时间"`
  388. StartDate string `description:"开始日期"`
  389. EndDate string `description:"结束日期"`
  390. ContractEndDate string `description:"合同结束日期"`
  391. LoseReason string `description:"流失原因"`
  392. LossTime time.Time `description:"流失时间"`
  393. CompanyType string `description:"客户类型"`
  394. OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
  395. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  396. ViewTotal int `description:"总阅读次数"`
  397. RoadShowTotal int `description:"累计路演次数"`
  398. LastViewTime time.Time `description:"最后一次阅读时间"`
  399. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  400. IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"`
  401. TodoStatus string `description:"任务处理状态;枚举值:'无任务','未完成','已完成'"`
  402. TodoCreateTime time.Time `description:"任务创建时间"`
  403. TodoApproveTime time.Time `description:"任务审批时间"`
  404. TryStage int `description:"试用客户子标签:1未分类、2 推进、3 跟踪、4 预备"`
  405. IsShare int `description:"0:非共享用户,1:共享客户"`
  406. ShareSeller string `description:"共享销售员"`
  407. ShareSellerId int `description:"共享销售员id"`
  408. }
  409. // GetCompanyProductItemListByCompanyIdList
  410. // @Description: 根据客户ID列表获取客户产品列表
  411. // @author: Roc
  412. // @datetime 2023-12-07 11:06:58
  413. // @param companyIdList []int
  414. // @param productId int
  415. // @return items []*CompanyProductItem
  416. // @return err error
  417. func GetCompanyProductItemListByCompanyIdList(companyIdList []int, productId int) (items []*CompanyProductItem, err error) {
  418. num := len(companyIdList)
  419. if num <= 0 {
  420. return
  421. }
  422. o := orm.NewOrm()
  423. sql := `SELECT a.* FROM company_product as a
  424. JOIN company b on a.company_id=b.company_id
  425. WHERE a.company_id in (` + utils.GetOrmInReplace(num) + `) AND a.product_id = ? `
  426. _, err = o.Raw(sql, companyIdList, productId).QueryRows(&items)
  427. return
  428. }
  429. // GetCompanyProductItemByCompanyId
  430. // @Description: 根据客户ID获取客户产品列表
  431. // @author: Roc
  432. // @datetime 2023-12-07 11:06:58
  433. // @param companyIdList []int
  434. // @param productId int
  435. // @return items []*CompanyProductItem
  436. // @return err error
  437. func GetCompanyProductItemByCompanyId(companyId int, productId int) (item *CompanyProductItem, err error) {
  438. o := orm.NewOrm()
  439. sql := `SELECT a.* FROM company_product as a
  440. JOIN company b on a.company_id=b.company_id
  441. WHERE a.company_id = ? AND a.product_id = ? `
  442. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  443. return
  444. }