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

Reviewed-on: #457
This commit is contained in:
mkm 2025-01-11 17:03:45 +08:00
commit 174ef18861
19 changed files with 599 additions and 143 deletions

View File

@ -93,6 +93,8 @@ class StoreBranchProductController extends BaseAdminController
*/
public function edit_stock()
{
$params = $this->request->post();
StoreBranchProductLogic::stock($params);
return $this->success('编辑成功', [], 1, 1);
}
/**

View File

@ -10,6 +10,7 @@ use app\admin\logic\store_order\StoreOrderLogic;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\admin\validate\store_order\StoreOrderValidate;
use app\api\logic\order\OrderLogic;
use app\common\enum\PayEnum;
use app\common\logic\PayNotifyLogic;
use app\common\model\delivery_service\DeliveryService;
@ -133,13 +134,31 @@ class StoreOrderController extends BaseAdminController
return $this->fail('无该订单请检查');
}
$params['id'] = $detail['id'];
if (empty($params['product_arr'])) {
$params['old_cart_id'] = StoreOrderCartInfo::where('oid', $detail['id'])->where('status', '<>', 2)->column('id');
if (!isset($params['product_arr'])) {
$params['product_arr'] = StoreOrderCartInfo::where('oid', $detail['id'])->where('status', '<>', 2)->field('product_id,cart_num')->select()->toArray();
}
$refundOrderService->refund($detail['uid'], $params);
return $this->success('退款成功',[],1,1);
}
/**
* 核销
*/
public function writeoff_order()
{
$params =$this->request->post();
if (empty($params['verify_code'])) {
return $this->fail('核销码不存在');
}
if (empty($params['store_id'])) {
return $this->fail('门店id不存在');
}
$params['staff_id']=0;
$res = OrderLogic::writeOff($params);
if ($res) {
return $this->success('核销成功',[],1,1);
}
return $this->fail('核销失败');
}
/**
* 设置配送员
*/

View File

@ -12,6 +12,7 @@ use app\common\model\system_store\SystemStore;
use app\common\lists\ListsExcelInterface;
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
use app\common\model\store_order\StoreOrder;
use app\common\model\system_store\SystemStoreStaff;
use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct;
@ -33,7 +34,7 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
public function setSearch(): array
{
return [
'=' => ['store_id', 'paid', 'status', 'order_type', 'admin_id'],
'=' => ['store_id', 'paid', 'status', 'order_type', 'admin_id', 'store_staff_id'],
'%like' => ['order_id','order_sn'],
'%like%' => ['mark'],
'between_time' => 'create_time'
@ -81,8 +82,9 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
$oid=WarehouseOrder::where('financial_pm',0)->where('code','like','%'.$order_ck)->column('id');
$this->searchWhere[] = ['outbound_id','in',$oid];
}
$file=['id','uid', 'order_id', 'order_sn','store_id', 'order_type', 'total_num', 'total_price', 'outbound_id', 'admin_id', 'create_time', 'status', 'mark', 'warehousing_id', 'file','other_data', 'audit_status'];
return BeforehandOrder::where($this->searchWhere)
$file=['id','uid', 'order_id', 'order_sn','store_id', 'order_type', 'total_num', 'total_price', 'outbound_id', 'admin_id', 'create_time', 'status', 'mark', 'warehousing_id', 'file','other_data', 'audit_status', 'store_staff_id'];
$query = BeforehandOrder::where($this->searchWhere);
return $query
->field($file)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
@ -94,6 +96,9 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
} else {
$item->admin_name = '';
}
if ($item->store_staff_id) {
$item->admin_name = SystemStoreStaff::where(['id' => $item->store_staff_id])->value('staff_name');
}
if ($item->order_type == 1) {
$item->order_type_name = '铺货订单';
} elseif ($item->order_type == 2) {

View File

@ -82,8 +82,12 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
if ($where) {
$this->searchWhere[] = $where;
}
return StoreBranchProduct::where($this->searchWhere)
->field(['id', 'store_id', 'product_id', 'image', 'store_name', 'store_info', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'purchase', 'status', 'batch', 'vip_price','bar_code', 'manufacturer_information','total_price'])
$query = StoreBranchProduct::where($this->searchWhere);
if (isset($this->params['low_stock']) && $this->params['low_stock'] == 1) {
$query->where('stock', '<=', 'low_stock');
}
return $query
->field(['id', 'store_id', 'product_id', 'image', 'store_name', 'store_info', 'cate_id', 'price', 'sales', 'stock', 'low_stock', 'unit', 'cost', 'purchase', 'status', 'batch', 'vip_price','bar_code', 'manufacturer_information','total_price'])
->when(!empty($this->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->adminInfo['store_id']);
})
@ -111,7 +115,11 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
*/
public function count(): int
{
return StoreBranchProduct::where($this->searchWhere)
$query = StoreBranchProduct::where($this->searchWhere);
if (isset($this->params['low_stock']) && $this->params['low_stock'] == 1) {
$query->where('stock', '<=', 'low_stock');
}
return $query
->when(!empty($this->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->adminInfo['store_id']);
})

View File

@ -112,6 +112,7 @@ class BeforehandOrderLogic extends BaseLogic
$order = BeforehandOrder::create([
'order_id' => getNewOrderId('YG'),
'admin_id' => $params['admin_id'] ?? 0,
'store_staff_id' => $params['store_staff_id'] ?? 0,
'store_id' => $params['store_id'] ?? 0,
'uid' => $uid,
'total_num' => $total_num,
@ -570,6 +571,7 @@ class BeforehandOrderLogic extends BaseLogic
'order_type' => 4,
'deduction_price' => 0,
'paid' => 0,
'audit_status' => 1,
'mark' => $params['mark'] ?? '',
'other_data' => json_encode($other_data, true)
@ -956,10 +958,10 @@ class BeforehandOrderLogic extends BaseLogic
{
$where = [];
$where2 = [];
if($params['store_id']>0){
if ($params['store_id'] > 0) {
$where2[] = ['store_id', '=', $params['store_id']];
}
if($params['start_time']!=''&& $params['end_time']!=''){
if ($params['start_time'] != '' && $params['end_time'] != '') {
$where2[] = ['create_time', 'between', [strtotime($params['start_time']), strtotime($params['end_time'])]];
}
if ($params['warehouse_type'] > 0) {
@ -984,22 +986,25 @@ class BeforehandOrderLogic extends BaseLogic
$orderCounts = BeforehandOrder::where('order_type', 'in', [1, 2, 3, 4, 5, 7, 8])
->where($where2)
->group('order_type')
->field([Db::raw('count(*) as count'),'order_type'])->select();
->field([Db::raw('count(*) as count'), 'order_type'])->select();
if ($params['order_type'] > 0) {
$where2[] = ['order_type', '=', $params['order_type']];
}
$outbound_0 = BeforehandOrder::where([['is_outbound', '=', 0], ['order_type', '<>', 5]])->where($where2)->count();
$outbound_1 = BeforehandOrder::where([['is_outbound', '=', 1]])->where($where2)->count();
$warehousing_0 = BeforehandOrder::where([['is_warehousing', '=', 0]])->where($where2)->count();
$warehousing_1 = BeforehandOrder::where([['is_warehousing', '=', 1]])->where($where2)->count();
$data=[
'order_type_1' =>0,
'order_type_2'=>0,
'order_type_3'=>0,
'order_type_4'=>0,
'order_type_5'=>0,
'order_type_7'=>0,
'order_type_8'=>0
$data = [
'order_type_1' => 0,
'order_type_2' => 0,
'order_type_3' => 0,
'order_type_4' => 0,
'order_type_5' => 0,
'order_type_7' => 0,
'order_type_8' => 0
];
foreach ($orderCounts as $k => $v) {
$data['order_type'.'_'.$v['order_type']] =$v['count'] ;
$data['order_type' . '_' . $v['order_type']] = $v['count'];
}
$data['outbound_0'] = $outbound_0;
$data['outbound_1'] = $outbound_1;

View File

@ -6,6 +6,7 @@ use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\common\model\inventory_transfer\InventoryTransfer;
use app\common\logic\BaseLogic;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use support\exception\BusinessException;
use think\facade\Db;
@ -29,75 +30,84 @@ class InventoryTransferLogic extends BaseLogic
*/
public static function add(array $params,$admin_id=0): bool
{
$one_before_nums = 0;
$one_after_nums = 0;
$two_before_nums = 0;
$two_after_nums = 0;
if($params['one_type']==1){
$stock = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['one_id'])->value('stock');
if ($stock < $params['nums']) {
throw new BusinessException('调拨数量不能大于当前门店库存');
if (empty($params['product_arr'])) {
throw new BusinessException('请选择商品');
}
$productIds = array_column($params['product_arr'], 'product_id');
if ($params['one_type'] == 1) {
$outProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $params['one_id'])->field('id,product_id,stock')->select()->toArray();
} else {
$outProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $params['one_id'])->field('id,product_id,nums stock')->select()->toArray();
}
$outProducts = reset_index($outProducts, 'product_id');
if ($params['two_type'] == 1) {
$inProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $params['two_id'])->field('id,product_id,stock')->select()->toArray();
} else {
$inProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $params['two_id'])->field('id,product_id,nums stock')->select()->toArray();
}
$inProducts = reset_index($inProducts, 'product_id');
$insert = [];
foreach ($params['product_arr'] as $v) {
$outProduct = !empty($outProducts[$v['product_id']]) ? $outProducts[$v['product_id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['product_id']];
$inProduct = !empty($inProducts[$v['product_id']]) ? $inProducts[$v['product_id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['product_id']];
if ($outProduct['stock'] < $v['nums']) {
throw new BusinessException("出库商品 {$outProduct['product_id']} 调拨数量不能大于当前仓库库存");
}
if($params['two_type']==1){
$stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock');
}elseif($params['two_type']==2){
$stock_two = WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['two_id'])->value('nums');
}
$one_before_nums = $stock;
$one_after_nums = bcsub($stock, $params['nums']);
$two_before_nums = $stock_two;
$two_after_nums = bcadd($stock_two, $params['nums']);
}elseif($params['one_type']==2){
$stock = WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['one_id'])->value('nums');
if ($stock < $params['nums']) {
throw new BusinessException('调拨数量不能大于当前仓库库存');
}
if($params['two_type']==1){
$stock_two = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->value('stock');
}elseif($params['two_type']==2){
$stock_two = WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['two_id'])->value('nums');
}
$one_before_nums = $stock;
$one_after_nums = bcsub($stock, $params['nums']);
$two_before_nums = $stock_two;
$two_after_nums = bcadd($stock_two, $params['nums']);
}else{
throw new BusinessException('调拨类型错误');
$insert[] = [
'product_id' => $v['product_id'],
'nums' => $v['nums'],
'one_before_nums' => $outProduct['stock'],
'one_after_nums' => bcsub($outProduct['stock'], $v['nums']),
'two_before_nums' => $inProduct['stock'],
'two_after_nums' => bcadd($inProduct['stock'], $v['nums']),
'one_type' => $params['one_type'],
'two_type' => $params['two_type'],
'one_id' => $params['one_id'],
'two_id' => $params['two_id'],
'create_time' => time(),
];
}
Db::startTrans();
try {
InventoryTransfer::create([
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'one_before_nums' => $one_before_nums,
'one_after_nums' => $one_after_nums,
'two_before_nums' => $two_before_nums,
'two_after_nums' => $two_after_nums,
'one_type' => $params['one_type'],
'two_type' => $params['two_type'],
'one_id' => $params['one_id'],
'two_id' => $params['two_id']
]);
if($params['one_type']==1){
$find=StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['one_id'])->find();
$find->save(['stock' =>bcsub( $find['stock'],$params['nums'],2)]);
SqlChannelLog('StoreBranchProduct', $find['id'], $params['nums'], -1, Request()->url(),$admin_id);
} elseif ($params['one_type'] == 2) {
$find=WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['one_id'])->find();
$find->save(['nums' =>bcsub( $find['nums'],$params['nums'],2)]);
SqlChannelLog('WarehouseProductStorege', $find['id'], $params['nums'], -1, Request()->url(),$admin_id);
}
if($params['two_type']==1){
$find=StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->find();
$find->save(['stock' =>bcadd( $find['stock'],$params['nums'],2)]);
SqlChannelLog('StoreBranchProduct', $find['id'], $params['nums'], 1, Request()->url(),$admin_id);
} elseif ($params['two_type'] == 2) {
$find=WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['two_id'])->find();
$find->save(['nums' =>bcadd( $find['nums'],$params['nums'],2)]);
SqlChannelLog('WarehouseProductStorege', $find['id'], $params['nums'], 1, Request()->url(),$admin_id);
InventoryTransfer::insertAll($insert);
foreach ($insert as $v) {
if($params['one_type']==1){
$find=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $params['one_id'])->find();
$find->save(['stock' =>bcsub( $find['stock'],$v['nums'],2)]);
SqlChannelLog('StoreBranchProduct', $find['id'], $v['nums'], -1, Request()->url(),$admin_id);
} elseif ($params['one_type'] == 2) {
$find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id', $params['one_id'])->find();
$find->save(['nums' =>bcsub( $find['nums'],$v['nums'],2)]);
SqlChannelLog('WarehouseProductStorege', $find['id'], $v['nums'], -1, Request()->url(),$admin_id);
}
if($params['two_type']==1){
$find=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $params['two_id'])->find();
if (empty($find)) {
$storeProduct = StoreProduct::field('top_cate_id,two_cate_id,cate_id,store_name,image,price,vip_price,cost,purchase,keyword,bar_code,store_info,rose,product_type,unit,batch,store_batch,label_id,is_lack,manufacturer_information')->where('id', $v['product_id'])->find()->toArray();
$find = new StoreBranchProduct();
$find->product_id = $v['product_id'];
$find->store_id = $params['two_id'];
$find->stock = $v['nums'];
$find->setAttrs($storeProduct);
$find->save();
} else {
$find->save(['stock' =>bcadd( $find['stock'],$v['nums'],2)]);
}
SqlChannelLog('StoreBranchProduct', $find['id'], $v['nums'], 1, Request()->url(),$admin_id);
} elseif ($params['two_type'] == 2) {
$find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id', $params['two_id'])->find();
if (empty($find)) {
$find = new WarehouseProductStorege();
$find->warehouse_id = $params['two_id'];
$find->product_id = $v['product_id'];
$find->nums = $v['nums'];
$find->save();
} else {
$find->save(['nums' =>bcadd( $find['nums'],$v['nums'],2)]);
}
SqlChannelLog('WarehouseProductStorege', $find['id'], $v['nums'], 1, Request()->url(),$admin_id);
}
}
Db::commit();
return true;

View File

@ -67,7 +67,7 @@ class StoreBranchProductLogic extends BaseLogic
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException('商品编辑失败:',$e->getMessage());
throw new BusinessException('商品编辑失败:', $e->getMessage());
}
}
/**
@ -77,29 +77,13 @@ class StoreBranchProductLogic extends BaseLogic
* @author admin
* @date 2024/06/07 13:56
*/
public static function stock(array $params, $type = 1,$admin_id=0): bool
public static function stock(array $params, $type = 1, $admin_id = 0): bool
{
Db::startTrans();
try {
$find = StoreProduct::where('id', $params['product_id'])->find()->toArray();
$storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find()->toArray();
if ($type == 1) {
$stock = bcadd($find['stock'], $params['nums'], 2);
$branchStock = bcadd($storeBranchProduct['stock'], $params['nums'], 2);
StoreBranchProduct::update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)],['id'=> $params['id']]);
SqlChannelLog('StoreBranchProduct', $params['id'], $params['nums'], 1, Request()->url(),$admin_id);
StoreProduct::update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)],['id'=> $params['product_id']]);
} else {
$branchStock = bcsub($storeBranchProduct['stock'], $params['nums'], 2);
$stock = bcsub($find['stock'], $params['nums'], 2);
StoreBranchProduct::where('id', $params['id'])->update(['stock' => $branchStock, 'total_price' => bcmul($branchStock, $find['purchase'], 2)],['id'=>$params['id']]);
SqlChannelLog('StoreBranchProduct', $params['id'], $params['nums'], -1, Request()->url(),$admin_id);
StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)],['id'=>$params['product_id']]);
}
StoreBranchProduct::update(['stock' => $params['stock'], 'total_price' => bcmul($params['stock'], $storeBranchProduct['purchase'], 2)], ['id' => $params['id']]);
SqlChannelLog('StoreBranchProduct', $params['id'], $params['stock'], 0, Request()->url(), $admin_id);
Db::commit();
return true;
} catch (\Throwable $e) {

View File

@ -237,10 +237,19 @@ class StoreProductLogic extends BaseLogic
$rose=bcmul($price_div, 100, 2);
}
$data['rose']=$rose;
StoreProduct::update($data, ['id' => $params['id']]);
$find=StoreProduct::where(['id' => $params['id']])->find();
if($find['purchase']!=$params['purchase']){
SqlChannelPriceLog($params['id'],21,$find['purchase'],$params['purchase'],);
}
if($find['cost']!=$params['cost']){
SqlChannelPriceLog($params['id'],4,$find['cost'],$params['cost'],);
}
if($find['price']!=$params['price']){
SqlChannelPriceLog($params['id'],22,$find['price'],$params['price'],);
}
$find->save($data);
// 修改活动专区商品
(new ActivityZoneLogic())->updateProduct($params['id'], $data);
// $dealCate = self::dealChangeCate($params['cate_id']);
//修改
StoreBranchProduct::where('product_id', $params['id'])->whereNotIn('store_id', [17, 18])->update([
@ -268,6 +277,7 @@ class StoreProductLogic extends BaseLogic
return true;
} catch (\Throwable $e) {
Db::rollback();
d($e);
throw new BusinessException('编辑商品失败' . $e->getMessage());
}
}

View File

@ -20,8 +20,6 @@ class InventoryTransferValidate extends BaseValidate
*/
protected $rule = [
'id' => 'require',
'product_id' => 'require',
'nums' => 'require',
'type' => 'require',
'one_id' => 'require',
'two_id' => 'require',
@ -34,8 +32,6 @@ class InventoryTransferValidate extends BaseValidate
*/
protected $field = [
'id' => 'id',
'product_id' => '商品',
'nums' => '数量',
'type' => '1商户2仓库',
'one_id' => '转出id',
'two_id' => '转入id',
@ -50,7 +46,7 @@ class InventoryTransferValidate extends BaseValidate
*/
public function sceneAdd()
{
return $this->only(['product_id','nums','one_id','two_id']);
return $this->only(['one_id','two_id']);
}
@ -62,7 +58,7 @@ class InventoryTransferValidate extends BaseValidate
*/
public function sceneEdit()
{
return $this->only(['id','product_id','nums','type','one_id','two_id']);
return $this->only(['id','type','one_id','two_id']);
}

View File

@ -0,0 +1,20 @@
<?php
namespace app\common\logic;
use app\common\model\change_price_log\ChangePriceLog;
class ChangePriceLogLogic extends BaseLogic
{
public function insert($product_id=0, $group_id=0, $before_price=0,$after_price=0):void
{
ChangePriceLog::create([
'product_id' => $product_id,
'group_id' => $group_id,
'before_price' => $before_price,
'after_price' => $after_price,
'create_time' => time()
]);
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace app\common\model\change_price_log;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 价格变更记录模型
* Class ChangePriceLog
* @package app\common\model\change_price_log
*/
class ChangePriceLog extends BaseModel
{
use SoftDelete;
protected $name = 'change_price_log';
protected $deleteTime = 'delete_time';
// 不生成该表的日志
public $doNotRecordLog = true;
}

View File

@ -36,14 +36,12 @@ class RefundOrderService
throw new BusinessException('订单不能退款');
}
$orderCartInfoWhere = ['oid' => $order['id']];
$refundNum = 0;
if (!empty($params['old_cart_id'])) {
$orderCartInfoWhere['id'] = $params['old_cart_id'];
$refundNum = count($params['old_cart_id']);
}
if (!empty($params['product_arr'])) {
$orderCartInfoWhere['product_id'] = array_column($params['product_arr'], 'product_id');
$refundNum = count($params['product_arr']);
}
if (!empty($params['old_cart_id'])) {
$orderCartInfoWhere['id'] = $params['old_cart_id'];
$params['product_arr'] = StoreOrderCartInfo::field('product_id,cart_num')->where($orderCartInfoWhere)->select()->toArray();
}
$orderCartProducts = StoreOrderCartInfo::where($orderCartInfoWhere)->select();
if (isset($params['refund_price'])) {
@ -62,7 +60,7 @@ class RefundOrderService
$this->refundMoney($order, $refundAmount);
$this->updateProductStock($orderCartProducts, $productInfo);
$this->updateOrderCartInfo($order, $orderCartProducts, $refundAmount, $productInfo);
$this->updateOrderStatus($order, $refundAmount, $refundNum);
$this->updateOrderStatus($order, $refundAmount);
$this->resetStoreFinanceFlow($order, $orderCartProducts, $productInfo);
// if ($order->status == 2 && $order->is_writeoff == 1) {
// $this->financeSettle($order);
@ -83,7 +81,8 @@ class RefundOrderService
{
$amount = '0.00';
foreach ($orderCartProducts as $orderCartProduct) {
$amount = bcadd($amount, $orderCartProduct['total_price'], 2);
$totalAmount = bcsub($orderCartProduct['total_price'], $orderCartProduct['refund_amount'], 2);
$amount = bcadd($amount, $totalAmount, 2);
}
return $amount;
}
@ -114,6 +113,8 @@ class RefundOrderService
continue;
}
$number = $productInfo[$product['product_id']]['cart_num'];
$maxNumber = bcsub($product['cart_num'], $product['refund_num'], 2);
$number = min($number, $maxNumber);
$storeBranchProductId = StoreBranchProduct::where('store_id', $product['store_id'])
->where('product_id', $product['product_id'])
->withTrashed()->value('id');
@ -131,7 +132,8 @@ class RefundOrderService
/**
* 更新订单商品状态
* @param $order
* @param $orderCartIds
* @param $orderCartProducts
* @param $refundAmount
* @param $productInfo
* @return void
* @throws DbException
@ -176,14 +178,13 @@ class RefundOrderService
* 更新订单状态
* @param $order
* @param $refundAmount
* @param $refundNum
* @return void
* @throws DbException
*/
public function updateOrderStatus($order, $refundAmount, $refundNum): void
public function updateOrderStatus($order, $refundAmount): void
{
$order->refund_price = bcadd($order['refund_price'], $refundAmount, 2);
$order->refund_num += $refundNum;
$order->refund_num = StoreOrderCartInfo::where('oid', $order['id'])->where('refund_num', '>', 0)->count();
if ($order->pay_price == $order->refund_price) {
// 全部退款完成,订单状态改为已退款
$order->refund_status = OrderEnum::REFUND_STATUS_FINISH;
@ -223,7 +224,7 @@ class RefundOrderService
}
}
$productIds = array_unique(array_column($storeOrderProducts->toArray(), 'product_id'));
StoreFinanceFlowProduct::where('oid', $order['id'])->whereIn('product_id', $productIds)->update(['number' => 0, 'update_time' => strtotime(time())]);
StoreFinanceFlowProduct::where('oid', $order['id'])->whereIn('product_id', $productIds)->update(['number' => 0, 'update_time' => time()]);
$village_uid = StoreFinanceFlow::where('order_id', $order['id'])->where('financial_type', 14)->value('other_uid');
$brigade_uid = StoreFinanceFlow::where('order_id', $order['id'])->where('financial_type', 15)->value('other_uid');
$transaction_id = StoreFinanceFlow::where('order_id', $order['id'])->value('transaction_id');

View File

@ -5,6 +5,7 @@
*/
use app\common\logic\ChangeLogLogic;
use app\common\logic\ChangePriceLogLogic;
use app\common\service\FileService;
use support\Log;
@ -559,6 +560,16 @@ function SqlChannelLog($model='', $id=0, $nums=0,$pm=0,$url='',$admin_id=0):void
{
(new ChangeLogLogic())->insert($model, $id, $nums, $pm, $url,$admin_id);
}
/**
* 价格日志记录
* @param model 模型
* @param id 更新的模型组件id
* @param nums 更新的数量
*/
function SqlChannelPriceLog($product_id=0, $group_id=0, $before_price=0,$after_price=0):void
{
(new ChangePriceLogLogic())->insert($product_id, $group_id, $before_price, $after_price);
}
// if (!function_exists('getNewOrderSn')) {
// /**

View File

@ -39,7 +39,7 @@ class BeforehandOrderController extends BaseAdminController
{
$params = $this->request->get();
$params['store_id'] = $this->request->adminInfo['store_id'] ?? 0;
$params['admin_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());
}
@ -63,7 +63,7 @@ class BeforehandOrderController extends BaseAdminController
public function add()
{
$params = $this->request->post();
$params['admin_id'] = $this->adminId;
$params['store_staff_id'] = $this->adminId;
$params['store_id'] = $this->request->adminInfo['store_id'] ?? 0;
$other_data = [
'nickname' => $params['nickname'] ?? '',

View File

@ -0,0 +1,95 @@
<?php
namespace app\store\controller\change_price_log;
use app\store\lists\change_price_log\ChangePriceLogLists;
use app\store\logic\change_price_log\ChangePriceLogLogic;
use app\store\validate\change_price_log\ChangePriceLogValidate;
use app\store\controller\BaseAdminController;
/**
* 价格变更记录控制器
* Class ChangePriceLogController
* @package app\store\controller\change_price_log
*/
class ChangePriceLogController extends BaseAdminController
{
/**
* @notes 获取价格变更记录列表
* @return \think\response\Json
* @author admin
* @date 2025/01/10 15:54
*/
public function lists()
{
return $this->dataLists(new ChangePriceLogLists());
}
/**
* @notes 添加价格变更记录
* @return \think\response\Json
* @author admin
* @date 2025/01/10 15:54
*/
public function add()
{
$params = (new ChangePriceLogValidate())->post()->goCheck('add');
$result = ChangePriceLogLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ChangePriceLogLogic::getError());
}
/**
* @notes 编辑价格变更记录
* @return \think\response\Json
* @author admin
* @date 2025/01/10 15:54
*/
public function edit()
{
$params = (new ChangePriceLogValidate())->post()->goCheck('edit');
$result = ChangePriceLogLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ChangePriceLogLogic::getError());
}
/**
* @notes 删除价格变更记录
* @return \think\response\Json
* @author admin
* @date 2025/01/10 15:54
*/
public function delete()
{
$params = (new ChangePriceLogValidate())->post()->goCheck('delete');
ChangePriceLogLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取价格变更记录详情
* @return \think\response\Json
* @author admin
* @date 2025/01/10 15:54
*/
public function detail()
{
$params = (new ChangePriceLogValidate())->goCheck('detail');
$result = ChangePriceLogLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,84 @@
<?php
namespace app\store\lists\change_price_log;
use app\common\lists\BaseDataLists;
use app\common\model\change_price_log\ChangePriceLog;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_product\StoreProduct;
use app\common\model\user_ship\UserShip;
/**
* 价格变更记录列表
* Class ChangePriceLogLists
* @package app\store\listschange_price_log
*/
class ChangePriceLogLists extends BaseDataLists implements ListsSearchInterface
{
public $ids;
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2025/01/10 15:54
*/
public function setSearch(): array
{
return [
'=' => ['product_id', 'group_id', 'before_price', 'after_price'],
];
}
/**
* @notes 获取价格变更记录列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2025/01/10 15:54
*/
public function lists(): array
{
if ($this->request->get('store_name')) {
$store_name = $this->request->get('store_name');
$ids = StoreProduct::where('store_name', 'like', '%' . $store_name . '%')->where('status', 1)->column('id');
if ($ids) {
$this->searchWhere[] = ['product_id', 'in', $ids];
$this->ids = $ids;
} else {
return [];
}
}
return ChangePriceLog::where($this->searchWhere)
->field(['id', 'product_id', 'group_id', 'before_price', 'after_price','create_time'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
$store_name= StoreProduct::where('id', $item['product_id'])->value('store_name');
$item->store_name = $store_name;
$item->group_name=UserShip::where('id',$item['group_id'])->value('title');
})
->toArray();
}
/**
* @notes 获取价格变更记录数量
* @return int
* @author admin
* @date 2025/01/10 15:54
*/
public function count(): int
{
if ($this->request->get('store_name')) {
if ($this->ids <= 0) {
return 0;
}
}
return ChangePriceLog::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,99 @@
<?php
namespace app\store\logic\change_price_log;
use app\common\model\change_price_log\ChangePriceLog;
use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db;
/**
* 价格变更记录逻辑
* Class ChangePriceLogLogic
* @package app\store\logic\change_price_log
*/
class ChangePriceLogLogic extends BaseLogic
{
/**
* @notes 添加价格变更记录
* @param array $params
* @return bool
* @author admin
* @date 2025/01/10 15:54
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ChangePriceLog::create([
'product_id' => $params['product_id'],
'group_id' => $params['group_id'],
'before_price' => $params['before_price'],
'after_price' => $params['after_price']
]);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 编辑价格变更记录
* @param array $params
* @return bool
* @author admin
* @date 2025/01/10 15:54
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ChangePriceLog::where('id', $params['id'])->update([
'product_id' => $params['product_id'],
'group_id' => $params['group_id'],
'before_price' => $params['before_price'],
'after_price' => $params['after_price']
]);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 删除价格变更记录
* @param array $params
* @return bool
* @author admin
* @date 2025/01/10 15:54
*/
public static function delete(array $params): bool
{
return ChangePriceLog::destroy($params['id']);
}
/**
* @notes 获取价格变更记录详情
* @param $params
* @return array
* @author admin
* @date 2025/01/10 15:54
*/
public static function detail($params): array
{
return ChangePriceLog::findOrEmpty($params['id'])->toArray();
}
}

View File

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

View File

@ -138,22 +138,24 @@ class Task
*/
public function setPurchase()
{
$list = WarehouseProduct::where('purchase', 0)->order('id desc')->limit(100)->select()->toArray();
$productIds = array_unique(array_column($list, 'product_id'));
$products = StoreProduct::whereIn('id', $productIds)->field('id,purchase')->select()->toArray();
$products = reset_index($products, 'id');
$update = [];
foreach ($list as $item) {
$product = $products[$item['product_id']] ?? [];
if (empty($product) || empty($product['purchase'])) {
continue;
new Crontab('0 0 * * * *', function () {
$list = WarehouseProduct::where('purchase', 0)->order('id desc')->limit(100)->select()->toArray();
$productIds = array_unique(array_column($list, 'product_id'));
$products = StoreProduct::whereIn('id', $productIds)->field('id,purchase')->select()->toArray();
$products = reset_index($products, 'id');
$update = [];
foreach ($list as $item) {
$product = $products[$item['product_id']] ?? [];
if (empty($product) || empty($product['purchase'])) {
continue;
}
$update[] = [
'id' => $item['id'],
'purchase' => min($product['purchase'], $item['price']),
];
}
$update[] = [
'id' => $item['id'],
'purchase' => min($product['purchase'], $item['price']),
];
}
(new WarehouseProduct())->saveAll($update);
(new WarehouseProduct())->saveAll($update);
});
}
}