diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index 57fa8101..f4834238 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -57,16 +57,22 @@ class BeforehandOrderController extends BaseAdminController { $params = $this->request->post(); $params['admin_id'] = $this->adminId; - $other_data=[ - 'nickname'=>$params['nickname']??'', - 'phone'=>$params['phone']??'', - 'address'=>$params['address']??'', - 'arrival_time'=>$params['arrival_time']??'', - 'purpose'=>$params['purpose']??'', - 'tables'=>$params['tables']??'', - 'days'=>$params['days']??'', - 'chef'=>$params['chef']??'', - 'chef_phone'=>$params['chef_phone']??'', + $other_data = [ + 'nickname' => $params['nickname'] ?? '', + 'phone' => $params['phone'] ?? '', + 'address' => $params['address'] ?? '', + 'arrival_time' => $params['arrival_time'] ?? '', + 'purpose' => $params['purpose'] ?? '', + 'tables' => $params['tables'] ?? '', + 'days' => $params['days'] ?? '', + 'chef' => $params['chef'] ?? '', + 'chef_phone' => $params['chef_phone'] ?? '', + 'splitting_officer' => $params['splitting_officer'] ?? '', + 'merchandiser' => $params['merchandiser'] ?? '', + 'distribution_personnel' => $params['distribution_personnel'] ?? '', + 'transporter' => $params['transporter'] ?? '', + 'system_store_name' => $params['system_store_name'] ?? '', + 'regional_manager' => $params['regional_manager'] ?? '', ]; $params['other_data'] = $other_data; $result = BeforehandOrderLogic::add($params); @@ -75,7 +81,8 @@ class BeforehandOrderController extends BaseAdminController /** * 生成支付订单 */ - public function generateOrder(){ + public function generateOrder() + { $params = $this->request->post(); $result = BeforehandOrderLogic::generateOrder($params); return $this->success('生成成功', [], 1, 1); @@ -156,35 +163,35 @@ class BeforehandOrderController extends BaseAdminController { $params = $this->request->post(); $order = BeforehandOrder::where('id', $params['id'])->field('outbound_id,order_sn')->find(); - if(!$order){ + if (!$order) { return $this->fail('未生成出库单'); } $warehouseOrder = WarehouseOrder::where('id', $order['outbound_id'])->field('store_id,delivery_time')->find(); $system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('name'); $data = WarehouseProduct::where('oid', $order['outbound_id'])->field('product_id,nums')->select() - ->each(function ($item) use ($system_store,$warehouseOrder,$order) { + ->each(function ($item) use ($system_store, $warehouseOrder, $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['nums']).'/'.$unit_name; + $item['subtitle'] = $item['oid'] . ' ' . convertStringToNumber($item['nums']) . '/' . $unit_name; $item['store_name'] = $find['store_name']; - if($warehouseOrder['oid']){ - $find=StoreOrder::where('order_id',$order['order_sn'])->field('real_name,user_address')->find(); - if($find){ - $item['address'] = $find['real_name'].' '.$find['user_address']; - }else{ + if ($warehouseOrder['oid']) { + $find = StoreOrder::where('order_id', $order['order_sn'])->field('real_name,user_address')->find(); + if ($find) { + $item['address'] = $find['real_name'] . ' ' . $find['user_address']; + } else { $item['address'] = '无地址'; } - }else{ + } else { $item['address'] = '无地址'; } }) ->toArray(); - $file_path=(new Beforehand())->export($data, $system_store); + $file_path = (new Beforehand())->export($data, $system_store); return $this->success('导出成功', ['url' => $file_path]); } - + /** * 导出订单 */ @@ -193,9 +200,46 @@ class BeforehandOrderController extends BaseAdminController $params = $this->request->post(); $order = BeforehandOrder::where('id', $params['id'])->find(); - $cart_info=BeforehandOrderCartInfo::where('bhoid',$params['id'])->select(); + $cart_info = BeforehandOrderCartInfo::where('bhoid', $params['id'])->select(); - $file_path=(new Beforehand())->order($order, $cart_info); + $file_path = (new Beforehand())->order($order, $cart_info); + return $this->success('导出成功', ['url' => $file_path]); + } + + /** + * 导出清单 + */ + public function export_order_list() + { + $params = $this->request->post(); + $file_path = BeforehandOrderLogic::OrderList($params); + return $this->success('导出成功', ['url' => $file_path]); + } + /** + * 导出分单 + */ + public function order_allocation() + { + $params = $this->request->post(); + $file_path = BeforehandOrderLogic::OrderAllocation($params); + return $this->success('导出成功', ['url' => $file_path]); + } + /** + * 采购信息 + */ + public function order_info() + { + $params = $this->request->post(); + $file_path = BeforehandOrderLogic::OrderInfo($params); + return $this->success('导出成功', ['url' => $file_path]); + } + /** + * 导出出库 + */ + public function order_outbound() + { + $params = $this->request->post(); + $file_path = BeforehandOrderLogic::OrderOutbound($params); return $this->success('导出成功', ['url' => $file_path]); } } diff --git a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php index 9e3c0ad3..3c6f03f6 100644 --- a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php +++ b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php @@ -84,7 +84,7 @@ class PurchaseProductOfferController extends BaseAdminController return $this->success('设置成功', [], 1, 1); } /** - * 设置仓库商品信息 + * 分拣设置 */ public function setStoreroomInfo() { diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 89a84113..03dbbc0c 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -8,6 +8,7 @@ use app\api\logic\order\CartLogic; use app\api\logic\order\OrderLogic; use app\common\model\beforehand_order\BeforehandOrder; use app\common\logic\BaseLogic; +use app\common\model\auth\Admin; use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; use app\common\model\purchase_product_offer\PurchaseProductOffer; use app\common\model\store_branch_product\StoreBranchProduct; @@ -21,6 +22,10 @@ use app\common\model\user\User; use app\common\model\user\UserAddress; use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_product\WarehouseProduct; +use app\common\service\xlsx\OrderAllocation; +use app\common\service\xlsx\OrderInfo; +use app\common\service\xlsx\OrderList; +use app\common\service\xlsx\OrderOutbound; use support\exception\BusinessException; use think\facade\Db; @@ -55,7 +60,7 @@ class BeforehandOrderLogic extends BaseLogic $total_price = 0; $uid = $params['uid'] ?? 0; foreach ($params['product_arr'] as $k => $v) { - if($v['product_id']<=0){ + if ($v['product_id'] <= 0) { unset($params['product_arr'][$k]); continue; } @@ -63,17 +68,18 @@ class BeforehandOrderLogic extends BaseLogic $datas[$k]['mark'] = $v['mark'] ?? ''; $datas[$k]['product_id'] = $v['product_id']; $datas[$k]['uid'] = $uid; - $datas[$k]['marques'] = $v['marques']??''; - $datas[$k]['store_info'] = $v['store_info']??''; - $datas[$k]['after_sales'] = $v['after_sales']??''; - $datas[$k]['loss'] = $v['loss']??''; - $datas[$k]['unit'] = $v['unit']??''; - $datas[$k]['gross_weight'] = $v['gross_weight']??''; - $datas[$k]['net_weight'] = $v['net_weight']??''; + $datas[$k]['marques'] = $v['marques'] ?? ''; + $datas[$k]['store_info'] = $v['store_info'] ?? ''; + $datas[$k]['after_sales'] = $v['after_sales'] ?? ''; + $datas[$k]['loss'] = $v['loss'] ?? ''; + $datas[$k]['unit'] = $v['unit'] ?? ''; + $datas[$k]['gross_weight'] = $v['gross_weight'] ?? ''; + $datas[$k]['net_weight'] = $v['net_weight'] ?? ''; $datas[$k]['cart_num'] = $v['nums']; $datas[$k]['price'] = $v['price']; - $datas[$k]['package'] = $v['package']??''; + $datas[$k]['package'] = $v['package'] ?? ''; $datas[$k]['total_price'] = $v['total_price']; + $datas[$k]['pay_price'] = $v['total_price']; $datas[$k]['create_time'] = time(); $datas[$k]['update_time'] = time(); $total_num += $v['nums']; @@ -86,6 +92,7 @@ class BeforehandOrderLogic extends BaseLogic 'uid' => $uid, 'total_num' => $total_num, 'total_price' => $total_price, + 'pay_price' => $total_price, 'pay_price' => 0, 'pay_type' => 0, 'deduction_price' => 0, @@ -96,38 +103,35 @@ class BeforehandOrderLogic extends BaseLogic 'mark' => $params['mark'] ?? '', 'arrival_time' => strtotime($params['arrival_time']), 'order_type' => $order_type, - 'other_data' => json_encode($params['other_data'],true) + 'other_data' => json_encode($params['other_data'], true) ]); - $product_arr=[]; + $product_arr = []; foreach ($datas as $k => $v) { $datas[$k]['bhoid'] = $order['id']; - - $data['id']=$v['product_id']; - if($v['marques']!=''){ - $data['marques']=$v['marques']; + + $data['id'] = $v['product_id']; + if ($v['marques'] != '') { + $data['marques'] = $v['marques']; } - if($v['store_info']!=''){ - $data['store_info']=$v['store_info']; + if ($v['store_info'] != '') { + $data['store_info'] = $v['store_info']; } - if($v['after_sales']!=''){ - $data['after_sales']=$v['after_sales']; + if ($v['after_sales'] != '') { + $data['after_sales'] = $v['after_sales']; } - if($v['package']!=''){ - $data['package']=$v['package']; + if ($v['package'] != '') { + $data['package'] = $v['package']; } - if($v['loss']!=''){ - $data['loss']=$v['loss']; + if ($v['loss'] != '') { + $data['loss'] = $v['loss']; } - if($v['gross_weight']!=''){ - $data['gross_weight']=$v['gross_weight']; + if ($v['gross_weight'] != '') { + $data['gross_weight'] = $v['gross_weight']; } - if($v['net_weight']!=''){ - $data['net_weight']=$v['net_weight']; + if ($v['net_weight'] != '') { + $data['net_weight'] = $v['net_weight']; } - if($v['mark']!=''){ - $data['mark']=$v['mark']; - } - $product_arr[]=$data; + $product_arr[] = $data; } (new StoreProduct())->saveAll($product_arr); (new BeforehandOrderCartInfo())->saveAll($datas); @@ -173,7 +177,7 @@ class BeforehandOrderLogic extends BaseLogic $purchase = $v['purchase']; } else { $purchase = StoreProduct::where('id', $v['product_id'])->withTrashed()->value('purchase'); - $find['purchase']=$purchase; + $find['purchase'] = $purchase; // $purchase = $v['price']; } $find->save(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $purchase]); @@ -348,8 +352,8 @@ class BeforehandOrderLogic extends BaseLogic throw new BusinessException('该订单已创建出库单'); } $info = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select(); - $count = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->where('cart_num',0)->count('id'); - if($count > 0){ + $count = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->where('cart_num', 0)->count('id'); + if ($count > 0) { throw new BusinessException('订单中有数量为0的商品,请先处理'); } Db::startTrans(); @@ -491,7 +495,91 @@ class BeforehandOrderLogic extends BaseLogic $arr = StoreCategory::where('id', 'in', $top_cate_list)->field('name,id')->select(); $res['top_cate'] = $arr?->toArray(); } - $res['system_store']=SystemStore::where('id',$res['store_id'])->value('name'); + $res['system_store'] = SystemStore::where('id', $res['store_id'])->value('name'); return $res; } + + /** + * 导出清单 + */ + public static function OrderList($params) + { + $order_list = new OrderList(); + $order = BeforehandOrder::where('id', $params['id'])->find(); + $order['admin_name'] = Admin::where('id', $order['admin_id'])->value('name'); + $data = BeforehandOrderCartInfo::where('bhoid', $params['id'])->select()->each(function ($item) { + $find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit')->find(); + $item['top_cate_name'] = StoreCategory::where('id', $find['top_cate_id'])->value('name'); + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['store_name'] = $find['store_name']; + return $item; + }); + $other_data = $order['other_data']; + unset($order['other_data']); + $file_path = $order_list->export($data, $order, $other_data); + return $file_path; + } + + /** + * 导出分单 + */ + public static function OrderAllocation($params) + { + $order_allocation = new OrderAllocation(); + $order = BeforehandOrder::where('id', $params['id'])->find(); + $order['admin_name'] = Admin::where('id', $order['admin_id'])->value('name'); + $data = BeforehandOrderCartInfo::where('bhoid', $params['id'])->select()->each(function ($item) { + $find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit')->find(); + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['store_name'] = $find['store_name']; + return $item; + }); + $other_data = $order['other_data']; + unset($order['other_data']); + $file_path = $order_allocation->export($data, $order, $other_data); + return $file_path; + } + + /** + * 采购信息 + */ + public static function OrderInfo($params) + { + $order_info = new OrderInfo(); + $order = BeforehandOrder::where('id', $params['id'])->find(); + $order['admin_name'] = Admin::where('id', $order['admin_id'])->value('name'); + $data = PurchaseProductOffer::where('order_id', $params['id'])->select()->each(function ($item) { + $find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit,gross_weight,net_weight')->find(); + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['buyer_name'] = User::where('id', $item['buyer_id'])->value('real_name'); + $item['store_name'] = $find['store_name']; + $item['gross_weight'] = $find['gross_weight']; + $item['net_weight'] = $find['net_weight']; + return $item; + }); + $other_data = $order['other_data']; + unset($order['other_data']); + $file_path = $order_info->export($data, $order, $other_data); + return $file_path; + } + + /** + * 导出出库 + */ + public static function OrderOutbound($params) + { + $order_info = new OrderOutbound(); + $order = BeforehandOrder::where('id', $params['id'])->find(); + $order['admin_name'] = Admin::where('id', $order['admin_id'])->value('name'); + $data = BeforehandOrderCartInfo::where('bhoid', $params['id'])->select()->each(function ($item) { + $find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit')->find(); + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['store_name'] = $find['store_name']; + return $item; + }); + $other_data = $order['other_data']; + unset($order['other_data']); + $file_path = $order_info->export($data, $order, $other_data); + return $file_path; + } } diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index 9105e603..f3405a1a 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -210,12 +210,21 @@ class PurchaseProductOfferLogic extends BaseLogic Db::startTrans(); try { PurchaseProductOffer::where('id', $params['id'])->update(['is_accept' => 1]); - $data = [ + $find=BeforehandOrderCartInfo::where(['bhoid' => $params['bhoid'], 'product_id' => $params['product_id']])->find(); + $data=[ 'gross_weight' => $params['gross_weight'] ?? 0, 'net_weight' => $params['net_weight'] ?? 0, 'accept_num' => $params['accept_num'] ?? 0, ]; - BeforehandOrderCartInfo::where(['bhoid' => $params['bhoid'], 'product_id' => $params['product_id']])->update($data); + if($params['accept_num']!=$find['cart_num']){ + $pay_price=bcmul($params['accept_num'], $find['price'], 2); + $data['pay_price']=$pay_price; + } + $find->save($data); + if($params['accept_num']!=$find['cart_num']){ + $pay_price=BeforehandOrderCartInfo::where(['bhoid' => $params['bhoid']])->sum('pay_price'); + BeforehandOrder::where('id', $params['bhoid'])->update(['pay_price' => $pay_price]); + } Db::commit(); return true; } catch (\Throwable $e) { diff --git a/app/common/service/xlsx/OrderAllocation.php b/app/common/service/xlsx/OrderAllocation.php new file mode 100644 index 00000000..f149d426 --- /dev/null +++ b/app/common/service/xlsx/OrderAllocation.php @@ -0,0 +1,172 @@ +getActiveSheet(); + // 合并单元格A1到K1 + $sheet->mergeCells('A1:P1'); + + $sheet->mergeCells('B2:C2'); + $sheet->mergeCells('E2:F2'); + $sheet->mergeCells('G2:H2'); + $sheet->mergeCells('I2:L2'); + $sheet->mergeCells('M2:N2'); + $sheet->mergeCells('O2:P2'); + + $sheet->mergeCells('B3:C3'); + $sheet->mergeCells('D3:E3'); + $sheet->mergeCells('F3:G3'); + + $sheet->setCellValue('A1', '订 单 分 配'); + $sheet->setCellValue('A2', '姓名:'); + $sheet->setCellValue('B2', $other_data->nickname); + $sheet->getColumnDimension('C')->setAutoSize(true); + + $sheet->setCellValue('D2', '电话:'); + $sheet->setCellValue('E2', $other_data->phone); + $sheet->setCellValue('G2', '收货地址:'); + $sheet->setCellValue('I2', $other_data->address); + $sheet->setCellValue('M2', '订单编号:'); + $sheet->setCellValue('O2', $order['order_id']??''); + + $sheet->setCellValue('A3', '下单时间:'); + $sheet->setCellValue('B3', $order['create_time']??''); + $sheet->setCellValue('D3', '送货时间:'); + $sheet->setCellValue('F3', $other_data->arrival_time); + + + $sheet->setCellValue('A4', '编号'); + $sheet->setCellValue('B4', '品名'); + $sheet->setCellValue('C4', '型号'); + $sheet->setCellValue('D4', '包装'); + $sheet->setCellValue('E4', '毛重'); + $sheet->setCellValue('F4', '净重(约)'); + $sheet->setCellValue('G4', '单位'); + $sheet->setCellValue('H4', '销售单价'); + $sheet->setCellValue('I4', '下单数量'); + $sheet->setCellValue('J4', '下单金额'); + $sheet->setCellValue('K4', '发货量'); + $sheet->setCellValue('L4', '实发量'); + $sheet->setCellValue('M4', '结算金额'); + $sheet->setCellValue('N4', '售后'); + $sheet->setCellValue('O4', '正常损耗'); + $sheet->setCellValue('P4', '备注'); + + // 设置默认的单元格样式 + $defaultStyle = [ + 'alignment' => [ + 'horizontal' => Alignment::HORIZONTAL_CENTER, + 'vertical' => Alignment::VERTICAL_CENTER, + ], + ]; + + // 应用默认样式到整个工作表 + $spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle); + + foreach ($data as $k => $v) { + $sheet->setCellValue('A' . ($k + 5), $v['product_id']); + $sheet->setCellValue('B' . ($k + 5), $v['store_name']); + $sheet->setCellValue('C' . ($k + 5), $v['marques']); + $sheet->setCellValue('D' . ($k + 5), $v['package']); + $sheet->setCellValue('E' . ($k + 5), $v['gross_weight']); + $sheet->setCellValue('F' . ($k + 5), $v['net_weight']); + $sheet->setCellValue('G' . ($k + 5), $v['unit_name']); + $sheet->setCellValue('H' . ($k + 5), $v['price']); + $sheet->setCellValue('I' . ($k + 5), $v['cart_num']); + $sheet->setCellValue('J' . ($k + 5), $v['total_price']); + $sheet->setCellValue('K' . ($k + 5), $v['accept_num']); + $sheet->setCellValue('L' . ($k + 5),$v['accept_num']); + $sheet->setCellValue('M' . ($k + 5),$v['pay_price']); + $sheet->setCellValue('N' . ($k + 5),$v['after_sales']); + $sheet->setCellValue('O' . ($k + 5),$v['loss']); + $sheet->setCellValue('P' . ($k + 5),$v['mark']); + + } + + $count = count($data); + $sheet->setCellValue('A' . ($count + 6),'合计'); + $sheet->setCellValue('C' . ($count + 6),$count); + $sheet->setCellValue('I' . ($count + 6),$order['total_price'].'元'); + $sheet->setCellValue('K' . ($count + 6),$order['pay_price'].'元'); + + $sheet->setCellValue('A' . ($count + 7),'累计接单'); + $sheet->setCellValue('B' . ($count + 7),$count); + + $sheet->setCellValue('C' . ($count + 7),'采购预收金额'); + $sheet->setCellValue('D' . ($count + 7),$order['total_price'].'元'); + $sheet->setCellValue('G' . ($count + 7),'预收押金'); + $sheet->setCellValue('H' . ($count + 7),$order['deposit'].'元'); + $sheet->setCellValue('I' . ($count + 7),'合计预收'); + $sheet->setCellValue('J' . ($count + 7),bcadd($order['deposit'],$order['total_price']).'元'); + + $sheet->setCellValue('A' . ($count + 8),'接单员'); + $sheet->setCellValue('B' . ($count + 8),$order['admin_name']); + $sheet->setCellValue('C' . ($count + 8),'分单员'); + $sheet->setCellValue('D' . ($count + 8),$other_data->splitting_officer??''); + $sheet->setCellValue('E' . ($count + 8),'跟单员'); + $sheet->setCellValue('F' . ($count + 8),$other_data->merchandiser??''); + $sheet->setCellValue('G' . ($count + 8),'配货员'); + $sheet->setCellValue('H' . ($count + 8),$other_data->distribution_personnel??''); + $sheet->setCellValue('I' . ($count + 8),'运输员'); + $sheet->setCellValue('J' . ($count + 8),$other_data->transporter??''); + $sheet->setCellValue('K' . ($count + 8),'门店'); + $sheet->setCellValue('L' . ($count + 8),$other_data->system_store_name??''); + $sheet->setCellValue('M' . ($count + 8),'区域经理'); + $sheet->setCellValue('N' . ($count + 8),$other_data->regional_manager??''); + + $sheet->setCellValue('A' . ($count + 9),'接单时间'); + $sheet->setCellValue('B' . ($count + 9),''); + $sheet->setCellValue('C' . ($count + 9),'分单时间'); + $sheet->setCellValue('D' . ($count + 9),''); + $sheet->setCellValue('E' . ($count + 9),'入库时间'); + $sheet->setCellValue('F' . ($count + 9),''); + $sheet->setCellValue('G' . ($count + 9),' 出库时间'); + $sheet->setCellValue('H' . ($count + 9),''); + $sheet->setCellValue('I' . ($count + 9),' 到门店时间'); + $sheet->setCellValue('J' . ($count + 9),''); + $sheet->setCellValue('K' . ($count + 9),' 下单到货时间'); + $sheet->setCellValue('L' . ($count + 9),''); + $sheet->setCellValue('M' . ($count + 9),' 实际到货时间'); + $sheet->setCellValue('N' . ($count + 9),''); + // 设置单元格的样式 + $styleArray = [ + 'font' => [ + 'bold' => true, + 'size' => 28, + ], + ]; + $sheet->getStyle('A1')->applyFromArray($styleArray); + // 定义线框样式 + $styleArray = [ + 'borders' => [ + 'allBorders' => [ + 'borderStyle' => Border::BORDER_THIN, // 线框样式 + 'color' => ['argb' => '000000'], // 线框颜色 + ], + ], + ]; + $sheet->getStyle('A1:P' . ($count + 9))->applyFromArray($styleArray); + + // 保存文件到 public 下 + + $writer = new Xlsx($spreadsheet); + $url = '/export/' . date('Y-m') . '/' .'订单分配-'.date('Y-m-d H:i') . '.xlsx'; + $file_path = public_path() . $url; + // 保存文件到 public 下 + $writer->save($file_path); + return getenv('APP_URL').$url; + } +} diff --git a/app/common/service/xlsx/OrderInfo.php b/app/common/service/xlsx/OrderInfo.php new file mode 100644 index 00000000..ea68df9d --- /dev/null +++ b/app/common/service/xlsx/OrderInfo.php @@ -0,0 +1,133 @@ +getActiveSheet(); + // 合并单元格A1到K1 + $sheet->mergeCells('A1:R1'); + + $sheet->mergeCells('B2:C2'); + $sheet->mergeCells('E2:F2'); + $sheet->mergeCells('G2:H2'); + $sheet->mergeCells('I2:L2'); + $sheet->mergeCells('M2:N2'); + $sheet->mergeCells('O2:P2'); + + $sheet->setCellValue('A1', '采 购 信 息'); + $sheet->setCellValue('A2', '姓名:'); + $sheet->setCellValue('B2', $other_data->nickname); + $sheet->getColumnDimension('B')->setAutoSize(true); + $sheet->getColumnDimension('Q')->setAutoSize(true); + + $sheet->setCellValue('D2', '电话:'); + $sheet->setCellValue('E2', $other_data->phone); + $sheet->setCellValue('G2', '收货地址:'); + $sheet->setCellValue('I2', $other_data->address); + $sheet->setCellValue('M2', '订单编号:'); + $sheet->setCellValue('O2', $order['order_id']??''); + + $sheet->setCellValue('A3', '编号'); + $sheet->setCellValue('B3', '品名'); + $sheet->setCellValue('C3', '毛重'); + $sheet->setCellValue('D3', '净重(约)'); + $sheet->setCellValue('E3', '单位'); + $sheet->setCellValue('F3', '采购单价'); + $sheet->setCellValue('G3', '下单数量'); + $sheet->setCellValue('H3', '实收量'); + $sheet->setCellValue('I3', '采购金额'); + $sheet->setCellValue('J3', '结算模式'); + $sheet->setCellValue('K3', '包装'); + $sheet->setCellValue('L3', '押金'); + $sheet->setCellValue('M3', '型号'); + $sheet->setCellValue('N3', '售后'); + $sheet->setCellValue('O3', '损耗'); + $sheet->setCellValue('P3', '供应商'); + $sheet->setCellValue('Q3', '备注'); + $sheet->setCellValue('R3', '采购人'); + + // 设置默认的单元格样式 + $defaultStyle = [ + 'alignment' => [ + 'horizontal' => Alignment::HORIZONTAL_CENTER, + 'vertical' => Alignment::VERTICAL_CENTER, + ], + ]; + + // 应用默认样式到整个工作表 + $spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle); + + foreach ($data as $k => $v) { + $sheet->setCellValue('A' . ($k + 4), $v['product_id']); + $sheet->setCellValue('B' . ($k + 4), $v['store_name']); + $sheet->setCellValue('C' . ($k + 4), $v['gross_weight']); + $sheet->setCellValue('D' . ($k + 4), $v['net_weight']); + $sheet->setCellValue('E' . ($k + 4), $v['unit_name']); + $sheet->setCellValue('F' . ($k + 4), $v['price']); + $sheet->setCellValue('G' . ($k + 4), $v['need_num']); + $sheet->setCellValue('H' . ($k + 4), $v['buyer_nums']); + $sheet->setCellValue('I' . ($k + 4), $v['total_price']); + $sheet->setCellValue('J' . ($k + 4), ''); + $sheet->setCellValue('K' . ($k + 4), $v['package']); + $sheet->setCellValue('L' . ($k + 4), $v['deposit']); + $sheet->setCellValue('M' . ($k + 4), $v['marques']); + $sheet->setCellValue('N' . ($k + 4), $v['after_sales']); + $sheet->setCellValue('O' . ($k + 4), $v['loss']); + $sheet->setCellValue('P' . ($k + 4), ''); + $sheet->setCellValue('Q' . ($k + 4), $v['mark']); + $sheet->setCellValue('R' . ($k + 4), $v['buyer_name']); + } + + $count = count($data); + $sheet->setCellValue('A' . ($count + 5),'合计'); + $sheet->setCellValue('C' . ($count + 5),$count); + + $sheet->mergeCells('A' . ($count + 6).':B' . ($count + 6)); + $sheet->setCellValue('A' . ($count + 6),'采购员接单确认:'); + + $sheet->mergeCells('E' . ($count + 6).':G' . ($count + 6)); + $sheet->setCellValue('E' . ($count + 6),'数据入库时间:'); + + $sheet->mergeCells('M' . ($count + 6).':N' . ($count + 6)); + $sheet->setCellValue('M' . ($count + 6),'采购员录入签字:'); + // 设置单元格的样式 + $styleArray = [ + 'font' => [ + 'bold' => true, + 'size' => 28, + ], + ]; + $sheet->getStyle('A1')->applyFromArray($styleArray); + // 定义线框样式 + $styleArray = [ + 'borders' => [ + 'allBorders' => [ + 'borderStyle' => Border::BORDER_THIN, // 线框样式 + 'color' => ['argb' => '000000'], // 线框颜色 + ], + ], + ]; + $sheet->getStyle('A1:R' . ($count + 6))->applyFromArray($styleArray); + + // 保存文件到 public 下 + + $writer = new Xlsx($spreadsheet); + $url = '/export/' . date('Y-m') . '/' .'采购信息-'.date('Y-m-d H:i') . '.xlsx'; + $file_path = public_path() . $url; + // 保存文件到 public 下 + $writer->save($file_path); + return getenv('APP_URL').$url; + } +} diff --git a/app/common/service/xlsx/OrderList.php b/app/common/service/xlsx/OrderList.php new file mode 100644 index 00000000..4d58eaaa --- /dev/null +++ b/app/common/service/xlsx/OrderList.php @@ -0,0 +1,168 @@ +getActiveSheet(); + // 合并单元格A1到K1 + $sheet->mergeCells('A1:P1'); + + $sheet->mergeCells('B2:C2'); + $sheet->mergeCells('E2:F2'); + $sheet->mergeCells('G2:H2'); + $sheet->mergeCells('I2:L2'); + $sheet->mergeCells('M2:N2'); + $sheet->mergeCells('O2:P2'); + + $sheet->mergeCells('B3:C3'); + $sheet->mergeCells('E3:F3'); + $sheet->mergeCells('G3:H3'); + $sheet->mergeCells('I3:K3'); + $sheet->mergeCells('N3:O3'); + + $sheet->mergeCells('B4:C4'); + $sheet->mergeCells('D4:E4'); + $sheet->mergeCells('F4:G4'); + + $sheet->setCellValue('A1', '供 投 里 海 农 特 产 品 下 单 清 单'); + $sheet->setCellValue('A2', '姓名:'); + $sheet->setCellValue('B2', $other_data->nickname); + $sheet->getColumnDimension('C')->setAutoSize(true); + + $sheet->setCellValue('D2', '电话:'); + $sheet->setCellValue('E2', $other_data->phone); + $sheet->setCellValue('G2', '收货地址:'); + $sheet->setCellValue('I2', $other_data->address); + $sheet->setCellValue('M2', '订单编号:'); + $sheet->setCellValue('O2', $order['order_id']??''); + + $sheet->setCellValue('A3', '厨师:'); + $sheet->setCellValue('B3', $other_data->chef); + $sheet->setCellValue('D3', '电话:'); + $sheet->setCellValue('E3', $other_data->chef_phone); + $sheet->setCellValue('G3', '事由:'); + $sheet->setCellValue('I3', $other_data->purpose); + $sheet->setCellValue('L3', '桌数:'); + $sheet->setCellValue('M3', $other_data->tables); + $sheet->setCellValue('N3', '办事时间:'); + $sheet->setCellValue('P3', $other_data->days); + + $sheet->setCellValue('A4', '下单时间:'); + $sheet->setCellValue('B4', $order['create_time']??''); + $sheet->setCellValue('D4', '送货时间:'); + $sheet->setCellValue('F4', $other_data->arrival_time); + + + $sheet->setCellValue('A5', '编号'); + $sheet->setCellValue('B5', '类别'); + $sheet->setCellValue('C5', '品名'); + $sheet->setCellValue('D5', '毛重'); + $sheet->setCellValue('E5', '净重(约)'); + $sheet->setCellValue('F5', '单位'); + $sheet->setCellValue('G5', '单价/元'); + $sheet->setCellValue('H5', '下单数量'); + $sheet->setCellValue('I5', '下单金额'); + $sheet->setCellValue('J5', '包装'); + $sheet->setCellValue('K5', '押金'); + $sheet->setCellValue('L5', '售后'); + $sheet->setCellValue('M5', '正常损耗'); + $sheet->setCellValue('N5', '产地'); + $sheet->mergeCells('O5:P5'); + $sheet->setCellValue('O5', '备注'); + + // 设置默认的单元格样式 + $defaultStyle = [ + 'alignment' => [ + 'horizontal' => Alignment::HORIZONTAL_CENTER, + 'vertical' => Alignment::VERTICAL_CENTER, + ], + ]; + + // 应用默认样式到整个工作表 + $spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle); + + foreach ($data as $k => $v) { + $sheet->setCellValue('A' . ($k + 6), $v['product_id']); + $sheet->setCellValue('B' . ($k + 6), $v['top_cate_name']); + $sheet->setCellValue('C' . ($k + 6), $v['store_name']); + $sheet->setCellValue('D' . ($k + 6), $v['gross_weight']); + $sheet->setCellValue('E' . ($k + 6), $v['net_weight']); + $sheet->setCellValue('F' . ($k + 6), $v['unit_name']); + $sheet->setCellValue('G' . ($k + 6), $v['price']); + $sheet->setCellValue('H' . ($k + 6), $v['cart_num']); + $sheet->setCellValue('I' . ($k + 6), $v['total_price']); + $sheet->setCellValue('J' . ($k + 6), $v['package']); + $sheet->setCellValue('K' . ($k + 6),$v['deposit']); + $sheet->setCellValue('L' . ($k + 6),$v['after_sales']); + $sheet->setCellValue('M' . ($k + 6),$v['loss']); + $sheet->mergeCells('O'.($k + 6).':P'.($k + 6)); + $sheet->setCellValue('O' . ($k + 6),$v['mark']); + + } + + $count = count($data); + $sheet->setCellValue('A' . ($count + 6),'合计'); + $sheet->setCellValue('C' . ($count + 6),$count); + $sheet->setCellValue('I' . ($count + 6),$order['total_price']); + $sheet->setCellValue('K' . ($count + 6),$order['deposit']); + + $sheet->setCellValue('A' . ($count + 7),'累计'); + $sheet->setCellValue('B' . ($count + 7),$count); + + $sheet->setCellValue('C' . ($count + 7),'采购预收金额'); + $sheet->setCellValue('D' . ($count + 7),$order['total_price'].'元'); + $sheet->setCellValue('G' . ($count + 7),'押金'); + $sheet->setCellValue('H' . ($count + 7),$order['deposit'].'元'); + $sheet->setCellValue('I' . ($count + 7),'合计预收'); + $sheet->setCellValue('J' . ($count + 7),bcadd($order['deposit'],$order['total_price']).'元'); + $sheet->setCellValue('L' . ($count + 7),'接单员'); + $sheet->setCellValue('M' . ($count + 7),$order['admin_name']); + $sheet->setCellValue('O' . ($count + 7),'分单员'); + $sheet->setCellValue('P' . ($count + 7),$other_data->splitting_officer??''); + + $sheet->mergeCells('A' . ($count + 8) . ':P' . $count + 8); + + $sheet->setCellValue('A' . $count + 8, '备注:数量金额最终以实际收货金额结算,多退少补。押金退框无利息退还。',); + + + // 设置单元格的样式 + $styleArray = [ + 'font' => [ + 'bold' => true, + 'size' => 28, + ], + ]; + $sheet->getStyle('A1')->applyFromArray($styleArray); + // 定义线框样式 + $styleArray = [ + 'borders' => [ + 'allBorders' => [ + 'borderStyle' => Border::BORDER_THIN, // 线框样式 + 'color' => ['argb' => '000000'], // 线框颜色 + ], + ], + ]; + $sheet->getStyle('A1:P' . ($count + 8))->applyFromArray($styleArray); + + // 保存文件到 public 下 + + $writer = new Xlsx($spreadsheet); + $url = '/export/' . date('Y-m') . '/' .'供投里海农特产品下单清单-'.date('Y-m-d H:i') . '.xlsx'; + $file_path = public_path() . $url; + // 保存文件到 public 下 + $writer->save($file_path); + return getenv('APP_URL').$url; + } +} diff --git a/app/common/service/xlsx/OrderOutbound.php b/app/common/service/xlsx/OrderOutbound.php new file mode 100644 index 00000000..31f583fe --- /dev/null +++ b/app/common/service/xlsx/OrderOutbound.php @@ -0,0 +1,126 @@ +getActiveSheet(); + // 合并单元格A1到K1 + $sheet->mergeCells('A1:I1'); + $sheet->mergeCells('D2:E2'); + $sheet->mergeCells('H2:I2'); + $sheet->mergeCells('G2:I2'); + + + $sheet->mergeCells('H3:I3'); + + $sheet->setCellValue('A1', '供 投 里 海 农 特 产 品 出 库 结 算 单'); + $sheet->setCellValue('A2', '姓名:'); + $sheet->setCellValue('B2', $other_data->nickname); + $sheet->getColumnDimension('B')->setWidth(16); + $sheet->getColumnDimension('H')->setAutoSize(true); + + $sheet->setCellValue('C2', '电话:'); + $sheet->setCellValue('D2', $other_data->phone); + $sheet->setCellValue('F2', '订单编号:'); + $sheet->setCellValue('G2', $order['order_id']??''); + + $sheet->setCellValue('A3', '编号'); + $sheet->setCellValue('B3', '品名'); + $sheet->setCellValue('C3', '型号'); + $sheet->setCellValue('D3', '单位'); + $sheet->setCellValue('E3', '净重(约)'); + $sheet->setCellValue('F3', '单价'); + $sheet->setCellValue('G3', '金额'); + $sheet->setCellValue('H3', '备注'); + + // 设置默认的单元格样式 + $defaultStyle = [ + 'alignment' => [ + 'horizontal' => Alignment::HORIZONTAL_CENTER, + 'vertical' => Alignment::VERTICAL_CENTER, + ], + ]; + + // 应用默认样式到整个工作表 + $spreadsheet->getDefaultStyle()->applyFromArray($defaultStyle); + + foreach ($data as $k => $v) { + $sheet->setCellValue('A' . ($k + 4), $v['product_id']); + $sheet->setCellValue('B' . ($k + 4), $v['store_name']); + $sheet->setCellValue('C' . ($k + 4), $v['marques']); + $sheet->setCellValue('D' . ($k + 4), $v['unit_name']); + $sheet->setCellValue('E' . ($k + 4), $v['gross_weight']); + $sheet->setCellValue('F' . ($k + 4), $v['price']); + $sheet->setCellValue('G' . ($k + 4), $v['pay_price']); + $sheet->mergeCells('H' . ($k + 4) . ':I' . $k + 4); + $sheet->setCellValue('H' . ($k + 4), $v['mark']); + } + + $count = count($data); + $sheet->setCellValue('A' . ($count + 4),'合计'); + $sheet->setCellValue('B' . ($count + 4),$count); + + $sheet->setCellValue('A' . ($count + 5),'累计接单:'); + $sheet->setCellValue('C' . ($count + 5),'预收金额:'); + $sheet->setCellValue('E' . ($count + 5),'预收押金:'); + $sheet->setCellValue('G' . ($count + 5),'合计预收:'); + + $sheet->setCellValue('A' . ($count + 6),'出库合计:'); + $sheet->setCellValue('C' . ($count + 6),'出库金额:'); + $sheet->setCellValue('E' . ($count + 6),'实收押金:'); + $sheet->setCellValue('G' . ($count + 6),'合计:'); + + $sheet->setCellValue('A' . ($count + 7),'应收:'); + $sheet->setCellValue('C' . ($count + 7),'应退:'); + + $sheet->mergeCells('B' . ($count + 8) . ':I' . $count + 8); + $sheet->setCellValue('A'. ($count + 8), '收货地址:'); + $sheet->setCellValue('B'. ($count + 8), $other_data->address); + + $sheet->mergeCells('B' . ($count + 9) . ':E' . $count + 9); + $sheet->setCellValue('A' . $count + 9, '销售地址:',); + $sheet->setCellValue('B' . $count + 9, '泸州市海吉星农产品商贸物流园122栋',); + $sheet->setCellValue('F' . $count + 9, '电话:',); + $sheet->setCellValue('G' . $count + 9, '08302669767',); + $sheet->setCellValue('H' . $count + 9, '签收:',); + // 设置单元格的样式 + $styleArray = [ + 'font' => [ + 'bold' => true, + 'size' => 16, + ], + ]; + $sheet->getStyle('A1')->applyFromArray($styleArray); + // 定义线框样式 + $styleArray = [ + 'borders' => [ + 'allBorders' => [ + 'borderStyle' => Border::BORDER_THIN, // 线框样式 + 'color' => ['argb' => '000000'], // 线框颜色 + ], + ], + ]; + $sheet->getStyle('A1:I' . ($count + 9))->applyFromArray($styleArray); + + // 保存文件到 public 下 + + $writer = new Xlsx($spreadsheet); + $url = '/export/' . date('Y-m') . '/' .'供投里海农特产品出库结算单-'.date('Y-m-d H:i') . '.xlsx'; + $file_path = public_path() . $url; + // 保存文件到 public 下 + $writer->save($file_path); + return getenv('APP_URL').$url; + } +}