feat: 添加门店商品添加、编辑、删除及详情查询功能
This commit is contained in:
parent
e46aa8d36e
commit
a059048407
117
app/admin/logic/store_branch_product/StoreBranchProductLogic.php
Normal file
117
app/admin/logic/store_branch_product/StoreBranchProductLogic.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\store_branch_product;
|
||||
|
||||
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
use Webman\RedisQueue\Redis;
|
||||
|
||||
/**
|
||||
* 门店商品逻辑
|
||||
* Class StoreBranchProductLogic
|
||||
* @package app\admin\logic\store_branch_product
|
||||
*/
|
||||
class StoreBranchProductLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加门店商品
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/06/07 13:56
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
StoreBranchProduct::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/06/07 13:56
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data=[
|
||||
'store_name'=>$params['store_name'],
|
||||
'image'=>$params['image'],
|
||||
'price'=>$params['price'],
|
||||
'bar_code'=>$params['bar_code'],
|
||||
'unit'=>$params['unit'],
|
||||
'status'=>$params['status'],
|
||||
];
|
||||
if(isset($params['cate_id'])){
|
||||
$StoreProduct=StoreBranchProduct::where('id', $params['id'])->find();
|
||||
if ($StoreProduct['cate_id'] != $params['cate_id']) {
|
||||
$find=Db::name('store_product_cate')->where(['cate_id'=>$params['cate_id'],'store_id'=>$StoreProduct['store_id']])->find();
|
||||
if($find['pid']>0){
|
||||
$two=Db::name('store_product_cate')->where(['cate_id'=>$find['pid'],'store_id'=>$StoreProduct['store_id']])->find();
|
||||
Db::name('store_product_cate')->where('id',$find['id'])->dec('count',1)->update();
|
||||
Db::name('store_product_cate')->where('id',$two['id'])->dec('count',1)->update();
|
||||
if($two['pid']>0){
|
||||
Db::name('store_product_cate')->where('id',$two['pid'])->dec('count',1)->update();
|
||||
}
|
||||
}
|
||||
Redis::send('store-storage', ['product_arr' => ['id' => $params['id'], 'stock' => 0], 'store_id' =>$StoreProduct['store_id'], 'admin_id' => Request()->adminId]);
|
||||
|
||||
}
|
||||
$data['cate_id']=$params['cate_id'];
|
||||
}
|
||||
StoreBranchProduct::where('id', $params['id'])->update($data);
|
||||
|
||||
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/06/07 13:56
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return StoreBranchProduct::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取门店商品详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2024/06/07 13:56
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return StoreBranchProduct::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user