Example #1
0
 function pageindex($inPath)
 {
     $ymd = date('Y-m-d', time());
     if ($_POST) {
         $salesObj = new m_sales();
         $type = (int) $_POST['type'] ? (int) $_POST['type'] : 1;
         $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}";
         }
         switch ($type) {
             case 1:
                 $this->params['title'] = "销售统计(不含退款)";
                 $rs = $salesObj->select($condi, "dateymd,sum(num*price-refund_amount) as money", "group by dateymd")->items;
                 break;
             case 2:
                 $condi .= $condi ? " and refund_type>0" : " refund_type>0";
                 $this->params['title'] = "退货统计";
                 $rs = $salesObj->select($condi, "dateymd,sum(refund_amount) as money", "group by dateymd")->items;
                 break;
             case 3:
                 $this->params['title'] = "销售利润统计";
                 $rs = $salesObj->select($condi, "dateymd,sum((num-refund_num)*(price-in_price)) as money", "group by dateymd")->items;
                 break;
             case 4:
                 break;
         }
         $this->params['start'] = $start;
         $this->params['end'] = $end;
         $this->params['type'] = $type;
         $this->params['line'] = $this->linedata($rs);
     }
     return $this->render('statistics/index.html', $this->params);
 }
Example #2
0
 /**
  * 处理退货
  * @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);
 }