添加一键复制预订单

This commit is contained in:
lewis 2025-01-13 16:55:21 +08:00
parent 227bde742d
commit a3dfac406b
2 changed files with 45 additions and 0 deletions

View File

@ -340,5 +340,13 @@ class BeforehandOrderController extends BaseAdminController
BeforehandOrderLogic::confirmLog($params);
return $this->success('确认成功');
}
public function copy()
{
$params = $this->request->post();
$params['admin_id'] = $this->adminId;
BeforehandOrderLogic::copy($params);
return $this->success('复制成功');
}
}

View File

@ -1028,4 +1028,41 @@ class BeforehandOrderLogic extends BaseLogic
return $data;
}
public static function copy($params)
{
Db::startTrans();
try {
$order = BeforehandOrder::where('id', $params['id'])->find();
if (empty($order)) {
throw new BusinessException('订单不存在');
}
if ($order['order_type'] != 1) {
throw new BusinessException('只能复制铺货订单');
}
$orderCartInfo = BeforehandOrderCartInfo::where('bhoid', $params['id'])->select()->toArray();
unset($order['id'], $order['create_time'], $order['update_time']);
$newOrder = new BeforehandOrder();
$newOrder->setAttrs($order->toArray());
$newOrder->admin_id = $params['admin_id'];
$newOrder->store_id = $params['store_id'];
$newOrder->order_id = getNewOrderId('YG');
if (!empty($params['mark'])) {
$newOrder->mark = $params['mark'];
}
$newOrder->save();
$insert = [];
foreach ($orderCartInfo as $v) {
unset($v['id'], $v['create_time'], $v['update_time']);
$v['bhoid'] = $newOrder->id;
$insert[] = $v;
}
(new BeforehandOrderCartInfo())->saveAll($insert);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
}