package hdl

import (
	"applet/app/db"
	"applet/app/e"
	"applet/app/svc"
	"fmt"
	"github.com/gin-gonic/gin"
)

func City(c *gin.Context) {
	var arg = make(map[string]string)
	c.ShouldBindJSON(&arg)
	sql := `select IF(city.name='省直辖县级行政区划' or city.name='市辖区',province.name,city.name) as newname from city
LEFT JOIN province on province.id=city.province_id
where %s
order by CONVERT(newname USING gbk)`
	str := "1=1"
	if arg["name"] != "" {
		str += " and newname like '%" + arg["name"] + "%'"
	}
	sql = fmt.Sprintf(sql, str)
	nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
	nodeList := make([]map[string]string, 0)
	for _, item := range nativeString {
		tmp := map[string]string{
			"name": item["newname"],
		}
		nodeList = append(nodeList, tmp)
	}
	e.OutSuc(c, nodeList, nil)
	return
}
func BankStoreCate(c *gin.Context) {
	var res = []map[string]string{
		{"name": "全部网点", "value": ""},
		{"name": "附近网点", "value": "1"},
		{"name": "关注网点", "value": "2"},
	}
	e.OutSuc(c, res, nil)
	return
}
func BankStore(c *gin.Context) {
	svc.BankStore(c)
}
func Store(c *gin.Context) {
	svc.Store(c)
}
func StoreAddLike(c *gin.Context) {
	svc.StoreAddLike(c)
}
func StoreCancelLike(c *gin.Context) {
	svc.StoreCancelLike(c)
}
