Example #1
0
 function pageaddgoods($inPath)
 {
     $url = $this->getUrlParams($inPath);
     $goods_id = (int) $url['gid'] > 0 ? (int) $url['gid'] : (int) $_POST['goods_id'];
     $goodsObj = new m_goods($goods_id);
     if ($_POST) {
         $post = base_Utils::shtmlspecialchars($_POST);
         if ($goodsObj->create($post)) {
             base_Utils::ssetcookie(array('cat_id' => $post['cat_id']));
             $this->ShowMsg("操作成功!", $this->createUrl("/goods/addgoods"), 2, 1);
         }
         $this->ShowMsg("操作失败" . $goodsObj->getError());
     }
     $categoryObj = new m_category();
     $this->params['cat_id'] = (int) $_COOKIE['cat_id'];
     $this->params['catelist'] = $categoryObj->getOrderCate('    ');
     $this->params['goods'] = $goodsObj->selectOne("goods_id={$goods_id}");
     return $this->render('goods/addgoods.html', $this->params);
 }
Example #2
0
 function pageOut($inPath)
 {
     $url = $this->getUrlParams($inPath);
     $order_id = (int) $url['oid'];
     session_start();
     $tempsales = new m_tempsales();
     $info = $tempsales->select("order_id='{$order_id}'")->items;
     //$info = $_SESSION ['goodsInfo'];
     $saleObj = new m_sales();
     $sales = $mem_rs = array();
     $purchaseObj = new m_purchase();
     if (is_array($info)) {
         $url['ac'] = '';
         $dateline = time();
         $goodsObj = new m_goods();
         $cardid = base_Utils::getStr($_POST['cardid']);
         if ($cardid) {
             $memberObj = new m_member();
             $mem_rs = $memberObj->getMemberPrice($cardid);
             if (!$mem_rs['mid']) {
                 $this->ShowMsg("会员卡不存在!");
             }
             $sales['mid'] = $mem_rs['mid'];
             $sales['membercardid'] = $mem_rs['membercardid'];
             $sales['realname'] = $mem_rs['realname'];
         }
         //$order_id = date ( "mdHis", time () ) . base_Utils::random ( 4, 1 );
         $mem_amount = 0;
         $pro_amount = 0;
         foreach ($info as $k => $v) {
             $out_amount += sprintf("%01.2f", $v['out_price'] * $v['num']);
             //总价
             $pro_amount += sprintf("%01.2f", $v['p_discount'] * $v['num']);
             //促销优惠的总价
             $sales['order_id'] = $order_id;
             $sales['goods_id'] = $v['goods_id'];
             $sales['cat_id'] = $v['cat_id'];
             $sales['goods_sn'] = $v['goods_sn'];
             $sales['goods_name'] = $v['goods_name'];
             $sales['num'] = $v['num'];
             $sales['out_price'] = $v['out_price'];
             $sales['in_price'] = $goodsObj->getAvgPrice($v['goods_id']);
             $sales['p_discount'] = $v['p_discount'];
             //促销优惠的金额
             $sales['price'] = $sales['out_price'] - $sales['p_discount'];
             if ($v['ismemberprice'] == 1 and $mem_rs['mid']) {
                 $sales['m_discount'] = ($v['out_price'] - $v['p_discount']) * (100 - $mem_rs['discount']) / 100;
                 //会员+促销优惠
                 $sales['m_discount'] = sprintf("%01.2f", $sales['m_discount']);
                 $sales['price'] = $sales['out_price'] - $sales['m_discount'];
                 $mem_amount += sprintf("%01.2f", $v['out_price'] * $v['num'] - $sales['m_discount'] * $v['num']);
                 //会员+促销总价
             }
             $sales['dateymd'] = date("Y-m-d", time());
             $sales['dateline'] = time();
             if (!$saleObj->insert($sales)) {
                 $this->ShowMsg("添加销售记录错误!" . $saleObj->getError());
             }
             $purchaseObj->outStock($sales['goods_id'], $v['num'], sprintf("%01.2f", $sales['price'] * $v['num']));
         }
         //计算应收金额
         $real_amount = $out_amount - $mem_amount - $pro_amount;
         if ($sales['mid']) {
             $memberObj->setCredit($sales['mid']);
         }
         $tempsales->delOrder($order_id);
         //清除临时销售记录
     }
     $goods = $saleObj->select("order_id={$order_id}")->items;
     if ($url['ac'] == 'p') {
         //独立打印
         if (!is_array($goods)) {
             $this->ShowMsg("订单中没有任何商品!");
         }
         foreach ($goods as $k => $v) {
             $out_amount += sprintf("%01.2f", $v['out_price'] * $v['num']);
             //应收金额
             $pro_amount += sprintf("%01.2f", $v['p_discount'] * $v['num']);
             //促销优惠的总价
             $mem_amount += sprintf("%01.2f", $v['m_discount'] * $v['num']);
             //会员优惠的总价
             $real_amount += sprintf("%01.2f", $v['price'] * $v['num']);
             //实收金额 减去会员优惠和促销优惠
             $dateline = $v['dateline'];
         }
     }
     $this->params['goods'] = $goods;
     $this->params['order_id'] = $order_id;
     $this->params['out_amount'] = $out_amount;
     $this->params['real_amount'] = $real_amount;
     $this->params['pro_amount'] = $pro_amount;
     $this->params['mem_amount'] = $mem_amount;
     $this->params['dateline'] = $dateline;
     $_SESSION['order_id'] = "";
     return $this->render('sales/out.html', $this->params);
 }
Example #3
0
 function pageecshop($inPath)
 {
     //define(DEBUG,1);
     $url = $this->getUrlParams($inPath);
     $lastid = (int) $url['lastid'] ? (int) $url['lastid'] : 0;
     if ($_POST or $lastid > 0) {
         $pre = base_Utils::getStr($_REQUEST['pre']) ? base_Utils::getStr($_REQUEST['pre']) : $url['pre'];
         $num = (int) $_POST['num'] ? (int) $_POST['num'] : $url['num'];
         $ecshop = new m_plugins("ecshop");
         $ecshop->_db->setLimit($num);
         $categoryObj = new m_category();
         $goodsObj = new m_goods();
         $type = $_POST['type'] ? $_POST['type'] : $url['type'];
         if ($type == 1) {
             $table = $pre . "category";
             if ($lastid == 0) {
                 $categoryObj->clearTable(array("category"));
             }
             $rs = $ecshop->_db->select($table, "cat_id>{$lastid}", "cat_id,cat_name,parent_id,sort_order,is_show", "order by cat_id asc")->items;
             if (is_array($rs[0])) {
                 foreach ($rs as $k) {
                     $itmes['cat_id'] = $k['cat_id'];
                     $itmes['cat_name'] = $k['cat_name'];
                     $itmes['pid'] = $k['parent_id'];
                     $itmes['sort'] = $k['sort_order'];
                     $itmes['is_show'] = $k['is_show'];
                     if (!$categoryObj->insert($itmes)) {
                         $this->showMsg('写入数据错误' . $categoryObj->getError());
                     }
                     $lastid = $k['cat_id'];
                 }
                 $this->showMsg("转换{$num}条完成!", $this->createUrl("/plugins/ecshop", array("lastid" => $lastid, "num" => $num, "type" => 1)) . "?pre={$pre}", 2, 1);
             } else {
                 $this->showMsg("转换完成", $this->createUrl("/plugins/ecshop"), 5, 1);
             }
         } else {
             $table = $pre . "goods";
             if ($lastid == 0) {
                 $goodsObj->clearTable(array("goods", "member", "purchase", "sales", "log"));
             }
             $rs = $ecshop->_db->select($table, "goods_id>{$lastid}", "", "order by goods_id asc")->items;
             if (is_array($rs[0])) {
                 $i = 0;
                 $j = 0;
                 foreach ($rs as $k) {
                     $itmes['cat_id'] = $k['cat_id'];
                     $itmes['goods_sn'] = $k['goods_sn'];
                     $itmes['goods_name'] = $k['goods_name'];
                     $itmes['market_price'] = $k['market_price'];
                     $itmes['out_price'] = $k['shop_price'];
                     $itmes['promote_price'] = $k['promote_price'];
                     $itmes['ispromote'] = $k['is_promote'];
                     $itmes['weight'] = $k['goods_weight'];
                     $itmes['unit'] = '';
                     $itmes['in_price'] = 0;
                     $itmes['ismemberprice'] = 1;
                     $itmes['promote_start_date'] = date("Y-m-d", $k['promote_start_date']);
                     $itmes['promote_end_date'] = date("Y-m-d", $k['promote_end_date']);
                     $itmes['warn_stock'] = $k['warn_number'];
                     $itmes['goods_desc'] = $k['goods_brief'];
                     if (!$goodsObj->create($itmes)) {
                         $j++;
                         //$this->showMsg('写入数据错误'.$goodsObj->getError());
                     }
                     $i++;
                     $lastid = $k['goods_id'];
                 }
                 $this->showMsg("共转换{$i}条数据,失败或者重复商品{$j}条!", $this->createUrl("/plugins/ecshop", array("lastid" => $lastid, "num" => $num, "type" => 2)) . "?pre={$pre}", 2, 1);
             } else {
                 $this->showMsg("转换商品完成", $this->createUrl("/plugins/ecshop"), 5, 1);
             }
         }
     }
     $this->params['head_title'] = "Ecshop转换插件-" . $this->params['head_title'];
     return $this->render('plugins/ecshop/index.html', $this->params);
 }