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

Reviewed-on: #555
This commit is contained in:
mkm 2025-03-21 09:17:28 +08:00
commit 0863b55846
14 changed files with 605 additions and 61 deletions

View File

@ -0,0 +1,115 @@
<?php
namespace app\admin\controller;
use app\admin\controller\BaseAdminController;
use app\admin\lists\PurchaseFundsLists;
use app\admin\logic\PurchaseFundsLogic;
use app\admin\validate\PurchaseFundsValidate;
/**
* PurchaseFunds控制器
* Class PurchaseFundsController
* @package app\admin\controller
*/
class PurchaseFundsController extends BaseAdminController
{
/**
* @notes 获取列表
* @author admin
* @date 2025/03/19 14:59
*/
public function lists()
{
return $this->dataLists(new PurchaseFundsLists());
}
/**
* @notes 添加
* @author admin
* @date 2025/03/19 14:59
*/
public function add()
{
$params = (new PurchaseFundsValidate())->post()->goCheck('add');
$result = PurchaseFundsLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(PurchaseFundsLogic::getError());
}
/**
* @notes 编辑
* @author admin
* @date 2025/03/19 14:59
*/
public function edit()
{
$params = (new PurchaseFundsValidate())->post()->goCheck('edit');
$result = PurchaseFundsLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(PurchaseFundsLogic::getError());
}
/**
* @notes 删除
* @author admin
* @date 2025/03/19 14:59
*/
public function delete()
{
$params = (new PurchaseFundsValidate())->post()->goCheck('delete');
PurchaseFundsLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @author admin
* @date 2025/03/19 14:59
*/
public function detail()
{
$params = (new PurchaseFundsValidate())->goCheck('detail');
$result = PurchaseFundsLogic::detail($params);
return $this->data($result);
}
/**
* @notes 审核
* @author admin
* @date 2025/03/19 14:59
*/
public function audit()
{
$params = (new PurchaseFundsValidate())->post()->goCheck('delete');
$params['approve_uid'] = $this->adminId;
PurchaseFundsLogic::audit($params);
return $this->success('操作成功', [], 1, 1);
}
/**
* @notes 补充
* @author admin
* @date 2025/03/19 14:59
*/
public function replenish()
{
$params = (new PurchaseFundsValidate())->post()->goCheck('delete');
$params['approve_uid'] = $this->adminId;
PurchaseFundsLogic::replenish($params);
return $this->success('操作成功', [], 1, 1);
}
}

View File

@ -0,0 +1,89 @@
<?php
namespace app\admin\lists;
use app\common\model\auth\Admin;
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
use app\common\model\PurchaseFunds;
use app\common\lists\ListsSearchInterface;
use app\common\model\user\User;
/**
* PurchaseFunds列表
* Class PurchaseFundsLists
* @package app\admin\lists
*/
class PurchaseFundsLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2025/03/19 14:59
*/
public function setSearch(): array
{
return [
'=' => ['from_uid', 'approve_uid', 'status'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2025/03/19 14:59
*/
public function lists(): array
{
$query = PurchaseFunds::where($this->searchWhere);
if (!empty($this->params['approve_uid'])) {
$userIds = Admin::where('name', 'like', '%' . $this->params['approve_uid'] . '%')->column('id');
$query->whereIn('approve_uid', $userIds);
}
if (!empty($this->params['order'])) {
$query->order(['id' => 'asc']);
} else {
$query->order(['id' => 'desc']);
}
return $query
->field(['id', 'from_uid', 'approve_uid', 'amount', 'current_amount', 'supply_price', 'status', 'create_time', 'audit_time'])
->limit($this->limitOffset, $this->limitLength)
->select()
->each(function ($item) {
$item['from_name'] = User::where('id', $item['from_uid'])->value('nickname');
$item['approve_name'] = empty($item['approve_uid']) ? '' : Admin::where('id', $item['approve_uid'])->value('name');
$item['status_name'] = $item->getStatusName();
if ($item['current_amount'] < 0) {
$item['status'] = -1;
$item['status_name'] = '已超额';
}
$item['audit_time'] = empty($item['audit_time']) ? '' : date('Y-m-d H:i:s', $item['audit_time']);
$item['supply_price'] = ProductSourceLinkInfo::where('purchase_funds_id', $item['id'])->where('types', ProductSourceLinkInfo::TypeOut)->sum('total_price');
$item['current_profit'] = ProductSourceLinkInfo::where('purchase_funds_id', $item['id'])->where('types', ProductSourceLinkInfo::TypeOrder)->sum('total_price');
})
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author admin
* @date 2025/03/19 14:59
*/
public function count(): int
{
return PurchaseFunds::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,163 @@
<?php
namespace app\admin\logic;
use app\admin\logic\delivery_service\DeliveryServiceLogic;
use app\common\model\PurchaseFunds;
use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db;
/**
* PurchaseFunds逻辑
* Class PurchaseFundsLogic
* @package app\admin\logic
*/
class PurchaseFundsLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author admin
* @date 2025/03/19 14:59
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
PurchaseFunds::create([
'from_uid' => $params['from_uid'],
'amount' => $params['amount'],
]);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author admin
* @date 2025/03/19 14:59
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
PurchaseFunds::where('id', $params['id'])->update([
'from_uid' => $params['from_uid'],
'approve_uid' => $params['approve_uid'],
'amount' => $params['amount'],
'status' => $params['status'],
]);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author admin
* @date 2025/03/19 14:59
*/
public static function delete(array $params): bool
{
return PurchaseFunds::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author admin
* @date 2025/03/19 14:59
*/
public static function detail($params): array
{
return PurchaseFunds::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 审核
* @param array $params
* @return bool
* @author admin
* @date 2025/03/19 14:59
*/
public static function audit(array $params): bool
{
$purchaseFunds = PurchaseFunds::findOrEmpty($params['id']);
if ($purchaseFunds->isEmpty()) {
throw new BusinessException('数据不存在');
}
Db::startTrans();
try {
$attrs = [
'approve_uid' => $params['approve_uid'],
'status' => $params['status'],
'audit_time' => time(),
];
if ($params['status'] == 1) {
$attrs['current_amount'] = $purchaseFunds['amount'];
}
PurchaseFunds::where('id', $params['id'])->update($attrs);
if ($params['status'] == 1) {
DeliveryServiceLogic::addPurchaseFunds($purchaseFunds['from_uid'], $purchaseFunds['amount']);
}
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 补充
* @param array $params
* @return bool
* @author admin
* @date 2025/03/19 14:59
*/
public static function replenish(array $params): bool
{
$purchaseFunds = PurchaseFunds::findOrEmpty($params['id']);
if ($purchaseFunds->isEmpty()) {
throw new BusinessException('数据不存在');
}
Db::startTrans();
try {
PurchaseFunds::where('id', $params['id'])->update([
'amount' => Db::raw('amount+' . $params['replenish_amount']),
'current_amount' => Db::raw('current_amount+' . $params['replenish_amount']),
]);
DeliveryServiceLogic::addPurchaseFunds($purchaseFunds['from_uid'], $params['replenish_amount']);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
}

View File

@ -450,8 +450,9 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
$data['price'] = $data['purchase'];
$data['manufacture'] = $purchaseProductOffer['manufacture'] > 0 ? date('Y-m-d H:i:s', $purchaseProductOffer['manufacture']) : '';
$data['expiration_date'] = $purchaseProductOffer['expiration_date'] > 0 ? date('Y-m-d H:i:s', $purchaseProductOffer['expiration_date']) : '';
$data['purchase_funds_id'] = $params['purchase_funds_id'];
if ($data['nums'] > 0) {
WarehouseProductLogic::add($data, 1, $params['admin_id']);
$warehouseProduct = WarehouseProductLogic::add($data, 1, $params['admin_id']);
}
$offerUpdate = ['price' => $purchaseProductOffer['price'], 'status' => 1, 'is_storage' => 1, 'warehouse_num' => $params['warehouse_num']];
$offerResult = PurchaseProductOffer::where('id', $purchaseProductOffer['id'])->where('is_storage', 0)->update($offerUpdate);
@ -472,7 +473,7 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
$product = StoreProduct::where('id', $purchaseProductOffer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id,cate_id')->find();
if (!in_array($beforehandOrder['order_type'], [6, 9])) {
PurchaseProductOfferLogic::setProductPrice($purchaseProductOffer, $product, $params['warehouse_id']);
PurchaseProductOfferLogic::setProductPrice($purchaseProductOffer, $product, $params['warehouse_id'], $warehouseProduct->id ?? 0);
}
Db::commit();
return true;

View File

@ -96,4 +96,24 @@ class DeliveryServiceLogic extends BaseLogic
{
return DeliveryService::findOrEmpty($params['id'])->toArray();
}
public static function addPurchaseFunds($uid, $amount)
{
$model = DeliveryService::where('uid', $uid)->findOrEmpty();
if (!$model->isEmpty()) {
$model->purchase_funds_total = bcadd($model->purchase_funds_total, $amount, 2);
$model->current_purchase_funds = bcadd($model->current_purchase_funds, $amount, 2);
$model->save();
}
}
public static function subPurchaseFunds($uid, $amount)
{
$model = DeliveryService::where('uid', $uid)->findOrEmpty();
if (!$model->isEmpty()) {
$model->current_purchase_funds = bcsub($model->current_purchase_funds, $amount, 2);
$model->save();
}
}
}

View File

@ -4,6 +4,7 @@ namespace app\admin\logic\product_source_link;
use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic;
use app\admin\logic\purchase_product_offer\PurchaseProductOfferLogic;
use app\common\model\inventory_transfer\InventoryTransfer;
use app\common\model\product_source_link\ProductSourceLink;
use app\common\logic\BaseLogic;
@ -42,7 +43,7 @@ class ProductSourceLinkLogic extends BaseLogic
$model->warehouse_id = $info['warehouse_id'];
$model->save();
}
ProductSourceLinkInfoLogic::add([
$attrs = [
'oid' => $model['id'],
'product_id' => $offer['product_id'],
'warehouse_id' => $info['warehouse_id'],
@ -52,7 +53,16 @@ class ProductSourceLinkLogic extends BaseLogic
'link_id' => $info['link_id'],
'price' => $offer['price'],
'total_price' => $offer['total_price'],
]);
'purchase_funds_id' => $offer['purchase_funds_id'] ?? 0,
];
if ($attrs['types'] == ProductSourceLinkInfo::TypeIn) {
// 商品入库,记录采购总价和供货总价
$priceRate = PurchaseProductOfferLogic::getProductPriceRate(['id' => $offer['product_id']]);
$attrs['purchase_price'] = $offer['total_price'];
$rate = bcdiv($priceRate['supply_rate'], 100, 2);
$attrs['supply_price'] = bcmul(bcmul($offer['price'], $rate, 2), $offer['nums'], 2);
}
ProductSourceLinkInfoLogic::add($attrs);
}
return true;
}
@ -166,7 +176,7 @@ class ProductSourceLinkLogic extends BaseLogic
'update_time' => $time,
];
} else {
$insert[] = [
$insertItem = [
'product_id' => $item['product_id'],
'warehouse_id' => $info['warehouse_id'] ?? 0,
'store_id' => $info['store_id'] ?? 0,
@ -178,9 +188,21 @@ class ProductSourceLinkLogic extends BaseLogic
'current_nums' => $needNum,
'price' => $item['price'],
'total_price' => bcmul($item['price'], $needNum, 2),
'purchase_funds_id' => $item['purchase_funds_id'],
'create_time' => !empty($info['create_time']) ? $info['create_time'] : $time,
'update_time' => $time,
];
if ($insertItem['types'] == ProductSourceLinkInfo::TypeOut) {
// 商品出库,价格为供货价,总价为供货总价
$insertItem['price'] = bcdiv($item['supply_price'], $item['nums'], 2);
$insertItem['total_price'] = bcmul($insertItem['price'], $insertItem['nums'], 2);
} elseif ($insertItem['types'] == ProductSourceLinkInfo::TypeOrder) {
// 商品订单出库,价格为销售价,总价为销售总价
$insertItem['price'] = $info['product']['price'];
$insertItem['total_price'] = bcmul($insertItem['price'], $insertItem['nums'], 2);
$insertItem['supply_price'] = bcmul($info['product']['supply_price'], $insertItem['nums'], 2);
}
$insert[] = $insertItem;
}
return [$update, $insert];
}
@ -215,6 +237,7 @@ class ProductSourceLinkLogic extends BaseLogic
'from_id' => $item['id'],
'price' => $item['price'],
'total_price' => $item['total_price'],
'purchase_funds_id' => $item['purchase_funds_id'],
]);
}
}

View File

@ -168,6 +168,7 @@ class ProductSourceLinkInfoLogic extends BaseLogic
{
$dataNums = bcsub($data['nums'], $rollbackNum, 2);
$currentNums = max(bcsub($data['current_nums'], $rollbackNum, 2), 0);
$totalPrice = bcmul($data['price'], $dataNums, 2);
$update[] = [
'id' => $data['id'],
'nums' => $dataNums,
@ -176,10 +177,26 @@ class ProductSourceLinkInfoLogic extends BaseLogic
'delete_time' => $dataNums > 0 ? null : time(),
];
if ($data['from_id'] > 0) {
$update[] = [
'id' => $data['from_id'],
'current_nums' => Db::raw("current_nums+{$rollbackNum}"),
];
if ($data['types'] == ProductSourceLinkInfo::TypeStoreIn) {
// 门店入库数量发起退库,更新出库单的数量和价格,更新入库单的可分配数量
$outboundLinkInfoId = ProductSourceLinkInfo::where('id', $data['from_id'])->value('from_id');
$update[] = [
'id' => $data['from_id'],
'nums' => Db::raw("nums-{$rollbackNum}"),
'current_nums' => Db::raw("current_nums-{$rollbackNum}"),
'total_price' => Db::raw("total_price-{$totalPrice}"),
];
$update[] = [
'id' => $outboundLinkInfoId,
'current_nums' => Db::raw("current_nums+{$rollbackNum}"),
];
} else {
// 更新来源单的可分配数量
$update[] = [
'id' => $data['from_id'],
'current_nums' => Db::raw("current_nums+{$rollbackNum}"),
];
}
}
return $update;
}

View File

@ -384,12 +384,14 @@ class PurchaseProductOfferLogic extends BaseLogic
* 设置商品价格
* @param $params
* @param $product
* @param $warehouseId
* @param $warehouseProductId
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function setProductPrice($params, $product, $warehouseId = 0)
public static function setProductPrice($params, $product, $warehouseId = 0, $warehouseProductId = 0)
{
$priceConfig = [];
$data = [
@ -401,6 +403,7 @@ class PurchaseProductOfferLogic extends BaseLogic
'update_time' => time(),
'status' => 0,
'warehouse_id' => $warehouseId,
'warehouse_product_id' => $warehouseProductId,
];
$productPriceRate = self::getProductPriceRate($product);
if (!empty($productPriceRate)) {
@ -423,8 +426,8 @@ class PurchaseProductOfferLogic extends BaseLogic
if (empty($list)) {
$list = [
'supply_rate' => 110,
'merchant_rate' => 106,
'vip_rate' => 110,
'merchant_rate' => 103,
'vip_rate' => 115,
'price_rate' => 120,
];
}

View File

@ -4,6 +4,7 @@ namespace app\admin\logic\store_product_price;
use app\admin\service\ProductPriceService;
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
use app\common\model\store_product_group_price\StoreProductGroupPrice;
use app\common\model\store_product_price\StoreProductPrice;
use app\common\logic\BaseLogic;
@ -58,51 +59,41 @@ class StoreProductPriceLogic extends BaseLogic
{
Db::startTrans();
try {
$postData = $params;
$find = StoreProductPrice::where('id', $params['id'])->find();
if ($find) {
$changePurchase = false;
$productPriceListAttrs = [];
if ($find['purchase_lv'] != $params['purchase_lv']) {
$params = self::updateProductPriceList2($find['product_id'], 'supply_rate', $params['purchase_lv'], $params, 'purchase', $find['purchase_price']);
$changePurchase = true;
}
if ($changePurchase) {
$params['cost'] = bcmul($params['purchase'], $params['cost_lv'], 2);
$params['vip_price'] = bcmul($params['purchase'], $params['vip_lv'], 2);
$params['price'] = bcmul($params['purchase'], $params['price_lv'], 2);
$productPriceListAttrs['supply_rate'] = $params['purchase_lv'] * 100;
}
if ($find['cost_lv'] != $params['cost_lv']) {
$params = self::updateProductPriceList2($find['product_id'], 'merchant_rate', $params['cost_lv'], $params, 'cost', $params['purchase']);
$productPriceListAttrs['merchant_rate'] = $params['cost_lv'] * 100;
}
if ($find['vip_lv'] != $params['vip_lv']) {
$params = self::updateProductPriceList2($find['product_id'], 'vip_rate', $params['vip_lv'], $params, 'vip_price', $params['purchase']);
$productPriceListAttrs['vip_rate'] = $params['vip_lv'] * 100;
}
if ($find['price_lv'] != $params['price_lv']) {
$params = self::updateProductPriceList2($find['product_id'], 'price_rate', $params['price_lv'], $params, 'price', $params['purchase']);
$productPriceListAttrs['price_rate'] = $params['price_lv'] * 100;
}
if (!empty($productPriceListAttrs)) {
$id = StoreProductPriceList::where('product_id', $find['product_id'])->value('id');
if (empty($id)) {
$productPriceListAttrs = array_merge($productPriceListAttrs, ['product_id' => $find['product_id']]);
StoreProductPriceList::create($productPriceListAttrs);
} else {
StoreProductPriceList::where('id', $id)->update($productPriceListAttrs);
}
}
$params['supply_rate'] = bcmul($params['purchase_lv'], 100);
$params['merchant_rate'] = bcmul($params['cost_lv'], 100);
$params['vip_rate'] = bcmul($params['vip_lv'], 100);
$params['price_rate'] = bcmul($params['price_lv'], 100);
$productService = new ProductPriceService();
$priceArray = $productService->setProductPrice($find['purchase_price'], $params);
// 计算出的价格与提交价格不同时,以提交价格为准
$priceArray['purchase'] = $postData['purchase'] != $priceArray['pxurchase'] ? $postData['purchase'] : $priceArray['purchase'];
$priceArray['cost'] = $postData['cost'] != $priceArray['cost'] ? $postData['cost'] : $priceArray['cost'];
$priceArray['vip_price'] = $postData['vip_price'] != $priceArray['vip_price'] ? $postData['vip_price'] : $priceArray['vip_price'];
$priceArray['price'] = $postData['price'] != $priceArray['price'] ? $postData['price'] : $priceArray['price'];
$find->save([
'status' => 1,
'purchase' => $priceArray['purchase'],
'purchase_lv' => $priceArray['purchase_lv'],
'cost' => $priceArray['cost'],
'cost_lv' => $priceArray['cost_lv'],
'vip_price' => $priceArray['vip_price'],
'vip_lv' => $priceArray['vip_lv'],
'price' => $priceArray['price'],
'price_lv' => $priceArray['price_lv'],
'purchase' => $params['purchase'],
'purchase_lv' => $params['purchase_lv'],
'cost' => $params['cost'],
'cost_lv' => $params['cost_lv'],
'vip_price' => $params['vip_price'],
'vip_lv' => $params['vip_lv'],
'price' => $params['price'],
'price_lv' => $params['price_lv'],
'price_config' => $params['price_config'],
]);
StoreProduct::where('id', $find['product_id'])->update([
@ -119,6 +110,15 @@ class StoreProductPriceLogic extends BaseLogic
'price' => $find['vip_price'],
'ot_price' => $find['price']
]);
$productSourceLinkInfo = ProductSourceLinkInfo::where('product_id', $find['product_id'])
->where('link_id', $find['warehouse_product_id'])
->where('types', ProductSourceLinkInfo::TypeIn)
->find();
if (!empty($productSourceLinkInfo)) {
ProductSourceLinkInfo::where('id', $productSourceLinkInfo['id'])->update(['supply_price' => bcmul($find['purchase'], $productSourceLinkInfo['nums'], 2)]);
}
}
Db::commit();
return true;
@ -128,7 +128,7 @@ class StoreProductPriceLogic extends BaseLogic
}
}
public static function updateProductPriceList2($productId, $field, $rate, $params, $index, $basePrice)
public static function updateProductPriceList2($productId, $field, $rate)
{
$id = StoreProductPriceList::where('product_id', $productId)->value('id');
if (empty($id)) {
@ -139,8 +139,6 @@ class StoreProductPriceLogic extends BaseLogic
} else {
StoreProductPriceList::where('id', $id)->update([$field => $rate * 100]);
}
$params[$index] = bcmul($basePrice, $rate, 2);
return $params;
}
public static function updateProductPriceList($productId, $priceType, $rate, $params, $field, $basePrice)

View File

@ -173,6 +173,9 @@ class WarehouseOrderLogic extends BaseLogic
* @date 2024/08/20 10:50
*/
public static function update_edit($data){
if (!empty($data['create_time'])) {
$data['create_time'] = strtotime($data['create_time']);
}
$res=WarehouseOrder::update($data);
if($res){
return true;

View File

@ -2,12 +2,14 @@
namespace app\admin\logic\warehouse_product;
use app\admin\logic\delivery_service\DeliveryServiceLogic;
use app\admin\logic\product_source_link\ProductSourceLinkLogic;
use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic;
use app\admin\logic\store_branch_product\StoreBranchProductLogic;
use app\admin\logic\store_product\StoreProductLogic;
use app\common\model\beforehand_order\BeforehandOrder;
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
use app\common\model\PurchaseFunds;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\logic\BaseLogic;
use app\common\model\purchase_product_offer\PurchaseProductOffer;
@ -118,6 +120,10 @@ class WarehouseProductLogic extends BaseLogic
$res = WarehouseProduct::create($data);
SqlChannelLog('WarehouseProduct', $res['id'], $params['nums'], $params['financial_pm'] == 1 ? 1 : -1, Request()->url(),$admin_id);
if (!empty($params['purchase_funds_id'])) {
PurchaseFunds::where('id', $params['purchase_funds_id'])->dec('current_amount', $params['total_price'])->save();
}
ProductSourceLinkLogic::add([
'purchase_product_offer' => [$params],
'types' => ProductSourceLinkInfo::TypeIn,
@ -125,6 +131,7 @@ class WarehouseProductLogic extends BaseLogic
'warehouse_id' => $params['warehouse_id'],
'link_id' => $res['id'],
]);
DeliveryServiceLogic::subPurchaseFunds($params['buyer_id'], $params['total_price']);
return $res;
} catch (\Throwable $e) {
throw new BusinessException($e->getMessage());
@ -142,20 +149,6 @@ class WarehouseProductLogic extends BaseLogic
if ($params['order_type'] != 6) {
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
if ($storege) {
// if (($params['store_id'] == 3 && in_array($params['order_type'], [1, 2, 3, 4, 8])) || in_array($params['order_type'], [1, 4])) {
// SystemStoreStorage::create([
// 'store_id' => $params['store_id'],
// 'admin_id' => $params['admin_id'],
// 'order_type' => $params['order_type'],
// 'staff_id' => 0,
// 'type' => 1,
// 'product_id' => $params['product_id'],
// 'nums' => $params['nums'],
// 'outbound_id' => $params['oid'] ?? 0,
// 'warehouse_id' =>1,
// 'status' => 0
// ]);
// }
$after_nums = bcsub($storege['nums'], $params['nums']);
$total_price = bcmul($after_nums, $params['purchase'], 2);
WarehouseProductStorege::update(['nums' => bcsub($storege['nums'], $params['nums']), 'total_price' => $total_price], ['id' => $storege['id']]);

View File

@ -0,0 +1,82 @@
<?php
namespace app\admin\validate;
use app\common\validate\BaseValidate;
/**
* PurchaseFunds验证器
* Class PurchaseFundsValidate
* @package app\admin\validate
*/
class PurchaseFundsValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
];
/**
* @notes 添加场景
* @return PurchaseFundsValidate
* @author admin
* @date 2025/03/19 14:59
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @return PurchaseFundsValidate
* @author admin
* @date 2025/03/19 14:59
*/
public function sceneEdit()
{
return $this->only(['id']);
}
/**
* @notes 删除场景
* @return PurchaseFundsValidate
* @author admin
* @date 2025/03/19 14:59
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return PurchaseFundsValidate
* @author admin
* @date 2025/03/19 14:59
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -645,6 +645,8 @@ class PayNotifyLogic extends BaseLogic
'product' => [
'product_id' => $v['product_id'],
'nums' => $v['cart_num'],
'price' => $branchProduct['price'],
'supply_price' => $branchProduct['purchase'],
],
'is_store_order' => true,
'store_id' => $v['store_id'],

View File

@ -0,0 +1,35 @@
<?php
namespace app\common\model;
use app\common\model\BaseModel;
/**
* PurchaseFunds模型
* Class PurchaseFunds
* @package app\common\model
*/
class PurchaseFunds extends BaseModel
{
protected $name = 'purchase_funds';
const StatusWait = 0; //待审核
const StatusApproved = 1; //审核通过
const StatusRejected = 2; //审核拒绝
public function getStatusName()
{
if ($this->status == self::StatusWait) {
return '待审核';
} else if ($this->status == self::StatusApproved) {
return '通过';
} else {
return '拒绝';
}
}
}