门店入库记录添加退库操作,采购单添加追加商品,调整商品改价列表
This commit is contained in:
parent
681f31153f
commit
45418d5f55
@ -5,6 +5,7 @@ namespace app\admin\controller\store_product_price;
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\store_product_price\StoreProductPriceLists;
|
||||
use app\admin\logic\store_finance_flow\StoreFinanceFlowLogic;
|
||||
use app\admin\logic\store_product_price\StoreProductPriceLogic;
|
||||
use app\admin\validate\store_product_price\StoreProductPriceValidate;
|
||||
|
||||
@ -100,5 +101,11 @@ class StoreProductPriceController extends BaseAdminController
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$file_path = StoreProductPriceLogic::export($params);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
|
||||
}
|
@ -106,4 +106,11 @@ class SystemStoreStorageController extends BaseAdminController
|
||||
return $this->success('操作成功',[]);
|
||||
}
|
||||
|
||||
public function rollback()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
SystemStoreStorageLogic::rollback($params);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\store_product_price\StoreProductPrice;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\warehouse\Warehouse;
|
||||
|
||||
/**
|
||||
* 商品价格更改列表
|
||||
@ -47,12 +48,19 @@ class StoreProductPriceLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
$store_id=StoreProduct::where('store_name','like','%'.$store_name.'%')->column('id');
|
||||
$this->searchWhere[]=['product_id','in',$store_id];
|
||||
}
|
||||
if (!empty($this->params['start_time'])) {
|
||||
$this->searchWhere[] = ['create_time', '>=', strtotime($this->params['start_time'])];
|
||||
}
|
||||
if (!empty($this->params['end_time'])) {
|
||||
$this->searchWhere[] = ['create_time', '<=', strtotime($this->params['end_time'])];
|
||||
}
|
||||
return StoreProductPrice::where($this->searchWhere)
|
||||
->field(['id','bhoid','offer_id', 'product_id', 'purchase_price', 'purchase_lv', 'purchase', 'cost_lv', 'cost', 'price_lv', 'price', 'vip_lv', 'vip_price', 'price_config', 'status','create_time','mark'])
|
||||
->field(['id','bhoid','offer_id', 'product_id', 'purchase_price', 'purchase_lv', 'purchase', 'cost_lv', 'cost', 'price_lv', 'price', 'vip_lv', 'vip_price', 'price_config', 'status','create_time','mark', 'warehouse_id'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($item){
|
||||
$find = StoreProduct::with('unitName')->where('id', $item['product_id'])->field('image,purchase,cost,price,store_name,store_info,unit')->withTrashed()->find();
|
||||
$item['warehouse'] = Warehouse::where('id', $item['warehouse_id'])->value('name');
|
||||
$item['unit_name']=$find['unitName']['name'] ?? '';
|
||||
$item['store_name']=$find['store_name'];
|
||||
$item['store_info']=$find['store_info'];
|
||||
|
@ -65,7 +65,7 @@ class StoreWarehouseProductLists extends BaseAdminDataLists implements ListsSear
|
||||
$this->searchWhere[] = ['financial_pm', '=',0];
|
||||
$this->searchWhere[] = ['order_type', 'in',[1, 2, 3, 4, 8]];
|
||||
return WarehouseProduct::where($this->searchWhere)
|
||||
->field(['id', 'admin_id', 'store_id','product_id', 'nums', 'status', 'mark', 'create_time',])
|
||||
->field(['id', 'admin_id', 'store_id','product_id', 'nums', 'refund_nums', 'status', 'mark', 'create_time',])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
// ->withTrashed()
|
||||
|
@ -71,6 +71,8 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
|
||||
$datas = [];
|
||||
$uid = $params['uid'] ?? 0;
|
||||
$bhoid = $params['id'];
|
||||
$offer = [];
|
||||
$buyerId = PurchaseProductOffer::where('order_id', $order['id'])->value('buyer_id');
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$datas[$k]['product_id'] = $v['id'];
|
||||
$datas[$k]['uid'] = $uid;
|
||||
@ -82,8 +84,28 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
|
||||
$datas[$k]['pay_price'] = $v['total_price'];
|
||||
$datas[$k]['create_time'] = time();
|
||||
$datas[$k]['update_time'] = time();
|
||||
$offer[] = [
|
||||
'order_id' => $order['id'],
|
||||
'product_id' => $v['id'],
|
||||
'is_buyer' => 1,
|
||||
'need_num' => $v['nums'],
|
||||
'unit' => $v['unit'],
|
||||
'buyer_id' => $buyerId,
|
||||
'status' => 0,
|
||||
'source_order_info' => [
|
||||
[
|
||||
'source_order_id' => $order['id'],
|
||||
'product_id' => $v['id'],
|
||||
'need_num' => $v['nums'],
|
||||
'mark' => '',
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
(new BeforehandOrderCartInfo())->saveAll($datas);
|
||||
if ($order['order_type'] == 7) {
|
||||
PurchaseProductOffer::insertAll($offer);
|
||||
}
|
||||
|
||||
$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();
|
||||
BeforehandOrder::where('id', $bhoid)->update(['total_price' => $info['total_price'],'pay_price'=>$info['pay_price'], 'total_num' => $info['cart_num']]);
|
||||
@ -436,7 +458,7 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
|
||||
$purchaseProductOffer['purchase']=$purchaseProductOffer['price'];
|
||||
$product = StoreProduct::where('id', $purchaseProductOffer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id,cate_id')->find();
|
||||
|
||||
PurchaseProductOfferLogic::setProductGroupPrice($purchaseProductOffer, $product);
|
||||
PurchaseProductOfferLogic::setProductGroupPrice($purchaseProductOffer, $product, $params['warehouse_id']);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
|
@ -388,7 +388,7 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function setProductGroupPrice($params, $product)
|
||||
public static function setProductGroupPrice($params, $product, $warehouseId = 0)
|
||||
{
|
||||
$priceConfig = [];
|
||||
$data = [
|
||||
@ -399,6 +399,7 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
'status' => 0,
|
||||
'warehouse_id' => $warehouseId,
|
||||
];
|
||||
$productPriceRate = self::getProductPriceRate($product);
|
||||
if (!empty($productPriceRate)) {
|
||||
|
@ -9,6 +9,8 @@ use app\common\logic\BaseLogic;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\StoreProductPriceList;
|
||||
use app\common\model\warehouse\Warehouse;
|
||||
use app\common\service\xlsx\StoreProductPriceXlsx;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
@ -213,4 +215,32 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
(new StoreProductGroupPrice())->saveAll($insertData);
|
||||
}
|
||||
|
||||
public static function export($params)
|
||||
{
|
||||
$query = StoreProductPrice::field('*');
|
||||
if (!empty($params['store_name'])) {
|
||||
$productIds = StoreProduct::where('store_name', 'like', "%{$params['store_name']}%")->column('id');
|
||||
$query->whereIn('product_id', $productIds);
|
||||
}
|
||||
if ($params['status'] != '') {
|
||||
$query->where('status', $params['status']);
|
||||
}
|
||||
if (!empty($params['start_time'])) {
|
||||
$query->where('create_time', '>=', strtotime($params['start_time']));
|
||||
}
|
||||
if (!empty($params['end_time'])) {
|
||||
$query->where('create_time', '<=', strtotime($params['end_time']));
|
||||
}
|
||||
$data = $query->order('id desc')->select()->toArray();
|
||||
$warehouses = Warehouse::field('id,name')->whereIn('id', array_unique(array_column($data, 'warehouse_id')))->select()->toArray();
|
||||
$warehouses = reset_index($warehouses, 'id');
|
||||
$products = StoreProduct::field('id,store_name')->whereIn('id', array_unique(array_column($data, 'product_id')))->select()->toArray();
|
||||
$products = reset_index($products, 'id');
|
||||
foreach ($data as &$item) {
|
||||
$item['warehouse'] = $warehouses[$item['warehouse_id']]['name'] ?? '';
|
||||
$item['store_name'] = $products[$item['product_id']]['store_name'] ?? '';
|
||||
}
|
||||
return (new StoreProductPriceXlsx())->export($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -167,4 +167,41 @@ class SystemStoreStorageLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
public static function rollback($params)
|
||||
{
|
||||
$warehouseProduct = WarehouseProduct::where('id', $params['id'])->find();
|
||||
if (empty($warehouseProduct)) {
|
||||
throw new BusinessException('数据不存在');
|
||||
}
|
||||
if ($warehouseProduct['status'] != 1) {
|
||||
throw new BusinessException('当前状态不能退库');
|
||||
}
|
||||
if ($params['num'] + $warehouseProduct['refund_nums'] > $warehouseProduct['nums']) {
|
||||
throw new BusinessException('数量不足');
|
||||
}
|
||||
$StoreProduct = StoreBranchProduct::where('store_id', $warehouseProduct['store_id'])->where('product_id', $warehouseProduct['product_id'])->find();
|
||||
if (empty($StoreProduct)) {
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
$warehouseStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])->where('product_id', $warehouseProduct['product_id'])->find();
|
||||
if (empty($warehouseStorage)) {
|
||||
throw new BusinessException('仓库没有此商品');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$StoreProduct->stock -= $params['num'];
|
||||
$StoreProduct->save();
|
||||
$warehouseProduct->refund_nums += $params['num'];
|
||||
$warehouseProduct->save();
|
||||
$warehouseStorage->nums += $params['num'];
|
||||
$warehouseStorage->save();
|
||||
SqlChannelLog('StoreBranchProduct', $warehouseProduct['id'], $warehouseProduct['nums'], 1,Request()->url());
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,11 +15,13 @@ use think\model\concern\SoftDelete;
|
||||
class StoreProductPrice extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
|
||||
protected $name = 'store_product_price';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
protected $json = ['price_config'];
|
||||
protected $jsonAssoc = true;
|
||||
// 不生成该表的日志
|
||||
public $doNotRecordLog = true;
|
||||
// 不生成该表的日志
|
||||
public $doNotRecordLog = true;
|
||||
|
||||
}
|
78
app/common/service/xlsx/StoreProductPriceXlsx.php
Normal file
78
app/common/service/xlsx/StoreProductPriceXlsx.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service\xlsx;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
|
||||
class StoreProductPriceXlsx
|
||||
{
|
||||
|
||||
public function export($data)
|
||||
{
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->setCellValue('A1', '商品ID');
|
||||
$sheet->setCellValue('B1', '商品');
|
||||
$sheet->setCellValue('C1', '采购价');
|
||||
$sheet->setCellValue('D1', '供货价比例');
|
||||
$sheet->setCellValue('E1', '供货价');
|
||||
$sheet->setCellValue('F1', '商户价比例');
|
||||
$sheet->setCellValue('G1', '商户价');
|
||||
$sheet->setCellValue('H1', '会员价比例');
|
||||
$sheet->setCellValue('I1', '会员价');
|
||||
$sheet->setCellValue('J1', '零售价比例');
|
||||
$sheet->setCellValue('K1', '零售价');
|
||||
$sheet->setCellValue('L1', '时间');
|
||||
|
||||
// 设置默认的单元格样式
|
||||
$defaultStyle = [
|
||||
'alignment' => [
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
'vertical' => Alignment::VERTICAL_CENTER,
|
||||
],
|
||||
];
|
||||
// 应用默认样式到整个工作表
|
||||
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
|
||||
|
||||
$column = 2;
|
||||
foreach ($data as $k => $item) {
|
||||
$sheet->setCellValue("A$column", $item['product_id']);
|
||||
$sheet->setCellValue("B$column", $item['store_name']);
|
||||
$sheet->setCellValue("C$column", $item['purchase_price']);
|
||||
$sheet->setCellValue("D$column", $item['purchase_lv']);
|
||||
$sheet->setCellValue("E$column", $item['purchase']);
|
||||
$sheet->setCellValue("F$column", $item['cost_lv']);
|
||||
$sheet->setCellValue("I$column", $item['cost']);
|
||||
$sheet->setCellValue("J$column", $item['vip_lv']);
|
||||
$sheet->setCellValue("G$column", $item['vip_price']);
|
||||
$sheet->setCellValue("H$column", $item['price_lv']);
|
||||
$sheet->setCellValue("K$column", $item['price']);
|
||||
$sheet->setCellValue("L$column", $item['create_time']);
|
||||
$column++;
|
||||
}
|
||||
|
||||
// 定义线框样式
|
||||
$styleArray = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => Border::BORDER_THIN, // 线框样式
|
||||
'color' => ['argb' => '000000'], // 线框颜色
|
||||
],
|
||||
],
|
||||
];
|
||||
$sheet->getStyle('A1:L' . $column)->applyFromArray($styleArray);
|
||||
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$url = '/export/' . "商品价格更改列表 " . date('YmdHi') . '.xlsx';
|
||||
$file_path = public_path() . $url;
|
||||
if (!is_dir(dirname($file_path))) {
|
||||
mkdir(dirname($file_path), 0777, true);
|
||||
}
|
||||
$writer->save($file_path);
|
||||
return getenv('APP_URL') . $url;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user