diff --git a/app/admin/controller/LocalController.php b/app/admin/controller/LocalController.php index 68b1353b3..ac80fab97 100644 --- a/app/admin/controller/LocalController.php +++ b/app/admin/controller/LocalController.php @@ -5,6 +5,8 @@ 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\service\ProductPriceService; use app\common\model\beforehand_order\BeforehandOrder; use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; use app\common\model\CeshiCopy; @@ -14,11 +16,13 @@ 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; @@ -27,10 +31,102 @@ use think\facade\Db; class LocalController extends BaseAdminController { - public $notNeedLogin = ['activityPrice', 'searchProduct', 'setPrice', 'index', 'updateProductPriceList', 'importOrder', 'warehousing', 'outbound']; + public $notNeedLogin = ['activityPrice', '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 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'); @@ -516,6 +612,7 @@ class LocalController extends BaseAdminController throw new BusinessException($e->getMessage()); } } + public function importStorege() { $file = $this->request->file('file'); @@ -533,7 +630,7 @@ class LocalController extends BaseAdminController 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(); + $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], @@ -558,7 +655,7 @@ class LocalController extends BaseAdminController $params['one_type'] = 1; //1门店2仓库 $params['two_id'] = 1; //1海吉星仓库 $params['two_type'] = 2; //1门店2仓库 - $params['types'] = 1; //0减库存 1不减库存 + $params['types'] = 0; //0减库存 1不减库存 InventoryTransferOrderLogic::add($params, $this->adminId); $new_params = json_encode($new_params, true); diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 744e0c9ba..e32cb2bcf 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -31,11 +31,10 @@ class StoreProductLogic extends BaseLogic /** * @notes 添加商品列表 * @param array $params - * @return bool * @author likeadmin * @date 2024/05/31 10:53 */ - public static function add(array $params): bool + public static function add(array $params) { $count = count($params['cate_arr']); $top_cate_id = 0; @@ -63,6 +62,7 @@ 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, @@ -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 true; + return $res; } catch (\Exception $e) { Db::rollback(); throw new BusinessException('添加商品失败' . $e->getMessage());