Merge pull request 'product' (#127) from product into main

Reviewed-on: #127
This commit is contained in:
mkm 2024-08-13 12:02:33 +08:00
commit afbce8f55f
6 changed files with 53 additions and 142 deletions

View File

@ -89,7 +89,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
}
if($item->product_id){
$find=StoreProduct::where('id',$item->product_id)->field('image,store_name')->find();
$item->store_name=$find->store_name;
$item->store_name=$find->store_name.'|'.$item->product_id;
$item->image=$find->image;
}else{
$item->store_name='';

View File

@ -13,8 +13,6 @@ 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\common\model\warehouse_product_storege\WarehouseProductStorege;
use app\Request;
use Illuminate\Support\Facades\Log;
use think\facade\Db;
use Webman\RedisQueue\Redis;
@ -456,21 +454,22 @@ class StoreProductLogic extends BaseLogic
Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
return false;
}
} else {
//更新门店库存
Db::startTrans();
try {
// if ($product_arr['stock'] > 0) {
// self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id);
}
// else {
// //更新门店库存
// Db::startTrans();
// try {
// // if ($product_arr['stock'] > 0) {
// // self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id);
// // }
// Db::commit();
// return true;
// } catch (\Exception $e) {
// Db::rollback();
// Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
// return false;
// }
// }
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
return false;
}
}
}
/**兑换 */
@ -497,22 +496,7 @@ class StoreProductLogic extends BaseLogic
'stock' => 0,
];
StoreBranchProductExchange::create($product);
// if ($product_arr['stock'] > 0) {
// self::storage($find, $store_id, $admin_id, $product_arr,$warehouse_id);
// }
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
return false;
}
} else {
Db::startTrans();
try {
// if ($product_arr['stock'] > 0) {
// self::storage($find, $store_id, $admin_id, $product_arr,2,$warehouse_id);
// }
Db::commit();
return true;
} catch (\Exception $e) {
@ -521,42 +505,19 @@ class StoreProductLogic extends BaseLogic
return false;
}
}
}
public static function storage($find, $store_id, $admin_id, $product_arr,$stock_type=1,$warehouse_id=0)
{
$storage = [
'product_id' => $product_arr['id'],
'store_id' => $store_id,
'nums' => $product_arr['stock'],
'admin_id' => $admin_id,
'type' => $stock_type,
'warehouse_id'=>$warehouse_id,
];
$data=[
'warehouse_id'=>$warehouse_id,
'product_id' => $product_arr['id'],
'store_id' => $store_id,
'financial_pm' => 0,
'batch' => $product_arr['batch']??1,
'nums' => $product_arr['stock'],
'status' =>1,
'admin_id' =>$admin_id,
];
$warehouse=WarehouseProductStorege::where('warehouse_id',$warehouse_id)->where('product_id',$product_arr['id'])->find();
if ($warehouse) {
if($warehouse['nums']< $product_arr['stock']){
$storage['status'] = -1;
$data['status'] = -1;
$storage['mark'] = '库存【'.$warehouse_id.'】不足,分库存为:' .$warehouse['nums'];
$data['mark'] = '库存【'.$warehouse_id.'】不足,分库存为:' .$warehouse['nums'].' 总仓库存为:'.$find['stock'];
}
$res=WarehouseProductLogic::add($data);
$storage['outbound_id']=$res['id']??0;
SystemStoreStorage::create($storage);
} else {
$res=WarehouseProductLogic::add($data);
$storage['outbound_id']=$res['id']??0;
SystemStoreStorage::create($storage);
}
// else {
// Db::startTrans();
// try {
// // if ($product_arr['stock'] > 0) {
// // self::storage($find, $store_id, $admin_id, $product_arr,2,$warehouse_id);
// // }
// Db::commit();
// return true;
// } catch (\Exception $e) {
// Db::rollback();
// Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
// return false;
// }
// }
}
}

View File

@ -61,14 +61,7 @@ class SystemStoreStorageLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
$find=SystemStoreStorage::where('id', $params['id'])->find();
//查看仓库库存
$productStorege=WarehouseProductStorege::where('product_id', $params['product_id'],['warehouse_id'=>$find['warehouse_id']])->find();
if($productStorege && $productStorege['nums']<$params['nums']){
self::setError('库存不足,仓库库存为:'.$productStorege['nums']);
return false;
}
return true;
Db::startTrans();
try {
SystemStoreStorage::where('id', $params['id'])->update([
@ -77,7 +70,6 @@ class SystemStoreStorageLogic extends BaseLogic
'status' => 0,
'mark' => '',
]);
StoreProduct::where('id', $params['product_id'])->inc('stock',bcsub($find['nums'] ,$params['nums'],2))->update();
Db::commit();
return true;
} catch (\Exception $e) {

View File

@ -34,23 +34,22 @@ class WarehouseProductLogic extends BaseLogic
{
// Db::startTrans();
// try {
$before_nums=0;
$after_nums=0;
$before_nums = 0;
$after_nums = 0;
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
if($storege){
if ($storege) {
if ($params['financial_pm'] == 0) {
$after_nums=$storege['nums']-$params['nums'];
if($after_nums<0){
$after_nums = $storege['nums'] - $params['nums'];
if ($after_nums < 0) {
throw new BusinessException('库存不足');
return false;
}
WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update();
} else {
$after_nums=$storege['nums']+$params['nums'];
$after_nums = $storege['nums'] + $params['nums'];
WarehouseProductStorege::where('id', $storege['id'])->inc('nums', $params['nums'])->update();
}
$before_nums=$storege['nums'];
}else{
$before_nums = $storege['nums'];
} else {
WarehouseProductStorege::create([
'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'],
@ -63,7 +62,7 @@ class WarehouseProductLogic extends BaseLogic
'store_id' => $params['store_id'] ?? 0,
'product_id' => $params['product_id'],
'financial_pm' => $params['financial_pm'],
'batch' => $batch_count+1,
'batch' => $batch_count + 1,
'nums' => $params['nums'],
'before_nums' => $before_nums,
'after_nums' => $after_nums,
@ -149,21 +148,15 @@ class WarehouseProductLogic extends BaseLogic
if ($res) {
$res->delete();
if ($res['financial_pm'] == 1) {
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->dec('nums', $res['nums'])->update();
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $res['nums'])->update();
} elseif ($res['financial_pm'] == 0) {
$find = SystemStoreStorage::where(['outbound_id' => $res['id']])->find();
if ($find) {
if ($find['status'] == 1) {
$stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock');
if ($stock < $res['nums']) {
self::setError('商品库存不足,无法退回');
return false;
}
StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update();
}
$find->delete();
}
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->inc('nums', $res['nums'])->update();
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update();
}
return true;

View File

@ -26,24 +26,7 @@ class WarehouseProductStoregeLogic extends BaseLogic
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
WarehouseProductStorege::create([
'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'price' => $params['price'],
'total_price' => $params['total_price'],
'status' => $params['status']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
@ -56,24 +39,7 @@ class WarehouseProductStoregeLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
WarehouseProductStorege::where('id', $params['id'])->update([
'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'price' => $params['price'],
'total_price' => $params['total_price'],
'status' => $params['status']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
@ -99,6 +65,6 @@ class WarehouseProductStoregeLogic extends BaseLogic
*/
public static function detail($params): array
{
return WarehouseProductStorege::findOrEmpty($params['id'])->toArray();
return [];
}
}

View File

@ -10,7 +10,6 @@ use app\common\model\store_branch_product_exchange\StoreBranchProductExchange;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\model\system_store_storage\SystemStoreStorage;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use Webman\RedisQueue\Consumer;
use support\Log;
use think\facade\Db;