/** * 随机生成一组条形码 */ public function pagegetbarcode($inPath) { $code = base_Constant::BARCODE . base_Utils::random(4, 1); $SBarcode = new SBarcode(); $code = $SBarcode->_ean13CheckDigit($code); if (strlen($code) == 13) { $imgsrc = $this->createUrl("/ajax/barcode") . "?code={$code}"; return json_encode(array("code" => $code, "imgsrc" => $imgsrc)); } else { return $this->pagegetbarcode($inPath); } }
function pagesales($inPath) { $url = $this->getUrlParams($inPath); session_start(); $order_id = $_SESSION['order_id']; $tempsales = new m_tempsales(); if (!$order_id) { $order_id = date("mdHis", time()) . base_Utils::random(4, 1); $_SESSION['order_id'] = $order_id; } else { $info = $tempsales->select("order_id='{$order_id}'")->items; } if ($url['ac'] == "del") { if ($order_id) { if (!$tempsales->delOrder($order_id)) { $this->ShowMsg("清空出错!" . $tempsales->getError()); } } $this->ShowMsg("操作成功!", $this->createUrl("/sales/sales"), 1, 1); } if ($_POST) { $goods_sn = base_Utils::getStr($_POST['goods_sn']); $num = (double) $_POST['num'] ? (double) $_POST['num'] : 1; $ishas = 0; if (is_array($info)) { foreach ($info as $k => $v) { if ($v['goods_sn'] == $goods_sn) { $info[$k]['num'] += $num; $ishas = 1; if ($info[$k]['num'] > $v['stock']) { $info[$k]['num'] -= $num; $this->ShowMsg("该商品库存不足!", $this->createUrl("/sales/sales")); } $data['order_id'] = $order_id; $data['goods_id'] = $v['goods_id']; $data['num'] = $info[$k]['num']; if (!$tempsales->updateOrder($data)) { $this->ShowMsg("插入订单失败!"); } } } } if (!$ishas) { $goodsObj = new m_goods(); $goods = $goodsObj->getSalePrice($goods_sn); if (!$goods) { $this->ShowMsg("商品信息不存在", $this->createUrl("/sales/sales"), 1); } if ($num > $goods['stock']) { $this->ShowMsg("该商品库存不足!", $this->createUrl("/sales/sales")); } $goods['num'] = $num; if (!$tempsales->insertOrder($goods, $order_id)) { $this->ShowMsg("插入订单失败!" . $tempsales->getError()); } } //$_SESSION ['goodsInfo'] = $info; $this->redirect($this->createUrl("/sales/sales")); } $total = $discount = 0; if (is_array($info)) { foreach ($info as $v) { $total += $v['num'] * $v['out_price']; $discount += $v['num'] * $v['p_discount']; } } $this->params['total'] = $total; $this->params['order_id'] = $order_id; $this->params['discount'] = $discount; $this->params['info'] = $info; //print_r($info); return $this->render('sales/sales.html', $this->params); }