Merge pull request 'dev' (#473) from dev into main

Reviewed-on: #473
This commit is contained in:
mkm 2025-01-20 11:25:22 +08:00
commit f0b7f234f4
11 changed files with 201 additions and 74 deletions

View File

@ -176,4 +176,11 @@ class BeforehandOrderCartInfoController extends BaseAdminController
return $this->success('操作成功', [], 1, 1);
}
public function setStoreSale()
{
$params = $this->request->post();
BeforehandOrderCartInfoLogic::setStoreSale($params);
return $this->success('操作成功', [], 1, 1);
}
}

View File

@ -42,9 +42,21 @@ class PurchaseProductOfferController extends BaseAdminController
$params['admin_id'] = $this->adminId;
$result = PurchaseProductOfferLogic::add($params);
return $this->success('设置成功', [], 1, 1);
}
/**
* @notes 一键添加往期采购商品
* @return \think\response\Json
* @author admin
* @date 2024/08/14 15:06
*/
public function add_purchases_one_click()
{
$params = $this->request->post();
$params['admin_id'] = $this->adminId;
$result = PurchaseProductOfferLogic::AddPurchasesOneClick($params);
return $this->success('设置成功', [], 1, 1);
}
/**
* @notes 编辑采购商品

View File

@ -114,11 +114,13 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
$item->order_type_name = '仓库补货';
$item->outbound = '无须出库';
} elseif ($item->order_type == 6) {
$item->order_type_name = '往期补单';
$item->order_type_name = '往期补单-出库';
} elseif ($item->order_type == 7) {
$item->order_type_name = '采购订单';
} elseif ($item->order_type == 8) {
$item->order_type_name = '其他订单';
}elseif ($item->order_type == 9) {
$item->order_type_name = '往期补单-入库';
}
$item->msg = '';
$count1 = PurchaseProductOffer::where('order_id', $item->id)->where('buyer_confirm', 0)->count('id');

View File

@ -77,7 +77,7 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
}
}
$list = BeforehandOrderCartInfo::where($this->searchWhere)
->field(['id', 'bhoid', 'package', 'store_info', 'marques', 'gross_weight', 'net_weight', 'accept_num', 'after_sales', 'loss', 'uid', 'pay_price', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'purchase', 'price', 'total_price', 'cart_num', 'mark','create_time', 'procurement_order_id'])
->field(['id', 'bhoid', 'package', 'store_info', 'marques', 'gross_weight', 'net_weight', 'accept_num', 'after_sales', 'loss', 'uid', 'pay_price', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'purchase', 'price', 'total_price', 'cart_num', 'mark','create_time', 'procurement_order_id', 'store_sale'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) use ($system_store, $order_mark) {

View File

@ -2,6 +2,7 @@
namespace app\admin\logic\beforehand_order;
use app\admin\logic\store_branch_product\StoreBranchProductLogic;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\api\logic\order\CartLogic;
@ -329,12 +330,16 @@ class BeforehandOrderLogic extends BaseLogic
try {
$find = BeforehandOrder::where('id', $params['id'])->find();
$other_data = $params['other_data'];
$find->save([
$data=[
'other_data' => json_encode($other_data, true),
'file' => $params['file'],
'store_id' => $params['store_id'],
'mark' => $params['mark']
]);
];
if(!empty($params['order_type']) && $params['order_type']>0){
$data['order_type'] = $params['order_type'];
}
$find->save($data);
Db::commit();
return true;
} catch (\Throwable $e) {
@ -397,6 +402,7 @@ class BeforehandOrderLogic extends BaseLogic
];
$arr['delivery_time'] = strtotime($delivery_time);
$res = WarehouseOrder::create($arr);
$totalPrice = '0.00';
foreach ($info as $key => $arr) {
if ($user_ship == 0) {
$price = 0;
@ -421,11 +427,16 @@ class BeforehandOrderLogic extends BaseLogic
'code' => $res['code'],
'unit' => $arr['unit'] ?? 0,
];
$totalPrice = bcadd($totalPrice, $arr['total_price'], 2);
if ($arr['store_sale'] == 1) {
StoreBranchProductLogic::decStock($store_id, $arr['product_id'], $arr['cart_num']);
} else {
WarehouseProductLogic::setOutbound($data, 1, $admin_id);
}
}
$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']]);
$order->save(['outbound_id' => $res['id'], 'is_outbound' => 1, 'pay_price' => $finds['total_price']]);
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $totalPrice, 'nums' => $finds['nums']]);
$order->save(['outbound_id' => $res['id'], 'is_outbound' => 1, 'pay_price' => $totalPrice]);
BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->update(['is_buyer' => -1]);
Db::commit();
return true;

View File

@ -205,6 +205,7 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
$arr = [
'warehouse_id' => $params['warehouse_id'],
'supplier_id' => 0,
'order_type' => $beforehandOrder['order_type']??0,
'oid' => $beforehandOrder['id'],
'admin_id' => $params['admin_id'],
'financial_pm' => 1,
@ -217,16 +218,6 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
];
$res = WarehouseOrder::create($arr);
foreach ($offer_list as $k => $v) {
if (!empty($v['source_order_info'])) {
// 采购单来源于往期补单,需要减少对应订单的入库数量
$sourceOrderInfo = reset_index($v['source_order_info'], 'source_order_id');
$orders = BeforehandOrder::field('id,order_type')->whereIn('id', array_keys($sourceOrderInfo))->select()->toArray();
foreach ($orders as $order) {
if ($order['order_type'] == 6) {
$v['buyer_nums'] = $v['buyer_nums'] - $sourceOrderInfo[$order['id']]['need_num'];
}
}
}
$data['admin_id'] = $params['admin_id'];
$data['order_type'] = $beforehandOrder['order_type'];
$data['store_id'] = 0;
@ -339,4 +330,15 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
(new BeforehandOrderCartInfo())->saveAll($update);
}
public static function setStoreSale($params)
{
$cartInfo = BeforehandOrderCartInfo::where('id', $params['id'])->find();
if ($cartInfo['store_sale'] == 1) {
$update = ['store_sale' => 0];
} else {
$update = ['store_sale' => 1];
}
BeforehandOrderCartInfo::where('id', $params['id'])->update($update);
}
}

View File

@ -107,7 +107,61 @@ class PurchaseProductOfferLogic extends BaseLogic
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 一键添加往期采购商品
* @param array $params
* @return bool
* @author admin
* @date 2024/08/14 15:06
*/
public static function AddPurchasesOneClick(array $params): bool
{
Db::startTrans();
try {
$arr=BeforehandOrderCartInfo::where('bhoid',$params['order_id'])->select();
$data_arr=[];
$procurementOrder = new BeforehandOrder();
$procurementOrder->order_id = getNewOrderId('CG');
$procurementOrder->buyer_id = $params['buyer_id'];
$procurementOrder->admin_id = $params['admin_id'];
$procurementOrder->order_type = 9;
$procurementOrder->total_price = 0;
$procurementOrder->pay_price = 0;
$procurementOrder->save();
foreach ($arr as $k=>$v){
$data_arr[]=[
'order_id' => $procurementOrder['id'],
'product_id' => $v['product_id'],
'unit' => $v['unit'],
'is_buyer' => $v['is_buyer'],
'need_num' => $v['cart_num'],
'buyer_id' => $params['buyer_id'],
'mark' => '往期补单采购',
'package' => '',
'store_info' => '',
'marques' => '',
'after_sales' => '',
'status' => 0,
'source_order_info' => [
[
'source_order_id' => $params['order_id'],
'product_id' => $v['product_id'],
'need_num' => $v['cart_num'],
'mark' => '往期补单采购',
]
]
];
}
(new PurchaseProductOffer())->saveAll($data_arr);
BeforehandOrderCartInfo::where(['bhoid' => $params['order_id']])->update(['is_buyer' => 1, 'procurement_order_id' => $procurementOrder['id']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 编辑采购商品
@ -461,5 +515,4 @@ class PurchaseProductOfferLogic extends BaseLogic
}
return $res;
}
}

View File

@ -120,4 +120,27 @@ class StoreBranchProductLogic extends BaseLogic
{
return StoreBranchProduct::findOrEmpty($params['id'])->toArray();
}
public static function decStock($storeId, $productId, $num)
{
$branchProduct = StoreBranchProduct::where('store_id', $storeId)->where('product_id', $productId)->find();
if ($branchProduct) {
$stock = bcsub($branchProduct['stock'], $num, 2);
StoreBranchProduct::update([
'stock' => $stock,
'total_price' => bcmul($stock, $branchProduct['purchase'], 2),
'sales' => bcadd($branchProduct['sales'], $num, 2)
], ['id' => $branchProduct['id']]);
SqlChannelLog('StoreBranchProduct',$branchProduct['id'], $num, -1, Request()->url());
} else {
$storeProduct = StoreProduct::where('id', $productId)->find();
$branchProduct = StoreProductLogic::ordinary(['id' => $productId], $storeId, 0, $storeProduct);
StoreBranchProduct::update([
'stock' => -$num,
'sales' => $num
], ['product_id' => $productId,'store_id'=>$storeId]);
SqlChannelLog('StoreBranchProduct',$branchProduct['id'], $num, -1, Request()->url());
}
}
}

View File

@ -38,7 +38,7 @@ class WarehouseProductLogic extends BaseLogic
// Db::startTrans();
try {
$after_nums = 0;
if ($params['order_type'] != 6) {
if (!in_array($params['order_type'],[6,7,9])) {
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
if ($storege) {
$after_nums = $storege['nums'] + $params['nums'];
@ -138,6 +138,8 @@ class WarehouseProductLogic extends BaseLogic
'type' => 1,
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'outbound_id' => $params['oid'] ?? 0,
'warehouse_id' =>1,
'status' => 0
]);
}

View File

@ -253,7 +253,13 @@ class PayNotifyLogic extends BaseLogic
UserProductStorageLogic::add($order);
}
if ($order->pay_type != 10) {
$order->pay_price = bcdiv($extra['amount']['payer_total'], 100, 2);
$payerTotal = $extra['amount']['payer_total'];
if (!empty($extra['promotion_detail'])) {
foreach ($extra['promotion_detail'] as $v) {
$payerTotal += $v['amount'];
}
}
$order->pay_price = bcdiv($payerTotal, 100, 2);
} else {
$extra['transaction_id'] = time();
}
@ -671,6 +677,9 @@ class PayNotifyLogic extends BaseLogic
//积分写入
if (isset($user) && $user['user_ship'] == 0) {
UserSignLogic::OrderWrite($order);
if (SystemStore::isActivityStore($order['store_id']) && $order['pay_price'] >= 19.9) {
User::where('id', $order['uid'])->update(['user_ship' => 43]);
}
}
if ($off_activity == 1) {
//-----活动价结算更改

View File

@ -42,4 +42,10 @@ class SystemStore extends BaseModel
Log::error('system_store:'.$e->getMessage());
}
}
public static function isActivityStore($storeId)
{
return in_array($storeId, [5]);
}
}