<?php

/**
 * luffy丶大叔 
 * <><><><><><><><><><><><><>有妹子加微信不哦！~<><><><><><><><><><><><><><><><>
 * $Author: luffy丶大叔 
 * $Z 2015-4-14 16:19:51
 * $email luffy00789@126.com
 * $encoding UTF-8
 * $ Copyright (c) 2014-2015, http://www.globex.cn. All Rights Reserved.
 */
class Lib_Exception {
    

    /**
     * 产品备案异常
     */
    public function productbeian() {
        $_24hoursAgo    =   date('Y-m-d H:i:s',strtotime("-24 hours"));
        //避免重复
        $count  =   Service_Exception::getByCondition(array(
            'et_code'   =>  'productbeian',
            'array_e_status'  =>  array(0,1)
        ),'count(*)');
        if($count > 0)return;
        
        $uGoods['pg_status'] = 2;
        $uGoods['_string'] = "pg_update_time < '{$_24hoursAgo}'";
        $productGoods    =   Service_ProductGoods::getByCondition($uGoods);
        $exception  =   [];
        if($productGoods){
            $exception[]  =   ['客户代码','产品SKU','产品条码','创建时间'];
            foreach($productGoods AS $key=>$val){                
                //产品有可能被删除
                $product    =   Service_Product::getByField($val['goods_code'],'goods_id');
                if($product && isset($product['goods_id'])){
                    $exception[]    =   [$product['customer_code'] , $product['product_sku'] , $product['product_barcode'] , $val['pg_update_time']];                                        
                }
                      
            }            
            Service_Exception::addExceptionByCode('productbeian','此异常无参考号' , $exception);
        }
    }
    
    /**
     * 客户预付款报警
     */
    public function customeramount() {        
        //避免重复
        $count  =   Service_Exception::getByCondition(array(
            'et_code'   =>  'customeramount',
            'array_e_status'  =>  array(0,1)
        ),'count(*)');
        if($count > 0)return;
        
        $customerBalance    =   Service_CustomerBalance::getLeftJoinByCondition(array(
            'availableLt'   =>  1000,
            'cash_type'     =>  1
        ));
        $exception  =   [];
        if($customerBalance){    
            $exception[]    =   ['客户代码','可用余额','币种'];           
            foreach ($customerBalance as  $value) {                 
                $cb =   $value['cb_value'] - $value['cb_hold_value'];
                $exception[]    =   [$value['customer_code'] , $cb , $value['customer_currency']];           
            }          
            Service_Exception::addExceptionByCode('customeramount','此异常无参考号' , $exception);
        }
        
    }
    
    
}
