123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502 |
- <?php
- namespace Factory\Admin;
- use Dever;
- class Excel extends Core
- {
- public function out($id, $user, $data)
- {
- if (!$data) {
- Dever::alert('无导出数据');
- }
- $info = Dever::db('factory/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_2($file, $user, $data, $file);
- }
- # 九阳模板
- public function out_2($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']);
- if (isset($address['contact']) && $address['contact']) {
- $v['type_info']['name'] = $address['contact'];
- } else {
- $v['type_info']['name'] = '';
- }
-
- $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);
- }
- # 纯米模板
- public function out_3($file, $user, $data)
- {
- $header = array();
- $header_0 = array('序号', '申请人', '发货日期', '客户名称', '品名', '单位', '数量', '订单号', '收件人', '收件电话', '收件邮寄地址', '备注');
- $header_1 = array('商品条码(必填)', '商品名称', '申请数量(必填)', '配销价(元)');
- $file = '纯米发货信息表';
- $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 = '-';
- }
- 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']['truename'] = $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']['truename'] = $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']['truename'] = $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']['truename'] = $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,
- $user['name'],
- $ps_date,
- '中食民安(北京)',
- $v2['name'],
- $v2['unit'],
- $v2['num'] * $v1['num'],
- $v['order_num'],
- $v['type_info']['truename'],
- $v['type_info']['mobile'],
- $v['type_info']['address'],
- $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,
- $user['name'],
- $ps_date,
- '中食民安(北京)',
- $goods_info['name'] . ' ' . $sku,
- $goods_info['unit'],
- $v1['num'],
- $v['order_num'],
- $v['type_info']['truename'],
- $v['type_info']['mobile'],
- $v['type_info']['address'],
- $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);
- }
- # 安鲜达模板
- public function out_4($file, $user, $data, $name = '')
- {
- $file = $name ? $name : '安鲜达发货信息表';
- $body_0 = $body_1 = $body_2 = array();
- $type = Dever::input('type');
- $parent_type = Dever::input('parent_type');
- $source_type = Dever::input('source_type');
- $header_0 = array('客户订单编号', '收件人姓名', '收件人手机', '收件省份(直辖市)', '收件市(州)', '收件区(县,县级市)', '收件详细地址', '收件人备注', '订单备注', '相关单号', '订单来源');
- $header_1 = array('客户订单编号', '客户货品编码', '销售平台货品编码', '数量', '备注');
- $header_2 = 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']);
- if ($info) {
- $v['type_info']['county_name'] = $info['name'];
- } else {
- $v['type_info']['county_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'] * $v1['num'],
- '',
- );
- $body_2[] = array
- (
- $v2['code'],
- $v2['name'],
- $v2['num'] * $v1['num'],
- round($v2['price'] * $v1['num'], 2),
- );
- }
- } else {
- $body_1[] = array
- (
- $v['order_num'],
- $goods_info['code'],
- $goods_info['name'] . ' ' . $sku,
- $v1['num'],
- '',
- );
- $body_2[] = array
- (
- $goods_info['code'],
- $goods_info['name'],
- $v1['num'],
- $v1['price'],
- );
- }
- }
- }
- $xls = Dever::excelExport($body_0, $header_0, $file, 0, '订单主信息', true);
- if ($xls) {
- $xls = Dever::excelExport($body_1, $header_1, $file, 1, '订单货品明细', true, $xls);
- return Dever::excelExport($body_2, $header_2, $file, 2, '要货模板', false, $xls);
- }
- }
- }
|