lihaiMiddleOffice/app/psi/controller/StoreProductPriceController.php

143 lines
3.8 KiB
PHP
Raw Permalink Normal View History

2025-04-03 16:25:57 +08:00
<?php
namespace app\psi\controller;
use app\admin\controller\BaseAdminController;
use app\psi\lists\StoreProductPriceLists;
use app\psi\logic\StoreProductPriceLogic;
use app\psi\validate\StoreProductPriceValidate;
/**
* StoreProductPrice控制器
* Class StoreProductPriceController
* @package app\psi\controller
*/
class StoreProductPriceController extends BaseAdminController
{
/**
* @notes 获取列表
* @author admin
* @date 2025/04/03 15:19
*/
public function lists()
{
return $this->dataLists(new StoreProductPriceLists());
}
/**
* @notes 添加
* @author admin
* @date 2025/04/03 15:19
*/
public function add()
{
$params = (new StoreProductPriceValidate())->post()->goCheck('add');
$result = StoreProductPriceLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(StoreProductPriceLogic::getError());
}
/**
* @notes 编辑
* @author admin
* @date 2025/04/03 15:19
*/
public function edit()
{
$params = (new StoreProductPriceValidate())->post()->goCheck('edit');
$result = StoreProductPriceLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(StoreProductPriceLogic::getError());
}
/**
* @notes 删除
* @author admin
* @date 2025/04/03 15:19
*/
public function delete()
{
$params = (new StoreProductPriceValidate())->post()->goCheck('delete');
StoreProductPriceLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @author admin
* @date 2025/04/03 15:19
*/
public function detail()
{
$params = (new StoreProductPriceValidate())->goCheck('detail');
$result = StoreProductPriceLogic::detail($params);
return $this->data($result);
}
/**
* @notes 确认改价
*/
public function enterPrice()
{
$params = $this->request->post();
$result = StoreProductPriceLogic::enterPrice($params);
return $this->success('设置成功', [], 1, 1);
}
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);
}
2025-04-07 10:25:38 +08:00
public function setProductPrice($params, $product, $warehouseId = 0, $warehouseProductId = 0)
{
$priceConfig = [];
$data = [
'bhoid' => $params['order_id'],
'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,
];
$productPriceRate = self::getProductPriceRate($product);
if (!empty($productPriceRate)) {
$productService = new ProductPriceService();
$priceArray = $productService->setProductPrice($params['purchase'], $productPriceRate);
$data = array_merge($data, $priceArray);
}
$data['price_config'] = $priceConfig;
$find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
if ($find) {
$find->save($data);
} else {
StoreProductPrice::create($data);
}
}
2025-04-03 16:25:57 +08:00
}