diff --git a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php index 51b8ccabd..25cdf8eca 100644 --- a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php +++ b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php @@ -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); + } + } \ No newline at end of file diff --git a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php index 4575398f0..bbe66e3ef 100644 --- a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php +++ b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php @@ -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 编辑采购商品 diff --git a/app/admin/lists/beforehand_order/BeforehandOrderLists.php b/app/admin/lists/beforehand_order/BeforehandOrderLists.php index fd8f380c0..a98521e58 100644 --- a/app/admin/lists/beforehand_order/BeforehandOrderLists.php +++ b/app/admin/lists/beforehand_order/BeforehandOrderLists.php @@ -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'); diff --git a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php index 59e00eb82..1667ce5ee 100644 --- a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php +++ b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php @@ -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) { diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 056c2af68..b12a578dc 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -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, ]; - WarehouseProductLogic::setOutbound($data, 1, $admin_id); + $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; diff --git a/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php index 22b456f3b..1defced89 100644 --- a/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php +++ b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php @@ -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); + } + } diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index e060de826..51e775b2c 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -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'])->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']; @@ -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 编辑采购商品 @@ -182,53 +236,53 @@ class PurchaseProductOfferLogic extends BaseLogic 'manufacture' => $params['manufacture'], 'expiration_date' => $params['expiration_date'], ]); -// $find = StoreProductPrice::where(['offer_id' => $params['id']])->find(); + // $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(); - $unit_name=StoreProductUnit::where('id', $offer['unit'])->value('name'); + $unit_name = StoreProductUnit::where('id', $offer['unit'])->value('name'); $order = BeforehandOrder::where('id', $params['bhoid'])->find(); $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); -// } + // $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; - $offer['buyer_name']=DeliveryService::where('uid',$offer['buyer_id'])->value('nickname'); - if($offer['pay_type']==1){ - $offer['pay_type_name']='赊账'; - }elseif($offer['pay_type']==2){ - $offer['pay_type_name']='现金'; - }else{ - $offer['pay_type_name']='没设置'; + $offer['store_name'] = $product['store_name']; + $offer['unit_name'] = $unit_name; + $offer['buyer_name'] = DeliveryService::where('uid', $offer['buyer_id'])->value('nickname'); + if ($offer['pay_type'] == 1) { + $offer['pay_type_name'] = '赊账'; + } elseif ($offer['pay_type'] == 2) { + $offer['pay_type_name'] = '现金'; + } else { + $offer['pay_type_name'] = '没设置'; } ProductOffer::push($offer); return true; @@ -283,19 +337,19 @@ 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=[ + $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'] != $find['cart_num']) { + $pay_price = bcmul($params['accept_num'], $find['price'], 2); + $data['pay_price'] = $pay_price; } $find->save($data); - if($params['accept_num']!=$find['cart_num']){ - $pay_price=BeforehandOrderCartInfo::where(['bhoid' => $params['bhoid']])->sum('pay_price'); + 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]); } Db::commit(); @@ -368,13 +422,13 @@ class PurchaseProductOfferLogic extends BaseLogic if (!empty($productCatePriceRate)) { $storeProductGroupPrice = StoreProductGroupPrice::where('product_id', $product['id'])->select()->toArray(); $storeProductGroupPrice = reset_index($storeProductGroupPrice, 'group_id'); - $purchase=0; + $purchase = 0; foreach ($productCatePriceRate as $k => $v) { if ($v['id'] == 100001 || $v['id'] == 21) { //供货 $data['purchase_lv'] = bcdiv($v['rate'], 100, 2); $data['purchase'] = bcmul($params['purchase'], bcadd($data['purchase_lv'], 1, 2), 2); - $purchase=$data['purchase']; + $purchase = $data['purchase']; break; } } @@ -383,12 +437,12 @@ class PurchaseProductOfferLogic extends BaseLogic if (empty($v['rate'])) { continue; } - if ($v['id'] == 4 &&$purchase>0) { + if ($v['id'] == 4 && $purchase > 0) { //商户 $data['cost_lv'] = bcdiv($v['rate'], 100, 2); $data['cost'] = bcmul($purchase, bcadd($data['cost_lv'], 1, 2), 2); continue; - }elseif (($v['id'] == 100002 || $v['id'] == 22) &&$purchase>0) { + } elseif (($v['id'] == 100002 || $v['id'] == 22) && $purchase > 0) { //零售 $data['price_lv'] = bcdiv($v['rate'], 100, 2); $data['price'] = bcmul($purchase, bcadd($data['price_lv'], 1, 2), 1); @@ -405,7 +459,7 @@ class PurchaseProductOfferLogic extends BaseLogic continue; } $baseRate = ($v['id'] == 100001 || $v['id'] == 21) ? 100 : 100 + $v['rate']; - if($purchase>0){ + if ($purchase > 0) { $item = [ 'product_id' => $product['id'], 'group_id' => $v['id'], @@ -461,5 +515,4 @@ class PurchaseProductOfferLogic extends BaseLogic } return $res; } - } diff --git a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php index b66cf1c2c..4d2ea5a4a 100644 --- a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php @@ -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()); + } + } + } diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index d068a06ab..ea046625d 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -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 ]); } diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index b835ae9fa..a576278eb 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -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) { //-----活动价结算更改 diff --git a/app/common/model/system_store/SystemStore.php b/app/common/model/system_store/SystemStore.php index f950d4e56..dc4564726 100644 --- a/app/common/model/system_store/SystemStore.php +++ b/app/common/model/system_store/SystemStore.php @@ -42,4 +42,10 @@ class SystemStore extends BaseModel Log::error('system_store:'.$e->getMessage()); } } + + public static function isActivityStore($storeId) + { + return in_array($storeId, [5]); + } + } \ No newline at end of file