Withdrawal.php 2.92 KB
<?php
/**
 * Created by PhpStorm.
 * User: scott
 * Date: 3/30/20
 * Time: 3:24 PM
 */
class Withdrawal
{
    const STATUS_WAIT_APPROVE = 1;//待审核
    const STATUS_APPROVE      = 2;//通过
    const STATUS_REJECT       = 3;//拒绝

    /**
     * @param $id
     * @return bool
     */
    static function rejectWithdrawal($id)
    {
        $res = pdo_update('cjdc_withdrawal', array('state'=> self::STATUS_REJECT, 'sh_time' => date('Y-m-d H:i:s')), array('id' => $id));
        return $res;
    }

    /**
     * @param $storeId
     * @param $status
     * @return bool
     */
    static function getWithdrawalMoney($uniacid, $storeId, $status)
    {
        return pdo_get('cjdc_withdrawal', array('store_id' => $storeId,'uniacid' => $uniacid, 'state '=> $status ), array('sum(tx_cost) as tx_cost'));
    }

    /**
     * 提现中的金额
     * @param $storeId
     * @return bool
     */
    static function getWithdrawalingMoney($uniacid, $storeId)
    {
        return self::getWithdrawalMoney($uniacid, $storeId, self::STATUS_WAIT_APPROVE);
    }

    /**
     * @param $storeId
     * @return bool
     */
    static function getWithdrawaledMoney($uniacid, $storeId)
    {
        return self::getWithdrawalMoney($uniacid, $storeId, self::STATUS_APPROVE);
    }

    /**
     * 计算商店商品收入金额,非退款的金额
     * @param $uniacid
     * @param $storeId
     * @return bool
     */
    static function storeOrdersAmount($uniacid, $storeId)
    {
        //cjdc_order_price_stat
        $where      = " where a.uniacid=:uniacid and a.store_id=:store_id and a.pay_type in (1,2) and a.state in (4,5,10)";
        $selectSQL  = "select sum(ops.pay_price) as 'pay_price',sum(ops.goods_price) as goods_price, sum(ops.service_fee) as service_fee, sum(ops.wx_pay_fee) as wx_pay_fee ".
                      " from ". tablename("cjdc_order") ." as a".
                      " left join ". tablename("cjdc_order_price_stat") ." as ops on ops.order_id = a.id".
                      $where;
        $params     = [':uniacid' => $uniacid, ':store_id' => $storeId];
        $totalAmount = pdo_fetch($selectSQL, $params);

        return $totalAmount;
    }

    /**
     * 未结算的金额
     * @param $uniacid
     * @param $storeId
     * @return bool
     */
    static function storeOnWayAmount($uniacid, $storeId)
    {
        $where      = " where a.uniacid=:uniacid and a.store_id=:store_id and a.pay_type in (1,2) and a.state in (2,3,8) ";
        $selectSQL  = "select sum(ops.pay_price) as 'pay_price',sum(ops.goods_price) as goods_price, sum(ops.service_fee) as service_fee, sum(ops.wx_pay_fee) as wx_pay_fee ".
            " from ". tablename("cjdc_order") ." as a".
            " left join ". tablename("cjdc_order_price_stat") ." as ops on ops.order_id = a.id".
            $where;
        $params     = [':uniacid' => $uniacid, ':store_id' => $storeId];
        $totalAmount = pdo_fetch($selectSQL, $params);

        return $totalAmount;
    }
}