Beispiel #1
0
func (c *PhotoController) PostAddOrder() {
	beego.Debug(c.Input())
	request_json := `{"errcode":1,"errmsg":"request_json error"}`
	if c.Ctx.Input.IsGet() {
		beego.Debug("PostAddOrder Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("PostAddOrder Post")
		size_id := c.Input().Get("size_id")
		temp_id := c.Input().Get("temp_id")
		photos := c.Input().Get("photos")
		//json 到 []string
		var photos_i []int64
		beego.Debug(photos)
		err := json.Unmarshal([]byte(photos), &photos_i)
		if err != nil {
			beego.Error(photos_i)
			request_json = `{"errcode":1,"errmsg":"to json error"}`
			c.Ctx.WriteString(request_json)
			return
		}
		order_number := getOrderNumber(size_id, temp_id, len(photos_i))
		beego.Debug("order_number:", order_number)
		openid, err := getPhotoOpenId(c.Ctx)
		if err != nil {
			beego.Error(err)
			request_json = `{"errcode":1,"errmsg":"getPhotoOpenId error"}`
			c.Ctx.WriteString(request_json)
			return
		}
		_, err = models.AddPorder(openid, order_number, photos, temp_id, size_id)
		if err != nil {
			beego.Error(err)
			request_json = `{"errcode":1,"errmsg":"AddPorder error"}`
			c.Ctx.WriteString(request_json)
			return
		}
		_, err = models.AddPdetails(openid, order_number, 1, "订单已经生成,等待客服处理")
		if err != nil {
			beego.Error(err)
			request_json = `{"errcode":1,"errmsg":"AddPorder error"}`
			c.Ctx.WriteString(request_json)
			return
		}
		request_json = `{"errcode":0,"errmsg":"","data":""}`
	}
	c.Ctx.WriteString(request_json)
}
Beispiel #2
0
func (c *PhotoController) PostAdminUpState() {
	beego.Debug(c.Input())
	request_json := `{"errcode":1,"errmsg":"request_json error"}`
	if c.Ctx.Input.IsGet() {
		beego.Debug("PostAadminUpState Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("PostAadminUpState Post")
		id := c.Input().Get("id")
		state := c.Input().Get("state")
		if len(id) == 0 || len(state) == 0 {
			request_json = `{"errcode":1,"errmsg":"id or state error"}`
			c.Ctx.WriteString(request_json)
			return
		}
		porder, err := models.GetPorder(id)
		if err != nil {
			beego.Error(err)
			request_json = `{"errcode":1,"errmsg":"GetPorder error"}`
			c.Ctx.WriteString(request_json)
			return
		}

		otype := int8(0)
		det := "类型错误"
		switch state {
		case "1":
			otype = int8(1)
			det = "订单已经生成,等待客服处理"
			break
		case "2":
			otype = int8(2)
			det = "客服确认订单"
			break
		case "3":
			otype = int8(3)
			det = "客服发送物流"
			break
		case "4":
			otype = int8(4)
			det = "订单完成"
			break
		}
		if otype == int8(0) {
			request_json = `{"errcode":1,"errmsg":"otype error"}`
			c.Ctx.WriteString(request_json)
			return
		}
		err = models.UpPorderState(id, state)
		if err != nil {
			beego.Error(err)
			request_json = `{"errcode":1,"errmsg":"UpPorderState error"}`
			c.Ctx.WriteString(request_json)
			return
		}
		_, err = models.AddPdetails(porder.OpenId, porder.Pnumber, otype, det)
		if err != nil {
			beego.Error(err)
			request_json = `{"errcode":1,"errmsg":"AddPorder error"}`
			c.Ctx.WriteString(request_json)
			return
		}
		request_json = fmt.Sprintf(`{"errcode":0,"errmsg":"","data":%d}`, otype)
		beego.Debug("request_json :", request_json)
	}
	c.Ctx.WriteString(request_json)
}