Merge pull request 'feat: 修改商品库存更新逻辑,增加日志记录' (#171) from dev_two into dev
Reviewed-on: #171
This commit is contained in:
commit
dc10bce200
@ -12,6 +12,7 @@ use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\lists\ListsExcelInterface;
|
||||
use app\common\lists\ListsSortInterface;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
|
||||
/**
|
||||
* 门店商品辅助表
|
||||
|
@ -81,19 +81,38 @@ class StoreBranchProductLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$find = StoreProduct::where('id', $params['product_id'])->find();
|
||||
$storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find();
|
||||
$find = StoreProduct::where('id', $params['product_id'])->find()->toArray();
|
||||
$storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find()->toArray();
|
||||
if ($type == 1) {
|
||||
$stock = bcadd($find['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['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)]);
|
||||
$find['stock']=$stock;
|
||||
$find['total_price']=bcmul($stock, $find['purchase'], 2);
|
||||
onAfterUpdate($find,'product');
|
||||
} else {
|
||||
$branchStock = bcsub($storeBranchProduct['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['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)]);
|
||||
$find['stock']=$stock;
|
||||
$find['total_price']=bcmul($stock, $find['purchase'], 2);
|
||||
onAfterUpdate($find,'product');
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
|
@ -42,11 +42,23 @@ class WarehouseProductLogic extends BaseLogic
|
||||
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storege) {
|
||||
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'];
|
||||
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
||||
|
||||
// if ($after_nums < 0) {
|
||||
// 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();
|
||||
if (!$storeBranchProduct) {
|
||||
@ -67,7 +79,12 @@ class WarehouseProductLogic extends BaseLogic
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
$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]);
|
||||
$storege=$storege->toArray();
|
||||
$storege['nums']=$after_nums;
|
||||
$storege['total_price']=$total_price;
|
||||
onAfterUpdate($storege,'product_storege');
|
||||
}
|
||||
}
|
||||
$before_nums = $storege['nums'];
|
||||
@ -78,12 +95,13 @@ class WarehouseProductLogic extends BaseLogic
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
||||
WarehouseProductStorege::create([
|
||||
$storege=WarehouseProductStorege::create([
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'nums' => $params['nums'],
|
||||
'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();
|
||||
$data = [
|
||||
|
@ -44,9 +44,15 @@ class IndexController extends BaseApiController
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 下载文件
|
||||
*/
|
||||
|
@ -7,7 +7,7 @@ use app\api\validate\CartValidate;
|
||||
use app\api\controller\BaseApiController;
|
||||
use app\api\lists\order\CartList;
|
||||
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;
|
||||
|
||||
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();
|
||||
$params['cart_num']=bcadd($params['cart_num'],0,2);
|
||||
//判断起批发价
|
||||
$branchProduct = StoreBranchProduct::where(
|
||||
$branchProduct = StoreProduct::where(
|
||||
[
|
||||
'product_id' => $params['product_id'],
|
||||
'store_id' => $params['store_id']
|
||||
'id' => $params['product_id'],
|
||||
]
|
||||
)->find();
|
||||
if (!$branchProduct) {
|
||||
@ -86,10 +85,9 @@ class CartController extends BaseApiController
|
||||
$params['uid'] = $this->request->userId;
|
||||
$params['cart_num']=bcadd($params['cart_num'],0,2);
|
||||
if (convertNumber($params['cart_num']) === false) {
|
||||
$branchProduct = StoreBranchProduct::where(
|
||||
$branchProduct = StoreProduct::where(
|
||||
[
|
||||
'product_id' => $params['product_id'],
|
||||
'store_id' => $params['store_id']
|
||||
'id' => $params['product_id'],
|
||||
]
|
||||
)->find();
|
||||
$is_bulk = StoreProductUnit::where('id', $branchProduct['unit'])->value('is_bulk');
|
||||
|
@ -6,7 +6,7 @@ namespace app\api\lists\cate;
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\cate\Cate;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\Request;
|
||||
use think\facade\Db;
|
||||
|
||||
@ -28,7 +28,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['name', 'data', 'store_id', 'sort'],
|
||||
'=' => ['name', 'data', 'sort'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -47,17 +47,17 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$level = Request()->get('level', 1);
|
||||
$pid = $this->request->get('pid',0);
|
||||
// $this->searchWhere[] = ['stock', '>', 0];
|
||||
$this->searchWhere[] = ['status', '=', 1];
|
||||
$this->searchWhere[] = ['is_show', '=', 1];
|
||||
if($pid && $level ==2){
|
||||
$this->searchWhere[] = ['top_cate_id','=',$pid];
|
||||
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
|
||||
$cate_arr = StoreProduct::where($this->searchWhere)->distinct()
|
||||
->column('two_cate_id');
|
||||
}elseif($pid && $level ==3){
|
||||
$this->searchWhere[] = ['two_cate_id','=',$pid];
|
||||
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
|
||||
$cate_arr = StoreProduct::where($this->searchWhere)->distinct()
|
||||
->column('cate_id');
|
||||
}else{
|
||||
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
|
||||
$cate_arr = StoreProduct::where($this->searchWhere)->distinct()
|
||||
->column('top_cate_id');
|
||||
}
|
||||
$lists = [];
|
||||
@ -85,14 +85,14 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$pid = $this->request->get('pid',0);
|
||||
if($pid && $level ==2){
|
||||
$this->searchWhere[] = ['top_cate_id','=',$pid];
|
||||
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
|
||||
$cate_arr = StoreProduct::where($this->searchWhere)->distinct()
|
||||
->column('two_cate_id');
|
||||
}elseif($pid && $level ==3){
|
||||
$this->searchWhere[] = ['two_cate_id','=',$pid];
|
||||
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
|
||||
$cate_arr = StoreProduct::where($this->searchWhere)->distinct()
|
||||
->column('cate_id');
|
||||
}else{
|
||||
$cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct()
|
||||
$cate_arr = StoreProduct::where($this->searchWhere)->distinct()
|
||||
->column('top_cate_id');
|
||||
}
|
||||
return Cate::where('id', 'in', $cate_arr)->count();
|
||||
|
@ -9,7 +9,7 @@ use app\common\model\order\Cart;
|
||||
use app\common\lists\ListsExtendInterface;
|
||||
use app\common\model\Config;
|
||||
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_unit\StoreProductUnit;
|
||||
use app\common\model\user\User;
|
||||
@ -65,14 +65,14 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
|
||||
->toArray();
|
||||
$off_activity = Config::where('name', 'off_activity')->value('value');
|
||||
$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])) {
|
||||
$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->off_activity = $off_activity;
|
||||
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)
|
||||
->find();
|
||||
if ($find) {
|
||||
|
@ -5,11 +5,8 @@ namespace app\api\lists\order;
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
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_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use Picqer\Barcode\BarcodeGeneratorPNG;
|
||||
|
||||
/**
|
||||
|
@ -6,11 +6,8 @@ namespace app\api\lists\product;
|
||||
use app\api\lists\BaseApiDataLists;
|
||||
use app\common\lists\ListsExtendInterface;
|
||||
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\lists\ListsSearchInterface;
|
||||
use app\common\model\cate\Cate;
|
||||
use app\common\model\Config;
|
||||
use app\common\model\user\User;
|
||||
//use app\common\model\goods\GoodsLabel;
|
||||
@ -35,7 +32,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
|
||||
public function setSearch(): array
|
||||
{
|
||||
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'],
|
||||
];
|
||||
}
|
||||
@ -79,7 +76,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
|
||||
} else {
|
||||
$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');
|
||||
if ($off_activity == 1) {
|
||||
$tag = '赠10%品牌礼品券';
|
||||
@ -96,13 +93,13 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
|
||||
if ($uid > 0) {
|
||||
$user_ship = User::where('id', $uid)->value('user_ship');
|
||||
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->searchWhere[] = ['status', '=', 1];
|
||||
$this->searchWhere[] = ['is_show', '=', 1];
|
||||
// $this->searchWhere[] = ['stock', '>', 0];
|
||||
return StoreBranchProduct::where($this->searchWhere)
|
||||
return StoreProduct::where($this->searchWhere)
|
||||
->field($fields)
|
||||
->with(['className', 'unitName'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
@ -126,7 +123,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return StoreBranchProduct::where($this->searchWhere)
|
||||
return StoreProduct::where($this->searchWhere)
|
||||
->count();
|
||||
}
|
||||
public function extend()
|
||||
|
@ -7,7 +7,6 @@ use app\api\lists\BaseApiDataLists;
|
||||
use app\common\lists\ListsExtendInterface;
|
||||
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\lists\ListsSearchInterface;
|
||||
use app\common\model\cate\Cate;
|
||||
@ -72,22 +71,17 @@ class StoreProductLists extends BaseApiDataLists implements ListsSearchInterface
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$store_id= $this->request->__get('store_id');
|
||||
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';
|
||||
$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';
|
||||
$type=$this->request->get('type',0);
|
||||
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){
|
||||
$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[] = ['stock', '>', 0];
|
||||
return StoreBranchProduct::where($this->searchWhere)
|
||||
return StoreProduct::where($this->searchWhere)
|
||||
->field($fields)
|
||||
->with(['className', 'unitName'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
@ -105,7 +99,7 @@ class StoreProductLists extends BaseApiDataLists implements ListsSearchInterface
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return StoreBranchProduct::where($this->searchWhere)
|
||||
return StoreProduct::where($this->searchWhere)
|
||||
->count();
|
||||
}
|
||||
}
|
||||
|
@ -87,9 +87,9 @@ class OrderLogic extends BaseLogic
|
||||
self::$fresh_price = 0; //生鲜金额
|
||||
/** 计算价格 */
|
||||
$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) {
|
||||
$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) {
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
@ -452,7 +452,7 @@ class OrderLogic extends BaseLogic
|
||||
return [];
|
||||
}
|
||||
$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();
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
@ -495,10 +495,8 @@ class OrderLogic extends BaseLogic
|
||||
|
||||
$find['goods_list'] = StoreOrderCartInfo::where('oid', $find['id'])
|
||||
->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();
|
||||
if (empty($find)) {
|
||||
$find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find();
|
||||
}
|
||||
|
||||
$item['store_name'] = $find['store_name'];
|
||||
$item['nums'] = floatval($item['nums']);
|
||||
$item['image'] = $find['image'];
|
||||
|
@ -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)
|
||||
{
|
||||
$product = StoreBranchProduct::where('product_id', $find['product_id'])->where('store_id', $order['store_id'])->find();
|
||||
if (!$product) {
|
||||
$product = StoreProduct::where('id', $find['product_id'])->find();
|
||||
}
|
||||
if ($product) {
|
||||
if ($product['product_type'] == 4) {
|
||||
$this->c($find, $order, $village_uid, $brigade_uid, $user_ship, $product);
|
||||
return true;
|
||||
} else {
|
||||
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) {
|
||||
$this->b($find, $order, $product,$user_ship);
|
||||
return true;
|
||||
|
@ -574,20 +574,42 @@ class PayNotifyLogic extends BaseLogic
|
||||
{
|
||||
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();
|
||||
try{
|
||||
foreach ($arr as $k => $v) {
|
||||
$branchProduct=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id',$v['store_id'])->find();
|
||||
if($branchProduct){
|
||||
$stock=bcsub($branchProduct['stock'],$v['cart_num'],2);
|
||||
StoreProduct::where('id',$branchProduct['id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2),
|
||||
'sales'=>bcmul($branchProduct['sales'],$v['cart_num'],2)]);
|
||||
onBeforeUpdate($branchProduct->toArray(),'branch_product');
|
||||
|
||||
StoreBranchProduct::where('id',$branchProduct['id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2),
|
||||
'sales'=>bcadd($branchProduct['sales'],$v['cart_num'],2)]);
|
||||
|
||||
$branchProduct=$branchProduct->toArray();
|
||||
$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'=>bcmul($storeProduct['sales'],$v['cart_num'],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();
|
||||
$off_activity = Config::where('name', 'off_activity')->value('value');
|
||||
$village_uid = 0;
|
||||
|
@ -36,10 +36,8 @@ class StoreBranchProduct extends BaseModel
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function store()
|
||||
{
|
||||
return $this->hasOne(StoreProduct::class,'id','product_id');
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ namespace app\common\model\store_product;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use support\Log;
|
||||
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']);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ namespace app\common\model\warehouse_product_storege;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use support\Log;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
@ -18,5 +19,12 @@ class WarehouseProductStorege extends BaseModel
|
||||
protected $name = 'warehouse_product_storege';
|
||||
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));
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
use app\common\service\FileService;
|
||||
|
||||
use support\Log;
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use app\api\validate\CartValidate;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\store\lists\cart\CartList;
|
||||
use app\common\model\order\Cart;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\store\controller\BaseAdminController;
|
||||
|
||||
@ -30,10 +31,9 @@ class CartController extends BaseAdminController
|
||||
$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();
|
||||
//判断起批发价
|
||||
$branchProduct = StoreBranchProduct::where(
|
||||
$branchProduct = StoreProduct::where(
|
||||
[
|
||||
'product_id' => $params['product_id'],
|
||||
'store_id' => $adminInfo['store_id']
|
||||
'id' => $params['product_id'],
|
||||
]
|
||||
)->find();
|
||||
if ($params['cart_num'] < $branchProduct['batch']) {
|
||||
@ -76,6 +76,18 @@ class CartController extends BaseAdminController
|
||||
{
|
||||
$params = (new CartValidate())->post()->goCheck('StoreChange');
|
||||
$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['staff_id'] = $adminInfo['admin_id'];
|
||||
$params['store_id'] = $adminInfo['store_id'];
|
||||
|
@ -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\user\User;
|
||||
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) {
|
||||
$find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']])
|
||||
->field('product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id')
|
||||
$find = StoreProduct::where(['id' => $item['product_id']])
|
||||
->field('id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id')
|
||||
->find();
|
||||
if ($find) {
|
||||
if ($off_activity == 1) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
@ -38,7 +39,80 @@ return [
|
||||
],
|
||||
'formatter' => [
|
||||
'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],
|
||||
],
|
||||
]
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user