feat: 修改商品属性值列表获取方式,优化商品添加逻辑,调整库存添加方式
This commit is contained in:
parent
f3a502cd3f
commit
ef7dfcb5aa
@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller\store_branch_product_attr_value;
|
||||||
|
|
||||||
|
|
||||||
|
use app\admin\controller\BaseAdminController;
|
||||||
|
use app\admin\lists\store_branch_product_attr_value\StoreBranchProductAttrValueLists;
|
||||||
|
use app\admin\logic\store_branch_product_attr_value\StoreBranchProductAttrValueLogic;
|
||||||
|
use app\admin\validate\store_branch_product_attr_value\StoreBranchProductAttrValueValidate;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 门店商品属性值辅助表控制器
|
||||||
|
* Class StoreBranchProductAttrValueController
|
||||||
|
* @package app\admin\controller\store_branch_product_attr_value
|
||||||
|
*/
|
||||||
|
class StoreBranchProductAttrValueController extends BaseAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取门店商品属性值辅助表列表
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public function lists()
|
||||||
|
{
|
||||||
|
return $this->dataLists(new StoreBranchProductAttrValueLists());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加门店商品属性值辅助表
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public function add()
|
||||||
|
{
|
||||||
|
$params = (new StoreBranchProductAttrValueValidate())->post()->goCheck('add');
|
||||||
|
$result = StoreBranchProductAttrValueLogic::add($params);
|
||||||
|
if (true === $result) {
|
||||||
|
return $this->success('添加成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
return $this->fail(StoreBranchProductAttrValueLogic::getError());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 编辑门店商品属性值辅助表
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public function status()
|
||||||
|
{
|
||||||
|
$params =$this->request->post();
|
||||||
|
$result = StoreBranchProductAttrValueLogic::status($params);
|
||||||
|
if (true === $result) {
|
||||||
|
return $this->success('变更成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 删除门店商品属性值辅助表
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$params = (new StoreBranchProductAttrValueValidate())->post()->goCheck('delete');
|
||||||
|
StoreBranchProductAttrValueLogic::delete($params);
|
||||||
|
return $this->success('删除成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取门店商品属性值辅助表详情
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public function detail()
|
||||||
|
{
|
||||||
|
$params = (new StoreBranchProductAttrValueValidate())->goCheck('detail');
|
||||||
|
$result = StoreBranchProductAttrValueLogic::detail($params);
|
||||||
|
return $this->data($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -47,7 +47,6 @@ class StoreProductController extends BaseAdminController
|
|||||||
if (true === $result) {
|
if (true === $result) {
|
||||||
return $this->success('添加成功', [], 1, 1);
|
return $this->success('添加成功', [], 1, 1);
|
||||||
}
|
}
|
||||||
return $this->fail(StoreProductLogic::getError());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\lists\store_branch_product_attr_value;
|
||||||
|
|
||||||
|
|
||||||
|
use app\admin\lists\BaseAdminDataLists;
|
||||||
|
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
|
||||||
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
use app\common\model\store_product_unit\StoreProductUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 门店商品属性值辅助表列表
|
||||||
|
* Class StoreBranchProductAttrValueLists
|
||||||
|
* @package app\admin\listsstore_branch_product_attr_value
|
||||||
|
*/
|
||||||
|
class StoreBranchProductAttrValueLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 设置搜索条件
|
||||||
|
* @return \string[][]
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public function setSearch(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'=' => ['product_id', 'store_id'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取门店商品属性值辅助表列表
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public function lists(): array
|
||||||
|
{
|
||||||
|
return StoreBranchProductAttrValue::where($this->searchWhere)
|
||||||
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
|
->order(['id' => 'desc'])
|
||||||
|
->select()->each(function ($item) {
|
||||||
|
$item->unit_name = StoreProductUnit::where('id', $item->unit)->value('name');
|
||||||
|
})
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取门店商品属性值辅助表数量
|
||||||
|
* @return int
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public function count(): int
|
||||||
|
{
|
||||||
|
return StoreBranchProductAttrValue::where($this->searchWhere)->count();
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ namespace app\admin\lists\store_product_attr_value;
|
|||||||
use app\admin\lists\BaseAdminDataLists;
|
use app\admin\lists\BaseAdminDataLists;
|
||||||
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
use app\common\model\store_product_unit\StoreProductUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品属性值列表
|
* 商品属性值列表
|
||||||
@ -43,11 +43,11 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear
|
|||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return StoreProductAttrValue::where($this->searchWhere)
|
return StoreProductAttrValue::where($this->searchWhere)
|
||||||
->field(['id', 'product_id'])
|
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()
|
->select()->each(function ($item) {
|
||||||
->toArray();
|
$item->unit_name = StoreProductUnit::where('id', $item->unit)->value('name');
|
||||||
|
})->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -61,5 +61,4 @@ class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSear
|
|||||||
{
|
{
|
||||||
return StoreProductAttrValue::where($this->searchWhere)->count();
|
return StoreProductAttrValue::where($this->searchWhere)->count();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\logic\store_branch_product_attr_value;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
|
||||||
|
use app\common\logic\BaseLogic;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 门店商品属性值辅助表逻辑
|
||||||
|
* Class StoreBranchProductAttrValueLogic
|
||||||
|
* @package app\admin\logic\store_branch_product_attr_value
|
||||||
|
*/
|
||||||
|
class StoreBranchProductAttrValueLogic extends BaseLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加门店商品属性值辅助表
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public static function add(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
StoreBranchProductAttrValue::create([
|
||||||
|
|
||||||
|
]);
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
self::setError($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 编辑门店商品属性值辅助表
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public static function edit(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
StoreBranchProductAttrValue::where('id', $params['id'])->update([
|
||||||
|
|
||||||
|
]);
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
self::setError($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @notes 更新状态
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public static function status(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
StoreBranchProductAttrValue::where('id', $params['id'])->update(['status' => $params['status']]);
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Db::rollback();
|
||||||
|
throw new BusinessException($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 删除门店商品属性值辅助表
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public static function delete(array $params): bool
|
||||||
|
{
|
||||||
|
return StoreBranchProductAttrValue::destroy($params['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取门店商品属性值辅助表详情
|
||||||
|
* @param $params
|
||||||
|
* @return array
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public static function detail($params): array
|
||||||
|
{
|
||||||
|
return StoreBranchProductAttrValue::findOrEmpty($params['id'])->toArray();
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ use app\common\model\store_product_cate\StoreProductCate;
|
|||||||
use app\common\model\system_store\SystemStore;
|
use app\common\model\system_store\SystemStore;
|
||||||
use app\common\model\system_store_storage\SystemStoreStorage;
|
use app\common\model\system_store_storage\SystemStoreStorage;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use support\exception\BusinessException;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use Webman\RedisQueue\Redis;
|
use Webman\RedisQueue\Redis;
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ class StoreProductLogic extends BaseLogic
|
|||||||
'store_name' => $params['store_name'],
|
'store_name' => $params['store_name'],
|
||||||
'image' => $params['image'],
|
'image' => $params['image'],
|
||||||
'store_info' => $params['store_info'] ?? '',
|
'store_info' => $params['store_info'] ?? '',
|
||||||
'bar_code' =>$params['product_arr'][0] ?? '',
|
'bar_code' =>$params['product_arr'][0]['bar_code'] ?? '',
|
||||||
'cate_id' => $params['cate_id'],
|
'cate_id' => $params['cate_id'],
|
||||||
'unit' => $params['product_arr'][0]['unit'],
|
'unit' => $params['product_arr'][0]['unit'],
|
||||||
'stock' => 0,
|
'stock' => 0,
|
||||||
@ -72,31 +73,11 @@ class StoreProductLogic extends BaseLogic
|
|||||||
(new StoreProductAttrValue())->saveAll($arr);
|
(new StoreProductAttrValue())->saveAll($arr);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
|
|
||||||
if ($params['is_store_all'] == 1) {
|
|
||||||
$store_arr = SystemStore::where('is_show', 1)->column('id');
|
|
||||||
foreach ($store_arr as $store_id) {
|
|
||||||
if ($store_id != 5) {
|
|
||||||
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (is_array($params['store_arr']) && count($params['store_arr']) > 0) {
|
|
||||||
foreach ($params['store_arr'] as $key => $store_id) {
|
|
||||||
if ($store_id != 5) {
|
|
||||||
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (getenv('STORE_ID')) {
|
|
||||||
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => getenv('STORE_ID'), 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Throwable $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
self::setError($e->getMessage());
|
d($e);
|
||||||
return false;
|
throw new BusinessException($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +276,6 @@ class StoreProductLogic extends BaseLogic
|
|||||||
'top_cate_id' => $dealCate['top_cate_id'],
|
'top_cate_id' => $dealCate['top_cate_id'],
|
||||||
'two_cate_id' => $dealCate['two_cate_id'],
|
'two_cate_id' => $dealCate['two_cate_id'],
|
||||||
'price' => $find['price'],
|
'price' => $find['price'],
|
||||||
// 'cost' => $find['cost'], //v1.0
|
|
||||||
'cost' => $find['cost'],
|
'cost' => $find['cost'],
|
||||||
'purchase' => $find['purchase'],
|
'purchase' => $find['purchase'],
|
||||||
'vip_price' => $find['vip_price'],
|
'vip_price' => $find['vip_price'],
|
||||||
@ -310,14 +290,14 @@ class StoreProductLogic extends BaseLogic
|
|||||||
'rose' => $find['rose'],
|
'rose' => $find['rose'],
|
||||||
];
|
];
|
||||||
$branch = StoreBranchProduct::create($product);
|
$branch = StoreBranchProduct::create($product);
|
||||||
$arr = [
|
$select=StoreProductAttrValue::where('product_id', $find['id'])->select()->toArray();
|
||||||
'product_id' => $product_arr['id'],
|
|
||||||
'store_id' => $store_id,
|
|
||||||
'sales' => 0,
|
foreach($select as $k=>&$v){
|
||||||
'type' => 0,
|
$v['store_id']=$store_id;
|
||||||
'bar_code' => $find['bar_code']
|
unset($v['id']);
|
||||||
];
|
}
|
||||||
StoreBranchProductAttrValue::create($arr);
|
(new StoreBranchProductAttrValue())->saveAll($select);
|
||||||
return $branch;
|
return $branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\validate\store_branch_product_attr_value;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 门店商品属性值辅助表验证器
|
||||||
|
* Class StoreBranchProductAttrValueValidate
|
||||||
|
* @package app\admin\validate\store_branch_product_attr_value
|
||||||
|
*/
|
||||||
|
class StoreBranchProductAttrValueValidate extends BaseValidate
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置校验规则
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected $rule = [
|
||||||
|
'id' => 'require',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数描述
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected $field = [
|
||||||
|
'id' => 'id',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加场景
|
||||||
|
* @return StoreBranchProductAttrValueValidate
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public function sceneAdd()
|
||||||
|
{
|
||||||
|
return $this->remove('id', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 编辑场景
|
||||||
|
* @return StoreBranchProductAttrValueValidate
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public function sceneEdit()
|
||||||
|
{
|
||||||
|
return $this->only(['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 删除场景
|
||||||
|
* @return StoreBranchProductAttrValueValidate
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public function sceneDelete()
|
||||||
|
{
|
||||||
|
return $this->only(['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 详情场景
|
||||||
|
* @return StoreBranchProductAttrValueValidate
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/08/26 16:17
|
||||||
|
*/
|
||||||
|
public function sceneDetail()
|
||||||
|
{
|
||||||
|
return $this->only(['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user