修改分类更新小程序查询的商户分类 更新短信验证码模板

This commit is contained in:
liu 2024-06-17 11:43:28 +08:00
parent f1219258c3
commit 2a9887e632
2 changed files with 91 additions and 26 deletions

View File

@ -9,6 +9,7 @@ use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
use app\common\model\store_category\StoreCategory;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\model\store_product_cate\StoreProductCate;
use app\common\model\system_store\SystemStore;
use app\common\model\system_store_storage\SystemStoreStorage;
use app\Request;
@ -48,7 +49,7 @@ class StoreProductLogic extends BaseLogic
'purchase' => $params['purchase'],
'rose' => $params['rose'],
'is_return' => $params['is_return'],
'swap' => $params['swap']??0,
'swap' => $params['swap'] ?? 0,
];
// if ($params['rose'] > 0) {
// $rose_price = bcmul($params['cost'], $params['rose'], 2);
@ -94,6 +95,34 @@ class StoreProductLogic extends BaseLogic
}
}
public static function deleteRelatedData($cate_id)
{
$data_to_delete = StoreProductCate::where('cate_id', $cate_id)->select();
foreach ($data_to_delete as $item) {
if ($item['pid'] != 0) {
self::deleteRelatedData($item['pid']);
StoreProductCate::where('id', $item['id'])->update(['delete_time' => time()]);
}
if($item['pid'] == 0 && in_array($item['count'],[0,1])){
StoreProductCate::where('id', $item['id'])->update(['delete_time' => time()]);
}
}
}
// 递归减少分类数据的count值
public static function decreaseCount($cate_id)
{
$data_to_decrease = StoreProductCate::where('cate_id', $cate_id)->select();
foreach ($data_to_decrease as $item) {
if ($item['pid'] != 0) {
self::decreaseCount($item['pid']);
}
StoreProductCate::where('id', $item['id'])->update(['count' => $item['count'] - 1]);
}
}
/**
* @notes 编辑商品列表
@ -106,30 +135,51 @@ class StoreProductLogic extends BaseLogic
{
Db::startTrans();
try {
$data = [
'store_name' => $params['store_name'],
'image' => $params['image'],
'bar_code' => $params['bar_code'] ?? '',
'cate_id' => $params['cate_id'],
'unit' => $params['unit'],
'stock' => $params['stock'],
'cost' => $params['cost'],
'purchase' => $params['purchase'],
'rose' => $params['rose'],
'is_return' => $params['is_return'],
'price' => $params['price'],
'vip_price' => $params['vip_price'],
'cost' => $params['cost'],
'swap' => $params['swap']??0,
$data = [
'store_name' => $params['store_name'],
'image' => $params['image'],
'bar_code' => $params['bar_code'] ?? '',
'cate_id' => $params['cate_id'],
'unit' => $params['unit'],
'stock' => $params['stock'],
'cost' => $params['cost'],
'purchase' => $params['purchase'],
'rose' => $params['rose'],
'is_return' => $params['is_return'],
'price' => $params['price'],
'vip_price' => $params['vip_price'],
'swap' => $params['swap'] ?? 0,
];
StoreProduct::where('id', $params['id'])->update($data);
$old_cate = StoreBranchProduct::where('product_id', $params['id'])->field('cate_id,store_id')
->select();
// 获取分类ID
foreach ($old_cate as $vv) {
$related_data = Db::name('store_product_cate')->where('cate_id', $vv['cate_id'])->select();
//删除之前的分类
foreach ($related_data as $value) {
if ($value['count'] == 1) {
self::deleteRelatedData($value['cate_id']);
} elseif ($value['count'] > 1) {
self::decreaseCount($value['cate_id']);
}
//新增对应的分类
self::updateGoodsclass($params['cate_id'], $value['store_id']);
}
}
//修改
StoreBranchProduct::where('product_id', $params['id'])->update([
'price' => $params['price'], 'vip_price' => $params['vip_price'],
'cost' => $params['cost'], 'cate_id' => $params['cate_id']
]);
];
StoreProduct::where('id', $params['id'])->update($data);
StoreBranchProduct::where('product_id', $params['id'])->update([
'price' => $params['price'], 'vip_price' => $params['vip_price'],
'cost' => $params['cost']
]);
Db::commit();
return true;
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
@ -148,7 +198,7 @@ class StoreProductLogic extends BaseLogic
public static function delete(array $params): bool
{
$res = StoreProduct::destroy($params['id']);
StoreBranchProduct::where('product_id', $params['id'])->update(['delete_time'=>time()]);
StoreBranchProduct::where('product_id', $params['id'])->update(['delete_time' => time()]);
return $res;
}
@ -192,7 +242,7 @@ class StoreProductLogic extends BaseLogic
self::cate_update($cate_id, $two['id'], $store_id, 3);
self::cate_update($two['id'], $two['pid'], $store_id, 2);
self::cate_update($two['pid'], 0, $store_id, 1);
}else{
} else {
if ($one['pid'] == 0) {
self::cate_update($one['id'], 0, $store_id, 1);
} else {
@ -200,7 +250,7 @@ class StoreProductLogic extends BaseLogic
self::cate_update($one['pid'], 0, $store_id, 1);
}
}
}
}
}
}
@ -213,6 +263,7 @@ class StoreProductLogic extends BaseLogic
Db::name('store_product_cate')->insert(['pid' => $pid, 'store_id' => $store_id, 'cate_id' => $cate_id, 'count' => 1, 'level' => $level, 'create_time' => time(), 'update_time' => time()]);
}
}
/**
* 复制商品到门店
*/

View File

@ -0,0 +1,14 @@
<?php
namespace app\common\model\store_product_cate;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
class StoreProductCate extends BaseModel
{
use SoftDelete;
protected $name = 'store_product_cate';
protected $deleteTime = 'delete_time';
}