'成本调整','href'=>'index.php?app=dealer&ctl=admin_goods&act=create','target'=>'dialog::{width:600,height:300,title:\'成本调整\'}'), array( 'label' => '导出模板', 'href' => 'index.php?app=dealer&ctl=admin_goods&act=exportTemplate', 'target' => "_blank", ), ); $params = array( 'title'=>'经销商商品', 'use_buildin_set_tag'=>false, 'use_buildin_filter'=>false, 'use_buildin_export'=>false, 'use_buildin_import'=>true, 'use_buildin_recycle'=>true, 'actions'=>$actions, ); $this->finder('dealer_mdl_goods', $params); } /* * 导出模板 */ public function exportTemplate() { header("Content-Type: text/csv"); $filename = "经销商货品模板.csv"; $encoded_filename = urlencode($filename); $encoded_filename = str_replace("+", "%20", $encoded_filename); $ua = $_SERVER["HTTP_USER_AGENT"]; if (preg_match("/MSIE/", $ua)) { header('Content-Disposition: attachment; filename="' . $encoded_filename . '"'); } else if (preg_match("/Firefox/", $ua)) { header('Content-Disposition: attachment; filename*="utf8\'\'' . $filename . '"'); } else { header('Content-Disposition: attachment; filename="' . $filename . '"'); } header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); header('Expires:0'); header('Pragma:public'); //模板 $dealerGoodsObj = app::get('dealer')->model('goods'); $title = $dealerGoodsObj->exportTemplate(); echo '"'.implode('","',$title).'"'; } /** * 创建 * @return mixed 返回值 */ public function create() { $this->display('admin/goods.html'); } /** * 保存 * @return mixed 返回操作结果 */ public function save() { if(empty($_POST['bs_id'])) { $this->splash('error', $this->url, '经销商必填'); } if(empty($_POST['bm_id'])) { $this->splash('error', $this->url, '基础物流必填'); } if(!is_numeric($_POST['cost'])) { $this->splash('error', $this->url, '成本必须为数值'); } $this->begin('index.php?app=dealer&ctl=admin_goods&act=index'); $data = array( 'bs_id' => $_POST['bs_id'], 'bm_id' => $_POST['bm_id'], 'cost' => $_POST['cost'], ); $dealerGoodsObj = app::get('dealer')->model('goods'); $oldRow = $dealerGoodsObj->db_dump(array('bs_id'=>$data['bs_id'], 'bm_id'=>$data['bm_id']), 'id'); if($oldRow) { $dealerGoodsObj->update(array('cost'=>$data['cost'], 'modify_time'=>time()), array('id'=>$oldRow['id'])); } else { $data['create_time'] = time(); $data['modify_time'] = time(); $dealerGoodsObj->insert($data); } $this->end(true, '操作成功'); } }