commit
2252caa643
@ -109,12 +109,12 @@ class PurchaseProductOfferController extends BaseAdminController
|
||||
PurchaseProductOfferLogic::setStoreroomInfo($params);
|
||||
return $this->success('设置成功', [], 1, 1);
|
||||
}
|
||||
public function setStoreroomInfoTwo()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
PurchaseProductOfferLogic::setStoreroomInfoTwo($params);
|
||||
return $this->success('设置成功', [], 1, 1);
|
||||
}
|
||||
// public function setStoreroomInfoTwo()
|
||||
// {
|
||||
// $params = $this->request->post();
|
||||
// PurchaseProductOfferLogic::setStoreroomInfoTwo($params);
|
||||
// return $this->success('设置成功', [], 1, 1);
|
||||
// }
|
||||
/**
|
||||
* @notes 删除采购商品
|
||||
* @return \think\response\Json
|
||||
|
@ -77,9 +77,10 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
|
||||
}
|
||||
if (!empty($this->params['store_staff_id']) || !empty($this->params['is_store'])) {
|
||||
$this->searchWhere[] = ['store_staff_id', '>', 0];
|
||||
} else {
|
||||
$this->searchWhere[] = ['store_staff_id', '=', 0];
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// $this->searchWhere[] = ['store_staff_id', '=', 0];
|
||||
// }
|
||||
if ($order_rk!='') {
|
||||
$oid=WarehouseOrder::where('financial_pm',1)->where('code','like','%'.$order_rk)->column('id');
|
||||
$this->searchWhere[] = ['warehousing_id','in',$oid];
|
||||
|
@ -49,7 +49,7 @@ class WarehouseOrderLists extends BaseAdminDataLists implements ListsSearchInter
|
||||
public function lists(): array
|
||||
{
|
||||
return WarehouseOrder::where($this->searchWhere)
|
||||
->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'code', 'financial_pm', 'admin_id', 'batch', 'mark', 'purchase', 'total_price', 'status', 'create_time', 'completed_amount', 'outstanding_amount'])
|
||||
->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'code', 'financial_pm', 'admin_id', 'batch', 'mark', 'purchase', 'total_price', 'status', 'create_time', 'completed_amount', 'outstanding_amount', 'oid'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
|
@ -389,7 +389,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
Db::startTrans();
|
||||
try {
|
||||
$arr = [
|
||||
'oid' => 0,
|
||||
'oid' => $order['id'],
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'store_id' => $store_id,
|
||||
'supplier_id' => 0,
|
||||
@ -436,7 +436,10 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
}
|
||||
$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' => $totalPrice, 'nums' => $finds['nums']]);
|
||||
$order->save(['outbound_id' => $res['id'], 'is_outbound' => 1, 'pay_price' => $totalPrice]);
|
||||
$result = BeforehandOrder::where('id', $order['id'])->where('outbound_id', 0)->where('is_outbound', 0)->update(['outbound_id' => $res['id'], 'is_outbound' => 1, 'pay_price' => $totalPrice]);
|
||||
if (!$result) {
|
||||
throw new BusinessException('出库失败,预订单更新出错');
|
||||
}
|
||||
BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->update(['is_buyer' => -1]);
|
||||
self::confirm(['id' => $params['bhoid']]);
|
||||
Db::commit();
|
||||
|
@ -258,7 +258,10 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
|
||||
if ($beforehandOrder['order_type'] == 7) {
|
||||
$attrs['is_buying'] = 1;
|
||||
}
|
||||
BeforehandOrder::where('id', $params['bhoid'])->update($attrs);
|
||||
$result = BeforehandOrder::where('id', $params['bhoid'])->where('warehousing_id', 0)->where('is_warehousing', 0)->update($attrs);
|
||||
if (!$result) {
|
||||
throw new BusinessException('出库失败,预订单更新出错');
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
|
@ -222,19 +222,19 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
Db::startTrans();
|
||||
try {
|
||||
$offer->save([
|
||||
'buyer_nums' => $params['buyer_nums'],
|
||||
// 'buyer_nums' => $params['buyer_nums'],
|
||||
'supplier_id' => $params['supplier_id'],
|
||||
'price' => $params['purchase'],
|
||||
'purchase_price' => $params['purchase_price'] ?? 0,
|
||||
// 'price' => $params['purchase'],
|
||||
// 'purchase_price' => $params['purchase_price'] ?? 0,
|
||||
'total_price' => $params['total_price'],
|
||||
'pay_type' => $params['pay_type'] ?? 0,
|
||||
'buyer_confirm' => 1,
|
||||
'package' => $params['package'],
|
||||
'store_info' => $params['store_info'],
|
||||
'marques' => $params['marques'],
|
||||
'after_sales' => $params['after_sales'],
|
||||
'manufacture' => $params['manufacture'],
|
||||
'expiration_date' => $params['expiration_date'],
|
||||
// 'package' => $params['package'],
|
||||
// 'store_info' => $params['store_info'],
|
||||
// 'marques' => $params['marques'],
|
||||
// 'after_sales' => $params['after_sales'],
|
||||
// 'manufacture' => $params['manufacture'],
|
||||
// 'expiration_date' => $params['expiration_date'],
|
||||
]);
|
||||
// $find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id,cate_id')->find();
|
||||
@ -243,36 +243,6 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
$order->pay_price = PurchaseProductOffer::where('order_id', $order['id'])->sum('total_price');
|
||||
$order->total_price = $order->pay_price;
|
||||
$order->save();
|
||||
self::setProductGroupPrice($params, $product);
|
||||
// $data = [];
|
||||
// $dict_data = DictData::where('type_value', 'price_lv_' . $product['top_cate_id'])->field('name,value')->select();
|
||||
// $data['bhoid'] = $offer['order_id'];
|
||||
// $data['offer_id'] = $params['id'];
|
||||
// $data['product_id'] = $offer['product_id'];
|
||||
// $data['purchase_price'] = $params['purchase'];
|
||||
// $data['status'] = 0;
|
||||
// if ($dict_data) {
|
||||
// foreach ($dict_data as $k => $v) {
|
||||
// if ($v['name'] == 'purchase') {
|
||||
// $data['purchase_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['purchase'] = bcadd($lv, $params['purchase'], 2);
|
||||
// } elseif ($v['name'] == 'cost') {
|
||||
// $data['cost_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['cost'] = bcadd($lv, $params['purchase'], 2);
|
||||
// } elseif ($v['name'] == 'price') {
|
||||
// $data['price_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['price'] = bcadd($lv, $params['purchase'], 2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if ($find) {
|
||||
// $find->save($data);
|
||||
// } else {
|
||||
// StoreProductPrice::create($data);
|
||||
// }
|
||||
Db::commit();
|
||||
$offer['store_name'] = $product['store_name'];
|
||||
$offer['unit_name'] = $unit_name;
|
||||
@ -288,7 +258,6 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
d($e);
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
@ -336,22 +305,25 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
PurchaseProductOffer::where('id', $params['id'])->update(['is_accept' => 1]);
|
||||
$find = BeforehandOrderCartInfo::where(['bhoid' => $params['bhoid'], 'product_id' => $params['product_id']])->find();
|
||||
$data = [
|
||||
'gross_weight' => $params['gross_weight'] ?? 0,
|
||||
'net_weight' => $params['net_weight'] ?? 0,
|
||||
'accept_num' => $params['accept_num'] ?? 0,
|
||||
];
|
||||
if ($params['accept_num'] != $find['cart_num']) {
|
||||
$pay_price = bcmul($params['accept_num'], $find['price'], 2);
|
||||
$data['pay_price'] = $pay_price;
|
||||
if($params['accept_num']<=0){
|
||||
throw new BusinessException('分拣数量不能小于0');
|
||||
}
|
||||
$find->save($data);
|
||||
if ($params['accept_num'] != $find['cart_num']) {
|
||||
$pay_price = BeforehandOrderCartInfo::where(['bhoid' => $params['bhoid']])->sum('pay_price');
|
||||
BeforehandOrder::where('id', $params['bhoid'])->update(['pay_price' => $pay_price]);
|
||||
$offer=PurchaseProductOffer::where('id', $params['id'])->find();
|
||||
$offer_data = ['buyer_nums' => $params['accept_num'],];
|
||||
$offer_data['is_storage'] = 1;
|
||||
if($offer['total_price']>0){
|
||||
$price= bcdiv($offer['total_price'],$params['accept_num'], 2);
|
||||
$offer_data['price'] = $price;
|
||||
}else{
|
||||
throw new BusinessException('采购总价不能为0');
|
||||
}
|
||||
$offer->save($offer_data);
|
||||
|
||||
$pay_price = PurchaseProductOffer::where(['order_id' => $offer['order_id']])->sum('total_price');
|
||||
BeforehandOrder::where('id', $offer['bhoid'])->update(['pay_price' => $pay_price]);
|
||||
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id,cate_id')->find();
|
||||
$offer['purchase']=$price;
|
||||
self::setProductGroupPrice($offer, $product);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
|
@ -238,13 +238,6 @@ class WarehouseProductLogic extends BaseLogic
|
||||
$datas['expiration_date'] = strtotime($params['expiration_date']);
|
||||
}
|
||||
$res->save($datas);
|
||||
$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();
|
||||
return $res;
|
||||
@ -266,22 +259,20 @@ class WarehouseProductLogic extends BaseLogic
|
||||
{
|
||||
$res = WarehouseProduct::where('id', $params['id'])->find();
|
||||
if ($res) {
|
||||
$res->delete();
|
||||
if ($res['financial_pm'] == 1) {
|
||||
$find = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $res['nums'])->save();
|
||||
SqlChannelLog('WarehouseProductStorege', $find['id'], $res['nums'], -1, Request()->url(),$admin_id);
|
||||
} elseif ($res['financial_pm'] == 0) {
|
||||
$find = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->save();
|
||||
SqlChannelLog('WarehouseProductStorege', $find['id'], $res['nums'], 1, Request()->url(),$admin_id);
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($res['financial_pm'] == 1) {
|
||||
self::incProductDecStorege($res, $res['nums'], $admin_id);
|
||||
} elseif ($res['financial_pm'] == 0) {
|
||||
self::decProductIncStorege($res, $res['nums'], $admin_id);
|
||||
}
|
||||
$res->delete();
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($th->getMessage());
|
||||
}
|
||||
$find = WarehouseProduct::where('oid', $res['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $res['oid'])->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
throw new BusinessException('没有查到出入库信息');
|
||||
}
|
||||
@ -339,12 +330,6 @@ class WarehouseProductLogic extends BaseLogic
|
||||
}
|
||||
|
||||
$res->save($datas);
|
||||
$finds = WarehouseProduct::where('oid', $res['oid'])->field('sum(nums) as nums')->find();
|
||||
if ($finds) {
|
||||
WarehouseOrder::where('id', $res['oid'])->update([
|
||||
'nums' => $finds['nums'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
@ -370,28 +355,84 @@ class WarehouseProductLogic extends BaseLogic
|
||||
}
|
||||
|
||||
//减少
|
||||
private static function decProductIncStorege($res,$nums,$admin_id=0)
|
||||
private static function decProductIncStorege($warehouseProduct,$nums,$admin_id=0)
|
||||
{
|
||||
$res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])
|
||||
->where('product_id', $res['product_id'])->find();
|
||||
$res1->nums = bcadd($res1->nums,$nums,2);
|
||||
$res1->save();
|
||||
SqlChannelLog('WarehouseProductStorege', $res1['id'], $nums, 1, Request()->url(),$admin_id);
|
||||
|
||||
WarehouseProduct::where('id',$res['id'])->update(['nums'=>bcsub($res['nums'],$nums,2)]);
|
||||
SqlChannelLog('WarehouseProduct', $res['id'], $nums, -1, Request()->url(),$admin_id);
|
||||
$warehouseProductStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])
|
||||
->where('product_id', $warehouseProduct['product_id'])->find();
|
||||
$warehouseProductStorage->nums = bcadd($warehouseProductStorage->nums,$nums,2);
|
||||
$warehouseProductStorage->save();
|
||||
SqlChannelLog('WarehouseProductStorege', $warehouseProductStorage['id'], $nums, 1, Request()->url(),$admin_id);
|
||||
|
||||
$update = [
|
||||
'nums' => bcsub($warehouseProduct['nums'], $nums, 2),
|
||||
'total_price' => bcsub($warehouseProduct['total_price'], bcmul($nums, $warehouseProduct['price'], 2), 2),
|
||||
];
|
||||
WarehouseProduct::where('id',$warehouseProduct['id'])->update($update);
|
||||
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $nums, -1, Request()->url(),$admin_id);
|
||||
|
||||
$find = WarehouseProduct::where('oid', $warehouseProduct['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $warehouseProduct['oid'])->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
|
||||
self::updateStoreStorage($warehouseProduct['oid'], $nums, 'dec');
|
||||
}
|
||||
|
||||
//增加
|
||||
private static function incProductDecStorege($res, $nums,$admin_id=0)
|
||||
private static function incProductDecStorege($warehouseProduct, $nums,$admin_id=0)
|
||||
{
|
||||
$res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])
|
||||
->where('product_id', $res['product_id'])->find();
|
||||
$res1->nums = bcsub($res1->nums,$nums,2);
|
||||
$res1->save();
|
||||
SqlChannelLog('WarehouseProductStorege', $res1['id'], $nums, -1, Request()->url(),$admin_id);
|
||||
$warehouseProductStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])
|
||||
->where('product_id', $warehouseProduct['product_id'])->find();
|
||||
$warehouseProductStorage->nums = bcsub($warehouseProductStorage->nums,$nums,2);
|
||||
$warehouseProductStorage->save();
|
||||
SqlChannelLog('WarehouseProductStorege', $warehouseProductStorage['id'], $nums, -1, Request()->url(),$admin_id);
|
||||
|
||||
WarehouseProduct::where('id',$res['id'])->update(['nums'=>bcadd($res['nums'],$nums,2)]);
|
||||
SqlChannelLog('WarehouseProduct', $res['id'], $nums, 1, Request()->url(),$admin_id);
|
||||
$update = [
|
||||
'nums' => bcadd($warehouseProduct['nums'], $nums, 2),
|
||||
'total_price' => bcadd($warehouseProduct['total_price'], bcmul($nums, $warehouseProduct['price'], 2), 2),
|
||||
];
|
||||
WarehouseProduct::where('id',$warehouseProduct['id'])->update($update);
|
||||
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $nums, 1, Request()->url(),$admin_id);
|
||||
|
||||
$find = WarehouseProduct::where('oid', $warehouseProduct['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $warehouseProduct['oid'])->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
|
||||
self::updateStoreStorage($warehouseProduct['oid'], $nums);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新门店库存和门店入库单
|
||||
* @param $outboundId
|
||||
* @param $nums
|
||||
* @param $type
|
||||
* @return void
|
||||
*/
|
||||
private static function updateStoreStorage($outboundId, $nums, $type = 'inc')
|
||||
{
|
||||
$storeStorage = SystemStoreStorage::where('outbound_id', $outboundId)->find();
|
||||
if (empty($storeStorage)) {
|
||||
return;
|
||||
}
|
||||
$storeStorage->nums = $type == 'inc' ? $storeStorage->nums + $nums : $storeStorage->nums - $nums;
|
||||
$storeStorage->save();
|
||||
if ($storeStorage->status == 0) {
|
||||
return;
|
||||
}
|
||||
// 门店入库单已确认,增加/减少 门店库存
|
||||
$storeBranchProduct = StoreBranchProduct::where('store_id', $storeStorage->store_id)
|
||||
->where('product_id', $storeStorage->product_id)->find();
|
||||
if (!empty($storeBranchProduct)) {
|
||||
$storeBranchProduct->stock = $type == 'inc' ? $storeBranchProduct->stock + $nums : $storeBranchProduct->stock - $nums;
|
||||
$storeBranchProduct->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ use app\common\model\store_product\StoreProduct;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\Config;
|
||||
use app\common\model\store_product_group_price\StoreProductGroupPrice;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\user\User;
|
||||
//use app\common\model\goods\GoodsLabel;
|
||||
use think\facade\Db;
|
||||
@ -104,7 +105,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
|
||||
$user_ship=-1;
|
||||
if ($uid > 0) {
|
||||
$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]) && !empty($this->params['store_id']) && !SystemStore::isSelfOperate($this->params['store_id'])) {
|
||||
$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,is_lack';
|
||||
}
|
||||
}
|
||||
@ -128,7 +129,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
$list = StoreProductGroupPrice::resetProductsPrice($list, $user_ship);
|
||||
$list = StoreProductGroupPrice::resetStoreProductPrice($list, $user_ship, $this->params['store_id'] ?? 0);
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace app\common\model\store_product_group_price;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
@ -40,5 +41,17 @@ class StoreProductGroupPrice extends BaseModel
|
||||
}
|
||||
return $product;
|
||||
}
|
||||
|
||||
public static function resetStoreProductPrice($productList, $userShip, $shopId)
|
||||
{
|
||||
if ($shopId > 0 && SystemStore::isSelfOperate($shopId) && $userShip > 0) {
|
||||
foreach ($productList as &$item) {
|
||||
$item['price'] = $item['vip_price'];
|
||||
}
|
||||
return $productList;
|
||||
} else {
|
||||
return self::resetProductsPrice($productList, $userShip);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -48,4 +48,14 @@ class SystemStore extends BaseModel
|
||||
return in_array($storeId, [5]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否自营门店
|
||||
* @param $storeId
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSelfOperate($storeId): bool
|
||||
{
|
||||
return !in_array($storeId, [21, 22, 15, 7]);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user