文件
mashangyoujiu/Application/Retail/Controller/ShipmentdetailController.class.php

283 行
12 KiB
PHP
可执行文件

<?php
namespace Retail\Controller;
use Think\Controller;
//[1.1.51]
class ShipmentdetailController extends BaseController{
public function index()
{
$merchantid = session("ls_userinfo")['merchantid'];
$store_info = M('retail_store')->where(array('state'=>0,'merchantid'=>$merchantid))->select();
$class_name = M('retail_goods_class')->where(array('merchantid' => $merchantid, 'status' => 0, 'type' => 1))->order('code asc')->select();
$this->assign('class_name', $class_name);
$this->assign('store_info',$store_info);
$this->display();
}
public function shipment_list()
{
$user = session("ls_userinfo");
$merchantid = $user['merchantid'];
$p = I('get.page');
$l = I('get.limit');
$date = I('get.date');
$good_number = I('get.good_number');
$allocation_state = I('get.allocation_state');
$store_id = I('get.store_id');
$person1 = I('get.person1');
$person2 = I('get.person2');
$person3 = I('get.person3');
if(!empty($date)){
$time = explode('至',$date);
$start_time = strtotime(date('Y-m-d 00:00:00',strtotime($time[0])));
$end_time = strtotime(date('Y-m-d 23:59:59',strtotime($time[1])));
$where['a.addtime'] = array('between',array($start_time,$end_time));
}
if(!empty($store_id)){
$where['a.storeid'] = $store_id;
}
if(!empty($allocation_state)){
$where['a.type'] = $allocation_state;
}
$flag = 0;
if(!empty($good_number)){
$where['a.goods_name|a.good_number|a.goods_code|a.sku_code|a.ordernum'] = array('like','%'.$good_number.'%');
}
if(!empty($person3)){
$where['a.goods_class_id'] = $person3;
}else if(!empty($person2)){
$class = M('retail_goods_class as c2')
->join('ls_retail_goods_class as c3 on c2.id=c3.pid')
->where(array('c2.id' => $person2, 'c3.status' => 0))
->field('c3.id')->select();
$flag = 1;
}else if(!empty($person1)){
$class = M('retail_goods_class as c1')
->join('ls_retail_goods_class as c2 on c1.id=c2.pid')
->join('ls_retail_goods_class as c3 on c2.id=c3.pid AND c3.status=0', 'LEFT')
->where(array('c1.id' => $person1, 'c2.status' => 0))
->field('c2.id,c3.id as c3_id')->select();
$flag = 1;
}
if (!empty($class)) {
$arr = array();
foreach ($class as &$val) {
if (!in_array($val['id'], $arr)) {
$arr[] = $val['id'];
}
if (!empty($val['c3_id'])) {
if (!in_array($val['c3_id'], $arr)) {
$arr[] = $val['c3_id'];
}
}
}
$str = implode(',', $arr);
$where['a.goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
} else if ($flag == 1) {
$where['a.goods_class_id'] = $person2 ? $person2 : $person1;
}
$where['a.merchantid'] = $merchantid;
$shipment_info = M('retail_purchase_store_goods_detail as a')
->join("ls_retail_store as s on a.storeid=s.id","LEFT")
->where($where)
->field("a.*,s.storetag")
->order('id desc')
->page($p,$l)
->select();
$count = M('retail_purchase_store_goods_detail as a')
->join("ls_retail_store as s on a.storeid=s.id","LEFT")
->where($where)
->count();
if($shipment_info){
foreach ($shipment_info as $key=>&$val){
$val['index'] = $key + 1;
if($val['can_exchange_weigh'] == 1){
$val['weigh_name'] = '不称重';
}else if($val['can_exchange_weigh'] == 2){
$val['weigh_name'] = '称重';
}
$val['addtime'] = date('Y-m-d H:i:s',$val['addtime']);
if($val['attribute'] == 2){
$sku_name = '';
$sku_list_ids = explode(',',$val['sku_id_list']);
foreach ($sku_list_ids as $skukey=>&$skuval){
$sku_name .= M('retail_sku_list')->where(array('id' => $skuval))->getField('name').',';
}
$val['goods_name'] = $val['goods_name'].','.$sku_name;
$val['goods_code'] = $val['sku_code'];
}
if($val['type'] == 1){
$val['shipment_name'] = '商户调拨';
}else if($val['type'] == 2){
$val['shipment_name'] = '门店申请调拨';
}else if($val['type'] == 3){
$val['shipment_name'] = '报损';
}else if($val['type'] == 4){
$val['shipment_name'] = '盘点减少';
}
}
}
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $shipment_info;
$res['count'] = $count;
$this->ajaxReturn($res);
}
//出库导出
public function shipment_list_export()
{
$user = session("ls_userinfo");
$merchantid = $user['merchantid'];
$date = I('get.date');
$good_number = I('get.good_number');
$allocation_state = I('get.allocation_state');
$store_id = I('get.store_id');
$person1 = I('get.person1');
$person2 = I('get.person2');
$person3 = I('get.person3');
if(!empty($date)){
$time = explode('至',$date);
$start_time = strtotime(date('Y-m-d 00:00:00',strtotime($time[0])));
$end_time = strtotime(date('Y-m-d 23:59:59',strtotime($time[1])));
$where['a.addtime'] = array('between',array($start_time,$end_time));
}else{
$time = time();
$start_time = strtotime(date('Y-m-d 00:00:00',$time));
$end_time = $start_time + 86399;
$where['a.addtime'] = array('between',array($start_time,$end_time));
}
if(!empty($store_id)){
$where['a.storeid'] = $store_id;
}
if(!empty($allocation_state)){
$where['a.type'] = $allocation_state;
}
$flag = 0;
if(!empty($good_number)){
$where['a.goods_name|a.good_number|a.goods_code|a.sku_code|a.ordernum'] = array('like','%'.$good_number.'%');
}
if(!empty($person3)){
$where['a.goods_class_id'] = $person3;
}else if(!empty($person2)){
$class = M('retail_goods_class as c2')
->join('ls_retail_goods_class as c3 on c2.id=c3.pid')
->where(array('c2.id' => $person2, 'c3.status' => 0))
->field('c3.id')->select();
$flag = 1;
}else if(!empty($person1)){
$class = M('retail_goods_class as c1')
->join('ls_retail_goods_class as c2 on c1.id=c2.pid')
->join('ls_retail_goods_class as c3 on c2.id=c3.pid AND c3.status=0', 'LEFT')
->where(array('c1.id' => $person1, 'c2.status' => 0))
->field('c2.id,c3.id as c3_id')->select();
$flag = 1;
}
if (!empty($class)) {
$arr = array();
foreach ($class as &$val) {
if (!in_array($val['id'], $arr)) {
$arr[] = $val['id'];
}
if (!empty($val['c3_id'])) {
if (!in_array($val['c3_id'], $arr)) {
$arr[] = $val['c3_id'];
}
}
}
$str = implode(',', $arr);
$where['a.goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
} else if ($flag == 1) {
$where['a.goods_class_id'] = $person2 ? $person2 : $person1;
}
$where['a.merchantid'] = $merchantid;
$shipment_info = M('retail_purchase_store_goods_detail as a')
->join("ls_retail_store as s on a.storeid=s.id","LEFT")
->where($where)
->field("a.*,s.storetag")
->order('id desc')
->select();
if($shipment_info){
foreach ($shipment_info as $key=>&$val){
$val['index'] = $key + 1;
if($val['can_exchange_weigh'] == 1){
$val['weigh_name'] = '不称重';
}else if($val['can_exchange_weigh'] == 2){
$val['weigh_name'] = '称重';
}
$val['addtime'] = date('Y-m-d H:i:s',$val['addtime']);
if($val['attribute'] == 2){
$sku_name = '';
$sku_list_ids = explode(',',$val['sku_id_list']);
foreach ($sku_list_ids as $skukey=>&$skuval){
$sku_name .= M('retail_sku_list')->where(array('id' => $skuval))->getField('name').',';
}
$val['goods_name'] = $val['goods_name'].','.$sku_name;
$val['goods_code'] = $val['sku_code'];
}
if($val['type'] == 1){
$val['shipment_name'] = '商户调拨';
}else if($val['type'] == 2){
$val['shipment_name'] = '门店申请调拨';
}else if($val['type'] == 3){
$val['shipment_name'] = '报损';
}else if($val['type'] == 4){
$val['shipment_name'] = '盘点减少';
}
}
}
$filename = '出库明细';
$headArr = array(
array('index','序号'),
array('ordernum','订单号'),
array('goods_name','商品名称'),
array('weigh_name','是否称重'),
array('good_number','商品货号'),
array('goods_code','条码'),
array('sku_num','单件对应库存'),
array('shipment_num','出货量'),
array('average_purch_price','成本价'),
array('purch_price','出货价'),
array('storetag','门店名称'),
array('shipment_name','出货方式'),
array('addtime','出货时间'),
);
$str = $filename.'导出时间'.date('Y-m-d',time());
$this->getExcel($filename,$headArr,$shipment_info,$str);
}
//$expTitle 文件名 $expCellName 二维数组字段名称 $expTableData 二维数组
private function getExcel($expTitle,$expCellName,$expTableData,$str=""){
$xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
$fileName = $expTitle.date('_YmdHis');//or $xlsTitle 文件名称可根据自己情况设定
$cellNum = count($expCellName);
$dataNum = count($expTableData);
$common = $str;
vendor("PHPExcel.PHPExcel");
ob_clean();
$objPHPExcel = new \PHPExcel();
$cellName = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ');
$objPHPExcel->getActiveSheet(0)->mergeCells('A1:'.$cellName[$cellNum-1].'1');//合并单元格
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1',$common);
// $objPHPExcel->setActiveSheetIndex(1)->setCellValue('A1', $str);
for($i=0;$i<$cellNum;$i++){
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i].'2', $expCellName[$i][1]);
}
for($i=0;$i<$dataNum;$i++){
for($j=0;$j<$cellNum;$j++){
$objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+3), ' '.$expTableData[$i][$expCellName[$j][0]]);
}
}
foreach ($cellName as $value) {
$objPHPExcel->getActiveSheet()->getColumnDimension($value)->setWidth(20);
}
header('pragma:public');
header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$xlsTitle.'.xls"');
header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit();
}
}