feat: 添加创建出库单功能及修改订单导出逻辑

This commit is contained in:
mkm 2024-09-02 12:07:25 +08:00
parent 0aa79334ac
commit 9962d9ae47
2 changed files with 123 additions and 37 deletions

View File

@ -7,6 +7,8 @@ use app\admin\controller\BaseAdminController;
use app\admin\lists\store_order\StoreOrderLists;
use app\admin\lists\store_order\StoreRefundOrderLists;
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\common\enum\PayEnum;
use app\common\logic\PayNotifyLogic;
@ -15,7 +17,11 @@ use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\service\xlsx\OrderDetail;
use support\exception\BusinessException;
use think\facade\Db;
/**
* 订单列表控制器
@ -155,25 +161,90 @@ class StoreOrderController extends BaseAdminController
$id = $this->request->post('id');
$system_store = $this->request->post('system_store');
$xlsx = new OrderDetail();
$order=StoreOrder::where('id',$id)->findOrEmpty();
$time= strtotime('+1 day', $order['pay_time']);
$order['pay_time']=date('Y-m-d H:i:s',$order['pay_time']);
$order['delivery_time']=date('Y-m-d', $time);
$order = StoreOrder::where('id', $id)->findOrEmpty();
$time = strtotime('+1 day', $order['pay_time']);
$order['pay_time'] = date('Y-m-d H:i:s', $order['pay_time']);
$order['delivery_time'] = date('Y-m-d', $time);
$data = StoreOrderCartInfo::where('oid', $id)->select();
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->total_price=bcmul($value['price'],$value['cart_num'],2);
if(!empty($find['unit'])){
$value->unit_name=StoreProductUnit::where('id',$find['unit'])->value('name');
}else{
$value->unit_name='';
$find = StoreProduct::where('id', $value->product_id)->find();
$value->store_name = $find['store_name'] ?? '';
$value->store_info = $find['store_info'] ?? '';
$value->total_price = bcmul($value['price'], $value['cart_num'], 2);
if (!empty($find['unit'])) {
$value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
} else {
$value->unit_name = '';
}
}
$order['total_price']=$order['pay_price'];
$file_path = $xlsx->export($data,$system_store,$order);
$order['total_price'] = $order['pay_price'];
$file_path = $xlsx->export($data, $system_store, $order);
return $this->success('导出成功', ['url' => $file_path]);
}
/**
* 创建出库单
*/
public function createOutboundOrder()
{
$id = $this->request->post('id');
$store_id = $this->request->post('store_id');
$warehouse_id = $this->request->post('warehouse_id');
$delivery_time = $this->request->post('delivery_time');
$mark = $this->request->post('mark');
$find = WarehouseOrder::where('oid',$id)->find();
if($find){
return $this->fail('该订单已创建出库单');
}
$product_arr=StoreOrderCartInfo::where('oid',$id)->field('oid,product_id id,price,total_price,cart_num stock')->select();
if(!$product_arr){
return $this->fail('无商品');
}
Db::startTrans();
try {
$arr = [
'oid' => $id,
'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,
];
$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);
}
}

View File

@ -63,13 +63,13 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
if ($this->request->get('start_time') == '') {
$this->searchWhere[] = ['create_time', 'between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]];
}
$this->searchWhere[]=['is_pay','=',1];
$this->searchWhere[]=['status','>=',0];
$this->searchWhere[] = ['is_pay', '=', 1];
$this->searchWhere[] = ['status', '>=', 0];
$query = StoreOrderCartInfo::where($this->searchWhere);
if ($this->request->get('is_group') == 1) {
$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');
$query->field('store_id,product_id,price,total_price,cart_num,create_time');
}
return $query->limit($this->limitOffset, $this->limitLength)
->select()->each(function ($item) {
@ -78,16 +78,16 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
$item['image'] = $find['image']; //商品图片
$item['store_name'] = $find['store_name']; //商品名称
$item['store_info'] = $find['store_info']; //商品规格
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??'';
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name')??'';
$item['system_store'] = SystemStore::where('id', $item['store_id'])->value('name')??'';
}else{
$item['image']='';//商品图片
$item['store_name']='';//商品名称
$item['store_info']='';//商品规格-(数据库叫商品简介)
$item['unit_name']='';//
$item['cate_name']='';//
$item['system_store']='';//
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? '';
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name') ?? '';
$item['system_store'] = SystemStore::where('id', $item['store_id'])->value('name') ?? '';
} else {
$item['image'] = ''; //商品图片
$item['store_name'] = ''; //商品名称
$item['store_info'] = ''; //商品规格-(数据库叫商品简介)
$item['unit_name'] = ''; //
$item['cate_name'] = ''; //
$item['system_store'] = ''; //
}
return $item; //返回处理后的数据。
})
@ -130,16 +130,31 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
*/
public function setExcelFields(): array
{
$data = [
'system_store' => '门店',
'store_name' => '商品名称',
'store_info' => '规格',
'unit_name' => '单位',
'cate_name' => '分类',
'cart_num' => '数量',
'price' => '单价',
'total_price' => '总价',
];
if ($this->request->get('is_group') == 1) {
$data = [
'system_store' => '门店',
'store_name' => '商品名称',
'store_info' => '规格',
'unit_name' => '单位',
'cate_name' => '分类',
'cart_num' => '数量',
'price' => '单价',
'total_price' => '总价',
];
} else {
$data = [
'system_store' => '门店',
'store_name' => '商品名称',
'store_info' => '规格',
'unit_name' => '单位',
'cate_name' => '分类',
'cart_num' => '数量',
'price' => '单价',
'total_price' => '总价',
'create_time' => '时间',
];
}
return $data;
}
}