添加商品规格列表

This commit is contained in:
luofei 2024-06-05 11:00:42 +08:00
parent fe4cb330c9
commit 4cf9124a85
5 changed files with 103 additions and 45 deletions

View File

@ -44,6 +44,9 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array
{
return StoreOrder::where($this->searchWhere)
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
$query->where('store_id', '=', $this->request->adminInfo['store_id']);
})
->field(['id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
@ -63,7 +66,11 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
*/
public function count(): int
{
return StoreOrder::where($this->searchWhere)->count();
return StoreOrder::where($this->searchWhere)
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
$query->where('store_id', '=', $this->request->adminInfo['store_id']);
})
->count();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace app\common\controller;
use hg\apidoc\annotation as ApiDoc;
class Definitions
{
#[
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
]
public function token()
{
}
#[
ApiDoc\Query("page_no", type: "int", require: false, default: 1, desc: "页码"),
ApiDoc\Query("page_size", type: "int", require: false, default: 25, desc: "每页条数"),
]
public function page()
{
}
}

View File

@ -4,6 +4,7 @@ namespace app\common\model\store_branch_product_attr_value;
use app\common\model\BaseModel;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use think\model\concern\SoftDelete;
@ -18,5 +19,9 @@ class StoreBranchProductAttrValue extends BaseModel
protected $name = 'store_branch_product_attr_value';
protected $deleteTime = 'delete_time';
public function attr()
{
return $this->hasOne(StoreProductAttrValue::class, 'unique', 'unique')->bind(['image']);
}
}

View File

@ -3,12 +3,12 @@
namespace app\store\controller\store_product_attr_value;
use app\common\controller\Definitions;
use app\store\controller\BaseAdminController;
use app\store\lists\store_product_attr_value\StoreProductAttrValueLists;
use app\store\logic\store_product_attr_value\StoreProductAttrValueLogic;
use app\store\validate\store_product_attr_value\StoreProductAttrValueValidate;
use hg\apidoc\annotation as ApiDoc;
#[ApiDoc\NotParse()]
/**
@ -16,28 +16,47 @@ use hg\apidoc\annotation as ApiDoc;
* Class StoreProductAttrValueController
* @package app\store\controller\store_product_attr_value
*/
#[ApiDoc\title('商品属性值')]
class StoreProductAttrValueController extends BaseAdminController
{
/**
* @notes 获取商品属性值列表
* @return \think\response\Json
* @author admin
* @date 2024/05/31 14:10
*/
#[
ApiDoc\Title('商品属性值列表'),
ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/lists'),
ApiDoc\Method('GET'),
ApiDoc\NotHeaders(),
ApiDoc\Header(ref: [Definitions::class, "token"]),
ApiDoc\Query(ref: [Definitions::class, "page"]),
ApiDoc\Query(name: 'product_id', type: 'int', require: true, desc: '商品ID'),
ApiDoc\Query(name: 'store_id', type: 'int', require: true, desc: '门店ID'),
ApiDoc\ResponseSuccess("data", type: "array", children: [
['name' => 'count', 'desc' => '总数', 'type' => 'int'],
['name' => 'page_no', 'desc' => '页码', 'type' => 'int'],
['name' => 'page_size', 'desc' => '每页数量', 'type' => 'int'],
['name' => 'extend', 'desc' => '扩展数据', 'type' => 'array'],
['name' => 'lists', 'desc' => '列表数据', 'type' => 'array', 'children' => [
['name' => 'id', 'desc' => 'ID', 'type' => 'int'],
['name' => 'product_id', 'desc' => '商品ID', 'type' => 'int'],
['name' => 'stock', 'desc' => '库存', 'type' => 'int'],
['name' => 'unique', 'desc' => '唯一值', 'type' => 'string'],
['name' => 'sales', 'desc' => '销量', 'type' => 'int'],
['name' => 'bar_code', 'desc' => '条码', 'type' => 'string'],
['name' => 'image', 'desc' => '规格图片', 'type' => 'string'],
]],
]),
]
public function lists()
{
return $this->dataLists(new StoreProductAttrValueLists());
}
/**
* @notes 添加商品属性值
* @return \think\response\Json
* @author admin
* @date 2024/05/31 14:10
*/
#[
ApiDoc\Title('添加商品属性值'),
ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/add'),
ApiDoc\Method('POST'),
ApiDoc\NotHeaders(),
ApiDoc\Header(ref: [Definitions::class, "token"]),
]
public function add()
{
$params = (new StoreProductAttrValueValidate())->post()->goCheck('add');
@ -48,13 +67,13 @@ class StoreProductAttrValueController extends BaseAdminController
return $this->fail(StoreProductAttrValueLogic::getError());
}
/**
* @notes 编辑商品属性值
* @return \think\response\Json
* @author admin
* @date 2024/05/31 14:10
*/
#[
ApiDoc\Title('编辑商品属性值'),
ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/edit'),
ApiDoc\Method('POST'),
ApiDoc\NotHeaders(),
ApiDoc\Header(ref: [Definitions::class, "token"]),
]
public function edit()
{
$params = (new StoreProductAttrValueValidate())->post()->goCheck('edit');
@ -65,13 +84,13 @@ class StoreProductAttrValueController extends BaseAdminController
return $this->fail(StoreProductAttrValueLogic::getError());
}
/**
* @notes 删除商品属性值
* @return \think\response\Json
* @author admin
* @date 2024/05/31 14:10
*/
#[
ApiDoc\Title('删除商品属性值'),
ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/delete'),
ApiDoc\Method('POST'),
ApiDoc\NotHeaders(),
ApiDoc\Header(ref: [Definitions::class, "token"]),
]
public function delete()
{
$params = (new StoreProductAttrValueValidate())->post()->goCheck('delete');
@ -79,13 +98,14 @@ class StoreProductAttrValueController extends BaseAdminController
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取商品属性值详情
* @return \think\response\Json
* @author admin
* @date 2024/05/31 14:10
*/
#[
ApiDoc\Title('获取商品属性值详情'),
ApiDoc\url('/store/store_product_attr_value/storeProductAttrValue/detail'),
ApiDoc\Method('GET'),
ApiDoc\Author('中国队长'),
ApiDoc\NotHeaders(),
ApiDoc\Header(ref: [Definitions::class, "token"]),
]
public function detail()
{
$params = (new StoreProductAttrValueValidate())->goCheck('detail');

View File

@ -3,8 +3,8 @@
namespace app\store\lists\store_product_attr_value;
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
use app\store\lists\BaseAdminDataLists;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\lists\ListsSearchInterface;
@ -26,7 +26,7 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear
public function setSearch(): array
{
return [
'=' => ['product_id'],
'=' => ['product_id', 'store_id'],
];
}
@ -42,8 +42,8 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear
*/
public function lists(): array
{
return StoreProductAttrValue::where($this->searchWhere)
->field(['id', 'product_id'])
return StoreBranchProductAttrValue::with('attr')->where($this->searchWhere)
->field(['id', 'product_id', 'stock', 'unique', 'sales', 'bar_code'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
@ -59,7 +59,7 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear
*/
public function count(): int
{
return StoreProductAttrValue::where($this->searchWhere)->count();
return StoreBranchProductAttrValue::with('attr')->where($this->searchWhere)->count();
}
}