commit
f810a002a4
@ -77,5 +77,12 @@ class StoreFinanceFlowController extends BaseAdminController
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$file_path = StoreFinanceFlowLogic::export($params);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -46,7 +46,7 @@ class StoreCashFinanceFlowLists extends BaseAdminDataLists implements ListsSearc
|
||||
public function lists(): array
|
||||
{
|
||||
return StoreCashFinanceFlow::where($this->searchWhere)
|
||||
->field(['id', 'store_id', 'cash_price', 'receivable', 'receipts', 'admin_id', 'file', 'remark', 'create_time', 'status'])
|
||||
->field(['id', 'store_id', 'cash_price', 'receivable', 'receipts', 'admin_id', 'file', 'remark', 'create_time', 'status','type'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
@ -55,6 +55,10 @@ class StoreCashFinanceFlowLists extends BaseAdminDataLists implements ListsSearc
|
||||
if ($item->admin_id > 0) {
|
||||
$item->admin_name = Admin::where('id', $item->admin_id)->value('name');
|
||||
}
|
||||
if($item->type==1){
|
||||
$item->cash_price='-'. $item->cash_price;
|
||||
$item->receivable='-'. $item->receivable;
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class StoreProductPriceLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
$this->searchWhere[]=['product_id','in',$store_id];
|
||||
}
|
||||
return StoreProductPrice::where($this->searchWhere)
|
||||
->field(['id','bhoid','offer_id', 'product_id', 'purchase_price', 'purchase_lv', 'purchase', 'cost_lv', 'cost', 'price_lv', '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'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($item){
|
||||
|
@ -15,6 +15,7 @@ use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_group_price\StoreProductGroupPrice;
|
||||
use app\common\model\store_product_price\StoreProductPrice;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\StoreProductPriceList;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\workWechat\ProductOffer;
|
||||
use support\exception\BusinessException;
|
||||
@ -378,6 +379,15 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
return PurchaseProductOffer::destroy($params['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置商品分组价格
|
||||
* @param $params
|
||||
* @param $product
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function setProductGroupPrice($params, $product)
|
||||
{
|
||||
$priceConfig = [];
|
||||
@ -390,62 +400,34 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
'update_time' => time(),
|
||||
'status' => 0,
|
||||
];
|
||||
$productCatePriceRate = self::getProductCatePriceRate($product);
|
||||
if (!empty($productCatePriceRate)) {
|
||||
$storeProductGroupPrice = StoreProductGroupPrice::where('product_id', $product['id'])->select()->toArray();
|
||||
$storeProductGroupPrice = reset_index($storeProductGroupPrice, 'group_id');
|
||||
$productPriceRate = self::getProductPriceRate($product);
|
||||
if (!empty($productPriceRate)) {
|
||||
$purchase = 0;
|
||||
foreach ($productCatePriceRate as $k => $v) {
|
||||
if ($v['id'] == 100001 || $v['id'] == 21) {
|
||||
//供货
|
||||
foreach ($productPriceRate as $v) {
|
||||
if ($v['price_type'] == StoreProductPriceList::PriceTypeSupply) {
|
||||
$data['purchase_lv'] = bcdiv($v['rate'], 100, 2);
|
||||
$data['purchase'] = bcmul($params['purchase'], bcadd($data['purchase_lv'], 1, 2), 2);
|
||||
$data['purchase'] = bcmul($params['purchase'], $data['purchase_lv'], 2);
|
||||
$purchase = $data['purchase'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!empty($purchase)) {
|
||||
foreach ($productCatePriceRate as $k => $v) {
|
||||
if (empty($v['rate'])) {
|
||||
foreach ($productPriceRate as $v) {
|
||||
if (empty($v['rate']) || $purchase <= 0) {
|
||||
continue;
|
||||
}
|
||||
if ($v['id'] == 4 && $purchase > 0) {
|
||||
//商户
|
||||
if ($v['price_type'] == StoreProductPriceList::PriceTypeBusiness) {
|
||||
//商户价
|
||||
$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) {
|
||||
//零售
|
||||
$data['cost'] = bcmul($purchase, $data['cost_lv'], 2);
|
||||
} elseif ($v['price_type'] == StoreProductPriceList::PriceTypeRetail) {
|
||||
//零售价
|
||||
$data['price_lv'] = bcdiv($v['rate'], 100, 2);
|
||||
$data['price'] = bcmul($purchase, bcadd($data['price_lv'], 1, 2), 1);
|
||||
if ($product['two_cate_id'] == 15268) {
|
||||
$lastNum = substr($data['price'], -1);
|
||||
if ($lastNum <= 2) {
|
||||
$data['price'] = floor($data['price']);
|
||||
} elseif ($lastNum < 5) {
|
||||
$data['price'] = bcadd(floor($data['price']), 0.5, 1);
|
||||
} else {
|
||||
$data['price'] = bcadd(floor($data['price']), 1, 1);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$baseRate = ($v['id'] == 100001 || $v['id'] == 21) ? 100 : 100 + $v['rate'];
|
||||
if ($purchase > 0) {
|
||||
$item = [
|
||||
'product_id' => $product['id'],
|
||||
'group_id' => $v['id'],
|
||||
'group_name' => $v['title'],
|
||||
'price' => bcmul($purchase, $baseRate / 100, 2),
|
||||
'price_type' => 3,
|
||||
'base_rate' => $baseRate,
|
||||
];
|
||||
if (isset($storeProductGroupPrice[$v['id']])) {
|
||||
$item['base_rate'] = $storeProductGroupPrice[$v['id']]['base_rate'];
|
||||
$item['price'] = bcmul($purchase, $item['base_rate'] / 100, 2);
|
||||
$item['id'] = $storeProductGroupPrice[$v['id']]['id'];
|
||||
}
|
||||
$priceConfig[] = $item;
|
||||
$data['price'] = bcmul($purchase, $data['price_lv'], 2);
|
||||
} elseif ($v['price_type'] == StoreProductPriceList::PriceTypeVip) {
|
||||
//会员价
|
||||
$data['vip_lv'] = bcdiv($v['rate'], 100, 2);
|
||||
$data['vip_price'] = bcmul($purchase, $data['vip_lv'], 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -459,6 +441,17 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
public static function getProductPriceRate($product)
|
||||
{
|
||||
return StoreProductPriceList::where('product_id', $product['id'])->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
* 获取商品分类价格比例
|
||||
* @param $product
|
||||
* @return array|mixed
|
||||
*/
|
||||
public static function getProductCatePriceRate($product)
|
||||
{
|
||||
$productCatePriceRate = StoreCategory::where('id', $product['cate_id'])->value('price_rate');
|
||||
@ -476,6 +469,11 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
* @param array $productCatePriceRate
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasPurchase(array $productCatePriceRate): bool
|
||||
{
|
||||
$res = true;
|
||||
|
@ -3,8 +3,14 @@
|
||||
namespace app\admin\logic\store_finance_flow;
|
||||
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\system_store\SystemStoreStaff;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\xlsx\StoreFinanceFlowXlsx;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
@ -90,4 +96,59 @@ class StoreFinanceFlowLogic extends BaseLogic
|
||||
{
|
||||
return StoreFinanceFlow::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
public static function export($params)
|
||||
{
|
||||
$query = StoreFinanceFlow::where('financial_pm', 1);
|
||||
if (!empty($params['type'])) {
|
||||
if ($params['type'] == OrderEnum::ORDER_HANDLING_FEES || $params['type'] == OrderEnum::OTHER_ORDER_OBTAINS) {
|
||||
$query->where('financial_type', $params['type']);
|
||||
} elseif ($params['type'] == 11) {
|
||||
$query->whereIn('financial_type', [OrderEnum::ORDER_MARGIN, OrderEnum::MERCHANT_ORDER_OBTAINS]);
|
||||
} else {
|
||||
$query->whereIn('financial_type', [OrderEnum::VIP_ORDER_OBTAINS, OrderEnum::VILLAGE_ORDER_OBTAINS, OrderEnum::BRIGADE_ORDER_OBTAINS]);
|
||||
}
|
||||
}
|
||||
if (!empty($params['store_id'])) {
|
||||
$query->where('store_id', $params['store_id']);
|
||||
}
|
||||
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']));
|
||||
}
|
||||
if (!empty($params['user_id'])) {
|
||||
$query->where('user_id', $params['user_id']);
|
||||
}
|
||||
if (!empty($params['order_sn'])) {
|
||||
$query->where('order_sn', 'like', "%{$params['order_sn']}%");
|
||||
}
|
||||
$data = $query->order('id desc')->select()->toArray();
|
||||
$users = User::field('id,nickname,real_name')->whereIn('id', array_unique(array_column($data, 'user_id')))->select()->toArray();
|
||||
$users = reset_index($users, 'id');
|
||||
$stores = SystemStore::field('id,name')->whereIn('id', array_unique(array_column($data, 'store_id')))->select()->toArray();
|
||||
$stores = reset_index($stores, 'id');
|
||||
foreach ($data as &$item) {
|
||||
$user = $users[$item['user_id']] ?? [];
|
||||
if ($item['user_id'] <= 0 || empty($user)) {
|
||||
$item['nickname'] = '游客';
|
||||
} else {
|
||||
$item['nickname'] = $user['real_name']!=''?$user['real_name']:$user['nickname'].'|'.$item['user_id'];
|
||||
}
|
||||
$item['number'] = '+' . $item['number'];
|
||||
$store = $stores[$item['store_id']] ?? [];
|
||||
$item['store_name'] = $store['name'] ?? '';
|
||||
}
|
||||
if ($params['type'] == 3) {
|
||||
$title = '手续费';
|
||||
} elseif ($params['type'] == 11) {
|
||||
$title = '其他收益';
|
||||
} elseif ($params['type'] == 16) {
|
||||
$title = '损耗';
|
||||
} else {
|
||||
$title = '佣金';
|
||||
}
|
||||
return (new StoreFinanceFlowXlsx())->export($data, $title, '');
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ use app\common\model\store_product_price\StoreProductPrice;
|
||||
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 support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
@ -56,26 +57,50 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
try {
|
||||
$find = StoreProductPrice::where('id', $params['id'])->find();
|
||||
if ($find) {
|
||||
$changePurchase = false;
|
||||
if ($find['purchase_lv'] != $params['purchase_lv']) {
|
||||
$params = self::updateProductPriceList($find['product_id'], StoreProductPriceList::PriceTypeSupply, $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);
|
||||
}
|
||||
if ($find['cost_lv'] != $params['cost_lv']) {
|
||||
$params = self::updateProductPriceList($find['product_id'], StoreProductPriceList::PriceTypeBusiness, $params['cost_lv'], $params, 'cost', $params['purchase']);
|
||||
}
|
||||
if ($find['vip_lv'] != $params['vip_lv']) {
|
||||
$params = self::updateProductPriceList($find['product_id'], StoreProductPriceList::PriceTypeVip, $params['vip_lv'], $params, 'vip_price', $params['purchase']);
|
||||
}
|
||||
if ($find['price_lv'] != $params['price_lv']) {
|
||||
$params = self::updateProductPriceList($find['product_id'], StoreProductPriceList::PriceTypeRetail, $params['price_lv'], $params, 'price', $params['purchase']);
|
||||
}
|
||||
$find->save([
|
||||
'status' => 1,
|
||||
'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([
|
||||
'purchase' => $find['purchase'],
|
||||
'cost' => $find['cost'],
|
||||
'vip_price' => $find['cost'],
|
||||
'vip_price' => $find['vip_price'],
|
||||
'price' => $find['price']
|
||||
]);
|
||||
StoreBranchProduct::where('product_id', $find['product_id'])->update([
|
||||
'purchase' => $find['purchase'],
|
||||
'cost' => $find['cost'],
|
||||
'vip_price' => $find['cost'],
|
||||
'vip_price' => $find['vip_price'],
|
||||
'price' => $find['price']
|
||||
]);
|
||||
self::setProductGroupPrice($find);
|
||||
// self::setProductGroupPrice($find);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
@ -84,6 +109,23 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateProductPriceList($productId, $priceType, $rate, $params, $field, $basePrice)
|
||||
{
|
||||
$id = StoreProductPriceList::where('product_id', $productId)->where('price_type', $priceType)->value('id');
|
||||
if (empty($id)) {
|
||||
StoreProductPriceList::create([
|
||||
'product_id' => $productId,
|
||||
'price_type' => $priceType,
|
||||
'rate' => $rate * 100,
|
||||
]);
|
||||
} else {
|
||||
StoreProductPriceList::where('id', $id)->update(['rate' => $rate * 100]);
|
||||
}
|
||||
$params[$field] = bcmul($basePrice, $rate, 2);
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 确认改价
|
||||
* @param array $params
|
||||
@ -103,16 +145,16 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
StoreProduct::where('id', $find['product_id'])->update([
|
||||
'purchase' => $find['purchase'] ?? 0,
|
||||
'cost' => $find['cost'] ?? 0,
|
||||
'vip_price' => $find['cost'] ?? 0,
|
||||
'vip_price' => $find['vip_price'] ?? 0,
|
||||
'price' => $find['price'] ?? 0
|
||||
]);
|
||||
StoreBranchProduct::where('product_id', $find['product_id'])->update([
|
||||
'purchase' => $find['purchase'] ?? 0,
|
||||
'cost' => $find['cost'] ?? 0,
|
||||
'vip_price' => $find['cost'] ?? 0,
|
||||
'vip_price' => $find['vip_price'] ?? 0,
|
||||
'price' => $find['price'] ?? 0
|
||||
]);
|
||||
self::setProductGroupPrice($find);
|
||||
// self::setProductGroupPrice($find);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
|
30
app/common/model/StoreProductPriceList.php
Normal file
30
app/common/model/StoreProductPriceList.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* StoreProductPriceList模型
|
||||
* Class StoreProductPriceList
|
||||
* @package app\common\model
|
||||
*/
|
||||
class StoreProductPriceList extends BaseModel
|
||||
{
|
||||
|
||||
use SoftDelete;
|
||||
protected $name = 'store_product_price_list';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
const PriceTypeSupply = 1;
|
||||
const PriceTypeBusiness = 2;
|
||||
const PriceTypeVip = 3;
|
||||
const PriceTypeRetail = 4;
|
||||
const TypeMap = [
|
||||
self::PriceTypeSupply => '供货价',
|
||||
self::PriceTypeBusiness => '商户价',
|
||||
self::PriceTypeVip => '会员价',
|
||||
self::PriceTypeRetail => '零售价',
|
||||
];
|
||||
|
||||
}
|
65
app/common/service/xlsx/StoreFinanceFlowXlsx.php
Normal file
65
app/common/service/xlsx/StoreFinanceFlowXlsx.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?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 StoreFinanceFlowXlsx
|
||||
{
|
||||
public function export($data, $type)
|
||||
{
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->setCellValue('A1', '交易单号');
|
||||
$sheet->setCellValue('B1', '交易时间');
|
||||
$sheet->setCellValue('C1', '金额');
|
||||
$sheet->setCellValue('D1', '门店');
|
||||
$sheet->setCellValue('E1', '用户');
|
||||
$sheet->setCellValue('F1', '流水类型');
|
||||
|
||||
// 设置默认的单元格样式
|
||||
$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['order_sn']);
|
||||
$sheet->setCellValue("B$column", $item['create_time']);
|
||||
$sheet->setCellValue("C$column", $item['number']);
|
||||
$sheet->setCellValue("D$column", $item['store_name']);
|
||||
$sheet->setCellValue("E$column", $item['nickname']);
|
||||
$sheet->setCellValue("F$column", $type);
|
||||
$column++;
|
||||
}
|
||||
|
||||
// 定义线框样式
|
||||
$styleArray = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => Border::BORDER_THIN, // 线框样式
|
||||
'color' => ['argb' => '000000'], // 线框颜色
|
||||
],
|
||||
],
|
||||
];
|
||||
$sheet->getStyle('A1:F' . $column)->applyFromArray($styleArray);
|
||||
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$url = '/export/' . "门店财务流水 - $type " . 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;
|
||||
}
|
||||
|
||||
}
|
@ -23,6 +23,7 @@ use app\common\model\auth\AdminJobs;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\common\model\auth\AdminSession;
|
||||
use app\common\cache\AdminTokenCache;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\system_store\SystemStoreStaff;
|
||||
use app\common\service\FileService;
|
||||
use support\exception\BusinessException;
|
||||
@ -229,7 +230,7 @@ class AdminLogic extends BaseLogic
|
||||
if ($action == 'detail') {
|
||||
return $admin;
|
||||
}
|
||||
|
||||
$admin['is_operated'] =SystemStore::where('id',$admin['store_id'])->value('is_operated');
|
||||
$result['user'] = $admin;
|
||||
// 当前管理员角色拥有的菜单
|
||||
$result['menu'] = MenuLogic::getMenuByAdminId($params['id']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user