Compare commits
No commits in common. "main" and "updateOrder" have entirely different histories.
main
...
updateOrde
@ -7,7 +7,6 @@ use Next\VarDumper\Dumper;
|
||||
use Next\VarDumper\DumperHandler;
|
||||
use support\exception\BusinessException;
|
||||
use support\exception\Handler;
|
||||
use support\Log;
|
||||
use Throwable;
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
@ -23,7 +22,6 @@ class ExceptionHandler extends Handler
|
||||
return \response(self::convertToHtml($exception));
|
||||
}elseif ($exception instanceof BusinessException) {
|
||||
if ($request->expectsJson()) {
|
||||
Log::error('BusinessException:',['msg'=>$exception->getMessage(),'file'=>$exception->getFile(),'line'=>$exception->getLine()]);
|
||||
return json(['code' => 0, 'msg' => $exception->getMessage(),'show'=>1]);
|
||||
}
|
||||
return response($exception->getMessage());
|
||||
@ -37,12 +35,9 @@ class ExceptionHandler extends Handler
|
||||
$error['file'] = $exception->getFile();
|
||||
$error['line'] = $exception->getLine();
|
||||
}
|
||||
Log::error('Exception:',['msg'=>$exception->getMessage(),'file'=>$exception->getFile(),'line'=>$exception->getLine()]);
|
||||
return response(json_encode($error, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
// 非json请求则返回一个页面
|
||||
Log::error('other:',['msg'=>$exception->getMessage(),'file'=>$exception->getFile(),'line'=>$exception->getLine()]);
|
||||
|
||||
return new Response(200, [], 'msg:'.$exception->getMessage().'。line:'.$exception->getLine().'。file:'.$exception->getFile());
|
||||
}
|
||||
}
|
||||
|
20
app/MyBusinessException.php
Normal file
20
app/MyBusinessException.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app;
|
||||
|
||||
use support\exception\BusinessException;
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
|
||||
class MyBusinessException extends BusinessException
|
||||
{
|
||||
public function render(Request $request): ?Response
|
||||
{
|
||||
// json请求返回json数据
|
||||
if ($request->expectsJson()) {
|
||||
return json(['code' => $this->getCode() ?: 500, 'msg' => $this->getMessage(),'show'=>1]);
|
||||
}
|
||||
// 非json请求则返回一个页面
|
||||
return new Response(200, [], $this->getMessage());
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\ActivityZoneLists;
|
||||
use app\admin\logic\ActivityZoneLogic;
|
||||
use app\admin\validate\ActivityZoneValidate;
|
||||
|
||||
|
||||
/**
|
||||
* ActivityZone控制器
|
||||
* Class ActivityZoneController
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class ActivityZoneController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ActivityZoneLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ActivityZoneValidate())->post()->goCheck('add');
|
||||
$result = ActivityZoneLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ActivityZoneLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ActivityZoneValidate())->post()->goCheck('edit');
|
||||
$result = ActivityZoneLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ActivityZoneLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ActivityZoneValidate())->post()->goCheck('delete');
|
||||
ActivityZoneLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ActivityZoneValidate())->goCheck('detail');
|
||||
$result = ActivityZoneLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\lists\ActivityZoneFormLists;
|
||||
use app\admin\logic\ActivityZoneFormLogic;
|
||||
use app\admin\validate\ActivityZoneFormValidate;
|
||||
|
||||
/**
|
||||
* ActivityZoneFormController控制器
|
||||
* Class ActivityZoneFormController
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class ActivityZoneFormController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ActivityZoneFormLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ActivityZoneFormValidate())->post()->goCheck('add');
|
||||
$result = ActivityZoneFormLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ActivityZoneFormLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ActivityZoneFormValidate())->post()->goCheck('edit');
|
||||
$result = ActivityZoneFormLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ActivityZoneFormLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ActivityZoneFormValidate())->post()->goCheck('delete');
|
||||
ActivityZoneFormLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ActivityZoneFormValidate())->goCheck('detail');
|
||||
$result = ActivityZoneFormLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$file_path = ActivityZoneFormLogic::export($params);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\ChangeLogLists;
|
||||
use app\admin\logic\ChangeLogLogic;
|
||||
use app\admin\validate\ChangeLogValidate;
|
||||
|
||||
|
||||
/**
|
||||
* ChangeLog控制器
|
||||
* Class ChangeLogController
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class ChangeLogController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ChangeLogLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ChangeLogValidate())->post()->goCheck('add');
|
||||
$result = ChangeLogLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ChangeLogLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ChangeLogValidate())->post()->goCheck('edit');
|
||||
$result = ChangeLogLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ChangeLogLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ChangeLogValidate())->post()->goCheck('delete');
|
||||
ChangeLogLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ChangeLogValidate())->goCheck('detail');
|
||||
$result = ChangeLogLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\api\logic\DemoLogic;
|
||||
use app\common\service\pay\PayService;
|
||||
|
||||
class IndexController extends BaseAdminController
|
||||
@ -25,24 +24,4 @@ class IndexController extends BaseAdminController
|
||||
return $this->fail($e->extra['message']);
|
||||
}
|
||||
}
|
||||
public function demo2()
|
||||
{
|
||||
$res=DemoLogic::test();
|
||||
return $this->success('成功');
|
||||
}
|
||||
public function demo3()
|
||||
{
|
||||
$id=$this->request->get('id');
|
||||
$warehouse_id=$this->request->get('warehouse_id',1);
|
||||
$res=DemoLogic::test3($id,$warehouse_id);
|
||||
return $this->success('成功');
|
||||
}
|
||||
|
||||
public function demo4()
|
||||
{
|
||||
$params=$this->request->get();
|
||||
$is_vip=$this->request->get('is_vip',0);
|
||||
$res=DemoLogic::syncPrice($params,$is_vip);
|
||||
return $this->success('成功');
|
||||
}
|
||||
}
|
@ -1,697 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\logic\beforehand_order_cart_info\BeforehandOrderCartInfoLogic;
|
||||
use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic;
|
||||
use app\admin\logic\inventory_transfer_order\InventoryTransferOrderLogic;
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\admin\logic\store_product_price\StoreProductPriceLogic;
|
||||
use app\admin\service\ProductPriceService;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||
use app\common\model\CeshiCopy;
|
||||
use app\common\model\product_source_link\ProductSourceLink;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
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\StoreProductPriceList;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use support\exception\BusinessException;
|
||||
use support\Redis;
|
||||
use think\facade\Db;
|
||||
|
||||
class LocalController extends BaseAdminController
|
||||
{
|
||||
|
||||
public $notNeedLogin = ['importPrice', 'searchProduct', 'setPrice', 'index', 'updateProductPriceList', 'importOrder', 'warehousing', 'outbound', 'syncPrice', 'importProduct'];
|
||||
|
||||
public $ids = [1829, 1828, 1827, 1826, 1825, 1824, 1823, 1821, 1820, 1814, 1813, 1811, 1810, 1809, 1808, 1807, 1806, 1800, 1799, 1798, 1796, 1795, 1794, 1793, 1792, 1791, 1790, 1789, 1788, 1787, 1786, 1785, 1784, 1783, 1782, 1781, 1780, 1779, 1778, 1777, 1776, 1775, 1774, 1773, 1772, 1771, 1770, 1768, 1765, 1764, 1763, 1762, 1761, 1760, 1759, 1758, 1757, 1756, 1755, 1754, 1753, 1752, 1751, 1750, 1749, 1748, 1747, 1746, 1745, 1744, 1743, 1742, 1741, 1740, 1739, 1738, 1737, 1736, 1735, 1733, 1732, 1731, 1730, 1729, 1728, 1727, 1726, 1725, 1724, 1723, 1722, 1720, 1719, 1718, 1717, 1716, 1715, 1714, 1713, 1712, 1711, 1710, 1709, 1708, 1707, 1706, 1705, 1704, 1703, 1701, 1700, 1699, 1698, 1697, 1696, 1695, 1694, 1693, 1692, 1691, 1690, 1689, 1688, 1687, 1686, 1685, 1684, 1683, 1682, 1681, 1680, 1679, 1678, 1677, 1676, 1675, 1674, 1673, 1672, 1671, 1670, 1668, 1667, 1666, 1665, 1664, 1663, 1660, 1659, 1658, 1657, 1656, 1655, 1654, 1652, 1651, 1650, 1649, 1648, 1647, 1646, 1645, 1644, 1643, 1642, 1641, 1640, 1639, 1638, 1637, 1636, 1635, 1634, 1633, 1632, 1631, 1630, 1629, 1628, 1627, 1626, 1623, 1622];
|
||||
|
||||
public function importPrice()
|
||||
{
|
||||
$file = $this->request->file('file');
|
||||
$reader = IOFactory::createReader('Xlsx');
|
||||
$spreadsheet = $reader->load($file->getRealPath());
|
||||
$data = $spreadsheet->getActiveSheet()->toArray();
|
||||
foreach ($data as $k => $v) {
|
||||
if ($k < 1) {
|
||||
continue;
|
||||
}
|
||||
$productId = $v[0];
|
||||
$purchasePrice = $v[12];
|
||||
$product = StoreProduct::where('id', $productId)->find();
|
||||
if (empty($product)) {
|
||||
continue;
|
||||
}
|
||||
$params = [
|
||||
'product_id' => $productId,
|
||||
'purchase_price' => $purchasePrice,
|
||||
'status' => 1,
|
||||
];
|
||||
$productService = new ProductPriceService();
|
||||
$productPriceRate = $productService->getProductPriceRate($productId);
|
||||
if (!empty($productPriceRate)) {
|
||||
$priceArray = $productService->setProductPrice($params['purchase_price'], $productPriceRate);
|
||||
$params = array_merge($params, $priceArray);
|
||||
}
|
||||
StoreProductPriceLogic::add($params);
|
||||
}
|
||||
}
|
||||
|
||||
public function importProduct()
|
||||
{
|
||||
$file = $this->request->file('file');
|
||||
$reader = IOFactory::createReader('Xlsx');
|
||||
$spreadsheet = $reader->load($file->getRealPath());
|
||||
$data = $spreadsheet->getActiveSheet()->toArray();
|
||||
$createTime = time();
|
||||
$updateTime = time();
|
||||
foreach ($data as $k => $v) {
|
||||
if ($k < 1) {
|
||||
continue;
|
||||
}
|
||||
$productName = $v[0];
|
||||
$num = $v[1];
|
||||
$package = $v[2];
|
||||
$product = StoreProduct::where('store_name', $productName)->find();
|
||||
if (empty($product)) {
|
||||
$product = StoreProductLogic::add([
|
||||
'store_name' => $productName,
|
||||
'image' => '',
|
||||
'cate_id' => 15627,
|
||||
'cate_arr' => [15324, 15627],
|
||||
'package' => $package,
|
||||
'unit' => 0,
|
||||
'price' => 0,
|
||||
'vip_price' => 0,
|
||||
'cost' => 0,
|
||||
'purchase' => 0,
|
||||
'is_return' => 0,
|
||||
'is_store_all' => 1,
|
||||
'product_type' => 3,
|
||||
]);
|
||||
}
|
||||
$warehouseProduct = WarehouseProductStorege::where('product_id', $product->id)->find();
|
||||
if (empty($warehouseProduct)) {
|
||||
WarehouseProductStorege::create([
|
||||
'product_id' => $product->id,
|
||||
'nums' => $num,
|
||||
'warehouse_id' => 1,
|
||||
'create_time' => $createTime,
|
||||
'update_time' => $updateTime,
|
||||
]);
|
||||
} else {
|
||||
$warehouseProduct->save(['nums' => $num]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function syncPrice(ProductPriceService $productPriceService)
|
||||
{
|
||||
$data = Db::connect('local')->query('SELECT id, product_id,purchase_price FROM (SELECT id,product_id,purchase_price,ROW_NUMBER() OVER (PARTITION BY product_id ORDER BY id DESC) as rn FROM la_store_product_price) subquery WHERE rn = 1');
|
||||
$products = StoreProduct::whereIn('id', array_column($data, 'product_id'))->field('id,store_name,top_cate_id,cate_id')->select()->toArray();
|
||||
$products = reset_index($products, 'id');
|
||||
$update = [];
|
||||
$update2 = [];
|
||||
foreach ($data as $item) {
|
||||
$product = $products[$item['product_id']] ?? [];
|
||||
if (empty($product)) {
|
||||
continue;
|
||||
}
|
||||
$priceRateList = $productPriceService->getProductPriceRate($product['id'], true);
|
||||
$rate = $priceRateList['supply_rate'];
|
||||
$costRate = $priceRateList['merchant_rate'];
|
||||
$vipPriceRate = $priceRateList['vip_rate'];
|
||||
$priceRate = $priceRateList['price_rate'];
|
||||
$purchase = bcmul($item['purchase_price'], $rate, 2);
|
||||
$cost = bcmul($purchase, $costRate, 2);
|
||||
$price = bcmul($purchase, $priceRate, 2);
|
||||
$vipPrice = bcmul($purchase, $vipPriceRate, 2);
|
||||
$update[] = [
|
||||
'id' => $item['id'],
|
||||
'purchase_lv' => $rate,
|
||||
'purchase' => $purchase,
|
||||
'cost_lv' => $costRate,
|
||||
'cost' => $cost,
|
||||
'price_lv' => $priceRate,
|
||||
'price' => $price,
|
||||
'vip_lv' => $vipPriceRate,
|
||||
'vip_price' => $vipPrice,
|
||||
];
|
||||
$update2[] = [
|
||||
'id' => $item['product_id'],
|
||||
'purchase' => $purchase,
|
||||
'cost' => $cost,
|
||||
'price' => $price,
|
||||
'vip_price' => $vipPrice,
|
||||
];
|
||||
}
|
||||
(new StoreProductPrice())->saveAll($update);
|
||||
(new StoreProduct())->saveAll($update2);
|
||||
}
|
||||
|
||||
public function warehousing()
|
||||
{
|
||||
$warehousingIds = BeforehandOrder::whereIn('id', $this->ids)->where('warehousing_id', '>', 0)->column('warehousing_id');
|
||||
$warehouseOrders = WarehouseOrder::field('id,warehouse_id')->whereIn('id', $warehousingIds)->where('financial_pm', 1)->select()->toArray();
|
||||
$productSourceLinkInfo = [];
|
||||
foreach ($warehouseOrders as $order) {
|
||||
$products = WarehouseProduct::field('id,product_id,nums,purchase,create_time')->where('oid', $order['id'])->select()->toArray();
|
||||
foreach ($products as $product) {
|
||||
$productSourceLink = ProductSourceLink::where('product_id', $product['product_id'])->where('purchase_uid', 20)->where('warehouse_id', $order['warehouse_id'])->find();
|
||||
if (empty($productSourceLink)) {
|
||||
$productSourceLink = new ProductSourceLink();
|
||||
$productSourceLink->product_id = $product['product_id'];
|
||||
$productSourceLink->purchase_uid = 20;
|
||||
$productSourceLink->warehouse_id = $order['warehouse_id'];
|
||||
$productSourceLink->save();
|
||||
}
|
||||
|
||||
$productSourceLinkInfo[] = [
|
||||
'oid' => $productSourceLink['id'],
|
||||
'product_id' => $product['product_id'],
|
||||
'warehouse_id' => $order['warehouse_id'],
|
||||
'nums' => $product['nums'],
|
||||
'current_nums' => $product['nums'],
|
||||
'types' => ProductSourceLinkInfo::TypeIn,
|
||||
'link_id' => $product['id'],
|
||||
'price' => $product['purchase'],
|
||||
'total_price' => bcmul($product['purchase'], $product['nums'], 2),
|
||||
'create_time' => strtotime($product['create_time']),
|
||||
];
|
||||
}
|
||||
}
|
||||
(new ProductSourceLinkInfo())->insertAll($productSourceLinkInfo);
|
||||
}
|
||||
|
||||
public function outbound()
|
||||
{
|
||||
$outboundIds = BeforehandOrder::whereIn('id', $this->ids)->where('outbound_id', '>', 0)->column('outbound_id');
|
||||
$outboundOrders = WarehouseOrder::field('id,warehouse_id,store_id')->whereIn('id', $outboundIds)->where('financial_pm', 0)->select()->toArray();
|
||||
foreach ($outboundOrders as $order) {
|
||||
$products = WarehouseProduct::field('id,product_id,nums,purchase,create_time')->where('oid', $order['id'])->select()->toArray();
|
||||
foreach ($products as $product) {
|
||||
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
||||
$productSourceLinkInfoLogic->warehouseProduct = $product;
|
||||
$productSourceLinkInfoLogic->setInfo([
|
||||
'warehouse_id' => $order['warehouse_id'],
|
||||
'store_id' => $order['store_id'],
|
||||
'link_id' => $product['id'],
|
||||
'create_time' => strtotime($product['create_time']),
|
||||
]);
|
||||
$productSourceLinkInfoLogic->outbound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function activityPrice()
|
||||
{
|
||||
$product = Db::table('la_ceshi_copy_copy')->select()->toArray();
|
||||
$userShip = 43;
|
||||
$insert = [];
|
||||
foreach ($product as $k => $v) {
|
||||
$rate = bcdiv($v['price'], $v['price_two'], 2);
|
||||
$rate = $rate * 100;
|
||||
$insert[] = [
|
||||
'product_id' => $v['product_id'],
|
||||
'group_id' => $userShip,
|
||||
'price_type' => 3,
|
||||
'base_rate' => $rate,
|
||||
'price' => $v['price'],
|
||||
];
|
||||
}
|
||||
StoreProductGroupPrice::insertAll($insert);
|
||||
return $this->data($insert);
|
||||
}
|
||||
|
||||
public function searchProduct()
|
||||
{
|
||||
$product = Db::table('la_ceshi')->select()->toArray();
|
||||
$product = reset_index($product, 'name');
|
||||
$product2 = Db::table('la_ceshi_copy_copy')->select()->toArray();
|
||||
$update = [];
|
||||
foreach ($product2 as $v) {
|
||||
if (isset($product[$v['name']])) {
|
||||
$update[] = [
|
||||
'id' => $v['id'],
|
||||
'product_id' => $product[$v['name']]['product_id'],
|
||||
];
|
||||
}
|
||||
}
|
||||
$result = (new CeshiCopy())->saveAll($update);
|
||||
return $this->data($update);
|
||||
}
|
||||
|
||||
public function setPrice()
|
||||
{
|
||||
$file = $this->request->file('file');
|
||||
$reader = IOFactory::createReader('Xlsx');
|
||||
$spreadsheet = $reader->load($file->getRealPath());
|
||||
$data = $spreadsheet->getActiveSheet()->toArray();
|
||||
$insert = [];
|
||||
$update = [];
|
||||
$productIds = [];
|
||||
foreach ($data as $k => $row) {
|
||||
if ($k < 2) {
|
||||
continue;
|
||||
}
|
||||
if (empty($row[0])) {
|
||||
continue;
|
||||
}
|
||||
$productId = intval($row[0]);
|
||||
if (empty($productId)) {
|
||||
continue;
|
||||
}
|
||||
$productIds[] = $productId;
|
||||
}
|
||||
$products = StoreProduct::whereIn('id', $productIds)->field('id,store_name,purchase')->select()->toArray();
|
||||
$products = reset_index($products, 'id');
|
||||
foreach ($data as $k => $row) {
|
||||
if ($k < 2) {
|
||||
continue;
|
||||
}
|
||||
if (empty($row[0])) {
|
||||
continue;
|
||||
}
|
||||
$productId = intval($row[0]);
|
||||
if (empty($productId)) {
|
||||
continue;
|
||||
}
|
||||
$product = $products[$productId] ?? [];
|
||||
if (empty($product)) {
|
||||
continue;
|
||||
}
|
||||
$groupIds = [
|
||||
5 => 23,
|
||||
7 => 24,
|
||||
9 => 25,
|
||||
11 => 26,
|
||||
13 => 27,
|
||||
15 => 28,
|
||||
17 => 29,
|
||||
19 => 30,
|
||||
21 => 31,
|
||||
23 => 32,
|
||||
25 => 33,
|
||||
27 => 34,
|
||||
29 => 35,
|
||||
31 => 36,
|
||||
33 => 37,
|
||||
35 => 1,
|
||||
37 => 18,
|
||||
39 => 22,
|
||||
];
|
||||
for ($i = 5; $i < 35; $i = $i + 2) {
|
||||
$rate = intval(rtrim($row[$i] ?? 0, '%'));
|
||||
if (empty($rate)) {
|
||||
continue;
|
||||
}
|
||||
$price = $row[$i + 1] ?? 0;
|
||||
if (empty($price)) {
|
||||
$price = $product['purchase'] * (1 + $rate / 100);
|
||||
}
|
||||
$item = [
|
||||
'product_id' => $productId,
|
||||
'group_id' => $groupIds[$i],
|
||||
'price_type' => 3,
|
||||
'base_rate' => 100 + $rate,
|
||||
'price' => $price
|
||||
];
|
||||
$insert[] = $item;
|
||||
}
|
||||
$productGroupPrices = StoreProductGroupPrice::where('product_id', $productId)->whereIn('group_id', [1, 18, 22])->select()->toArray();
|
||||
$groupIds = array_flip($groupIds);
|
||||
foreach ($productGroupPrices as $productGroupPrice) {
|
||||
$cellId = $groupIds[$productGroupPrice['group_id']] ?? 0;
|
||||
$rate = intval(rtrim($row[$cellId] ?? 0, '%'));
|
||||
if (empty($rate)) {
|
||||
continue;
|
||||
}
|
||||
$price = $row[$cellId + 1] ?? 0;
|
||||
if (empty($price)) {
|
||||
$price = $product['purchase'] * (1 + $rate / 100);
|
||||
}
|
||||
if ($price != $productGroupPrice['price']) {
|
||||
$update[] = [
|
||||
'id' => $productGroupPrice['id'],
|
||||
'base_rate' => $rate,
|
||||
'price' => $price,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($insert) > 0) {
|
||||
StoreProductGroupPrice::insertAll($insert);
|
||||
}
|
||||
if (count($update) > 0) {
|
||||
(new StoreProductGroupPrice())->saveAll($update);
|
||||
}
|
||||
return $this->success('插入成功:' . count($insert) . '条,更新成功:' . count($update) . '条');
|
||||
}
|
||||
|
||||
public function fixCategory()
|
||||
{
|
||||
$topCate = StoreCategory::where('pid', 0)->field('id,name,pid')->order('name')->select()->toArray();
|
||||
$topCate = reset_index($topCate, 'name');
|
||||
$sql = [];
|
||||
$time = time();
|
||||
foreach ($topCate as $item) {
|
||||
if (isset($topCate[$item['name'] . '类'])) {
|
||||
$target = $topCate[$item['name'] . '类'];
|
||||
$sql[] = "##原分类id:{$item['id']},原分类名:{$item['name']},目标分类id:{$target['id']},目标分类名:{$target['name']}";
|
||||
$sql[] = "update la_store_product set top_cate_id={$target['id']} where top_cate_id={$item['id']};";
|
||||
$sql[] = "update la_store_product set two_cate_id={$target['id']} where two_cate_id={$item['id']};";
|
||||
$sql[] = "update la_store_category set delete_time=$time where id={$item['id']};";
|
||||
}
|
||||
$secondCate = StoreCategory::where('pid', $item['id'])->field('id,name,pid')->order('name')->select()->toArray();
|
||||
$secondCate = reset_index($secondCate, 'name');
|
||||
foreach ($secondCate as $item2) {
|
||||
if (isset($secondCate[$item2['name'] . '类'])) {
|
||||
$target = $secondCate[$item2['name'] . '类'];
|
||||
$sql[] = "##原分类id:{$item2['id']},原分类名:{$item2['name']},目标分类id:{$target['id']},目标分类名:{$target['name']}";
|
||||
$sql[] = "update la_store_product set two_cate_id={$target['id']} where two_cate_id={$item2['id']};";
|
||||
$sql[] = "update la_store_product set cate_id={$target['id']} where cate_id={$item2['id']};";
|
||||
$sql[] = "update la_store_category set delete_time=$time where id={$item2['id']};";
|
||||
}
|
||||
$thirdCate = StoreCategory::where('pid', $item2['id'])->field('id,name,pid')->order('name')->select()->toArray();
|
||||
$thirdCate = reset_index($thirdCate, 'name');
|
||||
foreach ($thirdCate as $item3) {
|
||||
if (isset($thirdCate[$item3['name'] . '类'])) {
|
||||
$target = $thirdCate[$item3['name'] . '类'];
|
||||
$sql[] = "##原分类id:{$item3['id']},原分类名:{$item3['name']},目标分类id:{$target['id']},目标分类名:{$target['name']}";
|
||||
$sql[] = "update la_store_product set cate_id={$target['id']} where cate_id={$item3['id']};";
|
||||
$sql[] = "update la_store_category set delete_time=$time where id={$item3['id']};";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
file_put_contents(public_path() . '/update.sql', implode(PHP_EOL, $sql));
|
||||
return $this->success('数据已更新完成', $sql);
|
||||
}
|
||||
|
||||
public function updateProductPriceList()
|
||||
{
|
||||
$file = $this->request->file('file');
|
||||
$reader = IOFactory::createReader('Xlsx');
|
||||
$spreadsheet = $reader->load($file->getRealPath());
|
||||
$data = $spreadsheet->getActiveSheet()->toArray();
|
||||
$updateCount = 0;
|
||||
$insert = [];
|
||||
$time = time();
|
||||
foreach ($data as $k => $row) {
|
||||
if ($k < 1 || empty($row[0])) {
|
||||
continue;
|
||||
}
|
||||
$product = StoreProduct::where('id', $row[0])->value('id');
|
||||
if (empty($product)) {
|
||||
continue;
|
||||
}
|
||||
for ($i = 1; $i < 5; $i++) {
|
||||
if (empty($row[1 + $i])) {
|
||||
continue;
|
||||
}
|
||||
$insert[] = [
|
||||
'product_id' => $row[0],
|
||||
'price_type' => $i,
|
||||
'rate' => intval(rtrim($row[1 + $i], '%')) + 100,
|
||||
'create_time' => $time,
|
||||
];
|
||||
}
|
||||
}
|
||||
StoreProductPriceList::insertAll($insert);
|
||||
return $this->success('更新成功:' . $updateCount . '条');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$file = $this->request->file('file');
|
||||
$reader = IOFactory::createReader('Xlsx');
|
||||
$spreadsheet = $reader->load($file->getRealPath());
|
||||
$data = $spreadsheet->getActiveSheet()->toArray();
|
||||
$updateCount = 0;
|
||||
$finishCount = Redis::get('updateFinishCount');
|
||||
$finishCount = empty($finishCount) ? 0 : $finishCount;
|
||||
if ($finishCount >= count($data)) {
|
||||
return $this->success('数据已更新完成');
|
||||
}
|
||||
$max = $finishCount + 100;
|
||||
foreach ($data as $k => $row) {
|
||||
if ($k < (1 + $finishCount) || empty($row[0])) {
|
||||
continue;
|
||||
}
|
||||
if ($k > $max) {
|
||||
break;
|
||||
}
|
||||
$product = StoreProduct::where('id', $row[0])->field('id,store_name,top_cate_id,two_cate_id,cate_id')->findOrEmpty()->toArray();
|
||||
if (empty($product)) {
|
||||
continue;
|
||||
}
|
||||
$result = $this->updateProduct($product, $row);
|
||||
if ($result) {
|
||||
$updateCount++;
|
||||
}
|
||||
}
|
||||
Redis::set('updateFinishCount', 100 + $finishCount);
|
||||
return $this->success('更新成功:' . $updateCount . '条');
|
||||
}
|
||||
|
||||
public function updateProduct($product, $row)
|
||||
{
|
||||
$topCateName = $row[1];
|
||||
$secondCateName = $row[2];
|
||||
$cateName = $row[3];
|
||||
$topCate = StoreCategory::where('name', $topCateName)->value('id');
|
||||
$updateData = [];
|
||||
if (!empty($topCate) && $topCate != $product['top_cate_id']) {
|
||||
$updateData['top_cate_id'] = $topCate;
|
||||
}
|
||||
$secondCateId = StoreCategory::where('pid', $topCate)->where('name', $secondCateName)->value('id');
|
||||
if (empty($secondCateId)) {
|
||||
$secondCate = new StoreCategory();
|
||||
$secondCate->name = $secondCateName;
|
||||
$secondCate->pid = $topCate;
|
||||
$secondCate->save();
|
||||
$secondCateId = $secondCate->id;
|
||||
}
|
||||
if ($secondCateId != $product['two_cate_id']) {
|
||||
$updateData['two_cate_id'] = $secondCateId;
|
||||
}
|
||||
$cateId = StoreCategory::where('pid', $secondCateId)->where('name', $cateName)->value('id');
|
||||
if (empty($cateId)) {
|
||||
$cate = new StoreCategory();
|
||||
$cate->name = $cateName;
|
||||
$cate->pid = $secondCateId;
|
||||
$cate->save();
|
||||
$cateId = $cate->id;
|
||||
}
|
||||
if ($cateId != $product['cate_id']) {
|
||||
$updateData['cate_id'] = $cateId;
|
||||
}
|
||||
if (!empty($updateData)) {
|
||||
StoreProduct::where('id', $row[0])->update($updateData);
|
||||
echo '更新成功ID:' . $row[0] . PHP_EOL;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function importOrder()
|
||||
{
|
||||
$file = $this->request->file('file');
|
||||
$reader = IOFactory::createReader('Xlsx');
|
||||
$spreadsheet = $reader->load($file->getRealPath());
|
||||
$sheets = $spreadsheet->getAllSheets();
|
||||
foreach ($sheets as $sheetIndex => $sheet) {
|
||||
$params['is_buyer'] = -1;
|
||||
$params['buyer_id'] = 20;
|
||||
$params['admin_id'] = 1;
|
||||
$params['chef'] = '厨师';
|
||||
$params['chef_phone'] = '13513513513';
|
||||
$params['distribution_personnel'] = '余友"';
|
||||
$params['days'] = 0;
|
||||
$params['mark'] = '内部备注';
|
||||
$params['merchandiser'] = 0;
|
||||
$params['purpose'] = '备注';
|
||||
$params['store_id'] = 4;
|
||||
$params['splitting_officer'] = '分单员';
|
||||
$params['regional_manager'] = '张波';
|
||||
$params['system_store_name'] = '门店员';
|
||||
$params['transporter'] = '运输员';
|
||||
$params['pay_price'] = 0;
|
||||
$params['total_price'] = 0;
|
||||
$params['arrival_time'] = date('Y-m-d H:i:s');
|
||||
$rows = $sheet->toArray();
|
||||
foreach ($rows as $k => $row) {
|
||||
if ($k < 1 || empty($row[2])) {
|
||||
continue;
|
||||
}
|
||||
$product = StoreProduct::where('id', $row[0])->withTrashed()->field('id,package,store_info,marques,unit,price,purchase,after_sales')->findOrEmpty()->toArray();
|
||||
if (empty($product)) {
|
||||
continue;
|
||||
}
|
||||
$totalPrice = bcmul($product['price'], $row[2], 2);
|
||||
$params['total_price'] = bcadd($params['total_price'], $totalPrice, 2);
|
||||
$params['pay_price'] = $params['total_price'];
|
||||
$params['product_arr'][] = [
|
||||
'product_id' => $product['id'],
|
||||
'nums' => $row[2],
|
||||
'package' => $product['package'],
|
||||
'store_info' => $product['store_info'],
|
||||
'marques' => $product['marques'],
|
||||
'unit' => $product['unit'],
|
||||
'price' => $product['price'],
|
||||
'purchase' => $product['purchase'],
|
||||
'after_sales' => $product['after_sales'],
|
||||
'total_price' => $totalPrice,
|
||||
'purchase_total' => $row[3],
|
||||
];
|
||||
}
|
||||
$beforeOrderId = $this->batchCreate($params);
|
||||
$purchaseOffer = PurchaseProductOffer::where('order_id', $beforeOrderId)->field('id,product_id,buyer_nums')->select()->toArray();
|
||||
foreach ($purchaseOffer as $v) {
|
||||
$inStorageParams = [
|
||||
'admin_id' => 0,
|
||||
'bhoid' => $beforeOrderId,
|
||||
'buyer_nums' => $v['buyer_nums'],
|
||||
'id' => $v['id'],
|
||||
'product_id' => $v['product_id'],
|
||||
'warehouse_id' => 1,
|
||||
'warehouse_num' => $v['buyer_nums'],
|
||||
];
|
||||
BeforehandOrderCartInfoLogic::putInStorage($inStorageParams);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success('导入成功');
|
||||
}
|
||||
|
||||
public function batchCreate($params)
|
||||
{
|
||||
if (empty($params['buyer_id'])) {
|
||||
throw new BusinessException('请选择采购员');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$procurementOrder = new BeforehandOrder();
|
||||
$procurementOrder->order_id = getNewOrderId('CG');
|
||||
$procurementOrder->buyer_id = $params['buyer_id'];
|
||||
$procurementOrder->admin_id = $params['admin_id'];
|
||||
$procurementOrder->order_type = 9;
|
||||
$procurementOrder->total_price = $params['total_price'];
|
||||
$procurementOrder->pay_price = $params['pay_price'];
|
||||
$procurementOrder->save();
|
||||
$purchaseOffer = [];
|
||||
$cartInfo = [];
|
||||
foreach ($params['product_arr'] as $product) {
|
||||
if ($product['product_id'] <= 0) {
|
||||
continue;
|
||||
}
|
||||
$cartInfo[] = [
|
||||
'bhoid' => $procurementOrder['id'],
|
||||
'product_id' => $product['product_id'],
|
||||
'unit' => $product['unit'],
|
||||
'cart_num' => $product['nums'],
|
||||
'accept_num' => $product['nums'],
|
||||
'mark' => $product['mark'] ?? '',
|
||||
'is_buyer' => 1,
|
||||
'procurement_order_id' => $procurementOrder['id'],
|
||||
'total_price' => bcmul($product['price'], $product['nums'], 2),
|
||||
'pay_price' => bcmul($product['price'], $product['nums'], 2),
|
||||
'purchase' => $product['purchase'],
|
||||
'uid' => $params['uid'] ?? 0,
|
||||
'price' => $product['price'],
|
||||
'package' => $product['package'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
$purchaseOffer[] = [
|
||||
'order_id' => $procurementOrder['id'],
|
||||
'product_id' => $product['product_id'],
|
||||
'unit' => $product['unit'],
|
||||
'is_buyer' => 1,
|
||||
'need_num' => $product['nums'],
|
||||
'mark' => $product['mark'] ?? '',
|
||||
'buyer_id' => $params['buyer_id'],
|
||||
'buyer_confirm' => 1,
|
||||
'buyer_nums' => $product['nums'],
|
||||
'total_price' => $product['purchase_total'],
|
||||
'status' => 0,
|
||||
'source_order_info' => [
|
||||
[
|
||||
'source_order_id' => $procurementOrder['id'],
|
||||
'product_id' => $product['product_id'],
|
||||
'need_num' => $product['nums'],
|
||||
'mark' => $product['mark'] ?? '',
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
PurchaseProductOffer::insertAll($purchaseOffer);
|
||||
BeforehandOrderCartInfo::insertAll($cartInfo);
|
||||
Db::commit();
|
||||
return $procurementOrder->id;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function importStorege()
|
||||
{
|
||||
$file = $this->request->file('file');
|
||||
$reader = IOFactory::createReader('Xlsx');
|
||||
$spreadsheet = $reader->load($file->getRealPath());
|
||||
$sheets = $spreadsheet->getActiveSheet()->toArray();
|
||||
$new_params = [];
|
||||
$params = [];
|
||||
$system_store_id = 0;
|
||||
$params['product_arr'] = [];
|
||||
foreach ($sheets as $key => $row) {
|
||||
if ($key == 0) {
|
||||
continue;
|
||||
}
|
||||
if (!$system_store_id) {
|
||||
$system_store_id = SystemStore::where('name', $row[1])->value('id');
|
||||
}
|
||||
$product = StoreBranchProduct::where('product_id', $row[0])->where('store_id', $system_store_id)->field('id,product_id,stock')->findOrEmpty();
|
||||
if ($row[10] == $product->stock && intval($product->stock) > 0) {
|
||||
$arr = [
|
||||
'nums' => $row[10],
|
||||
'product_id' => $product->product_id,
|
||||
'purchase' => 0,
|
||||
'total_price' => $product->total_price,
|
||||
];
|
||||
$params['product_arr'][] = $arr;
|
||||
} else {
|
||||
$arr = [];
|
||||
$arr['product_id'] = $row[0];
|
||||
$arr['product_name'] = $row[2] ?? '';
|
||||
$arr['store_id'] = $system_store_id;
|
||||
$arr['nums'] = $row[10] ?? 0;
|
||||
$arr['stock'] = $product->stock ?? 0;
|
||||
$new_params[] = $arr;
|
||||
}
|
||||
}
|
||||
// 生成铺货单
|
||||
$params['mark'] = "门店铺货-excel导入";
|
||||
$params['one_id'] = $system_store_id; //门店id
|
||||
$params['one_type'] = 1; //1门店2仓库
|
||||
$params['two_id'] = 1; //1海吉星仓库
|
||||
$params['two_type'] = 2; //1门店2仓库
|
||||
$params['types'] = 0; //0减库存 1不减库存
|
||||
|
||||
InventoryTransferOrderLogic::add($params, $this->adminId);
|
||||
$new_params = json_encode($new_params, true);
|
||||
file_put_contents(public_path() . '/output.text', $new_params);
|
||||
return $this->success('导入成功');
|
||||
}
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
}
|
@ -336,7 +336,7 @@ class WorkbenchController extends BaseAdminController
|
||||
public function update_negative_zero()
|
||||
{
|
||||
$parmas = $this->request->get();
|
||||
$res = WarehouseLogic::updateNegativeZero($parmas,$this->adminId);
|
||||
$res = WarehouseLogic::updateNegativeZero($parmas);
|
||||
if($res){
|
||||
return $this->data([], '操作成功');
|
||||
}else{
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\accounts_receivable;
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\AccountsReceivableInfoLists;
|
||||
use app\admin\lists\AccountsReceivableLists;
|
||||
use app\admin\logic\AccountsReceivableLogic;
|
||||
use app\admin\validate\app_update\AppUpdateValidate;
|
||||
|
||||
/**
|
||||
* Class AccountsReceivableController
|
||||
* @package app\admin\controller\accounts_receivable
|
||||
*/
|
||||
class AccountsReceivableController extends BaseAdminController
|
||||
{
|
||||
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new AccountsReceivableLists());
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = AccountsReceivableLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(AccountsReceivableLogic::getError());
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$params = (new AppUpdateValidate())->post()->goCheck('delete');
|
||||
AccountsReceivableLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
public function detail()
|
||||
{
|
||||
$params = (new AppUpdateValidate())->goCheck('detail');
|
||||
$result = AccountsReceivableLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
public function record()
|
||||
{
|
||||
return $this->dataLists(new AccountsReceivableInfoLists());
|
||||
}
|
||||
|
||||
public function statistics()
|
||||
{
|
||||
$result = AccountsReceivableLogic::statistics();
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,6 @@ use app\admin\lists\beforehand_order\BeforehandOrderLists;
|
||||
use app\admin\lists\beforehand_order\BeforehandOrderTwoLists;
|
||||
use app\admin\lists\beforehand_order\BeforehandOrderThreeLists;
|
||||
use app\admin\logic\beforehand_order\BeforehandOrderLogic;
|
||||
use app\admin\logic\purchase_product_offer\PurchaseProductOfferLogic;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
@ -38,15 +37,7 @@ class BeforehandOrderController extends BaseAdminController
|
||||
{
|
||||
return $this->dataLists(new BeforehandOrderLists());
|
||||
}
|
||||
/**
|
||||
* 列表统计
|
||||
*/
|
||||
public function statistics_count()
|
||||
{
|
||||
$params=$this->request->get();
|
||||
$data=BeforehandOrderLogic::statisticsCount($params);
|
||||
return $this->data($data);
|
||||
}
|
||||
|
||||
public function warehousing_lists()
|
||||
{
|
||||
return $this->dataLists(new BeforehandOrderTwoLists());
|
||||
@ -84,11 +75,7 @@ class BeforehandOrderController extends BaseAdminController
|
||||
'regional_manager' => $params['regional_manager'] ?? '',
|
||||
];
|
||||
$params['other_data'] = $other_data;
|
||||
if (in_array($params['order_type'], [7, 9])) {
|
||||
PurchaseProductOfferLogic::batchCreate($params);
|
||||
} else {
|
||||
BeforehandOrderLogic::add($params);
|
||||
}
|
||||
$result = BeforehandOrderLogic::add($params);
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
/**
|
||||
@ -179,16 +166,6 @@ class BeforehandOrderController extends BaseAdminController
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 确认预订单
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
BeforehandOrderLogic::confirm($params);
|
||||
return $this->success('确认成功', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出标签
|
||||
*/
|
||||
@ -315,51 +292,4 @@ class BeforehandOrderController extends BaseAdminController
|
||||
$file_path = BeforehandOrderLogic::ReturnSupplier($params);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
|
||||
public function settle()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
BeforehandOrderLogic::settleOrder($params);
|
||||
return $this->success('确认成功');
|
||||
}
|
||||
|
||||
public function logList()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$result = BeforehandOrderLogic::logList($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
public function saveLog()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['submit_admin_id'] = $this->adminId;
|
||||
BeforehandOrderLogic::saveLog($params);
|
||||
return $this->success('保存成功');
|
||||
}
|
||||
|
||||
public function confirmLog()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['confirm_admin_id'] = $this->adminId;
|
||||
BeforehandOrderLogic::confirmLog($params);
|
||||
return $this->success('确认成功');
|
||||
}
|
||||
|
||||
public function copy()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
BeforehandOrderLogic::copy($params);
|
||||
return $this->success('复制成功');
|
||||
}
|
||||
|
||||
public function transfer()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
BeforehandOrderLogic::transfer($params);
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,7 +54,6 @@ class BeforehandOrderCartInfoController extends BaseAdminController
|
||||
public function append_add()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id']=$this->adminId;
|
||||
$result = BeforehandOrderCartInfoLogic::appendAdd($params);
|
||||
return $this->success('追加成功', [], 1, 1);
|
||||
|
||||
@ -86,6 +85,11 @@ class BeforehandOrderCartInfoController extends BaseAdminController
|
||||
}
|
||||
}
|
||||
$find->source_order_info = array_values($json);
|
||||
$productPrice = StoreProduct::where('id',$res['product_id'])->value('price');
|
||||
$procurementOrder = BeforehandOrder::where('id', $find['order_id'])->find();
|
||||
$procurementOrder->total_price = bcsub($procurementOrder->total_price, bcmul($productPrice, $res['cart_num'], 2), 2);
|
||||
$procurementOrder->pay_price = $procurementOrder->total_price;
|
||||
$procurementOrder->save();
|
||||
}
|
||||
if ($find->need_num <= 0) {
|
||||
$find->delete_time = time();
|
||||
@ -106,9 +110,6 @@ class BeforehandOrderCartInfoController extends BaseAdminController
|
||||
* @notes 一键入库
|
||||
*/
|
||||
public function one_click_storage(){
|
||||
if (time() > 1737561600) {
|
||||
return $this->fail('不允许一键入库');
|
||||
}
|
||||
$params=$this->request->post();
|
||||
$params['admin_id']=$this->adminId;
|
||||
BeforehandOrderCartInfoLogic::oneClickStorage($params);
|
||||
@ -170,32 +171,7 @@ class BeforehandOrderCartInfoController extends BaseAdminController
|
||||
{
|
||||
$params = $this->request->get();
|
||||
BeforehandOrderCartInfoLogic::fixAcceptNum($params);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
||||
public function syncPrice()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
BeforehandOrderCartInfoLogic::syncPrice($params);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
||||
public function setStoreSale()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
BeforehandOrderCartInfoLogic::setStoreSale($params);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分拣入库
|
||||
*/
|
||||
public function putInStorage()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
BeforehandOrderCartInfoLogic::putInStorage($params);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
return $this->data([]);
|
||||
}
|
||||
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\inventory_store;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\inventory_store\InventoryStoreLists;
|
||||
use app\admin\logic\inventory_store\InventoryStoreLogic;
|
||||
use app\admin\validate\inventory_store\InventoryStoreValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 门店盘存控制器
|
||||
* Class InventoryStoreController
|
||||
* @package app\admin\controller\inventory_store
|
||||
*/
|
||||
class InventoryStoreController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取门店盘存列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/02/14 11:46
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new InventoryStoreLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加门店盘存
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/02/14 11:46
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new InventoryStoreValidate())->post()->goCheck('add');
|
||||
$result = InventoryStoreLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(InventoryStoreLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑门店盘存
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/02/14 11:46
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new InventoryStoreValidate())->post()->goCheck('edit');
|
||||
$params['admin_id']=$this->adminId;
|
||||
$result = InventoryStoreLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(InventoryStoreLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 门店盘存核准
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/02/14 11:46
|
||||
*/
|
||||
public function enter_nums()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = InventoryStoreLogic::enterNums($params);
|
||||
if (true === $result) {
|
||||
return $this->success('核准成功', [], 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,8 +7,7 @@ use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\inventory_transfer\InventoryTransferLists;
|
||||
use app\admin\logic\inventory_transfer\InventoryTransferLogic;
|
||||
use app\admin\validate\inventory_transfer\InventoryTransferValidate;
|
||||
use app\admin\logic\inventory_transfer_order\InventoryTransferOrderLogic;
|
||||
use app\common\service\xlsx\InventoryTransferXlsx;
|
||||
|
||||
|
||||
/**
|
||||
* 商品调拨控制器
|
||||
@ -39,8 +38,8 @@ class InventoryTransferController extends BaseAdminController
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = InventoryTransferLogic::add($params, $this->adminId);
|
||||
$params = (new InventoryTransferValidate())->post()->goCheck('add');
|
||||
$result = InventoryTransferLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
@ -92,4 +91,6 @@ class InventoryTransferController extends BaseAdminController
|
||||
$result = InventoryTransferLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\inventory_transfer_order;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\inventory_transfer_order\InventoryTransferOrderLists;
|
||||
use app\admin\logic\inventory_transfer_order\InventoryTransferOrderLogic;
|
||||
use app\admin\validate\inventory_transfer_order\InventoryTransferOrderValidate;
|
||||
use app\common\service\xlsx\InventoryTransferXlsx;
|
||||
use app\common\model\inventory_transfer\InventoryTransfer;
|
||||
|
||||
/**
|
||||
* 商品调拨订单控制器
|
||||
* Class InventoryTransferOrderController
|
||||
* @package app\admin\controller\inventory_transfer_order
|
||||
*/
|
||||
class InventoryTransferOrderController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品调拨订单列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/24 09:59
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new InventoryTransferOrderLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加商品调拨订单
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/24 09:59
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = InventoryTransferOrderLogic::add($params, $this->adminId);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(InventoryTransferOrderLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑商品调拨订单
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/24 09:59
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new InventoryTransferOrderValidate())->post()->goCheck('edit');
|
||||
$result = InventoryTransferOrderLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(InventoryTransferOrderLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除商品调拨订单
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/24 09:59
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new InventoryTransferOrderValidate())->post()->goCheck('delete');
|
||||
InventoryTransferOrderLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品调拨订单详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/24 09:59
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new InventoryTransferOrderValidate())->goCheck('detail');
|
||||
$result = InventoryTransferOrderLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 审核商品调拨订单
|
||||
* @author admin
|
||||
* @date 2025/01/24 09:59
|
||||
*/
|
||||
public function audit()
|
||||
{
|
||||
$params = (new InventoryTransferOrderValidate())->post()->goCheck('delete');
|
||||
$order = InventoryTransferOrderLogic::detail($params);
|
||||
InventoryTransferOrderLogic::audit($order);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出调拨表格
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$xlsx = new InventoryTransferXlsx();
|
||||
$order = InventoryTransferOrderLogic::detail($params);
|
||||
$file_path = $xlsx->export($order['product_list'], $order);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\inventory_warehouse;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\inventory_warehouse\InventoryWarehouseLists;
|
||||
use app\admin\logic\inventory_warehouse\InventoryWarehouseLogic;
|
||||
use app\admin\validate\inventory_warehouse\InventoryWarehouseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 仓库盘存控制器
|
||||
* Class InventoryWarehouseController
|
||||
* @package app\admin\controller\inventory_warehouse
|
||||
*/
|
||||
class InventoryWarehouseController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取仓库盘存列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/02/14 17:24
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new InventoryWarehouseLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加仓库盘存
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/02/14 17:24
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new InventoryWarehouseValidate())->post()->goCheck('add');
|
||||
$result = InventoryWarehouseLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(InventoryWarehouseLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑仓库盘存
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/02/14 17:24
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new InventoryWarehouseValidate())->post()->goCheck('edit');
|
||||
$params['admin_id']=$this->adminId;
|
||||
$result = InventoryWarehouseLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(InventoryWarehouseLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除仓库盘存
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/02/14 17:24
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new InventoryWarehouseValidate())->post()->goCheck('delete');
|
||||
InventoryWarehouseLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 门店盘存核准
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/02/14 11:46
|
||||
*/
|
||||
public function enter_nums()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['warehouse_id']=1;
|
||||
$result = InventoryWarehouseLogic::enterNums($params);
|
||||
if (true === $result) {
|
||||
return $this->success('核准成功', [], 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\product_image;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\product_image\ProductImageLists;
|
||||
use app\admin\logic\product_image\ProductImageLogic;
|
||||
use app\admin\validate\product_image\ProductImageValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 商品图库管理控制器
|
||||
* Class ProductImageController
|
||||
* @package app\admin\controller\product_image
|
||||
*/
|
||||
class ProductImageController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品图库管理列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/04/14 11:02
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ProductImageLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加商品图库管理
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/04/14 11:02
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ProductImageValidate())->post()->goCheck('add');
|
||||
$result = ProductImageLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProductImageLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑商品图库管理
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/04/14 11:02
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ProductImageValidate())->post()->goCheck('edit');
|
||||
$result = ProductImageLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProductImageLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除商品图库管理
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/04/14 11:02
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ProductImageValidate())->post()->goCheck('delete');
|
||||
ProductImageLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品图库管理详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/04/14 11:02
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ProductImageValidate())->goCheck('detail');
|
||||
$result = ProductImageLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\product_source_link;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\product_source_link\ProductSourceLinkLists;
|
||||
use app\admin\logic\product_source_link\ProductSourceLinkLogic;
|
||||
use app\admin\validate\product_source_link\ProductSourceLinkValidate;
|
||||
use app\common\model\product_source_link\ProductSourceLink;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\service\xlsx\ProductSourceLinkXsl;
|
||||
|
||||
|
||||
/**
|
||||
* 商品溯源管理控制器
|
||||
* Class ProductSourceLinkController
|
||||
* @package app\admin\controller\product_source_link
|
||||
*/
|
||||
class ProductSourceLinkController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品溯源管理列表
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:03
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ProductSourceLinkLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加商品溯源管理
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:03
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ProductSourceLinkValidate())->post()->goCheck('add');
|
||||
$result = ProductSourceLinkLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProductSourceLinkLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑商品溯源管理
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:03
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ProductSourceLinkValidate())->post()->goCheck('edit');
|
||||
$result = ProductSourceLinkLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProductSourceLinkLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除商品溯源管理
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:03
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ProductSourceLinkValidate())->post()->goCheck('delete');
|
||||
ProductSourceLinkLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品溯源管理详情
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:03
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ProductSourceLinkValidate())->goCheck('detail');
|
||||
$result = ProductSourceLinkLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$query = ProductSourceLink::field('id,purchase_uid,product_id,warehouse_id');
|
||||
if (!empty($params['product_name'])) {
|
||||
$productIds = StoreProduct::where('store_name', 'like', "%{$params['product_name']}%")->column('id');
|
||||
$query->whereIn('product_id', $productIds);
|
||||
}
|
||||
if (!empty($params['purchase_uid'])) {
|
||||
$query->where('purchase_uid', $params['purchase_uid']);
|
||||
}
|
||||
if (!empty($params['warehouse_id'])) {
|
||||
$query->where('warehouse_id', $params['warehouse_id']);
|
||||
}
|
||||
$list = $query->with(['product', 'purchase'])
|
||||
->field(['id', 'purchase_uid', 'product_id'])
|
||||
->order(['id' => 'desc'])
|
||||
->group('purchase_uid,product_id')
|
||||
->select()
|
||||
->toArray();
|
||||
$linkInfos = ProductSourceLinkInfo::whereIn('oid', array_column($list, 'id'))->select()->toArray();
|
||||
$orderSnList = WarehouseProduct::field('id,code')->whereIn('id', array_unique(array_column($linkInfos, 'link_id')))->select()->toArray();
|
||||
$orderSnList = reset_index($orderSnList, 'id');
|
||||
foreach ($list as &$item) {
|
||||
$item['in_order_no'] = [];
|
||||
$item['out_order_no'] = [];
|
||||
$item['in_num'] = 0;
|
||||
$item['out_num'] = 0;
|
||||
foreach ($linkInfos as $linkInfo) {
|
||||
if ($linkInfo['oid'] == $item['id']) {
|
||||
$orderSnItem = $orderSnList[$linkInfo['link_id']] ?? [];
|
||||
if ($linkInfo['types'] == ProductSourceLinkInfo::TypeIn) {
|
||||
if (!empty($orderSnItem)) {
|
||||
$item['in_order_no'][] = $orderSnItem['code'];
|
||||
}
|
||||
$item['in_num'] = bcadd($item['in_num'], $linkInfo['nums'], 2);
|
||||
} else {
|
||||
if (!empty($orderSnItem)) {
|
||||
$item['out_order_no'][] = $orderSnItem['code'];
|
||||
}
|
||||
$item['out_num'] = bcadd($item['out_num'], $linkInfo['nums'], 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
$item['in_order_no'] = !empty($item['in_order_no']) ? implode(',', $item['in_order_no']) : '';
|
||||
$item['out_order_no'] =!empty($item['out_order_no']) ? implode(',', $item['out_order_no']) : '';
|
||||
}
|
||||
$file_path = (new ProductSourceLinkXsl())->export($list);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\product_source_link_info;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\product_source_link_info\ProductSourceLinkInfoLists;
|
||||
use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic;
|
||||
use app\admin\validate\product_source_link_info\ProductSourceLinkInfoValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 商品溯源详细控制器
|
||||
* Class ProductSourceLinkInfoController
|
||||
* @package app\admin\controller\product_source_link_info
|
||||
*/
|
||||
class ProductSourceLinkInfoController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品溯源详细列表
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:08
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ProductSourceLinkInfoLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加商品溯源详细
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:08
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ProductSourceLinkInfoValidate())->post()->goCheck('add');
|
||||
$result = ProductSourceLinkInfoLogic::add($params);
|
||||
if ($result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProductSourceLinkInfoLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑商品溯源详细
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:08
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ProductSourceLinkInfoValidate())->post()->goCheck('edit');
|
||||
$result = ProductSourceLinkInfoLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProductSourceLinkInfoLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除商品溯源详细
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:08
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ProductSourceLinkInfoValidate())->post()->goCheck('delete');
|
||||
ProductSourceLinkInfoLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品溯源详细详情
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:08
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ProductSourceLinkInfoValidate())->goCheck('detail');
|
||||
$result = ProductSourceLinkInfoLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -39,24 +39,11 @@ class PurchaseProductOfferController extends BaseAdminController
|
||||
public function add()
|
||||
{
|
||||
$params = (new PurchaseProductOfferValidate())->post()->goCheck('add');
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$result = PurchaseProductOfferLogic::add($params);
|
||||
return $this->success('设置成功', [], 1, 1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 一键添加往期采购商品
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/14 15:06
|
||||
*/
|
||||
public function add_purchases_one_click()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$result = PurchaseProductOfferLogic::AddPurchasesOneClick($params);
|
||||
return $this->success('设置成功', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑采购商品
|
||||
@ -109,12 +96,12 @@ class PurchaseProductOfferController extends BaseAdminController
|
||||
PurchaseProductOfferLogic::setStoreroomInfo($params);
|
||||
return $this->success('设置成功', [], 1, 1);
|
||||
}
|
||||
// public function setStoreroomInfoTwo()
|
||||
// {
|
||||
// $params = $this->request->post();
|
||||
// PurchaseProductOfferLogic::setStoreroomInfoTwo($params);
|
||||
// return $this->success('设置成功', [], 1, 1);
|
||||
// }
|
||||
public function setStoreroomInfoTwo()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
PurchaseProductOfferLogic::setStoreroomInfoTwo($params);
|
||||
return $this->success('设置成功', [], 1, 1);
|
||||
}
|
||||
/**
|
||||
* @notes 删除采购商品
|
||||
* @return \think\response\Json
|
||||
|
@ -93,8 +93,6 @@ class StoreBranchProductController extends BaseAdminController
|
||||
*/
|
||||
public function edit_stock()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
StoreBranchProductLogic::stock($params);
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
/**
|
||||
|
@ -91,10 +91,5 @@ class StoreCategoryController extends BaseAdminController
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
public function tree()
|
||||
{
|
||||
$result = StoreCategoryLogic::tree();
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
}
|
@ -77,12 +77,5 @@ 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]);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -10,7 +10,6 @@ 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;
|
||||
@ -22,7 +21,6 @@ use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\service\RefundOrderService;
|
||||
use app\common\service\xlsx\Beforehand;
|
||||
use app\common\service\xlsx\OrderDetail;
|
||||
use support\exception\BusinessException;
|
||||
@ -126,39 +124,20 @@ class StoreOrderController extends BaseAdminController
|
||||
* @return \support\Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function refund(RefundOrderService $refundOrderService)
|
||||
public function refund()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$detail = StoreOrder::where('order_id', $params['order_id'])->findOrEmpty();
|
||||
if (empty($detail)) {
|
||||
return $this->fail('无该订单请检查');
|
||||
}
|
||||
$params['id'] = $detail['id'];
|
||||
if (!isset($params['product_arr'])) {
|
||||
$params['product_arr'] = StoreOrderCartInfo::where('oid', $detail['id'])->where('status', '<>', 2)->field('product_id,cart_num')->select()->toArray();
|
||||
$res = StoreOrderLogic::refund($detail, $params);
|
||||
if ($res == false) {
|
||||
return $this->fail('退款失败');
|
||||
}
|
||||
$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('核销失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置配送员
|
||||
*/
|
||||
@ -263,7 +242,7 @@ class StoreOrderController extends BaseAdminController
|
||||
$data['purchase'] = $storeProduct['purchase'];
|
||||
$data['oid'] = $res['id'];
|
||||
$data['financial_pm'] = 0;
|
||||
WarehouseProductLogic::add($data,1,$this->adminId);
|
||||
WarehouseProductLogic::add($data);
|
||||
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
|
||||
}
|
||||
|
@ -11,19 +11,8 @@ use app\admin\validate\store_product\StoreProductValidate;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use TencentCloud\Common\Credential;
|
||||
use TencentCloud\Common\Profile\ClientProfile;
|
||||
use TencentCloud\Common\Profile\HttpProfile;
|
||||
use TencentCloud\Tiia\V20190529\Models\CreateImageRequest;
|
||||
use TencentCloud\Tiia\V20190529\Models\SearchImageRequest;
|
||||
use TencentCloud\Tiia\V20190529\TiiaClient;
|
||||
use Webman\RedisQueue\Redis;
|
||||
|
||||
use app\common\model\product_image\ProductImage;
|
||||
|
||||
use app\admin\logic\product_image\ProductImageLogic;
|
||||
|
||||
|
||||
/**
|
||||
* 商品列表控制器
|
||||
* Class StoreProductController
|
||||
@ -32,7 +21,6 @@ use app\admin\logic\product_image\ProductImageLogic;
|
||||
class StoreProductController extends BaseAdminController
|
||||
{
|
||||
|
||||
public $notNeedLogin = ['upload', 'recognition'];
|
||||
|
||||
/**
|
||||
* @notes 获取商品列表列表
|
||||
@ -136,105 +124,89 @@ class StoreProductController extends BaseAdminController
|
||||
return $this->success('复制成功', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 复制商品到仓库
|
||||
* @author likeadmin
|
||||
* @date 2024/05/31 10:53
|
||||
*/
|
||||
public function copyWarehouse()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
StoreProductLogic::copyWarehouse($params);
|
||||
return $this->success('复制成功', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品导入到门店
|
||||
*/
|
||||
public function import()
|
||||
{
|
||||
return $this->fail('接口已关闭');
|
||||
}
|
||||
|
||||
public function restore()
|
||||
{
|
||||
$params = (new StoreProductValidate())->post()->goCheck('delete');
|
||||
StoreProductLogic::restore($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
public function upload()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
// $params = [
|
||||
// 'ProductId' => '1024',
|
||||
// 'GroupId' => 'default',
|
||||
// ];
|
||||
$storeName = StoreProduct::where('id', $params['ProductId'])->value('store_name');
|
||||
$product_num = ProductImage::where('product_id', $params['ProductId'])->count('id');
|
||||
$cred = new Credential(getenv('TENCENT_SECRET_ID'), getenv('TENCENT_SECRET_KEY'));
|
||||
$httpProfile = new HttpProfile();
|
||||
$httpProfile->setEndpoint("tiia.tencentcloudapi.com");
|
||||
$clientProfile = new ClientProfile();
|
||||
$clientProfile->setHttpProfile($httpProfile);
|
||||
$client = new TiiaClient($cred, "ap-guangzhou", $clientProfile);
|
||||
$req = new CreateImageRequest();
|
||||
$file = $this->request->file('file');
|
||||
$filePath = $file->getRealPath();
|
||||
$fileName = $file->getuploadName();
|
||||
$file = file_get_contents($filePath);
|
||||
// $fileName ="矿泉水7";
|
||||
// $file = file_get_contents(public_path() . '/' . $fileName. '.jpg');
|
||||
$ImageParams = [
|
||||
'GroupId' => $params['GroupId'],
|
||||
'EntityId' => $params['ProductId'].'_'.$storeName.'_'.intval($product_num+1),
|
||||
'PicName' => $params['ProductId'].'_'.$fileName,
|
||||
'ImageBase64' => base64_encode($file)
|
||||
];
|
||||
$req->fromJsonString(json_encode($ImageParams));
|
||||
$resp = $client->CreateImage($req);
|
||||
$CreateParams = [
|
||||
'product_id' => $params['ProductId'],
|
||||
'group_id' => $ImageParams['GroupId'],
|
||||
'entity_id' => $ImageParams['EntityId'],
|
||||
'pic_name' => $ImageParams['PicName'],
|
||||
];
|
||||
ProductImageLogic::add($CreateParams);
|
||||
$result = json_decode($resp->toJsonString(), true);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
public function recognition()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
// $params = [
|
||||
// 'GroupId' => 'default',
|
||||
// ];
|
||||
$cred = new Credential(getenv('TENCENT_SECRET_ID'), getenv('TENCENT_SECRET_KEY'));
|
||||
$httpProfile = new HttpProfile();
|
||||
$httpProfile->setEndpoint("tiia.tencentcloudapi.com");
|
||||
$clientProfile = new ClientProfile();
|
||||
$clientProfile->setHttpProfile($httpProfile);
|
||||
$client = new TiiaClient($cred, "ap-guangzhou", $clientProfile);
|
||||
$req = new SearchImageRequest();
|
||||
$file = $this->request->file('file');
|
||||
$filePath = $file->getRealPath();
|
||||
$file = file_get_contents($filePath);
|
||||
// $fileName ="鱿鱼";
|
||||
// $file = file_get_contents(public_path() . '/' . $fileName. '.jpg');
|
||||
$ImageParams = [
|
||||
'GroupId' => $params['GroupId'],
|
||||
'ImageBase64' => base64_encode($file)
|
||||
];
|
||||
$req->fromJsonString(json_encode($ImageParams));
|
||||
$resp = $client->SearchImage($req);
|
||||
if(!empty($resp->ImageInfos)){
|
||||
$ids = array_column($resp->ImageInfos,'EntityId');
|
||||
$data = ProductImage::whereIn('entity_id', $ids)->field('product_id,group_id,entity_id,pic_name')->group(['product_id', 'entity_id'])->select();
|
||||
$resp->ImageInfos = $data->toArray();
|
||||
$resp->Count = $data->count('product_id');
|
||||
$product_arr = $this->request->post('product_arr');
|
||||
$store_arr = $this->request->post('store_arr');
|
||||
$stock_type = $this->request->post('stock_type', 1);
|
||||
$warehouse_id = $this->request->post('warehouse_id');
|
||||
$count = count($store_arr);
|
||||
foreach ($product_arr as $key => $arr) {
|
||||
$stock = bcmul($arr['stock'], $count);
|
||||
$nums = WarehouseProductStorege::where('warehouse_id', $warehouse_id)->where('product_id', $arr['id'])->value('nums');
|
||||
if ($nums < $stock) {
|
||||
return $this->fail('商品库存不足');
|
||||
}
|
||||
}
|
||||
$result = json_decode($resp->toJsonString(), true);
|
||||
return $this->data($result);
|
||||
if ($count == 1) {
|
||||
$store_id = $store_arr[0];
|
||||
foreach ($product_arr as $key => $arr) {
|
||||
$data = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'product_id' => $arr['id'],
|
||||
'store_id' => $store_id,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $this->adminId,
|
||||
];
|
||||
if ($arr['stock'] == 0) {
|
||||
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
} else {
|
||||
WarehouseProductLogic::add($data);
|
||||
$find = StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->find();
|
||||
if ($find) {
|
||||
StoreBranchProduct::where('id', $find['id'])->inc('stock', $arr['stock'])->update();
|
||||
} else {
|
||||
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update();
|
||||
}
|
||||
}
|
||||
// StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
|
||||
// Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]);
|
||||
}
|
||||
} else {
|
||||
foreach ($product_arr as $key => $arr) {
|
||||
foreach ($store_arr as $k => $store_id) {
|
||||
$data = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'product_id' => $arr['id'],
|
||||
'store_id' => $store_id,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $this->adminId,
|
||||
];
|
||||
if ($arr['stock'] == 0) {
|
||||
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
} else {
|
||||
WarehouseProductLogic::add($data);
|
||||
$find = StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->find();
|
||||
if ($find) {
|
||||
StoreBranchProduct::where('id', $find['id'])->inc('stock', $arr['stock'])->update();
|
||||
} else {
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update();
|
||||
}
|
||||
}
|
||||
|
||||
// $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
// StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
// Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\store_product_low_stock;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\store_product_low_stock\StoreProductLowStockLists;
|
||||
use app\admin\logic\store_product_low_stock\StoreProductLowStockLogic;
|
||||
use app\admin\validate\store_product_low_stock\StoreProductLowStockValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 商品缺库存控制器
|
||||
* Class StoreProductLowStockController
|
||||
* @package app\admin\controller\store_product_low_stock
|
||||
*/
|
||||
class StoreProductLowStockController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品缺库存列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/07 16:39
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new StoreProductLowStockLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加商品缺库存
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/07 16:39
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new StoreProductLowStockValidate())->post()->goCheck('add');
|
||||
$result = StoreProductLowStockLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreProductLowStockLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑商品缺库存
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/07 16:39
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new StoreProductLowStockValidate())->post()->goCheck('edit');
|
||||
$result = StoreProductLowStockLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreProductLowStockLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除商品缺库存
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/07 16:39
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new StoreProductLowStockValidate())->post()->goCheck('delete');
|
||||
StoreProductLowStockLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品缺库存详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/07 16:39
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new StoreProductLowStockValidate())->goCheck('detail');
|
||||
$result = StoreProductLowStockLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -6,7 +6,6 @@ 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_product_price\StoreProductPriceLogic;
|
||||
use app\admin\service\ProductPriceService;
|
||||
use app\admin\validate\store_product_price\StoreProductPriceValidate;
|
||||
|
||||
|
||||
@ -101,35 +100,5 @@ 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]);
|
||||
}
|
||||
|
||||
public function chart()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$data = StoreProductPriceLogic::chart($params);
|
||||
return $this->data($data);
|
||||
}
|
||||
|
||||
public function getRate(ProductPriceService $productPriceService)
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$productPriceRate = $productPriceService->getProductPriceRate($params['product_id'], true);
|
||||
return $this->data($productPriceRate);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$params = request()->post();
|
||||
$result = StoreProductPriceLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreProductPriceLogic::getError());
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,6 @@ namespace app\admin\controller\system_store_storage;
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\system_store_storage\SystemStoreStorageLists;
|
||||
use app\admin\lists\warehouse_product\StoreWarehouseProductLists;
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\admin\logic\system_store_storage\SystemStoreStorageLogic;
|
||||
use app\admin\validate\system_store_storage\SystemStoreStorageValidate;
|
||||
@ -30,8 +29,7 @@ class SystemStoreStorageController extends BaseAdminController
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
// return $this->dataLists(new SystemStoreStorageLists());
|
||||
return $this->dataLists(new StoreWarehouseProductLists());
|
||||
return $this->dataLists(new SystemStoreStorageLists());
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +62,7 @@ class SystemStoreStorageController extends BaseAdminController
|
||||
if($id==0){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
SystemStoreStorageLogic::edit(['id'=>$id,'admin_id'=>$this->adminId], $this->adminId);
|
||||
SystemStoreStorageLogic::edit(['id'=>$id,'admin_id'=>$this->adminId]);
|
||||
return $this->success('操作成功',[]);
|
||||
}
|
||||
|
||||
@ -96,21 +94,5 @@ class SystemStoreStorageController extends BaseAdminController
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 批量确认入库
|
||||
*/
|
||||
public function batchConfirm()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
SystemStoreStorageLogic::editAll($params, $this->adminId);
|
||||
return $this->success('操作成功',[]);
|
||||
}
|
||||
|
||||
public function rollback()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
SystemStoreStorageLogic::rollback($params);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
||||
}
|
@ -71,59 +71,65 @@ class WarehouseOrderController extends BaseAdminController
|
||||
public function outbound()
|
||||
{
|
||||
$product_arr = $this->request->post('product_arr');
|
||||
$store_arr = $this->request->post('store_arr');
|
||||
$warehouse_id = $this->request->post('warehouse_id');
|
||||
$delivery_time = $this->request->post('delivery_time');
|
||||
$mark = $this->request->post('mark');
|
||||
$type = $this->request->post('order_type', 1);
|
||||
$count = count($store_arr);
|
||||
// foreach ($product_arr as $key => $arr) {
|
||||
// $stock = bcmul($arr['stock'], $count);
|
||||
// $nums = WarehouseProductStorege::where('warehouse_id', $warehouse_id)->where('product_id', $arr['id'])->value('nums');
|
||||
// if ($nums < $stock) {
|
||||
// return $this->fail('商品库存不足');
|
||||
// }
|
||||
// }
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($type==1){
|
||||
$code=getNewOrderId('TGY');
|
||||
}else{
|
||||
$code=getNewOrderId('BS');
|
||||
}
|
||||
$arr = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'store_id' => 0,
|
||||
'supplier_id' => 0,
|
||||
'code' => $code,
|
||||
'admin_id' => $this->adminId,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 0,
|
||||
'mark' => $mark ?? "",
|
||||
];
|
||||
$arr['delivery_time'] = strtotime($delivery_time);
|
||||
$res = WarehouseOrder::create($arr);
|
||||
foreach ($product_arr as $key => $arr) {
|
||||
$data = [
|
||||
if ($count == 1) {
|
||||
$store_id = $store_arr[0];
|
||||
$arr = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'product_id' => $arr['id'],
|
||||
'store_id' => 0,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'status' => 1,
|
||||
'store_id' => $store_id,
|
||||
'supplier_id' => 0,
|
||||
'code' => getNewOrderId('PS'),
|
||||
'admin_id' => $this->adminId,
|
||||
'type' => $type,
|
||||
'order_type' => 0,
|
||||
'code' => $code,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 0,
|
||||
'mark' => $mark ?? "",
|
||||
];
|
||||
$storeProduct = StoreProduct::where('id', $arr['id'])->find();
|
||||
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
|
||||
$data['purchase'] = $storeProduct['purchase'];
|
||||
$data['oid'] = $res['id'];
|
||||
$data['financial_pm'] = 0;
|
||||
$data['price'] = $storeProduct['price'];
|
||||
WarehouseProductLogic::setOutbound($data,1,$this->adminId);
|
||||
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
|
||||
$arr['delivery_time'] = strtotime($delivery_time);
|
||||
$res = WarehouseOrder::create($arr);
|
||||
foreach ($product_arr as $key => $arr) {
|
||||
$data = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'product_id' => $arr['id'],
|
||||
'store_id' => $store_id,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $this->adminId,
|
||||
];
|
||||
$storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
if ($arr['stock'] == 0) {
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $storeProduct);
|
||||
} else {
|
||||
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
|
||||
$data['purchase'] = $storeProduct['purchase'];
|
||||
$data['oid'] = $res['id'];
|
||||
$data['financial_pm'] = 0;
|
||||
WarehouseProductLogic::add($data);
|
||||
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
return $this->success('出库成功', [], 1, 1);
|
||||
return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -136,7 +142,7 @@ class WarehouseOrderController extends BaseAdminController
|
||||
public function edit()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$params['admin_id']=$this->adminId;
|
||||
$result = WarehouseOrderLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
@ -149,8 +155,7 @@ class WarehouseOrderController extends BaseAdminController
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function update_edit()
|
||||
{
|
||||
public function update_edit(){
|
||||
$params = $this->request->post();
|
||||
$result = WarehouseOrderLogic::update_edit($params);
|
||||
if (true === $result) {
|
||||
@ -207,19 +212,19 @@ class WarehouseOrderController extends BaseAdminController
|
||||
$value->unit_name = '';
|
||||
}
|
||||
$order['total_num'] += $value->nums;
|
||||
$value->supplier_name = Supplier::where('id', $value->supplier_id)->value('mer_name');
|
||||
if ($value->pay_type == 1) {
|
||||
$value->supplier_name= Supplier::where('id', $value->supplier_id)->value('mer_name');
|
||||
if($value->pay_type==1){
|
||||
$credit_pay += $value->total_price;
|
||||
$value->pay_type_name = '赊账';
|
||||
} elseif ($value->pay_type == 2) {
|
||||
$value->pay_type_name='赊账';
|
||||
}elseif($value->pay_type==2){
|
||||
$cash_pay += $value->total_price;
|
||||
$value->pay_type_name = '现款';
|
||||
} else {
|
||||
$value->pay_type_name = '未设置';
|
||||
$value->pay_type_name='现款';
|
||||
}else{
|
||||
$value->pay_type_name='未设置';
|
||||
}
|
||||
}
|
||||
$order['credit_pay'] = $credit_pay;
|
||||
$order['cash_pay'] = $cash_pay;
|
||||
$order['credit_pay']=$credit_pay;
|
||||
$order['cash_pay']=$cash_pay;
|
||||
$file_path = $xlsx->export($data, $order);
|
||||
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
@ -232,7 +237,7 @@ class WarehouseOrderController extends BaseAdminController
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$type = $this->request->post('type');
|
||||
if (in_array($type, [2, 3])) {
|
||||
if(in_array($type, [2,3])){
|
||||
return $this->fail('暂不支持此操作');
|
||||
}
|
||||
$xlsx = new OrderDetail();
|
||||
@ -240,11 +245,11 @@ class WarehouseOrderController extends BaseAdminController
|
||||
$system_store = SystemStore::where('id', $order['store_id'])->value('name');
|
||||
$data = WarehouseProduct::where('oid', $id)->select();
|
||||
$order['total_num'] = 0;
|
||||
$total_price = 0;
|
||||
$total_price=0;
|
||||
foreach ($data as $key => &$value) {
|
||||
if (in_array($order['store_id'], [17, 18])) {
|
||||
$find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id', $order['store_id'])->withTrashed()->find();
|
||||
} else {
|
||||
if(in_array($order['store_id'],[17,18])){
|
||||
$find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->withTrashed()->find();
|
||||
}else{
|
||||
$find = StoreProduct::where('id', $value->product_id)->withTrashed()->find();
|
||||
}
|
||||
$value->store_name = $find['store_name'] ?? '';
|
||||
@ -262,10 +267,10 @@ class WarehouseOrderController extends BaseAdminController
|
||||
// $value->total_price=bcmul($find['price'],$value['nums'],2);
|
||||
// $total_price+=$value->total_price;
|
||||
// }else{
|
||||
if ($type == 1) {
|
||||
if($type==1){
|
||||
$value->price = $value['purchase'];
|
||||
$value->total_price = bcmul($value['purchase'], $value['nums'], 2);
|
||||
$total_price += $value->total_price;
|
||||
$value->total_price=bcmul($value['purchase'],$value['nums'],2);
|
||||
$total_price+=$value->total_price;
|
||||
}
|
||||
|
||||
|
||||
@ -278,25 +283,25 @@ class WarehouseOrderController extends BaseAdminController
|
||||
}
|
||||
$order['total_num'] += $value->nums;
|
||||
}
|
||||
if ($type == 2) {
|
||||
$order['total_price'] = $total_price;
|
||||
if($type==2){
|
||||
$order['total_price']=$total_price;
|
||||
}
|
||||
$order['delivery_time'] = date('Y-m-d H:i:s', $order['delivery_time']);
|
||||
$order['pay_time'] = $order['create_time'];
|
||||
$order['order_id'] = $order['code'];
|
||||
$order['delivery_time']=date('Y-m-d H:i:s',$order['delivery_time']);
|
||||
$order['pay_time']=$order['create_time'];
|
||||
$order['order_id']=$order['code'];
|
||||
|
||||
if ($order['oid'] > 0) {
|
||||
$orders = StoreOrder::where('id', $order['oid'])->findOrEmpty();
|
||||
$order['real_name'] = $orders['real_name'];
|
||||
$order['user_phone'] = $orders['user_phone'];
|
||||
$order['user_address'] = $orders['user_address'];
|
||||
if($order['oid']>0){
|
||||
$orders=StoreOrder::where('id',$order['oid'])->findOrEmpty();
|
||||
$order['real_name']=$orders['real_name'];
|
||||
$order['user_phone']=$orders['user_phone'];
|
||||
$order['user_address']=$orders['user_address'];
|
||||
}
|
||||
$file_path = $xlsx->export($data, $system_store, $order);
|
||||
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 导出标签
|
||||
*/
|
||||
public function export_tags()
|
||||
@ -304,26 +309,26 @@ class WarehouseOrderController extends BaseAdminController
|
||||
$id = $this->request->post('id');
|
||||
$warehouseOrder = WarehouseOrder::where('id', $id)->field('oid,store_id,delivery_time')->find();
|
||||
$system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('introduction');
|
||||
$data = WarehouseProduct::where('oid', $id)->where('financial_pm', 0)->field('oid,product_id,nums')->select()
|
||||
->each(function ($item) use ($system_store, $warehouseOrder) {
|
||||
$data = WarehouseProduct::where('oid', $id)->where('financial_pm',0)->field('oid,product_id,nums')->select()
|
||||
->each(function ($item) use ($system_store,$warehouseOrder) {
|
||||
$find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->withTrashed()->find();
|
||||
$unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
$item['system_store'] = $system_store;
|
||||
$item['subtitle'] = $item['oid'] . ' ' . convertStringToNumber($item['nums']) . '/' . $unit_name;
|
||||
$item['subtitle'] = $item['oid'].' '.convertStringToNumber($item['nums']).'/'.$unit_name;
|
||||
$item['store_name'] = $find['store_name'];
|
||||
if ($warehouseOrder['oid']) {
|
||||
$find = StoreOrder::where('id', $warehouseOrder['oid'])->field('real_name,user_address')->find();
|
||||
if ($find) {
|
||||
$item['address'] = $find['real_name'] . ' ' . $find['user_address'];
|
||||
} else {
|
||||
if($warehouseOrder['oid']){
|
||||
$find=StoreOrder::where('id',$warehouseOrder['oid'])->field('real_name,user_address')->find();
|
||||
if($find){
|
||||
$item['address'] = $find['real_name'].' '.$find['user_address'];
|
||||
}else{
|
||||
$item['address'] = '无地址';
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
$item['address'] = '无地址';
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
$file_path = (new Beforehand())->export($data, $system_store);
|
||||
$file_path=(new Beforehand())->export($data, $system_store);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
}
|
||||
|
@ -40,28 +40,28 @@ class WarehouseProductController extends BaseAdminController
|
||||
{
|
||||
return $this->fail('当前接口废弃');
|
||||
|
||||
// $params = $this->request->post();
|
||||
$params = $this->request->post();
|
||||
|
||||
// foreach ($params['product_arr'] as $k => $v) {
|
||||
// $data['admin_id'] = $this->adminId;
|
||||
// $data['store_id'] = 0;
|
||||
// $data['supplier_id'] = $params['supplier_id'];
|
||||
// $data['warehouse_id'] = $params['warehouse_id'];
|
||||
// $data['code'] = $params['code'];
|
||||
// $data['product_id'] = $v['product_id'];
|
||||
// $data['nums'] = $v['nums'];
|
||||
// $data['purchase'] = $v['purchase'];
|
||||
// $data['total_price'] = $v['total_price'];
|
||||
// $data['financial_pm'] = 1;
|
||||
// if (!empty($v['manufacture'])) {
|
||||
// $data['manufacture'] = $v['manufacture'];
|
||||
// }
|
||||
// if (!empty($v['expiration_date'])) {
|
||||
// $data['expiration_date'] = $v['expiration_date'];
|
||||
// }
|
||||
// WarehouseProductLogic::add($data);
|
||||
// }
|
||||
// return $this->success('添加成功', [], 1, 1);
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$data['admin_id'] = $this->adminId;
|
||||
$data['store_id'] = 0;
|
||||
$data['supplier_id'] = $params['supplier_id'];
|
||||
$data['warehouse_id'] = $params['warehouse_id'];
|
||||
$data['code'] = $params['code'];
|
||||
$data['product_id'] = $v['product_id'];
|
||||
$data['nums'] = $v['nums'];
|
||||
$data['purchase'] = $v['purchase'];
|
||||
$data['total_price'] = $v['total_price'];
|
||||
$data['financial_pm'] = 1;
|
||||
if (!empty($v['manufacture'])) {
|
||||
$data['manufacture'] = $v['manufacture'];
|
||||
}
|
||||
if (!empty($v['expiration_date'])) {
|
||||
$data['expiration_date'] = $v['expiration_date'];
|
||||
}
|
||||
WarehouseProductLogic::add($data);
|
||||
}
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ class WarehouseProductController extends BaseAdminController
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$result = WarehouseProductLogic::edit($params,$this->adminId);
|
||||
$result = WarehouseProductLogic::edit($params);
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ class WarehouseProductController extends BaseAdminController
|
||||
public function delete()
|
||||
{
|
||||
$params = (new WarehouseProductValidate())->post()->goCheck('delete');
|
||||
WarehouseProductLogic::delete($params,$this->adminId);
|
||||
WarehouseProductLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
|
||||
}
|
||||
@ -140,7 +140,7 @@ class WarehouseProductController extends BaseAdminController
|
||||
public function set_nums()
|
||||
{
|
||||
$params=$this->request->post();
|
||||
$result = WarehouseProductLogic::settNums($params,$this->adminId);
|
||||
$result = WarehouseProductLogic::settNums($params);
|
||||
return $this->success('');
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\warehouse_product_storege\WarehouseProductStoregeLists;
|
||||
use app\admin\logic\warehouse_product_storege\WarehouseProductStoregeLogic;
|
||||
use app\admin\validate\warehouse_product_storege\WarehouseProductStoregeValidate;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
|
||||
|
||||
/**
|
||||
* 仓库商品存储控制器
|
||||
@ -47,19 +47,21 @@ class WarehouseProductStoregeController extends BaseAdminController
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑仓库商品存储
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/01 10:22
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = WarehouseProductStoregeLogic::edit($params,$this->adminId);
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
|
||||
}
|
||||
// /**
|
||||
// * @notes 编辑仓库商品存储
|
||||
// * @return \think\response\Json
|
||||
// * @author admin
|
||||
// * @date 2024/08/01 10:22
|
||||
// */
|
||||
// public function edit()
|
||||
// {
|
||||
// $params = (new WarehouseProductStoregeValidate())->post()->goCheck('edit');
|
||||
// $result = WarehouseProductStoregeLogic::edit($params);
|
||||
// if (true === $result) {
|
||||
// return $this->success('编辑成功', [], 1, 1);
|
||||
// }
|
||||
// return $this->fail(WarehouseProductStoregeLogic::getError());
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
@ -88,15 +90,6 @@ class WarehouseProductStoregeController extends BaseAdminController
|
||||
// $result = WarehouseProductStoregeLogic::detail($params);
|
||||
// return $this->data($result);
|
||||
// }
|
||||
/**
|
||||
* @notes 修改商品状态
|
||||
* @return \think\response\Json
|
||||
* @date 2024/05/31 10:53
|
||||
*/
|
||||
public function verify(){
|
||||
$params=$this->request->post();
|
||||
WarehouseProductStorege::where('id',$params['id'])->update(['is_verify'=>$params['is_verify']]);
|
||||
return $this->success('操作成功',[],1,1);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\finance\AccountsReceivable;
|
||||
use app\common\model\finance\AccountsReceivableInfo;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
|
||||
/**
|
||||
* AccountsReceivableInfoLists
|
||||
* Class AccountsReceivableInfoLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class AccountsReceivableInfoLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['accounts_receivable_id'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$query = AccountsReceivableInfo::where($this->searchWhere);
|
||||
$list = $query
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
$accountReceivable = AccountsReceivable::field('id,store_id,nickname')->where('id', $this->params['accounts_receivable_id'])->findOrEmpty()->toArray();
|
||||
$store = SystemStore::where('id', $accountReceivable['store_id'])->value('name');
|
||||
$payTypeMap = [
|
||||
1 => '现金',
|
||||
2 => '微信支付',
|
||||
3 => '支付宝支付',
|
||||
4 => '对公账号',
|
||||
5 => '其他'
|
||||
];
|
||||
foreach ($list as &$item) {
|
||||
$item['store_name'] = $store;
|
||||
$item['pay_type_name'] = $payTypeMap[$item['pay_type']];
|
||||
$item['nickname'] = $accountReceivable['nickname'];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$query = AccountsReceivableInfo::where($this->searchWhere);
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\finance\AccountsReceivable;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
|
||||
/**
|
||||
* AccountsReceivableLists
|
||||
* Class AccountsReceivableLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class AccountsReceivableLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['store_id', 'user_id'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$query = AccountsReceivable::where($this->searchWhere);
|
||||
if (!empty($this->params['order_sn'])) {
|
||||
$orderIds = BeforehandOrder::where('order_id', 'like', '%' . $this->params['order_sn'] . '%')->column('id');
|
||||
$query->whereIn('order_id', $orderIds);
|
||||
}
|
||||
$list = $query->with('info')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
$stores = SystemStore::field('id,name')->whereIn('id', array_column($list, 'store_id'))->select()->toArray();
|
||||
$stores = reset_index($stores, 'id');
|
||||
$orderInfo = BeforehandOrder::field('id,order_id')->whereIn('id', array_column($list, 'order_id'))->select()->toArray();
|
||||
$orderInfo = reset_index($orderInfo, 'id');
|
||||
$orderInfo = reset_index($orderInfo, 'id');
|
||||
foreach ($list as &$item) {
|
||||
$item['store_name'] = $stores[$item['store_id']]['name'];
|
||||
$item['order_sn'] = $orderInfo[$item['order_id']]['order_id'];
|
||||
$item['debt_day'] = intval((time() - strtotime($item['create_time'])) / 86400);
|
||||
$item['deadline'] = date('Y-m-d H:i:s', $item['deadline']);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$query = AccountsReceivable::where($this->searchWhere);
|
||||
if (!empty($this->params['order_sn'])) {
|
||||
$orderIds = BeforehandOrder::where('order_id', 'like', '%' . $this->params['order_sn'] . '%')->column('id');
|
||||
$query->whereIn('order_id', $orderIds);
|
||||
}
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\ActivityZoneForm;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
|
||||
/**
|
||||
* ActivityZoneFormLists列表
|
||||
* Class ActivityZoneFormLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class ActivityZoneFormLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['type'],
|
||||
'%like%' => ['title'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$query = ActivityZoneForm::where($this->searchWhere);
|
||||
$cateIds = [];
|
||||
$list = $query
|
||||
->field(['id', 'type', 'cate_ids', 'title', 'remark'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->each(function ($item) use (&$cateIds) {
|
||||
$item['cate_ids'] = explode(',', $item['cate_ids']);
|
||||
foreach ($item['cate_ids'] as $cateId) {
|
||||
if (!empty($cateId) && !in_array($cateId, $cateIds)) {
|
||||
$cateIds[] = $cateId;
|
||||
}
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
$cateList = StoreCategory::where('id', 'in', $cateIds)->field('id,name')->select()->toArray();
|
||||
$cateList = reset_index($cateList, 'id');
|
||||
foreach ($list as &$item) {
|
||||
$item['cate_names'] = [];
|
||||
foreach ($item['cate_ids'] as $cateId) {
|
||||
if (isset($cateList[$cateId])) {
|
||||
$item['cate_names'][] = $cateList[$cateId]['name'];
|
||||
}
|
||||
}
|
||||
$item['cate_names'] = implode(',', $item['cate_names']);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$query = ActivityZoneForm::where($this->searchWhere);
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\ActivityZone;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
|
||||
|
||||
/**
|
||||
* ActivityZone列表
|
||||
* Class ActivityZoneLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class ActivityZoneLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['form_id'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$query = ActivityZone::where($this->searchWhere);
|
||||
if (!empty($this->params['store_name'])) {
|
||||
$productIds = StoreProduct::where('store_name', 'like', "%{$this->params['store_name']}%")->column('id');
|
||||
$query->whereIn('product_id', $productIds);
|
||||
}
|
||||
$list = $query->with('product')
|
||||
->field(['id', 'form_id', 'product_id'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
$unitIds = array_unique(array_column($list, 'unit'));
|
||||
$unit = StoreProductUnit::whereIn('id', $unitIds)->field('id,name')->withTrashed()->select()->toArray();
|
||||
$unit = reset_index($unit, 'id');
|
||||
foreach ($list as &$item) {
|
||||
$item['unit_name'] = $unit[$item['unit']]['name'] ?? '';
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$query = ActivityZone::where($this->searchWhere);
|
||||
if (!empty($this->params['store_name'])) {
|
||||
$productIds = StoreProduct::where('store_name', 'like', "%{$this->params['store_name']}%")->column('id');
|
||||
$query->whereIn('product_id', $productIds);
|
||||
}
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\ChangeLog;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\auth\Admin;
|
||||
|
||||
/**
|
||||
* ChangeLog列表
|
||||
* Class ChangeLogLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class ChangeLogLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['model', 'link_id', 'nums', 'pm'],
|
||||
'%like%' => ['mark', 'url'],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return ChangeLog::where($this->searchWhere)
|
||||
->field(['id', 'admin_id', 'model', 'link_id', 'nums', 'pm', 'url', 'mark', 'create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(
|
||||
function ($item) {
|
||||
if ($item->admin_id) {
|
||||
$item->admin_name = Admin::where('id', $item->admin_id)->value('name');
|
||||
} else {
|
||||
$item->admin_name = $item->admin_id;
|
||||
}
|
||||
}
|
||||
)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return ChangeLog::where($this->searchWhere)->count();
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,6 @@ 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;
|
||||
|
||||
@ -34,7 +33,7 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['id', 'store_id', 'paid', 'status', 'order_type', 'admin_id'],
|
||||
'=' => ['store_id', 'paid', 'status', 'order_type'],
|
||||
'%like' => ['order_id','order_sn'],
|
||||
'%like%' => ['mark'],
|
||||
'between_time' => 'create_time'
|
||||
@ -75,12 +74,6 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!empty($this->params['store_staff_id']) || !empty($this->params['is_store'])) {
|
||||
$this->searchWhere[] = ['store_staff_id', '>', 0];
|
||||
}
|
||||
// else {
|
||||
// $this->searchWhere[] = ['store_staff_id', '=', 0];
|
||||
// }
|
||||
if ($order_rk!='') {
|
||||
$oid=WarehouseOrder::where('financial_pm',1)->where('code','like','%'.$order_rk)->column('id');
|
||||
$this->searchWhere[] = ['warehousing_id','in',$oid];
|
||||
@ -88,27 +81,37 @@ 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', 'store_staff_id', 'is_arrears'];
|
||||
$query = BeforehandOrder::where($this->searchWhere);
|
||||
return $query
|
||||
$file=['id', 'order_id', 'order_sn','store_id', 'order_type', 'total_num', 'total_price', 'outbound_id', 'admin_id', 'create_time', 'status', 'mark', 'warehousing_id', 'file'];
|
||||
if($export==2){
|
||||
$file=['id', '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'];
|
||||
}
|
||||
return BeforehandOrder::where($this->searchWhere)
|
||||
->field($file)
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item)use($export) {
|
||||
$item['outbound'] = '';
|
||||
$item['outbound_time'] = '';
|
||||
$item['order_type_name'] = '';
|
||||
if ($item->admin_id) {
|
||||
$item->admin_name = Admin::where(['id' => $item->admin_id])->value('name');
|
||||
} else {
|
||||
$item->admin_name = '';
|
||||
}
|
||||
if ($item->store_staff_id) {
|
||||
$item->admin_name = SystemStoreStaff::where(['id' => $item->store_staff_id])->value('staff_name');
|
||||
}
|
||||
$item->order_type_name = BeforehandOrder::getOrderTypeName($item->order_type);
|
||||
if ($item->order_type == 5) {
|
||||
if ($item->order_type == 1) {
|
||||
$item->order_type_name = '铺货订单';
|
||||
} elseif ($item->order_type == 2) {
|
||||
$item->order_type_name = '商贩订单';
|
||||
} elseif ($item->order_type == 3) {
|
||||
$item->order_type_name = '一条龙订单';
|
||||
} elseif ($item->order_type == 4) {
|
||||
$item->order_type_name = '线上订单';
|
||||
} elseif ($item->order_type == 5) {
|
||||
$item->order_type_name = '仓库补货';
|
||||
$item->outbound = '无须出库';
|
||||
} elseif ($item->order_type == 6) {
|
||||
$item->order_type_name = '往期补单';
|
||||
} elseif ($item->order_type == 7) {
|
||||
$item->order_type_name = '采购订单';
|
||||
}
|
||||
$item->msg = '';
|
||||
$count1 = PurchaseProductOffer::where('order_id', $item->id)->where('buyer_confirm', 0)->count('id');
|
||||
@ -133,8 +136,6 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
|
||||
}
|
||||
if ($item['outbound_id'] > 0) {
|
||||
$item->outbound = '已出库|' . $item['outbound_id'];
|
||||
$outboundTime = WarehouseOrder::where('id', $item['outbound_id'])->value('create_time');
|
||||
$item->outbound_time = date('Y-m-d H:i:s', $outboundTime);
|
||||
}
|
||||
if ($item['store_id'] > 0) {
|
||||
$item->system_store = SystemStore::where(['id' => $item['store_id']])->value('name');
|
||||
@ -231,9 +232,6 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
if (!empty($this->params['store_staff_id'])) {
|
||||
$this->searchWhere[] = ['store_staff_id', '>', 0];
|
||||
}
|
||||
return BeforehandOrder::where($this->searchWhere)->count();
|
||||
}
|
||||
/**
|
||||
|
@ -76,21 +76,13 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
|
||||
$this->searchWhere[] = ['product_id', 'in', $ids];
|
||||
}
|
||||
}
|
||||
if (!empty($this->params['store_id'])) {
|
||||
$orderIds = BeforehandOrder::where('store_id', $this->params['store_id'])->column('id');
|
||||
$this->searchWhere[] = ['bhoid', 'in', $orderIds];
|
||||
}
|
||||
$list = BeforehandOrderCartInfo::where($this->searchWhere)
|
||||
->field(['id', 'bhoid', 'package', 'store_info', 'marques', 'gross_weight', 'net_weight', 'accept_num', 'after_sales', 'loss', 'uid', 'pay_price', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'purchase', 'price', 'total_price', 'cart_num', 'mark','create_time', 'procurement_order_id', 'store_sale'])
|
||||
->field(['id', 'bhoid', 'package', 'store_info', 'marques', 'gross_weight', 'net_weight', 'accept_num', 'after_sales', 'loss', 'uid', 'pay_price', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'purchase', 'price', 'total_price', 'cart_num', 'mark','create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) use ($system_store, $order_mark) {
|
||||
$find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,image,unit')->withTrashed()->find();
|
||||
if($find->unit>0){
|
||||
$item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name');
|
||||
}else{
|
||||
$item->unit_name = '';
|
||||
}
|
||||
$item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name');
|
||||
$item['warehouse_stock'] = WarehouseProductStorege::where('product_id', $item['product_id'])->where('warehouse_id',1)->value('nums') ?? 0;
|
||||
$item['store_name'] = $find['store_name'];
|
||||
$item['system_store'] = $system_store;
|
||||
@ -100,11 +92,7 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
|
||||
$item['top_cate_id'] = $find['top_cate_id'];
|
||||
$item['top_cate_name'] = StoreCategory::where('id', $item['top_cate_id'])->value('name');
|
||||
if ($item->bhoid) {
|
||||
$rawSql = "JSON_CONTAINS(source_order_info, '{\"source_order_id\": {$item->bhoid}}')";
|
||||
$status = PurchaseProductOffer::where(['product_id' => $item->product_id])->whereRaw($rawSql)->value('status');
|
||||
if (is_null($status)) {
|
||||
$status = PurchaseProductOffer::where('order_id', $item->bhoid)->where('product_id', $item->product_id)->value('status');
|
||||
}
|
||||
$status = PurchaseProductOffer::where('order_id', $item->bhoid)->where('product_id', $item->product_id)->value('status');
|
||||
if ($status == 1) {
|
||||
$item->status_name = '已完成';
|
||||
} else {
|
||||
@ -122,12 +110,6 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
$orderTypeMap = BeforehandOrder::whereIn('id', array_unique(array_column($list, 'bhoid')))->field('id, order_type')->select()->toArray();
|
||||
$orderTypeMap = reset_index($orderTypeMap, 'id');
|
||||
foreach ($list as &$item) {
|
||||
$orderType = $orderTypeMap[$item['bhoid']]['order_type'] ?? '';
|
||||
$item['order_type_name'] = BeforehandOrder::getOrderTypeName($orderType);
|
||||
}
|
||||
$this->list = $list;
|
||||
return $list;
|
||||
}
|
||||
@ -141,10 +123,6 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
if (!empty($this->params['store_id'])) {
|
||||
$orderIds = BeforehandOrder::where('store_id', $this->params['store_id'])->column('id');
|
||||
$this->searchWhere[] = ['bhoid', 'in', $orderIds];
|
||||
}
|
||||
return BeforehandOrderCartInfo::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
|
@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\inventory_store;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\inventory_store\InventoryStore;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\system_store\SystemStoreStaff;
|
||||
|
||||
/**
|
||||
* 门店盘存列表
|
||||
* Class InventoryStoreLists
|
||||
* @package app\admin\listsinventory_store
|
||||
*/
|
||||
class InventoryStoreLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2025/02/14 11:46
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['store_id', 'nums', 'enter_nums', 'status'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取门店盘存列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2025/02/14 11:46
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return InventoryStore::where($this->searchWhere)
|
||||
->field(['id', 'product_id', 'admin_id', 'staff_id', 'store_id', 'nums', 'enter_nums', 'status', 'create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['create_time' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
$item->status_name = match ($item->status) {
|
||||
0 => '待盘点',
|
||||
1 => '盘点中',
|
||||
2 => '盘点完成',
|
||||
default => '未知',
|
||||
};
|
||||
if($item->admin_id){
|
||||
$item->admin_name = Admin::where('id',$item->admin_id)->value('name');
|
||||
}
|
||||
if($item->staff_id){
|
||||
$item->staff_name = SystemStoreStaff::where('id',$item->staff_id)->value('staff_name');
|
||||
}
|
||||
if($item->store_id){
|
||||
$item->store_name = SystemStore::where('id',$item->store_id)->value('name');
|
||||
}
|
||||
if($item->product_id){
|
||||
$item->product_name = StoreProduct::where('id',$item->product_id)->withTrashed()->value('store_name');
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取门店盘存数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2025/02/14 11:46
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return InventoryStore::where($this->searchWhere)->count();
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\warehouse\Warehouse;
|
||||
use app\common\lists\ListsExcelInterface;
|
||||
use app\common\model\inventory_transfer_order\InventoryTransferOrder;
|
||||
|
||||
/**
|
||||
* 商品调拨列表
|
||||
@ -33,7 +32,7 @@ class InventoryTransferLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['type', 'product_id'],
|
||||
'=' => ['type'],
|
||||
'between_time' => 'create_time'
|
||||
];
|
||||
}
|
||||
@ -60,27 +59,23 @@ class InventoryTransferLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
return [];
|
||||
}
|
||||
}
|
||||
if ($this->request->get('order_id')) {
|
||||
$this->store_name = $this->request->get('order_id');
|
||||
$ids = InventoryTransferOrder::where('order_id', 'like', $this->request->get('order_id') . '%')->column('id');
|
||||
if ($this->request->get('bar_code')) {
|
||||
$this->bar_code = $this->request->get('bar_code');
|
||||
$ids = StoreProduct::where('bar_code', 'like', '%' . $this->bar_code . '%')->column('id');
|
||||
if ($ids) {
|
||||
$this->searchWhere[] = ['oid', 'in', $ids];
|
||||
$this->searchWhere[] = ['product_id', 'in', $ids];
|
||||
$this->ids = $ids;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
$query = InventoryTransfer::where($this->searchWhere);
|
||||
if (!empty($this->params['warehouse_id'])) {
|
||||
$query->whereRaw("(one_type=2 and one_id={$this->params['warehouse_id']}) or (two_type=2 and two_id={$this->params['warehouse_id']})");
|
||||
}
|
||||
return $query
|
||||
->field(['id','oid', 'product_id', 'nums', 'one_before_nums', 'one_after_nums','two_before_nums','two_after_nums', 'one_type','two_type', 'one_id', 'two_id', 'create_time'])
|
||||
|
||||
return InventoryTransfer::where($this->searchWhere)
|
||||
->field(['id', 'product_id', 'nums', 'one_before_nums', 'one_after_nums','two_before_nums','two_after_nums', 'one_type','two_type', 'one_id', 'two_id', 'create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($item){
|
||||
$find= StoreProduct::where('id',$item->product_id)->withTrashed()->field('store_name,price')->find();
|
||||
$item->order_id= InventoryTransferOrder::where('id',$item->oid)->value('order_id');
|
||||
$item->store_name=$find['store_name'];
|
||||
$item->price=$find['price'];
|
||||
$item->total_price=bcmul($find['price'],$item['nums'],2);
|
||||
@ -121,11 +116,7 @@ class InventoryTransferLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
$query = InventoryTransfer::where($this->searchWhere);
|
||||
if (!empty($this->params['warehouse_id'])) {
|
||||
$query->whereRaw("(one_type=2 and one_id={$this->params['warehouse_id']}) or (two_type=2 and two_id={$this->params['warehouse_id']})");
|
||||
}
|
||||
return $query->count();
|
||||
return InventoryTransfer::where($this->searchWhere)->count();
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,9 +141,8 @@ class InventoryTransferLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
public function setExcelFields(): array
|
||||
{
|
||||
$data = [
|
||||
'order_id' => '订单号',
|
||||
'store_name' => '商品名称',
|
||||
'nums' => '数量',
|
||||
'one_before_nums' => '数量',
|
||||
'one_name' => '转出方',
|
||||
'one_before_nums' => '转出前数量',
|
||||
'one_after_nums' => '转出后数量',
|
||||
|
@ -1,89 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\inventory_transfer_order;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\inventory_transfer_order\InventoryTransferOrder;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\warehouse\Warehouse;
|
||||
|
||||
/**
|
||||
* 商品调拨订单列表
|
||||
* Class InventoryTransferOrderLists
|
||||
* @package app\admin\listsinventory_transfer_order
|
||||
*/
|
||||
class InventoryTransferOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2025/01/24 09:59
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['id', 'order_id', 'one_type', 'two_type', 'types'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品调拨订单列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2025/01/24 09:59
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return InventoryTransferOrder::where($this->searchWhere)
|
||||
->field(['id', 'order_id', 'one_id', 'one_type', 'two_id', 'two_type', 'types', 'total_nums', 'total_price','mark', 'status'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
$type_name='';
|
||||
if($item->one_type==1){
|
||||
$item->one_name=SystemStore::where('id',$item->one_id)->value('name');
|
||||
$type_name='门店转';
|
||||
}else{
|
||||
$item->one_name=Warehouse::where('id',$item->one_id)->value('name');
|
||||
$type_name='仓库转';
|
||||
}
|
||||
if($item->two_type==1){
|
||||
$type_name.='门店';
|
||||
$item->two_name=SystemStore::where('id',$item->two_id)->value('name');
|
||||
}else{
|
||||
$type_name.='仓库';
|
||||
$item->two_name=Warehouse::where('id',$item->two_id)->value('name');
|
||||
}
|
||||
$item->type_name=$type_name;
|
||||
if($item->types==0){
|
||||
$item->types_name='正常减库';
|
||||
}else{
|
||||
$item->types_name='异常数据';
|
||||
}
|
||||
})
|
||||
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品调拨订单数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2025/01/24 09:59
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return InventoryTransferOrder::where($this->searchWhere)->count();
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\inventory_warehouse;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\inventory_warehouse\InventoryWarehouse;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
|
||||
/**
|
||||
* 仓库盘存列表
|
||||
* Class InventoryWarehouseLists
|
||||
* @package app\admin\listsinventory_warehouse
|
||||
*/
|
||||
class InventoryWarehouseLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2025/02/14 17:24
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['product_id', 'warehouse_id'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取仓库盘存列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2025/02/14 17:24
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return InventoryWarehouse::where($this->searchWhere)
|
||||
->field(['id', 'product_id', 'admin_id', 'warehouse_id', 'nums', 'enter_nums', 'status','create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
$item->status_name = match ($item->status) {
|
||||
0 => '待盘点',
|
||||
1 => '盘点中',
|
||||
2 => '盘点完成',
|
||||
default => '未知',
|
||||
};
|
||||
if($item->admin_id){
|
||||
$item->admin_name = Admin::where('id',$item->admin_id)->value('name');
|
||||
}
|
||||
if($item->product_id){
|
||||
$item->product_name = StoreProduct::where('id',$item->product_id)->withTrashed()->value('store_name');
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取仓库盘存数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2025/02/14 17:24
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return InventoryWarehouse::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\product_image;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\product_image\ProductImage;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* 商品图库管理列表
|
||||
* Class ProductImageLists
|
||||
* @package app\admin\listsproduct_image
|
||||
*/
|
||||
class ProductImageLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2025/04/14 11:02
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['product_id', 'entity_id', 'group_id', 'pic_name'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品图库管理列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2025/04/14 11:02
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return ProductImage::where($this->searchWhere)
|
||||
->field(['id', 'product_id', 'entity_id', 'group_id', 'pic_name'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品图库管理数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2025/04/14 11:02
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return ProductImage::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\product_source_link;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\product_source_link\ProductSourceLink;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
|
||||
/**
|
||||
* 商品溯源管理列表
|
||||
* Class ProductSourceLinkLists
|
||||
* @package app\admin\listsproduct_source_link
|
||||
*/
|
||||
class ProductSourceLinkLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:03
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['purchase_uid', 'product_id', 'warehouse_id'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品溯源管理列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:03
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$query = ProductSourceLink::where($this->searchWhere);
|
||||
if (!empty($this->params['product_name'])) {
|
||||
$productIds = StoreProduct::where('store_name', 'like', "%{$this->params['product_name']}%")->column('id');
|
||||
$query->whereIn('product_id', $productIds);
|
||||
}
|
||||
return $query->with(['product','warehouse','purchase'])
|
||||
->field(['id', 'purchase_uid', 'product_id','warehouse_id',])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->each(function ($item) {
|
||||
$item->total_nums = ProductSourceLinkInfo::where('product_id', $item->product_id)->where('oid',$item->id)->where('types',1)->sum('nums');
|
||||
$item->warehouse_outbound_nums = ProductSourceLinkInfo::where('product_id', $item->product_id)->where('oid',$item->id)->where('types',2)->sum('nums');
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品溯源管理数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:03
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$query = ProductSourceLink::where($this->searchWhere);
|
||||
if (!empty($this->params['product_name'])) {
|
||||
$productIds = StoreProduct::where('store_name', 'like', "%{$this->params['product_name']}%")->column('id');
|
||||
$query->whereIn('product_id', $productIds);
|
||||
}
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\product_source_link_info;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\inventory_transfer\InventoryTransfer;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
|
||||
|
||||
/**
|
||||
* 商品溯源详细列表
|
||||
* Class ProductSourceLinkInfoLists
|
||||
* @package app\admin\listsproduct_source_link_info
|
||||
*/
|
||||
class ProductSourceLinkInfoLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:08
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['oid', 'types', 'purchase_funds_id', ]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品溯源详细列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:08
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return ProductSourceLinkInfo::where($this->searchWhere)
|
||||
->with(['product'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->each(function ($item) {
|
||||
$item['route'] = $this->getRoute($item);
|
||||
$item['type_name'] = $item->getTypeName();
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品溯源详细数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:08
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return ProductSourceLinkInfo::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
public function getRoute($item)
|
||||
{
|
||||
if ($item['types'] == ProductSourceLinkInfo::TypeIn) {
|
||||
$path = '/procure/warehouse_product';
|
||||
$query = ['id' => $item['link_id']];
|
||||
} elseif (in_array($item['types'], [ProductSourceLinkInfo::TypeOut, ProductSourceLinkInfo::TypeStoreIn, ProductSourceLinkInfo::TypeStoreOut])) {
|
||||
$path = '/sales_inventory/outbound_list';
|
||||
$query = ['id' => $item['link_id']];
|
||||
} elseif ($item['types'] == ProductSourceLinkInfo::TypeOrder) {
|
||||
$path = '/order/store_order';
|
||||
$linkId = StoreOrderCartInfo::where('id', $item['link_id'])->value('oid');
|
||||
$query = ['id' => $linkId];
|
||||
} elseif ($item['types'] == ProductSourceLinkInfo::TypeOrderRefund) {
|
||||
$path = '/order/store_order';
|
||||
$query = ['id' => $item['link_id']];
|
||||
} elseif (in_array($item['types'], [ProductSourceLinkInfo::TypeS2W, ProductSourceLinkInfo::TypeS2S, ProductSourceLinkInfo::TypeW2W])) {
|
||||
$path = '/warehouse/inventory_transfer_order';
|
||||
$linkId = InventoryTransfer::where('id', $item['link_id'])->value('oid');
|
||||
$query = ['id' => $linkId];
|
||||
}
|
||||
return [
|
||||
'path' => $path ?? '',
|
||||
'query' => $query ?? []
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -33,7 +33,7 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['order_id','buyer_confirm','buyer_id','is_storage'],
|
||||
'=' => ['order_id','buyer_confirm','buyer_id'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -65,31 +65,14 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc
|
||||
$this->searchWhere[]=['order_id','in',$ids];
|
||||
}
|
||||
}
|
||||
if(!empty($this->params['order_sn'])){
|
||||
$orderIds = BeforehandOrder::where('order_id','like','%'.$this->params['order_sn'].'%')->column('id');
|
||||
$this->searchWhere[]=['order_id','in',$orderIds];
|
||||
}
|
||||
if(!empty($this->params['product_name'])){
|
||||
$productIds = StoreProduct::where('store_name','like','%'.$this->params['product_name'].'%')->column('id');
|
||||
$this->searchWhere[]=['product_id','in',$productIds];
|
||||
}
|
||||
if(!empty($this->params['order_sort_list'])){
|
||||
$this->searchWhere[]=['is_storage','=',0];
|
||||
$this->searchWhere[]=['total_price','>',0];
|
||||
}
|
||||
return PurchaseProductOffer::where($this->searchWhere)
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($item) use($job_ids){
|
||||
$item->order_sn=BeforehandOrder::where('id',$item['order_id'])->value('order_id');
|
||||
$find=StoreProduct::where('id',$item->product_id)->withTrashed()->find();
|
||||
$item->store_info = empty($item['store_info']) ? ($find['store_info'] ?? '') : $item['store_info'];
|
||||
$item->after_sales = empty($item['after_sales']) ? ($find['after_sales'] ?? '') : $item['after_sales'];
|
||||
$item->marques = empty($item['marques']) ? ($find['marques'] ?? '') : $item['marques'];
|
||||
$item->package = empty($item['package']) ? ($find['package'] ?? '') : $item['package'];
|
||||
$item->expiration_date = $item->expiration_date ? date('Y-m-d', $item->expiration_date) : '';
|
||||
$item->manufacture = $item->manufacture ? date('Y-m-d', $item->manufacture) : '';
|
||||
$item->store_name=$find->store_name;
|
||||
$item->store_info=$find->store_info;
|
||||
$item->image=$find->image;
|
||||
$item->unit_name=StoreProductUnit::where('id',$item->unit)->value('name');
|
||||
$item->cate_name=StoreCategory::where('id',$find->cate_id)->value('name');
|
||||
|
@ -5,7 +5,6 @@ namespace app\admin\lists\store_branch_product;
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\cate\Cate;
|
||||
use app\common\model\inventory_transfer\InventoryTransfer;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
@ -14,7 +13,6 @@ use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\lists\ListsExcelInterface;
|
||||
use app\common\lists\ListsSortInterface;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
|
||||
/**
|
||||
* 门店商品辅助表
|
||||
@ -84,12 +82,8 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
||||
if ($where) {
|
||||
$this->searchWhere[] = $where;
|
||||
}
|
||||
$query = StoreBranchProduct::where($this->searchWhere);
|
||||
if (isset($this->params['low_stock']) && $this->params['low_stock'] == 1) {
|
||||
$query->where('stock', '<=', 'low_stock');
|
||||
}
|
||||
$list = $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'])
|
||||
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'])
|
||||
->when(!empty($this->adminInfo['store_id']), function ($query) {
|
||||
$query->where('store_id', $this->adminInfo['store_id']);
|
||||
})
|
||||
@ -97,10 +91,6 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
||||
->order($this->sortOrder)
|
||||
->select()
|
||||
->each(function ($item) use($export) {
|
||||
$item['transfer_num'] = 0;
|
||||
$item['banquet_num'] = 0;
|
||||
$item['out_num'] = InventoryTransfer::where('one_type', 1)->where('one_id', $item['store_id'])->where('product_id', $item['product_id'])->sum('nums');
|
||||
$item['in_num'] = InventoryTransfer::where('two_type', 1)->where('two_id', $item['store_id'])->where('product_id', $item['product_id'])->sum('nums');
|
||||
$item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name');
|
||||
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
|
||||
$item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
|
||||
@ -110,24 +100,6 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
$productIds = array_unique(array_column($list, 'product_id'));
|
||||
$warehouseProductQuery = WarehouseProduct::whereIn('order_type', [1, 3])->whereIn('product_id', $productIds);
|
||||
if (!empty($this->params['store_id'])) {
|
||||
$warehouseProductQuery->where('store_id', $this->params['store_id']);
|
||||
}
|
||||
$warehouseProducts = $warehouseProductQuery->group('product_id,order_type')->field('product_id,order_type,sum(nums) num')->select()->toArray();
|
||||
foreach ($warehouseProducts as $warehouseProduct) {
|
||||
foreach ($list as &$item) {
|
||||
if ($item['product_id'] == $warehouseProduct['product_id']) {
|
||||
if ($warehouseProduct['order_type'] == 1) {
|
||||
$item['transfer_num'] = $warehouseProduct['num'];
|
||||
} elseif ($warehouseProduct['order_type'] == 3) {
|
||||
$item['banquet_num'] = $warehouseProduct['num'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
@ -139,11 +111,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$query = StoreBranchProduct::where($this->searchWhere);
|
||||
if (isset($this->params['low_stock']) && $this->params['low_stock'] == 1) {
|
||||
$query->where('stock', '<=', 'low_stock');
|
||||
}
|
||||
return $query
|
||||
return StoreBranchProduct::where($this->searchWhere)
|
||||
->when(!empty($this->adminInfo['store_id']), function ($query) {
|
||||
$query->where('store_id', $this->adminInfo['store_id']);
|
||||
})
|
||||
@ -176,17 +144,12 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
||||
{
|
||||
$data = [
|
||||
'product_id' => '商品ID',
|
||||
'system_store_name' => '门店',
|
||||
'store_name' => '商品名称',
|
||||
'store_info' => '规格',
|
||||
'unit_name' => '单位',
|
||||
'cate_name' => '分类',
|
||||
'stock' => '库存',
|
||||
'sales' => '销量',
|
||||
'transfer_num' => '铺货数量',
|
||||
'banquet_num' => '一条龙数量',
|
||||
'out_num' => '调拨出库数量',
|
||||
'in_num' => '调拨入库数量',
|
||||
'purchase' => '供货价',
|
||||
'cost' => '商户价',
|
||||
'vip_price' => '会员价',
|
||||
|
@ -28,9 +28,8 @@ class StoreCashFinanceFlowLists extends BaseAdminDataLists implements ListsSearc
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['store_id', 'status', 'cash_price'],
|
||||
"between_time" => 'create_time',
|
||||
'%like%' => ['remark'],
|
||||
'=' => ['store_id', 'status'],
|
||||
"between_time" => 'create_time'
|
||||
];
|
||||
}
|
||||
|
||||
@ -47,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','type'])
|
||||
->field(['id', 'store_id', 'cash_price', 'receivable', 'receipts', 'admin_id', 'file', 'remark', 'create_time', 'status'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
@ -56,10 +55,6 @@ 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();
|
||||
}
|
||||
|
@ -45,6 +45,8 @@ class StoreCategoryLists extends BaseAdminDataLists implements ListsSearchInterf
|
||||
public function lists(): array
|
||||
{
|
||||
$userGroups = UserShip::field('id,title')->select()->toArray();
|
||||
$userGroups[] = ['id' => 100001, 'title' => '供货价'];
|
||||
$userGroups[] = ['id' => 100002, 'title' => '零售价'];
|
||||
return StoreCategory::where($this->searchWhere)
|
||||
->field(['id', 'pid', 'name', 'data', 'pic', 'sort', 'price_rate'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
@ -54,24 +56,13 @@ class StoreCategoryLists extends BaseAdminDataLists implements ListsSearchInterf
|
||||
$item['price_rate'] = $userGroups;
|
||||
} else {
|
||||
$priceRate = reset_index($item['price_rate'], 'id');
|
||||
unset($priceRate[100003], $priceRate[100004]);
|
||||
$temp = [];
|
||||
foreach ($userGroups as $userGroup) {
|
||||
if (!isset($priceRate[$userGroup['id']])) {
|
||||
continue;
|
||||
$userGroup['rate'] = 0;
|
||||
$priceRate[] = $userGroup;
|
||||
}
|
||||
if ($userGroup['id'] == 21 && !empty($priceRate[100001]) && empty($userGroup['rate'])) {
|
||||
$userGroup['rate'] = $priceRate[100001]['rate'];
|
||||
unset($priceRate[100001]);
|
||||
} elseif ($userGroup['id'] == 22 && !empty($priceRate[100002]) && empty($userGroup['rate'])) {
|
||||
$userGroup['rate'] = $priceRate[100002]['rate'];
|
||||
unset($priceRate[100002]);
|
||||
} else {
|
||||
$userGroup['rate'] = $priceRate[$userGroup['id']]['rate'] ?? 0;
|
||||
}
|
||||
$temp[] = $userGroup;
|
||||
}
|
||||
$item['price_rate'] = $temp;
|
||||
$item['price_rate'] = array_values($priceRate);
|
||||
}
|
||||
$item['is_children'] = StoreCategory::where('pid', $item->id)->count(); // 判断是否有子分类
|
||||
return $item->toArray();
|
||||
|
@ -6,7 +6,6 @@ namespace app\admin\lists\store_order;
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
@ -32,9 +31,8 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['id', 'store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id', 'paid', 'status', 'is_writeoff', 'is_merge', 'uid'],
|
||||
'between_time' => 'create_time',
|
||||
'%like%' => ['order_id'],
|
||||
'=' => ['order_id', 'store_id', 'pay_type', 'staff_id', 'shipping_type', 'delivery_id', 'paid', 'status', 'is_writeoff', 'is_merge', 'uid', 'source'],
|
||||
'between_time' => 'create_time'
|
||||
];
|
||||
}
|
||||
|
||||
@ -53,14 +51,6 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
if ($this->request->get('is_delivery') >= 1) {
|
||||
$this->searchWhere[] = ['delivery_uid', '>', 0];
|
||||
}
|
||||
if (!empty($this->params['source'])) {
|
||||
if ($this->params['source'] < 10) {
|
||||
$this->searchWhere[] = ['source', $this->params['source']];
|
||||
} else {
|
||||
$orderType = substr($this->params['source'], 1);
|
||||
$this->searchWhere[] = ['order_type', $orderType];
|
||||
}
|
||||
}
|
||||
return StoreOrder::with(['staff', 'store'])->where($this->searchWhere)
|
||||
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
|
||||
$query->where('store_id', $this->request->adminInfo['store_id']);
|
||||
@ -73,7 +63,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$query->whereIn('status', $status);
|
||||
}
|
||||
})
|
||||
->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'source', 'pay_price', 'total_price', 'pay_time', 'pay_type', 'status', 'uid', 'refund_status', 'create_time', 'delivery_name', 'delivery_id', 'refund_price', 'order_type'])
|
||||
->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'source', 'pay_price', 'total_price', 'pay_time', 'pay_type', 'status', 'uid', 'refund_status', 'create_time', 'delivery_name', 'delivery_id', 'refund_price'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
@ -100,9 +90,6 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
} else {
|
||||
$item['source_name'] = '普通订单';
|
||||
}
|
||||
if (!empty($item['order_type'])) {
|
||||
$item['source_name'] = BeforehandOrder::getOrderTypeName($item['order_type']);
|
||||
}
|
||||
$product = StoreOrderCartInfo::where('oid', $item['id'])->field(['id', 'oid', 'product_id', 'cart_info'])
|
||||
->limit(3)->select();
|
||||
foreach ($product as &$items) {
|
||||
|
@ -34,7 +34,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['oid','product_id','is_pay','store_id'],
|
||||
'=' => ['oid','product_id','is_pay'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -51,9 +51,8 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
|
||||
public function lists(): array
|
||||
{
|
||||
return StoreOrderCartInfo::where($this->searchWhere)
|
||||
->field('id,oid,uid,product_id,store_id,cart_num,price,total_price,create_time,refund_num,refund_amount')->limit($this->limitOffset, $this->limitLength)
|
||||
->field('id,oid,uid,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength)
|
||||
->select()->each(function ($item) {
|
||||
$item['order_id']=StoreOrder::where('id',$item['oid'])->value('order_id')??"";//订单号
|
||||
$find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->withTrashed()->find();
|
||||
$item['nickname']='无';
|
||||
$item['mobile']='';
|
||||
@ -137,8 +136,6 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
|
||||
'cart_num' => '数量',
|
||||
'price' => '单价',
|
||||
'total_price' => '总价',
|
||||
'refund_num' => '退款数量',
|
||||
'refund_amount' => '退款金额',
|
||||
'nickname' => '用户',
|
||||
'mobile' => '手机',
|
||||
'create_time' => '时间',
|
||||
|
@ -70,9 +70,9 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
|
||||
$this->searchWhere[] = ['status', '>=', 0];
|
||||
$query = StoreOrderCartInfo::where($this->searchWhere);
|
||||
if ($is_group == 1) {
|
||||
$query->field('store_id,product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num,SUM(refund_num) as refund_num,SUM(refund_amount) as refund_amount')->group(['store_id', 'product_id']);
|
||||
$query->field('store_id,product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group(['store_id', 'product_id']);
|
||||
} else {
|
||||
$query->field('store_id,product_id,price,total_price,cart_num,create_time,uid,oid,refund_num,refund_amount');
|
||||
$query->field('store_id,product_id,price,total_price,cart_num,create_time,uid,oid');
|
||||
}
|
||||
return $query->limit($this->limitOffset, $this->limitLength)
|
||||
->select()->each(function ($item) use($is_group,$export){
|
||||
@ -167,8 +167,6 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
|
||||
'cart_num' => '数量',
|
||||
'price' => '单价',
|
||||
'total_price' => '总价',
|
||||
'refund_num' => '退款数量',
|
||||
'refund_amount' => '退款金额',
|
||||
];
|
||||
} else {
|
||||
$data = [
|
||||
@ -182,8 +180,6 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
|
||||
'cart_num' => '数量',
|
||||
'price' => '单价',
|
||||
'total_price' => '总价',
|
||||
'refund_num' => '退款数量',
|
||||
'refund_amount' => '退款金额',
|
||||
'nickname' => '用户',
|
||||
'mobile' => '手机',
|
||||
'create_time' => '时间',
|
||||
|
@ -4,7 +4,6 @@ namespace app\admin\lists\store_product;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\ActivityZone;
|
||||
use app\common\model\cate\Cate;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
@ -35,7 +34,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['cate_id', 'is_show', 'bar_code', 'id'],
|
||||
'=' => ['cate_id', 'is_show', 'bar_code','id'],
|
||||
'in' => ['product_type'],
|
||||
'<=' => ['stock'],
|
||||
'%like%' => ['store_name'],
|
||||
@ -54,8 +53,18 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$is_warehouse = $this->request->get('is_warehouse', 0);
|
||||
$order_type = $this->request->get('order_type', 0);
|
||||
$class_all = $this->request->get('class_all');
|
||||
if ($class_all) {
|
||||
//查3级别的
|
||||
$arr = Cate::where('pid', $class_all)->column('id');
|
||||
if ($arr) {
|
||||
$arr2 = Cate::where('pid', 'in', $arr)->column('id');
|
||||
$this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
|
||||
} else {
|
||||
$this->searchWhere[] = ['cate_id', '=', $class_all];
|
||||
}
|
||||
}
|
||||
$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');
|
||||
@ -71,34 +80,9 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$query->where('is_show', 1);
|
||||
}
|
||||
}
|
||||
$class_all = $this->request->get('class_all');
|
||||
if ($class_all) {
|
||||
if (count($class_all) == 1) {
|
||||
$query->where('top_cate_id', $class_all[0]);
|
||||
} elseif (count($class_all) == 2) {
|
||||
$query->where(function ($query) use ($class_all) {
|
||||
$query->where('two_cate_id', $class_all[1])->whereOr('cate_id', $class_all[1]);
|
||||
});
|
||||
} else {
|
||||
$query->where('cate_id', $class_all[2]);
|
||||
}
|
||||
}
|
||||
if (!empty($this->params['activity_zone_form_id'])) {
|
||||
$exceptIds = ActivityZone::where('form_id', $this->params['activity_zone_form_id'])->column('product_id');
|
||||
$query->where('is_show', 1)->where('product_type', '<>', 5)->whereNotIn('id', $exceptIds);
|
||||
}
|
||||
$storeId = $this->params['store_id'] ?? 0;
|
||||
$is_true = true;
|
||||
if ($storeId > 0) {
|
||||
$is_true = SystemStore::isSelfOperate($storeId);
|
||||
}
|
||||
if (!empty($this->params['product_status'])) {
|
||||
$query->onlyTrashed();
|
||||
}
|
||||
$list = $query->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) use ($is_warehouse, $userShip, $order_type, $is_true) {
|
||||
$item['price_update_time'] = !empty($item['price_update_time']) ? date('Y-m-d H:i:s', $item['price_update_time']) : '';
|
||||
->select()->each(function ($item) use($is_warehouse, $userShip) {
|
||||
$item['product_id'] = $item['id'];
|
||||
$item['bar_code_two'] = '';
|
||||
if (in_array($item['unit'], [2, 21])) {
|
||||
@ -116,7 +100,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$item['bar_code'] = '';
|
||||
}
|
||||
}
|
||||
switch ($item['product_type']) {
|
||||
switch($item['product_type']){
|
||||
case 2:
|
||||
$item['product_type_name'] = '兑换产品';
|
||||
break;
|
||||
@ -129,7 +113,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
case 5:
|
||||
$item['product_type_name'] = '批发产品';
|
||||
break;
|
||||
case 6:
|
||||
case 6:
|
||||
$item['product_type_name'] = '零采商品';
|
||||
break;
|
||||
default:
|
||||
@ -137,39 +121,27 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
}
|
||||
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
|
||||
$stock = StoreBranchProduct::where('store_id', '<>', '4')->where('product_id', $item['id'])->sum('stock');
|
||||
$category = StoreCategory::where('id', 'in', [$item['top_cate_id'], $item['two_cate_id'], $item['cate_id']])->column('name');
|
||||
$item['cate_name'] = implode('/', $category);
|
||||
if ($is_warehouse == 1) {
|
||||
$item['stock'] = WarehouseProductStorege::where('product_id', $item['id'])->where('warehouse_id', 1)->sum('nums');
|
||||
} else {
|
||||
$nums = WarehouseProductStorege::where('product_id', $item['id'])->where('warehouse_id', 1)->sum('nums');
|
||||
$category = StoreCategory::where('id','in',[$item['top_cate_id'],$item['two_cate_id'],$item['cate_id']])->column('name');
|
||||
$item['cate_name'] =implode('/', $category);
|
||||
if($is_warehouse==1){
|
||||
$item['stock'] = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
|
||||
}else{
|
||||
$nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
|
||||
$item['stock'] = bcadd($nums, $stock);
|
||||
}
|
||||
if ($userShip == 4) {
|
||||
$item['price'] = $item['cost'];
|
||||
}
|
||||
if ($item['is_show'] == 1) {
|
||||
$item['status_msg'] = '上架|常用';
|
||||
} else {
|
||||
$item['status_msg'] = '下架|不常用|是否有替换';
|
||||
}
|
||||
if ($order_type == 2) {
|
||||
// $price = StoreProductGroupPrice::where('group_id', 42)->where('product_id', $item['product_id'])->value('price');
|
||||
// if ($price > 0) {
|
||||
// $item['price'] = $price;
|
||||
// $item['store_name'] = $item['store_name'] . '|活动价';
|
||||
// }
|
||||
$item['price'] = $item['cost'];
|
||||
$item['store_name'] = $item['store_name'] . '|高级会员价';
|
||||
}elseif($is_true == true && $userShip>0){
|
||||
$item['price'] = $item['vip_price'];
|
||||
$item['store_name'] = $item['store_name'] . '|会员价';
|
||||
if($item['is_show']==1){
|
||||
$item['status_msg']='上架|常用';
|
||||
}else{
|
||||
$item['status_msg']='下架|不常用|是否有替换';
|
||||
}
|
||||
return $item;
|
||||
})?->toArray();
|
||||
// if ($userShip > 0 && $userShip != 4) {
|
||||
// $list = StoreProductGroupPrice::resetStoreProductsPrice($list, $userShip, $this->params['store_id'] ?? 0);
|
||||
// }
|
||||
// if ($userShip > 0 && $userShip != 4) {
|
||||
// $list = StoreProductGroupPrice::resetProductsPrice($list, $userShip);
|
||||
// }
|
||||
return $list;
|
||||
}
|
||||
|
||||
@ -182,19 +154,21 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$query = StoreProduct::where($this->searchWhere);
|
||||
$class_all = $this->request->get('class_all');
|
||||
if ($class_all) {
|
||||
if (count($class_all) == 1) {
|
||||
$query->where('top_cate_id', $class_all[0]);
|
||||
} elseif (count($class_all) == 2) {
|
||||
$query->where(function ($query) use ($class_all) {
|
||||
$query->where('two_cate_id', $class_all[1])->whereOr('cate_id', $class_all[1]);
|
||||
});
|
||||
} else {
|
||||
$query->where('cate_id', $class_all[2]);
|
||||
$export = $this->request->get('export');
|
||||
if ($export == 1) {
|
||||
$class_all = $this->request->get('class_all');
|
||||
if ($class_all) {
|
||||
//查3级别的
|
||||
$arr = Cate::where('pid', $class_all)->column('id');
|
||||
if ($arr) {
|
||||
$arr2 = Cate::where('pid', 'in', $arr)->column('id');
|
||||
$this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
|
||||
} else {
|
||||
$this->searchWhere[] = ['cate_id', '=', $class_all];
|
||||
}
|
||||
}
|
||||
}
|
||||
$query = StoreProduct::where($this->searchWhere);
|
||||
if (isset($this->params['type_filter'])) {
|
||||
if ($this->params['type_filter'] == 0) {
|
||||
$query->where(function ($query) {
|
||||
@ -204,9 +178,6 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$query->where('is_show', 1);
|
||||
}
|
||||
}
|
||||
if (!empty($this->params['product_status'])) {
|
||||
$query->onlyTrashed();
|
||||
}
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
@ -232,16 +203,14 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
{
|
||||
$data = [
|
||||
'id' => '商品id',
|
||||
'image' => '图片',
|
||||
'store_name' => '商品名称',
|
||||
'product_type_name' => '商品类型',
|
||||
'cate_name' => '分类',
|
||||
'unit_name' => '单位',
|
||||
'store_info' => '规格',
|
||||
'stock' => '库存',
|
||||
'purchase' => '供货价',
|
||||
'purchase' => '采购价',
|
||||
'cost' => '商户',
|
||||
'vip_price' => '商户',
|
||||
'price' => '零售',
|
||||
'rose' => '毛利率',
|
||||
'bar_code' => '条码',
|
||||
|
@ -44,11 +44,11 @@ class StoreProductGroupPriceLists extends BaseAdminDataLists implements ListsSea
|
||||
public function lists(): array
|
||||
{
|
||||
$query = StoreProduct::field('id,store_name,purchase,cost,vip_price,price,unit');
|
||||
$store_name=$this->request->get('store_name','');
|
||||
if ($store_name!='') {
|
||||
$query->where('store_name', 'like', '%'.$store_name.'%');
|
||||
if ($this->params['product_id']) {
|
||||
$query->where('id|store_name', $this->params['product_id']);
|
||||
}
|
||||
return $query->limit($this->limitOffset, $this->limitLength)
|
||||
->field('id,store_name,purchase,cost,vip_price,price,unit')
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
$item['lists'] =StoreProductGroupPrice::where('product_id',$item['id'])->field('id,group_id,price')
|
||||
@ -75,9 +75,8 @@ class StoreProductGroupPriceLists extends BaseAdminDataLists implements ListsSea
|
||||
public function count(): int
|
||||
{
|
||||
$query = StoreProduct::field('id,store_name,purchase,cost,vip_price,price,unit');
|
||||
$store_name=$this->request->get('store_name','');
|
||||
if ($store_name!='') {
|
||||
$query->where('store_name', 'like', '%'.$store_name.'%');
|
||||
if ($this->params['product_id']) {
|
||||
$query->where('id|store_name', $this->params['product_id']);
|
||||
}
|
||||
return $query->count();
|
||||
}
|
||||
|
@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\store_product_low_stock;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\store_product_low_stock\StoreProductLowStock;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
|
||||
/**
|
||||
* 商品缺库存列表
|
||||
* Class StoreProductLowStockLists
|
||||
* @package app\admin\listsstore_product_low_stock
|
||||
*/
|
||||
class StoreProductLowStockLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2025/01/07 16:39
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['product_id', 'store_id', 'status'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品缺库存列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2025/01/07 16:39
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return StoreProductLowStock::where($this->searchWhere)
|
||||
->field(['id', 'product_id', 'store_id', 'status'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
$find = StoreBranchProduct::where('product_id', $item->product_id)->where('store_id', $item->store_id)->withTrashed()->find();
|
||||
$item->product_name = $find->store_name.'|'.$item->product_id;
|
||||
$item->system_store_name = SystemStore::where('id', $item->store_id)->value('name').'|'.$item->store_id;
|
||||
$item->image = $find->image;
|
||||
$item->stock = $find->stock;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品缺库存数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2025/01/07 16:39
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return StoreProductLowStock::where($this->searchWhere)->count();
|
||||
}
|
||||
}
|
@ -4,12 +4,9 @@ namespace app\admin\lists\store_product_price;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\admin\service\ProductPriceService;
|
||||
use app\common\model\store_product_price\StoreProductPrice;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\StoreProductPriceList;
|
||||
use app\common\model\warehouse\Warehouse;
|
||||
|
||||
/**
|
||||
* 商品价格更改列表
|
||||
@ -50,42 +47,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'])];
|
||||
}
|
||||
$list = 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', 'warehouse_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'])
|
||||
->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');
|
||||
$find = StoreProduct::with('unitName')->where('id', $item['product_id'])->field('image,store_name,store_info,unit')->withTrashed()->find();
|
||||
$item['unit_name']=$find['unitName']['name'] ?? '';
|
||||
$item['store_name']=$find['store_name'];
|
||||
$item['store_info']=$find['store_info'];
|
||||
$item['image']=$find['image'];
|
||||
$item['current_purchase']=$find['purchase'];
|
||||
$item['current_cost']=$find['cost'];
|
||||
$item['current_price']=$find['price'];
|
||||
$item['status_name']=$item['status']==0?"未设置":"已设置";
|
||||
})
|
||||
->toArray();
|
||||
$productIds = array_unique(array_column($list, 'product_id'));
|
||||
$priceList = StoreProductPriceList::whereIn('product_id', $productIds)->select()->toArray();
|
||||
$priceList = reset_index($priceList, 'product_id');
|
||||
$productService = new ProductPriceService();
|
||||
foreach ($list as &$item) {
|
||||
$productPrice = $priceList[$item['product_id']] ?? [];
|
||||
if (empty($productPrice) || $item['status'] == 1) {
|
||||
continue;
|
||||
}
|
||||
$priceArray = $productService->setProductPrice($item['purchase_price'], $productPrice);
|
||||
$item = array_merge($item, $priceArray);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,7 +45,7 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
return Supplier::where($this->searchWhere)
|
||||
->field(['id', 'category_id', 'mer_name', 'phone', 'settle_cycle', 'address', 'mark'])
|
||||
->limit($this->limitOffset, 100)
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
$item->total_completed_amount=WarehouseProduct::where('supplier_id',$item['id'])->where('financial_pm',1)->where('is_pay',1)->sum('total_price');
|
||||
|
@ -45,17 +45,14 @@ class SystemStoreStorageLists extends BaseAdminDataLists implements ListsSearchI
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
if (!empty($this->params['product_name'])) {
|
||||
$productIds = StoreProduct::where('store_name', 'like', '%' . $this->params['product_name'] . '%')->column('id');
|
||||
$this->searchWhere[] = ['product_id', 'in', $productIds];
|
||||
}
|
||||
return SystemStoreStorage::where($this->searchWhere)
|
||||
->field(['id', 'store_id', 'admin_id', 'staff_id', 'product_id', 'nums','mark', 'status', 'create_time'])
|
||||
->field(['id', 'store_id', 'admin_id', 'staff_id', 'product_id', 'nums','mark', 'status'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
$item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name');
|
||||
$item['admin_name'] = Admin::where('id', $item['admin_id'])->value('name');
|
||||
$item['admin_name'] = Admin::where('id', $item['admin_id'])->value('name');
|
||||
if ($item['staff_id'] > 0) {
|
||||
$item['staff_name'] = SystemStoreStaff::where('id', $item['staff_id'])->value('staff_name');
|
||||
} else {
|
||||
|
@ -4,7 +4,6 @@ namespace app\admin\lists\warehouse_order;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\auth\Admin;
|
||||
@ -50,7 +49,7 @@ class WarehouseOrderLists extends BaseAdminDataLists implements ListsSearchInter
|
||||
public function lists(): array
|
||||
{
|
||||
return WarehouseOrder::where($this->searchWhere)
|
||||
->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'code', 'financial_pm', 'admin_id', 'batch', 'mark', 'purchase', 'total_price', 'status', 'create_time', 'completed_amount', 'outstanding_amount', 'oid', 'order_type'])
|
||||
->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'code', 'financial_pm', 'admin_id', 'batch', 'mark', 'purchase', 'total_price', 'status', 'create_time', 'completed_amount', 'outstanding_amount'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
@ -81,12 +80,6 @@ class WarehouseOrderLists extends BaseAdminDataLists implements ListsSearchInter
|
||||
}else{
|
||||
$item->supplier_name = '';
|
||||
}
|
||||
if (!empty($item['order_type'])) {
|
||||
$item->order_type_name = BeforehandOrder::getOrderTypeName($item->order_type);
|
||||
} else {
|
||||
$orderType = BeforehandOrder::where('id', $item['oid'])->value('order_type');
|
||||
$item->order_type_name = BeforehandOrder::getOrderTypeName($orderType);
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
@ -1,184 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\warehouse_product;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\warehouse\Warehouse;
|
||||
use app\common\lists\ListsExcelInterface;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\supplier\Supplier;
|
||||
|
||||
/**
|
||||
* 商品仓储信息列表
|
||||
* Class StoreWarehouseProductLists
|
||||
* @package app\admin\listswarehouse_product
|
||||
*/
|
||||
class StoreWarehouseProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
|
||||
{
|
||||
|
||||
public $ids;
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['store_id', 'status',],
|
||||
'between_time' => 'create_time'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品仓储信息列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
if ($this->request->get('product_name')) {
|
||||
$product_name = $this->request->get('product_name');
|
||||
$ids = StoreProduct::where('store_name', 'like', '%' . $product_name . '%')->withTrashed()->column('id');
|
||||
if ($ids) {
|
||||
$this->searchWhere[] = ['product_id', 'in', $ids];
|
||||
$this->ids = $ids;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
$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', 'refund_nums', 'status', 'mark', 'create_time', 'order_type'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
// ->withTrashed()
|
||||
->select()->each(function ($item) {
|
||||
$item->store_name = '';
|
||||
$item->image = '';
|
||||
$item->unit_name = '';
|
||||
if ($item->store_id > 0) {
|
||||
$item->system_store_name = SystemStore::where('id', $item->store_id)->value('name');
|
||||
} else {
|
||||
$item->system_store_name = '';
|
||||
}
|
||||
if ($item->status == 0) {
|
||||
$item->status_name = '未确认';
|
||||
} elseif ($item->status == 1) {
|
||||
$item->status_name = '已确认';
|
||||
}
|
||||
if ($item->admin_id) {
|
||||
$item->admin_name = Admin::where('id', $item->admin_id)->value('name');
|
||||
} else {
|
||||
$item->admin_name = '';
|
||||
}
|
||||
if ($item->product_id) {
|
||||
$find = StoreProduct::where('id', $item->product_id)->field('image,store_name,unit')->withTrashed()->find();
|
||||
if($find){
|
||||
$item->store_name = $find->store_name;
|
||||
$item->image = $find->image;
|
||||
$item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name');
|
||||
}
|
||||
}
|
||||
$item->order_type_name = BeforehandOrder::getOrderTypeName($item->order_type);
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品仓储信息数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
if ($this->ids) {
|
||||
return WarehouseProduct::whereIn('id', $this->ids)->where($this->searchWhere)->count();
|
||||
} else {
|
||||
return WarehouseProduct::where($this->searchWhere)->count();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notes 导出文件名
|
||||
* @return string
|
||||
* @author 乔峰
|
||||
* @date 2022/11/24 16:17
|
||||
*/
|
||||
public function setFileName(): string
|
||||
{
|
||||
$financial_pm = $this->request->get('financial_pm');
|
||||
if ($financial_pm == 1) {
|
||||
return '入库列表';
|
||||
}
|
||||
return '出库列表';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 导出字段
|
||||
* @return string[]
|
||||
* @author 乔峰
|
||||
* @date 2022/11/24 16:17
|
||||
*/
|
||||
public function setExcelFields(): array
|
||||
{
|
||||
$financial_pm = $this->request->get('financial_pm');
|
||||
if ($financial_pm == 1) {
|
||||
$data = [
|
||||
'admin_name' => '操作人员',
|
||||
'warehouse_name' => '仓库',
|
||||
'supplier_name' => '供应商',
|
||||
'store_name' => '商品名称',
|
||||
'financial_pm_name' => '出入库',
|
||||
'code' => '入库单',
|
||||
'batch' => '批次',
|
||||
'nums' => '数量',
|
||||
'manufacture' => '生产日期',
|
||||
'expiration_date' => '保质期',
|
||||
'purchase' => '采购价',
|
||||
'price' => '零售',
|
||||
'total_price' => '总价',
|
||||
'create_time' => '操作时间',
|
||||
];
|
||||
} else {
|
||||
$data = [
|
||||
'id' => 'id',
|
||||
'admin_name' => '操作人员',
|
||||
'warehouse_name' => '仓库',
|
||||
'store_name' => '商品名称',
|
||||
'top_cate_name' => '分类',
|
||||
'store_info' => '规格',
|
||||
'unit_name' => '单位',
|
||||
'financial_pm_name' => '出入库',
|
||||
'code' => '出库单',
|
||||
'system_store_name' => '门店',
|
||||
'nums' => '数量',
|
||||
'purchase' => '供货价',
|
||||
'price' => '零售价',
|
||||
'total_price' => '供货总价',
|
||||
'create_time' => '操作时间',
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -4,8 +4,6 @@ namespace app\admin\lists\warehouse_product;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\auth\Admin;
|
||||
@ -37,7 +35,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['id', 'warehouse_id', 'financial_pm', 'product_id','store_id','oid','supplier_id','is_pay','code'],
|
||||
'=' => ['warehouse_id', 'financial_pm', 'store_id','oid','supplier_id','is_pay','code'],
|
||||
'between_time' => 'create_time'
|
||||
];
|
||||
}
|
||||
@ -54,9 +52,9 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
if ($this->request->get('product_name')) {
|
||||
$product_name = $this->request->get('product_name');
|
||||
$ids = StoreProduct::where('store_name', 'like', '%' . $product_name . '%')->withTrashed()->column('id');
|
||||
if ($this->request->get('product_id')) {
|
||||
$product_id = $this->request->get('product_id');
|
||||
$ids = StoreProduct::where('store_name', 'like', '%' . $product_id . '%')->withTrashed()->column('id');
|
||||
if ($ids) {
|
||||
$this->searchWhere[] = ['product_id', 'in', $ids];
|
||||
$this->ids = $ids;
|
||||
@ -74,19 +72,11 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
return [];
|
||||
}
|
||||
}
|
||||
$query = WarehouseProduct::where($this->searchWhere);
|
||||
if (isset($this->params['is_group']) && $this->params['is_group'] == 1) {
|
||||
$query->group('product_id')->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'sum(nums) nums', 'price', 'purchase', 'cost', 'sum(total_price) total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay', 'order_type','vip_price', 'delete_time']);
|
||||
} else {
|
||||
$query->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay', 'order_type','vip_price', 'delete_time']);
|
||||
}
|
||||
if (!empty($this->params['product_status'])) {
|
||||
$query->onlyTrashed();
|
||||
}
|
||||
return $query
|
||||
return WarehouseProduct::where($this->searchWhere)
|
||||
->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
// ->withTrashed()
|
||||
->withTrashed()
|
||||
->select()->each(function ($item) {
|
||||
$item->store_name = '';
|
||||
$item->image = '';
|
||||
@ -95,7 +85,6 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
$item->unit_name = '';
|
||||
$item->store_info = '';
|
||||
$item->top_cate_name = '';
|
||||
$item->order_type_name = '';
|
||||
if ($item->financial_pm == 0) {
|
||||
$item->financial_pm_name = '出库';
|
||||
} else {
|
||||
@ -121,13 +110,13 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
if ($item->product_id) {
|
||||
$find = StoreProduct::where('id', $item->product_id)->field('price,purchase,image,store_name,unit,store_info,top_cate_id')->withTrashed()->find();
|
||||
if($find){
|
||||
// if($item->purchase<=0){
|
||||
// $item->purchase = $find->purchase;
|
||||
// $item->total_price=bcmul($find->purchase,$item->nums,2);
|
||||
// }
|
||||
if($item->purchase<=0){
|
||||
$item->purchase = $find->purchase;
|
||||
$item->total_price=bcmul($find->purchase,$item->nums,2);
|
||||
}
|
||||
$item->store_name = $find->store_name . '|' . $item->product_id;
|
||||
$item->image = $find->image;
|
||||
// $item->price = $find->price;
|
||||
$item->price = $find->price;
|
||||
$item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name');
|
||||
$item->store_info =$find->store_info;
|
||||
$item->top_cate_name =StoreCategory::where('id', $find->top_cate_id)->value('name');
|
||||
@ -145,19 +134,6 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
}
|
||||
$item->expiration_date = $item->expiration_date ? date('Y-m-d', $item->expiration_date) : '';
|
||||
$item->manufacture = $item->manufacture ? date('Y-m-d', $item->manufacture) : '';
|
||||
|
||||
if (!empty($item['order_type'])) {
|
||||
$item->order_type_name = BeforehandOrder::getOrderTypeName($item->order_type);
|
||||
} else {
|
||||
$beforehandOrderId = WarehouseOrder::where('id', $item['oid'])->value('oid');
|
||||
if ($beforehandOrderId) {
|
||||
$orderType = BeforehandOrder::where('id', $beforehandOrderId)->value('order_type');
|
||||
$item->order_type_name = BeforehandOrder::getOrderTypeName($orderType);
|
||||
}
|
||||
}
|
||||
if ($item->order_type == 5) {
|
||||
$item->outbound = '无须出库';
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
@ -171,14 +147,10 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$query = WarehouseProduct::where($this->searchWhere);
|
||||
if (!empty($this->params['product_status'])) {
|
||||
$query->onlyTrashed();
|
||||
}
|
||||
if ($this->ids) {
|
||||
return $query->whereIn('id', $this->ids)->count();
|
||||
return WarehouseProduct::whereIn('id', $this->ids)->where($this->searchWhere)->count();
|
||||
} else {
|
||||
return $query->count();
|
||||
return WarehouseProduct::where($this->searchWhere)->count();
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -230,7 +202,6 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
'warehouse_name' => '仓库',
|
||||
'store_name' => '商品名称',
|
||||
'top_cate_name' => '分类',
|
||||
'order_type_name' => '订单类型',
|
||||
'store_info' => '规格',
|
||||
'unit_name' => '单位',
|
||||
'financial_pm_name' => '出入库',
|
||||
@ -238,7 +209,6 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
'system_store_name' => '门店',
|
||||
'nums' => '数量',
|
||||
'purchase' => '供货价',
|
||||
'vip_price' => '会员价',
|
||||
'price' => '零售价',
|
||||
'total_price' => '供货总价',
|
||||
'create_time' => '操作时间',
|
||||
|
@ -64,14 +64,9 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$where = [];
|
||||
if ($this->request->get('store_name')) {
|
||||
$this->store_name = $this->request->get('store_name');
|
||||
$where[] = ['store_name', 'like', '%' . $this->request->get('store_name') . '%'];
|
||||
if($this->request->get('class_all')){
|
||||
$where[] = ['top_cate_id', 'in', $this->request->get('class_all')];
|
||||
}
|
||||
$ids = StoreProduct::where($where)->column('id');
|
||||
$ids = StoreProduct::where('store_name', 'like', '%' . $this->request->get('store_name') . '%')->column('id');
|
||||
if ($ids) {
|
||||
$this->searchWhere[] = ['product_id', 'in', $ids];
|
||||
$this->ids = $ids;
|
||||
@ -89,35 +84,24 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
|
||||
return [];
|
||||
}
|
||||
}
|
||||
if($this->request->get('class_all')){
|
||||
$where[] = ['top_cate_id', 'in', $this->request->get('class_all')];
|
||||
}
|
||||
$ids = StoreProduct::where($where)->column('id');
|
||||
if ($ids) {
|
||||
$this->searchWhere[] = ['product_id', 'in', $ids];
|
||||
$this->ids = $ids;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
return WarehouseProductStorege::where($this->searchWhere)
|
||||
->field(['id','is_verify','warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status'])
|
||||
->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();
|
||||
$find = StoreProduct::where('id', $item->product_id)->find();
|
||||
if ($find) {
|
||||
$item->store_name = $find->store_name;
|
||||
$item->image = $find->image;
|
||||
$item->bar_code = $find->bar_code;
|
||||
$item->price = $find->price;
|
||||
$item->vip_price = $find->vip_price;
|
||||
$item->cost = $find->cost;
|
||||
$item->purchase = $find->purchase;
|
||||
$item->store_info = $find->store_info;
|
||||
$item->rose = $find->rose;
|
||||
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->withTrashed()->value('name');
|
||||
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->withTrashed()->value('name');
|
||||
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name');
|
||||
}else{
|
||||
$item->store_name = '';
|
||||
$item->cate_name = '';
|
||||
@ -173,7 +157,6 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
|
||||
{
|
||||
|
||||
$data = [
|
||||
'product_id' => '商品ID',
|
||||
'store_name' => '商品名称',
|
||||
'cate_name' => '分类',
|
||||
'unit_name' => '单位',
|
||||
|
@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\finance\AccountsReceivable;
|
||||
use app\common\model\finance\AccountsReceivableInfo;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* Class AccountsReceivableLogic
|
||||
* @package app\admin\logic
|
||||
*/
|
||||
class AccountsReceivableLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @param array $order
|
||||
*/
|
||||
public static function add(array $order)
|
||||
{
|
||||
$model = new AccountsReceivable();
|
||||
$model->order_id = $order['id'];
|
||||
$model->store_id = $order['store_id'];
|
||||
$model->user_id = $order['uid'];
|
||||
$model->nickname = $order['other_data']->nickname;
|
||||
$model->phone = $order['other_data']->phone;
|
||||
$model->deadline = time() + 86400 * 15;
|
||||
$model->total_debt = $order['total_price'];
|
||||
$model->surplus_debt = $order['total_price'];
|
||||
$model->save();
|
||||
}
|
||||
|
||||
public static function edit($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$accountsReceivable = AccountsReceivable::where(['id' => $params['accounts_receivable_id']])->find();
|
||||
if ($accountsReceivable->surplus_debt <= 0) {
|
||||
throw new BusinessException('该账单已支付');
|
||||
}
|
||||
$surplusDebt = bcsub($accountsReceivable->surplus_debt, $params['pay_debt'], 2);
|
||||
$model = new AccountsReceivableInfo();
|
||||
$model->accounts_receivable_id = $params['accounts_receivable_id'];
|
||||
$model->pay_type = $params['pay_type'];
|
||||
$model->total_debt = $params['surplus_debt'];
|
||||
$model->pay_debt = $params['pay_debt'];
|
||||
$model->recipient = $params['recipient'];
|
||||
$model->surplus_debt = $surplusDebt;
|
||||
$model->file = $params['file'];
|
||||
$model->mark = $params['mark'];
|
||||
if (!$model->save()) {
|
||||
throw new BusinessException('添加失败');
|
||||
}
|
||||
$accountsReceivable->pay_debt = bcadd($accountsReceivable->pay_debt, $params['pay_debt'], 2);
|
||||
$accountsReceivable->surplus_debt = $surplusDebt;
|
||||
if (!$accountsReceivable->save()) {
|
||||
throw new BusinessException('更新账单出错');
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function record($params)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function statistics()
|
||||
{
|
||||
$query = AccountsReceivable::field('store_id,sum(total_debt) as total_debt,sum(pay_debt) as pay_debt,sum(surplus_debt) as surplus_debt')->group('store_id');
|
||||
$count = $query->count();
|
||||
$list = $query->select()->toArray();
|
||||
foreach ($list as &$item) {
|
||||
$item['store_name'] = SystemStore::where('id', $item['store_id'])->value('name');
|
||||
}
|
||||
return [
|
||||
'list' => $list,
|
||||
'count' => $count
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\ActivityZone;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\ActivityZoneForm;
|
||||
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\service\xlsx\ActivityZoneService;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* ActivityZone逻辑
|
||||
* Class ActivityZoneLogic
|
||||
* @package app\admin\logic
|
||||
*/
|
||||
class ActivityZoneFormLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$secondCateIds = [];
|
||||
$thirdCateIds = [];
|
||||
foreach ($params['cate_ids'] as $item) {
|
||||
if (count($item) == 3) {
|
||||
$thirdCateIds[] = $item[2];
|
||||
} else {
|
||||
$secondCateIds[] = $item[1];
|
||||
}
|
||||
}
|
||||
$cateIds = array_merge($secondCateIds, $thirdCateIds);
|
||||
$params['cate_ids'] = !empty($cateIds) ? implode(',', $cateIds) : '';
|
||||
$activityZoneForm = new ActivityZoneForm();
|
||||
$activityZoneForm->save($params);
|
||||
$products = StoreProduct::field('id,two_cate_id,cate_id')->where('two_cate_id', 'in', $cateIds)->whereOr('cate_id', 'in', $cateIds)->select()->toArray();
|
||||
$productInfo = [];
|
||||
$time = time();
|
||||
foreach ($products as $product) {
|
||||
$productInfo[] = [
|
||||
'product_id' => $product['id'],
|
||||
'form_id' => $activityZoneForm->id,
|
||||
'create_time' => $time,
|
||||
'update_time' => $time,
|
||||
];
|
||||
}
|
||||
if (!empty($productInfo)) {
|
||||
ActivityZone::insertAll($productInfo);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ActivityZoneForm::where('id', $params['id'])->update([
|
||||
'type' => $params['type'],
|
||||
'product_id' => $params['product_id'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ActivityZoneForm::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return ActivityZoneForm::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
public static function export($params)
|
||||
{
|
||||
$service = new ActivityZoneService();
|
||||
$activityZoneForm = ActivityZoneForm::findOrEmpty($params['id'])->toArray();
|
||||
$productIds = ActivityZone::where('form_id', $params['id'])->column('product_id');
|
||||
$products = StoreProduct::field('id,unit,store_name,two_cate_id')->whereIn('id', $productIds)->order('two_cate_id asc,cate_id asc')->select()->toArray();
|
||||
$unitIds = array_unique(array_column($products, 'unit'));
|
||||
$cateIds = array_unique(array_column($products, 'two_cate_id'));
|
||||
$unit = StoreProductUnit::whereIn('id', $unitIds)->field('id,name')->withTrashed()->select()->toArray();
|
||||
$categories = StoreCategory::whereIn('id', $cateIds)->field('id,name')->withTrashed()->select()->toArray();
|
||||
$unit = reset_index($unit, 'id');
|
||||
$categories = reset_index($categories, 'id');
|
||||
$data = [];
|
||||
foreach ($products as $item) {
|
||||
$currentCate = $categories[$item['two_cate_id']]['name'] ?? '';
|
||||
if (!empty($currentCate)) {
|
||||
$item['unit_name'] = $unit[$item['unit']]['name'] ?? '';
|
||||
unset($item['unit'], $item['two_cate_id']);
|
||||
$data[$currentCate][] = $item;
|
||||
}
|
||||
}
|
||||
return $service->export($data, $activityZoneForm['title'], $activityZoneForm['remark']);
|
||||
}
|
||||
|
||||
}
|
@ -1,140 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\ActivityZone;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\ActivityZoneForm;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* ActivityZone逻辑
|
||||
* Class ActivityZoneLogic
|
||||
* @package app\admin\logic
|
||||
*/
|
||||
class ActivityZoneLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$insert = [];
|
||||
$time = time();
|
||||
foreach ($params['product_ids'] as $product_id) {
|
||||
$insert[] = [
|
||||
'form_id' => $params['form_id'],
|
||||
'product_id' => $product_id,
|
||||
'create_time' => $time,
|
||||
'update_time' => $time,
|
||||
];
|
||||
}
|
||||
ActivityZone::insertAll($insert);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ActivityZone::where('id', $params['id'])->update([
|
||||
'form_id' => $params['form_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ActivityZone::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return ActivityZone::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
public function addProduct($product)
|
||||
{
|
||||
$activityFormId1 = ActivityZoneForm::whereRaw('FIND_IN_SET(:cate_id,cate_ids)', ['cate_id' => $product['two_cate_id']])->column('id');
|
||||
$activityFormId2 = ActivityZoneForm::whereRaw('FIND_IN_SET(:cate_id,cate_ids)', ['cate_id' => $product['cate_id']])->column('id');
|
||||
$activityFormIds = array_unique(array_merge($activityFormId1, $activityFormId2));
|
||||
foreach ($activityFormIds as $activityFormId) {
|
||||
$activityZone = new ActivityZone();
|
||||
$activityZone->form_id = $activityFormId;
|
||||
$activityZone->product_id = $product['id'];
|
||||
$activityZone->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function updateProduct($productId, $product)
|
||||
{
|
||||
$product['id'] = $productId;
|
||||
$formIds = ActivityZone::where('product_id', $productId)->column('form_id');
|
||||
if (empty($formIds)) {
|
||||
$this->addProduct($product);
|
||||
return;
|
||||
}
|
||||
$forms = ActivityZoneForm::whereIn('id', $formIds)->select()->toArray();
|
||||
foreach ($forms as $form) {
|
||||
$cateIds = explode(',', $form['cate_ids']);
|
||||
if (!in_array($product['two_cate_id'], $cateIds) && !in_array($product['cate_id'], $cateIds)) {
|
||||
ActivityZone::where('product_id', $productId)->where('form_id', $form['id'])->update(['delete_time' => time()]);
|
||||
}
|
||||
$this->addProduct($product);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteProduct($productId)
|
||||
{
|
||||
ActivityZone::where('product_id', $productId)->update(['delete_time' => time()]);
|
||||
}
|
||||
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\ChangeLog;
|
||||
use app\common\logic\BaseLogic;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* ChangeLog逻辑
|
||||
* Class ChangeLogLogic
|
||||
* @package app\admin\logic
|
||||
*/
|
||||
class ChangeLogLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ChangeLog::create([
|
||||
'model' => $params['model'],
|
||||
'link_id' => $params['link_id'],
|
||||
'nums' => $params['nums'],
|
||||
'pm' => $params['pm'],
|
||||
'url' => $params['url'],
|
||||
'mark' => $params['mark'],
|
||||
]);
|
||||
|
||||
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/06 10:03
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ChangeLog::where('id', $params['id'])->update([
|
||||
'model' => $params['model'],
|
||||
'link_id' => $params['link_id'],
|
||||
'nums' => $params['nums'],
|
||||
'pm' => $params['pm'],
|
||||
'url' => $params['url'],
|
||||
'mark' => $params['mark'],
|
||||
]);
|
||||
|
||||
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/06 10:03
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ChangeLog::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return ChangeLog::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
}
|
@ -2,17 +2,13 @@
|
||||
|
||||
namespace app\admin\logic\beforehand_order;
|
||||
|
||||
use app\admin\logic\AccountsReceivableLogic;
|
||||
use app\admin\logic\store_branch_product\StoreBranchProductLogic;
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\api\logic\order\CartLogic;
|
||||
use app\api\logic\order\OrderLogic;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\beforehand_order\BeforehandOrderLog;
|
||||
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||
use app\common\model\beforehand_order_record\BeforehandOrderRecord;
|
||||
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||
@ -26,11 +22,9 @@ use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserAddress;
|
||||
use app\common\model\user_ship\UserShip;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\model\warehouse_product_return\WarehouseProductReturn;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use app\common\service\xlsx\OrderAllocation;
|
||||
use app\common\service\xlsx\OrderInfo;
|
||||
use app\common\service\xlsx\OrderList;
|
||||
@ -89,20 +83,18 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
unset($params['product_arr'][$k]);
|
||||
continue;
|
||||
}
|
||||
$v['price'] = trim($v['price']);
|
||||
$v['nums'] = trim($v['nums']);
|
||||
$total_prices = bcmul($v['price'], $v['nums'], 2);
|
||||
$datas[$k]['purchase'] = $v['purchase'];
|
||||
$datas[$k]['mark'] = $v['mark'] ?? '';
|
||||
$datas[$k]['product_id'] = $v['product_id'];
|
||||
$datas[$k]['uid'] = $uid;
|
||||
// $datas[$k]['marques'] = $v['marques'] ?? '';
|
||||
// $datas[$k]['store_info'] = $v['store_info'] ?? '';
|
||||
// $datas[$k]['after_sales'] = $v['after_sales'] ?? '';
|
||||
// $datas[$k]['loss'] = $v['loss'] ?? '';
|
||||
$datas[$k]['marques'] = $v['marques'] ?? '';
|
||||
$datas[$k]['store_info'] = $v['store_info'] ?? '';
|
||||
$datas[$k]['after_sales'] = $v['after_sales'] ?? '';
|
||||
$datas[$k]['loss'] = $v['loss'] ?? '';
|
||||
$datas[$k]['unit'] = $v['unit'] ?? '';
|
||||
// $datas[$k]['gross_weight'] = $v['gross_weight'] ?? '';
|
||||
// $datas[$k]['net_weight'] = $v['net_weight'] ?? '';
|
||||
$datas[$k]['gross_weight'] = $v['gross_weight'] ?? '';
|
||||
$datas[$k]['net_weight'] = $v['net_weight'] ?? '';
|
||||
$datas[$k]['cart_num'] = $v['nums'];
|
||||
$datas[$k]['accept_num'] = $v['nums'];
|
||||
$datas[$k]['is_buyer'] = $is_buyer;
|
||||
@ -118,7 +110,6 @@ 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,
|
||||
@ -132,7 +123,6 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
'address' => $params['address'] ?? '',
|
||||
'mark' => $params['mark'] ?? '',
|
||||
'order_type' => $order_type,
|
||||
'is_arrears' => $params['is_arrears'] ?? 1,
|
||||
'other_data' => json_encode($params['other_data'], true)
|
||||
]);
|
||||
/** 添加审批记录 */
|
||||
@ -142,27 +132,27 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$datas[$k]['bhoid'] = $order['id'];
|
||||
|
||||
$data['id'] = $v['product_id'];
|
||||
// if ($v['marques'] != '') {
|
||||
// $data['marques'] = $v['marques'];
|
||||
// }
|
||||
// if ($v['store_info'] != '') {
|
||||
// $data['store_info'] = $v['store_info'];
|
||||
// }
|
||||
// if ($v['after_sales'] != '') {
|
||||
// $data['after_sales'] = $v['after_sales'];
|
||||
// }
|
||||
// if ($v['package'] != '') {
|
||||
// $data['package'] = $v['package'];
|
||||
// }
|
||||
// if ($v['loss'] != '') {
|
||||
// $data['loss'] = $v['loss'];
|
||||
// }
|
||||
// if ($v['gross_weight'] != '') {
|
||||
// $data['gross_weight'] = $v['gross_weight'];
|
||||
// }
|
||||
// if ($v['net_weight'] != '') {
|
||||
// $data['net_weight'] = $v['net_weight'];
|
||||
// }
|
||||
if ($v['marques'] != '') {
|
||||
$data['marques'] = $v['marques'];
|
||||
}
|
||||
if ($v['store_info'] != '') {
|
||||
$data['store_info'] = $v['store_info'];
|
||||
}
|
||||
if ($v['after_sales'] != '') {
|
||||
$data['after_sales'] = $v['after_sales'];
|
||||
}
|
||||
if ($v['package'] != '') {
|
||||
$data['package'] = $v['package'];
|
||||
}
|
||||
if ($v['loss'] != '') {
|
||||
$data['loss'] = $v['loss'];
|
||||
}
|
||||
if ($v['gross_weight'] != '') {
|
||||
$data['gross_weight'] = $v['gross_weight'];
|
||||
}
|
||||
if ($v['net_weight'] != '') {
|
||||
$data['net_weight'] = $v['net_weight'];
|
||||
}
|
||||
$product_arr[] = $data;
|
||||
}
|
||||
(new StoreProduct())->saveAll($product_arr);
|
||||
@ -185,12 +175,9 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
public static function generateOrder(array $params): bool
|
||||
{
|
||||
$order = BeforehandOrder::where('id', $params['id'])->find();
|
||||
if ($order['order_type'] == 4 || $order['order_type'] == 7) {
|
||||
if ($order['order_type'] == 4) {
|
||||
throw new BusinessException('该订单类型不能生成支付订单');
|
||||
}
|
||||
if (!empty($order['order_sn'])) {
|
||||
throw new BusinessException('当前订单已生成支付订单');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$cart_info = BeforehandOrderCartInfo::where('bhoid', $params['id'])->select()->toArray();
|
||||
@ -203,21 +190,21 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$total_prices = $v['total_price'];
|
||||
$v['uid'] = $params['user_id'];
|
||||
$v['store_id'] = $params['store_id'];
|
||||
$find = StoreBranchProduct::where('store_id', $params['store_id'])->where('product_id', $v['product_id'])->withTrashed()->find();
|
||||
$find = StoreBranchProduct::where('store_id', $params['store_id'])->where('product_id', $v['product_id'])->find();
|
||||
if (!$find) {
|
||||
$product = StoreProduct::where('id', $v['product_id'])->withTrashed()->find();
|
||||
$product = StoreProduct::where('id', $v['product_id'])->find();
|
||||
$find = StoreProductLogic::ordinary($product, $params['store_id'], 0, $product);
|
||||
}
|
||||
|
||||
$cart_select[$k]['price'] = $v['price'];
|
||||
// //判断如果零售价小于供货价,则零售价等于供货价
|
||||
// if ($v['price'] < $find['purchase'] && $find['purchase'] != 0) {
|
||||
// $cart_select[$k]['price'] = $find['purchase'];
|
||||
// }
|
||||
// if ($user['user_ship'] == 4 && $find['cost'] != 0) {
|
||||
// $cart_select[$k]['price'] = $find['cost'];
|
||||
// $total_prices = bcmul($find['cost'], $v['cart_num'], 2);
|
||||
// }
|
||||
//判断如果采购价小于售价,则采购价等于售价
|
||||
if ($v['price'] < $find['purchase'] && $find['purchase'] != 0) {
|
||||
$cart_select[$k]['price'] = $find['purchase'];
|
||||
}
|
||||
if ($user['user_ship'] == 4 && $find['cost'] != 0) {
|
||||
$cart_select[$k]['price'] = $find['cost'];
|
||||
$total_prices = bcmul($find['cost'], $v['cart_num'], 2);
|
||||
}
|
||||
$cart_select[$k]['cost'] = $find['cost'];
|
||||
$cart_select[$k]['purchase'] = $find['purchase'];
|
||||
$cart_select[$k]['vip'] = 0;
|
||||
@ -265,24 +252,17 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
'cart_id' => '',
|
||||
'store_id' => $params['store_id'] ?? 0,
|
||||
'shipping_type' => 2, //配送方式 1=快递 ,2=门店自提
|
||||
'deduction_price' => $params['deduction_price'] ?? 0, //抵扣金额
|
||||
'source' => OrderEnum::SOURCE_20, //来源
|
||||
'order_type' => $order['order_type'],
|
||||
'deduction_price' => 0, //抵扣金额
|
||||
'source' => 2, //后台下单
|
||||
'is_storage' => 0,
|
||||
'verify_code' => createCode($code),
|
||||
];
|
||||
if ($_order['pay_price'] == 0) {
|
||||
throw new BusinessException('支付金额不能为0');
|
||||
}
|
||||
if ($_order['deduction_price'] > 0) {
|
||||
$_order['pay_price'] = bcsub($_order['pay_price'], $_order['deduction_price'], 2);
|
||||
if ($_order['pay_price'] < 0.01) {
|
||||
throw new BusinessException('支付金额不能小于0.01元');
|
||||
}
|
||||
}
|
||||
$_order['uid'] = $uid;
|
||||
$_order['spread_uid'] = 0;
|
||||
$_order['mark'] = $params['mark'] ?? '';
|
||||
$_order['mark'] = '';
|
||||
$_order['real_name'] = $user['real_name'];
|
||||
$_order['user_phone'] = $user['mobile'];
|
||||
$_order['pay_type'] = $params['pay_type'];
|
||||
@ -342,23 +322,12 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
try {
|
||||
$find = BeforehandOrder::where('id', $params['id'])->find();
|
||||
$other_data = $params['other_data'];
|
||||
$data=[
|
||||
$find->save([
|
||||
'other_data' => json_encode($other_data, true),
|
||||
'file' => $params['file'],
|
||||
'store_id' => $params['store_id'],
|
||||
'mark' => $params['mark']
|
||||
];
|
||||
if(!empty($params['order_type']) && $params['order_type']>0){
|
||||
$data['order_type'] = $params['order_type'];
|
||||
if(!empty($find['warehousing_id'])){
|
||||
WarehouseOrder::where(['id' => $find['warehousing_id']])->update(['order_type' => $params['order_type']]);
|
||||
}
|
||||
if(!empty($find['outbound_id'])){
|
||||
WarehouseOrder::where(['id' => $find['outbound_id']])->update(['order_type' => $params['order_type']]);
|
||||
}
|
||||
}
|
||||
$find->save($data);
|
||||
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
@ -377,6 +346,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
public static function createOutboundOrder(array $params): bool
|
||||
{
|
||||
$warehouse_id = $params['warehouse_id'];
|
||||
$store_id = $params['store_id'];
|
||||
$admin_id = $params['admin_id'];
|
||||
$delivery_time = $params['delivery_time'];
|
||||
$mark = $params['remark'] ?? '';
|
||||
@ -390,35 +360,20 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
if ($order['outbound_id'] > 0) {
|
||||
throw new BusinessException('该订单已创建出库单');
|
||||
}
|
||||
$store_id = $order['store_id'];
|
||||
$info = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select()->toArray();
|
||||
$product_column = array_column($info, 'product_id');
|
||||
$storege_arr=WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id','in',$product_column)->select();
|
||||
$info = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select();
|
||||
foreach ($info as $k => $v) {
|
||||
if ($v['pay_price'] <= 0) {
|
||||
throw new BusinessException('商品价格为空 不能生成出库订单,对应id:' . $v['id']);
|
||||
}
|
||||
foreach ($storege_arr as $key => $value) {
|
||||
if ($value['is_verify']==1 && $v['product_id'] == $value['product_id']) {
|
||||
if (($v['cart_num'] < $value['nums'])==false) {
|
||||
$store_name=StoreProduct::where('id', $v['product_id'])->withTrashed()->value('store_name');
|
||||
throw new BusinessException('商品:'.$store_name.'已开启强制库存校验,库存不足,库存数量' . $value['nums'].',需求数量:' . $v['cart_num']);
|
||||
}
|
||||
}
|
||||
throw new BusinessException('商品价格未空 不能生成出库订单,对应id:' . $v['id']);
|
||||
}
|
||||
}
|
||||
$count = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->where('cart_num', 0)->count('id');
|
||||
if ($count > 0) {
|
||||
throw new BusinessException('订单中有数量为0的商品,请先处理');
|
||||
}
|
||||
$user_ship = 0;
|
||||
if ($order['uid'] > 0) {
|
||||
$user_ship = User::where('id', $order['uid'])->value('user_ship') ?? 0;
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$arr = [
|
||||
'oid' => $order['id'],
|
||||
'oid' => 0,
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'store_id' => $store_id,
|
||||
'supplier_id' => 0,
|
||||
@ -427,18 +382,10 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
'financial_pm' => 0,
|
||||
'batch' => 0,
|
||||
'mark' => $mark,
|
||||
'order_type' => $order['order_type'] ?? '',
|
||||
];
|
||||
$arr['delivery_time'] = strtotime($delivery_time);
|
||||
$res = WarehouseOrder::create($arr);
|
||||
$totalPrice = '0.00';
|
||||
foreach ($info as $key => $arr) {
|
||||
// if ($user_ship == 0) {
|
||||
// $price = 0;
|
||||
// } else {
|
||||
// $price = StoreProductGroupPrice::where('product_id', $arr['product_id'])->where('group_id', $user_ship)->value('price') ?? 0;
|
||||
// }
|
||||
$cost = StoreProduct::where('id', $arr['product_id'])->withTrashed()->value('cost') ?? 0;
|
||||
$data = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'product_id' => $arr['product_id'],
|
||||
@ -451,31 +398,16 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
'admin_id' => $admin_id,
|
||||
'total_price' => $arr['total_price'],
|
||||
'price' => $arr['price'],
|
||||
'cost' => $cost,
|
||||
'vip_price' => StoreProduct::where('id',$arr['product_id'])->withTrashed()->value('vip_price') ?? 0,
|
||||
'purchase' => $arr['purchase'],
|
||||
'oid' => $res['id'],
|
||||
'code' => $res['code'],
|
||||
'unit' => $arr['unit'] ?? 0,
|
||||
];
|
||||
$totalPrice = bcadd($totalPrice, $arr['total_price'], 2);
|
||||
if ($arr['store_sale'] == 1) {
|
||||
StoreBranchProductLogic::decStock($store_id, $arr['product_id'], $arr['cart_num']);
|
||||
} else {
|
||||
WarehouseProductLogic::setOutbound($data, 1, $admin_id);
|
||||
}
|
||||
WarehouseProductLogic::setOutbound($data);
|
||||
}
|
||||
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $totalPrice, 'nums' => $finds['nums']]);
|
||||
$result = BeforehandOrder::where('id', $order['id'])->where('outbound_id', 0)->where('is_outbound', 0)->update(['outbound_id' => $res['id'], 'is_outbound' => 1, 'pay_price' => $totalPrice]);
|
||||
if (!$result) {
|
||||
throw new BusinessException('出库失败,预订单更新出错');
|
||||
}
|
||||
BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->update(['is_buyer' => -1]);
|
||||
if ($order['is_arrears'] == 2) {
|
||||
AccountsReceivableLogic::add($order->toArray());
|
||||
}
|
||||
self::confirm(['id' => $params['bhoid']]);
|
||||
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
|
||||
$order->save(['outbound_id' => $res['id'], 'is_outbound' => 1, 'pay_price' => $finds['total_price']]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
@ -484,7 +416,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @notes 一键报损出库
|
||||
* @param array $params
|
||||
* @return bool
|
||||
@ -545,7 +477,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
'code' => $res['code'],
|
||||
'unit' => $arr['unit'] ?? 0,
|
||||
];
|
||||
WarehouseProductLogic::setOutbound($data, 1, $admin_id);
|
||||
WarehouseProductLogic::setOutbound($data);
|
||||
}
|
||||
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
|
||||
@ -580,9 +512,6 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$total_price = $order['total_price'];
|
||||
$uid = $order['uid'];
|
||||
foreach ($info as $k => $v) {
|
||||
if ($v['refund_num'] >= $v['cart_num']) {
|
||||
continue;
|
||||
}
|
||||
$datas[$k]['product_id'] = $v['product_id'];
|
||||
$datas[$k]['uid'] = $uid;
|
||||
$datas[$k]['cart_num'] = $v['cart_num'];
|
||||
@ -595,9 +524,6 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$datas[$k]['update_time'] = time();
|
||||
$total_num += $v['nums'];
|
||||
}
|
||||
if (empty($datas)) {
|
||||
throw new BusinessException('该订单商品已全部退款');
|
||||
}
|
||||
$other_data = [
|
||||
'nickname' => $order['real_name'] ?? '',
|
||||
'phone' => $order['user_phone'] ?? '',
|
||||
@ -628,10 +554,9 @@ 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),
|
||||
'is_arrears' => 2
|
||||
'other_data' => json_encode($other_data, true)
|
||||
|
||||
]);
|
||||
foreach ($datas as $k => $v) {
|
||||
$datas[$k]['bhoid'] = $order['id'];
|
||||
@ -661,20 +586,6 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 确认预订单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
*/
|
||||
public static function confirm(array $params): bool
|
||||
{
|
||||
$res = BeforehandOrder::find($params['id']);
|
||||
if (!empty($res) && $res['is_confirm'] == 0) {
|
||||
BeforehandOrder::where('id', $params['id'])->update(['is_confirm' => 1]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取预订单表详情
|
||||
@ -703,15 +614,6 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$res['examine_name'] = Admin::where('id', $record['check_user_id'])->value('name');
|
||||
}
|
||||
}
|
||||
|
||||
$res['is_vip']=0;
|
||||
if($res['uid']>0){
|
||||
$user_ship=User::where('id',$res['uid'])->value('user_ship');
|
||||
if($user_ship>0){
|
||||
$res['is_vip']=1;
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
@ -776,6 +678,10 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
{
|
||||
$order_info = new OrderInfo();
|
||||
$order = BeforehandOrder::where('id', $params['id'])->find();
|
||||
if ($order['order_type'] == 7 && isset($params['print']) && $params['print'] == 1) {
|
||||
$order->is_buying = 1;
|
||||
$order->save();
|
||||
}
|
||||
$order['admin_name'] = Admin::where('id', $order['admin_id'])->value('name');
|
||||
$data = PurchaseProductOffer::where('order_id', $params['id'])->select()->each(function ($item) {
|
||||
$find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit,gross_weight,net_weight')->withTrashed()->find();
|
||||
@ -817,11 +723,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$find = WarehouseOrder::where('id', $order['outbound_id'])->find();
|
||||
$order['order_id'] = $find['code'];
|
||||
$order['pay_price'] = $find['total_price'];
|
||||
if (!empty($params['type']) && $params['type'] == 3) {
|
||||
$file_path = $order_info->exportWithoutPrice($data, $order, $other_data);
|
||||
} else {
|
||||
$file_path = $order_info->export($data, $order, $other_data);
|
||||
}
|
||||
$file_path = $order_info->export($data, $order, $other_data);
|
||||
return $file_path;
|
||||
}
|
||||
/**
|
||||
@ -922,7 +824,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$v['store_name'] = $find['store_name'];
|
||||
$v['mark'] = $find['after_sales'];
|
||||
$v['pay_price'] = bcmul($v['purchase'], $v['nums'], 2);
|
||||
$v['profit'] = bcsub($v['total_price'], $v['pay_price'], 2);
|
||||
$v['profit']= bcsub($v['total_price'], $v['pay_price'], 2);
|
||||
$total_profit = bcadd($total_profit, $v['profit'], 2);
|
||||
$pay_price = bcadd($pay_price, $v['pay_price'], 2);
|
||||
$total_price = bcadd($total_price, $v['total_price'], 2);
|
||||
@ -951,32 +853,29 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
}
|
||||
$order['admin_name'] = Admin::where('id', $order['admin_id'])->value('name');
|
||||
$data = WarehouseProduct::where('oid', $order['outbound_id'])->where('nums', '>', 0)->select();
|
||||
if ($order['uid'] > 0) {
|
||||
if($order['uid']>0){
|
||||
$user_ship = User::where('id', $order['uid'])->value('user_ship');
|
||||
if ($user_ship == 0) {
|
||||
throw new BusinessException('用户角色id不能为0');
|
||||
if($user_ship==0){
|
||||
throw new BusinessException('用户id不能为0');
|
||||
}
|
||||
} else {
|
||||
throw new BusinessException('该订单没选择会员用户');
|
||||
}else{
|
||||
throw new BusinessException('用户id不能为0');
|
||||
}
|
||||
$total_price = 0;
|
||||
$pay_price = 0;
|
||||
$total_profit = 0;
|
||||
foreach ($data as $k => &$v) {
|
||||
$find = StoreProduct::where('id', $v['product_id'])->field('top_cate_id,store_name,unit,after_sales,cost')->withTrashed()->find();
|
||||
$find = StoreProduct::where('id', $v['product_id'])->field('top_cate_id,store_name,unit,after_sales')->withTrashed()->find();
|
||||
$v['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
$v['store_name'] = $find['store_name'];
|
||||
$v['mark'] = $find['after_sales'];
|
||||
if (isset($params['type']) && $params['type'] == 2) {
|
||||
$v['price'] = $v['vip_price']; //出库单价
|
||||
$v['purchase'] = $v['cost']; //高级会员单,供货价=商户价
|
||||
} else {
|
||||
$v['purchase'] = $v['vip_price'] > 0 ? $v['vip_price'] : $v['price']; //会员单,供货价=会员价
|
||||
$v['purchase']=StoreProductGroupPrice::where('product_id',$v['product_id'])->where('group_id',$user_ship)->value('price');
|
||||
if($v['purchase']){
|
||||
$v['pay_price'] = bcmul($v['purchase'], $v['nums'], 2);
|
||||
}else{
|
||||
$v['pay_price']=0;
|
||||
}
|
||||
|
||||
$v['total_price'] = bcmul($v['price'], $v['nums'], 2); //出库总价
|
||||
$v['pay_price'] = bcmul($v['purchase'], $v['nums'], 2); //供货总价
|
||||
$v['profit'] = bcsub($v['total_price'], $v['pay_price'], 2);
|
||||
$v['profit']= bcsub($v['total_price'], $v['pay_price'], 2);
|
||||
$total_profit = bcadd($total_profit, $v['profit'], 2);
|
||||
$pay_price = bcadd($pay_price, $v['pay_price'], 2);
|
||||
$total_price = bcadd($total_price, $v['total_price'], 2);
|
||||
@ -989,176 +888,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$order['pay_price'] = $pay_price;
|
||||
$order['total_profit'] = $total_profit;
|
||||
$order['total_price'] = $total_price;
|
||||
$order['group_title'] = '';
|
||||
if ($user_ship) {
|
||||
$order['group_title'] = UserShip::where('id', $user_ship)->value('title');
|
||||
}
|
||||
$file_path = $order_info->export($data, $order, $other_data, 2);
|
||||
return $file_path;
|
||||
}
|
||||
|
||||
public static function settleOrder($params)
|
||||
{
|
||||
$order = BeforehandOrder::where('id', $params['id'])->find();
|
||||
if ($order->status != 0) {
|
||||
throw new BusinessException('该订单已完结');
|
||||
}
|
||||
$order->audit_status = 1;
|
||||
$order->save();
|
||||
}
|
||||
|
||||
public static function logList($params)
|
||||
{
|
||||
$auditStatus = BeforehandOrder::where('id', $params['order_id'])->value('audit_status');
|
||||
$list = BeforehandOrderLog::with('admin')->where('order_id', $params['order_id'])->select()->toArray();
|
||||
return [
|
||||
'audit_status' => $auditStatus,
|
||||
'list' => $list,
|
||||
];
|
||||
}
|
||||
|
||||
public static function saveLog($params)
|
||||
{
|
||||
$model = new BeforehandOrderLog();
|
||||
$model->setAttrs($params);
|
||||
$model->save();
|
||||
}
|
||||
|
||||
public static function confirmLog($params)
|
||||
{
|
||||
$model = BeforehandOrderLog::where('id', $params['id'])->find();
|
||||
if ($model->status != 0) {
|
||||
throw new BusinessException('该审核已完成');
|
||||
}
|
||||
$model->status = 1;
|
||||
$model->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计
|
||||
*/
|
||||
public static function statisticsCount($params)
|
||||
{
|
||||
$where = [];
|
||||
$where2 = [];
|
||||
if ($params['store_id'] > 0) {
|
||||
$where2[] = ['store_id', '=', $params['store_id']];
|
||||
}
|
||||
if (!empty($params['is_store'])) {
|
||||
$where[] = ['store_staff_id', '>', 0];
|
||||
$where2[] = ['store_staff_id', '>', 0];
|
||||
} else {
|
||||
$where[] = ['store_staff_id', '=', 0];
|
||||
$where2[] = ['store_staff_id', '=', 0];
|
||||
}
|
||||
if ($params['start_time'] != '' && $params['end_time'] != '') {
|
||||
$where2[] = ['create_time', 'between', [strtotime($params['start_time']), strtotime($params['end_time'])]];
|
||||
}
|
||||
if ($params['warehouse_type'] > 0) {
|
||||
switch ($params['warehouse_type']) {
|
||||
case 1:
|
||||
$where[] = ['is_outbound', '=', 0];
|
||||
$where[] = ['order_type', 'not in', [5, 7]];
|
||||
break;
|
||||
case 2:
|
||||
$where[] = ['is_outbound', '=', 1];
|
||||
break;
|
||||
case 3:
|
||||
$where[] = ['is_warehousing', '=', 0];
|
||||
$where[] = ['order_type', '<>', 1];
|
||||
break;
|
||||
case 4:
|
||||
$where[] = ['is_warehousing', '=', 1];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
$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();
|
||||
if ($params['order_type'] > 0) {
|
||||
$where[] = ['order_type', '=', $params['order_type']];
|
||||
}
|
||||
$outbound_0 = BeforehandOrder::where([['is_outbound', '=', 0], ['order_type', 'not in', [5, 7]]])->where($where)->count();
|
||||
$outbound_1 = BeforehandOrder::where([['is_outbound', '=', 1]])->where($where)->count();
|
||||
$warehousing_0 = BeforehandOrder::where([['is_warehousing', '=', 0]])->where('order_type', '<>', 1)->where($where)->count();
|
||||
$warehousing_1 = BeforehandOrder::where([['is_warehousing', '=', 1]])->where($where)->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
|
||||
];
|
||||
foreach ($orderCounts as $k => $v) {
|
||||
$data['order_type' . '_' . $v['order_type']] = $v['count'];
|
||||
}
|
||||
$data['outbound_0'] = $outbound_0;
|
||||
$data['outbound_1'] = $outbound_1;
|
||||
$data['warehousing_0'] = $warehousing_0;
|
||||
$data['warehousing_1'] = $warehousing_1;
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function copy($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = BeforehandOrder::where('id', $params['id'])->find();
|
||||
if (empty($order)) {
|
||||
throw new BusinessException('订单不存在');
|
||||
}
|
||||
if ($order['order_type'] != 1) {
|
||||
throw new BusinessException('只能复制铺货订单');
|
||||
}
|
||||
$orderCartInfo = BeforehandOrderCartInfo::where('bhoid', $params['id'])->select()->toArray();
|
||||
unset($order['id'], $order['create_time'], $order['update_time'], $order['is_warehousing'], $order['warehousing_id'], $order['is_outbound'], $order['outbound_id']);
|
||||
$newOrder = new BeforehandOrder();
|
||||
$newOrder->setAttrs($order->toArray());
|
||||
$newOrder->admin_id = $params['admin_id'];
|
||||
$newOrder->store_id = $params['store_id'];
|
||||
$newOrder->order_id = getNewOrderId('YG');
|
||||
if (!empty($params['mark'])) {
|
||||
$newOrder->mark = $params['mark'];
|
||||
} else {
|
||||
$newOrder->mark = "复制订单,原订单id:{$params['id']}";
|
||||
}
|
||||
$newOrder->save();
|
||||
$insert = [];
|
||||
foreach ($orderCartInfo as $v) {
|
||||
unset($v['id'], $v['create_time'], $v['update_time']);
|
||||
$v['bhoid'] = $newOrder->id;
|
||||
$insert[] = $v;
|
||||
}
|
||||
(new BeforehandOrderCartInfo())->saveAll($insert);
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function transfer($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = BeforehandOrder::where('id', $params['id'])->findOrEmpty()->toArray();
|
||||
if ($order['is_arrears'] != 1) {
|
||||
throw new BusinessException('该订单已转欠款');
|
||||
}
|
||||
AccountsReceivableLogic::add($order);
|
||||
BeforehandOrder::where('id', $params['id'])->update(['is_arrears' => 2]);
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,14 +2,10 @@
|
||||
|
||||
namespace app\admin\logic\beforehand_order_cart_info;
|
||||
|
||||
use app\admin\logic\product_source_link\ProductSourceLinkLogic;
|
||||
use app\admin\logic\purchase_product_offer\PurchaseProductOfferLogic;
|
||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\product_source_link\ProductSourceLink;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
@ -63,53 +59,24 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
|
||||
*/
|
||||
public static function appendAdd(array $params): bool
|
||||
{
|
||||
$order = BeforehandOrder::where('id', $params['id'])->find();
|
||||
if(empty($params['admin_id'])){
|
||||
if ((!empty($order) && $order->is_confirm == 1 ) || $order['is_outbound'] > 0) {
|
||||
throw new BusinessException('该订单已确认,不能追加商品');
|
||||
}
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$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;
|
||||
$datas[$k]['bhoid'] = $bhoid;
|
||||
$datas[$k]['cart_num'] = $v['nums'];
|
||||
$datas[$k]['accept_num'] = $v['nums'];
|
||||
$datas[$k]['purchase'] = $v['prices']??0;
|
||||
$datas[$k]['price'] = $v['purchase'];
|
||||
$datas[$k]['total_price'] = $v['total_price'];
|
||||
$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 || $order['order_type'] == 9) {
|
||||
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']]);
|
||||
@ -137,11 +104,6 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
|
||||
if($params['admin_id']==23&&$params['purchases']!=$find['price'] ){
|
||||
throw new BusinessException('当前账号没有权限编辑价格, 请联系管理员修改');
|
||||
}
|
||||
$bhoid = $params['bhoid'];
|
||||
$order=BeforehandOrder::where('id', $bhoid)->find();
|
||||
if($order['outbound_id']>0){
|
||||
throw new BusinessException('该订单已出库,不能修改');
|
||||
}
|
||||
if($params['total_price']<=0){
|
||||
$total_price=bcmul($params['purchases'],$params['nums'],2);
|
||||
}else{
|
||||
@ -155,10 +117,12 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
|
||||
'accept_num' => $params['nums'],
|
||||
'mark' => $params['mark']??'',
|
||||
]);
|
||||
$bhoid = $params['bhoid'];
|
||||
$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();
|
||||
if($find['is_buyer']==1){
|
||||
PurchaseProductOffer::where('order_id',$bhoid)->where('product_id',$find['product_id'])->update(['need_num'=>$params['nums']]);
|
||||
}
|
||||
$order=BeforehandOrder::where('id', $bhoid)->find();
|
||||
$order->save(['total_price' => $info['total_price'],'pay_price' => $info['pay_price'], 'total_num' => $info['cart_num']]);
|
||||
|
||||
if($order['outbound_id']>0){
|
||||
@ -237,8 +201,6 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
|
||||
$arr = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'supplier_id' => 0,
|
||||
'order_type' => $beforehandOrder['order_type']??0,
|
||||
'oid' => $beforehandOrder['id'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'financial_pm' => 1,
|
||||
'batch' => 0,
|
||||
@ -263,43 +225,26 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
|
||||
$data['purchase'] = $v['price'];
|
||||
$data['total_price'] = $v['total_price'];
|
||||
$data['financial_pm'] = 1;
|
||||
$data['manufacture'] = $v['manufacture'] > 0 ? date('Y-m-d H:i:s', $v['manufacture']) : '';
|
||||
$data['expiration_date'] = $v['expiration_date'] > 0 ? date('Y-m-d H:i:s', $v['expiration_date']) : '';
|
||||
$product_arr=[];
|
||||
// if($v['package']!=''){
|
||||
// $product_arr['package']=$v['package'];
|
||||
// }
|
||||
// if($v['store_info']!=''){
|
||||
// $product_arr['store_info']=$v['store_info'];
|
||||
// }
|
||||
// if($v['marques']!=''){
|
||||
// $product_arr['marques']=$v['marques'];
|
||||
// }
|
||||
// if($v['after_sales']!=''){
|
||||
// $product_arr['after_sales']=$v['after_sales'];
|
||||
// }
|
||||
if($v['package']!=''){
|
||||
$product_arr['package']=$v['package'];
|
||||
}
|
||||
if($v['store_info']!=''){
|
||||
$product_arr['store_info']=$v['store_info'];
|
||||
}
|
||||
if($v['marques']!=''){
|
||||
$product_arr['marques']=$v['marques'];
|
||||
}
|
||||
if($v['after_sales']!=''){
|
||||
$product_arr['after_sales']=$v['after_sales'];
|
||||
}
|
||||
if($product_arr!=[]){
|
||||
StoreProduct::where('id',$v['product_id'])->save($product_arr);
|
||||
}
|
||||
if ($data['nums'] > 0) {
|
||||
WarehouseProductLogic::add($data,1,$params['admin_id']);
|
||||
}
|
||||
WarehouseProductLogic::add($data);
|
||||
PurchaseProductOffer::where('id', $v['id'])->update(['status' => 1, 'is_storage' => 1]);
|
||||
}
|
||||
$attrs = ['warehousing_id' => $res['id'],'is_warehousing'=>1];
|
||||
if ($beforehandOrder['order_type'] == 7) {
|
||||
$attrs['is_buying'] = 1;
|
||||
}
|
||||
$result = BeforehandOrder::where('id', $params['bhoid'])->where('warehousing_id', 0)->where('is_warehousing', 0)->update($attrs);
|
||||
if (!$result) {
|
||||
throw new BusinessException('出库失败,预订单更新出错');
|
||||
}
|
||||
ProductSourceLink::add([
|
||||
'purchase_product_offer' => $offer_list,
|
||||
'types' => ProductSourceLinkInfo::TypeIn,
|
||||
'buyer_id' => $res['buyer_id'],
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
]);
|
||||
BeforehandOrder::where('id', $params['bhoid'])->update(['warehousing_id' => $res['id'],'is_warehousing'=>1]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
@ -321,9 +266,8 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
|
||||
PurchaseProductOffer::where('order_id',$find['bhoid'])->where('product_id',$find['product_id'])->update(['delete_time'=>time()]);
|
||||
}
|
||||
$res=BeforehandOrderCartInfo::destroy($params['id']);
|
||||
$pay_price=BeforehandOrderCartInfo::where('bhoid', $find['bhoid'])->sum('pay_price');
|
||||
$total_price=BeforehandOrderCartInfo::where('bhoid', $find['bhoid'])->sum('total_price');
|
||||
BeforehandOrder::where('id',$find['bhoid'])->update(['pay_price'=>$pay_price, 'total_price'=>$total_price]);
|
||||
$pay_price=BeforehandOrderCartInfo::where('bhoid', $params['id'])->sum('pay_price');
|
||||
BeforehandOrder::where('id',$find['bhoid'])->update(['pay_price'=>$pay_price]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
@ -350,137 +294,4 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
public static function syncPrice($params)
|
||||
{
|
||||
$outbound_id=BeforehandOrder::where('id', $params['bhoid'])->value('outbound_id');
|
||||
if($outbound_id>0){
|
||||
throw new BusinessException('该订单已出库,不能修改');
|
||||
}
|
||||
$cartInfo = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select()->toArray();
|
||||
$productIds = array_column($cartInfo, 'product_id');
|
||||
$products = StoreProduct::whereIn('id', $productIds)->select()->toArray();
|
||||
$products = reset_index($products, 'id');
|
||||
$update = [];
|
||||
foreach ($cartInfo as $v) {
|
||||
$product = $products[$v['product_id']];
|
||||
if (empty($product) || empty($product['price'])) {
|
||||
continue;
|
||||
}
|
||||
$update[] = [
|
||||
'id' => $v['id'],
|
||||
'price' => $product['price'],
|
||||
'total_price' => $product['price'] * $v['cart_num'],
|
||||
'pay_price' => $product['price'] * $v['cart_num'],
|
||||
];
|
||||
}
|
||||
(new BeforehandOrderCartInfo())->saveAll($update);
|
||||
}
|
||||
|
||||
public static function setStoreSale($params)
|
||||
{
|
||||
$cartInfo = BeforehandOrderCartInfo::where('id', $params['id'])->find();
|
||||
if ($cartInfo['store_sale'] == 1) {
|
||||
$update = ['store_sale' => 0];
|
||||
} else {
|
||||
$update = ['store_sale' => 1];
|
||||
}
|
||||
BeforehandOrderCartInfo::where('id', $params['id'])->update($update);
|
||||
}
|
||||
|
||||
public static function putInStorage($params)
|
||||
{
|
||||
if ($params['warehouse_id'] <= 0 || $params['warehouse_id'] == '') {
|
||||
throw new BusinessException('请选择入库仓库');
|
||||
}
|
||||
$purchaseProductOffer = PurchaseProductOffer::where('id', $params['id'])->find();
|
||||
if (empty($purchaseProductOffer) || $params['warehouse_num'] == 0 || empty($purchaseProductOffer['total_price'])) {
|
||||
throw new BusinessException('请先设置采购信息再入库');
|
||||
}
|
||||
if ($purchaseProductOffer['is_storage'] == 1) {
|
||||
throw new BusinessException('商品已入库');
|
||||
}
|
||||
$beforehandOrder = BeforehandOrder::where('id', $params['bhoid'])->field('id,buyer_id,order_type,warehousing_id,is_warehousing')->find();
|
||||
|
||||
$completed_amount = PurchaseProductOffer::where(['order_id' => $params['bhoid'], 'pay_type' => 1, 'is_storage' => 1])->sum('total_price');
|
||||
$outstanding_amount = PurchaseProductOffer::where(['order_id' => $params['bhoid'], 'pay_type' => 2, 'is_storage' => 1])->sum('total_price');
|
||||
if ($purchaseProductOffer['pay_type'] == 1) {
|
||||
$completed_amount = bcadd($completed_amount, $purchaseProductOffer['total_price'], 2);
|
||||
} else {
|
||||
$outstanding_amount = bcadd($outstanding_amount, $purchaseProductOffer['total_price'], 2);
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$warehouseOrder = WarehouseOrder::where('oid', $purchaseProductOffer['order_id'])->where('financial_pm', 1)->find();
|
||||
if (empty($warehouseOrder)) {
|
||||
$arr = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'supplier_id' => 0,
|
||||
'order_type' => $beforehandOrder['order_type'] ?? 0,
|
||||
'oid' => $beforehandOrder['id'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'financial_pm' => 1,
|
||||
'batch' => 0,
|
||||
'code' => getNewOrderId('RK'),
|
||||
'mark' => $params['remark'] ?? '',
|
||||
'total_price' => $purchaseProductOffer['total_price'],
|
||||
'completed_amount' => $completed_amount,
|
||||
'outstanding_amount' => $outstanding_amount,
|
||||
];
|
||||
$warehouseOrder = WarehouseOrder::create($arr);
|
||||
} else {
|
||||
$warehouseOrder->total_price = bcadd($warehouseOrder->total_price, $purchaseProductOffer['total_price'], 2);
|
||||
$warehouseOrder->save();
|
||||
}
|
||||
$purchaseProductOffer['price'] = bcdiv($purchaseProductOffer['total_price'], $params['warehouse_num'], 2);
|
||||
$data['admin_id'] = $params['admin_id'];
|
||||
$data['order_type'] = $beforehandOrder['order_type'];
|
||||
$data['store_id'] = 0;
|
||||
$data['pay_type'] = $purchaseProductOffer['pay_type'];
|
||||
$data['oid'] = $warehouseOrder['id'];
|
||||
$data['supplier_id'] = $purchaseProductOffer['supplier_id'];
|
||||
$data['warehouse_id'] = $params['warehouse_id'];
|
||||
$data['code'] = $warehouseOrder['code'];
|
||||
$data['product_id'] = $purchaseProductOffer['product_id'];
|
||||
$data['nums'] = $params['warehouse_num'];
|
||||
$data['purchase'] = $purchaseProductOffer['price'];
|
||||
$data['total_price'] = $purchaseProductOffer['total_price'];
|
||||
$data['financial_pm'] = 1;
|
||||
$data['buyer_id'] = $beforehandOrder['buyer_id'];
|
||||
$data['buyer_nums'] = $data['nums'];
|
||||
$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) {
|
||||
$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);
|
||||
if (!$offerResult) {
|
||||
throw new BusinessException('入库失败,采购信息更新出错');
|
||||
}
|
||||
if ($beforehandOrder['is_warehousing'] == 0) {
|
||||
$attrs = ['warehousing_id' => $warehouseOrder['id'], 'is_warehousing' => 1];
|
||||
if ($beforehandOrder['order_type'] == 7) {
|
||||
$attrs['is_buying'] = 1;
|
||||
}
|
||||
$result = BeforehandOrder::where('id', $params['bhoid'])->where('warehousing_id', 0)->where('is_warehousing', 0)->update($attrs);
|
||||
if (!$result) {
|
||||
throw new BusinessException('入库失败,预订单更新出错');
|
||||
}
|
||||
}
|
||||
$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();
|
||||
|
||||
if (!in_array($beforehandOrder['order_type'], [6, 9])) {
|
||||
PurchaseProductOfferLogic::setProductPrice($purchaseProductOffer, $product, $params['warehouse_id'], $warehouseProduct->id ?? 0);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -96,30 +96,4 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 扣减采购人员资金
|
||||
* @param $uid
|
||||
* @param $amount
|
||||
* @return void
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\inventory_store;
|
||||
|
||||
|
||||
use app\common\model\inventory_store\InventoryStore;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use support\exception\BusinessException;
|
||||
use think\db\Raw;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 门店盘存逻辑
|
||||
* Class InventoryStoreLogic
|
||||
* @package app\admin\logic\inventory_store
|
||||
*/
|
||||
class InventoryStoreLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加门店盘存
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/02/14 11:46
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$find=InventoryStore::where('store_id', $params['store_id'])->whereDay('create_time')->find();
|
||||
if($find){
|
||||
throw new BusinessException('今日数据已生成');
|
||||
}
|
||||
$arr=StoreBranchProduct::where('store_id',$params['store_id'])->field('product_id,store_id,stock as nums')->select()->toArray();
|
||||
(new InventoryStore())->saveAll($arr);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑门店盘存
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/02/14 11:46
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
InventoryStore::where('id', $params['id'])->update([
|
||||
'admin_id'=>$params['admin_id']??0,
|
||||
'enter_nums'=>$params['nums']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
public static function enterNums(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
InventoryStore::where('store_id', $params['store_id'])->whereDay('create_time',$params['create_time'])->update([
|
||||
'status'=>2
|
||||
]);
|
||||
|
||||
$arr=InventoryStore::where('store_id', $params['store_id'])->where('nums','<>',new Raw('enter_nums'))->whereDay('create_time',$params['create_time'])->select();
|
||||
foreach ($arr as $k=>$v){
|
||||
StoreBranchProduct::where('product_id',$v['product_id'])->where('store_id',$v['store_id'])->update([
|
||||
'stock'=>$v['enter_nums']
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除门店盘存
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/02/14 11:46
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return InventoryStore::destroy($params['id']);
|
||||
}
|
||||
|
||||
}
|
@ -4,12 +4,9 @@ namespace app\admin\logic\inventory_transfer;
|
||||
|
||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\common\model\inventory_transfer\InventoryTransfer;
|
||||
use app\admin\logic\inventory_transfer_order\InventoryTransferOrderLogic;
|
||||
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 app\common\model\inventory_transfer_order\InventoryTransferOrder;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
@ -30,55 +27,69 @@ class InventoryTransferLogic extends BaseLogic
|
||||
* @author admin
|
||||
* @date 2024/08/13 16:18
|
||||
*/
|
||||
public static function add(array $params, $admin_id = 0)
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
$find = InventoryTransferOrder::where('id', $params['oid'])->find()->toArray();
|
||||
if (empty($params['product_arr'])) {
|
||||
throw new BusinessException('请选择商品');
|
||||
$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($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('调拨类型错误');
|
||||
}
|
||||
$productIds = array_column($params['product_arr'], 'id');
|
||||
if ($find['one_type'] == 1) {
|
||||
$outProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $find['one_id'])->field('id,product_id,stock')->select()->toArray();
|
||||
} else {
|
||||
$outProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $find['one_id'])->field('id,product_id,nums stock')->select()->toArray();
|
||||
}
|
||||
$outProducts = reset_index($outProducts, 'product_id');
|
||||
if ($find['two_type'] == 1) {
|
||||
$inProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $find['two_id'])->field('id,product_id,stock')->select()->toArray();
|
||||
} else {
|
||||
$inProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $find['two_id'])->field('id,product_id,nums stock')->select()->toArray();
|
||||
}
|
||||
$inProducts = reset_index($inProducts, 'product_id');
|
||||
$insert = [];
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$insert = [];
|
||||
foreach ($params['product_arr'] as $v) {
|
||||
$outProduct = !empty($outProducts[$v['id']]) ? $outProducts[$v['id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['id']];
|
||||
$inProduct = !empty($inProducts[$v['id']]) ? $inProducts[$v['id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['id']];
|
||||
if ($outProduct['stock'] < $v['nums']) {
|
||||
throw new BusinessException("出库商品库存不足 {$outProduct['product_id']} 调拨数量不能大于当前仓库库存");
|
||||
continue;
|
||||
}
|
||||
$insert[] = [
|
||||
'oid' => $find['id'],
|
||||
'product_id' => $v['id'],
|
||||
'nums' => $v['nums'],
|
||||
'remark' => $v['remark'],
|
||||
'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' => $find['one_type'],
|
||||
'two_type' => $find['two_type'],
|
||||
'one_id' => $find['one_id'],
|
||||
'two_id' => $find['two_id'],
|
||||
'create_time' => time(),
|
||||
];
|
||||
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){
|
||||
StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['one_id'])->dec('stock', $params['nums'])->update();
|
||||
} elseif ($params['one_type'] == 2) {
|
||||
WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['one_id'])->dec('nums', $params['nums'])->update();
|
||||
}
|
||||
InventoryTransfer::insertAll($insert);
|
||||
if ($find['two_type'] == 1 && $find['status'] == 1) {
|
||||
InventoryTransferOrderLogic::audit($find, $insert, $admin_id);
|
||||
if($params['two_type']==1){
|
||||
StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['two_id'])->inc('stock', $params['nums'])->update();
|
||||
} elseif ($params['two_type'] == 2) {
|
||||
WarehouseProductStorege::where('product_id', $params['product_id'])->where('warehouse_id', $params['two_id'])->inc('nums', $params['nums'])->update();
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
|
@ -1,237 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\inventory_transfer_order;
|
||||
|
||||
|
||||
use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic;
|
||||
use app\common\model\inventory_transfer_order\InventoryTransferOrder;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\inventory_transfer\InventoryTransfer;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\warehouse\Warehouse;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 商品调拨订单逻辑
|
||||
* Class InventoryTransferOrderLogic
|
||||
* @package app\admin\logic\inventory_transfer_order
|
||||
*/
|
||||
class InventoryTransferOrderLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加商品调拨订单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/01/24 09:59
|
||||
*/
|
||||
public static function add(array $params, $admin_id): bool
|
||||
{
|
||||
$types = $params['types'] ?? 0;
|
||||
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 = [];
|
||||
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
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']} 调拨数量不能大于当前仓库库存");
|
||||
}
|
||||
$insert[] = [
|
||||
'product_id' => $v['product_id'],
|
||||
'nums' => $v['nums'],
|
||||
'remark' => $v['remark'],
|
||||
'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(),
|
||||
];
|
||||
}
|
||||
$order = InventoryTransferOrder::create([
|
||||
'order_id' => getNewOrderId('DB'),
|
||||
'one_type' => $params['one_type'],
|
||||
'two_type' => $params['two_type'],
|
||||
'one_id' => $params['one_id'],
|
||||
'two_id' => $params['two_id'],
|
||||
'types' => $types,
|
||||
'mark' => $params['mark'] ?? '',
|
||||
'status' => ($params['two_type'] == 2 && $types == 0) ? 0 : 1,
|
||||
]);
|
||||
foreach ($insert as $k => $v) {
|
||||
$insert[$k]['oid'] = $order['id'];
|
||||
}
|
||||
InventoryTransfer::insertAll($insert);
|
||||
if ($types == 0 && $params['two_type'] == 1) {
|
||||
self::audit($params, $insert, $admin_id);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function audit($order = null, $products = null, $admin_id = 0)
|
||||
{
|
||||
if (empty($products)) {
|
||||
$products = InventoryTransfer::where('oid', $order['id'])->select()->toArray();
|
||||
}
|
||||
foreach ($products as $v) {
|
||||
if ($order['one_type'] == 1) {
|
||||
$find = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $order['one_id'])->find();
|
||||
$find->save(['stock' => bcsub($find['stock'], $v['nums'], 2)]);
|
||||
SqlChannelLog('StoreBranchProduct', $find['id'], $v['nums'], -1, Request()->url(), $admin_id);
|
||||
} elseif ($order['one_type'] == 2) {
|
||||
$find = WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id', $order['one_id'])->find();
|
||||
$find->save(['nums' => bcsub($find['nums'], $v['nums'], 2)]);
|
||||
SqlChannelLog('WarehouseProductStorege', $find['id'], $v['nums'], -1, Request()->url(), $admin_id);
|
||||
}
|
||||
if ($order['two_type'] == 1) {
|
||||
$find = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $order['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 = $order['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 ($order['two_type'] == 2) {
|
||||
$find = WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id', $order['two_id'])->find();
|
||||
if (empty($find)) {
|
||||
$find = new WarehouseProductStorege();
|
||||
$find->warehouse_id = $order['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);
|
||||
}
|
||||
InventoryTransferOrder::where('id', $order['id'])->update(['status' => 1]);
|
||||
|
||||
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
||||
$productSourceLinkInfoLogic->setInfo([
|
||||
'oid' => $v['oid'],
|
||||
'product_id' => $v['product_id'],
|
||||
]);
|
||||
$productSourceLinkInfoLogic->transfer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑商品调拨订单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/01/24 09:59
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
InventoryTransferOrder::where('id', $params['id'])->update([
|
||||
'order_id' => $params['order_id'],
|
||||
'one_id' => $params['one_id'],
|
||||
'one_type' => $params['one_type'],
|
||||
'two_id' => $params['two_id'],
|
||||
'two_type' => $params['two_type'],
|
||||
'types' => $params['types'],
|
||||
'total_nums' => $params['total_nums'],
|
||||
'total_price' => $params['total_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/24 09:59
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return InventoryTransferOrder::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品调拨订单详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2025/01/24 09:59
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data = InventoryTransferOrder::findOrEmpty($params['id']);
|
||||
$type_name = '';
|
||||
if ($data->one_type == 1) {
|
||||
$data->one_name = SystemStore::where('id', $data->one_id)->value('name');
|
||||
$type_name = '门店转';
|
||||
} else {
|
||||
$data->one_name = Warehouse::where('id', $data->one_id)->value('name');
|
||||
$type_name = '仓库转';
|
||||
}
|
||||
if ($data->two_type == 1) {
|
||||
$type_name .= '门店';
|
||||
$data->two_name = SystemStore::where('id', $data->two_id)->value('name');
|
||||
} else {
|
||||
$type_name .= '仓库';
|
||||
$data->two_name = Warehouse::where('id', $data->two_id)->value('name');
|
||||
}
|
||||
$data->type_name = $type_name;
|
||||
$data['product_list'] = InventoryTransfer::where('oid', $params['id'])->select()->each(function ($item) {
|
||||
$find = StoreProduct::where('id', $item->product_id)->withTrashed()->field('store_name')->find();
|
||||
$item->store_name = $find['store_name'] ?? '';
|
||||
})
|
||||
->toArray();
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\inventory_warehouse;
|
||||
|
||||
|
||||
use app\common\model\inventory_warehouse\InventoryWarehouse;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use support\exception\BusinessException;
|
||||
use think\db\Raw;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 仓库盘存逻辑
|
||||
* Class InventoryWarehouseLogic
|
||||
* @package app\admin\logic\inventory_warehouse
|
||||
*/
|
||||
class InventoryWarehouseLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加仓库盘存
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/02/14 17:24
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$find=InventoryWarehouse::where('warehouse_id', 1)->whereDay('create_time')->find();
|
||||
if($find){
|
||||
throw new BusinessException('今日数据已生成');
|
||||
}
|
||||
$arr=WarehouseProductStorege::where('warehouse_id',1)->field('product_id,nums,warehouse_id')->select()->toArray();
|
||||
(new InventoryWarehouse())->saveAll($arr);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑仓库盘存
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/02/14 17:24
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
InventoryWarehouse::where('id', $params['id'])->update([
|
||||
'admin_id'=>$params['admin_id']??0,
|
||||
'enter_nums'=>$params['nums']
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除仓库盘存
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/02/14 17:24
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return InventoryWarehouse::destroy($params['id']);
|
||||
}
|
||||
|
||||
public static function enterNums(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
InventoryWarehouse::where('warehouse_id', $params['warehouse_id'])->whereDay('create_time',$params['create_time'])->update([
|
||||
'status'=>2
|
||||
]);
|
||||
|
||||
$arr=InventoryWarehouse::where('warehouse_id', $params['warehouse_id'])->where('nums','<>',new Raw('enter_nums'))->whereDay('create_time',$params['create_time'])->select();
|
||||
foreach ($arr as $k=>$v){
|
||||
WarehouseProductStorege::where('product_id',$v['product_id'])->where('warehouse_id',$v['warehouse_id'])->update([
|
||||
'nums'=>$v['enter_nums']
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\product_image;
|
||||
|
||||
|
||||
use app\common\model\product_image\ProductImage;
|
||||
use app\common\logic\BaseLogic;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 商品图库管理逻辑
|
||||
* Class ProductImageLogic
|
||||
* @package app\admin\logic\product_image
|
||||
*/
|
||||
class ProductImageLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加商品图库管理
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/04/14 11:02
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProductImage::create([
|
||||
'product_id' => $params['product_id'],
|
||||
'entity_id' => $params['entity_id'],
|
||||
'group_id' => $params['group_id'],
|
||||
'pic_name' => $params['pic_name'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑商品图库管理
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/04/14 11:02
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProductImage::where('id', $params['id'])->update([
|
||||
'product_id' => $params['product_id'],
|
||||
'entity_id' => $params['entity_id'],
|
||||
'group_id' => $params['group_id'],
|
||||
'pic_name' => $params['pic_name'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除商品图库管理
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/04/14 11:02
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ProductImage::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品图库管理详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2025/04/14 11:02
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return ProductImage::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\product_source_link;
|
||||
|
||||
|
||||
use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic;
|
||||
use app\admin\service\ProductPriceService;
|
||||
use app\common\model\product_source_link\ProductSourceLink;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 商品溯源管理逻辑
|
||||
* Class ProductSourceLinkLogic
|
||||
* @package app\admin\logic\product_source_link
|
||||
*/
|
||||
class ProductSourceLinkLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加商品溯源管理
|
||||
* @param array $info
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:03
|
||||
*/
|
||||
public static function add(array $info): bool
|
||||
{
|
||||
foreach ($info['purchase_product_offer'] as $offer) {
|
||||
$model = ProductSourceLink::where('product_id', $offer['product_id'])->where('purchase_uid', $info['buyer_id'])->where('warehouse_id', $info['warehouse_id'])->find();
|
||||
if (empty($model)) {
|
||||
$model = new ProductSourceLink();
|
||||
$model->product_id = $offer['product_id'];
|
||||
$model->purchase_uid = $info['buyer_id'];
|
||||
$model->warehouse_id = $info['warehouse_id'];
|
||||
$model->save();
|
||||
}
|
||||
$attrs = [
|
||||
'oid' => $model['id'],
|
||||
'product_id' => $offer['product_id'],
|
||||
'warehouse_id' => $info['warehouse_id'],
|
||||
'nums' => $offer['buyer_nums'],
|
||||
'current_nums' => $offer['buyer_nums'],
|
||||
'types' => $info['types'],
|
||||
'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 = (new ProductPriceService())->getProductPriceRate($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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑商品溯源管理
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:03
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProductSourceLink::where('id', $params['id'])->update([
|
||||
'purchase_uid' => $params['purchase_uid'],
|
||||
'product_id' => $params['product_id'],
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
]);
|
||||
|
||||
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/12 10:03
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ProductSourceLink::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品溯源管理详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:03
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return ProductSourceLink::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
}
|
@ -1,544 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\product_source_link_info;
|
||||
|
||||
|
||||
use app\admin\service\ProductPriceService;
|
||||
use app\common\model\inventory_transfer\InventoryTransfer;
|
||||
use app\common\model\product_source_link\ProductSourceLink;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use app\common\logic\BaseLogic;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 商品溯源详细逻辑
|
||||
* Class ProductSourceLinkInfoLogic
|
||||
* @package app\admin\logic\product_source_link_info
|
||||
*/
|
||||
class ProductSourceLinkInfoLogic extends BaseLogic
|
||||
{
|
||||
|
||||
public $purchaseProductOffer = []; // 采购商品数据
|
||||
public $orderProduct = []; // 订单商品数据
|
||||
public $warehouseProduct = []; // 出入库商品数据
|
||||
public $storeProductPrice = []; // 商品改价数据
|
||||
|
||||
public $info = [
|
||||
'warehouse_id' => 0,
|
||||
'buyer_id' => 0,
|
||||
'types' => 0,
|
||||
'link_id' => 0,
|
||||
'is_store_order' => 0,
|
||||
'store_id' => 0,
|
||||
'create_time' => 0,
|
||||
'product_id' => 0,
|
||||
'nums' => 0,
|
||||
'add_nums' => 0,
|
||||
'oid' => 0,
|
||||
];
|
||||
|
||||
public function setInfo($info)
|
||||
{
|
||||
$this->info = array_merge($this->info, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加商品溯源详细
|
||||
* @param array $params
|
||||
* @return ProductSourceLinkInfo
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:08
|
||||
*/
|
||||
public static function add(array $params)
|
||||
{
|
||||
$model = new ProductSourceLinkInfo();
|
||||
$model->setAttrs($params);
|
||||
$model->save();
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑商品溯源详细
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:08
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProductSourceLinkInfo::where('id', $params['id'])->update([
|
||||
'oid' => $params['oid'],
|
||||
'product_id' => $params['product_id'],
|
||||
'nums' => $params['nums'],
|
||||
'types' => $params['types'],
|
||||
'link_id' => $params['link_id'],
|
||||
'total_price' => $params['total_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/03/12 10:08
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ProductSourceLinkInfo::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品溯源详细详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2025/03/12 10:08
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return ProductSourceLinkInfo::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 仓库入库
|
||||
* @return bool
|
||||
*/
|
||||
public function putInStorage(): bool
|
||||
{
|
||||
if (empty($this->purchaseProductOffer)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$model = ProductSourceLink::where('product_id', $this->purchaseProductOffer['product_id'])->where('purchase_uid', $this->info['buyer_id'])->where('warehouse_id', $this->info['warehouse_id'])->find();
|
||||
if (empty($model)) {
|
||||
$model = new ProductSourceLink();
|
||||
$model->product_id = $this->purchaseProductOffer['product_id'];
|
||||
$model->purchase_uid = $this->info['buyer_id'];
|
||||
$model->warehouse_id = $this->info['warehouse_id'];
|
||||
$model->save();
|
||||
}
|
||||
$attrs = [
|
||||
'oid' => $model['id'],
|
||||
'product_id' => $this->purchaseProductOffer['product_id'],
|
||||
'warehouse_id' => $this->info['warehouse_id'],
|
||||
'nums' => $this->purchaseProductOffer['buyer_nums'],
|
||||
'current_nums' => $this->purchaseProductOffer['buyer_nums'],
|
||||
'types' => $this->info['types'],
|
||||
'link_id' => $this->info['link_id'],
|
||||
'price' => $this->purchaseProductOffer['price'],
|
||||
'total_price' => $this->purchaseProductOffer['total_price'],
|
||||
'purchase_funds_id' => $this->purchaseProductOffer['purchase_funds_id'] ?? 0,
|
||||
];
|
||||
if ($attrs['types'] == ProductSourceLinkInfo::TypeIn) {
|
||||
// 商品入库,记录采购总价和供货总价
|
||||
$priceRate = (new ProductPriceService())->getProductPriceRate($this->purchaseProductOffer['product_id']);
|
||||
$attrs['purchase_price'] = $this->purchaseProductOffer['total_price'];
|
||||
$rate = bcdiv($priceRate['supply_rate'], 100, 2);
|
||||
$attrs['supply_price'] = bcmul(bcmul($this->purchaseProductOffer['price'], $rate, 2), $this->purchaseProductOffer['nums'], 2);
|
||||
}
|
||||
ProductSourceLinkInfoLogic::add($attrs);
|
||||
return true;
|
||||
} catch (BusinessException $e) {
|
||||
Log::error('商品入库溯源信息保存失败' . $e->getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 仓库出库
|
||||
* @return true
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function outbound()
|
||||
{
|
||||
$query = ProductSourceLinkInfo::where('product_id', $this->warehouseProduct['product_id'])->where('current_nums', '>', 0);
|
||||
$query->whereIn('types', [ProductSourceLinkInfo::TypeIn, ProductSourceLinkInfo::TypeS2W, ProductSourceLinkInfo::TypeW2W]);
|
||||
$productSourceLinkInfo = $query->select()->toArray();
|
||||
$needNum = $this->warehouseProduct['nums'];
|
||||
return $this->putOutStorage($productSourceLinkInfo, $needNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单销售出库
|
||||
* @return true
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function sale()
|
||||
{
|
||||
$query = ProductSourceLinkInfo::where('product_id', $this->orderProduct['product_id'])->where('current_nums', '>', 0);
|
||||
$query->where('store_id', $this->info['store_id'])->whereIn('types', [ProductSourceLinkInfo::TypeStoreIn, ProductSourceLinkInfo::TypeS2S]);
|
||||
$productSourceLinkInfo = $query->select()->toArray();
|
||||
$needNum = $this->orderProduct['nums'];
|
||||
return $this->putOutStorage($productSourceLinkInfo, $needNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新入库单的数量和价格
|
||||
* @return void
|
||||
* @throws DbException
|
||||
*/
|
||||
public function updateInStorageNum()
|
||||
{
|
||||
$data = ProductSourceLinkInfo::where('link_id', $this->info['link_id'])->where('types', ProductSourceLinkInfo::TypeIn)->findOrEmpty()->toArray();
|
||||
$attrs['nums'] = bcadd($data['nums'], $this->info['add_nums'], 2);
|
||||
$attrs['current_nums'] = bcadd($data['current_nums'], $this->info['add_nums'], 2);
|
||||
$attrs['total_price'] = bcmul($this->info['nums'], $data['price'], 2);
|
||||
$attrs['supply_price'] = bcmul($this->info['nums'], bcdiv($data['supply_price'], $data['nums'], 2), 2);
|
||||
ProductSourceLinkInfo::where('id', $data['id'])->update($attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新出库单的数量和价格
|
||||
* @return void
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function updateOutboundNum()
|
||||
{
|
||||
if ($this->info['add_nums'] < 0) {
|
||||
$list = ProductSourceLinkInfo::where('link_id', $this->info['link_id'])->where('types', ProductSourceLinkInfo::TypeOut)->order('id desc')->select()->toArray();
|
||||
if (empty($list)) {
|
||||
return;
|
||||
}
|
||||
$rollbackNum = abs($this->info['add_nums']);
|
||||
$update = [];
|
||||
foreach ($list as $item) {
|
||||
if ($item['nums'] > $rollbackNum) {
|
||||
$update = $this->setUpdate($item, $rollbackNum, $update);
|
||||
break;
|
||||
} else {
|
||||
$update = $this->setUpdate($item, $item['nums'], $update);
|
||||
}
|
||||
$rollbackNum = bcsub($rollbackNum, $item['nums'], 2);
|
||||
}
|
||||
(new ProductSourceLinkInfo())->saveAll($update);
|
||||
} else {
|
||||
$data = ProductSourceLinkInfo::where('link_id', $this->info['link_id'])->where('types', ProductSourceLinkInfo::TypeOut)->findOrEmpty()->toArray();
|
||||
if (empty($data)) {
|
||||
return;
|
||||
}
|
||||
$update = $this->setUpdate($data, -$this->info['add_nums'], []);
|
||||
(new ProductSourceLinkInfo())->saveAll($update);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据linkId删除
|
||||
* @param $linkId
|
||||
* @param $types
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function deleteByLinkId($linkId, $types)
|
||||
{
|
||||
$list = ProductSourceLinkInfo::where('link_id', $linkId)->where('types', $types)->select()->toArray();
|
||||
$update = [];
|
||||
foreach ($list as $item) {
|
||||
if ($types == ProductSourceLinkInfo::TypeOut && $item['from_id'] > 0) {
|
||||
$update[] = [
|
||||
'id' => $item['from_id'],
|
||||
'current_nums' => Db::raw("current_nums+{$item['nums']}"),
|
||||
];
|
||||
}
|
||||
$update[] = [
|
||||
'id' => $item['id'],
|
||||
'delete_time' => time(),
|
||||
];
|
||||
}
|
||||
(new ProductSourceLinkInfo())->saveAll($update);
|
||||
}
|
||||
|
||||
private function getInsertAndUpdate($update, $insert, $currentNum, $item, $needNum)
|
||||
{
|
||||
$time = time();
|
||||
$update[] = [
|
||||
'id' => $item['id'],
|
||||
'current_nums' => $currentNum,
|
||||
'update_time' => $time,
|
||||
];
|
||||
$exist = ProductSourceLinkInfo::field('id,from_id,nums,current_nums')->where('link_id', $this->info['link_id'])->where('types', ProductSourceLinkInfo::TypeOut)->findOrEmpty()->toArray();
|
||||
if (!empty($exist) && $exist['from_id'] == $item['id']) {
|
||||
$itemNums = bcadd($exist['nums'], $needNum, 2);
|
||||
$itemCurrentNums = bcadd($exist['current_nums'], $needNum, 2);
|
||||
$update[] = [
|
||||
'id' => $exist['id'],
|
||||
'nums' => $itemNums,
|
||||
'current_nums' => $itemCurrentNums,
|
||||
'total_price' => bcmul($item['price'], $itemNums, 2),
|
||||
'update_time' => $time,
|
||||
];
|
||||
} else {
|
||||
$insertItem = [
|
||||
'product_id' => $item['product_id'],
|
||||
'warehouse_id' => $this->info['warehouse_id'],
|
||||
'store_id' => $this->info['store_id'],
|
||||
'oid' => $item['oid'],
|
||||
'types' => empty($this->info['types']) ? ProductSourceLinkInfo::TypeOut : $this->info['types'],
|
||||
'link_id' => $this->info['link_id'],
|
||||
'from_id' => $item['id'],
|
||||
'nums' => $needNum,
|
||||
'current_nums' => $needNum,
|
||||
'price' => $item['price'],
|
||||
'total_price' => bcmul($item['price'], $needNum, 2),
|
||||
'purchase_funds_id' => $item['purchase_funds_id'],
|
||||
'create_time' => !empty($this->info['create_time']) ? $this->info['create_time'] : $time,
|
||||
'update_time' => $time,
|
||||
'trace_info' => empty($item['trace_info']) ? $item['id'] : $item['trace_info'] . ',' . $item['id'],
|
||||
];
|
||||
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'] = $this->orderProduct['price'];
|
||||
$insertItem['total_price'] = bcmul($insertItem['price'], $insertItem['nums'], 2);
|
||||
$insertItem['supply_price'] = bcmul($this->orderProduct['supply_price'], $insertItem['nums'], 2);
|
||||
}
|
||||
$insert[] = $insertItem;
|
||||
}
|
||||
return [$update, $insert];
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品溯源供货价
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function updateSupplyPrice()
|
||||
{
|
||||
$productSourceLinkInfo = ProductSourceLinkInfo::where('product_id', $this->storeProductPrice['product_id'])
|
||||
->where('link_id', $this->storeProductPrice['warehouse_product_id'])
|
||||
->where('types', ProductSourceLinkInfo::TypeIn)
|
||||
->find();
|
||||
if (!empty($productSourceLinkInfo)) {
|
||||
ProductSourceLinkInfo::where('id', $productSourceLinkInfo['id'])->update(['supply_price' => bcmul($this->storeProductPrice['purchase'], $productSourceLinkInfo['nums'], 2)]);
|
||||
$list = ProductSourceLinkInfo::field('id,nums,types')
|
||||
->whereFindInSet('trace_info', $productSourceLinkInfo['id'])
|
||||
->select()->toArray();
|
||||
$update = [];
|
||||
foreach ($list as $item) {
|
||||
if (in_array($item['types'], [ProductSourceLinkInfo::TypeOrder, ProductSourceLinkInfo::TypeOrderRefund])) {
|
||||
$update[] = [
|
||||
'id' => $item['id'],
|
||||
'supply_price' => bcmul($this->storeProductPrice['purchase'], $item['nums'], 2),
|
||||
];
|
||||
} else {
|
||||
$update[] = [
|
||||
'id' => $item['id'],
|
||||
'price' => $this->storeProductPrice['purchase'],
|
||||
'total_price' => bcmul($this->storeProductPrice['purchase'], $item['nums'], 2),
|
||||
];
|
||||
}
|
||||
}
|
||||
(new ProductSourceLinkInfo())->saveAll($update);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店退库
|
||||
* @return void
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function storeRollback()
|
||||
{
|
||||
$list = ProductSourceLinkInfo::where('link_id', $this->info['link_id'])
|
||||
->where('product_id', $this->info['product_id'])
|
||||
->where('types', ProductSourceLinkInfo::TypeStoreIn)
|
||||
->order('id desc')->select()->toArray();
|
||||
if (empty($list)) {
|
||||
return;
|
||||
}
|
||||
$rollbackNum = abs($this->info['nums']);
|
||||
$update = [];
|
||||
foreach ($list as $item) {
|
||||
if ($item['nums'] > $rollbackNum) {
|
||||
$update = $this->setUpdate2($item, $rollbackNum, $update);
|
||||
break;
|
||||
} else {
|
||||
$update = $this->setUpdate2($item, $item['nums'], $update);
|
||||
}
|
||||
$rollbackNum = bcsub($rollbackNum, $item['nums'], 2);
|
||||
}
|
||||
(new ProductSourceLinkInfo())->saveAll($update);
|
||||
}
|
||||
|
||||
private function setUpdate(array $data, float|int|string $rollbackNum, array $update): array
|
||||
{
|
||||
$dataNums = bcsub($data['nums'], $rollbackNum, 2);
|
||||
$currentNums = max(bcsub($data['current_nums'], $rollbackNum, 2), 0);
|
||||
$rollbackPrice = bcmul($data['price'], $rollbackNum, 2);
|
||||
$update[] = [
|
||||
'id' => $data['id'],
|
||||
'nums' => $dataNums,
|
||||
'current_nums' => $currentNums,
|
||||
'total_price' => bcmul($data['price'], $dataNums, 2),
|
||||
'delete_time' => $dataNums > 0 ? null : time(),
|
||||
];
|
||||
if ($data['from_id'] > 0) {
|
||||
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-{$rollbackPrice}"),
|
||||
];
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品调拨
|
||||
* @return void
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function transfer()
|
||||
{
|
||||
$inventoryTransfer = InventoryTransfer::field('id,nums,one_type,one_id,two_type,two_id')
|
||||
->where('oid', $this->info['oid'])
|
||||
->where('product_id', $this->info['product_id'])
|
||||
->findOrEmpty()->toArray();
|
||||
if (empty($inventoryTransfer)) {
|
||||
return;
|
||||
}
|
||||
$this->info['link_id'] = $inventoryTransfer['id'];
|
||||
$query = ProductSourceLinkInfo::where('product_id', $this->info['product_id']);
|
||||
if ($inventoryTransfer['one_type'] == 1) {
|
||||
$query->where('store_id', $inventoryTransfer['one_id'])->whereIn('types', [ProductSourceLinkInfo::TypeStoreIn, ProductSourceLinkInfo::TypeS2S]);
|
||||
$this->info['types'] = $inventoryTransfer['two_type'] == 1 ? ProductSourceLinkInfo::TypeS2S : ProductSourceLinkInfo::TypeS2W;
|
||||
} else {
|
||||
$this->info['types'] = ProductSourceLinkInfo::TypeW2W;
|
||||
$query->where('warehouse_id', $inventoryTransfer['one_id'])->whereIn('types', [ProductSourceLinkInfo::TypeIn, ProductSourceLinkInfo::TypeS2W, ProductSourceLinkInfo::TypeW2W]);
|
||||
}
|
||||
if ($inventoryTransfer['two_type'] == 1) {
|
||||
$this->info['store_id'] = $inventoryTransfer['two_id'];
|
||||
} else {
|
||||
$this->info['store_id'] = $inventoryTransfer['one_id'];
|
||||
$this->info['warehouse_id'] = $inventoryTransfer['two_id'];
|
||||
}
|
||||
$list = $query->where('current_nums', '>', 0)
|
||||
->field('id,oid,product_id,warehouse_id,store_id,purchase_funds_id,nums,current_nums,link_id,from_id,price,trace_info')
|
||||
->select()->toArray();
|
||||
if (empty($list)) {
|
||||
return;
|
||||
}
|
||||
$update = [];
|
||||
$insert = [];
|
||||
$needNum = $inventoryTransfer['nums'];
|
||||
foreach ($list as $item) {
|
||||
$currentNum = max(bcsub($item['current_nums'], $needNum, 2), 0);
|
||||
if ($item['current_nums'] > $needNum) {
|
||||
[$update, $insert] = $this->getInsertAndUpdate($update, $insert, $currentNum, $item, $needNum);
|
||||
break;
|
||||
} else {
|
||||
[$update, $insert] = $this->getInsertAndUpdate($update, $insert, 0, $item, $item['current_nums']);
|
||||
}
|
||||
$needNum = $needNum - $item['current_nums'];
|
||||
}
|
||||
(new ProductSourceLinkInfo())->saveAll($update);
|
||||
(new ProductSourceLinkInfo())->insertAll($insert);
|
||||
}
|
||||
|
||||
/**
|
||||
* 门店入库
|
||||
* @return void
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function storeInStorage()
|
||||
{
|
||||
$list = ProductSourceLinkInfo::where('link_id', $this->info['link_id'])
|
||||
->where('product_id', $this->info['product_id'])
|
||||
->where('types', ProductSourceLinkInfo::TypeOut)
|
||||
->select()->toArray();
|
||||
if (empty($list)) {
|
||||
return;
|
||||
}
|
||||
$insert = [];
|
||||
foreach ($list as $item) {
|
||||
$insert[] = [
|
||||
'oid' => $item['oid'],
|
||||
'product_id' => $item['product_id'],
|
||||
'warehouse_id' => $this->info['warehouse_id'],
|
||||
'store_id' => $this->info['store_id'],
|
||||
'nums' => $item['nums'],
|
||||
'current_nums' => $item['nums'],
|
||||
'types' => $this->info['types'],
|
||||
'link_id' => $this->info['link_id'],
|
||||
'from_id' => $item['id'],
|
||||
'price' => $item['price'],
|
||||
'total_price' => $item['total_price'],
|
||||
'purchase_funds_id' => $item['purchase_funds_id'],
|
||||
'trace_info' => empty($item['trace_info']) ? $item['id'] : $item['trace_info'] . ',' . $item['id'],
|
||||
];
|
||||
}
|
||||
ProductSourceLinkInfo::insertAll($insert);
|
||||
}
|
||||
|
||||
public function putOutStorage(array $productSourceLinkInfo, mixed $needNum): bool
|
||||
{
|
||||
$update = [];
|
||||
$insert = [];
|
||||
foreach ($productSourceLinkInfo as $item) {
|
||||
$this->info['warehouse_id'] = empty($this->info['warehouse_id']) ? $item['warehouse_id'] : $this->info['warehouse_id'];
|
||||
$this->info['store_id'] = empty($this->info['store_id']) ? $item['store_id'] : $this->info['store_id'];
|
||||
$currentNum = max(bcsub($item['current_nums'], $needNum, 2), 0);
|
||||
if ($item['current_nums'] > $needNum) {
|
||||
[$update, $insert] = $this->getInsertAndUpdate($update, $insert, $currentNum, $item, $needNum);
|
||||
break;
|
||||
} else {
|
||||
[$update, $insert] = $this->getInsertAndUpdate($update, $insert, 0, $item, $item['current_nums']);
|
||||
}
|
||||
$needNum = $needNum - $item['current_nums'];
|
||||
}
|
||||
(new ProductSourceLinkInfo())->saveAll($update);
|
||||
(new ProductSourceLinkInfo())->insertAll($insert);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@
|
||||
namespace app\admin\logic\purchase_product_offer;
|
||||
|
||||
|
||||
use app\admin\service\ProductPriceService;
|
||||
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\auth\Admin;
|
||||
@ -16,7 +15,6 @@ 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;
|
||||
@ -43,16 +41,13 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$procurementOrder = BeforehandOrder::where('order_type', 7)
|
||||
->where('buyer_id', $params['buyer_id'])
|
||||
->where('is_buying', 0)
|
||||
->where('create_time', '>=', strtotime('today'))
|
||||
->find();
|
||||
$procurementOrder = BeforehandOrder::where('order_type', 7)->where('is_buying', 0)->where('create_time', '>=', strtotime('-3 days'))->find();
|
||||
if (empty($procurementOrder)) {
|
||||
$beforeOrder = BeforehandOrder::where('id', $params['order_id'])->findOrEmpty()->toArray();
|
||||
unset($beforeOrder['id'], $beforeOrder['create_time'], $beforeOrder['update_time']);
|
||||
$procurementOrder = new BeforehandOrder();
|
||||
$procurementOrder->setAttrs($beforeOrder);
|
||||
$procurementOrder->order_id = getNewOrderId('CG');
|
||||
$procurementOrder->buyer_id = $params['buyer_id'];
|
||||
$procurementOrder->admin_id = $params['admin_id'];
|
||||
$procurementOrder->order_type = 7;
|
||||
$procurementOrder->total_price = 0;
|
||||
$procurementOrder->pay_price = 0;
|
||||
@ -62,8 +57,12 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
if ($mark == '') {
|
||||
$mark = BeforehandOrderCartInfo::where('bhoid', $params['order_id'])->where('product_id', $params['product_id'])->value('mark');
|
||||
}
|
||||
$find=StoreProduct::where('id',$params['product_id'])->find();
|
||||
$purchaseProductOffer = PurchaseProductOffer::where(['order_id' => $procurementOrder['id'], 'product_id' => $params['product_id']])->find();
|
||||
if (isset($params['merge_product']) && $params['merge_product'] == 1 && $purchaseProductOffer) {
|
||||
$procurementOrder->total_price = bcadd($procurementOrder->total_price, bcmul($find['price'], $params['need_num'], 2), 2);
|
||||
$procurementOrder->pay_price = $procurementOrder->total_price;
|
||||
$procurementOrder->save();
|
||||
if ($purchaseProductOffer) {
|
||||
$purchaseProductOffer->need_num = $purchaseProductOffer['need_num'] + $params['need_num'];
|
||||
if (!empty($purchaseProductOffer['source_order_info'])) {
|
||||
$sourceOrderInfo = $purchaseProductOffer['source_order_info'];
|
||||
@ -85,10 +84,10 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
'need_num' => $params['need_num'],
|
||||
'mark' => $mark,
|
||||
'buyer_id' => $params['buyer_id'],
|
||||
// 'package' => $find['package'],
|
||||
// 'store_info' => $find['store_info'],
|
||||
// 'marques' => $find['marques'],
|
||||
// 'after_sales' => $find['after_sales'],
|
||||
'package' => $find['package'],
|
||||
'store_info' => $find['store_info'],
|
||||
'marques' => $find['marques'],
|
||||
'after_sales' => $find['after_sales'],
|
||||
'status' => 0,
|
||||
'source_order_info' => [
|
||||
[
|
||||
@ -100,70 +99,15 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
]
|
||||
]);
|
||||
}
|
||||
BeforehandOrderCartInfo::where(['bhoid' => $params['order_id'], 'product_id' => $params['product_id']])->update(['is_buyer' => 1, 'procurement_order_id' => $procurementOrder['id']]);
|
||||
BeforehandOrderCartInfo::where(['bhoid' => $params['order_id'], 'product_id' => $params['product_id']])->update(['is_buyer' => 1]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
d($e);
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notes 一键添加往期采购商品
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/14 15:06
|
||||
*/
|
||||
public static function AddPurchasesOneClick(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$arr=BeforehandOrderCartInfo::where('bhoid',$params['order_id'])->select();
|
||||
$data_arr=[];
|
||||
$procurementOrder = new BeforehandOrder();
|
||||
$procurementOrder->order_id = getNewOrderId('CG');
|
||||
$procurementOrder->buyer_id = $params['buyer_id'];
|
||||
$procurementOrder->admin_id = $params['admin_id'];
|
||||
$procurementOrder->order_type = 9;
|
||||
$procurementOrder->total_price = 0;
|
||||
$procurementOrder->pay_price = 0;
|
||||
$procurementOrder->save();
|
||||
foreach ($arr as $k=>$v){
|
||||
$data_arr[]=[
|
||||
'order_id' => $procurementOrder['id'],
|
||||
'product_id' => $v['product_id'],
|
||||
'unit' => $v['unit'],
|
||||
'is_buyer' => $v['is_buyer'],
|
||||
'need_num' => $v['cart_num'],
|
||||
'buyer_id' => $params['buyer_id'],
|
||||
'mark' => '往期补单采购',
|
||||
'package' => '',
|
||||
'store_info' => '',
|
||||
'marques' => '',
|
||||
'after_sales' => '',
|
||||
'status' => 0,
|
||||
'source_order_info' => [
|
||||
[
|
||||
'source_order_id' => $params['order_id'],
|
||||
'product_id' => $v['product_id'],
|
||||
'need_num' => $v['cart_num'],
|
||||
'mark' => '往期补单采购',
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
(new PurchaseProductOffer())->saveAll($data_arr);
|
||||
|
||||
BeforehandOrderCartInfo::where(['bhoid' => $params['order_id']])->update(['is_buyer' => 1, 'procurement_order_id' => $procurementOrder['id']]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑采购商品
|
||||
@ -212,14 +156,7 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
*/
|
||||
public static function setProcureInfo(array $params): bool
|
||||
{
|
||||
$params['manufacture'] = !empty($params['manufacture']) ? strtotime($params['manufacture']) : '';
|
||||
$params['expiration_date'] = !empty($params['expiration_date']) ? strtotime($params['expiration_date']) : '';
|
||||
$offer = PurchaseProductOffer::where(['id' => $params['id']])->find();
|
||||
$lastPrice = PurchaseProductOffer::where(['product_id' => $offer['product_id']])->where('status', 1)->order('id desc')->value('price');
|
||||
$currentPrice = bcdiv($params['total_price'], $params['buyer_nums'], 2);
|
||||
if ($lastPrice > 0 && ($currentPrice > $lastPrice * 3 || $currentPrice < $lastPrice / 3)) {
|
||||
// throw new BusinessException('价格异常,请重新输入');
|
||||
}
|
||||
// $uid=Admin::where('id',$params['admin_id'])->value('uid');
|
||||
// if($params['admin_id']!=1){
|
||||
// if($offer['buyer_id']!=$uid){
|
||||
@ -229,37 +166,61 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
Db::startTrans();
|
||||
try {
|
||||
$offer->save([
|
||||
'buyer_nums' => $params['buyer_nums'],
|
||||
'buyer_nums' => $params['buyer_nums'],
|
||||
'supplier_id' => $params['supplier_id'],
|
||||
// 'price' => $params['purchase'],
|
||||
// 'purchase_price' => $params['purchase_price'] ?? 0,
|
||||
'price' => $params['purchase'],
|
||||
'outbound_price' => $params['outbound_price'] ?? 0,
|
||||
'total_price' => $params['total_price'],
|
||||
'pay_type' => $params['pay_type'] ?? 0,
|
||||
'buyer_confirm' => 1,
|
||||
// 'package' => $params['package'],
|
||||
// 'store_info' => $params['store_info'],
|
||||
// 'marques' => $params['marques'],
|
||||
// 'after_sales' => $params['after_sales'],
|
||||
// 'manufacture' => $params['manufacture'],
|
||||
// 'expiration_date' => $params['expiration_date'],
|
||||
'package' => $params['package'],
|
||||
'store_info' => $params['store_info'],
|
||||
'marques' => $params['marques'],
|
||||
'after_sales' => $params['after_sales'],
|
||||
]);
|
||||
// $find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id,cate_id')->find();
|
||||
$unit_name = StoreProductUnit::where('id', $offer['unit'])->value('name');
|
||||
$order = BeforehandOrder::where('id', $params['bhoid'])->find();
|
||||
$order->pay_price = PurchaseProductOffer::where('order_id', $order['id'])->sum('total_price');
|
||||
$order->total_price = $order->pay_price;
|
||||
$order->save();
|
||||
// $find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id')->find();
|
||||
$unit_name=StoreProductUnit::where('id', $offer['unit'])->value('name');
|
||||
self::setProductGroupPrice($params, $product);
|
||||
// $data = [];
|
||||
// $dict_data = DictData::where('type_value', 'price_lv_' . $product['top_cate_id'])->field('name,value')->select();
|
||||
// $data['bhoid'] = $offer['order_id'];
|
||||
// $data['offer_id'] = $params['id'];
|
||||
// $data['product_id'] = $offer['product_id'];
|
||||
// $data['purchase_price'] = $params['purchase'];
|
||||
// $data['status'] = 0;
|
||||
// if ($dict_data) {
|
||||
// foreach ($dict_data as $k => $v) {
|
||||
// if ($v['name'] == 'purchase') {
|
||||
// $data['purchase_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['purchase'] = bcadd($lv, $params['purchase'], 2);
|
||||
// } elseif ($v['name'] == 'cost') {
|
||||
// $data['cost_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['cost'] = bcadd($lv, $params['purchase'], 2);
|
||||
// } elseif ($v['name'] == 'price') {
|
||||
// $data['price_lv'] = $v['value'];
|
||||
// $lv = bcmul($v['value'], $params['purchase'], 2);
|
||||
// $data['price'] = bcadd($lv, $params['purchase'], 2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if ($find) {
|
||||
// $find->save($data);
|
||||
// } else {
|
||||
// StoreProductPrice::create($data);
|
||||
// }
|
||||
Db::commit();
|
||||
$offer['store_name'] = $product['store_name'];
|
||||
$offer['unit_name'] = $unit_name;
|
||||
$offer['buyer_name'] = DeliveryService::where('uid', $offer['buyer_id'])->value('nickname');
|
||||
if ($offer['pay_type'] == 1) {
|
||||
$offer['pay_type_name'] = '赊账';
|
||||
} elseif ($offer['pay_type'] == 2) {
|
||||
$offer['pay_type_name'] = '现金';
|
||||
} else {
|
||||
$offer['pay_type_name'] = '没设置';
|
||||
$offer['store_name']=$product['store_name'];
|
||||
$offer['unit_name']=$unit_name;
|
||||
$offer['buyer_name']=DeliveryService::where('uid',$offer['buyer_id'])->value('nickname');
|
||||
if($offer['pay_type']==1){
|
||||
$offer['pay_type_name']='赊账';
|
||||
}elseif($offer['pay_type']==2){
|
||||
$offer['pay_type_name']='现金';
|
||||
}else{
|
||||
$offer['pay_type_name']='没设置';
|
||||
}
|
||||
ProductOffer::push($offer);
|
||||
return true;
|
||||
@ -312,25 +273,22 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($params['accept_num']<=0){
|
||||
throw new BusinessException('分拣数量不能小于0');
|
||||
PurchaseProductOffer::where('id', $params['id'])->update(['is_accept' => 1]);
|
||||
$find=BeforehandOrderCartInfo::where(['bhoid' => $params['bhoid'], 'product_id' => $params['product_id']])->find();
|
||||
$data=[
|
||||
'gross_weight' => $params['gross_weight'] ?? 0,
|
||||
'net_weight' => $params['net_weight'] ?? 0,
|
||||
'accept_num' => $params['accept_num'] ?? 0,
|
||||
];
|
||||
if($params['accept_num']!=$find['cart_num']){
|
||||
$pay_price=bcmul($params['accept_num'], $find['price'], 2);
|
||||
$data['pay_price']=$pay_price;
|
||||
}
|
||||
$offer=PurchaseProductOffer::where('id', $params['id'])->find();
|
||||
$offer_data = ['buyer_nums' => $params['accept_num'],];
|
||||
$offer_data['is_storage'] = 1;
|
||||
if($offer['total_price']>0){
|
||||
$price= bcdiv($offer['total_price'],$params['accept_num'], 2);
|
||||
$offer_data['price'] = $price;
|
||||
}else{
|
||||
throw new BusinessException('采购总价不能为0');
|
||||
$find->save($data);
|
||||
if($params['accept_num']!=$find['cart_num']){
|
||||
$pay_price=BeforehandOrderCartInfo::where(['bhoid' => $params['bhoid']])->sum('pay_price');
|
||||
BeforehandOrder::where('id', $params['bhoid'])->update(['pay_price' => $pay_price]);
|
||||
}
|
||||
$offer->save($offer_data);
|
||||
|
||||
$pay_price = PurchaseProductOffer::where(['order_id' => $offer['order_id']])->sum('total_price');
|
||||
BeforehandOrder::where('id', $offer['bhoid'])->update(['pay_price' => $pay_price]);
|
||||
$product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id,cate_id')->find();
|
||||
$offer['purchase']=$price;
|
||||
self::setProductPrice($offer, $product);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
@ -385,36 +343,62 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
return PurchaseProductOffer::destroy($params['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置商品价格
|
||||
* @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, $warehouseProductId = 0)
|
||||
public static function setProductGroupPrice($params, $product)
|
||||
{
|
||||
$priceConfig = [];
|
||||
$data = [
|
||||
'bhoid' => $params['order_id'],
|
||||
'bhoid' => $params['bhoid'],
|
||||
'offer_id' => $params['id'],
|
||||
'product_id' => $product['id'],
|
||||
'purchase_price' => $params['purchase'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
'status' => 0,
|
||||
'warehouse_id' => $warehouseId,
|
||||
'warehouse_product_id' => $warehouseProductId,
|
||||
];
|
||||
$productService = new ProductPriceService();
|
||||
$productPriceRate = $productService->getProductPriceRate($product['id']);
|
||||
if (!empty($productPriceRate)) {
|
||||
$priceArray = $productService->setProductPrice($params['purchase'], $productPriceRate);
|
||||
$data = array_merge($data, $priceArray);
|
||||
$productCatePriceRate = StoreCategory::where('id', $product['top_cate_id'])->value('price_rate');
|
||||
if (!empty($productCatePriceRate)) {
|
||||
$storeProductGroupPrice = StoreProductGroupPrice::where('product_id', $product['id'])->select()->toArray();
|
||||
$storeProductGroupPrice = reset_index($storeProductGroupPrice, 'group_id');
|
||||
foreach ($productCatePriceRate as $k => $v) {
|
||||
if ($v['id'] == 4) {
|
||||
$data['cost_lv'] = bcdiv($v['rate'], 100, 2);
|
||||
$data['cost'] = bcmul($params['purchase'], bcadd($data['cost_lv'], 1, 2), 2);
|
||||
continue;
|
||||
} elseif ($v['id'] == 100001) {
|
||||
$data['purchase_lv'] = bcdiv($v['rate'], 100, 2);
|
||||
$data['purchase'] = bcmul($params['purchase'], bcadd($data['purchase_lv'], 1, 2), 2);
|
||||
continue;
|
||||
} elseif ($v['id'] == 100002) {
|
||||
$data['price_lv'] = bcdiv($v['rate'], 100, 2);
|
||||
$data['price'] = bcmul($params['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 = 100 + $v['rate'];
|
||||
$item = [
|
||||
'product_id' => $product['id'],
|
||||
'group_id' => $v['id'],
|
||||
'group_name' => $v['title'],
|
||||
'price' => bcmul($params['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($params['purchase'], $item['base_rate'] / 100, 2);
|
||||
$item['id'] = $storeProductGroupPrice[$v['id']]['id'];
|
||||
}
|
||||
$priceConfig[] = $item;
|
||||
}
|
||||
}
|
||||
$data['price_config'] = $priceConfig;
|
||||
$find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||
@ -424,134 +408,4 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
StoreProductPrice::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 已废弃,使用(new ProductPriceService())->getProductPriceRate($product['id'])
|
||||
* @param $product
|
||||
* @return array|int[]
|
||||
*/
|
||||
public static function getProductPriceRate($product)
|
||||
{
|
||||
$list = StoreProductPriceList::where('product_id', $product['id'])->findOrEmpty()->toArray();
|
||||
if (empty($list)) {
|
||||
$list = [
|
||||
'supply_rate' => 110,
|
||||
'merchant_rate' => 103,
|
||||
'vip_rate' => 115,
|
||||
'price_rate' => 120,
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
* 获取商品分类价格比例
|
||||
* @param $product
|
||||
* @return array|mixed
|
||||
*/
|
||||
public static function getProductCatePriceRate($product)
|
||||
{
|
||||
$productCatePriceRate = StoreCategory::where('id', $product['cate_id'])->value('price_rate');
|
||||
if (!empty($productCatePriceRate) && self::hasPurchase($productCatePriceRate)) {
|
||||
return $productCatePriceRate;
|
||||
}
|
||||
$productCatePriceRate = StoreCategory::where('id', $product['two_cate_id'])->value('price_rate');
|
||||
if (!empty($productCatePriceRate) && self::hasPurchase($productCatePriceRate)) {
|
||||
return $productCatePriceRate;
|
||||
}
|
||||
$productCatePriceRate = StoreCategory::where('id', $product['top_cate_id'])->value('price_rate');
|
||||
if (!empty($productCatePriceRate) && self::hasPurchase($productCatePriceRate)) {
|
||||
return $productCatePriceRate;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
* @param array $productCatePriceRate
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasPurchase(array $productCatePriceRate): bool
|
||||
{
|
||||
$res = true;
|
||||
foreach ($productCatePriceRate as $item) {
|
||||
if ($item['id'] == 21 && empty($item['rate'])) {
|
||||
$res = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function batchCreate($params)
|
||||
{
|
||||
if (empty($params['buyer_id'])) {
|
||||
throw new BusinessException('请选择采购员');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$procurementOrder = new BeforehandOrder();
|
||||
$procurementOrder->order_id = getNewOrderId('CG');
|
||||
$procurementOrder->buyer_id = $params['buyer_id'];
|
||||
$procurementOrder->admin_id = $params['admin_id'];
|
||||
$procurementOrder->order_type = $params['order_type'];
|
||||
$procurementOrder->total_price = 0;
|
||||
$procurementOrder->pay_price = 0;
|
||||
$procurementOrder->save();
|
||||
$purchaseOffer = [];
|
||||
$cartInfo = [];
|
||||
foreach ($params['product_arr'] as $product) {
|
||||
if ($product['product_id'] <= 0) {
|
||||
continue;
|
||||
}
|
||||
$product['price'] = trim($product['price']);
|
||||
$product['nums'] = trim($product['nums']);
|
||||
$cartInfo[] = [
|
||||
'bhoid' => $procurementOrder['id'],
|
||||
'product_id' => $product['product_id'],
|
||||
'unit' => $product['unit'],
|
||||
'cart_num' => $product['nums'],
|
||||
'accept_num' => $product['nums'],
|
||||
'mark' => $product['mark'] ?? '',
|
||||
'is_buyer' => 1,
|
||||
'procurement_order_id' => $procurementOrder['id'],
|
||||
'total_price' => bcmul($product['price'], $product['nums'], 2),
|
||||
'pay_price' => bcmul($product['price'], $product['nums'], 2),
|
||||
'purchase' => $product['purchase'],
|
||||
'uid' => $params['uid'],
|
||||
'price' => $product['price'],
|
||||
'package' => $product['package'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
$purchaseOffer[] = [
|
||||
'order_id' => $procurementOrder['id'],
|
||||
'product_id' => $product['product_id'],
|
||||
'unit' => $product['unit'],
|
||||
'is_buyer' => 1,
|
||||
'need_num' => $product['nums'],
|
||||
'mark' => $product['mark'] ?? '',
|
||||
'buyer_id' => $params['buyer_id'],
|
||||
'status' => 0,
|
||||
'source_order_info' => [
|
||||
[
|
||||
'source_order_id' => $procurementOrder['id'],
|
||||
'product_id' => $product['product_id'],
|
||||
'need_num' => $product['nums'],
|
||||
'mark' => $product['mark'] ?? '',
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
PurchaseProductOffer::insertAll($purchaseOffer);
|
||||
BeforehandOrderCartInfo::insertAll($cartInfo);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -267,17 +267,14 @@ class WarehouseLogic extends BaseLogic
|
||||
/**
|
||||
* 负库存更新归0
|
||||
*/
|
||||
public static function updateNegativeZero($parmas,$admin_id=0)
|
||||
public static function updateNegativeZero($parmas)
|
||||
{
|
||||
if ($parmas['type'] == 1) {
|
||||
$res = StoreProduct::where('id', $parmas['id'])->update(['stock' => 0]);
|
||||
SqlChannelLog('StoreProduct', $parmas['id'], 0, 0, Request()->url(),$admin_id);
|
||||
} elseif ($parmas['type'] == 2) {
|
||||
$res = StoreBranchProduct::where('id', $parmas['id'])->update(['stock' => 0]);
|
||||
SqlChannelLog('StoreBranchProduct', $parmas['id'], 0, 0, Request()->url(),$admin_id);
|
||||
} elseif ($parmas['type'] == 3) {
|
||||
$res = WarehouseProductStorege::where('id', $parmas['id'])->update(['nums' => 0]);
|
||||
SqlChannelLog('WarehouseProductStorege', $parmas['id'], 0, 0, Request()->url(),$admin_id);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
@ -2,9 +2,7 @@
|
||||
|
||||
namespace app\admin\logic\store_branch_product;
|
||||
|
||||
use app\admin\logic\product_source_link\ProductSourceLinkLogic;
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
@ -69,7 +67,7 @@ class StoreBranchProductLogic extends BaseLogic
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException('商品编辑失败:', $e->getMessage());
|
||||
throw new BusinessException('商品编辑失败:',$e->getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -79,13 +77,27 @@ 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): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$find = StoreProduct::where('id', $params['product_id'])->find()->toArray();
|
||||
$storeBranchProduct = StoreBranchProduct::where('id', $params['id'])->find()->toArray();
|
||||
StoreBranchProduct::update(['stock' => $params['stock'], 'sales' => $params['sales'], 'total_price' => bcmul($params['stock'], $storeBranchProduct['purchase'], 2)], ['id' => $params['id']]);
|
||||
SqlChannelLog('StoreBranchProduct', $params['id'], $params['stock'], 0, Request()->url(), $admin_id);
|
||||
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']]);
|
||||
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']]);
|
||||
StoreProduct::where('id', $params['product_id'])->update(['stock' => $stock, 'total_price' => bcmul($stock, $find['purchase'], 2)],['id'=>$params['product_id']]);
|
||||
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
@ -122,34 +134,4 @@ class StoreBranchProductLogic extends BaseLogic
|
||||
{
|
||||
return StoreBranchProduct::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
public static function decStock($storeId, $productId, $num)
|
||||
{
|
||||
$branchProduct = StoreBranchProduct::where('store_id', $storeId)->where('product_id', $productId)->find();
|
||||
if ($branchProduct) {
|
||||
$stock = bcsub($branchProduct['stock'], $num, 2);
|
||||
StoreBranchProduct::update([
|
||||
'stock' => $stock,
|
||||
'total_price' => bcmul($stock, $branchProduct['purchase'], 2),
|
||||
'sales' => bcadd($branchProduct['sales'], $num, 2)
|
||||
], ['id' => $branchProduct['id']]);
|
||||
SqlChannelLog('StoreBranchProduct',$branchProduct['id'], $num, -1, Request()->url());
|
||||
} else {
|
||||
$storeProduct = StoreProduct::where('id', $productId)->find();
|
||||
$branchProduct = StoreProductLogic::ordinary(['id' => $productId], $storeId, 0, $storeProduct);
|
||||
StoreBranchProduct::update([
|
||||
'stock' => -$num,
|
||||
'sales' => $num
|
||||
], ['product_id' => $productId,'store_id'=>$storeId]);
|
||||
SqlChannelLog('StoreBranchProduct',$branchProduct['id'], $num, -1, Request()->url());
|
||||
}
|
||||
ProductSourceLinkLogic::add([
|
||||
'purchase_product_offer' => [$params],
|
||||
'types' => ProductSourceLinkInfo::TypeIn,
|
||||
'buyer_id' => $params['buyer_id'],
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'link_id' => $res['id'],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,17 +29,12 @@ class StoreCategoryLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$priceRate = [];
|
||||
foreach ($params['price_rate'] as $v) {
|
||||
$priceRate[$v['id']] = $v;
|
||||
}
|
||||
StoreCategory::create([
|
||||
'pid' => $params['pid'],
|
||||
'name' => $params['name'],
|
||||
'data' => $params['data'],
|
||||
'pic' => $params['pic'],
|
||||
'sort' => $params['sort'],
|
||||
'price_rate' => array_values($priceRate)
|
||||
'sort' => $params['sort']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
@ -62,17 +57,13 @@ class StoreCategoryLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$priceRate = [];
|
||||
foreach ($params['price_rate'] as $v) {
|
||||
$priceRate[$v['id']] = $v;
|
||||
}
|
||||
StoreCategory::where('id', $params['id'])->update([
|
||||
'pid' => $params['pid'],
|
||||
'name' => $params['name'],
|
||||
'data' => $params['data'],
|
||||
'pic' => $params['pic'],
|
||||
'sort' => $params['sort'],
|
||||
'price_rate' => array_values($priceRate)
|
||||
'price_rate' => $params['price_rate']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
@ -108,11 +99,4 @@ class StoreCategoryLogic extends BaseLogic
|
||||
{
|
||||
return StoreCategory::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
public static function tree()
|
||||
{
|
||||
$data = StoreCategory::field('id,pid,name')->order('id desc')->select()->toArray();
|
||||
return list2tree($data);
|
||||
}
|
||||
|
||||
}
|
@ -3,14 +3,8 @@
|
||||
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;
|
||||
|
||||
@ -96,59 +90,4 @@ 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, '');
|
||||
}
|
||||
}
|
@ -35,13 +35,13 @@ class StoreOrderCartInfoLogic extends BaseLogic
|
||||
if($cart_info['is_pay']==1){
|
||||
throw new BusinessException('已支付订单无法追加');
|
||||
}
|
||||
// $value=DictData::where('type_value','vendors_store')->column('value');
|
||||
// if(!$value){
|
||||
// throw new BusinessException('请先配置店铺');
|
||||
// }
|
||||
// if(!in_array($cart_info['store_id'],$value)){
|
||||
// throw new BusinessException('该订单不属于可设置店铺');
|
||||
// }
|
||||
$value=DictData::where('type_value','vendors_store')->column('value');
|
||||
if(!$value){
|
||||
throw new BusinessException('请先配置店铺');
|
||||
}
|
||||
if(!in_array($cart_info['store_id'],$value)){
|
||||
throw new BusinessException('该订单不属于可设置店铺');
|
||||
}
|
||||
foreach($params['product_arr'] as $k=>$v){
|
||||
$find=StoreProduct::where('id',$v['product_id'])->find();
|
||||
|
||||
@ -86,6 +86,7 @@ class StoreOrderCartInfoLogic extends BaseLogic
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
d($e);
|
||||
throw new BusinessException('编辑商品失败' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,22 @@
|
||||
|
||||
namespace app\admin\logic\store_product;
|
||||
|
||||
use app\admin\logic\ActivityZoneLogic;
|
||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
|
||||
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 app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
use Webman\RedisQueue\Redis;
|
||||
@ -31,10 +34,11 @@ class StoreProductLogic extends BaseLogic
|
||||
/**
|
||||
* @notes 添加商品列表
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/05/31 10:53
|
||||
*/
|
||||
public static function add(array $params)
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
$count = count($params['cate_arr']);
|
||||
$top_cate_id = 0;
|
||||
@ -62,7 +66,6 @@ class StoreProductLogic extends BaseLogic
|
||||
'vip_price' => $params['vip_price'],
|
||||
'cost' => $params['cost'],
|
||||
'purchase' => $params['purchase'],
|
||||
'package' => $params['package']??'',
|
||||
'is_return' => $params['is_return'],
|
||||
'manufacturer_information' => $params['manufacturer_information'] ?? '',
|
||||
'swap' => $params['swap'] ?? 0,
|
||||
@ -70,7 +73,6 @@ class StoreProductLogic extends BaseLogic
|
||||
'store_batch' => $params['store_batch'] ?? 1,
|
||||
'product_type' => $params['product_type'] ?? 0,
|
||||
'is_show' => $params['is_show'] ?? 0,
|
||||
'made_place' => $params['made_place'] ?? '',
|
||||
];
|
||||
$rose = 0;
|
||||
//零售-供货
|
||||
@ -82,8 +84,6 @@ class StoreProductLogic extends BaseLogic
|
||||
}
|
||||
$data['rose']=$rose;
|
||||
$res = StoreProduct::create($data);
|
||||
// 添加商品到活动专区
|
||||
(new ActivityZoneLogic())->addProduct($res);
|
||||
StoreProductAttrValue::create([
|
||||
"bar_code" => $params["bar_code"] ?? '',
|
||||
"image" => $params["image"] ?? '',
|
||||
@ -120,7 +120,7 @@ class StoreProductLogic extends BaseLogic
|
||||
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => getenv('STORE_ID'), 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
||||
}
|
||||
|
||||
return $res;
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException('添加商品失败' . $e->getMessage());
|
||||
@ -222,7 +222,6 @@ class StoreProductLogic extends BaseLogic
|
||||
'manufacturer_information' => $params['manufacturer_information'] ?? '',
|
||||
'swap' => $params['swap'] ?? 0,
|
||||
'is_show' => $params['is_show'] ?? 0,
|
||||
'made_place' => $params['made_place'] ?? '',
|
||||
];
|
||||
$rose = 0;
|
||||
//零售-供货
|
||||
@ -233,19 +232,8 @@ class StoreProductLogic extends BaseLogic
|
||||
$rose=bcmul($price_div, 100, 2);
|
||||
}
|
||||
$data['rose']=$rose;
|
||||
$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);
|
||||
StoreProduct::update($data, ['id' => $params['id']]);
|
||||
|
||||
// $dealCate = self::dealChangeCate($params['cate_id']);
|
||||
//修改
|
||||
StoreBranchProduct::where('product_id', $params['id'])->whereNotIn('store_id', [17, 18])->update([
|
||||
@ -260,6 +248,7 @@ class StoreProductLogic extends BaseLogic
|
||||
'cate_id' => $params['cate_id'],
|
||||
'top_cate_id' => $top_cate_id,
|
||||
'two_cate_id' => $two_cate_id,
|
||||
'cate_id' => $params['cate_id'],
|
||||
'bar_code' => $params['bar_code'],
|
||||
'purchase' => $params['purchase'],
|
||||
'rose' => $rose,
|
||||
@ -273,7 +262,6 @@ class StoreProductLogic extends BaseLogic
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
d($e);
|
||||
throw new BusinessException('编辑商品失败' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
@ -289,23 +277,10 @@ class StoreProductLogic extends BaseLogic
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
$res = StoreProduct::destroy($params['id']);
|
||||
// 删除活动专区商品
|
||||
(new ActivityZoneLogic())->deleteProduct($params['id']);
|
||||
StoreBranchProduct::where('product_id', $params['id'])->update(['delete_time' => time()]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function restore(array $params): bool
|
||||
{
|
||||
$data = StoreProduct::where('id', $params['id'])->onlyTrashed()->find();
|
||||
if (empty($data)) {
|
||||
throw new BusinessException('数据不存在');
|
||||
}
|
||||
$res = $data->restore();
|
||||
StoreBranchProduct::where('product_id', $params['id'])->withTrashed()->update(['delete_time' => null]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品详情
|
||||
@ -337,7 +312,7 @@ class StoreProductLogic extends BaseLogic
|
||||
if ($userShip == 4) {
|
||||
$data['price'] = $data['cost'];
|
||||
} else {
|
||||
$data = StoreProductGroupPrice::resetStoreProductPrice($data, $userShip, $params['store_id'] ?? 0);
|
||||
$data = StoreProductGroupPrice::resetProductPrice($data, $userShip);
|
||||
}
|
||||
}
|
||||
if($data['is_show']==1){
|
||||
@ -462,32 +437,4 @@ class StoreProductLogic extends BaseLogic
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制商品到仓库
|
||||
* @param $params
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function copyWarehouse($params)
|
||||
{
|
||||
$exist = WarehouseProductStorege::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id']])->find();
|
||||
if ($exist) {
|
||||
throw new BusinessException('该商品已存在该仓库');
|
||||
}
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
|
||||
if (!$storeProduct) {
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'nums' => 0,
|
||||
'total_price' => 0
|
||||
];
|
||||
WarehouseProductStorege::create($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -105,7 +105,9 @@ class StoreProductGroupPriceLogic extends BaseLogic
|
||||
{
|
||||
$arr=StoreProductGroupPrice::where('product_id',$params['product_id'])->select()->toArray();
|
||||
$purchase=StoreProduct::where('id',$params['product_id'])->value('purchase');
|
||||
$arr_two=UserShip::where('id','>',0)->select()->toArray();
|
||||
$arr_two=UserShip::where('id','>',4)->select()->toArray();
|
||||
$arr_two[] = ['id' => 100001, 'title' => '供货价'];
|
||||
$arr_two[] = ['id' => 100002, 'title' => '零售价'];
|
||||
foreach ($arr_two as $k=>$v){
|
||||
$arr_two[$k]['purchase']=$purchase;
|
||||
$arr_two[$k]['product_id']=$params['product_id'];
|
||||
|
@ -1,97 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\store_product_low_stock;
|
||||
|
||||
|
||||
use app\common\model\store_product_low_stock\StoreProductLowStock;
|
||||
use app\common\logic\BaseLogic;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 商品缺库存逻辑
|
||||
* Class StoreProductLowStockLogic
|
||||
* @package app\admin\logic\store_product_low_stock
|
||||
*/
|
||||
class StoreProductLowStockLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加商品缺库存
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/01/07 16:39
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
StoreProductLowStock::create([
|
||||
'product_id' => $params['product_id'],
|
||||
'store_id' => $params['store_id'],
|
||||
'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/01/07 16:39
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
StoreProductLowStock::where('id', $params['id'])->update([
|
||||
'product_id' => $params['product_id'],
|
||||
'store_id' => $params['store_id'],
|
||||
'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/01/07 16:39
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return StoreProductLowStock::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取商品缺库存详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2025/01/07 16:39
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return StoreProductLowStock::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
@ -3,16 +3,11 @@
|
||||
namespace app\admin\logic\store_product_price;
|
||||
|
||||
|
||||
use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic;
|
||||
use app\admin\service\ProductPriceService;
|
||||
use app\common\model\store_product_group_price\StoreProductGroupPrice;
|
||||
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 app\common\model\warehouse\Warehouse;
|
||||
use app\common\service\xlsx\StoreProductPriceXlsx;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
@ -37,46 +32,7 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$model = StoreProductPrice::create($params);
|
||||
|
||||
$storeProductPriceList = StoreProductPriceList::where('product_id', $model['product_id'])->find();
|
||||
$attrs = [
|
||||
'supply_rate' => $params['purchase_lv'] * 100,
|
||||
'merchant_rate' => $params['cost_lv'] * 100,
|
||||
'vip_rate' => $params['vip_lv'] * 100,
|
||||
'price_rate' => $params['price_lv'] * 100,
|
||||
];
|
||||
if (empty($storeProductPriceList)) {
|
||||
$attrs['product_id'] = $model['product_id'];
|
||||
StoreProductPriceList::create($attrs);
|
||||
} else {
|
||||
StoreProductPriceList::where('product_id', $model['product_id'])->update($attrs);
|
||||
}
|
||||
|
||||
$productPrice = StoreProduct::where('id', $model['product_id'])->value('vip_price');
|
||||
if ($productPrice != $model['vip_price']) {
|
||||
SqlChannelPriceLog($model['product_id'], 43, $productPrice, $model['vip_price']);
|
||||
}
|
||||
|
||||
StoreProduct::where('id', $model['product_id'])->update([
|
||||
'purchase' => $model['purchase'],
|
||||
'cost' => $model['cost'],
|
||||
'vip_price' => $model['vip_price'],
|
||||
'price' => $model['price'],
|
||||
'ot_price' => $model['price'],
|
||||
'price_update_time' => time(),
|
||||
]);
|
||||
StoreBranchProduct::where('product_id', $model['product_id'])->update([
|
||||
'purchase' => $model['purchase'],
|
||||
'cost' => $model['cost'],
|
||||
'vip_price' => $model['vip_price'],
|
||||
'price' => $model['price'],
|
||||
'ot_price' => $model['price']
|
||||
]);
|
||||
|
||||
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
||||
$productSourceLinkInfoLogic->storeProductPrice = $model;
|
||||
$productSourceLinkInfoLogic->updateSupplyPrice();
|
||||
StoreProductPrice::create([]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
@ -100,64 +56,26 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
try {
|
||||
$find = StoreProductPrice::where('id', $params['id'])->find();
|
||||
if ($find) {
|
||||
$productPriceListAttrs = [];
|
||||
if ($find['purchase_lv'] != $params['purchase_lv']) {
|
||||
$productPriceListAttrs['supply_rate'] = $params['purchase_lv'] * 100;
|
||||
}
|
||||
if ($find['cost_lv'] != $params['cost_lv']) {
|
||||
$productPriceListAttrs['merchant_rate'] = $params['cost_lv'] * 100;
|
||||
}
|
||||
if ($find['vip_lv'] != $params['vip_lv']) {
|
||||
$productPriceListAttrs['vip_rate'] = $params['vip_lv'] * 100;
|
||||
}
|
||||
if ($find['price_lv'] != $params['price_lv']) {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
$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'],
|
||||
]);
|
||||
$productPrice = StoreProduct::where('id', $find['product_id'])->value('vip_price');
|
||||
if ($productPrice != $find['vip_price']) {
|
||||
SqlChannelPriceLog($find['product_id'], 43, $productPrice, $find['vip_price']);
|
||||
}
|
||||
StoreProduct::where('id', $find['product_id'])->update([
|
||||
'purchase' => $find['purchase'],
|
||||
'cost' => $find['cost'],
|
||||
'vip_price' => $find['vip_price'],
|
||||
'price' => $find['price'],
|
||||
'ot_price' => $find['price'],
|
||||
'price_update_time' => time(),
|
||||
'vip_price' => $find['cost'],
|
||||
'price' => $find['price']
|
||||
]);
|
||||
StoreBranchProduct::where('product_id', $find['product_id'])->update([
|
||||
'purchase' => $find['purchase'],
|
||||
'cost' => $find['cost'],
|
||||
'vip_price' => $find['vip_price'],
|
||||
'price' => $find['price'],
|
||||
'ot_price' => $find['price']
|
||||
'vip_price' => $find['cost'],
|
||||
'price' => $find['price']
|
||||
]);
|
||||
|
||||
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
||||
$productSourceLinkInfoLogic->storeProductPrice = $find;
|
||||
$productSourceLinkInfoLogic->updateSupplyPrice();
|
||||
self::setProductGroupPrice($find);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
@ -166,36 +84,6 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateProductPriceList2($productId, $field, $rate)
|
||||
{
|
||||
$id = StoreProductPriceList::where('product_id', $productId)->value('id');
|
||||
if (empty($id)) {
|
||||
StoreProductPriceList::create([
|
||||
'product_id' => $productId,
|
||||
$field => $rate * 100,
|
||||
]);
|
||||
} else {
|
||||
StoreProductPriceList::where('id', $id)->update([$field => $rate * 100]);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
@ -209,33 +97,22 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
try {
|
||||
$find = StoreProductPrice::where('id', $params['id'])->find();
|
||||
if ($find) {
|
||||
$productService = new ProductPriceService();
|
||||
$productPriceRate = StoreProductPriceList::whereIn('product_id', $find['product_id'])->findOrEmpty()->toArray();
|
||||
$update = ['status' => 1];
|
||||
if (!empty($productPriceRate)) {
|
||||
$update = $productService->setProductPrice($find['purchase_price'], $productPriceRate);
|
||||
$update['status'] = 1;
|
||||
}
|
||||
$find->save($update);
|
||||
$productPrice = StoreProduct::where('id', $find['product_id'])->value('vip_price');
|
||||
if ($productPrice != $find['vip_price']) {
|
||||
SqlChannelPriceLog($find['product_id'], 43, $productPrice, $find['vip_price']);
|
||||
}
|
||||
$find->save([
|
||||
'status' => 1
|
||||
]);
|
||||
StoreProduct::where('id', $find['product_id'])->update([
|
||||
'purchase' => $find['purchase'] ?? 0,
|
||||
'cost' => $find['cost'] ?? 0,
|
||||
'vip_price' => $find['vip_price'] ?? 0,
|
||||
'price' => $find['price'] ?? 0,
|
||||
'ot_price' => $find['price'] ?? 0,
|
||||
'price_update_time' => time(),
|
||||
'purchase' => $find['purchase'],
|
||||
'cost' => $find['cost'],
|
||||
'vip_price' => $find['cost'],
|
||||
'price' => $find['price']
|
||||
]);
|
||||
StoreBranchProduct::where('product_id', $find['product_id'])->update([
|
||||
'purchase' => $find['purchase'] ?? 0,
|
||||
'cost' => $find['cost'] ?? 0,
|
||||
'vip_price' => $find['vip_price'] ?? 0,
|
||||
'price' => $find['price'] ?? 0,
|
||||
'ot_price' => $find['price'] ?? 0,
|
||||
'purchase' => $find['purchase'],
|
||||
'cost' => $find['cost'],
|
||||
'vip_price' => $find['cost'],
|
||||
'price' => $find['price']
|
||||
]);
|
||||
self::setProductGroupPrice($find);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
@ -294,55 +171,4 @@ 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);
|
||||
}
|
||||
|
||||
public static function chart($params)
|
||||
{
|
||||
$list = StoreProductPrice::where('product_id', $params['product_id'])
|
||||
->field('id,purchase_price,purchase,create_time')
|
||||
->order('id desc')->limit(30)
|
||||
->select()->toArray();
|
||||
foreach ($list as &$item) {
|
||||
$item['date'] = date('m-d', strtotime($item['create_time']));
|
||||
if ($params['type'] == 1) {
|
||||
$item['price'] = $item['purchase_price'];
|
||||
} else {
|
||||
$item['price'] = $item['purchase'];
|
||||
}
|
||||
}
|
||||
asort($list);
|
||||
$data = [
|
||||
'name' => '价格趋势',
|
||||
'series' => [['name' => '价格', 'value' => array_column($list, 'price')]],
|
||||
'x' => array_column($list, 'date'),
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,10 +2,9 @@
|
||||
|
||||
namespace app\admin\logic\system_store_storage;
|
||||
|
||||
use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic;
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
|
||||
use app\common\model\system_store_storage\SystemStoreStorage;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
@ -60,35 +59,27 @@ class SystemStoreStorageLogic extends BaseLogic
|
||||
* @author admin
|
||||
* @date 2024/06/06 17:06
|
||||
*/
|
||||
public static function edit(array $params,$admin_id=0): bool
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$find= WarehouseProduct::where(['id' => $params['id']])->find();
|
||||
$find=SystemStoreStorage::where(['id' => $params['id']])->find();
|
||||
if($find){
|
||||
$find->save(['status'=>1,'staff_id'=>$params['staff_id']??0,'admin_id'=>$params['admin_id']??0,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]);
|
||||
$branch_product=StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->find();
|
||||
if($branch_product){
|
||||
$branch_product->stock=$branch_product['stock']+$find['nums'];
|
||||
$branch_product->save();
|
||||
SqlChannelLog('StoreBranchProduct', $branch_product['id'], $find['nums'], 1,Request()->url(),$admin_id);
|
||||
if($find['order_type']==1){
|
||||
$find->save(['status'=>1,'staff_id'=>$params['staff_id']??0,'admin_id'=>$params['admin_id']??0,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]);
|
||||
$branch_product=StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->find();
|
||||
if($branch_product){
|
||||
$branch_product->save(['stock'=>$branch_product['stock']+$find['nums']]);
|
||||
}else{
|
||||
$storeProduct = StoreProduct::where('id', $find['product_id'])->findOrEmpty();
|
||||
$storeBranchProduct = StoreProductLogic::ordinary(['id' => $find['product_id']], $find['store_id'], 0, $storeProduct);
|
||||
$storeBranchProduct->stock = $find['nums'];
|
||||
$storeBranchProduct->save();
|
||||
}
|
||||
}else{
|
||||
$storeProduct = StoreProduct::where('id', $find['product_id'])->withTrashed()->findOrEmpty();
|
||||
$storeBranchProduct = StoreProductLogic::ordinary(['id' => $find['product_id']], $find['store_id'], 0, $storeProduct);
|
||||
$storeBranchProduct->stock = $find['nums'];
|
||||
$storeBranchProduct->save();
|
||||
SqlChannelLog('StoreBranchProduct', $storeBranchProduct['id'], $find['nums'], 1,Request()->url(),$admin_id);
|
||||
$find->save(['status'=>1,'staff_id'=>$params['staff_id']??0,'admin_id'=>$params['admin_id']??0,'mark'=>'确认时间:'.date('Y-m-d H:i:s',time())]);
|
||||
}
|
||||
|
||||
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
||||
$productSourceLinkInfoLogic->setInfo([
|
||||
'link_id' => $find['id'],
|
||||
'product_id' => $find['product_id'],
|
||||
'warehouse_id' => $find['warehouse_id'],
|
||||
'store_id' => $find['store_id'],
|
||||
'types' => ProductSourceLinkInfo::TypeStoreIn,
|
||||
]);
|
||||
$productSourceLinkInfoLogic->storeInStorage();
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
@ -99,24 +90,6 @@ class SystemStoreStorageLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
public static function editAll(array $params, $adminId = 0): bool
|
||||
{
|
||||
$where = ['status' => 0];
|
||||
if (!empty($params['store_id'])) {
|
||||
$where['store_id'] = $params['store_id'];
|
||||
}
|
||||
if (!empty($params['product_name'])) {
|
||||
$productIds = StoreProduct::where('store_name', 'like', '%' . $params['product_name'] . '%')->column('id');
|
||||
$where[] = ['product_id', 'in', $productIds];
|
||||
}
|
||||
// $list = SystemStoreStorage::where($where)->column('id');
|
||||
$list = WarehouseProduct::where($where)->column('id');
|
||||
foreach ($list as $item) {
|
||||
$params['id'] = $item;
|
||||
self::edit($params, $adminId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除门店入库记录
|
||||
@ -163,7 +136,6 @@ class SystemStoreStorageLogic extends BaseLogic
|
||||
$storage->status = 1;
|
||||
$storage->staff_id = $params['staff_id'];
|
||||
$storage->save();
|
||||
SqlChannelLog('StoreBranchProduct', $storage['id'], $storage['nums'], 1,Request()->url());
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -172,52 +144,4 @@ 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('WarehouseProductStorege', $warehouseStorage['id'], $params['num'], 1,Request()->url());
|
||||
SqlChannelLog('StoreBranchProduct', $StoreProduct['id'], $params['num'], -1,Request()->url());
|
||||
|
||||
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
||||
$productSourceLinkInfoLogic->setInfo([
|
||||
'link_id' => $warehouseProduct['id'],
|
||||
'product_id' => $warehouseProduct['product_id'],
|
||||
'nums' => $params['num'],
|
||||
'types' => ProductSourceLinkInfo::TypeStoreOut,
|
||||
]);
|
||||
$productSourceLinkInfoLogic->storeRollback();
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -243,10 +243,12 @@ class UserLogic extends BaseLogic
|
||||
$capitalFlowDao = new CapitalFlowLogic($find, 'user');
|
||||
if ($params['type'] == 1) {
|
||||
$capitalFlowDao->userIncome('system_purchase_add', 'system', 0, $params['purchase_funds'],$params['mark']??'',1);
|
||||
User::where(['id' => $params['id']])->update(['purchase_funds' => bcadd($params['purchase_funds'], $find['purchase_funds'], 2)]);
|
||||
$find->purchase_funds = bcadd($params['purchase_funds'], $find['purchase_funds'], 2);
|
||||
$find->save();
|
||||
} else {
|
||||
$capitalFlowDao->userExpense('system_purchase_dec', 'system', 0, $params['purchase_funds'],$params['mark']??'');
|
||||
User::where(['id' => $params['id']])->update(['purchase_funds' =>bcsub($find['purchase_funds'],$params['purchase_funds'], 2)]);
|
||||
$find->purchase_funds = bcsub($find['purchase_funds'],$params['purchase_funds'], 2);
|
||||
$find->save();
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
@ -266,10 +268,12 @@ class UserLogic extends BaseLogic
|
||||
$capitalFlowDao = new CapitalFlowLogic($find, 'user');
|
||||
if ($params['type'] == 1) {
|
||||
$capitalFlowDao->userIncome('system_balance_add', 'system', 0, $params['now_money'],$params['mark']??'');
|
||||
User::where(['id' => $params['id']])->update(['now_money' => bcadd($params['now_money'], $find['now_money'], 2)]);
|
||||
$find->now_money = bcadd($params['now_money'], $find['now_money'], 2);
|
||||
$find->save();
|
||||
} else {
|
||||
$capitalFlowDao->userExpense('system_balance_reduce', 'system', 0, $params['now_money'],$params['mark']??'');
|
||||
User::where(['id' => $params['id']])->update(['now_money' =>bcsub($find['now_money'],$params['now_money'], 2)]);
|
||||
$find->now_money = bcsub($find['now_money'],$params['now_money'], 2);
|
||||
$find->save();
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
|
@ -20,7 +20,6 @@ class WarehouseOrderLogic extends BaseLogic
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated 已禁止直接创建入库单
|
||||
* @notes 添加仓储商品单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
@ -68,7 +67,7 @@ class WarehouseOrderLogic extends BaseLogic
|
||||
if (!empty($v['expiration_date'])) {
|
||||
$data['expiration_date'] = $v['expiration_date'];
|
||||
}
|
||||
WarehouseProductLogic::add($data,1,$params['admin_id']);
|
||||
WarehouseProductLogic::add($data);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
@ -93,11 +92,9 @@ class WarehouseOrderLogic extends BaseLogic
|
||||
throw new BusinessException('订单不存在');
|
||||
}
|
||||
$order_type=BeforehandOrder::where('warehousing_id|outbound_id',$find['id'])->value('order_type')??0;
|
||||
$buyerId = BeforehandOrder::where('warehousing_id|outbound_id',$find['id'])->value('buyer_id') ?? 0;
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$data['buyer_id'] = $buyerId;
|
||||
$data['order_type'] = $order_type;
|
||||
$data['supplier_id'] = $v['supplier_id']??0;
|
||||
$data['pay_type'] = $v['pay_type']??0;
|
||||
@ -109,8 +106,6 @@ class WarehouseOrderLogic extends BaseLogic
|
||||
$data['product_id'] = $v['id'];
|
||||
$data['nums'] = $v['nums'];
|
||||
$data['purchase'] = $v['purchase'];
|
||||
$data['buyer_nums'] = $v['nums'];
|
||||
$data['price'] = $v['purchase'];
|
||||
$data['total_price'] = $v['total_price'];
|
||||
$data['financial_pm'] = $find['financial_pm'];
|
||||
if (!empty($v['manufacture'])) {
|
||||
@ -123,11 +118,7 @@ class WarehouseOrderLogic extends BaseLogic
|
||||
$data['purchase'] = $v['prices'];
|
||||
$data['total_price'] = bcmul($v['prices'], $v['nums'], 2);
|
||||
}
|
||||
if ($data['financial_pm'] == 1) {
|
||||
WarehouseProductLogic::add($data,1,$params['admin_id']);
|
||||
} else {
|
||||
WarehouseProductLogic::setOutbound($data,1,$params['admin_id']);
|
||||
}
|
||||
WarehouseProductLogic::add($data);
|
||||
}
|
||||
$find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
@ -177,9 +168,6 @@ 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;
|
||||
|
@ -2,20 +2,17 @@
|
||||
|
||||
namespace app\admin\logic\warehouse_product;
|
||||
|
||||
use app\admin\logic\delivery_service\DeliveryServiceLogic;
|
||||
use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use app\common\model\PurchaseFunds;
|
||||
use app\admin\logic\store_branch_product\StoreBranchProductLogic;
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\system_store_storage\SystemStoreStorage;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use support\Log;
|
||||
use think\facade\Db;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
@ -32,15 +29,17 @@ class WarehouseProductLogic extends BaseLogic
|
||||
/**
|
||||
* @notes 添加商品仓储信息
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function add(array $params, $type = 1,$admin_id=0)
|
||||
public static function add(array $params, $type = 1)
|
||||
{
|
||||
// Db::startTrans();
|
||||
try {
|
||||
$before_nums = 0;
|
||||
$after_nums = 0;
|
||||
if (!in_array($params['order_type'],[6,9])) {
|
||||
if ($params['order_type'] != 6) {
|
||||
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storege) {
|
||||
$after_nums = $storege['nums'] + $params['nums'];
|
||||
@ -49,24 +48,23 @@ class WarehouseProductLogic extends BaseLogic
|
||||
if (!$storeProduct) {
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
if ($storeProduct['purchase'] <= 0) {
|
||||
$total_price = 0;
|
||||
} else {
|
||||
if($storeProduct['purchase']<=0){
|
||||
$total_price=0;
|
||||
}else{
|
||||
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
||||
}
|
||||
WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price], ['id' => $storege['id']]);
|
||||
SqlChannelLog('WarehouseProductStorege', $storege['id'], $params['nums'], 1, Request()->url(),$admin_id);
|
||||
|
||||
}
|
||||
$before_nums = $storege['nums'];
|
||||
} else {
|
||||
$after_nums = $params['nums'];
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
|
||||
if (!$storeProduct) {
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
if ($storeProduct['purchase'] <= 0) {
|
||||
$total_price = 0;
|
||||
} else {
|
||||
if($storeProduct['purchase']<=0){
|
||||
$total_price=0;
|
||||
}else{
|
||||
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
||||
}
|
||||
$data = [
|
||||
@ -79,8 +77,6 @@ class WarehouseProductLogic extends BaseLogic
|
||||
$data['nums'] = -$params['nums'];
|
||||
}
|
||||
$storege = WarehouseProductStorege::create($data);
|
||||
SqlChannelLog('WarehouseProductStorege', $storege['id'], -$params['nums'], 1, Request()->url(),$admin_id);
|
||||
|
||||
}
|
||||
}
|
||||
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count();
|
||||
@ -93,9 +89,9 @@ class WarehouseProductLogic extends BaseLogic
|
||||
'financial_pm' => $params['financial_pm'],
|
||||
'batch' => $batch_count + 1,
|
||||
'nums' => $params['nums'],
|
||||
'before_nums' => 0,
|
||||
'after_nums' => 0,
|
||||
'price' => $params['price'] ?? '',
|
||||
'before_nums' => $before_nums,
|
||||
'after_nums' => $after_nums,
|
||||
// 'price' => $params['price'] ?? '',
|
||||
'purchase' => $params['purchase'] ?? '',
|
||||
// 'cost' => $params['cost'] ?? '',
|
||||
'total_price' => $params['total_price'] ?? '',
|
||||
@ -112,23 +108,6 @@ class WarehouseProductLogic extends BaseLogic
|
||||
$data['expiration_date'] = strtotime($params['expiration_date']);
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
||||
$productSourceLinkInfoLogic->purchaseProductOffer = $params;
|
||||
$productSourceLinkInfoLogic->setInfo([
|
||||
'types' => ProductSourceLinkInfo::TypeIn,
|
||||
'buyer_id' => $params['buyer_id'],
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'link_id' => $res['id'],
|
||||
]);
|
||||
$productSourceLinkInfoLogic->putInStorage();
|
||||
|
||||
DeliveryServiceLogic::subPurchaseFunds($params['buyer_id'], $params['total_price']);
|
||||
return $res;
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
@ -138,7 +117,7 @@ class WarehouseProductLogic extends BaseLogic
|
||||
/**
|
||||
* 设置出库商品
|
||||
*/
|
||||
public static function setOutbound(array $params, $type = 1,$admin_id=0)
|
||||
public static function setOutbound(array $params, $type = 1)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
@ -146,10 +125,21 @@ 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['order_type']!=7){
|
||||
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'],
|
||||
'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']]);
|
||||
SqlChannelLog('WarehouseProductStorege', $storege['id'], $params['nums'], -1, Request()->url(),$admin_id);
|
||||
} else {
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
@ -158,7 +148,6 @@ class WarehouseProductLogic extends BaseLogic
|
||||
'total_price' => 0
|
||||
];
|
||||
$storege = WarehouseProductStorege::create($data);
|
||||
SqlChannelLog('WarehouseProductStorege', $storege->id, $params['nums'], -1, Request()->url(),$admin_id);
|
||||
}
|
||||
} else {
|
||||
$storege['nums'] = 0;
|
||||
@ -178,28 +167,14 @@ class WarehouseProductLogic extends BaseLogic
|
||||
'after_nums' => $after_nums,
|
||||
'price' => $params['price'] ?? 0,
|
||||
'purchase' => $params['purchase'] ?? 0,
|
||||
'vip_price' => $params['vip_price'] ?? 0,
|
||||
'cost' => $params['cost'] ?? 0,
|
||||
'total_price' => $params['total_price'] ?? 0,
|
||||
'admin_id' => $params['admin_id'],
|
||||
'code' => $params['code'] ?? '',
|
||||
'unit' => $params['unit'] ?? 0,
|
||||
'status' => 0,
|
||||
'status' => 1,
|
||||
'mark' => $params['mark'] ?? '',
|
||||
'order_type' => $params['order_type'] ?? '',
|
||||
];
|
||||
$res = WarehouseProduct::create($data);
|
||||
SqlChannelLog('WarehouseProduct', $res->id, $params['nums'], $params['financial_pm'] == 1 ? 1 : -1, Request()->url(),$admin_id);
|
||||
|
||||
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
||||
$productSourceLinkInfoLogic->warehouseProduct = $data;
|
||||
$productSourceLinkInfoLogic->setInfo([
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'store_id' => $data['store_id'],
|
||||
'link_id' => $res['id'],
|
||||
]);
|
||||
$productSourceLinkInfoLogic->outbound();
|
||||
|
||||
Db::commit();
|
||||
return $res;
|
||||
} catch (\Throwable $e) {
|
||||
@ -215,42 +190,63 @@ class WarehouseProductLogic extends BaseLogic
|
||||
* @author admin
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function edit(array $params,$admin_id=0)
|
||||
public static function edit(array $params)
|
||||
{
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$before_nums = 0;
|
||||
$after_nums = 0;
|
||||
$find = WarehouseOrder::where('id', $params['oid'])->find();
|
||||
if ($find) {
|
||||
$res = WarehouseProduct::where('id', $params['id'])->withTrashed()->find();
|
||||
$updateNums = bcsub($params['nums'], $res['nums'],2);
|
||||
if ($updateNums != 0) {
|
||||
if ($res['status'] == 1 && $res['store_id'] > 0) {
|
||||
throw new BusinessException('门店已确认入库,不能修改数量');
|
||||
}
|
||||
$storageNum = $res['financial_pm'] == 0 ? -$updateNums : $updateNums;
|
||||
$productNum = $updateNums;
|
||||
self::updateWarehouseProduct($res, $storageNum, $productNum);
|
||||
$res = WarehouseProduct::where('id', $params['id'])->find();
|
||||
|
||||
self::updateProductSourceLink($res, $params, $updateNums);
|
||||
}
|
||||
$datas = [
|
||||
'total_price' => $params['total_price'],
|
||||
];
|
||||
if ($find['financial_pm'] == 1) {
|
||||
$datas['supplier_id'] = $params['supplier_id'];
|
||||
$datas['pay_type'] = $params['pay_type'];
|
||||
$datas['purchase'] = $params['purchase'];
|
||||
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $res['nums'])->update();
|
||||
StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->dec('stock', $res['nums'])->update();
|
||||
|
||||
$warehouseProductStorege = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->find();
|
||||
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $params['nums'])->update();
|
||||
StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->inc('stock', $params['nums'])->update();
|
||||
$before_nums = $warehouseProductStorege['nums'];
|
||||
$after_nums = $warehouseProductStorege['nums'] + $params['nums'];
|
||||
} else {
|
||||
$datas['price'] = $params['price'];
|
||||
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update();
|
||||
StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->dec('stock', $res['nums'])->update();
|
||||
|
||||
$warehouseProductStorege = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->find();
|
||||
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $params['nums'])->update();
|
||||
StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->inc('stock', $params['nums'])->update();
|
||||
$before_nums = $warehouseProductStorege['nums'];
|
||||
$after_nums = bcsub($warehouseProductStorege['nums'], $params['nums'], 2);
|
||||
}
|
||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||
$datas['manufacture'] = strtotime($params['manufacture']);
|
||||
if($find['financial_pm']==1){
|
||||
$datas=[
|
||||
'nums' => $params['nums'],
|
||||
'supplier_id' => $params['supplier_id'],
|
||||
'pay_type' => $params['pay_type'],
|
||||
'purchase' => $params['purchase'],
|
||||
'before_nums' => $before_nums,
|
||||
'after_nums' => $after_nums,
|
||||
'total_price' => $params['total_price'],
|
||||
];
|
||||
}else{
|
||||
$datas=[
|
||||
'nums' => $params['nums'],
|
||||
'price' => $params['price'],
|
||||
'before_nums' => $before_nums,
|
||||
'after_nums' => $after_nums,
|
||||
'total_price' => $params['total_price'],
|
||||
];
|
||||
}
|
||||
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
||||
$datas['expiration_date'] = strtotime($params['expiration_date']);
|
||||
WarehouseProduct::where('id', $params['id'])->update($datas);
|
||||
$finds = WarehouseProduct::where('oid', $params['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($finds) {
|
||||
WarehouseOrder::where('id', $params['oid'])->update([
|
||||
'nums' => $finds['nums'],
|
||||
'total_price' => $finds['total_price']
|
||||
]);
|
||||
}
|
||||
$res->save($datas);
|
||||
self::updateWarehouseOrder($res['oid']);
|
||||
}
|
||||
Db::commit();
|
||||
return $res;
|
||||
@ -267,28 +263,29 @@ class WarehouseProductLogic extends BaseLogic
|
||||
* @author admin
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function delete(array $params,$admin_id=0): bool
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
$res = WarehouseProduct::where('id', $params['id'])->find();
|
||||
if ($res) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
$storageNum = $res['financial_pm'] == 1 ? -$res['nums'] : $res['nums'];
|
||||
$productNum = -$res['nums'];
|
||||
self::updateWarehouseProduct($res, $storageNum, $productNum);
|
||||
$res->delete();
|
||||
self::updateWarehouseOrder($res['oid']);
|
||||
$types = $res['financial_pm'] == 1 ? ProductSourceLinkInfo::TypeIn : ProductSourceLinkInfo::TypeOut;
|
||||
|
||||
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
||||
$productSourceLinkInfoLogic->deleteByLinkId($res['id'], $types);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($th->getMessage());
|
||||
$res->delete();
|
||||
if ($res['financial_pm'] == 1) {
|
||||
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $res['nums'])->update();
|
||||
} elseif ($res['financial_pm'] == 0) {
|
||||
$stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock');
|
||||
if ($stock < $res['nums']) {
|
||||
throw new BusinessException('商品库存不足,无法退回');
|
||||
}
|
||||
StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update();
|
||||
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update();
|
||||
}
|
||||
$find = WarehouseProduct::where('oid', $res['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $res['oid'])->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
throw new BusinessException('没有查到出入库信息');
|
||||
}
|
||||
@ -320,34 +317,54 @@ class WarehouseProductLogic extends BaseLogic
|
||||
* @param $id
|
||||
* @return void
|
||||
*/
|
||||
public static function settNums($params,$admin_id=0)
|
||||
public static function settNums($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$warehouseProduct = WarehouseProduct::where('id', $params['id'])->find();
|
||||
if ($warehouseProduct) {
|
||||
$updateNums = bcsub($params['nums'], $warehouseProduct['nums'],2);
|
||||
if ($updateNums != 0) {
|
||||
$storageNum = $warehouseProduct['financial_pm'] == 0 ? -$updateNums : $updateNums;
|
||||
$productNum = $updateNums;
|
||||
self::updateWarehouseProduct($warehouseProduct, $storageNum, $productNum);
|
||||
$res = WarehouseProduct::where('id',$params['id'])->find();
|
||||
if ($res) {
|
||||
if ($res['financial_pm'] == 1) {
|
||||
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $res['nums'])->update();
|
||||
StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->dec('stock', $res['nums'])->update();
|
||||
|
||||
self::updateProductSourceLink($warehouseProduct, $params, $updateNums);
|
||||
$warehouseProductStorege = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->find();
|
||||
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $params['nums'])->update();
|
||||
StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->inc('stock', $params['nums'])->update();
|
||||
$before_nums = $warehouseProductStorege['nums'];
|
||||
$after_nums = $warehouseProductStorege['nums'] + $params['nums'];
|
||||
} else {
|
||||
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update();
|
||||
StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->dec('stock', $res['nums'])->update();
|
||||
|
||||
$warehouseProductStorege = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->find();
|
||||
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $params['nums'])->update();
|
||||
StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->inc('stock', $params['nums'])->update();
|
||||
$before_nums = $warehouseProductStorege['nums'];
|
||||
$after_nums = bcsub($warehouseProductStorege['nums'], $params['nums'], 2);
|
||||
}
|
||||
if($warehouseProduct['financial_pm']==1){
|
||||
$datas = [
|
||||
if($res['financial_pm']==1){
|
||||
$datas=[
|
||||
'nums' => $params['nums'],
|
||||
'total_price' => bcmul($params['nums'], $warehouseProduct['purchase'], 2),
|
||||
'before_nums' => $before_nums,
|
||||
'after_nums' => $after_nums,
|
||||
'total_price' => bcmul($params['nums'], $res['purchase'], 2),
|
||||
|
||||
];
|
||||
}else{
|
||||
$datas = [
|
||||
$datas=[
|
||||
'nums' => $params['nums'],
|
||||
'total_price' => bcmul($params['nums'], $warehouseProduct['price'], 2),
|
||||
'before_nums' => $before_nums,
|
||||
'after_nums' => $after_nums,
|
||||
'total_price' => bcmul($params['nums'], $res['price'], 2),
|
||||
];
|
||||
}
|
||||
|
||||
$warehouseProduct->save($datas);
|
||||
self::updateWarehouseOrder($warehouseProduct['oid']);
|
||||
WarehouseProduct::where('id', $params['id'])->update($datas);
|
||||
$finds = WarehouseProduct::where('oid', $res['oid'])->field('sum(nums) as nums')->find();
|
||||
if ($finds) {
|
||||
WarehouseOrder::where('id', $res['oid'])->update([
|
||||
'nums' => $finds['nums'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
@ -371,183 +388,4 @@ class WarehouseProductLogic extends BaseLogic
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
private static function decProductIncStorege($warehouseProduct,$nums,$admin_id=0)
|
||||
{
|
||||
$warehouseProductStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])
|
||||
->where('product_id', $warehouseProduct['product_id'])->find();
|
||||
$warehouseProductStorage->nums = bcadd($warehouseProductStorage->nums,$nums,2);
|
||||
$warehouseProductStorage->save();
|
||||
SqlChannelLog('WarehouseProductStorege', $warehouseProductStorage['id'], $nums, 1, Request()->url(),$admin_id);
|
||||
|
||||
$update = [
|
||||
'nums' => bcsub($warehouseProduct['nums'], $nums, 2),
|
||||
'total_price' => bcsub($warehouseProduct['total_price'], bcmul($nums, $warehouseProduct['price'], 2), 2),
|
||||
];
|
||||
WarehouseProduct::where('id',$warehouseProduct['id'])->update($update);
|
||||
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $nums, -1, Request()->url(),$admin_id);
|
||||
|
||||
$find = WarehouseProduct::where('oid', $warehouseProduct['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $warehouseProduct['oid'])->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
|
||||
self::updateStoreStorage($warehouseProduct['oid'], $nums, 'dec');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
//增加
|
||||
private static function incProductDecStorege($warehouseProduct, $nums,$admin_id=0)
|
||||
{
|
||||
$warehouseProductStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])
|
||||
->where('product_id', $warehouseProduct['product_id'])->find();
|
||||
$warehouseProductStorage->nums = bcsub($warehouseProductStorage->nums,$nums,2);
|
||||
$warehouseProductStorage->save();
|
||||
SqlChannelLog('WarehouseProductStorege', $warehouseProductStorage['id'], $nums, -1, Request()->url(),$admin_id);
|
||||
|
||||
$update = [
|
||||
'nums' => bcadd($warehouseProduct['nums'], $nums, 2),
|
||||
'total_price' => bcadd($warehouseProduct['total_price'], bcmul($nums, $warehouseProduct['price'], 2), 2),
|
||||
];
|
||||
WarehouseProduct::where('id',$warehouseProduct['id'])->update($update);
|
||||
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $nums, 1, Request()->url(),$admin_id);
|
||||
|
||||
$find = WarehouseProduct::where('oid', $warehouseProduct['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $warehouseProduct['oid'])->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
|
||||
self::updateStoreStorage($warehouseProduct['oid'], $nums);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 已废弃
|
||||
*/
|
||||
private static function updateStoreStorage($outboundId, $nums, $type = 'inc')
|
||||
{
|
||||
$storeStorage = SystemStoreStorage::where('outbound_id', $outboundId)->find();
|
||||
if (empty($storeStorage)) {
|
||||
return;
|
||||
}
|
||||
$storeStorage->nums = $type == 'inc' ? $storeStorage->nums + $nums : $storeStorage->nums - $nums;
|
||||
$storeStorage->save();
|
||||
if ($storeStorage->status == 0) {
|
||||
return;
|
||||
}
|
||||
// 门店入库单已确认,增加/减少 门店库存
|
||||
$storeBranchProduct = StoreBranchProduct::where('store_id', $storeStorage->store_id)
|
||||
->where('product_id', $storeStorage->product_id)->find();
|
||||
if (!empty($storeBranchProduct)) {
|
||||
$storeBranchProduct->stock = $type == 'inc' ? $storeBranchProduct->stock + $nums : $storeBranchProduct->stock - $nums;
|
||||
$storeBranchProduct->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加商品数量
|
||||
* @param $warehouseProduct
|
||||
* @param $storageNum
|
||||
* @param $productNum
|
||||
* @return void
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public static function updateWarehouseProduct($warehouseProduct, $storageNum, $productNum)
|
||||
{
|
||||
$warehouseProductStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])
|
||||
->where('product_id', $warehouseProduct['product_id'])->find();
|
||||
$warehouseProductStorage->nums = bcadd($warehouseProductStorage->nums, $storageNum, 2);
|
||||
$warehouseProductStorage->save();
|
||||
SqlChannelLog('WarehouseProductStorege', $warehouseProductStorage['id'], $storageNum, $storageNum > 0 ? 1 : -1, Request()->url());
|
||||
|
||||
$update = [
|
||||
'nums' => bcadd($warehouseProduct['nums'], $productNum, 2),
|
||||
'total_price' => bcadd($warehouseProduct['total_price'], bcmul($productNum, $warehouseProduct['price'], 2), 2),
|
||||
];
|
||||
WarehouseProduct::where('id',$warehouseProduct['id'])->update($update);
|
||||
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $productNum, $productNum > 0 ? 1 : -1, Request()->url());
|
||||
|
||||
self::updateStoreStorage2($warehouseProduct, $productNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单数量和总价
|
||||
* @param $oid
|
||||
* @return void
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public static function updateWarehouseOrder($oid)
|
||||
{
|
||||
$find = WarehouseProduct::where('oid', $oid)->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $oid)->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改门店商品库存
|
||||
* @param $warehouseProduct
|
||||
* @param $nums
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function updateStoreStorage2($warehouseProduct, $nums)
|
||||
{
|
||||
if ($warehouseProduct['financial_pm'] == 0 && $warehouseProduct['status'] == 1) {
|
||||
// 出库单已确认,增加门店库存
|
||||
$storeBranchProduct = StoreBranchProduct::where('store_id', $warehouseProduct->store_id)
|
||||
->where('product_id', $warehouseProduct->product_id)->find();
|
||||
if (!empty($storeBranchProduct)) {
|
||||
$storeBranchProduct->stock = $storeBranchProduct->stock + $nums;
|
||||
$storeBranchProduct->save();
|
||||
}
|
||||
} elseif ($warehouseProduct['store_id'] == 1 && $warehouseProduct['financial_pm'] == 1 && $warehouseProduct['status'] == 1) {
|
||||
// 入库单已确认,减少门店库存
|
||||
$storeBranchProduct = StoreBranchProduct::where('store_id', $warehouseProduct->store_id)
|
||||
->where('product_id', $warehouseProduct->product_id)->find();
|
||||
if (!empty($storeBranchProduct)) {
|
||||
$storeBranchProduct->stock = $storeBranchProduct->stock - $nums;
|
||||
$storeBranchProduct->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateProductSourceLink($warehouseProduct, $params, $updateNums)
|
||||
{
|
||||
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
||||
$productSourceLinkInfoLogic->setInfo([
|
||||
'link_id' => $warehouseProduct['id'],
|
||||
'product_id' => $warehouseProduct['product_id'],
|
||||
'nums' => $params['nums'],
|
||||
'add_nums' => $updateNums,
|
||||
]);
|
||||
if ($warehouseProduct['financial_pm'] == 1) {
|
||||
$productSourceLinkInfoLogic->updateInStorageNum();
|
||||
} else {
|
||||
$productSourceLinkInfoLogic->setInfo([
|
||||
'add_nums' => bcsub($params['nums'], $warehouseProduct['nums'],2),
|
||||
]);
|
||||
$productSourceLinkInfoLogic->updateOutboundNum();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,9 +3,6 @@
|
||||
namespace app\admin\logic\warehouse_product_return;
|
||||
|
||||
|
||||
use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic;
|
||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use app\common\model\warehouse_product_return\WarehouseProductReturn;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
@ -79,11 +76,15 @@ class WarehouseProductReturnLogic extends BaseLogic
|
||||
throw new BusinessException('该商品库存:'.$params['nums'].'小于仓库库存'.$proudct['nums']);
|
||||
}
|
||||
}
|
||||
$offer = PurchaseProductOffer::where('order_id', $params['bhoid'])->where('product_id', $find['product_id'])->find();
|
||||
if (!$offer) {
|
||||
throw new BusinessException('该商品没有采购信息');
|
||||
}
|
||||
$datas = [
|
||||
'source_id' => $params['id'],
|
||||
'bhoid' => $params['bhoid'] ?? 0,
|
||||
'warehouse_id' => $find['warehouse_id'],
|
||||
'supplier_id' => 0,
|
||||
'supplier_id' => $offer['supplier_id'],
|
||||
'store_id' => $find['store_id'],
|
||||
'product_id' => $find['product_id'],
|
||||
'unit' => $find['unit'],
|
||||
@ -92,19 +93,12 @@ class WarehouseProductReturnLogic extends BaseLogic
|
||||
'nums' => $params['nums'],
|
||||
'return_type' => $params['return_type'],
|
||||
'mark' => $params['mark'],
|
||||
'price' => 0,
|
||||
'total_price' => 0,
|
||||
'price' => $offer['price'],
|
||||
'total_price' => bcmul($params['nums'], $offer['price'], 2),
|
||||
];
|
||||
}
|
||||
|
||||
WarehouseProductReturn::create($datas);
|
||||
|
||||
$updateNums = bcsub($find['nums'], $params['nums'], 2);
|
||||
if ($params['nums'] != 0) {
|
||||
$numTemp = bcsub($find['nums'], $params['nums'], 2);
|
||||
WarehouseProductLogic::updateProductSourceLink($find, array_merge($params, ['nums' => $numTemp]), $updateNums);
|
||||
}
|
||||
|
||||
if ($params['financial_pm'] == 1 && $params['return_type'] == 1) {
|
||||
$nums = bcsub($find['nums'], $params['nums'], 2);
|
||||
$total_price = 0;
|
||||
@ -113,15 +107,16 @@ class WarehouseProductReturnLogic extends BaseLogic
|
||||
}
|
||||
$find->save(['nums' => $nums, 'total_price' => $total_price]);
|
||||
$total_price = WarehouseProduct::where('oid', $find['oid'])->sum('total_price');
|
||||
WarehouseOrder::where(['id' => $find['oid']])->update(['total_price' => $total_price]);
|
||||
BeforehandOrder::update(['pay_price' => $total_price, 'total_price' => $total_price], ['id' => $params['bhoid']]);
|
||||
$res=WarehouseProductStorege::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id']])->find();
|
||||
$res->save(['nums' =>bcadd( $res['nums'],$params['nums'],2)]);
|
||||
SqlChannelLog('WarehouseProductStorege', $res['id'], $params['nums'], 1, Request()->url(),$params['admin_id']);
|
||||
if ($nums > 0) {
|
||||
WarehouseOrder::where(['id' => $find['oid']])->update(['total_price' => $total_price]);
|
||||
BeforehandOrder::update(['pay_price' => $total_price], ['id' => $params['bhoid']]);
|
||||
} elseif ($nums == 0) {
|
||||
WarehouseOrder::where(['id' => $find['oid']])->update(['total_price' => $total_price]);
|
||||
BeforehandOrder::update(['pay_price' => $total_price], ['id' => $params['bhoid']]);
|
||||
}
|
||||
WarehouseProductStorege::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id']])->inc('nums', $params['nums'])->update();
|
||||
} elseif ($params['financial_pm'] == 0 && $params['return_type'] == 2) {
|
||||
$res=WarehouseProductStorege::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id']])->find();
|
||||
$res->save(['nums' =>bcsub( $res['nums'],$params['nums'],2)]);
|
||||
SqlChannelLog('WarehouseProductStorege', $res['id'], $params['nums'], -1, Request()->url(),$params['admin_id']);
|
||||
WarehouseProductStorege::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id']])->dec('nums', $params['nums'])->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ namespace app\admin\logic\warehouse_product_storege;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
|
||||
/**
|
||||
* 仓库商品存储逻辑
|
||||
@ -37,26 +37,9 @@ class WarehouseProductStoregeLogic extends BaseLogic
|
||||
* @author admin
|
||||
* @date 2024/08/01 10:22
|
||||
*/
|
||||
public static function edit(array $params,$admin_id=0): bool
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
if (empty($params['remark'])) {
|
||||
throw new BusinessException('请输入备注');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$find=WarehouseProductStorege::where('id',$params['id'])->find();
|
||||
if($find){
|
||||
$find->save(['nums'=>$params['nums']]);
|
||||
SqlChannelLog('WarehouseProductStorege', $params['id'], $params['nums'], 0,Request()->url(),$admin_id, $params['remark']);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($th->getMessage());
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\StoreProductPriceList;
|
||||
|
||||
class ProductPriceService
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置商品价格
|
||||
* @param $purchasePrice float 采购价
|
||||
* @param $productPriceRate array 价格比例
|
||||
* @return array
|
||||
*/
|
||||
public function setProductPrice(float $purchasePrice, array $productPriceRate)
|
||||
{
|
||||
$result = [];
|
||||
$result['purchase_lv'] = bcdiv($productPriceRate['supply_rate'], 100, 2);
|
||||
$result['purchase'] = bcmul($purchasePrice, $result['purchase_lv'], 2);
|
||||
$result['cost_lv'] = bcdiv($productPriceRate['merchant_rate'], 100, 2);
|
||||
$result['cost'] = bcmul($result['purchase'], $result['cost_lv'], 2);
|
||||
$result['vip_lv'] = bcdiv($productPriceRate['vip_rate'], 100, 2);
|
||||
$result['vip_price'] = bcmul($result['purchase'], $result['vip_lv'], 2);
|
||||
$result['price_lv'] = bcdiv($productPriceRate['price_rate'], 100, 2);
|
||||
$result['price'] = bcmul($result['purchase'], $result['price_lv'], 2);
|
||||
$lastNum = substr($result['price'], -1);
|
||||
if ($lastNum > 0) {
|
||||
$result['price'] = ceil($result['price'] * 10);
|
||||
$result['price'] = bcdiv($result['price'], 10, 2);
|
||||
}
|
||||
$lastNum = substr($result['vip_price'], -1);
|
||||
if ($lastNum > 0) {
|
||||
$result['vip_price'] = ceil($result['vip_price'] * 10);
|
||||
$result['vip_price'] = bcdiv($result['vip_price'], 10, 2);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $productId int 商品id
|
||||
* @param $percent bool 是否返回百分比
|
||||
* @return array|int[]
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getProductPriceRate($productId, $percent = false)
|
||||
{
|
||||
$list = StoreProductPriceList::where('product_id', $productId)->findOrEmpty()->toArray();
|
||||
$product = StoreProduct::where('id', $productId)->field('id,store_name,top_cate_id,cate_id')->find();
|
||||
if (empty($list)) {
|
||||
if ($product->isSpecial()) {
|
||||
$list = [
|
||||
'supply_rate' => 102,
|
||||
'merchant_rate' => 102,
|
||||
'vip_rate' => 104,
|
||||
'price_rate' => 108,
|
||||
];
|
||||
} else {
|
||||
$list = [
|
||||
'supply_rate' => 105,
|
||||
'merchant_rate' => 105,
|
||||
'vip_rate' => 108,
|
||||
'price_rate' => 112,
|
||||
];
|
||||
}
|
||||
}
|
||||
if ($percent) {
|
||||
$list['supply_rate'] = $list['supply_rate'] / 100;
|
||||
$list['merchant_rate'] = $list['merchant_rate'] / 100;
|
||||
$list['vip_rate'] = $list['vip_rate'] / 100;
|
||||
$list['price_rate'] = $list['price_rate'] / 100;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* ActivityZone验证器
|
||||
* Class ActivityZoneValidate
|
||||
* @package app\admin\validate
|
||||
*/
|
||||
class ActivityZoneFormValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'type' => 'require',
|
||||
'title' => 'require',
|
||||
'cate_ids' => 'require',
|
||||
'remark' => 'string',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'type' => '类型',
|
||||
'product_ids' => '商品',
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return ActivityZoneValidate
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['type', 'title', 'cate_ids']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return ActivityZoneValidate
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id', 'type', 'title', 'cate_ids']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return ActivityZoneValidate
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return ActivityZoneValidate
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* ActivityZone验证器
|
||||
* Class ActivityZoneValidate
|
||||
* @package app\admin\validate
|
||||
*/
|
||||
class ActivityZoneValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'form_id' => 'require',
|
||||
'product_ids' => 'require',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'form_id' => '表单',
|
||||
'product_ids' => '商品',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return ActivityZoneValidate
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['form_id', 'product_ids']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return ActivityZoneValidate
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id', 'form_id', 'product_ids']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return ActivityZoneValidate
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return ActivityZoneValidate
|
||||
* @author admin
|
||||
* @date 2024/12/20 10:52
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* ChangeLog验证器
|
||||
* Class ChangeLogValidate
|
||||
* @package app\admin\validate
|
||||
*/
|
||||
class ChangeLogValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return ChangeLogValidate
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id', true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return ChangeLogValidate
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return ChangeLogValidate
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return ChangeLogValidate
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ use app\common\enum\AdminTerminalEnum;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\validate\BaseValidate;
|
||||
use app\MyBusinessException;
|
||||
use support\exception\BusinessException;
|
||||
use Webman\Config;
|
||||
|
||||
|
@ -1,82 +0,0 @@
|
||||
<?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']);
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user