commit
353aade6be
@ -100,82 +100,6 @@ class StoreProductController extends BaseAdminController
|
||||
*/
|
||||
public function import()
|
||||
{
|
||||
$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('商品库存不足');
|
||||
}
|
||||
}
|
||||
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);
|
||||
return $this->fail('接口已关闭');
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\warehouse_order;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\warehouse_order\WarehouseOrderLists;
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\admin\logic\warehouse_order\WarehouseOrderLogic;
|
||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\admin\validate\warehouse_order\WarehouseOrderValidate;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
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\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use app\common\service\xlsx\OrderDetail;
|
||||
use app\common\service\xlsx\WarehouseOrdeRentry;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 仓储商品单控制器
|
||||
* Class WarehouseOrderController
|
||||
* @package app\admin\controller\warehouse_order
|
||||
*/
|
||||
class WarehouseOrderController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取仓储商品单列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
|
||||
return $this->dataLists(new WarehouseOrderLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加入库单
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$result = WarehouseOrderLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(WarehouseOrderLogic::getError());
|
||||
}
|
||||
/**
|
||||
* @notes 添加出库单
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
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');
|
||||
$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 ($count == 1) {
|
||||
$store_id = $store_arr[0];
|
||||
$arr = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'store_id' => $store_id,
|
||||
'supplier_id' => 0,
|
||||
'code' => getNewOrderId('PS'),
|
||||
'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 = [
|
||||
'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,
|
||||
];
|
||||
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
if ($arr['stock'] == 0) {
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||
} else {
|
||||
$data['total_price'] = bcmul($arr['stock'], $find['purchase'], 2);
|
||||
$data['purchase'] = $find['purchase'];
|
||||
$data['oid'] = $res['id'];
|
||||
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();
|
||||
}
|
||||
$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']]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return $this->fail('暂不支持多门店入库');
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
d($e);
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑仓储商品单
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除仓储商品单
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new WarehouseOrderValidate())->post()->goCheck('delete');
|
||||
WarehouseOrderLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取仓储商品单详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new WarehouseOrderValidate())->goCheck('detail');
|
||||
$result = WarehouseOrderLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
/**
|
||||
* 入库表格
|
||||
*/
|
||||
public function rentry_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;
|
||||
foreach ($data as $key => &$value) {
|
||||
$find = StoreProduct::where('id', $value->product_id)->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;
|
||||
}
|
||||
$file_path = $xlsx->export($data, $order);
|
||||
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 出库表格
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$xlsx = new OrderDetail();
|
||||
$order = WarehouseOrder::where('id', $id)->findOrEmpty();
|
||||
$system_store = SystemStore::where('id', $order['store_id'])->value('name');
|
||||
$data = WarehouseProduct::where('oid', $id)->select();
|
||||
$order['total_num'] = 0;
|
||||
foreach ($data as $key => &$value) {
|
||||
$find = StoreProduct::where('id', $value->product_id)->find();
|
||||
$value->store_name = $find['store_name'] ?? '';
|
||||
$value->store_info = $find['store_info'] ?? '';
|
||||
$value->price = $value['purchase'];
|
||||
$value->cart_num = $value['nums'];
|
||||
if (!empty($find['unit'])) {
|
||||
$value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
} else {
|
||||
$value->unit_name = '';
|
||||
}
|
||||
$order['total_num'] += $value->nums;
|
||||
}
|
||||
$order['delivery_time']=date('Y-m-d H:i:s',$order['delivery_time']);
|
||||
$order['pay_time']=$order['create_time'];
|
||||
$order['order_id']=$order['code'];
|
||||
$file_path = $xlsx->export($data, $system_store, $order);
|
||||
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
}
|
@ -38,6 +38,8 @@ class WarehouseProductController extends BaseAdminController
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
return $this->fail('当前接口废弃');
|
||||
|
||||
$params = $this->request->post();
|
||||
|
||||
foreach($params['product_arr'] as $k=>$v){
|
||||
|
@ -148,6 +148,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
||||
'cost' => '商户价',
|
||||
'vip_price' => '会员价',
|
||||
'price' => '零售价',
|
||||
'bar_code' => '条码',
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
94
app/admin/lists/warehouse_order/WarehouseOrderLists.php
Normal file
94
app/admin/lists/warehouse_order/WarehouseOrderLists.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\warehouse_order;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\warehouse\Warehouse;
|
||||
|
||||
/**
|
||||
* 仓储商品单列表
|
||||
* Class WarehouseOrderLists
|
||||
* @package app\admin\listswarehouse_order
|
||||
*/
|
||||
class WarehouseOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'='=>['financial_pm']
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取仓储商品单列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
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'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item){
|
||||
if ($item->financial_pm == 0) {
|
||||
$item->financial_pm_name = '出库';
|
||||
} else {
|
||||
$item->financial_pm_name = '入库';
|
||||
}
|
||||
if($item->financial_pm==0){
|
||||
if($item->store_id){
|
||||
$item->system_store=SystemStore::where('id',$item->store_id)->value('name');
|
||||
}else{
|
||||
$item->system_store='';
|
||||
}
|
||||
}
|
||||
if ($item->admin_id) {
|
||||
$item->admin_name = Admin::where('id', $item->admin_id)->value('name');
|
||||
} else {
|
||||
$item->admin_name = '';
|
||||
}
|
||||
if ($item->warehouse_id) {
|
||||
$item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name');
|
||||
} else {
|
||||
$item->warehouse_name = '';
|
||||
}
|
||||
if ($item->supplier_id) {
|
||||
$item->supplier_name = Supplier::where('id', $item->supplier_id)->value('mer_name');
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取仓储商品单数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return WarehouseOrder::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
@ -33,7 +33,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['warehouse_id', 'financial_pm', 'store_id'],
|
||||
'=' => ['warehouse_id', 'financial_pm', 'store_id','oid'],
|
||||
'between_time' => 'create_time'
|
||||
];
|
||||
}
|
||||
|
@ -115,6 +115,7 @@ class StoreOrderLogic extends BaseLogic
|
||||
$refund = (new \app\common\logic\store_order\StoreOrderLogic())
|
||||
->refund($params['order_id'], $money, $money);
|
||||
if ($refund) {
|
||||
StoreOrderCartInfo::where('oid',$detail['id'])->update(['is_pay'=>-1]);
|
||||
return '退款成功';
|
||||
}
|
||||
}
|
||||
@ -127,11 +128,13 @@ class StoreOrderLogic extends BaseLogic
|
||||
]
|
||||
];
|
||||
PayNotifyLogic::refund($params['order_id'], $arr);
|
||||
StoreOrderCartInfo::where('oid',$detail['id'])->update(['is_pay'=>-1]);
|
||||
return '退款成功';
|
||||
}
|
||||
//现金支付
|
||||
if ($detail['pay_type'] = PayEnum::CASH_PAY) {
|
||||
PayNotifyLogic::cash_refund($params['order_id']);
|
||||
StoreOrderCartInfo::where('oid',$detail['id'])->update(['is_pay'=>-1]);
|
||||
return '退款成功';
|
||||
}
|
||||
return false;
|
||||
|
@ -444,7 +444,7 @@ class StoreProductLogic extends BaseLogic
|
||||
// }
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
|
||||
return false;
|
||||
|
137
app/admin/logic/warehouse_order/WarehouseOrderLogic.php
Normal file
137
app/admin/logic/warehouse_order/WarehouseOrderLogic.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\warehouse_order;
|
||||
|
||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 仓储商品单逻辑
|
||||
* Class WarehouseOrderLogic
|
||||
* @package app\admin\logic\warehouse_order
|
||||
*/
|
||||
class WarehouseOrderLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加仓储商品单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$arr=[
|
||||
'warehouse_id'=>$params['warehouse_id'],
|
||||
'supplier_id'=>$params['supplier_id'],
|
||||
'code'=>$params['code'],
|
||||
'admin_id'=>$params['admin_id'],
|
||||
'financial_pm'=>1,
|
||||
'batch'=>0,
|
||||
'mark'=>$params['remark'],
|
||||
'total_price'=>$params['remark'],
|
||||
];
|
||||
|
||||
$total_price=0;
|
||||
foreach($params['product_arr'] as $k=>$v){
|
||||
$total_price+=$v['total_price'];
|
||||
}
|
||||
$arr['total_price']=$total_price;
|
||||
$res=WarehouseOrder::create($arr);
|
||||
foreach($params['product_arr'] as $k=>$v){
|
||||
$data['admin_id']=$params['admin_id'];
|
||||
$data['store_id']=0;
|
||||
$data['oid']=$res['id'];
|
||||
$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);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑仓储商品单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
WarehouseOrder::where('id', $params['id'])->update([
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'supplier_id' => $params['supplier_id'],
|
||||
'store_id' => $params['store_id'],
|
||||
'code' => $params['code'],
|
||||
'financial_pm' => $params['financial_pm'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'batch' => $params['batch'],
|
||||
'mark' => $params['mark'],
|
||||
'purchase' => $params['purchase'],
|
||||
'total_price' => $params['total_price'],
|
||||
'status' => $params['status']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除仓储商品单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return WarehouseOrder::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取仓储商品单详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return WarehouseOrder::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
@ -62,6 +62,7 @@ class WarehouseProductLogic extends BaseLogic
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||
'oid' => $params['oid'] ?? 0,
|
||||
'store_id' => $params['store_id'] ?? 0,
|
||||
'product_id' => $params['product_id'],
|
||||
'financial_pm' => $params['financial_pm'],
|
||||
|
@ -59,12 +59,13 @@ class editSelfValidate extends BaseValidate
|
||||
if (empty($data['password_old'])) {
|
||||
return '请填写当前密码';
|
||||
}
|
||||
|
||||
$admin = Admin::findOrEmpty($data['admin_id']);
|
||||
if (!password_verify($data['password_old'],$admin['password'])) {
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$oldPassword = create_password($data['password_old'], $passwordSalt);
|
||||
|
||||
if ($admin['password'] != $oldPassword) {
|
||||
return '当前密码错误';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate\warehouse_order;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 仓储商品单验证器
|
||||
* Class WarehouseOrderValidate
|
||||
* @package app\admin\validate\warehouse_order
|
||||
*/
|
||||
class WarehouseOrderValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'warehouse_id' => 'require',
|
||||
'batch' => 'require',
|
||||
'total_price' => 'require',
|
||||
'status' => 'require',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'warehouse_id' => '仓库',
|
||||
'batch' => '批次',
|
||||
'total_price' => '总价格',
|
||||
'status' => '状态',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return WarehouseOrderValidate
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['warehouse_id','batch','total_price','status']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return WarehouseOrderValidate
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','warehouse_id','batch','total_price','status']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return WarehouseOrderValidate
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return WarehouseOrderValidate
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
}
|
@ -289,6 +289,7 @@ class OrderLogic extends BaseLogic
|
||||
}
|
||||
$_order['uid'] = $uid;
|
||||
$_order['spread_uid'] = $params['spread_uid'] ?? 0;
|
||||
$_order['mark'] = $params['mark'] ?? '';
|
||||
$_order['real_name'] = $user['real_name'] ?? '';
|
||||
$_order['user_phone'] = $user['mobile'] ?? '';
|
||||
$_order['pay_type'] = $orderInfo['order']['pay_type'];
|
||||
|
@ -115,6 +115,7 @@ class CapitalFlowLogic extends BaseLogic
|
||||
$model->title = $this->getTitle($category, $amount);
|
||||
$model->mark = empty($mark) ? $model->title : $mark;
|
||||
$model->save();
|
||||
//这里有bug 要修改
|
||||
$this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]);
|
||||
return $model->id;
|
||||
}
|
||||
@ -144,6 +145,7 @@ class CapitalFlowLogic extends BaseLogic
|
||||
$model->title = $this->getTitle($category, $amount);
|
||||
$model->mark = empty($mark) ? $model->title : $mark;
|
||||
$model->save();
|
||||
//这里有bug 要修改
|
||||
$this->store->update(['balance' => $model->balance], ['id' => $this->store['id']]);
|
||||
return $model->id;
|
||||
}
|
||||
|
22
app/common/model/warehouse_order/WarehouseOrder.php
Normal file
22
app/common/model/warehouse_order/WarehouseOrder.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\warehouse_order;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 仓储商品单模型
|
||||
* Class WarehouseOrder
|
||||
* @package app\common\model\warehouse_order
|
||||
*/
|
||||
class WarehouseOrder extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'warehouse_order';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
@ -79,33 +79,40 @@ class OrderDetail
|
||||
$sheet->setCellValue('F' . $count + 6, '合计价格');
|
||||
$sheet->setCellValue('G' . $count + 6, $order['total_price']);
|
||||
|
||||
$sheet->mergeCells('A' . ($count + 7) . ':J' . $count + 7);
|
||||
$sheet->setCellValue('A' . ($count + 7), '备注');
|
||||
$sheet->mergeCells('B' . ($count + 7) . ':J' . $count + 7);
|
||||
$sheet->setCellValue('B' . ($count + 7), $order['mark']??'');
|
||||
|
||||
$sheet->mergeCells('A' . ($count + 8) . ':J' . $count + 8);
|
||||
|
||||
$sheet->mergeCells('A' . ($count + 9) . ':A' . $count + 10);
|
||||
$sheet->setCellValue('A' . ($count + 9), '销售单位');
|
||||
$sheet->setCellValue('B' . ($count + 9), '名称');
|
||||
$sheet->setCellValue('C' . ($count + 9), $this->company);
|
||||
$sheet->setCellValue('B' . ($count + 10), '地址');
|
||||
$sheet->setCellValue('C' . ($count + 10), $this->address);
|
||||
$sheet->setCellValue('G' . ($count + 9), '公司电话');
|
||||
$sheet->setCellValue('H' . ($count + 9), $this->phone);
|
||||
$sheet->setCellValue('G' . ($count + 10), '售后电话');
|
||||
$sheet->setCellValue('H' . ($count + 10), $this->tel);
|
||||
|
||||
|
||||
|
||||
$sheet->mergeCells('A' . ($count + 8) . ':A' . $count + 9);
|
||||
$sheet->setCellValue('A' . ($count + 8), '销售单位');
|
||||
$sheet->setCellValue('B' . ($count + 8), '名称');
|
||||
$sheet->setCellValue('C' . ($count + 8), $this->company);
|
||||
$sheet->setCellValue('B' . ($count + 9), '地址');
|
||||
$sheet->setCellValue('C' . ($count + 9), $this->address);
|
||||
$sheet->setCellValue('G' . ($count + 8), '公司电话');
|
||||
$sheet->setCellValue('H' . ($count + 8), $this->phone);
|
||||
$sheet->setCellValue('G' . ($count + 9), '售后电话');
|
||||
$sheet->setCellValue('H' . ($count + 9), $this->tel);
|
||||
|
||||
$sheet->mergeCells('C' . ($count + 8) . ':F' . $count + 8);
|
||||
$sheet->mergeCells('C' . ($count + 9) . ':F' . $count + 9);
|
||||
$sheet->mergeCells('H' . ($count + 8) . ':J' . ($count + 8));
|
||||
$sheet->mergeCells('H' . ($count + 9) . ':J' . $count + 9);
|
||||
$sheet->mergeCells('C' . ($count + 10) . ':F' . $count + 10);
|
||||
$sheet->mergeCells('H' . ($count + 9) . ':J' . ($count + 9));
|
||||
$sheet->mergeCells('H' . ($count + 10) . ':J' . $count + 10);
|
||||
|
||||
$sheet->mergeCells('A' . ($count + 10) . ':J' . $count + 10);
|
||||
$sheet->mergeCells('A' . ($count + 11) . ':J' . $count + 11);
|
||||
|
||||
$sheet->setCellValue('A' . $count + 11, '仓库',);
|
||||
$sheet->setCellValue('A' . $count + 12, '仓库',);
|
||||
// $sheet->setCellValue('B' . $count + 11, $this->warehouse);
|
||||
$sheet->mergeCells('B' . ($count + 11) . ':C' . $count + 11);
|
||||
$sheet->setCellValue('D' . $count + 11, '送货');
|
||||
$sheet->mergeCells('E' . ($count + 11) . ':F' . $count + 11);
|
||||
$sheet->setCellValue('G' . $count + 11, '签收人');
|
||||
$sheet->mergeCells('H' . ($count + 11) . ':J' . $count + 11);
|
||||
$sheet->mergeCells('B' . ($count + 12) . ':C' . $count + 12);
|
||||
$sheet->setCellValue('D' . $count + 12, '送货');
|
||||
$sheet->mergeCells('E' . ($count + 12) . ':F' . $count + 12);
|
||||
$sheet->setCellValue('G' . $count + 12, '签收人');
|
||||
$sheet->mergeCells('H' . ($count + 12) . ':J' . $count + 12);
|
||||
|
||||
// 设置单元格的样式
|
||||
$styleArray = [
|
||||
@ -124,12 +131,12 @@ class OrderDetail
|
||||
],
|
||||
],
|
||||
];
|
||||
$sheet->getStyle('A1:J' . ($count + 11))->applyFromArray($styleArray);
|
||||
$sheet->getStyle('A1:J' . ($count + 12))->applyFromArray($styleArray);
|
||||
|
||||
// 保存文件到 public 下
|
||||
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$url = '/export/' . date('Y-m') . '/' . $system_store . '.xlsx';
|
||||
$url = '/export/' . date('Y-m') . '/' . $system_store.'出库单-'.date('Y-m-d H:i') . '.xlsx';
|
||||
$file_path = public_path() . $url;
|
||||
// 保存文件到 public 下
|
||||
$writer->save($file_path);
|
||||
|
120
app/common/service/xlsx/WarehouseOrdeRentry.php
Normal file
120
app/common/service/xlsx/WarehouseOrdeRentry.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service\xlsx;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
|
||||
class WarehouseOrdeRentry
|
||||
{
|
||||
|
||||
public $warehouse='海吉星仓库';
|
||||
public $company='供投里海';
|
||||
public $address='泸州龙马潭区海吉星122栋';
|
||||
public $phone='08302669767';
|
||||
public $tel='17309099881';
|
||||
|
||||
public function export($data,$order)
|
||||
{
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
// 合并单元格A1到K1
|
||||
$sheet->mergeCells('A1:J1');//标题
|
||||
$sheet->mergeCells('B2:E2');//开单日期
|
||||
$sheet->mergeCells('G2:J2');//单号
|
||||
$sheet->mergeCells('B3:C3');
|
||||
$sheet->mergeCells('D3:E3');
|
||||
|
||||
$sheet->setCellValue('A1', $this->company.'公司入库单');
|
||||
$sheet->setCellValue('A2', '入库时间');
|
||||
$sheet->setCellValue('B2', $order['create_time']??'');
|
||||
$sheet->setCellValue('F2', '单号');
|
||||
$sheet->setCellValue('G2', $order['code']??'');
|
||||
$sheet->setCellValue('A3', '序号');
|
||||
$sheet->setCellValue('B3', '商品名称');
|
||||
$sheet->setCellValue('D3', '规格');
|
||||
$sheet->setCellValue('F3', '单位');
|
||||
$sheet->setCellValue('G3', '单价');
|
||||
$sheet->setCellValue('H3', '数量');
|
||||
$sheet->setCellValue('I3', '总价');
|
||||
$sheet->setCellValue('J3', '备注');
|
||||
|
||||
// 设置默认的单元格样式
|
||||
$defaultStyle = [
|
||||
'alignment' => [
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
'vertical' => Alignment::VERTICAL_CENTER,
|
||||
],
|
||||
];
|
||||
|
||||
// 应用默认样式到整个工作表
|
||||
$spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle);
|
||||
|
||||
foreach ($data as $k => $v) {
|
||||
$sheet->setCellValue('A' . ($k + 4), $k+1 );
|
||||
$sheet->setCellValue('B' . ($k + 4), $v['store_name']);
|
||||
$sheet->mergeCells('B' . ($k + 4) . ':C' . $k + 4);
|
||||
$sheet->setCellValue('D' . ($k + 4), $v['store_info']);
|
||||
$sheet->mergeCells('D' . ($k + 4) . ':E' . $k + 4);
|
||||
$sheet->setCellValue('F' . ($k + 4), $v['unit_name']);
|
||||
$sheet->setCellValue('G' . ($k + 4), $v['purchase']);
|
||||
$sheet->setCellValue('H' . ($k + 4), $v['nums']);
|
||||
$sheet->setCellValue('I' . ($k + 4), $v['total_price']);
|
||||
}
|
||||
|
||||
$count = count($data);
|
||||
$sheet->mergeCells('A' . ($count + 4) . ':J' . $count + 4);
|
||||
|
||||
$sheet->mergeCells('B' . ($count + 5) . ':E' . $count + 5);
|
||||
$sheet->setCellValue('A' . $count + 5, '合计数量');
|
||||
$sheet->setCellValue('B' . $count + 5,$order['total_num']);
|
||||
$sheet->mergeCells('G' . ($count + 5) . ':J' . $count + 5);
|
||||
$sheet->setCellValue('F' . $count + 5, '合计价格');
|
||||
$sheet->setCellValue('G' . $count + 5, $order['total_price']);
|
||||
|
||||
// $sheet->mergeCells('C' . ($count + 7) . ':F' . $count + 7);
|
||||
// $sheet->mergeCells('C' . ($count + 8) . ':F' . $count + 8);
|
||||
// $sheet->mergeCells('H' . ($count + 7) . ':J' . ($count + 7));
|
||||
// $sheet->mergeCells('H' . ($count + 8) . ':J' . $count + 8);
|
||||
|
||||
$sheet->mergeCells('A' . ($count + 6) . ':J' . $count + 6);
|
||||
|
||||
$sheet->setCellValue('A' . $count + 7, '录入人',);
|
||||
// $sheet->setCellValue('B' . $count + 11, $this->warehouse);
|
||||
$sheet->mergeCells('B' . ($count + 7) . ':C' . $count + 7);
|
||||
$sheet->setCellValue('D' . $count + 7, '采购人');
|
||||
$sheet->mergeCells('E' . ($count + 7) . ':F' . $count + 7);
|
||||
$sheet->setCellValue('G' . $count + 7, '审核人');
|
||||
$sheet->mergeCells('H' . ($count + 7) . ':J' . $count + 7);
|
||||
|
||||
// 设置单元格的样式
|
||||
$styleArray = [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 16,
|
||||
],
|
||||
];
|
||||
$sheet->getStyle('A1')->applyFromArray($styleArray);
|
||||
// 定义线框样式
|
||||
$styleArray = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => Border::BORDER_THIN, // 线框样式
|
||||
'color' => ['argb' => '000000'], // 线框颜色
|
||||
],
|
||||
],
|
||||
];
|
||||
$sheet->getStyle('A1:J' . ($count + 7))->applyFromArray($styleArray);
|
||||
|
||||
// 保存文件到 public 下
|
||||
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$url = '/export/' . date('Y-m') . '/' .$this->company.'公司入库单-'.date('Y-m-d H:i') . '.xlsx';
|
||||
$file_path = public_path() . $url;
|
||||
// 保存文件到 public 下
|
||||
$writer->save($file_path);
|
||||
return getenv('APP_URL').$url;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user