function save() { $mainframe = JFactory::getApplication(); include_once JPATH_COMPONENT_SITE . "/lib/csv.io.class.php"; $ie_id = JRequest::getInt("ie_id"); if (!$ie_id) { $ie_id = $this->get('ie_id'); } $_importexport = JTable::getInstance('ImportExport', 'jshop'); $_importexport->load($ie_id); $alias = $_importexport->get('alias'); $_importexport->set('endstart', time()); $params = JRequest::getVar("params"); if (is_array($params)) { $paramsstr = parseArrayToParams($params); $_importexport->set('params', $paramsstr); } $_importexport->store(); $ie_params_str = $_importexport->get('params'); $ie_params = parseParamsToArray($ie_params_str); $jshopConfig = JSFactory::getConfig(); $lang = JSFactory::getLang(); $db = JFactory::getDBO(); $query = "SELECT prod.product_id, prod.product_ean, prod.product_quantity, prod.product_date_added, prod.product_price, tax.tax_value as tax, prod.`" . $lang->get('name') . "` as name, prod.`" . $lang->get('short_description') . "` as short_description, prod.`" . $lang->get('description') . "` as description, cat.`" . $lang->get('name') . "` as cat_name\n FROM `#__jshopping_products` AS prod\n LEFT JOIN `#__jshopping_products_to_categories` AS categ USING (product_id)\n LEFT JOIN `#__jshopping_categories` as cat on cat.category_id=categ.category_id\n LEFT JOIN `#__jshopping_taxes` AS tax ON tax.tax_id = prod.product_tax_id \n GROUP BY prod.product_id"; $db->setQuery($query); $products = $db->loadObjectList(); $data = array(); $head = array("product_id", "ean", "qty", "date", "price", "tax", "category", "name", "short_description", "description"); $data[] = $head; foreach ($products as $prod) { $row = array(); $row[] = $prod->product_id; $row[] = $prod->product_ean; $row[] = $prod->product_quantity; $row[] = $prod->product_date_added; $row[] = $prod->product_price; $row[] = $prod->tax; $row[] = utf8_decode($prod->cat_name); $row[] = utf8_decode($prod->name); $row[] = utf8_decode($prod->short_description); $row[] = utf8_decode($prod->description); $data[] = $row; } $filename = $jshopConfig->importexport_path . $alias . "/" . $ie_params['filename'] . ".csv"; $csv = new csv(); $csv->write($filename, $data); if (!JRequest::getInt("noredirect")) { $mainframe->redirect("index.php?option=com_jshopping&controller=importexport&task=view&ie_id=" . $ie_id, _JSHOP_COMPLETED); } }
public function report() { $startTime = $this->_get('stime', ''); //开始时间 $endTime = $this->_get('etime', ''); //结束时间 $serviceId = $this->_getid('service_id', 0); //服务社 $isOutput = $this->_getid('is_output', 0); //是否导出数据 $cateId = $this->_getid('cid', 0); //类目 $cateList = array(275 => '半成品菜', 273 => '预定下午茶'); if (!isset($cateList[$cateId])) { showError('抱歉,该类目不允许查看'); } if (!parent::_checkIsAdmin()) { if ($cateId != 275 || steadmin::$adminInfo['user_id'] != 291) { //半成品菜店长 showError('抱歉,暂无权限'); } } //取类目及所有子类目 $cateAllList = M('ste_goods_cate')->where(array('city_id' => steadmin::$adminInfo['city_id'], 'is_del' => 0))->order('sort DESC')->select('id'); $tidList = D('tree')->getSubs($cateAllList, $cateId, true); $cateId = $tidList['list'] ? implode(',', $tidList['list']) : $cateId; //默认报表时间为今天 $today = mktime(0, 0, 0, date('m'), date('d'), date('Y')); $stime = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')); if (!$startTime) { $startTime = date('Y-m-d', $stime); } if (!$endTime) { $endTime = date('Y-m-d', $stime); } if ($startTime && $endTime) { $startTime = inTime($startTime); $endTime = inTime($endTime) + 60 * 60 * 24 - 1; } if ($serviceId) { $where = ' AND a.service_id=' . $serviceId; $sWhere = ' AND service_id=' . $serviceId; } else { $where = ''; $sWhere = ''; } if ($startTime < $today) { $statusList = '1,3,4,5,6,7,8,9,10,11'; } else { $statusList = '1,3,4,5,6,7,8,9,10,11'; //搜索状态:已支付、已审核、正在配货 } //根据类目搜索所有的商品gid $where = ''; $rs = M('ste_order')->query('SELECT a.order_id,a.order_sn,a.order_type,a.service_id,a.village_id,a.uid,a.address,a.phone,a.username,' . 'a.desc,a.arrive_date,a.arrive_time,a.order_source,a.status,a.order_time,a.goods_counts AS goods_total,b.gid,b.shop_id,b.goods_name,b.goods_counts,b.goods_price' . ' FROM __TABLE__ AS a LEFT JOIN __PRE__ste_order_goods AS b ON a.order_id=b.order_id WHERE a.arrive_date>=' . $startTime . ' AND a.arrive_date<=' . $endTime . ' AND a.status IN (' . $statusList . ') AND b.gid IN ( SELECT gid FROM __PRE__ste_goods WHERE cate_id IN (' . $cateId . ') ' . $sWhere . ' )' . $where . ' ORDER BY service_id ASC'); // z(M('ste_order')->getAllSql()); // z($rs); $orderList = array(); $orderTotal = array(); $serviceList = array(); if ($rs) { foreach ($rs as $val) { //统计各个菜的数量 $goodsName = md5($val['goods_name']); if (!isset($orderTotal[$goodsName])) { $orderTotal[$goodsName] = array('name' => $val['goods_name'], 'counts' => $val['goods_counts'], 'item' => array()); } else { $orderTotal[$goodsName]['counts'] += $val['goods_counts']; } if (!isset($orderTotal[$goodsName]['item'][$val['service_id']])) { $orderTotal[$goodsName]['item'][$val['service_id']] = array('name' => $this->serviceData[$val['service_id']]['stitle'], 'counts' => $val['goods_counts']); } else { $orderTotal[$goodsName]['item'][$val['service_id']]['counts'] += $val['goods_counts']; } //按服务社统计菜单 if (!isset($serviceList[$val['service_id']])) { $serviceList[$val['service_id']] = array('service_name' => $this->serviceData[$val['service_id']]['stitle'], 'counts' => $val['goods_counts'], 'item' => array()); } else { $serviceList[$val['service_id']]['counts'] += $val['goods_counts']; } if (!isset($serviceList[$val['service_id']]['item'][$val['gid']])) { $serviceList[$val['service_id']]['item'][$val['gid']] = array('name' => $val['goods_name'], 'counts' => $val['goods_counts']); } else { $serviceList[$val['service_id']]['item'][$val['gid']]['counts'] += $val['goods_counts']; } //按订单号归类商品 if (!isset($orderList[$val['order_id']])) { $orderList[$val['order_id']] = array('order_id' => $val['order_id'], 'order_sn' => $val['order_sn'], 'order_type' => $val['order_type'], 'service_id' => $val['service_id'], 'service_name' => $this->serviceData[$val['service_id']]['stitle'], 'village_id' => $val['village_id'], 'village_name' => parent::getVillageName($val['village_id']), 'address' => $val['address'], 'phone' => $val['phone'], 'username' => $val['username'], 'desc' => $val['desc'], 'arrive_date' => $val['arrive_date'], 'arrive_time' => $val['arrive_time'], 'order_source' => $val['order_source'], 'status' => $val['status'], 'order_time' => $val['order_time'], 'goods_total' => $val['goods_total'], 'select_goods_total' => 0, 'list' => array()); } $orderList[$val['order_id']]['list'][] = array('goods_name' => $val['goods_name'], 'goods_counts' => $val['goods_counts'], 'goods_price' => $val['goods_price']); $orderList[$val['order_id']]['select_goods_total'] += $val['goods_counts']; } } // z($orderTotal); // z($serviceList); if ($isOutput) { $dataList = array(); $title = array('订单号', '收货人', '手机', '地址', '配送时间', '商品列表', '留言', '混合订单'); foreach ($orderList as $val) { $list = array(); foreach ($val['list'] as $v) { $list[] = $v['goods_name'] . ' (x ' . $v['goods_counts'] . ')'; } $dataList[] = array($val['order_sn'], $val['username'], $val['phone'], $val['address'], outTime($val['arrive_date'], 2) . ' ' . $val['arrive_time'], implode("\r\n", $list), $val['desc'], $val['goods_total'] == $val['select_goods_total'] ? '否' : '是'); } if (isset($this->serviceData[$serviceId])) { $tname = $this->serviceData[$serviceId]['stitle']; } else { $tname = '全部'; } $dataList[] = array('', '', '', '', '', '', '', ''); $dataList[] = array('', '', '', '', '', '', '', ''); $dataList[] = array('品类', '详细', '数量', '', '', '', '', ''); //将统计信息附加到报表中 foreach ($orderTotal as $val) { $list = array(); foreach ($val['item'] as $v) { $list[] = $v['name'] . ' (' . $v['counts'] . '份)'; } $dataList[] = array($val['name'], implode('、', $list), $val['counts'], '', '', '', '', ''); } $dataList[] = array('', '', '', '', '', '', '', ''); $dataList[] = array('', '', '', '', '', '', '', ''); $dataList[] = array('服务社', '详细', '数量', '', '', '', '', ''); //将统计信息附加到报表中 foreach ($serviceList as $val) { $list = array(); foreach ($val['item'] as $v) { $list[] = $v['name'] . ' (' . $v['counts'] . '份)'; } $dataList[] = array($val['service_name'], implode("\r\n", $list), $val['counts'], '', '', '', '', ''); } load('csv'); $csv = new csv(); $csv->write($title, $dataList, $cateList[$cateId] . '订单_' . $tname . date('Y-m-d H/i/s')); } else { $this->assign(array('rs' => $orderList, 'orderTotal' => $orderTotal, 'cid' => $cateId, 'service_id' => $serviceId, 'startTime' => $startTime, 'endTime' => $endTime, 'serviceList' => $serviceList, 'service' => $this->serviceData, 'setting' => $this->steSetting)); $this->display(); } }
public function out() { parent::_checkLogin(); parent::_authUser(array(1)); $maxRead = 1000; //单次读出最大的数据量 $serviceId = $this->_getid('service_id', 0); //类别 $shopId = $this->_getid('shop_id', 0); //店铺 $where = array('status' => array(0, 1)); if ($serviceId) { $where['service_id'] = $serviceId; } if ($shopId) { $where['shop_id'] = $shopId; } $count = M('ste_goods')->where($where)->count(); $pages = ceil($count / $maxRead); $rs = array(); if ($pages) { for ($i = 1; $i <= $pages; $i += 1) { $list = M('ste_goods')->where($where)->order('shop_id DESC')->limit(($i - 1) * $maxRead . ',' . $maxRead)->findAll(false); if ($list) { $rs = array_merge($rs, $list); } } } load('csv'); $myCsv = new csv(); $list = array(); foreach ($rs as $val) { $cateList = $this->getCateTree($val['cate_id']); if ($cateList) { $cateName = implode('->', $cateList) . '->' . parent::_getCateName($val['cate_id']); } else { $cateName = parent::_getCateName($val['cate_id']); } $list[] = array($val['gid'], "\t" . $val['goods_sn'], parent::_getShopName($val['shop_id']), $cateName, parent::_getAdminName($val['user_id']), $val['goods_name'], $val['goods_subtitle'], $val['goods_spec'], getImgUrl($val['goods_pic']), "\t" . $val['original_price'], $val['price_pre'], "\t" . $val['price'], "\t" . $val['purc_price'], "\t" . $val['goods_number'], "\t" . $val['bar_code'], strip_tags($val['goods_desc']), $val['order_counts'], $val['sale_counts'], $val['storage_counts'], "\t" . outTime($val['start_times']), "\t" . outTime($val['end_times']), $val['is_limited'] ? '是' : '否', $val['limit_counts'], strip_tags($this->getStatus($val['start_times'], $val['end_times'], $val['status']))); } unset($rs); $myCsv->write(array('编号', '商品货号', '店铺', '类别', '帐号', '商品名称', '副标题', '规格', '图片', '原价', '价格前缀', '售价', '进价', '商家货号', '条形码', '描述', '下单量', '销售量', '库存', '上架时间', '下架时间', '是否特价', '限购数量', '销售状态'), $list, 'goods_' . date('y-m-d')); }