|
@@ -9,6 +9,7 @@ class Commodity extends Start_Controller {
|
|
|
$this->load->_model('Model_apismt','apismt');
|
|
|
$this->load->_model('Model_typeclass','typeclass');
|
|
|
$this->load->_model('Model_commodityread_del','commodityreaddel');
|
|
|
+ $this->load->_model('Model_classid','classid');
|
|
|
}
|
|
|
//定义方法的调用规则 获取URI第二段值
|
|
|
public function _remap($arg,$arg_array)
|
|
@@ -29,6 +30,9 @@ class Commodity extends Start_Controller {
|
|
|
{
|
|
|
$this->_skuedit($arg_array);
|
|
|
}
|
|
|
+ else if($arg == 'excel_export'){
|
|
|
+ $this->_excel_export();
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
$this->_index();
|
|
@@ -622,4 +626,148 @@ class Commodity extends Start_Controller {
|
|
|
echo 2;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public function _excel_export(){
|
|
|
+ if(isset($_SESSION['api']))
|
|
|
+ {
|
|
|
+ $user = $this->user->get_api($_SESSION['api']);
|
|
|
+ $usp = $user;
|
|
|
+ $fgshop = "";$sid = "";
|
|
|
+ $usersp = explode('|',trim($user['shop'],'|'));
|
|
|
+ foreach ($usersp as $value)
|
|
|
+ {
|
|
|
+ $fgshop .= " shop = ".$value." or";
|
|
|
+ $sid .= " id = ".$value." or";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $params = $this->input->get(NULL, TRUE);
|
|
|
+ if(isset($params['excel']) && $params['excel'] == 1){
|
|
|
+ $shop = $this->input->get('shop',true);
|
|
|
+ $productid = $this->input->get('productid',true);
|
|
|
+ $title = $this->input->get('title',true);
|
|
|
+ $type = $this->input->get('type',true);
|
|
|
+ $code = $this->input->get('code',true);
|
|
|
+ $skuid = $this->input->get('skuid',true);
|
|
|
+ $category = $this->input->get('category',true);
|
|
|
+ $categorytypeclass = $this->typeclass->get_titleclassid($category,16);
|
|
|
+ $where = "1=1 and (".rtrim($fgshop,'or').")";
|
|
|
+ if($shop)
|
|
|
+ {
|
|
|
+ $where .= " and shop = '$shop'";
|
|
|
+ }
|
|
|
+ if($productid)
|
|
|
+ {
|
|
|
+ $where .= " and productid = '$productid'";
|
|
|
+ }
|
|
|
+ if($title)
|
|
|
+ {
|
|
|
+ $where .= " and title like '%$title%'";
|
|
|
+ }
|
|
|
+ if($type)
|
|
|
+ {
|
|
|
+ $where .= " and type = '$type'";
|
|
|
+ }
|
|
|
+ if($category)
|
|
|
+ {
|
|
|
+ $where .= " and category like '%".$categorytypeclass['id']."%'";
|
|
|
+ }
|
|
|
+ if($code)
|
|
|
+ {
|
|
|
+ $u = $this->commodityread->get_sku($code);
|
|
|
+ $u = $u['productid'];
|
|
|
+ $where .= " and productid = '$u'";
|
|
|
+ }
|
|
|
+ if($skuid)
|
|
|
+ {
|
|
|
+ $u = $this->commodityread->get_skuid($skuid);
|
|
|
+ $u = $u['productid'];
|
|
|
+ $where .= " and productid = '$u'";
|
|
|
+ }
|
|
|
+ //数据排序
|
|
|
+ $order_str = "time desc";
|
|
|
+
|
|
|
+ //取得信息列表
|
|
|
+ $info_list = $this->commodity->find_all($where,'id,shop,productid,img,title,category,time',$order_str);
|
|
|
+ //格式化数据
|
|
|
+ $final_list = [];
|
|
|
+ $shop_where = trim($sid,'or');
|
|
|
+ $shop_list = $this->shop->find_all($shop_where,'id,shopname');
|
|
|
+ $shop_list = array_column($shop_list,'shopname','id');
|
|
|
+
|
|
|
+ $typeclass = [];
|
|
|
+ $classid = $this->classid->sku();
|
|
|
+ $tcall = $this->typeclass->find_all();
|
|
|
+ foreach ($tcall as $v)
|
|
|
+ {
|
|
|
+ //$tcjm[$v['id']] = array($v['jm'],$v['classid']);
|
|
|
+ $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($info_list as $key=>$v)
|
|
|
+ {
|
|
|
+ $shop_info = $this->shop->get_shop($v['shop']);
|
|
|
+ $shopname = isset($shop_list[$v['shop']])?$shop_list[$v['shop']]['shopname']:'';
|
|
|
+ $skulist = $this->commodityread->find_all("productid = ".$v['productid']);
|
|
|
+ $tmp_list = [];
|
|
|
+ foreach($skulist as $skv){
|
|
|
+ $u9_info = $this->logic_u9tools->getOneU9bm($skv['sku'],$classid,$typeclass);
|
|
|
+ $tmp_list[] = [
|
|
|
+ 'codeid' => $skv['codeid'],
|
|
|
+ 'erp_sku' => $skv['sku'],
|
|
|
+ 'jm'=>$u9_info['jm'],
|
|
|
+ 'zh'=>$u9_info['zh'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $tmp_codeid = "";
|
|
|
+ $tmp_erp_sku = "";
|
|
|
+ $tmp_jm = "";
|
|
|
+ $tmp_zh = "";
|
|
|
+ foreach($tmp_list as $t){
|
|
|
+ $tmp_codeid .= $t['codeid']."<br>";
|
|
|
+ $tmp_erp_sku .= $t['erp_sku']."<br>";
|
|
|
+ $tmp_jm .= $t['jm']."<br>";
|
|
|
+ $tmp_zh .= $t['zh']."<br>";
|
|
|
+
|
|
|
+ }
|
|
|
+ $final_list[] = [
|
|
|
+ 'shopname' => $shopname,
|
|
|
+ 'productid' => $v['productid'],
|
|
|
+ 'codeid' => $tmp_codeid,
|
|
|
+ 'erp_sku' => $tmp_erp_sku,
|
|
|
+ 'jm' => $tmp_jm,
|
|
|
+ 'zh' => $tmp_zh,
|
|
|
+ 'title' => $v['title'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ //生成excel
|
|
|
+ $filename = '订单出库-'.date('Ymd',time()).".xlsx";
|
|
|
+ $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\"><head>
|
|
|
+ <!--[if gte mso 9]><xml>
|
|
|
+ <x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>EXCEL</x:Name><x:WorksheetOptions><x:Print><x:ValidPrinterInfo /></x:Print></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml>
|
|
|
+ <![endif]-->
|
|
|
+ </head><body>";
|
|
|
+ $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
|
|
|
+ $str .= "<tr><td>店铺名称</td><td>速卖通产品ID</td><td>速卖通品名</td><td>速卖通编码</td><td>erpSKU</td><td>用友简码</td><td>仓库品名</td></tr>";
|
|
|
+ foreach ($final_list as $key=>$value)
|
|
|
+ {
|
|
|
+ $str .= "<tr>";
|
|
|
+ $str .= "<td>". $value['shopname']. "</td>";
|
|
|
+ $str .= "<td>". $value['productid']. "</td>";
|
|
|
+ $str .= "<td>". $value['title']. "</td>";
|
|
|
+ $str .= "<td>". $value['codeid']. "</td>";
|
|
|
+ $str .= "<td>". $value['erp_sku']. "</td>";
|
|
|
+ $str .= "<td>". $value['jm']. "</td>";
|
|
|
+ $str .= "<td>". $value['zh']. "</td>";
|
|
|
+ $str .= "</tr>";
|
|
|
+ }
|
|
|
+ $str .= "</table></body></html>";
|
|
|
+ header( "Content-Type: application/vnd.ms-excel; name='excel'" );
|
|
|
+ header( "Content-type: application/octet-stream" );
|
|
|
+ header( "Content-Disposition: attachment; filename=".$filename );
|
|
|
+ header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
|
|
|
+ header( "Pragma: no-cache" );
|
|
|
+ header( "Expires: 0" );
|
|
|
+ exit($str);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|