Esempio n. 1
0
        public object Do_ScanOrderCode(BaseApi baseApi)
        {
            ScanOrderCodeParam scanOrderCodeParam = JsonConvert.DeserializeObject <ScanOrderCodeParam>(baseApi.param.ToString());

            if (scanOrderCodeParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            StoreGoodsCode storeGoodsCode = Utils.GetCache <StoreGoodsCode>(scanOrderCodeParam);

            if (storeGoodsCode == null)
            {
                throw new ApiException(CodeMessage.InvalidOrderCode, "InvalidOrderCode");
            }
            StoreDao  storeDao  = new StoreDao();
            string    storeId   = storeDao.GetStoreId(storeGoodsCode.order.storeCode);
            OpenDao   openDao   = new OpenDao();
            StoreUser storeUser = openDao.GetStoreUser(Utils.GetOpenID(baseApi.token));

            if (storeUser.storeId != storeId)
            {
                throw new ApiException(CodeMessage.NotStoreUserOrder, "NotStoreUserOrder");
            }
            Utils.DeleteCache <StoreGoodsCode>(scanOrderCodeParam);
            return(storeGoodsCode.order);
        }
Esempio n. 2
0
        public object Do_GetStoreGoodsCode(BaseApi baseApi)
        {
            GetStoreGoodsCodeParam getStoreGoodsCodeParam = JsonConvert.DeserializeObject <GetStoreGoodsCodeParam>(baseApi.param.ToString());

            if (getStoreGoodsCodeParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            OrderDao orderDao = new OrderDao();
            Order    order    = orderDao.GetOrderInfo(getStoreGoodsCodeParam.orderId);

            if (order == null)
            {
                throw new ApiException(CodeMessage.InvalidOrderState, "InvalidOrderState");
            }
            if (order.state != "2")
            {
                throw new ApiException(CodeMessage.InvalidOrderState, "InvalidOrderState");
            }
            string scanCode = "";

            using (var md5 = MD5.Create())
            {
                var result    = md5.ComputeHash(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()));
                var strResult = BitConverter.ToString(result);
                scanCode = "ORDER_" + strResult.Replace("-", "");
            }
            ScanOrderCodeParam scanOrderCodeParam = new ScanOrderCodeParam
            {
                code = scanCode,
            };

            StoreGoodsCode storeGoodsCode = new StoreGoodsCode
            {
                code   = scanCode,
                order  = order,
                Unique = scanOrderCodeParam.GetUnique(),
            };

            Utils.SetCache(storeGoodsCode, 0, 0, 30);

            return(scanCode);
        }