コード例 #1
0
ファイル: apiVisitStat.action.php プロジェクト: ohjack/newErp
 /**
  * ApiVisitStatAct::actIndex()
  * 列出符合条件的数据并分页显示
  * @param string $condition 查询条件
  * @param integer $curpage 页码
  * @param integer $pagenum 每页个数
  * @return array 
  */
 public function actIndex()
 {
     $data = array();
     $condition = '';
     $trackEmailStat = new ApiVisitStatModel();
     //接收参数生成条件
     $apiId = isset($_GET['apiId']) ? abs(intval($_GET['apiId'])) : 0;
     $curpage = isset($_GET['page']) ? abs(intval($_GET['page'])) : 1;
     $timeNode = isset($_GET['timeNode']) ? post_check(trim($_GET['timeNode'])) : '';
     $condition .= "1";
     if (!empty($apiId)) {
         $condition .= " AND apiId = '{$apiId}'";
     }
     if (!empty($timeNode)) {
         if (!in_array($timeNode, array('firstTime', 'lastTime'))) {
             redirect_to("index.php?mod=apiVisitStat&act=index");
         }
         $startTime = isset($_GET['startTime']) ? strtotime(trim($_GET['startTime']) . " 00:00:00") : strtotime(date("Y-m-d", time()) . " 00:00:00");
         $endTime = isset($_GET['endTime']) ? strtotime(trim($_GET['endTime']) . " 23:59:59") : strtotime(date("Y-m-d", time()) . " 23:59:59");
         if ($startTime && $endTime) {
             $condition .= ' AND ' . $timeNode . " BETWEEN '" . $startTime . "' AND " . "'" . $endTime . "'";
         }
     }
     //获取符合条件的数据并分页
     $pagenum = 20;
     $total = $trackEmailStat->modListCount($condition);
     $res = $trackEmailStat->modList($condition, $curpage, $pagenum);
     $page = new Page($total, $pagenum, '', 'CN');
     $pageStr = "";
     if ($res) {
         if ($total > $pagenum) {
             $pageStr = $page->fpage(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
         } else {
             $pageStr = $page->fpage(array(0, 1, 2, 3));
         }
     } else {
         $pageStr = '暂无数据';
     }
     //封装数据返回
     $data['apiId'] = $apiId;
     $data['lists'] = $res;
     $data['pages'] = $pageStr;
     $data['timeNode'] = $timeNode;
     $data['startTime'] = $startTime ? date('Y-m-d', $startTime) : '';
     $data['endTime'] = $endTime ? date('Y-m-d', $endTime) : '';
     $data['apiList'] = TransOpenApiModel::getApiCompetenceList();
     self::$errCode = trackEmailStatModel::$errCode;
     self::$errMsg = trackEmailStatModel::$errMsg;
     if (self::$errCode != 0) {
         show_message($this->smarty, self::$errMsg, "");
         return false;
     }
     return $data;
 }
コード例 #2
0
ファイル: apiVisitStat.model.php プロジェクト: ohjack/newErp
 /**
  * ApiVisitStatModel::updateApiVisitStat()
  * 更新API访问统计
  * @param integer $apiId api Id
  * @param integer $apiUid api Uid
  * @return array 结果集数组
  */
 public static function updateApiVisitStat($apiId, $apiUid)
 {
     self::initDB();
     $res = 0;
     $data = array();
     $times = time();
     $firstTime = strtotime(date('Y-m-d', $times) . " 00:00:01");
     $where = "apiId = '{$apiId}' AND apiUid = '{$apiUid}' AND firstTime >= '{$firstTime}'";
     $res = self::modListCount($where);
     if ($res > 0) {
         $sql = "UPDATE `" . self::$prefix . self::$table . "` SET apiCount = apiCount + 1,lastTime = '{$times}' WHERE apiId = '{$apiId}' AND apiUid = '{$apiUid}' AND firstTime >= '{$firstTime}'";
     } else {
         $data = array("apiId" => $apiId, "apiUid" => $apiUid, "apiCount" => 1, "firstTime" => $times, "lastTime" => $times);
         $sql = array2sql($data);
         $sql = "INSERT INTO `" . self::$prefix . self::$table . "` SET " . $sql;
     }
     $query = self::$dbConn->query($sql);
     if ($query) {
         return true;
     } else {
         self::$errCode = 10000;
         self::$errMsg = "执行SQL语句出错";
         return false;
     }
 }
コード例 #3
0
ファイル: transOpenApi.action.php プロジェクト: ohjack/newErp
 /**
  * TransOpenApiAct::act_openBestCarrierShipFee()
  * 开放批量最优运输方式费用接口
  * @param string $country 国家
  * @param float $weight 重量
  * @param int $shipAddId 发货地址ID
  * @param string $postCode 邮政编码
  * @param string $apiToken api调用token
  * @param string $noShipId 不参与计算的运输方式ID
  * @return array;
  */
 public function act_openBestCarrierShipFee()
 {
     $res = array();
     $data = array();
     $openFee = array();
     $noShipArr = array();
     $times = time();
     $usRate = 0;
     $exRates = array();
     $apiToken = isset($_REQUEST['apiToken']) ? post_check($_REQUEST['apiToken']) : '';
     $noShipId = isset($_REQUEST['noShipId']) ? post_check($_REQUEST['noShipId']) : '';
     $weightFlag = isset($_REQUEST['weightFlag']) ? post_check($_REQUEST['weightFlag']) : '';
     if (empty($apiToken)) {
         self::$errCode = 20001;
         self::$errMsg = 'API TOKEN 参数有误!';
         return false;
     }
     if (!empty($noShipId)) {
         if (!preg_match("/^([\\d]+,)*[\\d]+\$/", $noShipId)) {
             self::$errCode = 20002;
             self::$errMsg = '要排除的运输方式ID参数有误!';
             return false;
         } else {
             $noShipArr = explode(",", $noShipId);
         }
     }
     //检查API token 合法性
     $res = ApiCompetenceModel::getApiInfoByToken($apiToken);
     if (empty($res)) {
         self::$errCode = 20004;
         self::$errMsg = '当前API TOKEN数据不存在,请检查相关token数据!';
         return false;
     }
     $apiTokenExpire = isset($res['apiTokenExpire']) ? intval($res['apiTokenExpire']) : 0;
     $apiMaxCount = isset($res['apiMaxCount']) ? intval($res['apiMaxCount']) : 0;
     $apiName = isset($res['apiName']) ? $res['apiName'] : '';
     $apiValue = isset($res['apiValue']) ? $res['apiValue'] : '';
     $apiUid = isset($res['apiUid']) ? $res['apiUid'] : 0;
     $apiId = isset($res['id']) ? $res['id'] : 0;
     $maxCount = 0;
     if ($apiTokenExpire <= $times) {
         self::$errCode = 20003;
         self::$errMsg = '当前API TOKEN已过期,请更新API TOKEN!';
         return false;
     }
     if ($apiName !== 'openBestCarrierShipFee') {
         self::$errCode = 20004;
         self::$errMsg = '当前API调用接口名称有误,请检查!';
         return false;
     }
     if ($apiMaxCount > 0) {
         $s_time = strtotime(date('Y-m-d', $times) . " 00:00:01");
         $e_time = strtotime(date('Y-m-d', $times) . " 23:59:59");
         $res = ApiVisitStatModel::getStatByTime($apiId, $apiUid, $s_time, $e_time);
         $maxCount = isset($res['apiCount']) ? intval($res['apiCount']) : 0;
         if ($maxCount > $apiMaxCount) {
             self::$errCode = 20005;
             self::$errMsg = "当日当前API接口调用次数:{$maxCount},已超过最大次:{$apiMaxCount}!";
             return false;
         }
     }
     //API 接口调用统计
     $res = ApiVisitStatModel::updateApiVisitStat($apiId, $apiUid);
     if (!$res) {
         self::$errCode = 20006;
         self::$errMsg = "API 接口调用统计出错,请联系相关负责人处理!";
         return false;
     }
     //开放API运费计算
     $res = self::act_batchBestCarrier();
     $carriers = explode(",", $apiValue);
     foreach ($carriers as $v) {
         if (!empty($noShipArr)) {
             if (in_array($v, $noShipArr)) {
                 continue;
             }
         }
         $res = self::openFixCarrierQueryNew($v, $weightFlag);
         $totalFee = 0;
         // 开放价格 = 原价 + 开放折扣价
         $result = CarrierOpenModel::getCarrierOpenByCid($v);
         if (empty($res['totalFee'])) {
             continue;
         }
         $totalFee = ceil($res['totalFee'] + $res['totalFee'] * $result['carrierDiscount']);
         //针对运德物流的开放运费查询做美元转换
         if ($apiToken == 'e19d2feabc0eb1705f69c6ea2d9d0e1d') {
             $exRates = TransOpenApiModel::cacheExRateInfo(array('USD'), array('CNY'), 'usRate', 7200, 0);
             $usRate = round(floatval($exRates['USD/CNY']), 4);
             if ($usRate <= 0) {
                 continue;
             }
             $totalFee = ceil($totalFee / $usRate);
         }
         $openFee[] = array("carrierId" => $res['carrierId'], "channelId" => $res['channelId'], "totalFee" => $totalFee, "abb" => $result['carrierAbb'], "enName" => $result['carrierEn'], "aging" => $result['carrierAging'], "note" => $result['carrierNote']);
     }
     //对计算价格默认按照价格升序排列
     foreach ($openFee as $key => $row) {
         $fee[$key] = $row['totalFee'];
     }
     array_multisort($fee, SORT_ASC, $openFee);
     return $openFee;
 }