项目结构
| 序号 |
项目名称 |
说明 |
引用的类库 |
备注 |
| 1 |
DTcms.Core.Admin |
后台管理项目 |
无 |
作为后台管理项目,可能是供管理员使用的Web应用,管理整个系统。独立性较强,不引用其他类库,确保管理员工具的安全性。 |
| 2 |
DTcms.Core.API |
RESTful API接口项目 |
Model、IServices、Services、DBFactory、Common |
提供RESTful API服务,可能是为外部应用或前端提供数据接口。 |
| 3 |
DTcms.Core.Common |
公共组件方法类库 |
无 |
包含一系列公共工具和方法,为其他项目提供支持。 |
| 4 |
DTcms.Core.DBFactory |
数据库工厂类库 |
Model、Common |
提供数据库上下文和数据库策略功能,连接模型与实际数据库。 |
| 5 |
DTcms.Core.IServices |
数据访问层接口类库 |
Model、Common |
定义数据访问层的接口,方便依赖注入。 |
| 6 |
DTcms.Core.Model |
数据库表实体类库 |
无 |
定义与数据库相关的数据模型,同时包括数据传输对象 (DTO)。 |
| 7 |
DTcms.Core.Services |
数据访问层接口实现类库 |
Model、IServices、DBFactory、Common |
实现数据访问层的接口,完成与数据库的交互。 |
| 8 |
DTcms.Core.Web |
网站前台项目 |
Model、Common |
前台展示项目,供用户访问和互动。 |
### -1、前端html代码片段
<el-table :data="model.orderGoods" border class="table-form">
<el-table-column label="商品名称" min-width="220">
<template slot-scope="scope">
<el-image class="pic" fit="contain" :src="$api.loadFile(scope.row.imgUrl)">
<div slot="error" class="image-slot">
<i class="el-icon-picture-outline"></i>
</div>
</el-image>
<h4>{{scope.row.goodsTitle}}</h4>
<span class="date">{{scope.row.goodsNo}}</span>
</template>
</el-table-column>
<el-table-column label="规格" min-width="120">
<template slot-scope="scope">
<span class="nowrap">{{scope.row.specText}}</span>
</template>
</el-table-column>
<el-table-column label="现价格" width="100">
<template slot-scope="scope">
<div v-if="model.paymentStatus=='1'">
<span class="nowrap">{{scope.row.realPrice}}</span>
</div>
<div v-else>
<el-input v-model="scope.row.realPrice" @blur="handleQuantityChange(scope.row)" type="number"></el-input>
</div>
</template>
</el-table-column>
<el-table-column prop="goodsPrice" label="原售价" width="80"></el-table-column>
<el-table-column label="数量" width="100">
<template slot-scope="scope">
<div v-if="model.paymentStatus=='1'">
<span class="nowrap">{{scope.row.quantity}}</span>
</div>
<div v-else>
<el-input v-model="scope.row.quantity" @blur="handleQuantityChange(scope.row)" type="number"></el-input>
</div>
</template>
</el-table-column>
</el-table>
0、前端JS代码片段
handleQuantityChange(row) {
let _this = this;
const newQuantity = row.quantity;
if (newQuantity < 1) {
this.$message.error('数量不能小于1');
return;
}
if (row.realPrice < 1) {
this.$message.error('价格不能小于1');
return;
}
_this.$api.request({
method: 'put',
url: '/admin/order/ordergoods/' + _this.model.id,
data: _this.model.orderGoods,
successMsg: '商品信息修改成功',
beforeSend() {
_this.loading = true
},
success(res) {
},
complete() {
_this.loading = false
}
});
},
1、先在DTcms.Core.API增加一个方法“UpdateOrderGoods”修改待付款商品实际成交价格和购买数量
[HttpPut("ordergoods/{id}")]
[Authorize]
[AuthorizeFilter("Order", ActionType.Edit)]
public async Task<IActionResult> UpdateOrderGoods([FromRoute] long id, [FromBody] List<OrderGoodsEditDto> modelDto)
{
foreach (var item in modelDto)
{
var result = await _orderService.UpdateOrderGoodsAsync(item.Id, item);
}
return NoContent();
}
2、DTcms.Core.IServices 在数据访问层增加一个接口
Task<bool> UpdateOrderGoodsAsync(long id, OrderGoodsEditDto modelDto, WriteRoRead writeRoRead = WriteRoRead.Write);
3、DTcms.Core.Services 在数据访问层增加一个接口实现
public async Task<bool> UpdateOrderGoodsAsync(long id, OrderGoodsEditDto modelDto, WriteRoRead writeAndRead = WriteRoRead.Write)
{
_context = _contextFactory.CreateContext(writeAndRead);
var model = await _context.Set<OrderGoods>().FirstOrDefaultAsync(x => x.Id == id);
if (model == null)
{
throw new ResponseException("订单商品不存在或已删除");
}
model.RealPrice = modelDto.RealPrice;
model.Quantity = modelDto.Quantity;
_context.Set<OrderGoods>().Update(model);
return await this.SaveAsync();
}
4、DTcms.Core.Model在数据表实体类 增加一个Dto OrderGoodsEditDto
public class OrderGoodsEditDto
{
[Display(Name = "自增ID")]
public long Id { get; set; }
[Display(Name = "所属订单")]
public long OrderId { get; set; }
[Display(Name = "所属货品")]
public long ProductId { get; set; }
[Display(Name = "购买数量")]
public int Quantity { get; set; } = 1;
[Display(Name ="实际价格")]
[Column(TypeName = "decimal(18, 2)")]
public decimal RealPrice { get; set; } = 0M;
}