username@email.com
2021-10-09 f33ece65bdfd7b8354bd5046d4b9d2d600643b0f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using DTO;
using IServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Transactions;
using zhengcaioa.IService;
using zhengcaioa.Models;
 
namespace zhengcaioa.Controllers.admin
{
    public class AdmGoodsRecordController : Controller
    {
        private readonly ILogger<AdmGoodsRecordController> _logger;
        private readonly IAdmGoodsRecordService _admGoodsRecordService;
        private readonly ILiaotianService _liaotianService;
 
        private readonly IAdmGoodsManageService _admGoodsManageService;
 
        public AdmGoodsRecordController(ILogger<AdmGoodsRecordController> logger, IAdmGoodsRecordService admGoodsRecordService, ILiaotianService liaotianService
            , IAdmGoodsManageService admGoodsManageService)
        {
            _logger = logger;
          
            _liaotianService = liaotianService;
            _admGoodsRecordService = admGoodsRecordService;
            _admGoodsManageService = admGoodsManageService;
        }
 
        //出库接口
        public IActionResult BookChuKu([FromBody] AdmGoodsRecordDTO dto)
        {
            ReturnMsg<List<ProjectDTO>> returnMsg = new ReturnMsg<List<ProjectDTO>>();
            returnMsg.code = 2;
 
            if (string.IsNullOrEmpty(dto.ISBN))
            {
                
                    returnMsg.code = 2;
                    returnMsg.error = "没有ISBN";
                    returnMsg.count = 0;
                    return new JsonResult(returnMsg);
              
            }
 
            var admGoodsManageDTOs = _admGoodsManageService.GetList().Where(x=>x.ISBN == dto.ISBN).FirstOrDefault();
            
            if (admGoodsManageDTOs==null)
            {
                
               
                    returnMsg.code = 2;
                    returnMsg.error = "没有找到该商品";
                    returnMsg.count = 0;
                    return new JsonResult(returnMsg);
 
            }
            else if(!admGoodsManageDTOs.GoodsLeft.HasValue )
            {
                returnMsg.code = 2;
                returnMsg.error = "该商品没有库存";
                returnMsg.count = 0;
                return new JsonResult(returnMsg);
            }
            else if (admGoodsManageDTOs.GoodsLeft.Value< dto.GoodsNum)
            {
                returnMsg.code = 2;
                returnMsg.error = "该商品库存不足";
                returnMsg.count = 0;
                return new JsonResult(returnMsg);
            }
 
           
 
 
 
 
 
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    var left = admGoodsManageDTOs.GoodsLeft - dto.GoodsNum;
                    dto.GoodsId = admGoodsManageDTOs.Id;
                    dto.GoodsLeft = left;
                    dto.RecordTypeId = "02";
 
                    admGoodsManageDTOs.GoodsLeft = left;
 
                    var resultEntity = _admGoodsManageService.save(admGoodsManageDTOs);
 
                    dto.RecStatus = "A";
                    if (String.IsNullOrEmpty(dto.Id))
                    {
                        dto.Creater = "1";
                        dto.Createtime = DateTime.Now;
                    }
                    dto.Modifier = "1";
                    dto.Modifytime = DateTime.Now;
 
                    resultEntity = _admGoodsRecordService.save(dto);
 
                    returnMsg.code = 1;
                    returnMsg.count = 0;
                    returnMsg.returnObj = null;
                    scope.Complete();
                }
 
            }
            catch (Exception ex)
            {
                returnMsg.code = 2;
                returnMsg.error = "没有获取到token";
                returnMsg.count = 0;
 
            }
            return new JsonResult(returnMsg);
        }
    }
}