feat: #10000 店铺增加成本倍率

This commit is contained in:
赵世界 2022-10-24 00:23:09 +08:00
parent 65c6aebf46
commit 21cd070e92
4 changed files with 80 additions and 25 deletions

View File

@ -40,6 +40,7 @@ class ShopsController extends Controller
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'name' => 'required|string|max:191|unique:shops,name', 'name' => 'required|string|max:191|unique:shops,name',
'plat_id' => 'required|integer', 'plat_id' => 'required|integer',
'ratio' => 'required|numeric',
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); $this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
@ -49,6 +50,7 @@ class ShopsController extends Controller
$shop = new Shop(); $shop = new Shop();
$shop->name = $request->name; $shop->name = $request->name;
$shop->plat_id = $request->plat_id; $shop->plat_id = $request->plat_id;
$shop->ratio = $request->ratio;
if (0 == $request->plat_id) { if (0 == $request->plat_id) {
$shop->status = 2; $shop->status = 2;
} }
@ -57,6 +59,15 @@ class ShopsController extends Controller
return response($this->res, $this->res['httpCode']); return response($this->res, $this->res['httpCode']);
} }
public function update(Request $request, $id)
{
$shop = Shop::query()->find($id);
$shop->ratio = $request->ratio;
$shop->save();
return response($this->res, $this->res['httpCode']);
}
public function authBind(Request $request) public function authBind(Request $request)
{ {
[$shopId, $platId] = explode('_', $request->get('state')); [$shopId, $platId] = explode('_', $request->get('state'));

View File

@ -29,6 +29,7 @@ class CreateShopsTable extends Migration
$table->text('scope')->nullable()->comment('接口列表'); $table->text('scope')->nullable()->comment('接口列表');
$table->text('pop_auth_token_create_response')->nullable()->comment('授权认证信息'); $table->text('pop_auth_token_create_response')->nullable()->comment('授权认证信息');
$table->unsignedTinyInteger('status')->index()->default(0)->comment('状态'); $table->unsignedTinyInteger('status')->index()->default(0)->comment('状态');
$table->decimal('ratio')->default(1)->comment('成本倍率');
$table->softDeletes(); $table->softDeletes();
$table->timestamps(); $table->timestamps();
//索引 //索引

View File

@ -4,32 +4,40 @@ import http from "@/util/http.js";
// 店铺平台 // 店铺平台
export function shopListId() { export function shopListId() {
return http({ return http({
url: "/api/shop_platforms", url: "/api/shop_platforms",
method: "get", method: "get",
}); });
} }
// 店铺新增 // 店铺新增
export function shopAdd(data) { export function shopAdd(data) {
return http({ return http({
url: "/api/shops", url: "/api/shops",
method: "post", method: "post",
data, data,
}); });
} }
// 店铺列表 // 店铺列表
export function storeList(params) { export function storeList(params) {
return http({ return http({
url: "/api/shops", url: "/api/shops",
method: "get", method: "get",
params, params,
}); });
} }
// 下载商品 // 下载商品
export function downloadGoods(id) { export function downloadGoods(id) {
return http({ return http({
url: `/api/download/${id}/goods`, url: `/api/download/${id}/goods`,
method: "get", method: "get",
}); });
}
export function updateStore(id, params) {
return http({
url: `/api/shops/${id}`,
method: "patch",
params,
});
} }

View File

@ -5,10 +5,16 @@
<div class="table" style="margin-top: 10px"> <div class="table" style="margin-top: 10px">
<el-table v-loading="loading" :data="tableData" style="width: 100%"> <el-table v-loading="loading" :data="tableData" style="width: 100%">
<el-table-column prop="id" label="ID" width="180"> </el-table-column> <el-table-column prop="id" label="ID"> </el-table-column>
<el-table-column prop="name" label="店铺名称" width="180"> <el-table-column prop="name" label="店铺名称">
</el-table-column> </el-table-column>
<el-table-column prop="plat_id" label="所属平台"></el-table-column> <el-table-column prop="plat_id" label="所属平台"></el-table-column>
<el-table-column label="成本倍率">
<template slot-scope="scope">
<el-input v-model="scope.row.ratio" placeholder="成本倍率" @change="handleCellChange(scope.row)">
</el-input>
</template>
</el-table-column>
<el-table-column label="操作"> <el-table-column label="操作">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="danger" v-if="scope.row.status === '未授权'"><a :href="scope.row.authUrl" <el-button type="danger" v-if="scope.row.status === '未授权'"><a :href="scope.row.authUrl"
@ -47,17 +53,20 @@
</div> </div>
<!-- 新增店铺 --> <!-- 新增店铺 -->
<el-dialog title="新增店铺" :visible.sync="dialogFormVisible" :close-on-click-modal="false"> <el-dialog title="新增店铺" :visible.sync="dialogFormVisible" :close-on-click-modal="false" width="20%">
<el-form :model="form"> <el-form ref="form" :rules="rules" :model="form" lable-width="80px">
<el-form-item label="店铺名称"> <el-form-item label="店铺名称">
<el-input v-model="form.name" placeholder="输入店铺名称"></el-input> <el-input v-model="form.name" placeholder="输入店铺名称" style="width: 400px;"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="店铺平台"> <el-form-item label="店铺平台">
<el-select v-model="form.plat_id" placeholder="输入店铺平台"> <el-select v-model="form.plat_id" placeholder="输入店铺平台" style="width: 400px;">
<el-option v-for="(item, index) in storeId" :key="index" :label="item" :value="index"> <el-option v-for="(item, index) in storeId" :key="index" :label="item" :value="index">
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="成本倍率">
<el-input v-model="form.ratio" placeholder="成本倍率" style="width: 400px;"></el-input>
</el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false"> </el-button> <el-button @click="dialogFormVisible = false"> </el-button>
@ -68,7 +77,7 @@
</template> </template>
<script> <script>
import { shopListId, shopAdd, storeList, downloadGoods } from "../../api/shop"; import { shopListId, shopAdd, storeList, downloadGoods, updateStore } from "../../api/shop";
export default { export default {
data() { data() {
return { return {
@ -76,6 +85,18 @@ export default {
form: { form: {
name: "", name: "",
plat_id: "", plat_id: "",
ratio: 1,
},
rules: {
name: [
{ required: true, message: '请输入店铺名称', trigger: 'blur' },
],
plat_id: [
{ required: true, message: '请选择店铺平台', trigger: 'blur' },
],
ratio: [
{ required: true, message: '请输入成本倍率', trigger: 'blur', },
],
}, },
storeId: [], // id storeId: [], // id
loading: true, loading: true,
@ -161,6 +182,20 @@ export default {
}); });
}); });
}, },
handleCellChange(row) {
this.$confirm('确认修改成本倍率吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateStore(row.id, { ratio: row.ratio }).then((res) => {
this.$message({
type: 'info',
message: res.data.message
})
})
});
},
}, },
}; };
</script> </script>