123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type CompanyJson struct {
- CompanyName string `json:"name"`
- ShortName string `json:"short_name"`
- CreditCode string `json:"social"`
- City string `json:"city"`
- SignType string `json:"sign_type"`
- Fe string `json:"f_e"`
- IndustryName string `json:"industry"`
- Mobile string `json:"sale_phone"`
- Status string `json:"status"`
- Permission string `json:"permissions"`
- StartDate string `json:"start_time"`
- EndDate string `json:"end_time"`
- Info string `json:"info"`
- CreatedTime string `json:"create_time"`
-
- EndDateTime time.Time
- }
- type UserJson struct {
- CreditCode string `json:"social"`
- RealName string `json:"name"`
- Mobile string `json:"phone"`
- CountryCode string `json:"area_code"`
- OutboundMobile string `json:"phone2"`
- OutboundCountryCode string `json:"area_code2"`
- Telephone string `json:"machine"`
- MachineAreaCode string `json:"machine_area_code"`
- Sex string `json:"sex"`
- Email string `json:"email"`
- Department string `json:"department"`
- Position string `json:"position"`
- Level string `json:"level"`
- IsMaker string `json:"policymakers"`
- CreatedTime string `json:"create_time"`
- }
- type CompanyJsonList struct {
- SyncData *[]CompanyJson `json:"sync_data"`
- }
- type CompanyUnJsonList struct {
- SyncData []CompanyJson `json:"sync_data"`
- }
- func GetSendCompanyList(condition string) (items []*CompanyJson, err error) {
- o := orm.NewOrm()
- sql := ` SELECT
- c.company_name,
- c.company_id as cid,
- c.credit_code,
- c.city,
- p.industry_name,
- am.real_name,
- am.mobile,
- a.status,
- p.end_date as end_date_time,
- UNIX_TIMESTAMP( p.start_date ) AS start_date,
- UNIX_TIMESTAMP( p.end_date ) AS end_date,
- UNIX_TIMESTAMP( a.created_time ) AS created_time,
- (SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR ',')
- FROM company_report_permission AS a
- INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
- INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
- WHERE a.company_id=cid
- AND c.enabled = 1
- AND b.cygx_auth=1
- AND c.status IN('正式','试用')
- AND a.status IN('正式','试用')) AS permission
- FROM
- company_report_permission AS a
- INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
- INNER JOIN company_product AS p ON a.company_id = p.company_id
- INNER JOIN company AS c ON c.company_id = a.company_id
- INNER JOIN admin AS am ON am.admin_id = p.seller_id
- AND a.product_id = p.product_id
- WHERE
- 1 = 1
- AND c.enabled = 1
- AND b.cygx_auth = 1
- AND p.STATUS IN ( '正式', '试用' )
- AND a.STATUS IN ( '正式', '试用' )
- AND( c.credit_code LIKE '91%' OR c.credit_code LIKE 'HZ%' )
- AND p.product_id = 2 ` + condition +
- `GROUP BY
- c.company_id `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetSendCompanyFiccList(condition string) (items []*CompanyJson, err error) {
- o := orm.NewOrm()
- sql := ` SELECT
- c.company_name,
- c.company_id AS cid,
- c.credit_code,
- c.city,
- p.industry_name,
- am.real_name,
- am.mobile,
- a.status,
- p.end_date AS end_date_time,
- UNIX_TIMESTAMP( p.start_date ) AS start_date,
- UNIX_TIMESTAMP( p.end_date ) AS end_date,
- UNIX_TIMESTAMP( a.created_time ) AS created_time,
- (
- SELECT
- GROUP_CONCAT( DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR ',' )
- FROM
- company_report_permission AS a
- INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
- INNER JOIN company_product AS c ON a.company_id = c.company_id
- AND a.product_id = c.product_id
- WHERE
- a.company_id = cid
- AND c.enabled = 1
- AND b.cygx_auth = 1
- AND c.STATUS IN ( '正式', '试用' )
- AND a.STATUS IN ( '正式', '试用' )) AS permission
- FROM
- company_report_permission AS a
- INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
- INNER JOIN company_product AS p ON a.company_id = p.company_id
- INNER JOIN company AS c ON c.company_id = a.company_id
- INNER JOIN admin AS am ON am.admin_id = p.seller_id
- AND a.product_id = p.product_id
- WHERE
- 1 = 1
- AND c.enabled = 1
- AND b.cygx_auth = 1
- AND p.STATUS IN ( '正式', '试用' )
- AND a.STATUS IN ( '正式', '试用' )
- AND ( c.credit_code LIKE '91%' OR c.credit_code LIKE 'HZ%' )
- AND p.product_id = 1 ` + condition +
- `AND c.company_id NOT IN (
- SELECT
- c.company_id
- FROM
- company_report_permission AS a
- INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
- INNER JOIN company_product AS p ON a.company_id = p.company_id
- INNER JOIN company AS c ON c.company_id = a.company_id
- INNER JOIN admin AS am ON am.admin_id = p.seller_id
- AND a.product_id = p.product_id
- WHERE
- 1 = 1
- AND c.enabled = 1
- AND b.cygx_auth = 1
- AND p.STATUS IN ( '正式', '试用' )
- AND a.STATUS IN ( '正式', '试用' )
- AND ( c.credit_code LIKE '91%' OR c.credit_code LIKE 'HZ%' )
- AND p.product_id = 2
- GROUP BY
- c.company_id
- )
- GROUP BY
- c.company_id `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetSendUserList(condition string) (items []*UserJson, err error) {
- o := orm.NewOrm()
- sql := ` SELECT
- c.credit_code,
- u.real_name,
- u.mobile,
- u.country_code,
- u.outbound_mobile,
- u.outbound_country_code,
- u.telephone,
- u.sex,
- u.is_maker,
- c.company_id,
- UNIX_TIMESTAMP( us.create_time ) AS created_time
- FROM
- wx_user AS u
- INNER JOIN company AS c ON c.company_id = u.company_id
- INNER JOIN user_seller_relation AS us ON us.user_id = u.user_id
- WHERE
- 1 = 1
- AND u.company_id IN (
- SELECT
- c.company_id
- FROM
- company_report_permission AS a
- INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id
- INNER JOIN company_product AS p ON a.company_id = p.company_id
- INNER JOIN company AS c ON c.company_id = a.company_id
- INNER JOIN admin AS am ON am.admin_id = p.seller_id
- AND a.product_id = p.product_id
- WHERE
- 1 = 1
- AND c.enabled = 1
- AND b.cygx_auth = 1
- AND p.STATUS IN ( '正式', '试用' )
- AND a.STATUS IN ( '正式', '试用' )
- AND us.create_time != '' ` + condition +
- `GROUP BY
- c.company_id
- )
- AND us.create_time != ''
- AND u.real_name != ''
- AND u.mobile != ''
- AND ( c.credit_code LIKE '91%' OR c.credit_code LIKE 'HZ%' ) GROUP BY u.user_id ORDER BY c.company_id DESC `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- type WxUserOpLogResp struct {
- CompanyId int `description:"客户ID"`
- UserId int `description:"用户ID"`
- Mobile string `description:"用户ID"`
- }
- func GetWxUserOpLog(createTime string) (items []*WxUserOpLogResp, err error) {
- o := orm.NewOrm()
- sql := ` SELECT company_id FROM wx_user_op_log WHERE log_type IN ('add','edit','import') AND create_time >= '` + createTime + `' AND company_id > 1 GROUP BY company_id `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetWxUserOpLogList(createTime string) (items []*WxUserOpLogResp, err error) {
- o := orm.NewOrm()
- sql := ` SELECT company_id,user_id,mobile FROM wx_user_op_log WHERE log_type IN ('move','add') AND create_time >= '` + createTime + `' AND company_id > 1 GROUP BY user_id `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
|