finance.inc.php 3.73 KB
<?php
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL); 
require_once IA_ROOT . '/addons/zh_cjdianc/inc/config.php';
require_once IA_ROOT . '/addons/zh_cjdianc/inc/class/Withdrawal.php';
global $_GPC, $_W;
$GLOBALS['frames']  = $this->getMainMenu2();
$storeid            = $_COOKIE["storeid"];
$operation          = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$cur_store          = $this->getStoreById($storeid);
$type               = isset($_GPC['type'])? $_GPC['type']:'today';
$pageindex          = max(1, intval($_GPC['page']));
$pagesize           = 10;
$system             = pdo_get('cjdc_system',array('uniacid'=> $_W['uniacid']));

$data[':uniacid']   = $_W['uniacid'];
$data[':store_id']  = $storeid;


$orderAmount        = Withdrawal::storeOrdersAmount($_W['uniacid'], $storeid);
$storeIncome        = 0;
if ($orderAmount) {
    //select sum(pay_price) as 'pay_price',sum(goods_price) as goods_price, sum(service_fee) as service_fee, sum(wx_pay_fee) as wx_pay_fee
    $storeIncome = $orderAmount['pay_price'] - $orderAmount['service_fee'] - $orderAmount['wx_pay_fee'] - $orderAmount['delivery_fee'];
}

//已申请金额
$applyWithdrawal    = Withdrawal::getWithdrawalingMoney($_W['uniacid'], $storeid);
//已提现金额
$withdrawaled       = Withdrawal::getWithdrawaledMoney($_W['uniacid'], $storeid);

//可提现金额
$ktxcost            = 0;
$withdrawaledAmount             = '0.00';
$applyWithdrawalAmount              = '0.00';
if ($withdrawaled['tx_cost']) {
  $withdrawaledAmount = $withdrawaled['tx_cost'];
}
if ($applyWithdrawal['tx_cost']) {
  $applyWithdrawalAmount = $applyWithdrawal['tx_cost'];
}

$balance = ($storeIncome - $withdrawaledAmount - $applyWithdrawalAmount);
//未入账
$onWayAmountArr     = Withdrawal::storeOnWayAmount($_W['uniacid'], $storeid);
$onWayAmount        = 0;

if ($onWayAmountArr) {
    $onWayAmount = $onWayAmountArr['pay_price'] - $onWayAmountArr['service_fee'] - $onWayAmountArr['wx_pay_fee'] - $onWayAmountArr['delivery_fee'];
}

$where2             = " where a.store_id={$storeid} ";

if($_GPC['time']) {
  $start    = strtotime($_GPC['time']['start']);
  $end      = strtotime($_GPC['time']['end']);
  $where2 .= " and UNIX_TIMESTAMP(a.time) >='{$start}' and UNIX_TIMESTAMP(a.time)<='{$end}'";
}

//提现记录
$withdrawalSql      = "SELECT {selectFields} ".
                    " FROM ".tablename('cjdc_withdrawal') .  " a"  .
                    " left join " . tablename("cjdc_store") . " b on a.store_id = b.id ".
                    $where2." ORDER BY a.time DESC";
$selectFields       = "a.*,b.name as store_name,b.user_id";
$pageSql            = str_replace('{selectFields}',$selectFields, $withdrawalSql);
$countSql           = str_replace('{selectFields}', "count(*)", $withdrawalSql);
$withdrawalCount    = pdo_fetchcolumn($countSql, $data);

$select_sql         = $pageSql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
$withdrawalCountList= pdo_fetchall($select_sql, $data);
$pager              = pagination($total, $pageindex, $pagesize);

/**
 * 提现申请
 */
if(checksubmit('submit2')) {
  $data2['name']    = $_GPC['name'];
  $data2['type']    = $_GPC['orderby'];
  $data2['time']    = date('Y-m-d H:i:s');
  $data2['state']   = 1;
  $data2['type']    = $_GPC['is_brand'];
  $data2['tx_cost'] = $_GPC['tx_cost'];
  $data2['sj_cost'] = $_GPC['tx_cost'];
  $data2['store_id']= $storeid;
  $data2['uniacid'] = $_W['uniacid'];
  $data2['yhk_num'] = $_GPC['yhk_num'];
  $data2['tel']     = $_GPC['tel'];
  $data2['yh_info'] = $_GPC['yh_info'];
  $res = pdo_insert('cjdc_withdrawal',$data2);
  if($res){
       message('添加成功!', $this->createWebUrl('finance'), 'success');
  }else{
       message('添加失败!','','error');
  }

}

include $this->template('web/finance');