添加订单标签导出功能

- 在 StoreOrderController 中新增 export_tags 方法,用于导出订单标签
- 在 Beforehand 类中调整字体样式大小
This commit is contained in:
mkm 2024-10-09 15:01:05 +08:00
parent 194fbbb2dd
commit c370a96e60
2 changed files with 37 additions and 8 deletions

View File

@ -18,8 +18,10 @@ 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\system_store\SystemStore;
use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\service\xlsx\Beforehand;
use app\common\service\xlsx\OrderDetail;
use support\exception\BusinessException;
use think\facade\Db;
@ -168,9 +170,9 @@ class StoreOrderController extends BaseAdminController
$order['delivery_time'] = date('Y-m-d', $time);
$data = StoreOrderCartInfo::where('oid', $id)->select();
foreach ($data as $key => &$value) {
if(in_array($order['store_id'],[17,18])){
$find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->find();
}else{
if (in_array($order['store_id'], [17, 18])) {
$find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id', $order['store_id'])->find();
} else {
$find = StoreProduct::where('id', $value->product_id)->find();
}
$value->store_name = $find['store_name'] ?? '';
@ -198,12 +200,12 @@ class StoreOrderController extends BaseAdminController
$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){
$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){
$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();
@ -252,4 +254,31 @@ class StoreOrderController extends BaseAdminController
}
return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);
}
/**
* 导出标签
*/
public function export_tags()
{
$id = $this->request->post('id');
$order = StoreOrder::where('id', $id)->field('store_id,uid,real_name,user_address')->find();
$system_store = SystemStore::where('id', $order['store_id'])->value('introduction');
$data = StoreOrderCartInfo::where('oid', $id)->field('oid,product_id,cart_num')->select()
->each(function ($item) use ($system_store, $order) {
$find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->find();
$unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
$item['system_store'] = $system_store;
$item['subtitle'] = $item['oid'] . ' ' . convertStringToNumber($item['cart_num']) . '/' . $unit_name;
$item['store_name'] = $find['store_name'];
if ($order['uid']) {
$item['address'] = $find['real_name'] . ' ' . $find['user_address'];
} else {
$item['address'] = '无地址';
}
})
->toArray();
$file_path = (new Beforehand())->export($data, $system_store);
return $this->success('导出成功', ['url' => $file_path]);
}
}

View File

@ -21,7 +21,7 @@ class Beforehand
'marginTop' => Converter::cmToTwip(0.2),
'marginBottom' => Converter::cmToTwip(0),
));
$fontStyle = ['name' => 'Arial', 'size' => 12, 'bold' => true];
$fontStyle = ['name' => 'Arial', 'size' => 10, 'bold' => true];
$fontStyle1 = ['name' => 'Arial', 'size' => 8, 'bold' => true];
$fontStyle2 = ['name' => 'Arial', 'size' => 8, 'bold' => true];
$fontStyle3 = ['name' => 'Arial', 'size' => 8, 'bold' => true];