Exemple #1
0
        /// <summary>
        /// 更新ConsumptionModel
        /// </summary>
        /// <param name="model">Model</param>
        /// <returns></returns>
        public async Task <bool> CancelOppointment(ConsumptionModel model, GoodsItemModel goodsItemModel, MerchantScheduleDetailModel msdModel)
        {
            var result = await MySqlHelper.TransactionAsync(async (conn, tran) =>
            {
                //消费预约信息
                if (await conn.UpdateAsync(model) < 1)
                {
                    return(false);
                }

                //撤回已扣除数量
                if (await conn.UpdateAsync(goodsItemModel) < 1)
                {
                    return(false);
                }

                //取消预约后,若个人商品处于不可用状态时,更新个人商品为可用状态
                await conn.ExecuteAsync("update t_consumer_goods set available=1 where goods_guid=@goodsGuid and available=0", new { goodsGuid = goodsItemModel.GoodsGuid });

                //去除预约所占的时间
                await conn.DeleteAsync <MerchantScheduleDetailModel>(msdModel.LockDetailGuid);
                await conn.DeleteAsync(msdModel);

                return(true);
            });

            return(result);
        }
Exemple #2
0
        public GoodsItem Create([FromBody] GoodsItemModel item)
        {
            var goods = new GoodsItem(item.Name, item.Shipper, _user.Id,
                                      new GoodsCharacteristics
            {
                TemperatureLow  = item.TemperatureLow,
                TemperatureHigh = item.TemperatureHigh,
                HumidityLow     = item.HumidityLow,
                HumidityHigh    = item.HumidityHigh,
                Volume          = item.Volume
            });

            return(_service.Create(goods));
        }
Exemple #3
0
        /// <summary>
        /// 预约记录过期不扣除可用项目次数
        /// </summary>
        /// <returns></returns>
        public async Task <bool> MissConsumptionWithoutAbatementAsync(ConsumptionModel model, GoodsItemModel goodsItemModel)
        {
            var result = await MySqlHelper.TransactionAsync(async (conn, tran) =>
            {
                //消费预约信息
                if (await conn.UpdateAsync(model) < 1)
                {
                    return(false);
                }

                //撤回已扣除数量
                if (await conn.UpdateAsync(goodsItemModel) < 1)
                {
                    return(false);
                }

                //取消预约后,若个人商品处于不可用状态时,更新个人商品为可用状态
                await conn.ExecuteAsync("update t_consumer_goods set available=1 where goods_guid=@goodsGuid and available=0", new { goodsGuid = goodsItemModel.GoodsGuid });

                return(true);
            });

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// 消费预约
        /// </summary>
        /// <param name="consumptionModel">消费预约model</param>
        /// <param name="merchantScheduleDetailModel">预约时间明细model</param>
        /// <param name="item">个人卡项model</param>
        /// <param name="lockScheduleDetailModel">预约锁定时间明细model</param>
        /// <returns></returns>
        public async Task <bool> MakeAnAppointmentWithConsumption(ConsumptionModel consumptionModel, MerchantScheduleDetailModel merchantScheduleDetailModel, GoodsItemModel item, MerchantScheduleDetailModel lockScheduleDetailModel = null)
        {
            return(await MySqlHelper.TransactionAsync(async (conn, tran) =>
            {
                var lockUpdate = lockScheduleDetailModel;
                var sql = @"UPDATE t_merchant_schedule_detail a
                            LEFT JOIN t_merchant_schedule_detail b ON a.schedule_guid = b.schedule_guid
                            AND b.`enable` = 1
                            AND a.schedule_detail_guid <> b.schedule_detail_guid
                            AND b.last_updated_date < a.last_updated_date
                            AND (
                           ( a.start_time >= b.start_time AND a.start_time<b.end_time )
                            OR ( a.end_time > b.start_time AND a.end_time<=b.end_time )
                            )
                            SET a.consumption_guid = @consumptionGuid $lockUpdate$
                            WHERE
	                            a.schedule_detail_guid = @scheduleDetailGuid
                                AND a.`enable` = 1
	                            AND b.schedule_detail_guid IS NULL;"    ;

                if (lockScheduleDetailModel != null)
                {
                    //插入预约排班明细(项目间隔锁定时间)
                    if (string.IsNullOrEmpty(await conn.InsertAsync <string, MerchantScheduleDetailModel>(lockScheduleDetailModel)))
                    {
                        return false;
                    }

                    //检查预约时间是否可行(项目间隔锁定时间,有无时间交叉?)
                    if ((await conn.ExecuteAsync(sql.Replace("$lockUpdate$", ""), new { scheduleDetailGuid = lockScheduleDetailModel.ScheduleDetailGuid, consumptionGuid = "Lock" })) == 0)
                    {
                        return false;
                    }
                }

                //插入预约排班明细
                if (string.IsNullOrEmpty(await conn.InsertAsync <string, MerchantScheduleDetailModel>(merchantScheduleDetailModel)))
                {
                    return false;
                }

                //检查预约时间是否可行(有无时间交叉?)
                if ((await conn.ExecuteAsync(sql.Replace("$lockUpdate$", $",a.lock_detail_guid='{lockScheduleDetailModel?.ScheduleDetailGuid}'"), new { scheduleDetailGuid = merchantScheduleDetailModel.ScheduleDetailGuid, consumptionGuid = consumptionModel.ConsumptionGuid })) == 0)
                {
                    return false;
                }

                //插入消费记录
                if (string.IsNullOrEmpty(await conn.InsertAsync <string, ConsumptionModel>(consumptionModel)))
                {
                    return false;
                }

                if ((await conn.UpdateAsync(item) != 1))
                {
                    return false;
                }

                return true;
            }));
        }