Example #1
0
 /**
  *  数据备份
  */
 public function doBackUp(ZOL_Request $input, ZOL_Response $output)
 {
     $db = Db_Andyou::instance();
     //需要备份的数据库
     $tablesArr = array("adminuser", "bills", "billsitem", "member", "membercate", "options", "product", "productcate", "staff", "staffcate", "log_backup", "log_cardchange", "log_productinstorage", "log_scorechange");
     $sqlTxt = "";
     foreach ($tablesArr as $tbl) {
         $sql = "select * from {$tbl} order by id desc limit 10000";
         $res = $db->getAll($sql);
         if ($res) {
             $keys = false;
             $sqlTxt .= "\n\ninsert into {$tbl}";
             $comma = "";
             foreach ($res as $re) {
                 if (!$keys) {
                     $keys = array_keys($re);
                     $sqlTxt .= "(" . implode(",", $keys) . ") values \n";
                 }
                 $sqlTxt .= $comma . "('" . implode("','", $re) . "')";
                 $comma = ",";
             }
         }
         $sqlTxt .= ";";
     }
     file_put_contents(SYSTEM_VAR . "backup/" . date("Ymd") . ".sql", $sqlTxt);
     echo "OK";
     exit;
 }
Example #2
0
 /**
  * 更新库存
  */
 public function doAddIn(ZOL_Request $input, ZOL_Response $output)
 {
     $db = Db_Andyou::instance();
     $itemIdArr = $input->post("item_id");
     //所有产品ID
     $itemNumArr = $input->post("item_num");
     //所有产品产品数量
     if ($itemIdArr) {
         foreach ($itemIdArr as $i => $pid) {
             $num = $itemNumArr[$i];
             if ($num) {
                 $orgNum = (int) $db->getOne("select stock from product where id = {$pid}");
                 //获得以前的库存数
                 //更新库存信息
                 $sql = "update product set stock = stock + {$num} where id = {$pid} ";
                 $db->query($sql);
                 //获得当前产品的信息
                 $proInfo = Helper_Product::getProductInfo(array('id' => $pid));
                 //记录日志 log_productInStorage
                 $item = array('proId' => $pid, 'adminer' => $output->admin, 'dateTm' => SYSTEM_TIME, 'orgNum' => $orgNum, 'addNum' => $num, 'cateId' => $proInfo["cateId"], 'name' => $proInfo["name"], 'code' => $proInfo["code"]);
                 Helper_Dao::insertItem(array('addItem' => $item, 'dbName' => 'Db_Andyou', 'tblName' => 'log_productInStorage'));
             }
         }
     }
     $urlStr = "?c={$output->ctlName}";
     echo "<script>alert('Success!');document.location='{$urlStr}';</script>";
     exit;
 }
Example #3
0
 /**
  * 获得一个充值的一个单号
  */
 public static function getCardMaxBno()
 {
     $db = Db_Andyou::instance();
     //获得今天订单个数
     $date = date("Y-m-d ", SYSTEM_TIME);
     $startTm = strtotime($date . "00:00:00");
     $sql = "select count(*) from log_cardchange where dateTm >" . $startTm;
     $num = $db->getOne($sql);
     return date("Ymd", SYSTEM_TIME) . sprintf("%06d", $num + 1);
 }
Example #4
0
 public function doDone(ZOL_Request $input, ZOL_Response $output)
 {
     $otherProIdArr = $input->post("otherProId");
     //所有商品
     $staffid = (int) $input->post("staffid");
     //员工
     $remark = $input->post("remark");
     //填写的备注
     $memberId = (int) $input->post("memberId");
     //会员ID
     if (!$staffid || empty($otherProIdArr)) {
         $this->showErrMsg();
     }
     //获得会员信息
     $memberInfo = Helper_Member::getMemberInfo(array("id" => $memberId));
     if (!$memberInfo) {
         $this->showErrMsg();
     }
     //获得商品列表
     $proInfoArr = array();
     foreach ($otherProIdArr as $id) {
         $info = Helper_Product::getMemberOtherPro(array('id' => $id, 'memberId' => $memberId));
         if ($info && $info["num"] > 0) {
             //筛选一下商品
             $proInfoArr[] = $info;
         }
     }
     //生成一个单号
     $bno = Helper_Bill::getCommonMaxBno();
     $db = Db_Andyou::instance();
     if ($proInfoArr) {
         foreach ($proInfoArr as $info) {
             //数量减少
             $sql = "update memeberotherpro set num = num - 1 where id = " . $info["id"];
             $db->query($sql);
             //记录消费日志
             $tmpLogRow = array('memberId' => $memberId, 'phone' => $memberInfo["phone"], 'otherproId' => $info["id"], 'name' => $info["name"], 'direction' => 1, 'cvalue' => 1, 'orgcvalue' => $info["num"], 'ctype' => $info["ctype"], 'dateTm' => SYSTEM_TIME, 'staffid' => $staffid, 'bno' => $bno, 'remark' => $remark);
             Helper_Dao::insertItem(array('addItem' => $tmpLogRow, 'dbName' => 'Db_Andyou', 'tblName' => 'log_useotherpro'));
         }
     }
     $staffArr = Helper_Staff::getStaffPairs();
     //准备进入打印页面
     $output->proInfoArr = $proInfoArr;
     $output->bno = $bno;
     $output->memberId = $memberId;
     $output->memberInfo = $memberInfo;
     //会员信息
     $output->staffid = $staffid;
     $output->staffName = $staffArr[$staffid];
     Helper_Bill::createOneCommonBno();
     //生成一个通用订单号
     $output->setTemplate('OtherProPrint');
 }
Example #5
0
 private function doPost(ZOL_Request $input, ZOL_Response $output)
 {
     $db = Db_Andyou::instance();
     $res = $output->data;
     if ($res) {
         $data = array();
         foreach ($res as $re) {
             $re["site"] = $output->sysName;
             $re["objId"] = $re["id"];
             unset($re["id"]);
             unset($re['rowTm']);
             $data[] = $re;
         }
         $jsonstr = base64_encode(api_json_encode($data));
         echo $jsonstr . "<hr/>";
         $token = md5($output->url . "AAFDFDF&RE3");
         $rtn = ZOL_Http::curlPost(array('url' => $output->yunUrl . "?" . $output->url . "&token={$token}", 'postdata' => "table={$output->table}&data={$jsonstr}", 'timeout' => 3));
         return $rtn;
     }
     return false;
 }
Example #6
0
 public function doDefault(ZOL_Request $input, ZOL_Response $output)
 {
     $sqlArr = array("create table `bno` (`id` int (11)   NOT NULL AUTO_INCREMENT  COMMENT 'ID',  `tm` int (11)   NOT NULL  COMMENT '日期' , PRIMARY KEY ( `id` )  )", "alter table `bno` add index `tm` ( `tm` )", "alter table `log_scorechange` add column `rsync` tinyint (1)  DEFAULT '0' NOT NULL  COMMENT '表示该记录是否同步到云端'", "update log_scorechange set rsync = 1", "alter table `log_cardchange` add column `rsync` tinyint (1)  DEFAULT '0' NOT NULL  COMMENT '表示该记录是否同步到云端'", "update log_cardchange set rsync = 1", "alter table `member` add column `upTm` int (11)   NOT NULL  COMMENT '信息修改时间'", "alter table `member` add column `rsync` tinyint (11)   NOT NULL  COMMENT '表示该记录是否同步到云端'", "create table `log_yunrsync` (    `id` int (11)   NOT NULL AUTO_INCREMENT ,  `name` varchar (20)   NOT NULL  COMMENT '同步实例名称',  `tm` int (20)   NOT NULL  COMMENT '同步时间' , PRIMARY KEY ( `id` )  )", "alter table `member` add column `site` varchar (11)   NOT NULL  COMMENT '来自哪个站点'", "alter table `member` add column `siteObjId` int (11)   NOT NULL  COMMENT '在那个站点的ID'", "alter table `memeberotherpro` add column `phone` varchar (20)   NOT NULL  COMMENT '电话' after `memberId`, add column `upTm` int (11)   NOT NULL  COMMENT '更新时间' after `ctype`, add column `site` varchar (20)   NOT NULL  COMMENT '站点' after `upTm`, add column `siteObjId` int (11)   NOT NULL  COMMENT '在那个站点的ID' after `site`", "alter table `log_useotherpro` add column `phone` varchar (20)   NOT NULL  COMMENT '电话' after `memberId`", "alter table `bills` add column `phone` varchar (20)   NOT NULL  COMMENT '会员电话' after `memberId`, add column `rsync` tinyint (1)   NOT NULL  COMMENT '是否同步' after `isBuyScore`", "alter table `memeberotherpro` add column `rsync` tinyint (1)   NOT NULL  COMMENT '是否同步'", "alter table `product` add column `rowTm` timestamp   NOT NULL  COMMENT '更新时间戳'", "alter table `staff` add column `rowTm` timestamp   NOT NULL  COMMENT '更新时间戳'", "alter table `membercate` add column `rowTm` timestamp   NOT NULL  COMMENT '更新时间戳'", "alter table `productcate` add column `rowTm` timestamp   NOT NULL  COMMENT '更新时间戳'", "alter table `staffcate` add column `rowTm` timestamp   NOT NULL  COMMENT '更新时间戳'", "alter table `options` add column `rowTm` timestamp   NOT NULL  COMMENT '更新时间戳'", "alter table `billsitem` add column `rowTm` timestamp   NOT NULL  COMMENT '更新时间戳'");
     $db = Db_Andyou::instance();
     if ($sqlArr) {
         foreach ($sqlArr as $sql) {
             echo $sql . "<br/>";
             $db->query($sql);
         }
     }
     $sql = "select memberId from memeberotherpro where phone = '' union select memberId from log_useotherpro where phone = ''";
     $res = $db->getAll($sql);
     if ($res) {
         foreach ($res as $re) {
             $memberId = $re["memberId"];
             $minfo = Helper_Member::getMemberInfo(array('id' => $memberId));
             $phone = $minfo["phone"];
             $db->query("update memeberotherpro set phone = '{$phone}' where memberId = {$memberId}");
             $db->query("update log_useotherpro set phone = '{$phone}' where memberId = {$memberId}");
         }
     }
     echo "OK";
 }
Example #7
0
 /**
  * 获得数据列表
  */
 public function doDefault(ZOL_Request $input, ZOL_Response $output)
 {
     $wArr = array();
     #搜索字段
     $whereSql = "";
     $page = (int) $input->get('page') < 1 ? 1 : (int) $input->get('page');
     $output->sername = $wArr['name'] = $input->get('name');
     $output->sercode = $wArr['code'] = $input->get('code');
     $output->sercateId = $wArr['cateId'] = $input->get('cateId');
     if (!empty($wArr)) {
         foreach ($wArr as $k => $v) {
             if (gettype($v) == 'string') {
                 $whereSql .= !empty($v) ? ' AND ' . $k . ' like binary "%' . $v . '%" ' : '';
             } else {
                 $whereSql .= !empty($v) ? ' AND ' . $k . '=' . $v : '';
             }
         }
     }
     $pageUrl = "?c={$output->ctlName}&a={$output->actName}&page={$page}&name={$wArr['name']}&code={$wArr['code']}&cateId={$wArr['cateId']}";
     $pageSize = 30;
     $orderSql = "order by id desc";
     $data = Helper_Dao::getList(array('dbName' => "Db_Andyou", 'tblName' => "product", 'cols' => "*", 'pageSize' => $pageSize, 'page' => $page, 'pageUrl' => $pageUrl, 'whereSql' => $whereSql, 'orderSql' => $orderSql, 'iswrite' => true, 'pageTpl' => 9));
     //获得符合条件的库存总量
     $db = Db_Andyou::instance();
     $sql = "select sum(stock) sumstock,sum(stock*price) sumprice from product where ctype = 1 {$whereSql}";
     $tmp = $db->getRow($sql);
     $output->sumstock = $tmp["sumstock"];
     $output->sumprice = $tmp["sumprice"];
     if ($data) {
         $output->pageBar = $data['pageBar'];
         $output->allCnt = $data['allCnt'];
         $output->data = $data['data'];
         $output->pageUrl = $pageUrl;
     }
     $output->cateInfo = Helper_Product::getProductCatePairs();
     $output->setTemplate('ProductSm');
 }
Example #8
0
 /**
  *  记录会员获得会员卡余额历史
  */
 public static function getOtherPros($params)
 {
     $options = array('id' => false, 'phone' => false, 'cardno' => false);
     if (is_array($params)) {
         $options = array_merge($options, $params);
     }
     extract($options);
     $whereSql = '';
     if (!$id && !$phone && !$name && !$phoneOrCardno) {
         return false;
     }
     if ($id) {
         $whereSql .= "and m.id = '{$id}' ";
     }
     if ($phone) {
         $whereSql .= "and m.phone = '{$phone}' ";
     }
     if ($cardno) {
         $whereSql .= "and m.cardno = '{$cardno}' ";
     }
     if ($phoneOrCardno) {
         $whereSql .= "and (m.cardno = '{$phoneOrCardno}' or m.phone = '{$phoneOrCardno}') ";
     }
     $db = Db_Andyou::instance();
     $sql = "select p.id,p.proId,p.name,p.proName,p.num,p.ctype,p.buytm from member m left join memeberotherpro p on m.id = p.memberId where p.num > 0  " . $whereSql;
     $data = $db->getAll($sql);
     return $data;
 }
Example #9
0
 private function doPost(ZOL_Request $input, ZOL_Response $output)
 {
     $db = Db_Andyou::instance();
     $res = $output->data;
     if ($res) {
         $data = array();
         foreach ($res as $re) {
             $re["site"] = $output->sysName;
             //获得会员的信息
             if (in_array($output->table, array("log_scorechange", "log_cardchange"))) {
                 $minfo = Helper_Member::getMemberInfo(array("id" => $re["memberId"]));
                 $re["phone"] = $minfo["phone"];
             }
             if (in_array($output->table, array("bills"))) {
                 if (empty($re["phone"])) {
                     $minfo = Helper_Member::getMemberInfo(array("id" => $re["memberId"]));
                     $re["phone"] = $minfo["phone"];
                     $db->query("update {$output->table} set phone = '{$minfo["phone"]}' where memberId = {$re["memberId"]}");
                 }
             }
             $data[] = $re;
         }
         $jsonstr = base64_encode(api_json_encode($data));
         echo $jsonstr . "<hr/>";
         $token = md5($output->url . "AAFDFDF&RE3");
         $rtn = ZOL_Http::curlPost(array('url' => $output->yunUrl . "?" . $output->url . "&token={$token}", 'postdata' => "table={$output->table}&data={$jsonstr}", 'timeout' => 3));
         return $rtn;
     }
     return false;
 }
Example #10
0
 /**
  * 获得会员分类管理列表
  */
 public static function getProductCatePairs()
 {
     $db = Db_Andyou::instance();
     return $db->getPairs("select id,name from productcate ", "id", "name");
 }
Example #11
0
 /**
  *  更新用户会员卡余额
  */
 public function doUpCard(ZOL_Request $input, ZOL_Response $output)
 {
     $mid = (int) $input->post("mid");
     $card = (int) $input->post("card");
     $direction = (int) $input->post("direction");
     $remark = $input->post("remark");
     $staffid = (int) $input->post('staffid');
     $urlStr = "?c={$output->ctlName}";
     if ($mid == 0) {
         echo "<script>alert('Error!');document.location='{$urlStr}';</script>";
         exit;
     }
     if ($card < 0) {
         $card = -$card;
     }
     //生成一个单号
     $output->bno = Helper_Bill::getCommonMaxBno();
     #获得会员信息
     $minfo = Helper_Member::getMemberInfo(array("id" => $mid));
     if (!$minfo) {
         echo "<script>alert('Member Error!');document.location='{$urlStr}';</script>";
         exit;
     }
     if ($direction == 1) {
         //减分的时候判断用户是否有这么多
         if ($minfo["balance"] < $card) {
             echo "<script>alert('Balance Error!');document.location='{$urlStr}';</script>";
             exit;
         }
     }
     $db = Db_Andyou::instance();
     $op = $direction == 1 ? "-" : "+";
     $sql = "update member set balance = balance {$op} {$card} where id = {$mid}";
     $db->query($sql);
     $logItem = array("memberId" => $mid, "direction" => $direction, "card" => $card, "dateTm" => SYSTEM_TIME, "adminer" => $output->admin, "remark" => $remark, "orgCard" => $minfo["balance"], "staffid" => $staffid, "bno" => $output->bno);
     $data = Helper_Dao::insertItem(array('addItem' => $logItem, 'dbName' => 'Db_Andyou', 'tblName' => 'log_cardchange'));
     if ($direction != 1) {
         //充值大小票
         $output->money = $card;
         #充值的钱
         $output->nowBalance = $card + $minfo["balance"];
         $output->memberInfo = $minfo;
         $staffArr = Helper_Staff::getStaffPairs();
         $output->staffName = $staffArr[$staffid];
         Helper_Bill::createOneCommonBno();
         //生成一个通用订单号
         $output->setTemplate("CardPrint");
     } else {
         echo "<script>document.location='{$urlStr}';</script>";
         exit;
     }
 }
Example #12
0
 public function doDone(ZOL_Request $input, ZOL_Response $output)
 {
     $billInfo = $input->post("bill");
     $itemIdArr = $input->post("item_id");
     //所有产品ID
     $itemDiscArr = $input->post("item_disc");
     //所有产品折扣
     $itemNumArr = $input->post("item_num");
     //所有产品产品数量
     $staffid = (int) $input->post("staffid");
     //员工
     $isBuyScore = (int) $input->post("isBuyScore");
     //是否是从积分兑换页面的提交
     $remark = $input->post("remark");
     //填写的备注
     $endSumModifyFlag = (int) $input->post("endSumModifyFlag");
     //是否手工调整了最总价格
     $endBillPrice = $billInfo["bill_end_sum"];
     //最终的价格,这个价格是可以修改的
     $db = Db_Andyou::instance();
     //----------------------
     //获得会员信息
     //----------------------
     $memberId = (int) $input->post("memberId");
     //会员ID
     $memberInfo = Helper_Member::getMemberInfo(array("id" => $memberId));
     if ($memberInfo) {
         $memberScore = $memberInfo["score"];
         //会员的积分
         $memberCard = $memberInfo["balance"];
         //会员的卡内余额
     } else {
         //如果没有这个会员
         $memberScore = $memberCard = 0;
         $billInfo["bill_member_card"] = 0;
         //传递过来的会员扣费,强制失效掉
         $billInfo["bill_member_score"] = 0;
     }
     //----------------------
     //获得说有的商品信息
     //----------------------
     $proInfoArr = array();
     $sumPrice = 0;
     //原价总金额
     $orgSumPrice = 0;
     //商品总额
     //折扣获得的金额
     $discGetMoney = 0;
     //记录所有商品的总价格
     $itemSumPrice = 0;
     //判断是否购买了其他的服务,如次卡
     $hasBuyOtherPro = false;
     $otherProItemArr = array();
     if ($itemIdArr) {
         foreach ($itemIdArr as $idx => $pid) {
             $proInfo = Helper_Product::getProductInfo(array('id' => $pid));
             $num = (int) $itemNumArr[$idx];
             $price = $num * $proInfo["oprice"] * $itemDiscArr[$idx];
             $orgSumPrice += $num * $proInfo["oprice"];
             $sumPrice += $price;
             $itemSumPrice += $price;
             $proInfoArr[] = array('proId' => $pid, 'num' => $num, 'discount' => $itemDiscArr[$idx], 'price' => $price, 'staffid' => $staffid);
             if ($proInfo["ctype"] != 1) {
                 //购买非商品类的服务
                 $hasBuyOtherPro = true;
                 $otherProItemArr[] = array('info' => $proInfo, 'num' => $num);
             }
         }
     }
     //生成一个单号
     #$bno = Helper_Bill::getMaxBno();
     $bno = Helper_Bill::getCommonMaxBno();
     //----------------------
     //计算总金额
     //----------------------
     $billDisc = $billInfo["bill_disc"];
     //总折扣
     $sumPriceAftDisc = $sumPrice;
     //$orgSumPrice * $billDisc;//总折扣的价格  $sumPrice * $billDisc; //不可以给商品设置单价了
     $discGetMoney = $orgSumPrice - $sumPriceAftDisc;
     //折扣省下来的金额
     //扣除会员卡内余额
     $leftCard = $memberCard;
     //扣除后,卡内还有的余额
     $useCardFlag = false;
     $useCardMoney = 0;
     if ($sumPriceAftDisc && $memberCard && $billInfo["bill_member_card"]) {
         $useCard = min($memberCard, $billInfo["bill_member_card"]);
         $useCard = $useCard * 100;
         $useCard = min($useCard, $sumPriceAftDisc);
         //卡余额和收费的金额比较
         $leftCard = $memberCard - $useCard / 100;
         $useCardMoney = $useCard / 100;
         //记录用了多少卡的金额
         $sumPriceAftDisc = $sumPriceAftDisc - $useCard;
         $useCardFlag = true;
     }
     //会员积分计算
     $sysOptions = Helper_Option::getAllOptions();
     $scoreRatio = !empty($sysOptions["ScoreRatio"]) ? $sysOptions["ScoreRatio"]["value"] : 0;
     $useScore = (int) $billInfo["bill_member_score"];
     if ($useScore && $memberScore > 0) {
         $duihuanRatio = !empty($sysOptions["DuihuanRatio"]) ? $sysOptions["DuihuanRatio"]["value"] : 0;
         $sumPriceAftDisc = $sumPriceAftDisc - round($useScore / $duihuanRatio) * 100;
     }
     /*
              * 先不用会员积分了
             if($sumPriceAftDisc && $memberScore && $billInfo["bill_member_score"]){
                 $useScore = min($memberScore,$billInfo["bill_member_score"]);//需要花多少积分,避免比用户的积分还多
                 
                 //将用户的积分转换成钱
                 $scoreMoney = round($useScore / $scoreRatio,2);// 9 = 270 /30
                 $scoreMoney = $scoreMoney * 100;             // 900 = 9 * 100
                 $scoreMoney = min($scoreMoney,$sumPriceAftDisc); //避免花费的积分比剩余金额还多 
                 
                 $sumPriceAftDisc = $sumPriceAftDisc - $scoreMoney;
                 
             }*/
     //获得订单的信息
     $sumPriceAftDisc = round($sumPriceAftDisc / 100) * 100;
     //金额的四舍五入
     $billDetail = array('useScore' => $useScore, 'useScoreAsMoney' => round($scoreMoney / 100, 2), 'useCard' => $billInfo["bill_member_card"], 'price' => $sumPriceAftDisc, 'discount' => $billDisc, 'orgPrice' => $orgSumPrice, 'staffid' => $staffid, 'memberId' => $memberId, 'bno' => $bno, 'tm' => SYSTEM_TIME, 'dateDay' => date("Ymd"), 'memberScore' => $memberScore, 'memberCard' => $memberCard, 'remark' => $remark, 'isBuyScore' => $isBuyScore);
     if ($memberInfo) {
         $billDetail["phone"] = $memberInfo["phone"];
     }
     //如果销售眼前台修改了应收款,不是计算出来的,就记录
     if ($endSumModifyFlag) {
         if ($sumPriceAftDisc != $endBillPrice) {
             $billDetail["priceTrue"] = $billDetail["price"];
             $billDetail["price"] = $endBillPrice * 100;
             //使用销售员修改的
         }
     }
     //积分的重新计算
     //         =  积分剩余额                                    +  实际消费产品的积分
     $leftScore = $memberScore - (int) $billDetail["useScore"] + ($billDetail["price"] / 100 + $billDetail["useCard"]) * $scoreRatio;
     $memLeftInfo = array();
     $memLeftInfo['score'] = round($leftScore);
     if ($useCardFlag) {
         //使用了会员卡
         $memLeftInfo['balance'] = $leftCard;
     }
     //计算用户的总消费额
     $memLeftInfo['allsum'] = $memberInfo['allsum'] + $endBillPrice + $billInfo["bill_member_card"];
     //记入订单库
     $output->newScore = (int) (($billDetail['useCard'] + $billDetail['price'] / 100) * $scoreRatio);
     //获得的积分
     $billDetail["getScore"] = $output->newScore;
     $bid = Helper_Dao::insertItem(array('addItem' => $billDetail, 'dbName' => 'Db_Andyou', 'tblName' => 'bills'));
     //记入订单详情
     if ($proInfoArr) {
         foreach ($proInfoArr as $item) {
             //补充信息
             $item["bid"] = $bid;
             $item["bno"] = $bno;
             $item["memberId"] = $memberId;
             $item["tm"] = SYSTEM_TIME;
             Helper_Dao::insertItem(array('addItem' => $item, 'dbName' => 'Db_Andyou', 'tblName' => 'billsitem'));
         }
     }
     //更新用户详情信息
     Helper_Dao::updateItem(array('editItem' => $memLeftInfo, 'dbName' => 'Db_Andyou', 'tblName' => 'member', 'where' => ' id=' . $memberId));
     $staffArr = Helper_Staff::getStaffPairs();
     //更新商品的库存情况
     if ($itemIdArr) {
         foreach ($itemIdArr as $idx => $pid) {
             $num = (int) $itemNumArr[$idx];
             $db->query("update product set stock = stock - {$num} where id =  {$pid} ");
             /*
                            $proInfo = Helper_Product::getProductInfo(array('id'=>$pid));
                            $stock   = (int)$proInfo["stock"];
                            if($stock){
                $num = (int)$itemNumArr[$idx];
                $stock = $stock - $num;
                //if($stock < 0)$stock = 0; 不限制负数了,一直减下去
                
                 Helper_Dao::updateItem(array(
                         'editItem'       =>  array("stock"=>$stock),
                         'dbName'         =>  'Db_Andyou',
                         'tblName'        =>  'product',
                         'where'          =>  ' id=' . $pid, 
                 ));
                
                            }
             */
         }
     }
     //记录积分历史
     if ($output->newScore && $memberId) {
         //记录自己的积分历史
         Helper_Member::addScoreLog(array('memberId' => $memberId, 'direction' => 0, 'score' => $output->newScore, 'orgScore' => $memberInfo["score"], 'bno' => $bno, 'remark' => '消费'));
         //给介绍人增加积分
         if ($sysOptions && !empty($sysOptions["MemberParentRatio"]) && !empty($sysOptions["MemberParentRatio"]["value"])) {
             $introducerId = $memberInfo["introducerId"];
             $introducer = $memberInfo["introducer"];
             if (empty($memberInfo["allsum"])) {
                 //如果用户从来没有消费过,也就是第一次消费才给介绍人增加积分
                 if (!$introducerId || !$introducer) {
                     #如果没有ID,就尝试活儿
                     $introInfo = Helper_Member::getMemberInfo(array('phone' => $introducer, 'id' => $introducerId));
                     $introducerId = $introInfo["id"];
                     $iscore = $output->newScore * $sysOptions["MemberParentRatio"]["value"];
                     //更新积分
                     $sql = "update member set score = score + {$iscore}  where id = {$introducerId}";
                     $db->query($sql);
                     //记录积分
                     Helper_Member::addScoreLog(array('memberId' => $introducerId, 'direction' => 0, 'score' => $iscore, 'orgScore' => $introInfo["score"], 'bno' => $bno, 'remark' => '介绍【' . $memberInfo["phone"] . "-" . $memberInfo["name"] . '】消费得积分' . $output->newScore . '*' . $sysOptions["MemberParentRatio"]["value"]));
                 }
             }
         }
     }
     //记录会员会员卡使用记录
     if ($memberId && $billDetail["useCard"]) {
         Helper_Member::addCardLog(array('memberId' => $memberId, 'direction' => 1, 'card' => $billDetail["useCard"], 'orgCard' => $memberInfo["balance"], 'bno' => $bno, 'remark' => '消费'));
     }
     //记录会员会员卡使用记录
     if ($memberId && $billDetail["useScore"]) {
         Helper_Member::addScoreLog(array('memberId' => $memberId, 'direction' => 1, 'score' => $billDetail["useScore"], 'orgScore' => $memberInfo["score"], 'bno' => $bno, 'remark' => '积分兑换'));
     }
     //记录订单的一些额外的信息,但是不记录到数据库
     $billDetail['itemSumPrice'] = $itemSumPrice;
     //所有商品折扣后的累计金额
     //购买了其他商品的服务,如次卡
     if ($hasBuyOtherPro && $memberId) {
         foreach ($otherProItemArr as $re) {
             $info = $re["info"];
             $num = (int) $re["num"];
             $tmpRow = array('memberId' => $memberId, 'phone' => $memberInfo["phone"], 'proId' => $info["id"], 'name' => $info["othername"], 'proName' => $info["name"], 'num' => $info["num"], 'ctype' => $info["ctype"], 'buytm' => SYSTEM_TIME);
             $tmpLogRow = array('memberId' => $memberId, 'phone' => $memberInfo["phone"], 'otherproId' => $info["id"], 'name' => $info["othername"], 'direction' => 0, 'cvalue' => $info["num"], 'orgcvalue' => 0, 'ctype' => $info["ctype"], 'dateTm' => SYSTEM_TIME, 'staffid' => $staffid, 'bno' => $bno);
             //记录用户的所有服务
             for ($i = 0; $i < $num; $i++) {
                 Helper_Dao::insertItem(array('addItem' => $tmpRow, 'dbName' => 'Db_Andyou', 'tblName' => 'memeberotherpro'));
                 //数据变化日志
                 Helper_Dao::insertItem(array('addItem' => $tmpLogRow, 'dbName' => 'Db_Andyou', 'tblName' => 'log_useotherpro'));
             }
         }
     }
     //准备进入打印页面
     $output->bno = $bno;
     $output->bid = $bid;
     $output->bsn = substr(md5($bid . "HOOHAHA"), 0, 10);
     $output->billDetail = $billDetail;
     $output->proInfoArr = $proInfoArr;
     $output->memLeftInfo = $memLeftInfo;
     $output->staffid = $staffid;
     $output->staffName = $staffArr[$staffid];
     $output->memberInfo = $memberInfo;
     //会员信息
     $output->discGetMoney = $discGetMoney;
     //折扣省下的钱
     $output->orgSumPrice = $orgSumPrice;
     //原始总价
     $output->isBuyScore = $isBuyScore;
     Helper_Bill::createOneCommonBno();
     //生成一个通用订单号
     $output->setTemplate('BillPrint');
 }
Example #13
0
 /**
  * 添加记录
  */
 public function doAddItem(ZOL_Request $input, ZOL_Response $output)
 {
     $Arr = array();
     $name = $Arr['name'] = $input->post('name');
     $code = $Arr['code'] = $input->post('code');
     $Arr['cateId'] = $input->post('cateId');
     $Arr['price'] = $input->post('price');
     $Arr['inPrice'] = $input->post('inPrice');
     $Arr['stock'] = $input->post('stock');
     $Arr['score'] = $input->post('score');
     $Arr['discut'] = $input->post('discut');
     $Arr['canByScore'] = (int) $input->post('canByScore');
     $Arr['addtm'] = SYSTEM_TIME;
     $Arr['ctype'] = (int) $input->post('ctype');
     $Arr['othername'] = $input->post('othername');
     $Arr['num'] = (int) $input->post('num');
     //产品报价,保存以分为单位的价格
     $Arr['price'] = $Arr['price'] * 100;
     $Arr['inPrice'] = $Arr['inPrice'] * 100;
     $pageUrl = $input->request('pageUrl');
     $urlStr = $pageUrl ? $pageUrl : "?c={$output->ctlName}&t={$output->rnd}";
     if (!$name || !$code) {
         echo "<script>alert('请填写完整,数据不能为空!')</script>";
         echo "<script>document.location='{$urlStr}';</script>";
         exit;
     }
     //查看是否已经入库了
     $db = Db_Andyou::instance();
     $sql = "select 'x' from product where name = '{$name}' and code = '{$code}' limit 1";
     $has = $db->getOne($sql);
     if ($has) {
         //是否存在
         echo "<script>alert('该商品已经存在了,不能重复添加!')</script>";
         echo "<script>document.location='{$urlStr}';</script>";
         exit;
     }
     $pid = Helper_Dao::insertItem(array('addItem' => $Arr, 'dbName' => 'Db_Andyou', 'tblName' => 'product'));
     //记录入库日志
     if ($Arr['ctype'] == 1) {
         //次卡不记录日志了
         //记录日志 log_productInStorage
         $item = array('proId' => $pid, 'adminer' => $output->admin, 'dateTm' => SYSTEM_TIME, 'orgNum' => 0, 'addNum' => $Arr['stock'], 'cateId' => $Arr["cateId"], 'name' => $Arr["name"], 'code' => $Arr["code"]);
         Helper_Dao::insertItem(array('addItem' => $item, 'dbName' => 'Db_Andyou', 'tblName' => 'log_productInStorage'));
     }
     if (!$pid) {
         echo "<script>alert('添加失败,请重新添加!')</script>";
     }
     /*backUrl*/
     echo "<script>document.location='{$urlStr}';</script>";
     exit;
 }
Example #14
0
 /**
  * 获得会员分类管理列表
  */
 public static function getStaffPairs()
 {
     $db = Db_Andyou::instance();
     return $db->getPairs("select id,name from staff", "id", "name");
 }