company_product.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. package company
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. type CompanyProduct struct {
  8. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  9. CompanyId int `description:"客户id"`
  10. ProductId int `description:"产品id"`
  11. ProductName string `description:"产品名称"`
  12. CompanyName string `description:"客户名称"`
  13. Source string `description:"来源"`
  14. Reasons string `description:"新增理由"`
  15. Status string `description:"客户状态"`
  16. IndustryId int `description:"行业id"`
  17. IndustryName string `description:"行业名称"`
  18. SellerId int `description:"销售id"`
  19. SellerName string `description:"销售名称"`
  20. GroupId int `description:"销售分组id"`
  21. DepartmentId int `description:"销售部门id"`
  22. IsSuspend int `description:"1:暂停,0:启用"`
  23. SuspendTime time.Time `description:"暂停启用时间"`
  24. TryOutTime time.Time `description:"正式转试用时间"`
  25. RenewalReason string `description:"正式转试用后的续约情况说明"`
  26. RenewalTodo string `description:"未续约说明中的待办事项说明"`
  27. LastDescriptionTime time.Time `description:"上次添加说明时间"`
  28. RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
  29. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  30. FreezeTime time.Time `description:"冻结时间"`
  31. FreezeReason time.Time `description:"冻结理由"`
  32. Remark string `description:"备注信息"`
  33. CreateTime time.Time `description:"创建时间"`
  34. ModifyTime time.Time `description:"修改时间"`
  35. StartDate string `description:"开始日期"`
  36. EndDate string `description:"结束日期"`
  37. ContractEndDate time.Time `description:"合同结束日期"`
  38. LoseReason string `description:"流失原因"`
  39. LossTime time.Time `description:"流失时间"`
  40. CompanyType string `description:"客户类型"`
  41. OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
  42. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  43. ViewTotal int `description:"总阅读次数"`
  44. RoadShowTotal int `description:"累计路演次数"`
  45. LastViewTime time.Time `description:"最后一次阅读时间"`
  46. PackageType int `description:"套餐类型"`
  47. IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"`
  48. TodoStatus string `description:"任务处理状态;枚举值:'无任务','未完成','已完成'"`
  49. TodoCreateTime time.Time `description:"任务创建时间"`
  50. TodoApproveTime time.Time `description:"任务审批时间"`
  51. TryStage int `description:"试用客户子标签:1未分类、2 推进、3 跟踪、4 预备"`
  52. TryOutDayTotal int `description:"客户总试用天数"`
  53. CloseReason string `description:"关闭原因"`
  54. CloseTime time.Time `description:"关闭时间"`
  55. }
  56. // 新增客户产品
  57. func AddCompanyProduct(item *CompanyProduct) (newId int64, err error) {
  58. o := orm.NewOrm()
  59. newId, err = o.Insert(item)
  60. return
  61. }
  62. type CompanyProductDetail struct {
  63. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  64. CompanyId int `description:"客户id"`
  65. ProductId int `description:"产品id"`
  66. ProductName string `description:"产品名称"`
  67. CompanyName string `description:"客户名称"`
  68. Source string `description:"来源"`
  69. Reasons string `description:"新增理由"`
  70. Status string `description:"客户状态"`
  71. IndustryId int `description:"行业id"`
  72. IndustryName string `description:"行业名称"`
  73. SellerId int `description:"销售id"`
  74. SellerName string `description:"销售名称"`
  75. GroupId int `description:"销售分组id"`
  76. DepartmentId int `description:"销售部门id"`
  77. IsSuspend int `description:"1:暂停,0:启用"`
  78. SuspendTime time.Time `description:"暂停启用时间"`
  79. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  80. FreezeTime time.Time `description:"冻结时间"`
  81. Remark string `description:"备注信息"`
  82. CreateTime time.Time `description:"创建时间"`
  83. ModifyTime time.Time `description:"修改时间"`
  84. StartDate string `description:"开始日期"`
  85. EndDate string `description:"结束日期"`
  86. LoseReason string `description:"流失原因"`
  87. LossTime time.Time `description:"流失时间"`
  88. OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
  89. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  90. SpecialSurplus string `description:"专项调研剩余次数"`
  91. Points string `description:"公司研选服务剩余点数"`
  92. PermissionList []*PermissionLookList
  93. }
  94. func GetCompanyProductsByCompanyId(companyId int) (items []*CompanyProductDetail, err error) {
  95. sql := `SELECT * FROM company_product WHERE company_id=? ORDER BY create_time ASC `
  96. o := orm.NewOrm()
  97. _, err = o.Raw(sql, companyId).QueryRows(&items)
  98. return
  99. }
  100. func GetCompanyProductById(companyProductId int) (item *CompanyProduct, err error) {
  101. o := orm.NewOrm()
  102. sql := `SELECT * FROM company_product WHERE company_product_id=? `
  103. err = o.Raw(sql, companyProductId).QueryRow(&item)
  104. return
  105. }
  106. func GetCompanyProductByCompanyIdAndProductId(companyId, productId int) (item *CompanyProduct, err error) {
  107. o := orm.NewOrm()
  108. sql := `SELECT b.* FROM company AS a
  109. INNER JOIN company_product AS b ON a.company_id=b.company_id
  110. WHERE a.company_id=? AND b.product_id=? LIMIT 1 `
  111. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  112. return
  113. }
  114. // 修改客户产品
  115. func ModifyCompanyProduct(item *CompanyProduct) (err error) {
  116. o := orm.NewOrm()
  117. sql := `UPDATE company_product
  118. SET
  119. company_name = ?,
  120. source = ?,
  121. reasons = ?,
  122. status = ?,
  123. industry_id = ?,
  124. industry_name = ?,
  125. seller_id = ?,
  126. seller_name = ?,
  127. group_id = ?,
  128. department_id = ?,
  129. start_date = ?,
  130. end_date = ?,
  131. scale = ?,
  132. modify_time = NOW()
  133. WHERE company_product_id = ? `
  134. _, err = o.Raw(sql, item.CompanyName, item.Source, item.Reasons, item.Status, item.IndustryId, item.IndustryName, item.SellerId,
  135. item.SellerName, item.GroupId, item.DepartmentId, item.StartDate, item.EndDate, item.Scale, item.CompanyProductId).Exec()
  136. return
  137. }
  138. // 更新客户产品信息
  139. func (companyProduct *CompanyProduct) Update(cols []string) (err error) {
  140. o := orm.NewOrm()
  141. _, err = o.Update(companyProduct, cols...)
  142. return
  143. }
  144. func DeleteCompanyProductById(companyId, productId, companyProductId int) (companyProductList []*CompanyProduct, companyReportPermissionList []*CompanyReportPermission, err error) {
  145. o := orm.NewOrm()
  146. to, err := o.Begin()
  147. if err != nil {
  148. return
  149. }
  150. defer func() {
  151. if err != nil {
  152. _ = to.Rollback()
  153. } else {
  154. _ = to.Commit()
  155. }
  156. }()
  157. searchSql := `select * FROM company_product WHERE company_product_id=? `
  158. _, err = to.Raw(searchSql, companyProductId).QueryRows(&companyProductList)
  159. sql := `DELETE FROM company_product WHERE company_product_id=? `
  160. _, err = to.Raw(sql, companyProductId).Exec()
  161. if err != nil {
  162. return
  163. }
  164. searchSql = `select * FROM company_report_permission WHERE company_id=? AND product_id=? `
  165. _, err = to.Raw(searchSql, companyId, productId).QueryRows(&companyReportPermissionList)
  166. sql = `DELETE FROM company_report_permission WHERE company_id=? AND product_id=? `
  167. _, err = to.Raw(sql, companyId, productId).Exec()
  168. return
  169. }
  170. func SuspendCompanyProductById(companyId, productId, suspend int) (err error) {
  171. o := orm.NewOrm()
  172. sql := `UPDATE company_product SET is_suspend=?,suspend_time=NOW(),modify_time=NOW() WHERE company_id=? AND product_id=? `
  173. _, err = o.Raw(sql, suspend, companyId, productId).Exec()
  174. return
  175. }
  176. func GetAllCompanyProducts() (items []*CompanyProductDetail, err error) {
  177. sql := `SELECT * FROM company_product `
  178. o := orm.NewOrm()
  179. _, err = o.Raw(sql).QueryRows(&items)
  180. return
  181. }
  182. type CompanyProductTotalSlice struct {
  183. Total int `description:"总产品数"`
  184. CompanyId int `description:"用户id"`
  185. }
  186. // 根据用户id字符串获取企业用户的产品数
  187. func GetCountProductByCompanyIds(companyIds string) (items []*CompanyProductTotalSlice, err error) {
  188. //如果companyIds是空串,那么直接返回
  189. if companyIds == "" {
  190. return
  191. }
  192. o := orm.NewOrm()
  193. sql := `SELECT count(1) total,company_id FROM company_product WHERE company_id in (` + companyIds + `) group by company_id`
  194. _, err = o.Raw(sql).QueryRows(&items)
  195. return
  196. //return items2,err
  197. }
  198. // TryOutCompanyList 正式转试用的客户
  199. type TryOutCompanyList struct {
  200. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  201. CompanyId int `description:"客户id"`
  202. ProductId int `description:"产品id"`
  203. ProductName string `description:"产品名称"`
  204. CompanyName string `description:"客户名称"`
  205. CreditCode string `description:"社会统一信用码"`
  206. Status string `description:"客户状态"`
  207. TryOutTime time.Time `description:"正式转试用时间"`
  208. RenewalReason string `description:"正式转试用后的续约情况说明"`
  209. RenewalTodo string `description:"未续约说明中的待办事项说明"`
  210. LastDescriptionTime string `description:"上次添加说明时间"`
  211. RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
  212. CreateTime time.Time `description:"创建时间"`
  213. ModifyTime time.Time `description:"修改时间"`
  214. StartDate string `description:"开始日期"`
  215. EndDate string `description:"结束日期"`
  216. ExpireDays int `description:"到期日期"`
  217. }
  218. // GetTryOutCompanyCount
  219. // 获取今日待办消息数量
  220. func GetTryOutCompanyCount(condition string, pars []interface{}) (total int, err error) {
  221. o := orm.NewOrm()
  222. sql := ` select count(*) count from company_product a
  223. join company b on a.company_id=b.company_id where 1=1 and a.status="试用" `
  224. sql += condition
  225. err = o.Raw(sql, pars).QueryRow(&total)
  226. return
  227. }
  228. // GetTryOutCompanyList
  229. // 获取今日待办消息
  230. func GetTryOutCompanyList(condition string, pars []interface{}, startSize, pageSize int) (items []*TryOutCompanyList, err error) {
  231. o := orm.NewOrm()
  232. sql := ` select a.company_product_id,a.company_id,a.product_id,a.product_name,a.status,b.credit_code,b.company_name,a.try_out_time,a.renewal_reason,a.renewal_todo,a.last_description_time,a.create_time,a.modify_time,a.start_date,a.end_date from company_product a
  233. join company b on a.company_id=b.company_id where 1=1 and a.status="试用" `
  234. sql += condition
  235. sql += ` LIMIT ?,? `
  236. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  237. return
  238. }
  239. // EditTryOutCompanyReason 编辑续约情况说明
  240. func EditTryOutCompanyReason(companyProduct *CompanyProduct, reason string, renewalTodo string) (err error) {
  241. o := orm.NewOrm()
  242. updateCols := make([]string, 0)
  243. companyProduct.RenewalReason = reason
  244. companyProduct.RenewalTodo = renewalTodo
  245. companyProduct.ModifyTime = time.Now()
  246. companyProduct.LastDescriptionTime = time.Now()
  247. updateCols = append(updateCols, "RenewalReason", "RenewalTodo", "ModifyTime", "LastDescriptionTime", "RenewalIntention")
  248. _, err = o.Update(companyProduct, updateCols...)
  249. return
  250. }
  251. // CompanyRenewalReason 未续约说明
  252. type CompanyRenewalReason struct {
  253. CompanyRenewalReasonId int `orm:"column(company_renewal_reason_id);pk" description:"未续约说明id"`
  254. CompanyId int `description:"客户id"`
  255. ProductId int `description:"产品id"`
  256. ProductName string `description:"产品名称"`
  257. CompanyName string `description:"客户名称"`
  258. TryOutTime time.Time `description:"正式转试用时间"`
  259. RenewalReason string `description:"正式转试用后的续约情况说明"`
  260. RenewalTodo string `description:"未续约说明中的待办事项说明"`
  261. LastDescriptionTime time.Time `description:"上次添加说明时间"`
  262. EndDays time.Time `description:"到期时间"`
  263. ExpirationTimeExceeded int `description:"超出到期时间"`
  264. RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
  265. CreateTime time.Time `description:"创建时间"`
  266. }
  267. // AddRenewalReason 新增续约情况说明
  268. func AddRenewalReason(renewalReason *CompanyRenewalReason) (err error) {
  269. o := orm.NewOrm()
  270. _, err = o.Insert(renewalReason)
  271. return
  272. }
  273. // GetLastDescriptionTime 查询上次添加未续约说明时间
  274. func GetLastDescriptionTime() (items []*TryOutCompanyList, err error) {
  275. o := orm.NewOrm()
  276. sql := "SELECT * FROM company_product ORDER BY last_description_time desc limit 1"
  277. err = o.Raw(sql).QueryRow(&items)
  278. return
  279. }
  280. // UpdateLastDescriptionTime 更新最后一次修改未续约说明时间
  281. func UpdateLastDescriptionTime(companyProduct *CompanyProduct) (err error) {
  282. o := orm.NewOrm()
  283. updateCols := make([]string, 0)
  284. companyProduct.LastDescriptionTime = time.Now()
  285. updateCols = append(updateCols, "LastDescriptionTime")
  286. _, err = o.Update(companyProduct, updateCols...)
  287. return
  288. }
  289. // GetTryOutTimeFromOperationRecord 查询转试用时间
  290. func GetTryOutTimeFromOperationRecord(companyId int) (item *string, err error) {
  291. o := orm.NewOrm()
  292. sql := "SELECT create_time FROM company_operation_record WHERE company_id=? AND operation='try_out' ORDER BY create_time DESC "
  293. err = o.Raw(sql, companyId).QueryRow(&item)
  294. return
  295. }
  296. // GetCompanyProductsByCompanyIds 根据客户id集合字符串获取所有客户产品列表
  297. func GetCompanyProductsByCompanyIds(companyIds, condition string, pars []interface{}) (items []*CompanyProduct, err error) {
  298. if companyIds == `` {
  299. return
  300. }
  301. sql := `SELECT * FROM company_product WHERE company_id in (` + companyIds + `) `
  302. sql += condition
  303. sql += ` ORDER BY create_time ASC `
  304. o := orm.NewOrm()
  305. _, err = o.Raw(sql, pars).QueryRows(&items)
  306. return
  307. }
  308. // 更新最后一次编辑时间
  309. func UpdateCompanyProductModifyTime(companyId, productId int) (err error) {
  310. o := orm.NewOrm()
  311. sql := `UPDATE company_product SET modify_time=NOW() WHERE company_id=? AND product_id=? `
  312. _, err = o.Raw(sql, companyId, productId).Exec()
  313. return
  314. }
  315. // CompanyProductRemark 备注
  316. type CompanyProductRemark struct {
  317. CompanyProductRemarkId int `orm:"column(company_product_remark_id);pk" description:"备注id"`
  318. CompanyId int `description:"客户id"`
  319. ProductId int `description:"产品id"`
  320. ProductName string `description:"产品名称"`
  321. Remark string `description:"备注"`
  322. CreateTime time.Time `description:"创建时间"`
  323. Mark int `description:"是否标记 0不是 1是"`
  324. SysUserId int `description:"创建人ID"`
  325. SysRealName string `description:"创建人姓名"`
  326. }
  327. func AddCompanyRemark(remark *CompanyProductRemark) (err error) {
  328. o := orm.NewOrm()
  329. _, err = o.Insert(remark)
  330. return
  331. }
  332. // GetRemarkList 获取备注列表
  333. func GetRemarkList(CompanyId, ProductId string) (items []*CompanyProductRemark, err error) {
  334. o := orm.NewOrm()
  335. sql := "SELECT * FROM company_product_remark WHERE company_id=? AND product_id=? ORDER BY create_time DESC"
  336. _, err = o.Raw(sql, CompanyId, ProductId).QueryRows(&items)
  337. return
  338. }
  339. // GetRemarkList 获取备注列表
  340. func GetRemarkListByCompanyId(CompanyId string) (items []*CompanyProductRemark, err error) {
  341. o := orm.NewOrm()
  342. sql := "SELECT * FROM company_product_remark WHERE company_id=? ORDER BY create_time DESC"
  343. _, err = o.Raw(sql, CompanyId).QueryRows(&items)
  344. return
  345. }
  346. // 冻结客户
  347. //func FreezeCompany(productId, companyId, adminId int, remark, realName string) (msg, errMsg string){
  348. // time.Sleep(time.Second)
  349. // productName := ""
  350. // if productId == 1 {
  351. // productName = "ficc"
  352. // } else if productId == 2 {
  353. // productName = "权益"
  354. // } else {
  355. // productName = "佣金客户"
  356. // }
  357. //
  358. // cp, err := GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  359. // if err != nil {
  360. // msg = "查询该客户产品异常!"
  361. // errMsg = "查询该客户产品异常,err:" + err.Error()
  362. // return
  363. // }
  364. // if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  365. // msg = "客户状态为:" + cp.Status + ";不可冻结"
  366. // errMsg = "客户状态为:" + cp.Status + ";不可冻结"
  367. // return
  368. // }
  369. // //查询客户的产品权限
  370. // companyReportPermissionList, err := GetCompanyReportPermission(companyId, productId)
  371. // if err != nil {
  372. // msg = "查询客户的产品权限异常"
  373. // errMsg = "查询客户的产品权限异常:" + err.Error()
  374. // return
  375. // }
  376. // err = CompanyFreeze(companyId, productId, remark)
  377. // if err != nil {
  378. // msg = "冻结失败!"
  379. // errMsg = "冻结失败,Err:" + err.Error()
  380. // return
  381. // }
  382. // //新增操作记录
  383. // {
  384. // approveContent := remark
  385. // remark := "冻结客户"
  386. // operation := "freeze"
  387. // services.AddCompanyOperationRecord(companyId, cp.SellerId, adminId, productId, adminId, cp.CompanyName,
  388. // productName, "超级管理员", remark, operation, approveContent, realName, "", "冻结")
  389. //
  390. // //新增产品权限冻结操作日志
  391. // for _, companyReportPermission := range companyReportPermissionList {
  392. // record := company_report_permission_log.CompanyReportPermissionLog{
  393. // CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  394. // CompanyId: companyReportPermission.CompanyId,
  395. // ProductId: productId,
  396. // ProductName: companyReportPermission.ProductName,
  397. // SysUserId: adminId,
  398. // SysUserName: "超级管理员",
  399. // Remark: "冻结客户",
  400. // Operation: "freeze",
  401. // Status: companyReportPermission.Status,
  402. // CreateTime: time.Now(),
  403. // }
  404. // _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  405. // }
  406. // }
  407. // if err != nil {
  408. // msg = "编辑失败"
  409. // errMsg = "编辑失败,Err:" + err.Error()
  410. // }
  411. // return
  412. //}
  413. // SellerTryCompanyProductIds 销售对应的客户ID
  414. type SellerTryCompanyProductIds struct {
  415. CompanyIds string `description:"客户ids"`
  416. SellerId int `description:"销售ID"`
  417. }
  418. // GetTryCompanyIdsBySellerIds 获取销售对应的试用客户ID
  419. func GetTryCompanyIdsBySellerIds(productId int, sellerIds string) (list []*SellerTryCompanyProductIds, err error) {
  420. o := orm.NewOrm()
  421. sql := ` SELECT seller_id, GROUP_CONCAT(DISTINCT company_id SEPARATOR ',') AS company_ids
  422. FROM company_product
  423. WHERE product_id=? and status = "试用" and seller_id in ` + sellerIds + ` GROUP BY seller_id
  424. `
  425. _, err = o.Raw(sql, productId).QueryRows(&list)
  426. return
  427. }
  428. // GetCompanyProductsByCompanyIdsAndProductId 根据客户id集合字符串以及品种id获取所有客户产品列表
  429. func GetCompanyProductsByCompanyIdsAndProductId(companyIds []int, productId int) (items []*CompanyProduct, err error) {
  430. lenCompanyId := len(companyIds)
  431. if lenCompanyId == 0 {
  432. return
  433. }
  434. sql := `SELECT b.* FROM company a left join company_product b on a.company_id=b.company_id WHERE a.company_id in (` + utils.GetOrmInReplace(lenCompanyId) + `) AND b.product_id = ? `
  435. o := orm.NewOrm()
  436. _, err = o.Raw(sql, companyIds, productId).QueryRows(&items)
  437. return
  438. }
  439. // GetCompanyProductByCompanyIdAndSellerId 根据客户id和所属销售id获取客户产品信息
  440. func GetCompanyProductByCompanyIdAndSellerId(companyId, sellerId int) (item *CompanyProduct, err error) {
  441. o := orm.NewOrm()
  442. sql := `SELECT b.* FROM company AS a
  443. INNER JOIN company_product AS b ON a.company_id=b.company_id
  444. WHERE a.company_id=? AND b.seller_id=? LIMIT 1 `
  445. err = o.Raw(sql, companyId, sellerId).QueryRow(&item)
  446. return
  447. }
  448. // GetCompanyProductsByCompanyIds 根据客户id集合字符串获取所有客户产品列表
  449. func GetCompanyProductsBySellerId(sellerId string) (items []*CompanyProduct, err error) {
  450. sql := `SELECT * FROM company_product WHERE seller_id in (` + sellerId + `) `
  451. o := orm.NewOrm()
  452. _, err = o.Raw(sql).QueryRows(&items)
  453. return
  454. }
  455. // GetCompanyProductsByCondition 获取客户产品列表
  456. func GetCompanyProductsByCondition(condition string, pars []interface{}) (list []*CompanyProduct, err error) {
  457. sql := `SELECT
  458. b.*
  459. FROM
  460. company AS a
  461. JOIN company_product AS b ON a.company_id = b.company_id
  462. WHERE
  463. 1 = 1 `
  464. if condition != `` {
  465. sql += condition
  466. }
  467. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  468. return
  469. }
  470. // AddCompanyProductTryOutDayTotal 将客户产品的试用天数+1
  471. func AddCompanyProductTryOutDayTotal(companyId, productId int) (err error) {
  472. o := orm.NewOrm()
  473. sql := `UPDATE company_product
  474. SET
  475. try_out_day_total = try_out_day_total+1
  476. WHERE company_id = ? AND product_id = ?`
  477. _, err = o.Raw(sql, companyId, productId).Exec()
  478. return
  479. }
  480. // 获取详情
  481. func GetCompanyProductDetail(companyId, productId int) (item *CompanyProductDetail, err error) {
  482. sql := ` SELECT * FROM company_product WHERE company_id = ? AND product_id = ?; `
  483. o := orm.NewOrm()
  484. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  485. return
  486. }
  487. // 根据状态获取客户列表
  488. func GetCompanyProductListByStatus(status string, productId int) (items []*CompanyProduct, err error) {
  489. sql := ` SELECT * FROM company_product WHERE status = ? AND product_id = ?; `
  490. o := orm.NewOrm()
  491. _, err = o.Raw(sql, status, productId).QueryRows(&items)
  492. return
  493. }
  494. // 根据规模取客户列表
  495. func GetCompanyProductListByScale(status string, productId int) (items []*CompanyProduct, err error) {
  496. sql := ` SELECT * FROM company_product WHERE scale IN (?) AND product_id = ?; `
  497. o := orm.NewOrm()
  498. _, err = o.Raw(sql, status, productId).QueryRows(&items)
  499. return
  500. }
  501. // GetCompanyRemarkById 获取客户备注
  502. func GetCompanyRemarkById(remarkId int) (item *CompanyProductRemark, err error) {
  503. o := orm.NewOrm()
  504. sql := `SELECT * FROM company_product_remark WHERE company_product_remark_id = ? LIMIT 1`
  505. err = o.Raw(sql, remarkId).QueryRow(&item)
  506. return
  507. }
  508. // DelCompanyRemark 删除客户备注
  509. func DelCompanyRemark(remarkId int) (err error) {
  510. o := orm.NewOrm()
  511. sql := `DELETE FROM company_product_remark WHERE company_product_remark_id = ? LIMIT 1`
  512. _, err = o.Raw(sql, remarkId).Exec()
  513. return
  514. }