commit
0d74d1549b
@ -21,6 +21,9 @@ class ExceptionHandler extends Handler
|
|||||||
if ($exception instanceof Dumper) {
|
if ($exception instanceof Dumper) {
|
||||||
return \response(self::convertToHtml($exception));
|
return \response(self::convertToHtml($exception));
|
||||||
}elseif ($exception instanceof BusinessException) {
|
}elseif ($exception instanceof BusinessException) {
|
||||||
|
if ($request->expectsJson()) {
|
||||||
|
return json(['code' => 0, 'msg' => $exception->getMessage(),'show'=>1]);
|
||||||
|
}
|
||||||
return response($exception->getMessage());
|
return response($exception->getMessage());
|
||||||
} elseif ($exception instanceof \Exception) {
|
} elseif ($exception instanceof \Exception) {
|
||||||
$isDebug = config('app.debug');
|
$isDebug = config('app.debug');
|
||||||
|
@ -316,10 +316,27 @@ class WorkbenchController extends BaseAdminController
|
|||||||
return $this->data($data);
|
return $this->data($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 负库存检测
|
||||||
|
*/
|
||||||
public function negative_inventory()
|
public function negative_inventory()
|
||||||
{
|
{
|
||||||
$parmas = $this->request->get();
|
$parmas = $this->request->get();
|
||||||
$data = WarehouseLogic::negativeInventory($parmas);
|
$data = WarehouseLogic::negativeInventory($parmas);
|
||||||
return $this->data($data);
|
return $this->data($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 负库存归零
|
||||||
|
*/
|
||||||
|
public function update_negative_zero()
|
||||||
|
{
|
||||||
|
$parmas = $this->request->get();
|
||||||
|
$res = WarehouseLogic::updateNegativeZero($parmas);
|
||||||
|
if($res){
|
||||||
|
return $this->data([], '操作成功');
|
||||||
|
}else{
|
||||||
|
return $this->data([], '操作失败', 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,22 @@ class StoreProductController extends BaseAdminController
|
|||||||
return $this->data($result);
|
return $this->data($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 复制商品
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/05/31 10:53
|
||||||
|
*/
|
||||||
|
public function copy()
|
||||||
|
{
|
||||||
|
$params = $this->request->post();
|
||||||
|
$find = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
|
||||||
|
foreach ($params['store_arr'] as $key => $store_id) {
|
||||||
|
StoreProductLogic::ordinary($find, $store_id, $this->adminId, $find);
|
||||||
|
}
|
||||||
|
return $this->success('复制成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品导入到门店
|
* 商品导入到门店
|
||||||
*/
|
*/
|
||||||
|
@ -42,29 +42,29 @@ class WarehouseProductController extends BaseAdminController
|
|||||||
|
|
||||||
$params = $this->request->post();
|
$params = $this->request->post();
|
||||||
|
|
||||||
foreach($params['product_arr'] as $k=>$v){
|
foreach ($params['product_arr'] as $k => $v) {
|
||||||
$data['admin_id']=$this->adminId;
|
$data['admin_id'] = $this->adminId;
|
||||||
$data['store_id']=0;
|
$data['store_id'] = 0;
|
||||||
$data['supplier_id']=$params['supplier_id'];
|
$data['supplier_id'] = $params['supplier_id'];
|
||||||
$data['warehouse_id']=$params['warehouse_id'];
|
$data['warehouse_id'] = $params['warehouse_id'];
|
||||||
$data['code']=$params['code'];
|
$data['code'] = $params['code'];
|
||||||
$data['product_id']=$v['product_id'];
|
$data['product_id'] = $v['product_id'];
|
||||||
$data['nums']=$v['nums'];
|
$data['nums'] = $v['nums'];
|
||||||
$data['purchase']=$v['purchase'];
|
$data['purchase'] = $v['purchase'];
|
||||||
$data['total_price']=$v['total_price'];
|
$data['total_price'] = $v['total_price'];
|
||||||
$data['financial_pm']=1;
|
$data['financial_pm'] = 1;
|
||||||
if(!empty($v['manufacture'])){
|
if (!empty($v['manufacture'])) {
|
||||||
$data['manufacture']=$v['manufacture'];
|
$data['manufacture'] = $v['manufacture'];
|
||||||
}
|
}
|
||||||
if(!empty($v['expiration_date'])){
|
if (!empty($v['expiration_date'])) {
|
||||||
$data['expiration_date']=$v['expiration_date'];
|
$data['expiration_date'] = $v['expiration_date'];
|
||||||
}
|
}
|
||||||
WarehouseProductLogic::add($data);
|
WarehouseProductLogic::add($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WarehouseProductLogic::hasError()) {
|
if (WarehouseProductLogic::hasError()) {
|
||||||
return $this->fail(WarehouseProductLogic::getError());
|
return $this->fail(WarehouseProductLogic::getError());
|
||||||
}else{
|
} else {
|
||||||
return $this->success('添加成功', [], 1, 1);
|
return $this->success('添加成功', [], 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,14 +78,10 @@ class WarehouseProductController extends BaseAdminController
|
|||||||
*/
|
*/
|
||||||
public function edit()
|
public function edit()
|
||||||
{
|
{
|
||||||
$params = (new WarehouseProductValidate())->post()->goCheck('edit');
|
$params = $this->request->post();
|
||||||
$params['admin_id']=$this->adminId;
|
$params['admin_id'] = $this->adminId;
|
||||||
$result = WarehouseProductLogic::edit($params);
|
$result = WarehouseProductLogic::edit($params);
|
||||||
if (WarehouseProductLogic::hasError()) {
|
return $this->success('编辑成功', [], 1, 1);
|
||||||
return $this->fail(WarehouseProductLogic::getError());
|
|
||||||
}else{
|
|
||||||
return $this->success('编辑成功', [], 1, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -101,7 +97,7 @@ class WarehouseProductController extends BaseAdminController
|
|||||||
WarehouseProductLogic::delete($params);
|
WarehouseProductLogic::delete($params);
|
||||||
if (WarehouseProductLogic::hasError()) {
|
if (WarehouseProductLogic::hasError()) {
|
||||||
return $this->fail(WarehouseProductLogic::getError());
|
return $this->fail(WarehouseProductLogic::getError());
|
||||||
}else{
|
} else {
|
||||||
return $this->success('删除成功', [], 1, 1);
|
return $this->success('删除成功', [], 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,7 +119,8 @@ class WarehouseProductController extends BaseAdminController
|
|||||||
/**
|
/**
|
||||||
* 确认操作
|
* 确认操作
|
||||||
*/
|
*/
|
||||||
public function enter(){
|
public function enter()
|
||||||
|
{
|
||||||
// $id=$this->request->post('id');
|
// $id=$this->request->post('id');
|
||||||
// $result = WarehouseProductLogic::enter($id);
|
// $result = WarehouseProductLogic::enter($id);
|
||||||
// if (true === $result) {
|
// if (true === $result) {
|
||||||
@ -132,4 +129,4 @@ class WarehouseProductController extends BaseAdminController
|
|||||||
// return $this->fail(WarehouseProductLogic::getError());
|
// return $this->fail(WarehouseProductLogic::getError());
|
||||||
return $this->success('');
|
return $this->success('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return WarehouseProduct::where($this->searchWhere)
|
return WarehouseProduct::where($this->searchWhere)
|
||||||
->field(['id', 'admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time'])
|
->field(['id', 'oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time'])
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()->each(function ($item) {
|
->select()->each(function ($item) {
|
||||||
|
@ -217,5 +217,19 @@ class WarehouseLogic extends BaseLogic
|
|||||||
$count = WarehouseProductStorege::where('nums', '<', 0)->count();
|
$count = WarehouseProductStorege::where('nums', '<', 0)->count();
|
||||||
}
|
}
|
||||||
return ['lists' => $list, 'count' => $count];
|
return ['lists' => $list, 'count' => $count];
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 负库存更新归0
|
||||||
|
*/
|
||||||
|
public static function updateNegativeZero($parmas)
|
||||||
|
{
|
||||||
|
if ($parmas['type'] == 1) {
|
||||||
|
$res = StoreProduct::where('id',$parmas['id'])->update(['stock'=>0]);
|
||||||
|
} elseif ($parmas['type'] == 2) {
|
||||||
|
$res=StoreBranchProduct::where('id',$parmas['id'])->update(['stock'=>0]);
|
||||||
|
} elseif ($parmas['type'] == 3) {
|
||||||
|
$res = WarehouseProductStorege::where('id',$parmas['id'])->update(['nums'=>0]);
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,45 +51,8 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
$params['shipping_type']=2;
|
$params['shipping_type']=2;
|
||||||
$params['pay_type'] = 7;
|
$params['pay_type'] = 7;
|
||||||
$order = OrderLogic::createOrder($cartId, null, $user, $params);
|
$order = OrderLogic::createOrder($cartId, null, $user, $params);
|
||||||
if (OrderLogic::hasError()) {
|
return true;
|
||||||
StoreOrderLogic::setError(OrderLogic::getError());
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
$arr = [
|
|
||||||
'warehouse_id' => $params['warehouse_id']??-1,
|
|
||||||
'store_id' => $params['store_id'],
|
|
||||||
'supplier_id' => 0,
|
|
||||||
'code' => getNewOrderId('PS'),
|
|
||||||
'admin_id' => $params['admin_id'],
|
|
||||||
'financial_pm' => 0,
|
|
||||||
'batch' => 0,
|
|
||||||
'mark' => $mark ?? "",
|
|
||||||
];
|
|
||||||
$arr['delivery_time'] = time();
|
|
||||||
$res = WarehouseOrder::create($arr);
|
|
||||||
foreach ($params['product_arr'] as $k => $v) {
|
|
||||||
$data = [
|
|
||||||
'warehouse_id' => $params['warehouse_id']??-1,
|
|
||||||
'product_id' => $v['product_id'],
|
|
||||||
'store_id' => $params['store_id'],
|
|
||||||
'financial_pm' => 0,
|
|
||||||
'batch' => 1,
|
|
||||||
'nums' => $v['stock'],
|
|
||||||
'status' => 1,
|
|
||||||
'admin_id' => $params['admin_id'],
|
|
||||||
];
|
|
||||||
$storeProduct = StoreBranchProduct::where('id', $v['id'])->findOrEmpty()->toArray();
|
|
||||||
if ($v['stock']>0) {
|
|
||||||
$data['total_price'] = bcmul($v['stock'], $storeProduct['purchase'], 2);
|
|
||||||
$data['purchase'] = $storeProduct['purchase'];
|
|
||||||
$data['oid'] = $res['id'];
|
|
||||||
WarehouseProductLogic::add($data,0);
|
|
||||||
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
|
||||||
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,7 +122,6 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
// Db::commit();
|
// Db::commit();
|
||||||
return $res;
|
return $res;
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
d($e);
|
|
||||||
throw new BusinessException($e->getMessage());
|
throw new BusinessException($e->getMessage());
|
||||||
// Db::rollback();
|
// Db::rollback();
|
||||||
// Log::error($e->getMessage().',file:'.$e->getFile().',line:'.$e->getLine());
|
// Log::error($e->getMessage().',file:'.$e->getFile().',line:'.$e->getLine());
|
||||||
@ -141,34 +140,54 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function edit(array $params): bool
|
public static function edit(array $params): bool
|
||||||
{
|
{
|
||||||
|
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
$data = [
|
$before_nums = 0;
|
||||||
'warehouse_id' => $params['warehouse_id'],
|
$after_nums = 0;
|
||||||
'product_id' => $params['product_id'],
|
$find=WarehouseOrder::where('id',$params['oid'])->find();
|
||||||
'financial_pm' => $params['financial_pm'],
|
if($find){
|
||||||
'nums' => $params['nums'],
|
$res = WarehouseProduct::where('id', $params['id'])->find();
|
||||||
// 'price' => $params['price'],
|
|
||||||
'admin_id' => $params['admin_id'],
|
|
||||||
'total_price' => $params['total_price'],
|
|
||||||
'code' => $params['code'],
|
|
||||||
'purchase' => $params['purchase'] ?? '',
|
|
||||||
// 'cost' => $params['cost'] ?? '',
|
|
||||||
];
|
|
||||||
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::where('id', $params['id'])->update($data);
|
|
||||||
|
|
||||||
|
if($find['financial_pm']==1){
|
||||||
|
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->dec('nums',$res['nums'])->update();
|
||||||
|
StoreBranchProduct::where('store_id',$res['store_id'])->where('product_id',$res['product_id'])->dec('stock',$res['nums'])->update();
|
||||||
|
|
||||||
|
$warehouseProductStorege=WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->find();
|
||||||
|
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->inc('nums',$params['nums'])->update();
|
||||||
|
StoreBranchProduct::where('store_id',$res['store_id'])->where('product_id',$res['product_id'])->inc('stock',$params['nums'])->update();
|
||||||
|
$before_nums=$warehouseProductStorege['nums'];
|
||||||
|
$after_nums=$warehouseProductStorege['nums']+$params['nums'];
|
||||||
|
}else{
|
||||||
|
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->inc('nums',$res['nums'])->update();
|
||||||
|
StoreBranchProduct::where('store_id',$res['store_id'])->where('product_id',$res['product_id'])->dec('stock',$res['nums'])->update();
|
||||||
|
|
||||||
|
$warehouseProductStorege=WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->find();
|
||||||
|
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->dec('nums',$params['nums'])->update();
|
||||||
|
StoreBranchProduct::where('store_id',$res['store_id'])->where('product_id',$res['product_id'])->inc('stock',$params['nums'])->update();
|
||||||
|
$before_nums=$warehouseProductStorege['nums'];
|
||||||
|
$after_nums=bcsub($warehouseProductStorege['nums'],$params['nums'],2);
|
||||||
|
}
|
||||||
|
WarehouseProduct::where('id', $params['id'])->update([
|
||||||
|
'nums' => $params['nums'],
|
||||||
|
'purchase' => $params['purchase'],
|
||||||
|
'before_nums' => $before_nums,
|
||||||
|
'after_nums' => $after_nums,
|
||||||
|
'total_price' => $params['nums'] * $params['purchase'],
|
||||||
|
]);
|
||||||
|
$finds = WarehouseProduct::where('oid', $params['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||||
|
if ($finds) {
|
||||||
|
WarehouseOrder::where('id', $params['oid'])->update([
|
||||||
|
'nums' => $finds['nums'],
|
||||||
|
'total_price' => $finds['total_price']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return $res;
|
return $res;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
self::setError($e->getMessage());
|
throw new BusinessException($e->getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user