function pagesales($inPath) { $ymd = date('Y-m-d', time()); if ($_POST) { $purchaseObj = new m_purchase(); $condi = ''; $start = base_Utils::getStr($_POST['start']); $end = base_Utils::getStr($_POST['end']); if ($start) { $condi = "dateymd>={$start}"; $condi .= $end ? " and dateymd<={$end}" : " and dateymd<={$ymd}"; } $this->params['title'] = "进货统计"; $rs = $purchaseObj->select($condi, "dateymd,sum(in_num*in_price) as money", "group by dateymd")->items; $this->params['start'] = $start; $this->params['end'] = $end; $this->params['line'] = $this->linedata($rs); } return $this->render('statistics/sales.html', $this->params); }
function pagepurchase($inPath) { $url = $this->getUrlParams($inPath); $goods_id = $url['gid'] ? (int) $url['gid'] : (int) $_POST['goods_id']; $url['ac'] = $url['ac'] ? $url['ac'] : "add"; $purchaseObj = new m_purchase((int) $url['id']); switch ($url['ac']) { case "add": $goodsObj = base_mAPI::get("m_goods", $goods_id); if ($_POST) { $goods_sn = base_Utils::getStr($_POST['goods_sn']); $rs = $goodsObj->get("goods_sn = '{$goods_sn}'"); if (!$rs) { $this->ShowMsg("没有该商品信息"); } $data['goods_id'] = $rs['goods_id']; $data['goods_sn'] = $rs['goods_sn']; $data['in_num'] = (double) $_POST['in_num']; $data['in_price'] = (double) $_POST['in_price']; if (!$data['in_num'] or !$data['in_price']) { $this->showMsg("数量和单价不能够为空!"); } $data['content'] = base_Utils::getStr($_POST['content']); if ($purchaseObj->create($data)) { $this->ShowMsg("入库成功!", $this->createUrl("/purchase/index"), 2, 1); } $this->ShowMsg("入库出错!原因:" . $purchaseObj->getError()); } if ($url['id']) { $this->params['goods'] = $purchaseObj->get(); } else { $this->params['goods'] = $goodsObj->get(); } break; case "del": if ($url['gid']) { if ($purchaseObj->deleteOne($url['gid'])) { $this->ShowMsg("删除成功!", $this->createUrl("/purchase/index"), 2, 1); } $this->ShowMsg("删除出错!原因:" . $purchaseObj->getError()); } break; } $this->params['ac'] = $url['ac']; return $this->render('purchase/purchase.html', $this->params); }
/** * 处理退货 * @param array $inPath */ function pagereturn($inPath) { $url = $this->getUrlParams($inPath); if ($_POST) { $order_id = intval($_POST['order_id']); $salesObj = new m_sales(); $this->params['order_id'] = $order_id; if ($_POST['ac'] == 'del') { $sidArr = (array) $_POST['sid']; $numArr = (array) $_POST['num']; $returnArr = array(); $i = 0; if ($sidArr) { foreach ($sidArr as $k => $v) { $v = (int) $v; $rs = $salesObj->selectOne("sid='{$v}' and order_id='{$order_id}' and refund_type=0", "num,goods_id,goods_name,price,mid"); //退过款的商品不能够二次退款 if (!$rs) { $this->ShowMsg("该订单中没有该商品!"); } $mid = $rs['mid']; if ($numArr[$k] > 0 and $numArr[$k] <= $rs['num']) { $returnArr[$i]['sid'] = $v; $returnArr[$i]['goods_id'] = $rs['goods_id']; $returnArr[$i]['num'] = (double) $numArr[$k]; $returnArr[$i]['refund_type'] = 2; $returnArr[$i]['refund_amount'] = sprintf("%01.2f", $rs['price'] * $numArr[$k]); if ($numArr[$k] == $rs['num']) { $returnArr[$i]['refund_type'] = 1; } $i++; } else { $this->ShowMsg("{$rs['goods_name']} 退货数量不正确"); } } } $purchaseObj = new m_purchase(); //退货操作 1修改库存 2 修改商品销售总价 3更新会员卡积分 foreach ($returnArr as $v) { if (!$purchaseObj->backStock($v['goods_id'], $v['num'], $v['refund_amount'])) { $salesObj->update("order_id='{$order_id}' and goods_id = '{$v['goods_id']}'", "refund_type={$v['refund_type']},refund_amount={$v['refund_amount']},refund_num={$v['num']}"); $this->ShowMsg("商品{$v['goods_id']}退款出错" . $purchaseObj->getError()); } } if ($mid) { $memberObj = new m_member(); $memberObj->setCredit($mid); } $this->ShowMsg("退货成功!", $this->createUrl("/sales/return"), 20, 1); } $this->params['list'] = $salesObj->select("order_id='{$order_id}'")->items; } return $this->render('sales/return.html', $this->params); }