/**
  * ProductStockalarmModel::updateWarnNew()
  * 新更新选择料号的预警信息
  * @param array skuArr 料号数组
  * @param int gid 采购员ID
  * @return bool 
  */
 public static function updateWarnNew($sku)
 {
     self::initDB();
     $res = CommonModel::getSkuInfo($sku);
     print_r($res);
     exit;
     $res = json_decode($res, true);
     $days7 = 0.7;
     $days15 = 0.2;
     $days30 = 0.1;
     $dataarray = array();
     $run_starttime = time();
     $first_sale = CommonModel::getSkuFirstSaleTime($sku);
     $last_sale = CommonModel::getSkuLastSaleTime($sku);
     $stock_qty = CommonModel::getSkuStockqty($sku);
     // 实际库存
     $everyday_sale = $res[0]['everyday_sale'];
     // 每日均量
     $purchase_days = $res[0]['purchasedays'];
     // 采购天数
     $alert_days = $res[0]['goods_days'];
     // 预警天数
     $warehouse_id = 76;
     // 仓库编号
     $partner_id = 0;
     // 供应商编号
     $salensend = CommonModel::getSkuSalensend($sku);
     // 待发货数量
     $interceptnums = CommonModel::getSkuInterceptnums($sku);
     // 拦截数量
     $autointerceptnums = CommonModel::getSkuAutointerceptnums($sku);
     // 自动拦截数量
     $auditingnums = CommonModel::getSkuAuditingnums($sku);
     // 审核数量
     $hasbooknum = PurchaseOrderModel::hasBookNum($skuid, $warehouse_id, $purid);
     // 已订购数量
     $hasbooknum = !empty($hasbooknum) ? $hasbooknum : 0;
     if ($first_sale > 0) {
         $time = time() - $first_sale;
         $saleday = ceil($time / (3600 * 24));
         // 至今距离第一次卖出时间天数
         $thirtycheck = time() - 30 * 24 * 3600;
         // 一个月前
         $totalqty = $stock_qty + $hasbooknum;
         // 总库存=实际库存+已订购数量
         $hasuseqty = $totalqty - $salensend - $interceptnums - $auditingnums - $autointerceptnums;
         // 可用库存数量
         if ($saleday > 30) {
             if ($last_sale > $thirtycheck) {
                 // 最近一次卖出时间已经超过一个月
                 $end1 = strtotime(date('Y-m-d') . '23:59:59');
                 $start1 = $end1 - 7 * 24 * 3600;
                 $qty1 = CommonModel::getSkuSaleProducts($start1, $end1, $sku, $everyday_sale);
                 // getSaleNum($start1, $end1, $sku, $warehouse_id, $everyday_sale);//取1~7天销售量
                 $end2 = $start1;
                 $start2 = $end1 - 15 * 4 * 600;
                 $qty2 = CommonModel::getSkuSaleProducts($start2, $end2, $sku, $everyday_sale);
                 // getSaleNum($start1, $end1, $sku, $warehouse_id, $everyday_sale);//取1~7天销售量
                 $end3 = $start2;
                 $start3 = $end1 - 30 * 24 * 3600;
                 $qty3 = CommonModel::getSkuSaleProducts($start3, $end3, $sku, $everyday_sale);
                 // getSaleNum($start1, $end1, $sku, $warehouse_id, $everyday_sale);//取1~7天销售量
                 $everyday_sale = $qty1 / 7 * $days7 + $qty2 / 8 * $days15 + $qty3 / 15 * $days30;
                 // 每日均量计算
                 $needqty = ceil($everyday_sale * $alert_days) + $interceptnums;
                 // 库存预警警数量
                 $dataarray['everyday_sale'] = $everyday_sale > 0.005 ? round($everyday_sale, 2) : 0;
                 $dataarray['booknums'] = $hasbooknum;
                 $dataarray['salensend'] = $salensend;
                 $dataarray['auditingnums'] = $auditingnums;
                 $dataarray['interceptnums'] = $interceptnums;
                 $dataarray['autointerceptnums'] = $autointerceptnums;
                 $dataarray['is_warning'] = $hasuseqty < 1 || $hasuseqty < $needqty ? 1 : 0;
             } else {
                 $dataarray['everyday_sale'] = 0;
                 $dataarray['booknums'] = $hasbooknum;
                 $dataarray['salensend'] = $salensend;
                 $dataarray['auditingnums'] = $auditingnums;
                 $dataarray['interceptnums'] = $interceptnums;
                 $dataarray['autointerceptnums'] = $autointerceptnums;
                 $dataarray['is_warning'] = $hasuseqty < 0 ? 1 : 0;
             }
         } else {
             $end = strtotime(date('Y-m-d') . '23:59:59');
             $start = $end - ($saleday + 1) * 24 * 3600;
             $qty = 20;
             // getSaleNum($start, $end, $sku, $warehouse_id, $everyday_sale);
             $everyday_sale = $qty / $saleday;
             $needqty = ceil($everyday_sale * $alert_days) + $interceptnums;
             // 计算产品库存报警数量
             $dataarray['everyday_sale'] = round($everyday_sale, 2);
             $dataarray['booknums'] = $hasbooknum;
             $dataarray['salensend'] = $salensend;
             $dataarray['auditingnums'] = $auditingnums;
             $dataarray['interceptnums'] = $interceptnums;
             $dataarray['autointerceptnums'] = $autointerceptnums;
             $dataarray['is_warning'] = $hasuseqty < 1 || $hasuseqty < $needqty ? 1 : 0;
         }
     } else {
         $dataarray['everyday_sale'] = 0;
         $dataarray['booknums'] = $hasbooknum;
         $dataarray['salensend'] = 0;
         $dataarray['auditingnums'] = 0;
         $dataarray['interceptnums'] = 0;
         $dataarray['autointerceptnums'] = 0;
         $dataarray['is_warning'] = 0;
     }
     if ($needqty <= 0) {
         $dataarray['is_warning'] = 0;
     }
     $dataarray['lastupdate'] = time();
     $dataarray['factory'] = $res[0]['factory'];
     $dataarray['purchaseuser'] = $res[0]['purchaseuser'];
     $dataarray['storeid'] = $res[0]['storeid'];
     $dataarray['sevendays'] = $res[0]['sevendays'];
     $dataarray['fifteendays'] = $res[0]['fifteendays'];
     $dataarray['thirtydays'] = $res[0]['thirtydays'];
     $dataarray['ow_stock'] = $res[0]['ow_count'];
     $dataarray['it_stock'] = $res[0]['it_count'];
     $dataarray['stock_qty'] = $res[0]['goods_count'];
     $dataarray['purchaseDays'] = $res[0]['purchasedays'];
     $dataarray['alertDays'] = $res[0]['goods_days'];
     $dataarray['purchaseId'] = $_SESSION[C('USER_AUTH_SYS_ID')];
     $res = self::updateWarnInfo($sku, $dataarray);
     $run_endtime = time();
     $speed_time = $run_endtime - $run_starttime;
     if ($res) {
         return "料号:{$sku} 缓存更新成功!";
     } else {
         self::$errCode = 10001;
         self::$errMsg = "料号:{$sku} 缓存更新失败!";
         return false;
     }
 }