169 lines
5.1 KiB
PHP
169 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic\warehouse_product;
|
|
|
|
|
|
use app\common\model\warehouse_product\WarehouseProduct;
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\store_product\StoreProduct;
|
|
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
|
use support\Log;
|
|
use think\facade\Db;
|
|
|
|
|
|
/**
|
|
* 商品仓储信息逻辑
|
|
* Class WarehouseProductLogic
|
|
* @package app\admin\logic\warehouse_product
|
|
*/
|
|
class WarehouseProductLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 添加商品仓储信息
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/07/31 16:55
|
|
*/
|
|
public static function add(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
$data=[
|
|
'warehouse_id' => $params['warehouse_id'],
|
|
'product_id' => $params['product_id'],
|
|
'financial_pm' => $params['financial_pm'],
|
|
'batch' => $params['batch'],
|
|
'nums' => $params['nums'],
|
|
'price' => $params['price']??'',
|
|
'total_price' => $params['total_price']??'',
|
|
'admin_id' => $params['admin_id'],
|
|
'code' => $params['code']??'',
|
|
'status' => $params['status']??0,
|
|
'mark' => $params['mark']??'',
|
|
];
|
|
if(isset($params['manufacture']) &&$params['manufacture']!=''){
|
|
$data['manufacture']=strtotime($params['manufacture']);
|
|
}
|
|
if(isset($params['expiration_date']) &&$params['expiration_date']!=''){
|
|
$data['expiration_date']=strtotime($params['expiration_date']);
|
|
}
|
|
$res=WarehouseProduct::create($data);
|
|
self::enter($res['id']);
|
|
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/07/31 16:55
|
|
*/
|
|
public static function edit(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
$data=[
|
|
'warehouse_id' => $params['warehouse_id'],
|
|
'product_id' => $params['product_id'],
|
|
'financial_pm' => $params['financial_pm'],
|
|
'batch' => $params['batch'],
|
|
'nums' => $params['nums'],
|
|
'price' => $params['price'],
|
|
'admin_id' => $params['admin_id'],
|
|
'total_price' => $params['total_price'],
|
|
'code' => $params['code'],
|
|
];
|
|
if(isset($params['manufacture']) &&$params['manufacture']!=''){
|
|
$data['manufacture']=strtotime($params['manufacture']);
|
|
}
|
|
if(isset($params['expiration_date']) &&$params['expiration_date']!=''){
|
|
$data['expiration_date']=strtotime($params['expiration_date']);
|
|
}
|
|
WarehouseProduct::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
|
|
* @author admin
|
|
* @date 2024/07/31 16:55
|
|
*/
|
|
public static function enter($id)
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
$find=WarehouseProduct::where('id',$id)->find();
|
|
$find->status=1;
|
|
$find->save();
|
|
StoreProduct::where('id',$find['product_id'])->inc('stock',$find['nums'])->update();
|
|
$storege=WarehouseProductStorege::where('warehouse_id',$find['warehouse_id'])->where('product_id',$find['product_id'])->find();
|
|
if($storege){
|
|
$storege->nums=$storege->nums+$find['nums'];
|
|
$storege->save();
|
|
}else{
|
|
WarehouseProductStorege::create([
|
|
'warehouse_id' => $find['warehouse_id'],
|
|
'product_id' => $find['product_id'],
|
|
'nums' => $find['nums'],
|
|
]);
|
|
}
|
|
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/07/31 16:55
|
|
*/
|
|
public static function delete(array $params): bool
|
|
{
|
|
return WarehouseProduct::destroy($params['id']);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取商品仓储信息详情
|
|
* @param $params
|
|
* @return array
|
|
* @author admin
|
|
* @date 2024/07/31 16:55
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
$data= WarehouseProduct::findOrEmpty($params['id'])->toArray();
|
|
if($data){
|
|
$data['manufacture']=date('Y-m-d',$data['manufacture']);
|
|
$data['expiration_date']=date('Y-m-d',$data['expiration_date']);
|
|
|
|
}
|
|
return $data;
|
|
}
|
|
} |