Beispiel #1
0
 function pagecategory($inPath)
 {
     $url = $this->getUrlParams($inPath);
     $catid = (int) $url['catid'] > 0 ? (int) $url['catid'] : (int) $_POST['cat_id'];
     $categoryObj = new m_category($catid);
     $this->params['categorylist'] = $categoryObj->getOrderCate('    ');
     if ($_POST) {
         $post = base_Utils::shtmlspecialchars($_POST);
         if ($catid) {
             if ($categoryObj->isErrorPid($post['pid'], $post['cat_id']) === false) {
                 $this->ShowMsg("不能将父分类修改为它的子分类");
             }
             if ($categoryObj->create($post)) {
                 $this->ShowMsg("修改成功!", $this->createUrl("/category/index"), '', 1);
             }
             $this->ShowMsg("修改失败" . $categoryObj->getError());
         } else {
             if ($categoryObj->isHasPid($post['pid']) === false) {
                 $this->ShowMsg("你选择的上级分类不存在");
             }
             if ($categoryObj->create($post)) {
                 $this->ShowMsg("添加成功!", $this->createUrl("/category/index"), '', 1);
             }
             $this->ShowMsg("添加失败,原因:" . $categoryObj->getError());
         }
     } else {
         if ($catid) {
             $this->params['category'] = $categoryObj->get();
         }
         return $this->render('category/category.html', $this->params);
     }
 }
Beispiel #2
0
 function pageaddmember($inPath)
 {
     $url = $this->getUrlParams($inPath);
     $mid = (int) $url['mid'] > 0 ? (int) $url['mid'] : (int) $_POST['mid'];
     $memberObj = new m_member($mid);
     if ($_POST) {
         $post = base_Utils::shtmlspecialchars($_POST);
         if ($mid) {
             if ($memberObj->create($post)) {
                 $this->ShowMsg("修改成功!", $this->createUrl("/member/index"), '', 1);
             }
             $this->ShowMsg("修改失败" . $memberObj->getError());
         } else {
             if ($memberObj->create($post)) {
                 $this->ShowMsg("添加成功!", $this->createUrl("/member/index"), '', 1);
             }
             $this->ShowMsg("添加失败,原因:" . $memberObj->getError());
         }
     } else {
         if ($mid) {
             $this->params['member'] = $memberObj->get();
         }
         $mbgroupObj = new m_mbgroup();
         $this->params['group'] = $mbgroupObj->select()->items;
         return $this->render('member/addmember.html', $this->params);
     }
 }
Beispiel #3
0
 /**
  * 随机生成一组条形码
  */
 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);
     }
 }
Beispiel #4
0
 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);
 }
Beispiel #5
0
 function isLogin()
 {
     if ($_COOKIE['key']) {
         if ($_COOKIE['key'] != md5($_COOKIE['admin_id'] . $_COOKIE['admin_name'] . $_COOKIE['lastlogintime'] . base_Constant::COOKIE_KEY)) {
             $cookie['key'] = '';
             $cookie['admin_id'] = '';
             $cookie['gid'] = '';
             $cookie['admin_name'] = '';
             $cookie['lastlogintime'] = '';
             base_Utils::ssetcookie($cookie, -1);
             return false;
         }
     } else {
         return false;
     }
     return true;
 }
Beispiel #6
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);
 }
Beispiel #7
0
 public function checkLogin($username, $pwd, $timeout = 7200)
 {
     $pwd = md5($pwd);
     $rs = $this->selectOne("admin_name = '{$username}' and admin_pwd = '{$pwd}'");
     if ($rs) {
         if ($this->update("admin_id = {$rs['admin_id']}", "lastlogintime = {$this->_time}")) {
             $cookie['admin_id'] = $rs['admin_id'];
             $cookie['admin_name'] = $rs['admin_name'];
             $cookie['gid'] = $rs['gid'];
             $cookie['lastlogintime'] = $rs['lastlogintime'];
             $cookie['key'] = md5($rs['admin_id'] . $rs['admin_name'] . $rs['lastlogintime'] . base_Constant::COOKIE_KEY);
             base_Utils::ssetcookie($cookie, $timeout);
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #8
0
 /**
  * 日志
  * @param int $goods_id
  * @param string $content
  * @param int $type 0添加商品 1入库 2出库
  */
 function create($goods_id, $content, $type = 0)
 {
     if (!goods_id or !$content) {
         $this->setError(0, "缺少必要参数");
         return false;
     }
     $this->set("goods_id", $goods_id);
     $this->set("type", $type);
     $this->set("content", base_Utils::getStr($content));
     $this->set("user_id", $_COOKIE['admin_id']);
     $this->set("username", $_COOKIE['admin_name']);
     $this->set("dateymd", date("Y-m-d", $this->_time));
     $this->set("dateline", $this->_time);
     $res = $this->save();
     if ($res) {
         return $res;
     }
     $this->setError(0, "保存数据失败:" . $this->getError());
     return false;
 }
Beispiel #9
0
 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);
 }
Beispiel #10
0
 function pagemodifypwd($inPath)
 {
     $admin_id = (int) $_COOKIE['admin_id'];
     if ($_POST) {
         $adminObj = new m_admin();
         $post = base_Utils::shtmlspecialchars($_POST);
         $resPwd = $adminObj->get("admin_id = {$admin_id}", 'admin_pwd');
         if ($resPwd['admin_pwd'] == md5($post['old_pwd']) and $post['new_pwd'] == $post['new_pwd2'] and $post['new_pwd']) {
             $pwd = md5($post['new_pwd']);
             $rs = $adminObj->update("admin_id = {$admin_id}", "admin_pwd = '{$pwd}'");
             if ($rs) {
                 $this->ShowMsg('修改成功', $this->createUrl('/account/modifypwd'), '', 1);
             } else {
                 $this->ShowMsg('修改失败,请重试!错误原因:' . $adminObj->getError());
             }
         } else {
             $this->ShowMsg('原密码错误或者两次新密码不一致!');
         }
     }
     return $this->render('account/modifypwd.html', $this->params);
 }
Beispiel #11
0
 private function creatRights($post)
 {
     $post = (array) base_Utils::shtmlspecialchars($post);
     $action = $menu = array();
     foreach ($post as $key => $val) {
         if (in_array($key, array('system', 'account', 'member', 'category', 'goods', 'purchase', 'sales', 'statistics'))) {
             $_temp = array();
             foreach ($val as $v) {
                 $vArr = explode(':', $v);
                 $_temp[$vArr[1]] = $vArr[0];
                 $action[] = $key . '_' . $vArr[1];
             }
             $menu[$key] = $_temp;
         }
     }
     return serialize(array('all' => 0, 'action' => $action, 'menu' => $menu));
 }
Beispiel #12
0
 function pagelogout($inPath)
 {
     $cookie['key'] = '';
     base_Utils::ssetcookie($cookie, -1);
     return $this->ShowMsg("成功退出!", $this->createUrl('/main/index'), 2, 1);
 }
Beispiel #13
0
 /**
  * 打印小票
  * @param array $inPath
  */
 function pageprint($inPath)
 {
     $url = $this->getUrlParams($inPath);
     $page = $url['page'] ? (int) $url['page'] : 1;
     $ymd = date("Y-m-d", time());
     $condi = '';
     if ($_POST) {
         $key = base_Utils::getStr($_POST['key']);
         $stime = base_Utils::getStr($_POST['stime']);
         $etime = base_Utils::getStr($_POST['etime']);
         if ($key) {
             $condi = "order_id ='{$key}' or goods_name like '%{$key}%' or realname like '%{$key}%' or membercardid ='{$key}'";
         }
         if ($stime) {
             $etime = $etime ? $etime : $ymd;
             $condi = $condi ? $condi . " and" : "";
             $condi .= " dateymd between '{$stime}' and '{$etime}'";
         }
     }
     $saleObj = new m_sales();
     $saleObj->setCount(true);
     $saleObj->setPage($page);
     $saleObj->setLimit(base_Constant::PAGE_SIZE);
     $rs = $saleObj->select($condi, "order_id,sum(price*num) as allprice,dateymd,sum(p_discount+m_discount) as discount,sum(refund_amount) as refund", "group by order_id", "order by sid desc");
     $this->params['sales'] = $rs->items;
     $this->params['key'] = $key;
     $this->params['stime'] = $stime;
     $this->params['etime'] = $etime;
     $this->params['pagebar'] = $this->PageBar($rs->totalSize, base_Constant::PAGE_SIZE, $page, $inPath);
     return $this->render('sales/print.html', $this->params);
 }
Beispiel #14
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);
 }