Esempio n. 1
0
 protected function _report_breach($where, $where_order)
 {
     $orderModel = new \Loan\Model\OrderModel();
     $data = [];
     $statModel = new \Loan\Model\StatModel();
     $statModel->updateBreach();
     $where = ['type' => ['in', [$statModel::TYPE_LOAN_MONEY_UNREPAY, $statModel::TYPE_LOAN_MONEY_BREACH, $statModel::TYPE_LOAN_MONEY_BREACH_REPAY, $statModel::TYPE_LOAN_MONEY_BREACH_UNREPAY]]];
     list($city, $is_city_id) = $this->_initRegion();
     if ($city > 0) {
         $where['university_id'] = ['exp', ' in (select university_id from zj_university_campus where ' . ($is_city_id ? 'city_id' : 'province_id') . '=' . $city . ')'];
     }
     for ($month = '2015-04-01'; $month < date('Y-m-01');) {
         $where['target_date'] = $month;
         $data[substr($month, 0, -3)] = $statModel->where($where)->group('type')->getField('type, sum(number)');
         $month = date('Y-m-d', strtotime('+1 month', strtotime($month)));
     }
     $where['target_date'] = date('Y-m-01');
     $data['当前'] = $statModel->where($where)->group('type')->getField('type, sum(number)');
     foreach ($data as &$row) {
         for ($i = 7; $i <= 10; $i++) {
             $row[$i] = number_format(isset($row[$i]) ? $row[$i] / 10000 : 0, 2);
         }
     }
     $this->assign('data', $data);
 }
    /**
     * @title 修复数据
     *
     * @method get
     */
    public function fix_loan_stat_today($type)
    {
        $statModel = new \Loan\Model\StatModel();
        in_array($type, ['in', $statModel::TYPE_ORDER_MONEY_CHECK_SUCCESS, $statModel::TYPE_ORDER_MONEY_LEND]) or $this->error('不支持此类型!');
        if ($type == $statModel::TYPE_ORDER_MONEY_CHECK_SUCCESS) {
            $contractModel = M()->table('zj_loan_order o')->join('zj_loan_order_contract c on
c.order_id=o.id')->join('zj_university_campus campus on
campus.id=o.campus_id');
            $orders = $contractModel->where(['c.check_time' => [['egt', strtotime(date('Y-m-d') . ' 00:00:00')]], 'c.check_status' => 1])->field('o.loan_money,c.check_time,campus.university_id')->select();
            $orders or die('no data');
            $statModel->where(['type' => $type, 'target_date' => date('Y-m-d')])->delete();
            foreach ($orders as $order) {
                $statModel->update($type, $order['university_id'], $order['loan_money'], $order['check_time']);
            }
            die('done');
        }
        if ($type == $statModel::TYPE_ORDER_MONEY_LEND) {
            $financeModel = M()->table('zj_loan_order o')->join('zj_loan_order_finance f on f.order_id=o.id')->join('zj_university_campus c on c.id=o.campus_id');
            $orders = $financeModel->where(['f.lend_time' => ['egt', strtotime(date('Y-m-d') . ' 00:00:00')]])->field('f.lend_money,f.lend_time,c.university_id')->select();
            $orders or die('no data');
            $statModel->where(['type' => $type, 'target_date' => date('Y-m-d')])->delete();
            foreach ($orders as $order) {
                $statModel->update($type, $order['university_id'], $order['lend_money'], $order['lend_time']);
            }
            die('done');
        }
    }