lihaiMiddleOffice/app/psi/controller/WarehouseOrderController.php
2025-03-12 11:19:42 +08:00

143 lines
4.2 KiB
PHP

<?php
namespace app\psi\controller;
use app\admin\controller\BaseAdminController;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\supplier\Supplier;
use app\common\model\system_store\SystemStore;
use app\common\model\WarehouseOrder;
use app\common\model\WarehouseProduct;
use app\common\service\xlsx\OrderDetail;
use app\common\service\xlsx\WarehouseOrderEntry;
use app\psi\lists\WarehouseOrderLists;
use app\psi\logic\WarehouseOrderLogic;
use app\psi\validate\WarehouseOrderValidate;
/**
* PsiWarehouseOrder控制器
* Class WarehouseOrderController
* @package app\psi\controller
*/
class WarehouseOrderController extends BaseAdminController
{
/**
* @notes 获取列表
* @author admin
* @date 2025/03/10 11:08
*/
public function lists()
{
return $this->dataLists(new WarehouseOrderLists());
}
/**
* @notes 添加
* @author admin
* @date 2025/03/10 11:08
*/
public function add()
{
$params = (new WarehouseOrderValidate())->post()->goCheck('add');
$params['admin_id'] = $this->adminId;
$result = WarehouseOrderLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(WarehouseOrderLogic::getError());
}
/**
* @notes 编辑
* @author admin
* @date 2025/03/10 11:08
*/
public function edit()
{
$params = (new WarehouseOrderValidate())->post()->goCheck('edit');
$result = WarehouseOrderLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(WarehouseOrderLogic::getError());
}
public function updateAmount()
{
$params = $this->request->post();
$res = WarehouseOrder::update($params);
if ($res) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail('编辑失败');
}
/**
* @notes 删除
* @author admin
* @date 2025/03/10 11:08
*/
public function delete()
{
$params = (new WarehouseOrderValidate())->post()->goCheck('delete');
WarehouseOrderLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @author admin
* @date 2025/03/10 11:08
*/
public function detail()
{
$params = (new WarehouseOrderValidate())->goCheck('detail');
$result = WarehouseOrderLogic::detail($params);
return $this->data($result);
}
/**
* 入库表格
*/
public function export()
{
$id = $this->request->post('id');
$xlsx = new WarehouseOrderEntry();
$order = WarehouseOrder::where('id', $id)->findOrEmpty();
$data = WarehouseProduct::where('oid', $id)->select();
$order['total_num'] = 0;
$credit_pay = 0;
$cash_pay = 0;
foreach ($data as $value) {
$find = StoreProduct::where('id', $value->product_id)->withTrashed()->find();
$value->store_name = $find['store_name'] ?? '';
$value->store_info = $find['store_info'] ?? '';
if (!empty($find['unit'])) {
$value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
} else {
$value->unit_name = '';
}
$order['total_num'] += $value->nums;
$value->supplier_name = Supplier::where('id', $value->supplier_id)->value('name');
if ($value->pay_type == 1) {
$credit_pay += $value->total_price;
$value->pay_type_name = '赊账';
} elseif ($value->pay_type == 2) {
$cash_pay += $value->total_price;
$value->pay_type_name = '现款';
} else {
$value->pay_type_name = '未设置';
}
}
$order['credit_pay'] = $credit_pay;
$order['cash_pay'] = $cash_pay;
$file_path = $xlsx->export($data, $order);
return $this->success('导出成功', ['url' => $file_path]);
}
}