where(array('merchantid' => $merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select(); $this->assign('goodsClass1', json_encode($class_name)); } /* * 查询供货商与仓库 */ private function Info($merchant_id, $store_id) { $where['merchant_id'] = $merchant_id; $where['store_id'] = $store_id; $where['status'] = 1; $supplier = D('SSupplier')->getSelect($where, $page = '', $limit = '', "id,supplier_name"); $map['merchant_id'] = $merchant_id; $map['store_id'] = $store_id; $map['status'] = 1; $fields = "id,name"; $warehouse = D('SPurchaseWarehouse')->getSelect($map, $page = '', $limit = '', $fields, $order = 'default_state desc'); $this->assign('supplier', json_encode($supplier)); $this->assign('warehouse', json_encode($warehouse)); } public function index() { $arr = array( 'exportOperation' => '/index.php/Retail/SPurchaseGoods/export', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $user = session("ls_userinfo"); $store_id = session("storeid"); $this->Info($user['merchantid'], $store_id); $this->goodsClass($user['merchantid']); $this->assign('showPrice', self::$showPrice); $this->assign('identity', self::$identity); $this->assign("global_store_jurisdiction", self::$global_store_jurisdiction); $this->display(); } //采购串号信息 public function purchaseSerial() { $data = I('post.'); $data['user_type'] = 4; $data['type'] = 1; $SerialClass = new SerialNumberGoods(); $result = $SerialClass->purchaseDetailSerial($data); $this->ajaxReturn($result); } //采购退货串号信息 public function retreatSerial() { $data = I('post.'); $data['user_type'] = 4; $RetreatOrderClass = new RetreatOrder(); $result = $RetreatOrderClass->basisPurchaseOrderSerial($data); $this->ajaxReturn($result); } //入库的串号信息 public function warehouseSerial() { $data = I('post.'); $data['user_type'] = 4; $WarehousingClass = new WarehousingRecord(); $result = $WarehousingClass->basisOrderSerial($data); $this->ajaxReturn($result); } //商品列表 public function goodsList() { $data = I('post.'); $data['user_type'] = 4; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $data['showPrice'] = self::$showPrice; $data['identity'] = self::$identity; $PurchaseGoodsClass = new PurchaseGoodsInfo(); $result = $PurchaseGoodsClass->purchaseGoodsList($data); $this->ajaxReturn($result); } public function export() { $user = session("ls_userinfo"); $store_id = session("storeid"); $merchant_id = $user['merchantid']; $content = I("get."); $order_number = $content['order_number']; $supplier_id = $content['supplier_id']; $warehouse_id = $content['warehouse_id']; $add_time = $content['add_time']; $person1 = $content['person1']; $person2 = $content['person2']; $person3 = $content['person3']; if (!empty($order_number)) { $where['order_number|goods_number|sku_goods_number|goods_code|sku_code|goods_name|sku_name'] = array('like', '%' . $order_number . '%'); } if (!empty($supplier_id)) { $where['supplier_id'] = $supplier_id; } if (!empty($warehouse_id)) { $where['warehouse_id'] = $warehouse_id; } if (!empty($add_time)) { if (!is_array($add_time)) { $add_time = explode(',', $add_time); } $start_time = strtotime($add_time[0]); $end_time = strtotime($add_time[1]); $where['add_time'] = array('between', array($start_time, $end_time)); } $flag = 0; if (!empty($person3)) { $where['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['goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1)); } else if ($flag == 1) { $where['goods_class_id'] = $person2 ? $person2 : $person1; } $where['merchant_id'] = $merchant_id; $where['store_id'] = $store_id; $goodsList = D('SPurchaseGoods')->getSelect($where, $page = '', $limit = ''); if ($goodsList) { foreach ($goodsList as $key => &$val) { $val['index'] = $key + 1; if (!empty($val['build_date'])) { $val['build_date'] = date('Y-m-d', $val['build_date']); } $val['sku_num'] = strval(round($val['sku_num'], 3)); $val['class_name'] = M('retail_goods_class')->where(array('id' => $val['goods_class_id']))->getField("class_name"); $val['supplier_name'] = D('SSupplier')->getFindField(array('id' => $val['supplier_id']), "supplier_name"); $val['warehouse_name'] = D('SPurchaseWarehouse')->getFindField(array('id' => $val['warehouse_id']), "name"); $val['purchase_num'] = strval(round($val['purchase_num'], 3)); $val['warehousing_num'] = strval(round($val['warehousing_num'], 3)); $val['retreat_num'] = strval(round($val['retreat_num'], 3)); if (self::$showPrice == 2 && self::$identity == 2) { $val['purchase_price'] = "***"; $val['subtotal'] = "***"; } else { $val['purchase_price'] = strval(round($val['purchase_price'], 2)); $val['subtotal'] = strval(round($val['subtotal'], 2)); } if ($val['attribute_state'] == 2) { $val['goods_number'] = $val['sku_goods_number']; $val['goods_code'] = $val['sku_code']; } } } else { $goodsList = array(); } $fileds_name = "采购商品明细导出"; $arr = array( array('index', '序号'), array('class_name', '分类'), array('goods_name', '商品名称'), array('sku_name', '规格'), array('goods_number', '货号'), array('goods_code', '条码'), array('company', '单位'), array('build_date', '生产日期'), array('quality_guarantee_period', '保质期'), array('sku_num', '规格基数'), array('purchase_num', '采购数量'), array('warehousing_num', '入库数量'), array('retreat_num', '退货数量'), array('purchase_price', '金额'), array('subtotal', '小计'), array('supplier_name', '供货商'), array('warehouse_name', '仓库'), array('order_number', '批次号'), array('remarks', '备注'), ); $str = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time()); $this->getExcel($fileds_name, $arr, $goodsList, $str); } 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(); } }