Merge pull request 'feat: 修改商品库存更新逻辑,增加日志记录' (#171) from dev_two into dev

Reviewed-on: #171
This commit is contained in:
mkm 2024-08-28 15:22:49 +08:00
commit dc10bce200
20 changed files with 239 additions and 84 deletions

View File

@ -12,6 +12,7 @@ use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\lists\ListsExcelInterface; use app\common\lists\ListsExcelInterface;
use app\common\lists\ListsSortInterface; use app\common\lists\ListsSortInterface;
use app\common\model\store_product\StoreProduct;
/** /**
* 门店商品辅助表 * 门店商品辅助表

View File

@ -81,19 +81,38 @@ class StoreBranchProductLogic extends BaseLogic
{ {
Db::startTrans(); Db::startTrans();
try { try {
$find = StoreProduct::where('id', $params['product_id'])->find(); $find = StoreProduct::where('id', $params['product_id'])->find()->toArray();
$storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find(); $storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find()->toArray();
if ($type == 1) { if ($type == 1) {
$stock = bcadd($find['stock'], $params['nums'], 2); $stock = bcadd($find['stock'], $params['nums'], 2);
$branchStock = bcadd($storeBranchProduct['stock'], $params['nums'], 2); $branchStock = bcadd($storeBranchProduct['stock'], $params['nums'], 2);
onBeforeUpdate($storeBranchProduct,'branch_product');
StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)]); StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)]);
$storeBranchProduct['stock']=$branchStock;
$storeBranchProduct['total_price']=bcmul($branchStock, $find['purchase'], 2);
onAfterUpdate($storeBranchProduct,'branch_product');
onBeforeUpdate($find,'product');
StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)]); StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)]);
$find['stock']=$stock;
$find['total_price']=bcmul($stock, $find['purchase'], 2);
onAfterUpdate($find,'product');
} else { } else {
$branchStock = bcsub($storeBranchProduct['stock'], $params['nums'], 2); $branchStock = bcsub($storeBranchProduct['stock'], $params['nums'], 2);
$stock = bcsub($find['stock'], $params['nums'], 2); $stock = bcsub($find['stock'], $params['nums'], 2);
onBeforeUpdate($storeBranchProduct,'branch_product');
StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)]); StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)]);
$storeBranchProduct['stock']=$branchStock;
$storeBranchProduct['total_price']=bcmul($branchStock, $find['purchase'], 2);
onAfterUpdate($storeBranchProduct,'branch_product');
onBeforeUpdate($find,'product');
StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)]); StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)]);
$find['stock']=$stock;
$find['total_price']=bcmul($stock, $find['purchase'], 2);
onAfterUpdate($find,'product');
} }
Db::commit(); Db::commit();
return true; return true;

View File

@ -42,11 +42,23 @@ class WarehouseProductLogic extends BaseLogic
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find(); $storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
if ($storege) { if ($storege) {
if ($params['financial_pm'] == 0) { if ($params['financial_pm'] == 0) {
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
if (!$storeProduct) {
throw new BusinessException('商品不存在');
}
$after_nums = $storege['nums'] - $params['nums']; $after_nums = $storege['nums'] - $params['nums'];
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
// if ($after_nums < 0) { // if ($after_nums < 0) {
// throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']); // throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']);
// } // }
WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update(); onBeforeUpdate($storege->toArray(),'product_storege');
WarehouseProductStorege::where('id', $storege['id'])->update(['nums'=>$after_nums, 'total_price' => $total_price]);
$storege=$storege->toArray();
$storege['nums']=$after_nums;
$storege['total_price']=$total_price;
onAfterUpdate($storege,'product_storege');
//门店加库存 //门店加库存
$storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find(); $storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find();
if (!$storeBranchProduct) { if (!$storeBranchProduct) {
@ -67,7 +79,12 @@ class WarehouseProductLogic extends BaseLogic
throw new BusinessException('商品不存在'); throw new BusinessException('商品不存在');
} }
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2); $total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
onBeforeUpdate($storege->toArray(),'product_storege');
WarehouseProductStorege::where('id', $storege['id'])->update(['nums' => $after_nums, 'total_price' => $total_price]); WarehouseProductStorege::where('id', $storege['id'])->update(['nums' => $after_nums, 'total_price' => $total_price]);
$storege=$storege->toArray();
$storege['nums']=$after_nums;
$storege['total_price']=$total_price;
onAfterUpdate($storege,'product_storege');
} }
} }
$before_nums = $storege['nums']; $before_nums = $storege['nums'];
@ -78,12 +95,13 @@ class WarehouseProductLogic extends BaseLogic
throw new BusinessException('商品不存在'); throw new BusinessException('商品不存在');
} }
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2); $total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
WarehouseProductStorege::create([ $storege=WarehouseProductStorege::create([
'warehouse_id' => $params['warehouse_id'], 'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'], 'product_id' => $params['product_id'],
'nums' => $params['nums'], 'nums' => $params['nums'],
'total_price'=>$total_price 'total_price'=>$total_price
]); ]);
onAfterUpdate($storege->toArray(),'product_storege');
} }
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count(); $batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count();
$data = [ $data = [

View File

@ -44,9 +44,15 @@ class IndexController extends BaseApiController
public function index() public function index()
{ {
$a=StoreProduct::where('is_show',1)->select();
foreach($a as $k=>$v){
$find=StoreBranchProduct::where('product_id',$v['id'])->find();
StoreProduct::where('id',$v['id'])->update(['top_cate_id'=>$find['top_cate_id'],'two_cate_id'=>$find['two_cate_id'],'cate_id'=>$find['cate_id']]);
}
return json([1]); return json([1]);
} }
/** /**
* @notes 下载文件 * @notes 下载文件
*/ */

View File

@ -7,7 +7,7 @@ use app\api\validate\CartValidate;
use app\api\controller\BaseApiController; use app\api\controller\BaseApiController;
use app\api\lists\order\CartList; use app\api\lists\order\CartList;
use app\common\model\order\Cart; use app\common\model\order\Cart;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
class CartController extends BaseApiController class CartController extends BaseApiController
@ -27,10 +27,9 @@ class CartController extends BaseApiController
$result = Cart::where(['uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0, 'delete_time' => null])->find(); $result = Cart::where(['uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0, 'delete_time' => null])->find();
$params['cart_num']=bcadd($params['cart_num'],0,2); $params['cart_num']=bcadd($params['cart_num'],0,2);
//判断起批发价 //判断起批发价
$branchProduct = StoreBranchProduct::where( $branchProduct = StoreProduct::where(
[ [
'product_id' => $params['product_id'], 'id' => $params['product_id'],
'store_id' => $params['store_id']
] ]
)->find(); )->find();
if (!$branchProduct) { if (!$branchProduct) {
@ -86,10 +85,9 @@ class CartController extends BaseApiController
$params['uid'] = $this->request->userId; $params['uid'] = $this->request->userId;
$params['cart_num']=bcadd($params['cart_num'],0,2); $params['cart_num']=bcadd($params['cart_num'],0,2);
if (convertNumber($params['cart_num']) === false) { if (convertNumber($params['cart_num']) === false) {
$branchProduct = StoreBranchProduct::where( $branchProduct = StoreProduct::where(
[ [
'product_id' => $params['product_id'], 'id' => $params['product_id'],
'store_id' => $params['store_id']
] ]
)->find(); )->find();
$is_bulk = StoreProductUnit::where('id', $branchProduct['unit'])->value('is_bulk'); $is_bulk = StoreProductUnit::where('id', $branchProduct['unit'])->value('is_bulk');

View File

@ -6,7 +6,7 @@ namespace app\api\lists\cate;
use app\admin\lists\BaseAdminDataLists; use app\admin\lists\BaseAdminDataLists;
use app\common\model\cate\Cate; use app\common\model\cate\Cate;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct;
use app\Request; use app\Request;
use think\facade\Db; use think\facade\Db;
@ -28,7 +28,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['name', 'data', 'store_id', 'sort'], '=' => ['name', 'data', 'sort'],
]; ];
} }
@ -47,17 +47,17 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
$level = Request()->get('level', 1); $level = Request()->get('level', 1);
$pid = $this->request->get('pid',0); $pid = $this->request->get('pid',0);
// $this->searchWhere[] = ['stock', '>', 0]; // $this->searchWhere[] = ['stock', '>', 0];
$this->searchWhere[] = ['status', '=', 1]; $this->searchWhere[] = ['is_show', '=', 1];
if($pid && $level ==2){ if($pid && $level ==2){
$this->searchWhere[] = ['top_cate_id','=',$pid]; $this->searchWhere[] = ['top_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() $cate_arr = StoreProduct::where($this->searchWhere)->distinct()
->column('two_cate_id'); ->column('two_cate_id');
}elseif($pid && $level ==3){ }elseif($pid && $level ==3){
$this->searchWhere[] = ['two_cate_id','=',$pid]; $this->searchWhere[] = ['two_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() $cate_arr = StoreProduct::where($this->searchWhere)->distinct()
->column('cate_id'); ->column('cate_id');
}else{ }else{
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() $cate_arr = StoreProduct::where($this->searchWhere)->distinct()
->column('top_cate_id'); ->column('top_cate_id');
} }
$lists = []; $lists = [];
@ -85,14 +85,14 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
$pid = $this->request->get('pid',0); $pid = $this->request->get('pid',0);
if($pid && $level ==2){ if($pid && $level ==2){
$this->searchWhere[] = ['top_cate_id','=',$pid]; $this->searchWhere[] = ['top_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() $cate_arr = StoreProduct::where($this->searchWhere)->distinct()
->column('two_cate_id'); ->column('two_cate_id');
}elseif($pid && $level ==3){ }elseif($pid && $level ==3){
$this->searchWhere[] = ['two_cate_id','=',$pid]; $this->searchWhere[] = ['two_cate_id','=',$pid];
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() $cate_arr = StoreProduct::where($this->searchWhere)->distinct()
->column('cate_id'); ->column('cate_id');
}else{ }else{
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() $cate_arr = StoreProduct::where($this->searchWhere)->distinct()
->column('top_cate_id'); ->column('top_cate_id');
} }
return Cate::where('id', 'in', $cate_arr)->count(); return Cate::where('id', 'in', $cate_arr)->count();

View File

@ -9,7 +9,7 @@ use app\common\model\order\Cart;
use app\common\lists\ListsExtendInterface; use app\common\lists\ListsExtendInterface;
use app\common\model\Config; use app\common\model\Config;
use app\common\model\dict\DictType; use app\common\model\dict\DictType;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\user\User; use app\common\model\user\User;
@ -65,14 +65,14 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
->toArray(); ->toArray();
$off_activity = Config::where('name', 'off_activity')->value('value'); $off_activity = Config::where('name', 'off_activity')->value('value');
$user_ship = User::where('id', $userId)->value('user_ship'); $user_ship = User::where('id', $userId)->value('user_ship');
$field = 'product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch'; $field = 'id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch';
if (in_array($user_ship, [4, 6, 7])) { if (in_array($user_ship, [4, 6, 7])) {
$field = 'product_id,image,cost price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch'; $field = 'id,id product_id,image,cost price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch';
} }
$this->user_ship = $user_ship; $this->user_ship = $user_ship;
$this->off_activity = $off_activity; $this->off_activity = $off_activity;
foreach ($list as $key => &$item) { foreach ($list as $key => &$item) {
$find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']]) $find = StoreProduct::where(['id' => $item['product_id']])
->field($field) ->field($field)
->find(); ->find();
if ($find) { if ($find) {

View File

@ -5,11 +5,8 @@ namespace app\api\lists\order;
use app\admin\lists\BaseAdminDataLists; use app\admin\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit;
use Picqer\Barcode\BarcodeGeneratorPNG; use Picqer\Barcode\BarcodeGeneratorPNG;
/** /**

View File

@ -6,11 +6,8 @@ namespace app\api\lists\product;
use app\api\lists\BaseApiDataLists; use app\api\lists\BaseApiDataLists;
use app\common\lists\ListsExtendInterface; use app\common\lists\ListsExtendInterface;
use app\common\lists\ListsSortInterface; use app\common\lists\ListsSortInterface;
use app\common\model\dict\DictType;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\cate\Cate;
use app\common\model\Config; use app\common\model\Config;
use app\common\model\user\User; use app\common\model\user\User;
//use app\common\model\goods\GoodsLabel; //use app\common\model\goods\GoodsLabel;
@ -35,7 +32,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['store_id', 'cate_id', 'top_cate_id', 'two_cate_id'], '=' => [ 'cate_id', 'top_cate_id', 'two_cate_id'],
'%pipe_like%' => ['store_name' => 'store_name|bar_code'], '%pipe_like%' => ['store_name' => 'store_name|bar_code'],
]; ];
} }
@ -79,7 +76,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
} else { } else {
$order = [$field => $order]; $order = [$field => $order];
} }
$fields = 'id,product_id,top_cate_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; $fields = 'id,id product_id,top_cate_id,cate_id,store_name,cost,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
$off_activity = Config::where('name', 'off_activity')->value('value'); $off_activity = Config::where('name', 'off_activity')->value('value');
if ($off_activity == 1) { if ($off_activity == 1) {
$tag = '赠10%品牌礼品券'; $tag = '赠10%品牌礼品券';
@ -96,13 +93,13 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
if ($uid > 0) { if ($uid > 0) {
$user_ship = User::where('id', $uid)->value('user_ship'); $user_ship = User::where('id', $uid)->value('user_ship');
if (in_array($user_ship, [4, 6, 7])) { if (in_array($user_ship, [4, 6, 7])) {
$fields = 'id,product_id,top_cate_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; $fields = 'id,id product_id,top_cate_id,cate_id,store_name,cost,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
} }
} }
$this->off_activity = $off_activity; $this->off_activity = $off_activity;
$this->searchWhere[] = ['status', '=', 1]; $this->searchWhere[] = ['is_show', '=', 1];
// $this->searchWhere[] = ['stock', '>', 0]; // $this->searchWhere[] = ['stock', '>', 0];
return StoreBranchProduct::where($this->searchWhere) return StoreProduct::where($this->searchWhere)
->field($fields) ->field($fields)
->with(['className', 'unitName']) ->with(['className', 'unitName'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
@ -126,7 +123,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
*/ */
public function count(): int public function count(): int
{ {
return StoreBranchProduct::where($this->searchWhere) return StoreProduct::where($this->searchWhere)
->count(); ->count();
} }
public function extend() public function extend()

View File

@ -7,7 +7,6 @@ use app\api\lists\BaseApiDataLists;
use app\common\lists\ListsExtendInterface; use app\common\lists\ListsExtendInterface;
use app\common\lists\ListsSortInterface; use app\common\lists\ListsSortInterface;
use app\common\model\dict\DictType; use app\common\model\dict\DictType;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use app\common\model\cate\Cate; use app\common\model\cate\Cate;
@ -72,22 +71,17 @@ class StoreProductLists extends BaseApiDataLists implements ListsSearchInterface
*/ */
public function lists(): array public function lists(): array
{ {
$store_id= $this->request->__get('store_id'); $fields = 'id,id product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
if($store_id){
$this->searchWhere[] = ['store_id', '=', $store_id];
}
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
$type=$this->request->get('type',0); $type=$this->request->get('type',0);
if($type==1){ if($type==1){
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; $fields = 'id,id product_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
}elseif($type==2){ }elseif($type==2){
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,purchase price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock'; $fields = 'id,id product_id,cate_id,store_name,cost,store_id,vip_price,purchase,purchase price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
} }
$this->searchWhere[] = ['status', '=', 1]; $this->searchWhere[] = ['status', '=', 1];
// $this->searchWhere[] = ['stock', '>', 0]; // $this->searchWhere[] = ['stock', '>', 0];
return StoreBranchProduct::where($this->searchWhere) return StoreProduct::where($this->searchWhere)
->field($fields) ->field($fields)
->with(['className', 'unitName']) ->with(['className', 'unitName'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
@ -105,7 +99,7 @@ class StoreProductLists extends BaseApiDataLists implements ListsSearchInterface
*/ */
public function count(): int public function count(): int
{ {
return StoreBranchProduct::where($this->searchWhere) return StoreProduct::where($this->searchWhere)
->count(); ->count();
} }
} }

View File

@ -87,9 +87,9 @@ class OrderLogic extends BaseLogic
self::$fresh_price = 0; //生鲜金额 self::$fresh_price = 0; //生鲜金额
/** 计算价格 */ /** 计算价格 */
$off_activity = Config::where('name', 'off_activity')->value('value'); $off_activity = Config::where('name', 'off_activity')->value('value');
$field = 'product_id id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose'; $field = 'id,store_name,image,unit,price,vip_price,cost,purchase,cate_id,store_info,rose';
foreach ($cart_select as $k => $v) { foreach ($cart_select as $k => $v) {
$find = StoreBranchProduct::where(['product_id' => $v['product_id'],'store_id'=>$params['store_id']])->field($field)->find(); $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find();
if (!$find) { if (!$find) {
throw new BusinessException('商品不存在'); throw new BusinessException('商品不存在');
} }
@ -452,7 +452,7 @@ class OrderLogic extends BaseLogic
return []; return [];
} }
$goods_arr = array_unique($goods_id); $goods_arr = array_unique($goods_id);
$select = StoreBranchProduct::where('product_id', 'in', $goods_arr)->with('unitName')->field('id,store_name,price,image,unit')->select(); $select = StoreProduct::where('id', 'in', $goods_arr)->with('unitName')->field('id,store_name,price,image,unit')->select();
return $select->toArray(); return $select->toArray();
} catch (\Throwable $e) { } catch (\Throwable $e) {
throw new BusinessException($e->getMessage()); throw new BusinessException($e->getMessage());
@ -495,10 +495,8 @@ class OrderLogic extends BaseLogic
$find['goods_list'] = StoreOrderCartInfo::where('oid', $find['id']) $find['goods_list'] = StoreOrderCartInfo::where('oid', $find['id'])
->field('product_id,cart_num nums,store_id')->select()->each(function ($item) use ($find) { ->field('product_id,cart_num nums,store_id')->select()->each(function ($item) use ($find) {
$find = StoreBranchProduct::where('product_id', $item['product_id'])->where('store_id', $find['store_id'])->find(); $find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find();
if (empty($find)) {
$find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find();
}
$item['store_name'] = $find['store_name']; $item['store_name'] = $find['store_name'];
$item['nums'] = floatval($item['nums']); $item['nums'] = floatval($item['nums']);
$item['image'] = $find['image']; $item['image'] = $find['image'];

View File

@ -22,17 +22,14 @@ class CommissionProductLogic extends BaseLogic
*/ */
function calculate_product_flow($find, $order, $village_uid = 0, $brigade_uid = 0, $user_ship = 0, $spread_user_ship = 0) function calculate_product_flow($find, $order, $village_uid = 0, $brigade_uid = 0, $user_ship = 0, $spread_user_ship = 0)
{ {
$product = StoreBranchProduct::where('product_id', $find['product_id'])->where('store_id', $order['store_id'])->find(); $product = StoreProduct::where('id', $find['product_id'])->find();
if (!$product) {
$product = StoreProduct::where('id', $find['product_id'])->find();
}
if ($product) { if ($product) {
if ($product['product_type'] == 4) { if ($product['product_type'] == 4) {
$this->c($find, $order, $village_uid, $brigade_uid, $user_ship, $product); $this->c($find, $order, $village_uid, $brigade_uid, $user_ship, $product);
return true; return true;
} else { } else {
if ($user_ship == 5) { if ($user_ship == 5) {
$top_cate_id = StoreBranchProduct::where('product_id', $find['product_id'])->value('top_cate_id'); $top_cate_id = $product['top_cate_id'];
if ($top_cate_id == 15189) { if ($top_cate_id == 15189) {
$this->b($find, $order, $product,$user_ship); $this->b($find, $order, $product,$user_ship);
return true; return true;

View File

@ -574,20 +574,42 @@ class PayNotifyLogic extends BaseLogic
{ {
StoreOrderCartInfo::where('oid', $order['id'])->update(['is_pay' => 1]); StoreOrderCartInfo::where('oid', $order['id'])->update(['is_pay' => 1]);
$arr = StoreOrderCartInfo::where('oid', $order['id'])->field('id,oid,product_id,store_id,cart_num')->select(); $arr = StoreOrderCartInfo::where('oid', $order['id'])->field('id,oid,product_id,store_id,cart_num')->select();
foreach ($arr as $k => $v) { try{
$branchProduct=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id',$v['store_id'])->find(); foreach ($arr as $k => $v) {
if($branchProduct){ $branchProduct=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id',$v['store_id'])->find();
$stock=bcsub($branchProduct['stock'],$v['cart_num'],2); if($branchProduct){
StoreProduct::where('id',$branchProduct['id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2), $stock=bcsub($branchProduct['stock'],$v['cart_num'],2);
'sales'=>bcmul($branchProduct['sales'],$v['cart_num'],2)]); onBeforeUpdate($branchProduct->toArray(),'branch_product');
}
$storeProduct=StoreProduct::where('id', $v['product_id'])->find(); StoreBranchProduct::where('id',$branchProduct['id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2),
if($storeProduct){ 'sales'=>bcadd($branchProduct['sales'],$v['cart_num'],2)]);
$stock=bcsub($storeProduct['stock'],$v['cart_num'],2);
StoreProduct::where('id', $v['product_id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$storeProduct['purchase'],2), $branchProduct=$branchProduct->toArray();
'sales'=>bcmul($storeProduct['sales'],$v['cart_num'],2)]); $branchProduct['stock']=$stock;
$branchProduct['total_price']=bcmul($stock,$branchProduct['purchase'],2);
$branchProduct['sales']=bcadd($branchProduct['sales'],$v['cart_num'],2);
onAfterUpdate($branchProduct,'branch_product');
}
$storeProduct=StoreProduct::where('id', $v['product_id'])->find();
if($storeProduct){
$stock=bcsub($storeProduct['stock'],$v['cart_num'],2);
onBeforeUpdate($storeProduct->toArray(),'product');
StoreProduct::where('id', $v['product_id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$storeProduct['purchase'],2),
'sales'=>bcadd($storeProduct['sales'],$v['cart_num'],2)]);
$storeProduct=$storeProduct->toArray();
$storeProduct['stock']=$stock;
$storeProduct['total_price']=bcmul($stock,$storeProduct['purchase'],2);
$storeProduct['sales']=bcadd($storeProduct['sales'],$v['cart_num'],2);
onAfterUpdate($storeProduct,'product');
}
} }
}catch (\Throwable $e) {
Log::error('订单库存更新失败:' . $e->getMessage());
// 异常处理代码,例如记录日志或发送通知等。
} }
$financeLogic = new StoreFinanceFlowLogic(); $financeLogic = new StoreFinanceFlowLogic();
$off_activity = Config::where('name', 'off_activity')->value('value'); $off_activity = Config::where('name', 'off_activity')->value('value');
$village_uid = 0; $village_uid = 0;

View File

@ -36,10 +36,8 @@ class StoreBranchProduct extends BaseModel
} }
public function store() public function store()
{ {
return $this->hasOne(StoreProduct::class,'id','product_id'); return $this->hasOne(StoreProduct::class,'id','product_id');
} }
} }

View File

@ -6,6 +6,7 @@ namespace app\common\model\store_product;
use app\common\model\BaseModel; use app\common\model\BaseModel;
use app\common\model\store_category\StoreCategory; use app\common\model\store_category\StoreCategory;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use support\Log;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
@ -31,8 +32,5 @@ class StoreProduct extends BaseModel
{ {
return $this->hasOne(StoreCategory::class,'id','cate_id')->bind(['class_name'=>'name']); return $this->hasOne(StoreCategory::class,'id','cate_id')->bind(['class_name'=>'name']);
} }
} }

View File

@ -4,6 +4,7 @@ namespace app\common\model\warehouse_product_storege;
use app\common\model\BaseModel; use app\common\model\BaseModel;
use support\Log;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
@ -18,5 +19,12 @@ class WarehouseProductStorege extends BaseModel
protected $name = 'warehouse_product_storege'; protected $name = 'warehouse_product_storege';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
public function onBeforeUpdate($product){
$log = Log::channel('product_storege');
$log->info('更新前:'.json_encode($product));
}
public function onAfterUpdate($product){
$log = Log::channel('product_storege');
$log->info('更新后:'.json_encode($product));
}
} }

View File

@ -5,7 +5,7 @@
*/ */
use app\common\service\FileService; use app\common\service\FileService;
use support\Log;
if (!function_exists('substr_symbol_behind')) { if (!function_exists('substr_symbol_behind')) {
/** /**
@ -500,3 +500,20 @@ if (!function_exists('convertNumber')) {
} }
} }
} }
/**
* 日志记录
* @param product
* @param branch_product
* @param product_storege
*/
function onBeforeUpdate($data, $type)
{
$log = Log::channel($type);
$log->info('更新前:',$data);
}
function onAfterUpdate($data, $type)
{
$log = Log::channel($type);
$log->info('更新后:' ,$data);
}

View File

@ -7,6 +7,7 @@ use app\api\validate\CartValidate;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\store\lists\cart\CartList; use app\store\lists\cart\CartList;
use app\common\model\order\Cart; use app\common\model\order\Cart;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use app\store\controller\BaseAdminController; use app\store\controller\BaseAdminController;
@ -30,10 +31,9 @@ class CartController extends BaseAdminController
$params['store_id'] = $adminInfo['store_id']; $params['store_id'] = $adminInfo['store_id'];
$result = Cart::where(['uid' => 0, 'staff_id' => $adminInfo['admin_id'], 'store_id' => $adminInfo['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0])->find(); $result = Cart::where(['uid' => 0, 'staff_id' => $adminInfo['admin_id'], 'store_id' => $adminInfo['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0])->find();
//判断起批发价 //判断起批发价
$branchProduct = StoreBranchProduct::where( $branchProduct = StoreProduct::where(
[ [
'product_id' => $params['product_id'], 'id' => $params['product_id'],
'store_id' => $adminInfo['store_id']
] ]
)->find(); )->find();
if ($params['cart_num'] < $branchProduct['batch']) { if ($params['cart_num'] < $branchProduct['batch']) {
@ -76,6 +76,18 @@ class CartController extends BaseAdminController
{ {
$params = (new CartValidate())->post()->goCheck('StoreChange'); $params = (new CartValidate())->post()->goCheck('StoreChange');
$adminInfo = $this->adminInfo; $adminInfo = $this->adminInfo;
$params['cart_num']=bcadd($params['cart_num'],0,2);
if (convertNumber($params['cart_num']) === false) {
$branchProduct = StoreProduct::where(
[
'id' => $params['product_id'],
]
)->find();
$is_bulk = StoreProductUnit::where('id', $branchProduct['unit'])->value('is_bulk');
if ($is_bulk == 0) {
return $this->fail('非计量商品,不能有小数,请编辑购物车');
}
}
$params['uid'] = 0; $params['uid'] = 0;
$params['staff_id'] = $adminInfo['admin_id']; $params['staff_id'] = $adminInfo['admin_id'];
$params['store_id'] = $adminInfo['store_id']; $params['store_id'] = $adminInfo['store_id'];

View File

@ -12,6 +12,7 @@ use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\lists\ListsExtendInterface; use app\common\lists\ListsExtendInterface;
use app\common\model\store_product\StoreProduct;
/** /**
* 购物车列表 * 购物车列表
@ -70,8 +71,8 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
} }
} }
foreach ($list as $key => &$item) { foreach ($list as $key => &$item) {
$find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']]) $find = StoreProduct::where(['id' => $item['product_id']])
->field('product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id') ->field('id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id')
->find(); ->find();
if ($find) { if ($find) {
if ($off_activity == 1) { if ($off_activity == 1) {

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* This file is part of webman. * This file is part of webman.
* *
@ -38,7 +39,80 @@ return [
], ],
'formatter' => [ 'formatter' => [
'class' => Monolog\Formatter\LineFormatter::class, 'class' => Monolog\Formatter\LineFormatter::class,
'constructor' => [null, 'Y-m-d H:i:s', true,true], 'constructor' => [null, 'Y-m-d H:i:s', true, true],
],
]
],
],
// log2通道
'product' => [
// 处理默认通道的handler可以设置多个
'handlers' => [
[
// handler类的名字
'class' => Monolog\Handler\RotatingFileHandler::class,
// handler类的构造函数参数
'constructor' => [
runtime_path() . '/product/'.date('Ym').'/.log',
2048,
Monolog\Logger::DEBUG,
true,
0755
],
// 格式相关
'formatter' => [
// 格式化处理类的名字
'class' => Monolog\Formatter\LineFormatter::class,
// 格式化处理类的构造函数参数
'constructor' => [null, 'Y-m-d H:i:s', true],
],
]
],
],
'branch_product' => [
// 处理默认通道的handler可以设置多个
'handlers' => [
[
// handler类的名字
'class' => Monolog\Handler\RotatingFileHandler::class,
// handler类的构造函数参数
'constructor' => [
runtime_path() . '/branch_product/'.date('Ym').'/.log',
2048,
Monolog\Logger::DEBUG,
true,
0755
],
// 格式相关
'formatter' => [
// 格式化处理类的名字
'class' => Monolog\Formatter\LineFormatter::class,
// 格式化处理类的构造函数参数
'constructor' => [null, 'Y-m-d H:i:s', true],
],
]
],
],
'product_storege' => [
// 处理默认通道的handler可以设置多个
'handlers' => [
[
// handler类的名字
'class' => Monolog\Handler\RotatingFileHandler::class,
// handler类的构造函数参数
'constructor' => [
runtime_path() . '/product_storege/'.date('Ym').'/.log',
2048,
Monolog\Logger::DEBUG,
true,
0755
],
// 格式相关
'formatter' => [
// 格式化处理类的名字
'class' => Monolog\Formatter\LineFormatter::class,
// 格式化处理类的构造函数参数
'constructor' => [null, 'Y-m-d H:i:s', true],
], ],
] ]
], ],