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

Reviewed-on: #376
This commit is contained in:
mkm 2024-12-10 14:38:38 +08:00
commit c2d3a81a77
6 changed files with 226 additions and 5 deletions

View File

@ -17,6 +17,7 @@ namespace app\admin\controller;
use app\admin\lists\statistics\StoreProductLists;
use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupLists;
use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupMonthLists;
use app\admin\lists\warehouse_product_storege\WarehouseProductStoregeTwoLists;
use app\admin\logic\statistic\ProductStatisticLogic;
use app\admin\logic\statistic\TradeStatisticLogic;
use app\admin\logic\statistic\UserStatisticLogic;
@ -322,6 +323,9 @@ class WorkbenchController extends BaseAdminController
public function negative_inventory()
{
$parmas = $this->request->get();
if($parmas['type'] == 3){
return $this->dataLists(new WarehouseProductStoregeTwoLists());
}
$data = WarehouseLogic::negativeInventory($parmas);
return $this->data($data);
}

View File

@ -64,10 +64,14 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
}
}
$is_warehouse=$this->request->get('is_warehouse',0);
$userShip = 0;
if (!empty($this->params['user_id'])) {
$userShip = User::where('id', $this->params['user_id'])->value('user_ship');
}
$list = StoreProduct::where($this->searchWhere)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) use($is_warehouse) {
->select()->each(function ($item) use($is_warehouse, $userShip) {
$item['product_id'] = $item['id'];
$item['bar_code_two'] = '';
if (in_array($item['unit'], [2, 21])) {
@ -111,10 +115,12 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
$nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
$item['stock'] = bcadd($nums, $stock);
}
if ($userShip == 4) {
$item['price'] = $item['cost'];
}
return $item;
})?->toArray();
if (!empty($this->params['user_id'])) {
$userShip = User::where('id', $this->params['user_id'])->value('user_ship');
if ($userShip > 0 && $userShip != 4) {
$list = StoreProductGroupPrice::resetProductsPrice($list, $userShip);
}
return $list;

View File

@ -0,0 +1,135 @@
<?php
namespace app\admin\lists\warehouse_product_storege;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_category\StoreCategory;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\warehouse\Warehouse;
use app\common\lists\ListsSortInterface;
use app\common\lists\ListsExcelInterface;
/**
* 仓库商品存储列表
* Class WarehouseProductStoregeTwoLists
* @package app\admin\listswarehouse_product_storege
*/
class WarehouseProductStoregeTwoLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface, ListsExcelInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/08/01 10:22
*/
public function setSearch(): array
{
return [
'=' => ['warehouse_id', 'product_id'],
];
}
/**
* @notes 设置支持排序字段
* @return string[]
* @remark 格式: ['前端传过来的字段名' => '数据库中的字段名'];
*/
public function setSortFields(): array
{
return ['nums' => 'nums'];
}
/**
* @notes 设置默认排序
* @return string[]
*/
public function setDefaultOrder(): array
{
return ['id' => 'desc', 'nums' => 'desc',];
}
/**
* @notes 获取仓库商品存储列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2024/08/01 10:22
*/
public function lists(): array
{
if ($this->request->get('store_name')) {
$ids = StoreProduct::where('store_name', 'like', '%' . $this->request->get('store_name') . '%')->column('id');
if ($ids) {
$this->searchWhere[] = ['product_id', 'in', $ids];
} else {
return [];
}
}
$this->searchWhere[] = ['nums', '<=', 0];
return WarehouseProductStorege::where($this->searchWhere)
->field(['id', 'warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status'])
->limit($this->limitOffset, $this->limitLength)
->order($this->sortOrder)
->select()->each(function ($item) {
$item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name');
$find = StoreProduct::where('id', $item->product_id)->withTrashed()->find();
$item->store_name = $find->store_name;
$item->image = $find->image;
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
$item['stock'] = $item['nums'];
return $item;
})
->toArray();
}
/**
* @notes 获取仓库商品存储数量
* @return int
* @author admin
* @date 2024/08/01 10:22
*/
public function count(): int
{
return WarehouseProductStorege::where($this->searchWhere)->count();
}
/**
* @notes 导出文件名
* @return string
* @author 乔峰
* @date 2022/11/24 16:17
*/
public function setFileName(): string
{
return '仓库商品列表';
}
/**
* @notes 导出字段
* @return string[]
* @author 乔峰
* @date 2022/11/24 16:17
*/
public function setExcelFields(): array
{
$data = [
'warehouse_name' => '仓库名称',
'product_id' => '商品id',
'store_name' => '商品名称',
'unit_name' => '单位',
'stock' => '数量',
];
return $data;
}
}

View File

@ -11,9 +11,11 @@ use app\common\model\store_branch_product_exchange\StoreBranchProductExchange;
use app\common\model\store_category\StoreCategory;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\model\store_product_cate\StoreProductCate;
use app\common\model\store_product_group_price\StoreProductGroupPrice;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\system_store\SystemStore;
use app\common\model\system_store_storage\SystemStoreStorage;
use app\common\model\user\User;
use Illuminate\Support\Facades\Log;
use support\exception\BusinessException;
use think\facade\Db;
@ -288,7 +290,11 @@ class StoreProductLogic extends BaseLogic
*/
public static function detail($params): array
{
$data = StoreProduct::where('id', $params['id'])->findOrEmpty()->toArray();
$query = StoreProduct::where('id', $params['id']);
if (isset($params['is_show'])) {
$query->where('is_show', $params['is_show']);
}
$data = $query->findOrEmpty()->toArray();
if(empty($data)){
throw new BusinessException('商品不存在');
}
@ -300,6 +306,14 @@ class StoreProductLogic extends BaseLogic
$data['cate_arr'][]=$data['cate_id'];
}
$data['unit_name']=StoreProductUnit::where('id', $data['unit'])->value('name');
if (!empty($params['user_id'])) {
$userShip = User::where('id', $params['user_id'])->value('user_ship');
if ($userShip == 4) {
$data['price'] = $data['cost'];
} else {
$data = StoreProductGroupPrice::resetProductPrice($data, $userShip);
}
}
return $data;
}

View File

@ -76,6 +76,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
$find = StoreProduct::where(['id' => $item['product_id']])
->field($field)
->find();
$find = StoreProductGroupPrice::resetProductPrice($find, $user_ship);
if ($find) {
if ($off_activity == 1) {
$this->activity_price = bcadd(bcmul($find['cost'], $item['cart_num'], 2), $this->activity_price, 2);
@ -93,7 +94,6 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
}
}
$list = StoreProductGroupPrice::resetProductsPrice($list, $user_ship);
return $list;
}

View File

@ -0,0 +1,62 @@
<?php
namespace app\api\logic;
use app\common\logic\BaseLogic;
use app\common\model\store_product\StoreProduct;
use think\facade\Db;
class DemoLogic extends BaseLogic
{
public static function test()
{
$arr = Db::name('ceshi_two')->select();
foreach ($arr as $k => $v) {
//门店供货、商户、零售
StoreProduct::where('id', $v['product_id'])->update(['purchase' => $v['price'], 'cost' => bcadd($v['price1'], 0, 2), 'vip_price' => bcadd($v['price1'], 0, 2), 'price' => bcadd($v['price6'], 0, 2)]);
//种养殖
$find = Db::name('store_product_group_price')->where('product_id', $v['product_id'])->where('group_id', 5)->find();
if ($find) {
Db::name('store_product_group_price')->where('product_id', $v['product_id'])->where('group_id', 5)->update(['price' => bcadd($v['price8'], 0, 2)]);
} else {
Db::name('store_product_group_price')->insert(['product_id' => $v['product_id'], 'group_id' => 5, 'price' => bcadd($v['price8'], 0, 2), 'price_type' => 3, 'base_rate' => bcadd(bcmul($v['lv8'], 100), 100, 2)]);
}
//酒店
$find2 = Db::name('store_product_group_price')->where('product_id', $v['product_id'])->where('group_id', 7)->find();
if ($find2) {
Db::name('store_product_group_price')->where('product_id', $v['product_id'])->where('group_id', 7)->update(['price' => bcadd($v['price3'], 0, 2)]);
} else {
Db::name('store_product_group_price')->insert(['product_id' => $v['product_id'], 'group_id' => 7, 'price' => bcadd($v['price3'], 0, 2), 'price_type' => 3, 'base_rate' => bcadd(bcmul($v['lv3'], 100), 100, 2)]);
}
//一条龙
$find3 = Db::name('store_product_group_price')->where('product_id', $v['product_id'])->where('group_id', 18)->find();
if ($find3) {
Db::name('store_product_group_price')->where('product_id', $v['product_id'])->where('group_id', 18)->update(['price' => bcadd($v['price5'], 0, 2)]);
} else {
Db::name('store_product_group_price')->insert(['product_id' => $v['product_id'], 'group_id' => 18, 'price' => bcadd($v['price5'], 0, 2), 'price_type' => 3, 'base_rate' => bcadd(bcmul($v['lv5'], 100), 100, 2)]);
}
//厨师
$find4 = Db::name('store_product_group_price')->where('product_id', $v['product_id'])->where('group_id', 1)->find();
if ($find4) {
Db::name('store_product_group_price')->where('product_id', $v['product_id'])->where('group_id', 1)->update(['price' => bcadd($v['price7'], 0, 2)]);
} else {
Db::name('store_product_group_price')->insert(['product_id' => $v['product_id'], 'group_id' => 1, 'price' => bcadd($v['price7'], 0, 2), 'price_type' => 3, 'base_rate' => bcadd(bcmul($v['lv7'], 100), 100, 2)]);
}
//商户会员
$find4 = Db::name('store_product_group_price')->where('product_id', $v['product_id'])->where('group_id', 19)->find();
if ($find4) {
Db::name('store_product_group_price')->where('product_id', $v['product_id'])->where('group_id', 19)->update(['price' => bcadd($v['price2'], 0, 2)]);
} else {
Db::name('store_product_group_price')->insert(['product_id' => $v['product_id'], 'group_id' => 19, 'price' => bcadd($v['price2'], 0, 2), 'price_type' => 3, 'base_rate' => bcadd(bcmul($v['lv2'], 100), 100, 2)]);
}
//食堂会员
$find4 = Db::name('store_product_group_price')->where('product_id', $v['product_id'])->where('group_id', 20)->find();
if ($find4) {
Db::name('store_product_group_price')->where('product_id', $v['product_id'])->where('group_id', 20)->update(['price' => bcadd($v['price4'], 0, 2)]);
} else {
Db::name('store_product_group_price')->insert(['product_id' => $v['product_id'], 'group_id' => 20, 'price' => bcadd($v['price4'], 0, 2), 'price_type' => 3, 'base_rate' => bcadd(bcmul($v['lv4'], 100), 100, 2)]);
}
}
}
}