feat: 添加创建出库单功能及修改订单导出逻辑
This commit is contained in:
parent
0aa79334ac
commit
9962d9ae47
@ -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;
|
||||
|
||||
/**
|
||||
* 订单列表控制器
|
||||
@ -176,4 +182,69 @@ class StoreOrderController extends BaseAdminController
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
|
||||
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) {
|
||||
@ -130,6 +130,7 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
|
||||
*/
|
||||
public function setExcelFields(): array
|
||||
{
|
||||
if ($this->request->get('is_group') == 1) {
|
||||
$data = [
|
||||
'system_store' => '门店',
|
||||
'store_name' => '商品名称',
|
||||
@ -140,6 +141,20 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
|
||||
'price' => '单价',
|
||||
'total_price' => '总价',
|
||||
];
|
||||
} else {
|
||||
$data = [
|
||||
'system_store' => '门店',
|
||||
'store_name' => '商品名称',
|
||||
'store_info' => '规格',
|
||||
'unit_name' => '单位',
|
||||
'cate_name' => '分类',
|
||||
'cart_num' => '数量',
|
||||
'price' => '单价',
|
||||
'total_price' => '总价',
|
||||
'create_time' => '时间',
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user