附近小店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_store.go 13 KiB

2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
2 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. package hdl
  2. import (
  3. agentSvc "applet/app/agent/svc"
  4. "applet/app/db"
  5. "applet/app/db/model"
  6. "applet/app/e"
  7. "applet/app/md"
  8. "applet/app/svc"
  9. "applet/app/utils"
  10. "encoding/json"
  11. "fmt"
  12. "github.com/gin-gonic/gin"
  13. "time"
  14. )
  15. // UserStoreList 门店列表
  16. // @Summary 门店-列表
  17. // @Tags 门店
  18. // @Description 门店-列表
  19. // @Accept json
  20. // @Produce json
  21. // @Param req body md.Store true "请求参数"
  22. // @Success 200 {string} ""
  23. // @Failure 400 {object} md.Response "具体错误"
  24. // @Router /api/v1/communityTeam/agent/store/list [POST]
  25. func UserStoreList(c *gin.Context) {
  26. var arg md.Store
  27. if err := c.ShouldBindJSON(&arg); err != nil {
  28. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  29. return
  30. }
  31. user := svc.GetUser(c)
  32. list, count := db.GetUserList(svc.MasterDb(c), arg, user.Info.Uid)
  33. data := make([]map[string]interface{}, 0)
  34. if list != nil {
  35. currentMonth := utils.GetTimeRange("current_month")
  36. for _, v := range *list {
  37. store := v.CommunityTeamStore
  38. tmp := map[string]interface{}{
  39. "uid": utils.IntToStr(v.User.Uid),
  40. "create_at": store.CreateAt.Format("2006-01-02 15:04:05"),
  41. "name": "",
  42. "address": "",
  43. "logo": "",
  44. "order_count": "0",
  45. "order_amount": "0",
  46. "agent_commission": "0",
  47. "platform_commission": "0",
  48. "base_commission": "0",
  49. "work_state": "",
  50. }
  51. count1, _ := svc.MasterDb(c).Where("store_uid=? and parent_uid=?", v.User.Uid, user.Info.Uid).In("state", []string{"1", "2"}).Count(&model.CommunityTeamOrder{})
  52. sum, _ := svc.MasterDb(c).Where("store_uid=? and parent_uid=? and create_at>=?", v.User.Uid, user.Info.Uid, time.Unix(currentMonth["start"], 0).Format("2006-01-02 15:04:05")).In("state", []string{"1", "2"}).Sum(&model.CommunityTeamOrder{}, "amount")
  53. tmp["order_count"] = utils.Int64ToStr(count1)
  54. tmp["order_amount"] = svc.GetCommissionPrec(c, utils.Float64ToStr(sum), "2", "")
  55. tmp["name"] = store.Name
  56. tmp["address"] = store.Address
  57. tmp["logo"] = store.Logo
  58. tmp["work_state"] = "营业中"
  59. if store.WorkState == 1 {
  60. tmp["work_state"] = "休息中"
  61. }
  62. tmp["agent_commission"] = store.AgentCommission
  63. data = append(data, tmp)
  64. }
  65. }
  66. res := map[string]interface{}{
  67. "total": count,
  68. "list": data,
  69. }
  70. e.OutSuc(c, res, nil)
  71. }
  72. // UserStoreSave 门店编辑
  73. // @Summary 门店-门店编辑
  74. // @Tags 门店
  75. // @Description 门店-门店编辑
  76. // @Accept json
  77. // @Produce json
  78. // @Param req body md.StoreSave true "请求参数"
  79. // @Success 200 {string} ""
  80. // @Failure 400 {object} md.Response "具体错误"
  81. // @Router /api/v1/communityTeam/agent/store/save [POST]
  82. func UserStoreSave(c *gin.Context) {
  83. var arg md.StoreSave
  84. if err := c.ShouldBindJSON(&arg); err != nil {
  85. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  86. return
  87. }
  88. store := db.GetUserStore(svc.MasterDb(c), utils.StrToInt(arg.Uid))
  89. if store == nil {
  90. e.OutErr(c, 400, e.NewErr(400, "门店不存在"))
  91. return
  92. }
  93. store.AgentCommission = arg.AgentCommission
  94. svc.MasterDb(c).Where("id=?", store.Id).Cols("agent_commission").Update(store)
  95. e.OutSuc(c, "success", nil)
  96. return
  97. }
  98. // UserStoreOrder 门店订单-订单管理共用一个
  99. // @Summary 门店-门店订单
  100. // @Tags 门店
  101. // @Description 门店-门店订单
  102. // @Accept json
  103. // @Produce json
  104. // @Param req body md.StoreOrder true "请求参数"
  105. // @Success 200 {string} ""
  106. // @Failure 400 {object} md.Response "具体错误"
  107. // @Router /api/v1/communityTeam/agent/store/order [POST]
  108. func UserStoreOrder(c *gin.Context) {
  109. var arg md.StoreOrder
  110. if err := c.ShouldBindJSON(&arg); err != nil {
  111. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  112. return
  113. }
  114. user := svc.GetUser(c)
  115. data, total, _ := db.GetStoreOrderList(svc.MasterDb(c), arg, user.Info.Uid)
  116. list := make([]map[string]string, 0)
  117. if data != nil {
  118. stateList := []string{"待付款", "已支付", "已提货", "已取消"}
  119. for _, v := range *data {
  120. tmp := map[string]string{
  121. "oid": utils.Int64ToStr(v.Oid),
  122. "uid": utils.IntToStr(v.Uid),
  123. "phone": "",
  124. "nickname": "",
  125. "store_name": "",
  126. "state_str": stateList[v.State],
  127. "amount": v.Amount,
  128. "agent_commission": v.AgentCommission,
  129. "state": utils.IntToStr(v.State),
  130. "create_at": v.CreateAt.Format("2006-01-02 15:04:05"),
  131. "confirm_at": utils.Int64ToStr(v.Oid),
  132. }
  133. if v.ConfirmAt.IsZero() == false {
  134. tmp["confirm_at"] = v.ConfirmAt.Format("2006-01-02 15:04:05")
  135. }
  136. user1, _ := db.UserFindByID(svc.MasterDb(c), v.Uid)
  137. if user1 != nil {
  138. tmp["phone"] = user1.Phone
  139. tmp["nickname"] = user1.Nickname
  140. }
  141. store := db.GetUserStore(svc.MasterDb(c), v.StoreUid)
  142. if store != nil {
  143. tmp["store_name"] = store.Name
  144. }
  145. list = append(list, tmp)
  146. }
  147. }
  148. res := map[string]interface{}{
  149. "total": total,
  150. "state": []map[string]string{
  151. {"name": "待付款", "value": "0"},
  152. {"name": "已支付", "value": "1"},
  153. {"name": "已提货", "value": "2"},
  154. {"name": "已取消", "value": "3"},
  155. },
  156. "list": list,
  157. }
  158. e.OutSuc(c, res, nil)
  159. }
  160. func UserStoreOrderPay(c *gin.Context) {
  161. var arg map[string]string
  162. if err := c.ShouldBindJSON(&arg); err != nil {
  163. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  164. return
  165. }
  166. user := svc.GetUser(c)
  167. str := "ctpo.parent_uid=" + utils.IntToStr(user.Info.Uid) + " and ctpo.state=1"
  168. if arg["uid"] != "" {
  169. str += " and ctpo.uid=" + arg["uid"]
  170. }
  171. if arg["store_id"] != "" {
  172. str += " and ctpo.store_uid=" + arg["store_id"]
  173. }
  174. if arg["store_name"] != "" {
  175. str += " and cts.name like '%" + arg["store_name"] + "%'"
  176. }
  177. if arg["phone"] != "" {
  178. str += " and u.phone like '%" + arg["phone"] + "%'"
  179. }
  180. if arg["oid"] != "" {
  181. str += " and ctpo.oid like '%" + arg["oid"] + "%'"
  182. }
  183. if arg["start_time"] != "" {
  184. str += " and ctpo.pay_at>='" + arg["start_time"] + "'"
  185. }
  186. if arg["end_time"] != "" {
  187. str += " and ctpo.pay_at<='" + arg["end_time"] + "'"
  188. }
  189. sql := `select ctpo.pay_at,ctpo.oid,cts.name,u.phone,ctpo.uid,ctpo.amount,ctpo.agent_commission,ctpo.platform_commission from community_team_pay_order ctpo
  190. LEFT JOIN user u on u.uid=ctpo.uid
  191. LEFT JOIN community_team_store cts on cts.uid=ctpo.store_uid
  192. where %s order by ctpo.pay_at desc %s`
  193. size := utils.StrToInt(arg["size"])
  194. start := (utils.StrToInt(arg["p"]) - 1) * size
  195. sql = fmt.Sprintf(sql, str, "limit "+utils.IntToStr(start)+","+utils.IntToStr(size))
  196. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  197. list := make([]map[string]string, 0)
  198. for _, v := range nativeString {
  199. tmp := map[string]string{
  200. "time": v["pay_at"],
  201. "name": v["name"],
  202. "amount": v["amount"],
  203. "phone": v["phone"],
  204. "uid": v["uid"],
  205. "agent_commission": v["agent_commission"],
  206. "oid": v["oid"],
  207. }
  208. list = append(list, tmp)
  209. }
  210. sql1 := `select COUNT(*) as count from community_team_pay_order ctpo
  211. LEFT JOIN user u on u.uid=ctpo.uid
  212. where %s `
  213. sql = fmt.Sprintf(sql, str)
  214. nativeString1, _ := db.QueryNativeString(svc.MasterDb(c), sql1)
  215. total := 0
  216. for _, v := range nativeString1 {
  217. total = utils.StrToInt(v["count"])
  218. }
  219. res := map[string]interface{}{
  220. "total": total,
  221. "list": list,
  222. }
  223. e.OutSuc(c, res, nil)
  224. return
  225. }
  226. // UserStoreOrderDetail 门店订单详情-订单管理共用一个
  227. // @Summary 门店-门店订单详情
  228. // @Tags 门店
  229. // @Description 门店-门店订单详情
  230. // @Accept json
  231. // @Produce json
  232. // @Param req body md.StoreOrderDetail true "请求参数"
  233. // @Success 200 {string} ""
  234. // @Failure 400 {object} md.Response "具体错误"
  235. // @Router /api/v1/communityTeam/agent/store/order/detail [POST]
  236. func UserStoreOrderDetail(c *gin.Context) {
  237. var arg md.StoreOrderDetail
  238. if err := c.ShouldBindJSON(&arg); err != nil {
  239. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  240. return
  241. }
  242. order := db.GetOrderByOid(svc.MasterDb(c), arg.Oid)
  243. if order == nil {
  244. e.OutErr(c, 400, e.NewErr(400, "订单不存在"))
  245. return
  246. }
  247. stateList := []string{"待付款", "已支付", "已提货", "已取消"}
  248. payMethodStr := []string{"余额支付", "支付宝支付", "微信支付"}
  249. orderInfoMap := make([]map[string]string, 0)
  250. res := map[string]interface{}{
  251. "oid": utils.Int64ToStr(order.Oid),
  252. "uid": utils.IntToStr(order.Uid),
  253. "phone": order.Phone,
  254. "nickname": "",
  255. "store_name": "",
  256. "memo": order.Memo,
  257. "coupon": order.Coupon,
  258. "code": order.Code,
  259. "amount": order.Amount,
  260. "all_amount": utils.Float64ToStr(utils.StrToFloat64(order.Amount) + utils.StrToFloat64(order.Coupon)),
  261. "pay_method_str": payMethodStr[order.PayMethod],
  262. "state_str": stateList[order.State],
  263. "state": utils.IntToStr(order.State),
  264. "create_at": order.CreateAt.Format("2006-01-02 15:04:05"),
  265. "confirm_at": "",
  266. "pay_at": "",
  267. "order_info": orderInfoMap,
  268. }
  269. if order.ConfirmAt.IsZero() == false {
  270. res["confirm_at"] = order.ConfirmAt.Format("2006-01-02 15:04:05")
  271. } else {
  272. res["confirm_at"] = order.Timer
  273. if order.IsNow == 1 {
  274. res["confirm_at"] = "立即提货"
  275. }
  276. }
  277. if order.PayAt.IsZero() == false {
  278. res["pay_at"] = order.PayAt.Format("2006-01-02 15:04:05")
  279. }
  280. user, _ := db.UserFindByID(svc.MasterDb(c), order.Uid)
  281. if user != nil {
  282. res["nickname"] = user.Nickname
  283. if order.Phone == "" {
  284. res["phone"] = user.Phone
  285. }
  286. }
  287. store := db.GetUserStore(svc.MasterDb(c), order.StoreUid)
  288. if store != nil {
  289. res["store_name"] = store.Name
  290. }
  291. orderInfo := db.GetOrderInfoAllEg(svc.MasterDb(c), arg.Oid)
  292. if orderInfo != nil {
  293. for _, v := range *orderInfo {
  294. skuData := make([]md.Sku, 0)
  295. json.Unmarshal([]byte(v.SkuInfo), &skuData)
  296. skuStr := ""
  297. for _, v1 := range skuData {
  298. if skuStr != "" {
  299. skuStr += ";"
  300. }
  301. skuStr += v1.Value
  302. }
  303. tmp := map[string]string{
  304. "sku_str": skuStr,
  305. "goods_title": v.Title,
  306. "goods_img": v.Img,
  307. "num": utils.IntToStr(v.Num),
  308. "amount": utils.Float64ToStr(float64(v.Num) * utils.StrToFloat64(v.Price)),
  309. }
  310. orderInfoMap = append(orderInfoMap, tmp)
  311. }
  312. res["order_info"] = orderInfoMap
  313. }
  314. e.OutSuc(c, res, nil)
  315. return
  316. }
  317. // UserStoreTotal 销售额统计
  318. // @Summary 门店-销售额统计
  319. // @Tags 门店
  320. // @Description 门店-销售额统计
  321. // @Accept json
  322. // @Produce json
  323. // @Param req body md.StoreOrderTotal true "请求参数"
  324. // @Success 200 {string} ""
  325. // @Failure 400 {object} md.Response "具体错误"
  326. // @Router /api/v1/communityTeam/agent/store/total [POST]
  327. func UserStoreTotal(c *gin.Context) {
  328. var arg md.StoreOrderTotal
  329. if err := c.ShouldBindJSON(&arg); err != nil {
  330. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  331. return
  332. }
  333. user := svc.GetUser(c)
  334. currentMonth := utils.GetTimeRange("current_month")
  335. today := utils.GetTimeRange("today")
  336. withinSevenDays := utils.GetTimeRange("within_seven_days")
  337. monthSum, _ := svc.MasterDb(c).Where("store_uid=? and parent_uid=? and create_at>=?", arg.StoreUid, user.Info.Uid, time.Unix(currentMonth["start"], 0).Format("2006-01-02 15:04:05")).In("state", []string{"1", "2"}).Sum(&model.CommunityTeamOrder{}, "amount")
  338. daySum, _ := svc.MasterDb(c).Where("store_uid=? and parent_uid=? and create_at>=?", arg.StoreUid, user.Info.Uid, time.Unix(today["start"], 0).Format("2006-01-02 15:04:05")).In("state", []string{"1", "2"}).Sum(&model.CommunityTeamOrder{}, "amount")
  339. withinSevenDaysSum, _ := svc.MasterDb(c).Where("store_uid=? and parent_uid=? and create_at>=?", arg.StoreUid, user.Info.Uid, time.Unix(withinSevenDays["start"], 0).Format("2006-01-02 15:04:05")).In("state", []string{"1", "2"}).Sum(&model.CommunityTeamOrder{}, "amount")
  340. list := []map[string]string{
  341. {"name": "本日销售额", "value": utils.Float64ToStr(daySum)},
  342. {"name": "近七日销售额", "value": utils.Float64ToStr(withinSevenDaysSum)},
  343. {"name": "本月销售额", "value": utils.Float64ToStr(monthSum)},
  344. }
  345. commission, _ := svc.MasterDb(c).Where("store_uid=? and parent_uid=? ", arg.StoreUid, user.Info.Uid).Sum(&model.CommunityTeamOrder{}, "agent_commission")
  346. store := db.GetStoreIdEg(svc.MasterDb(c), arg.StoreUid)
  347. res := map[string]interface{}{
  348. "list": list,
  349. "platform_bili": "-",
  350. "platform_amount": "-",
  351. "base_bili": "-",
  352. "base_amount": "-",
  353. "agent_bili": store.AgentCommission + "%",
  354. "agent_amount": utils.Float64ToStr(commission),
  355. }
  356. e.OutSuc(c, res, nil)
  357. return
  358. }
  359. func StoreWithdrawFlow(c *gin.Context) {
  360. agentSvc.StoreWithdrawFlow(c)
  361. }
  362. func StoreWithdrawTotal(c *gin.Context) {
  363. agentSvc.StoreWithdrawTotal(c)
  364. }
  365. func StoreWithdrawAudit(c *gin.Context) {
  366. agentSvc.StoreWithdrawAudit(c)
  367. }
  368. func StoreWithdrawAuditAll(c *gin.Context) {
  369. agentSvc.StoreWithdrawAuditAll(c)
  370. }
  371. func StoreWithdrawOutPut(c *gin.Context) {
  372. agentSvc.StoreWithdrawOutPut(c)
  373. }