# Conflicts:
#	app/common/logic/PayNotifyLogic.php
This commit is contained in:
lewis 2025-02-05 11:16:33 +08:00
commit c7c7bb9831
11 changed files with 200 additions and 72 deletions
app
admin
controller
lists
logic
beforehand_order
beforehand_order_cart_info
inventory_transfer_order
purchase_product_offer
api/logic
common
store/controller/beforehand_order

@ -37,4 +37,12 @@ class IndexController extends BaseAdminController
$res=DemoLogic::test3($id,$warehouse_id);
return $this->success('成功');
}
public function demo4()
{
$params=$this->request->get();
$is_vip=$this->request->get('is_vip',0);
$res=DemoLogic::syncPrice($params,$is_vip);
return $this->success('成功');
}
}

@ -86,9 +86,14 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
$exceptIds = ActivityZone::where('form_id', $this->params['activity_zone_form_id'])->column('product_id');
$query->where('is_show', 1)->where('product_type', '<>', 5)->whereNotIn('id', $exceptIds);
}
$storeId = $this->params['store_id'] ?? 0;
$is_true = true;
if ($storeId > 0) {
$is_true = SystemStore::isSelfOperate($storeId);
}
$list = $query->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) use($is_warehouse, $userShip,$order_type) {
->select()->each(function ($item) use ($is_warehouse, $userShip, $order_type, $is_true) {
$item['product_id'] = $item['id'];
$item['bar_code_two'] = '';
if (in_array($item['unit'], [2, 21])) {
@ -149,14 +154,15 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
$item['price'] = $price;
$item['store_name'] = $item['store_name'] . '|活动价';
}
}elseif($is_true == true && $userShip>0){
$item['price'] = $item['vip_price'];
$item['store_name'] = $item['store_name'] . '|会员价';
}
return $item;
})?->toArray();
if ($userShip > 0 && $userShip != 4) {
$list = StoreProductGroupPrice::resetStoreProductsPrice($list, $userShip, $this->params['store_id'] ?? 0);
}
// if ($userShip > 0 && $userShip != 4) {
// $list = StoreProductGroupPrice::resetStoreProductsPrice($list, $userShip, $this->params['store_id'] ?? 0);
// }
return $list;
}

@ -54,7 +54,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
{
if ($this->request->get('product_id')) {
$product_id = $this->request->get('product_id');
$ids = StoreProduct::where('store_name', 'like', '%' . $product_id . '%')->withTrashed()->column('id');
$ids = StoreProduct::where('store_name', 'like', '%' . $product_id . '%')->column('id');
if ($ids) {
$this->searchWhere[] = ['product_id', 'in', $ids];
$this->ids = $ids;
@ -64,7 +64,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
}
if ($this->request->get('bar_code')) {
$bar_code = $this->request->get('bar_code');
$ids = StoreProduct::where('bar_code', 'like', '%' . $bar_code . '%')->withTrashed()->column('id');
$ids = StoreProduct::where('bar_code', 'like', '%' . $bar_code . '%')->column('id');
if ($ids) {
$this->searchWhere[] = ['product_id', 'in', $ids];
$this->ids = $ids;
@ -76,7 +76,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
->field(['id', 'code','pay_type','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','is_pay'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->withTrashed()
// ->withTrashed()
->select()->each(function ($item) {
$item->store_name = '';
$item->image = '';

@ -8,6 +8,7 @@ use app\admin\logic\store_product\StoreProductLogic;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\api\logic\order\CartLogic;
use app\api\logic\order\OrderLogic;
use app\common\enum\OrderEnum;
use app\common\model\beforehand_order\BeforehandOrder;
use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
@ -262,7 +263,7 @@ class BeforehandOrderLogic extends BaseLogic
'store_id' => $params['store_id'] ?? 0,
'shipping_type' => 2, //配送方式 1=快递 2=门店自提
'deduction_price' => 0, //抵扣金额
'source' => 2, //后台下单
'source' => OrderEnum::SOURCE_20, //来源
'order_type' => $order['order_type'],
'is_storage' => 0,
'verify_code' => createCode($code),
@ -674,6 +675,15 @@ class BeforehandOrderLogic extends BaseLogic
$res['examine_name'] = Admin::where('id', $record['check_user_id'])->value('name');
}
}
$res['is_vip']=0;
if($res['uid']>0){
$user_ship=User::where('id',$res['uid'])->value('user_ship');
if($user_ship>0){
$res['is_vip']=1;
}
}
return $res;
}

@ -61,9 +61,11 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
public static function appendAdd(array $params): bool
{
$order = BeforehandOrder::where('id', $params['id'])->find();
if ((!empty($order) && $order->is_confirm == 1 && empty($params['admin_id'])) || $order['is_outbound'] > 0) {
if(empty($params['admin_id'])){
if ((!empty($order) && $order->is_confirm == 1 ) || $order['is_outbound'] > 0) {
throw new BusinessException('该订单已确认,不能追加商品');
}
}
Db::startTrans();
try {
$datas = [];
@ -109,6 +111,11 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
if($params['admin_id']==23&&$params['purchases']!=$find['price'] ){
throw new BusinessException('当前账号没有权限编辑价格, 请联系管理员修改');
}
$bhoid = $params['bhoid'];
$order=BeforehandOrder::where('id', $bhoid)->find();
if($order['outbound_id']>0){
throw new BusinessException('该订单已出库,不能修改');
}
if($params['total_price']<=0){
$total_price=bcmul($params['purchases'],$params['nums'],2);
}else{
@ -122,12 +129,10 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
'accept_num' => $params['nums'],
'mark' => $params['mark']??'',
]);
$bhoid = $params['bhoid'];
$info = BeforehandOrderCartInfo::where('bhoid', $bhoid)->field('sum(cart_num) as cart_num,sum(total_price) as total_price,sum(pay_price) as pay_price')->find();
if($find['is_buyer']==1){
PurchaseProductOffer::where('order_id',$bhoid)->where('product_id',$find['product_id'])->update(['need_num'=>$params['nums']]);
}
$order=BeforehandOrder::where('id', $bhoid)->find();
$order->save(['total_price' => $info['total_price'],'pay_price' => $info['pay_price'], 'total_num' => $info['cart_num']]);
if($order['outbound_id']>0){
@ -315,7 +320,11 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
public static function syncPrice($params)
{
$cartInfo = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->where('price', 0)->select()->toArray();
$outbound_id=BeforehandOrder::where('id', $params['bhoid'])->value('outbound_id');
if($outbound_id>0){
throw new BusinessException('该订单已出库,不能修改');
}
$cartInfo = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select()->toArray();
$productIds = array_column($cartInfo, 'product_id');
$products = StoreProduct::whereIn('id', $productIds)->select()->toArray();
$products = reset_index($products, 'id');

@ -8,6 +8,8 @@ use app\common\logic\BaseLogic;
use app\common\model\inventory_transfer\InventoryTransfer;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore;
use app\common\model\warehouse\Warehouse;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use support\exception\BusinessException;
use think\facade\Db;
@ -31,6 +33,7 @@ class InventoryTransferOrderLogic extends BaseLogic
*/
public static function add(array $params,$admin_id): bool
{
$types=$params['types']??0;
if (empty($params['product_arr'])) {
throw new BusinessException('请选择商品');
}
@ -78,13 +81,17 @@ class InventoryTransferOrderLogic extends BaseLogic
'two_type' => $params['two_type'],
'one_id' => $params['one_id'],
'two_id' => $params['two_id'],
'types' => $params['types']??0,
'types' => $types,
'mark' => $params['mark']??'',
]);
foreach ($insert as $k => $v) {
$insert[$k]['oid'] = $order['id'];
}
InventoryTransfer::insertAll($insert);
if($types==1){
Db::commit();
return true;
}
foreach ($insert as $v) {
if($params['one_type']==1){
$find=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $params['one_id'])->find();
@ -185,6 +192,28 @@ class InventoryTransferOrderLogic extends BaseLogic
*/
public static function detail($params): array
{
return InventoryTransferOrder::findOrEmpty($params['id'])->toArray();
$data= InventoryTransferOrder::findOrEmpty($params['id']);
$type_name='';
if($data->one_type==1){
$data->one_name=SystemStore::where('id',$data->one_id)->value('name');
$type_name='门店转';
}else{
$data->one_name=Warehouse::where('id',$data->one_id)->value('name');
$type_name='仓库转';
}
if($data->two_type==1){
$type_name.='门店';
$data->two_name=SystemStore::where('id',$data->two_id)->value('name');
}else{
$type_name.='仓库';
$data->two_name=Warehouse::where('id',$data->two_id)->value('name');
}
$data->type_name=$type_name;
$data['product_list']=InventoryTransfer::where('oid',$params['id'])->select()->each(function ($item) {
$find= StoreProduct::where('id',$item->product_id)->withTrashed()->field('store_name')->find();
$item->store_name=$find['store_name'];
})
->toArray();
return $data->toArray();
}
}

@ -60,7 +60,7 @@ class PurchaseProductOfferLogic extends BaseLogic
if ($mark == '') {
$mark = BeforehandOrderCartInfo::where('bhoid', $params['order_id'])->where('product_id', $params['product_id'])->value('mark');
}
$find = StoreProduct::where('id', $params['product_id'])->find();
$find = StoreProduct::where('id', $params['product_id'])->withTrashed()->find();
$purchaseProductOffer = PurchaseProductOffer::where(['order_id' => $procurementOrder['id'], 'product_id' => $params['product_id']])->find();
if ($purchaseProductOffer) {
$purchaseProductOffer->need_num = $purchaseProductOffer['need_num'] + $params['need_num'];
@ -104,6 +104,7 @@ class PurchaseProductOfferLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Db::rollback();
d($e);
throw new BusinessException($e->getMessage());
}
}

@ -3,9 +3,12 @@
namespace app\api\logic;
use app\common\logic\BaseLogic;
use app\common\model\beforehand_order\BeforehandOrder;
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_group_price\StoreProductGroupPrice;
use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use think\facade\Db;
@ -111,4 +114,49 @@ class DemoLogic extends BaseLogic
}
}
}
public static function syncPrice($params,$is_vip=0)
{
$outbound_id=BeforehandOrder::where('id', $params['id'])->value('outbound_id');
$cartInfo = BeforehandOrderCartInfo::where('bhoid', $params['id'])->select()->toArray();
$productIds = array_column($cartInfo, 'product_id');
$products = StoreProduct::whereIn('id', $productIds)->withTrashed()->select()->toArray();
$products = reset_index($products, 'id');
$update = [];
foreach ($cartInfo as $v) {
$product = $products[$v['product_id']];
if (empty($product)) {
continue;
}
if ($is_vip == 1) {
$price = $product['vip_price'];
} else {
$price = $product['price'];
}
$update[] = [
'id' => $v['id'],
'price' => $price,
'total_price' => $price * $v['cart_num'],
'pay_price' => $price * $v['cart_num'],
];
}
(new BeforehandOrderCartInfo())->saveAll($update);
$totalPrice = array_sum(array_column($update, 'total_price'));
BeforehandOrder::where('id', $params['id'])->update(['total_price' => $totalPrice,'pay_price' => $totalPrice]);
if($outbound_id){
WarehouseProduct::where('oid', $outbound_id)->select()->each(function ($item) use($is_vip) {
if($is_vip==0){
$find = StoreProduct::where('id', $item['product_id'])->withTrashed()->field('purchase,vip_price,price')->find();
$item->save(['price' => $find['price'], 'purchase' => $find['purchase'], 'vip_price' => $find['vip_price'],'total_price' => $find['price'] * $item['nums']]);
}else{
$find = StoreProduct::where('id', $item['product_id'])->withTrashed()->field('purchase,vip_price,price')->find();
$item->save(['price' => $find['vip_price'], 'purchase' => $find['purchase'], 'vip_price' => $find['vip_price'],'total_price' => $find['vip_price'] * $item['nums']]);
}
});
$total_price=WarehouseProduct::where('oid', $outbound_id)->sum('total_price');
WarehouseOrder::where('id', $outbound_id)->update(['total_price' => $total_price]);
}
}
}

@ -49,6 +49,18 @@ class OrderEnum
const USER_ORDER_REFUND = 19;//订单返还
const PAY_BACK =-1;
//-----------------------订单来源-----------------------//
/**
* @SOURCE_0 小程序
* @SOURCE_1 收银台
* @SOURCE_2 后台下单
* @SOURCE_20 预订单转订单
*/
const SOURCE_0 =0;//小程序
const SOURCE_1 =1;//收银台
const SOURCE_2 =2;//后台下单
const SOURCE_20 =20;//预订单转订单
/**
* 收入支出类型

@ -351,7 +351,7 @@ class PayNotifyLogic extends BaseLogic
// $user = User::where('id', $order['uid'])->findOrEmpty();
// $capitalFlowDao = new CapitalFlowLogic($user);
// $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $order['pay_price'], '', 1);
// self::addStock($order['id']); //微信
self::addStock($order['id'], $order);
return true;
}
@ -374,7 +374,7 @@ class PayNotifyLogic extends BaseLogic
}
$user->save();
//增加数量
self::addStock($order['id']);
self::addStock($order['id'], $order);
}
if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付
$user = User::where('id', $order['uid'])->findOrEmpty();
@ -389,7 +389,7 @@ class PayNotifyLogic extends BaseLogic
}
$user->save();
//增加数量
self::addStock($order['id']);
self::addStock($order['id'], $order);
}
UserSignLogic::RefundOrder($order);
@ -427,7 +427,7 @@ class PayNotifyLogic extends BaseLogic
$model->status = YesNoEnum::YES;
$model->save();
//增加数量
self::addStock($order['id']);
self::addStock($order['id'], $order);
StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]);
(new StoreFinanceFlowLogic())->store_finance_back($orderSn, $order['store_id']);
@ -630,6 +630,7 @@ class PayNotifyLogic extends BaseLogic
continue;
}
}
if ($order['source'] != OrderEnum::SOURCE_20) {
if ($branchProduct) {
$stock = bcsub($branchProduct['stock'], $v['cart_num'], 2);
StoreBranchProduct::update([
@ -647,6 +648,7 @@ class PayNotifyLogic extends BaseLogic
SqlChannelLog('StoreBranchProduct', $branchProduct['id'], $v['cart_num'], -1, Request()->url());
}
}
}
} catch (\Throwable $e) {
Log::error('订单库存更新失败:' . $e->getMessage());
// 异常处理代码,例如记录日志或发送通知等。
@ -868,8 +870,11 @@ class PayNotifyLogic extends BaseLogic
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function addStock($oid)
public static function addStock($oid, $order)
{
if ($order && $order['source'] == OrderEnum::SOURCE_20) {
return true;
}
$updateData = [];
$goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray();
foreach ($goods_list as $v) {

@ -39,7 +39,7 @@ class BeforehandOrderController extends BaseAdminController
{
$params = $this->request->get();
$params['store_id'] = $this->request->adminInfo['store_id'] ?? 0;
$params['store_staff_id'] = $this->request->adminInfo['admin_id'] ?? 0;
// $params['store_staff_id'] = $this->request->adminInfo['admin_id'] ?? 0;
$this->request->setGet($params);
return $this->dataLists(new BeforehandOrderLists());
}