附近小店
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

318 satır
11 KiB

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