123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- package service
-
- import (
- "gdyb/models"
- "fmt"
- )
-
- func FindFaPiaoConfigInfo(org_id int64) (config models.FapiaoConfig, err error) {
- err = readDb.Model(&models.FapiaoConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
- return
- }
- func GetAdminUserRole(id int64, orgid int64) (models.SgjUserAdminRole, error) {
- role := models.SgjUserAdminRole{}
- err := UserReadDB().Where("admin_user_id = ? and org_id = ? and status = 1", id, orgid).Find(&role).Error
- return role, err
- }
- func GetFaPiaoSettleList(user_org_id int64, page int64, limit int64, start_time_timestamp int64, end_time_timestamp int64, sort_type int64, start_time string, end_time string, is_open_fapiao int64, patient_id int64) (order []*models.HisOrderByFaPiao, err error, total int64) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.HisOrderByFaPiao{})
-
- // Join the patients table based on user_org_id
- db = db.Joins("join xt_patients as patient on patient.id = his_order.patient_id and patient.user_org_id = ?", user_org_id)
-
- // Handle the is_open_fapiao logic
- if is_open_fapiao == 1 {
- // is_open_fapiao == 1: Look for orders with a corresponding fa_piao_number
- db = db.Joins("left join his_fapiao_order as fo on fo.ticket_sn = his_order.fa_piao_number and fo.user_org_id = ?", user_org_id).
- Where("fo.id IS NOT NULL") // Ensure fa_piao_number exists
- } else if is_open_fapiao == 2 {
- // is_open_fapiao == 2: Look for orders without a corresponding fa_piao_number
- db = db.Joins("left join his_fapiao_order as fo on fo.ticket_sn = his_order.fa_piao_number and fo.user_org_id = ?", user_org_id).
- Where("fo.id IS NULL") // Ensure fa_piao_number does not exist
- }
-
- // Handle sorting logic
- if sort_type == 1 {
- if start_time_timestamp != 0 {
- db = db.Where("his_order.settle_accounts_date >= ?", start_time_timestamp)
- }
- if end_time_timestamp != 0 {
- db = db.Where("his_order.settle_accounts_date <= ?", end_time_timestamp)
- }
- } else {
- if len(start_time) != 0 {
- db = db.Where("his_order.setl_time >= ?", start_time+" 00:00:00")
- }
- if len(end_time) != 0 {
- db = db.Where("his_order.setl_time <= ?", end_time+" 23:59:59")
- }
- }
- if patient_id > 0 {
- db = db.Where("his_order.patient_id = ?", patient_id)
-
- }
-
- // Preload related data
- db = db.Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
- Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
- Preload("HisFaPiaoOrder", "status = 1")
-
- // Count the total number of records
- db = db.Count(&total)
-
- // Apply pagination
- db = db.Limit(limit).Offset(offset)
-
- // Execute query and return results
- err = db.Find(&order).Error
- //
- //for _, item := range order {
- // var hfpo models.HisFaPiaoOrder
- // readDb.Model(&models.HisFaPiaoOrder{}).Where("ticket_sn = ?", item.FaPiaoNumber).First(&hfpo)
- // item.HisFaPiaoOrder =
- //}
-
- return
- }
-
- func GetFaPiaoList(user_org_id int64, page int64, limit int64, start_time_timestamp int64, end_time_timestamp int64) (order []*models.HisFaPiaoOrder, err error, total int64) {
- offset := (page - 1) * limit
- db := readDb.Model(&models.HisFaPiaoOrder{})
- db = db.Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id)
- db = db.Where("ctime >= ? and ctime <= ? and user_org_id = ? and status = 1", start_time_timestamp, end_time_timestamp, user_org_id)
- // Count the total number of records
- db = db.Count(&total)
- // Apply pagination
- db = db.Limit(limit).Offset(offset)
- // Execute query and return results
- err = db.Find(&order).Error
- return
- }
-
- func GetFaPiaoOrderByIDS(ids []string) (orders []models.HisOrder, err error) {
- err = readDb.Model(&models.HisOrder{}).Where("id in (?) AND status = 1", ids).Find(&orders).Error
- return
- }
-
- func GetFaPiaoOrderById(id int64) (orders models.HisFaPiaoOrder, err error) {
- err = readDb.Model(&models.HisFaPiaoOrder{}).Where("id = ?", id).Find(&orders).Error
- return
- }
-
- func GetFaPiaoOrderInfoByNumbers(numbers []string) (infos []models.HisOrderInfo, err error) {
- err = readDb.Model(&models.HisOrderInfo{}).Where("order_number in (?)", numbers).Find(&infos).Error
- return
- }
-
- func SaveFaPiaoOrder(fapiao *models.HisFaPiaoOrder) (err error) {
- err = writeDb.Save(&fapiao).Error
- return
- }
-
- func UpdateFaPiaoNumber(number string, ids []string) (err error) {
- err = XTWriteDB().Model(&models.HisOrder{}).Where("id in (?)", ids).Updates(map[string]interface{}{"fa_piao_number": number}).Error
- return
- }
-
- func UpdateFaPiaoSN(number string, ids []string) (err error) {
- fmt.Println(ids)
- fmt.Println(number)
-
- err = XTWriteDB().Model(&models.HisOrder{}).Where("id in (?)", ids).Updates(map[string]interface{}{"fa_piao_sn": number}).Error
- return
- }
-
- func UpdateFaPiaoNumberByNumber(number string) (err error) {
- err = XTWriteDB().Model(&models.HisOrder{}).Where("fa_piao_number = ?", number).Updates(map[string]interface{}{"fa_piao_number": ""}).Error
- return
- }
-
|