123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558 |
- <?php
- namespace Store\Admin;
- use Dever;
- class Excel extends Core
- {
- public function out($id, $user, $data)
- {
- if (!$data) {
- Dever::alert('无导出数据');
- }
- $info = Dever::db('store/info')->find($id);
- if (!$info) {
- Dever::alert('操作失败');
- }
- $method = 'out_' . $info['out_template'];
- $file = '发货信息表';
- return $this->$method($file, $user, $data);
- }
- # 模板模板
- public function out_1($file, $user, $data)
- {
- $this->out_3($file, $user, $data, $file);
- }
- # 安鲜达模板
- public function out_2($file, $user, $data, $name = '')
- {
- $file = $name ? $name : '安鲜达发货信息表';
- $body_0 = $body_1 = array();
- $type = Dever::input('type');
- $parent_type = Dever::input('parent_type');
- $source_type = Dever::input('source_type');
- if ($type == 1 && $parent_type != 1) {
- $file .= '-平台商城订单';
- $header_0 = array('客户订单编号', '收件人姓名', '收件人手机', '收件省份(直辖市)', '收件市(州)', '收件区(县,县级市)', '收件详细地址', '收件人备注', '订单备注', '相关单号', '订单来源');
- $header_1 = array('客户订单编号', '客户货品编码', '销售平台货品编码', '数量', '备注');
- foreach ($data as $k => $v) {
- if (!is_array($v)) {
- continue;
- }
- Dever::load('mshop/lib/buy')->setOutStatus($v['id'], 2);
- if ($v['ps_info'] && $v['ps_info']['cdate_day']) {
- $ps_date = $v['ps_info']['cdate_day'];
- } else {
- $ps_date = '-';
- }
- if ($v['parent_type'] == 2) {
- $parent_order = Dever::db('shop/sell_order')->find($v['parent_order_id']);
- if ($parent_order && $parent_order['uid']) {
- if ($parent_order['address_id']) {
- $address = Dever::load('passport/address')->getOne($parent_order['uid'], $parent_order['address_id']);
- $v['type_info']['name'] = $address['contact'];
- $v['type_info']['mobile'] = $address['mobile'];
- $v['type_info']['address'] = $address['address_info'];
- $v['type_info']['province_name'] = $address['province_name'];
- $v['type_info']['city_name'] = $address['city_name'];
- $v['type_info']['county_name'] = $address['county_name'];
- } else {
- $address = Dever::db('passport/user')->find($parent_order['uid']);
- $v['type_info']['name'] = $address['username'];
- $v['type_info']['mobile'] = $address['mobile'];
- $v['type_info']['address'] = '';
- $v['type_info']['province_name'] = $v['type_info']['city_name'] = $v['type_info']['county_name'] = '';
- }
- }
- } elseif ($v['parent_type'] == 3) {
- $parent_order = Dever::db('agent/dh_order')->find($v['parent_order_id']);
- if ($parent_order && $parent_order['mid']) {
- if ($parent_order['address_id']) {
- $address = Dever::load('agent/address')->getOne($parent_order['mid'], $parent_order['address_id']);
- $v['type_info']['name'] = $address['contact'];
- $v['type_info']['mobile'] = $address['mobile'];
- $v['type_info']['address'] = $address['address_info'];
- $v['type_info']['province_name'] = $address['province_name'];
- $v['type_info']['city_name'] = $address['city_name'];
- $v['type_info']['county_name'] = $address['county_name'];
- } else {
- $address = Dever::db('agent/member')->find($parent_order['mid']);
- $v['type_info']['name'] = $address['name'];
- $v['type_info']['mobile'] = $address['mobile'];
- $v['type_info']['address'] = '';
- $v['type_info']['province_name'] = $v['type_info']['city_name'] = $v['type_info']['county_name'] = '';
- }
- }
- } else {
- $info = Dever::db('area/province')->find($v['type_info']['province']);
- $v['type_info']['province_name'] = $info['name'];
- $info = Dever::db('area/city')->find($v['type_info']['city']);
- $v['type_info']['city_name'] = $info['name'];
- $info = Dever::db('area/county')->find($v['type_info']['county']);
- $v['type_info']['county_name'] = $info['name'];
- }
- $body_0[] = array
- (
- $v['order_num'],
- $v['type_info']['name'],
- $v['type_info']['mobile'],
- $v['type_info']['province_name'],
- $v['type_info']['city_name'],
- $v['type_info']['county_name'],
- $v['type_info']['address'],
- '',
- $v['info'],
- '',
- '',
- );
- foreach ($v['goods'] as $k1 => $v1) {
- $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
- if (isset($goods_info['sku'])) {
- $sku = $goods_info['sku']['string'];
- } else {
- $sku = '';
- }
- if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
-
- foreach ($goods_info['goods'] as $v2) {
- $p = $v2['price'];
- if (is_numeric($v2['num']) && is_numeric($v2['price'])) {
- $p = $v2['price']*$v2['num'];
- }
- $body_1[] = array
- (
- $v['order_num'],
- $v2['code'],
- $v2['name'],
- $v2['num'],
- '',
- );
- }
- } else {
- $body_1[] = array
- (
- $v['order_num'],
- $goods_info['code'],
- $goods_info['name'] . ' ' . $sku,
- $v1['num'],
- '',
- );
- }
- }
- }
- $xls = Dever::excelExport($body_0, $header_0, $file, 0, '订单主信息', true);
- if ($xls) {
- return Dever::excelExport($body_1, $header_1, $file, 1, '订单货品明细', false, $xls);
- }
- } else {
-
- $header_0 = array('客户出库单号', '业务单据类型', '预计出库时间', '备注', '门店名称', '收件人', '收件人手机', '收件人电话', '收件人省份', '收件人城市', '收件人区县', '收件人详细地址');
- $header_1 = array('客户出库单号', '货品编码', '应出数量', '库存类型', '批次号');
- if ($type == 2 && $source_type == 2) {
- $file .= '-仓库调拨订单';
- $header_0[4] = '仓库名称';
- } else {
- $file .= '-门店订单';
- }
- foreach ($data as $k => $v) {
- if (!is_array($v)) {
- continue;
- }
- Dever::load('mshop/lib/buy')->setOutStatus($v['id'], 2);
- if ($v['ps_info'] && $v['ps_info']['cdate_day']) {
- $ps_date = $v['ps_info']['cdate_day'];
- } else {
- $ps_date = '-';
- }
- $info = Dever::db('area/province')->find($v['type_info']['province']);
- $v['type_info']['province_name'] = $info['name'];
- $info = Dever::db('area/city')->find($v['type_info']['city']);
- $v['type_info']['city_name'] = $info['name'];
- $v['type_info']['county_name'] = '';
- if (isset($v['type_info']['county']) && $v['type_info']['county']) {
- $info = Dever::db('area/county')->find($v['type_info']['county']);
- if ($info) {
- $v['type_info']['county_name'] = $info['name'];
- }
-
- }
- $body_0[] = array
- (
- $v['order_num'],
- '出库单',
- $ps_date,
- $v['info'],
- $v['type_info']['name'],
- $v['type_info']['truename'],
- $v['type_info']['mobile'],
- $v['type_info']['mobile'],
- $v['type_info']['province_name'],
- $v['type_info']['city_name'],
- $v['type_info']['county_name'],
- $v['type_info']['address'],
- );
- foreach ($v['goods'] as $k1 => $v1) {
- $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
- if (isset($goods_info['sku'])) {
- $sku = $goods_info['sku']['string'];
- } else {
- $sku = '';
- }
- if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
-
- foreach ($goods_info['goods'] as $v2) {
- $p = $v2['price'];
- if (is_numeric($v2['num']) && is_numeric($v2['price'])) {
- $p = $v2['price']*$v2['num'];
- }
- $body_1[] = array
- (
- $v['order_num'],
- $v2['code'],
- $v2['num'],
- '',
- '',
- );
- }
- } else {
- $body_1[] = array
- (
- $v['order_num'],
- $goods_info['code'],
- $v1['num'],
- '',
- '',
- );
- }
- }
- }
- $xls = Dever::excelExport($body_0, $header_0, $file, 0, '出库单主表', true);
- if ($xls) {
- return Dever::excelExport($body_1, $header_1, $file, 1, '出库单明细', false, $xls);
- }
- }
- }
- # 大连模板
- public function out_3($file, $user, $data, $name = '')
- {
- $header = array();
- $header = array('所属客户', '所属仓库', '出库时间', '收货人编码', '包装箱数', '备注', '货位编码', '商品编码', '计量单位', '批号', '数量', '明细备注');
- $file = $name ? $name : '大连仓发货信息表';
- $body = array();
- $i = 1;
- foreach ($data as $k => $v) {
- if (!is_array($v)) {
- continue;
- }
- Dever::load('mshop/lib/buy')->setOutStatus($v['id'], 2);
- if ($v['ps_info'] && $v['ps_info']['cdate_day']) {
- $ps_date = $v['ps_info']['cdate_day'];
- } else {
- $ps_date = '-';
- }
- if ($v['parent_type'] == 2) {
- $parent_order = Dever::db('shop/sell_order')->find($v['parent_order_id']);
- if ($parent_order && $parent_order['uid']) {
- if ($parent_order['address_id']) {
- $address = Dever::load('passport/address')->getOne($parent_order['uid'], $parent_order['address_id']);
- $v['type_info']['name'] = $address['contact'];
- $v['type_info']['mobile'] = $address['mobile'];
- $v['type_info']['address'] = $address['address_info'];
- } else {
- $address = Dever::db('passport/user')->find($parent_order['uid']);
- $v['type_info']['name'] = $address['username'];
- $v['type_info']['mobile'] = $address['mobile'];
- $v['type_info']['address'] = '';
- }
- }
- } elseif ($v['parent_type'] == 3) {
- $parent_order = Dever::db('agent/dh_order')->find($v['parent_order_id']);
- if ($parent_order && $parent_order['mid']) {
- if ($parent_order['address_id']) {
- $address = Dever::load('agent/address')->getOne($parent_order['mid'], $parent_order['address_id']);
- $v['type_info']['name'] = $address['contact'];
- $v['type_info']['mobile'] = $address['mobile'];
- $v['type_info']['address'] = $address['address_info'];
- } else {
- $address = Dever::db('agent/member')->find($parent_order['mid']);
- $v['type_info']['name'] = $address['name'];
- $v['type_info']['mobile'] = $address['mobile'];
- $v['type_info']['address'] = '';
- }
- }
- }
- if (!isset($v['type_info']['sid'])) {
- $v['type_info']['sid'] = '';
- }
-
- foreach ($v['goods'] as $k1 => $v1) {
- $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
- if (isset($goods_info['sku'])) {
- $sku = $goods_info['sku']['string'];
- } else {
- $sku = '';
- }
- if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
-
- foreach ($goods_info['goods'] as $v2) {
- $p = $v2['price'];
- if (is_numeric($v2['num']) && is_numeric($v2['price'])) {
- $p = $v2['price']*$v2['num'];
- }
- $d = array
- (
- '简单生活(中食)有限公司',
- $v['type_info']['name'],
- $ps_date,
- $v['type_info']['sid'],
- '',
- $v['info'],
- '',
- $v2['code'],
- $v2['unit'],
- '',
- $v2['num'],
- $v2['name'],
-
- );
- $body[] = $d;
- }
- } else {
- $d = array
- (
- '简单生活(中食)有限公司',
- $v['type_info']['name'],
- $ps_date,
- $v['type_info']['sid'],
- '',
- $v['info'],
- '',
- $goods_info['code'],
- $goods_info['unit'],
- '',
- $v1['num'],
- $goods_info['name'] . ' ' . $sku,
-
- );
- $body[] = $d;
- }
- $i++;
- }
- }
- return Dever::excelExport($body, $header, $file);
- }
- # 九阳模板
- public function out_4($file, $user, $data, $name = '')
- {
- $header = array();
- $header_0 = array('序号', '申请发货时间', '申请人', '产品名称', '数量', '订单号', '收件人姓名', '收件人电话', '收件地址', '发货时间', '发件物流', '运单编号', '备注');
- $header_1 = array('商品条码(必填)', '商品名称', '申请数量(必填)', '配销价(元)');
- $file = $name ? $name : '中食民安&九阳发货信息表';
- $body_0 = $body_1 = array();
- $i = 1;
- foreach ($data as $k => $v) {
- if (!is_array($v)) {
- continue;
- }
- Dever::load('mshop/lib/buy')->setOutStatus($v['id'], 2);
- if ($v['ps_info'] && $v['ps_info']['cdate_day']) {
- $ps_date = $v['ps_info']['cdate_day'];
- } else {
- $ps_date = '-';
- }
- $service_name = array();
- $service_num = array();
- if (isset($v['ps_info']['service']) && $v['ps_info']['service']) {
- foreach ($v['ps_info']['service'] as $k1 => $v1) {
- $service_name[] = $v1['service_name'];
- $service_num[] = $v1['order_num'];
- }
- }
- $service_name = implode(',', $service_name);
- $service_num = implode(',', $service_num);
- if ($v['parent_type'] == 2) {
- $parent_order = Dever::db('shop/sell_order')->find($v['parent_order_id']);
- if ($parent_order && $parent_order['uid']) {
- if ($parent_order['address_id']) {
- $address = Dever::load('passport/address')->getOne($parent_order['uid'], $parent_order['address_id']);
- $v['type_info']['name'] = $address['contact'];
- $v['type_info']['mobile'] = $address['mobile'];
- $v['type_info']['address'] = $address['address_info'];
- } else {
- $address = Dever::db('passport/user')->find($parent_order['uid']);
- $v['type_info']['name'] = $address['username'];
- $v['type_info']['mobile'] = $address['mobile'];
- $v['type_info']['address'] = '';
- }
- }
- } elseif ($v['parent_type'] == 3) {
- $parent_order = Dever::db('agent/dh_order')->find($v['parent_order_id']);
- if ($parent_order && $parent_order['mid']) {
- if ($parent_order['address_id']) {
- $address = Dever::load('agent/address')->getOne($parent_order['mid'], $parent_order['address_id']);
- $v['type_info']['name'] = $address['contact'];
- $v['type_info']['mobile'] = $address['mobile'];
- $v['type_info']['address'] = $address['address_info'];
- } else {
- $address = Dever::db('agent/member')->find($parent_order['mid']);
- $v['type_info']['name'] = $address['name'];
- $v['type_info']['mobile'] = $address['mobile'];
- $v['type_info']['address'] = '';
- }
- }
- }
- foreach ($v['goods'] as $k1 => $v1) {
- $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
- if (isset($goods_info['sku'])) {
- $sku = $goods_info['sku']['string'];
- } else {
- $sku = '';
- }
- if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
-
- foreach ($goods_info['goods'] as $v2) {
- $p = $v2['price'];
- if (is_numeric($v2['num']) && is_numeric($v2['price'])) {
- $p = $v2['price']*$v2['num'];
- }
- $body_0[] = array
- (
- $i,
- $v['operdate_day'],
- $user['name'],
- $v2['name'],
- $v2['num'] * $v1['num'],
- $v['order_num'],
- $v['type_info']['name'],
- $v['type_info']['mobile'],
- $v['type_info']['address'],
- $ps_date,
- $service_name,
- $service_num,
- $v['info'],
-
- );
- $body_1[] = array
- (
- $v2['code'],
- $v2['name'],
- $v2['num'] * $v1['num'],
- round($v2['price'] * $v1['num'], 2),
- );
- // $body[] = $d;
- }
- } else {
- $body_0[] = array
- (
- $i,
- $v['operdate_day'],
- $user['name'],
- $goods_info['name'] . ' ' . $sku,
- $v1['num'],
- $v['order_num'],
- $v['type_info']['name'],
- $v['type_info']['mobile'],
- $v['type_info']['address'],
- $ps_date,
- $service_name,
- $service_num,
- $v['info'],
-
- );
- $body_1[] = array
- (
- $goods_info['code'],
- $goods_info['name'],
- $v1['num'],
- $v1['price'],
- );
- // $body[] = $d;
- }
- $i++;
- }
- }
- $xls = Dever::excelExport($body_0, $header_0, $file, 0, '发货主信息', true);
- if($xls){
- return Dever::excelExport($body_1, $header_1, $file, 1 , '要货模板', false, $xls);
- }
- // return Dever::excelExport($body, $header, $file);
- }
- }
|