mirror of http://gitlab.batiao8.com/yic/film.git
95 lines
2.6 KiB
Go
95 lines
2.6 KiB
Go
package nowcar
|
|
|
|
import (
|
|
"encoding/json"
|
|
"film/dao"
|
|
"film/model"
|
|
"fmt"
|
|
"github.com/silenceper/wechat/util"
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/smbrave/goutil"
|
|
"github.com/spf13/cast"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type Ddf struct {
|
|
}
|
|
|
|
func (d *Ddf) Sync() {
|
|
shopIds := []int{826, 1693, 38, 1900, 372, 1613, 1372, 56, 1701, 45}
|
|
|
|
for _, shopId := range shopIds {
|
|
reqUrl := fmt.Sprintf("https://v9.ddfkj.com/mpserver/getwangdiandata.php?wdid=%d", shopId)
|
|
body, err := util.HTTPGet(reqUrl)
|
|
if err != nil {
|
|
log.Errorf("get http[%s] error :%s", reqUrl, err.Error())
|
|
continue
|
|
}
|
|
mp := make(map[string]interface{})
|
|
if err := json.Unmarshal(body, &mp); err != nil {
|
|
log.Errorf("json[%s] error:%s", string(body), err.Error())
|
|
continue
|
|
}
|
|
d.getDetail(shopId)
|
|
}
|
|
}
|
|
|
|
func (d *Ddf) getDetail(shopId int) {
|
|
reqUrl := fmt.Sprintf("https://v9.ddfkj.com/mpserver/getmcstate.php?wdid=%d", shopId)
|
|
body, err := util.HTTPGet(reqUrl)
|
|
if err != nil {
|
|
log.Errorf("get http[%s] error :%s", reqUrl, err.Error())
|
|
return
|
|
}
|
|
res := make([]interface{}, 0)
|
|
if err := json.Unmarshal(body, &res); err != nil {
|
|
log.Errorf("json[%s] error:%s", string(body), err.Error())
|
|
return
|
|
}
|
|
|
|
for _, r := range res {
|
|
obj := cast.ToStringMap(r)
|
|
status := cast.ToString(obj["zhuangtai"])
|
|
shopName := cast.ToString(obj["wangdian"])
|
|
workstation := cast.ToString(obj["address"])
|
|
if status == "维护中" {
|
|
continue
|
|
} else if status == "空闲" {
|
|
m1, _ := dao.NewDdfDao().GetBusy(shopName, workstation)
|
|
if m1 == nil {
|
|
continue
|
|
}
|
|
m1.EndTime = time.Now().Unix()
|
|
dao.NewDdfDao().Update(m1)
|
|
|
|
//完成提示
|
|
todays, _ := dao.NewDdfDao().QueryToday(shopName, workstation, time.Now().Format("2006-01-02"))
|
|
totalAmount := int64(0)
|
|
for _, day := range todays {
|
|
totalAmount += day.Amount
|
|
}
|
|
//订单完成提示
|
|
log.Errorf("[DDF] shopName=%s,workstation=%s,time=[%s],cost_minute=%d,money=%s,total=[%s/%d]",
|
|
m1.ShopName, m1.Workstation, goutil.TimeToDateTime(m1.StartTime),
|
|
(m1.EndTime-m1.StartTime)/60, goutil.FormatMoney(m1.Amount),
|
|
goutil.FormatMoney(totalAmount), len(todays))
|
|
|
|
} else if status == "忙碌中" {
|
|
yiyongtime := cast.ToString(obj["yiyongtime"])
|
|
useMinute := cast.ToFloat64(strings.TrimSuffix(yiyongtime, "分钟"))
|
|
m1, _ := dao.NewDdfDao().GetBusy(shopName, workstation)
|
|
if m1 != nil {
|
|
continue
|
|
}
|
|
m1 = new(model.Ddf)
|
|
m1.Day = time.Now().Format("2006-01-02")
|
|
m1.ShopName = shopName
|
|
m1.Workstation = workstation
|
|
m1.Amount = 600
|
|
m1.StartTime = time.Now().Unix() - int64(float64(60)*useMinute)
|
|
dao.NewDdfDao().Create(m1)
|
|
}
|
|
}
|
|
}
|