Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * ApiCompetenceAct::act_delApiCompetence()
  * 删除API开放授权
  * @param int $id 开放权限ID
  * @return  bool
  */
 public function act_delApiCompetence()
 {
     $gid = isset($_POST["id"]) ? intval(trim($_POST["id"])) : 0;
     $act = isset($_REQUEST["act"]) ? post_check($_REQUEST["act"]) : "";
     $mod = isset($_REQUEST["mod"]) ? post_check($_REQUEST["mod"]) : "";
     if (!AuthUser::checkLogin($mod, $act)) {
         self::$errCode = 30001;
         self::$errMsg = "对不起,您无数据删除权限!";
         return false;
     }
     if (empty($gid) || !is_numeric($gid)) {
         self::$errCode = 30000;
         self::$errMsg = "开放用户权限ID有误!";
         return false;
     }
     $res = ApiCompetenceModel::delApiCompetence($gid);
     self::$errCode = ApiCompetenceModel::$errCode;
     self::$errMsg = ApiCompetenceModel::$errMsg;
     return $res;
 }
Example #3
0
 /**
  * ApiCompetenceModel::getApiCompetenceById()
  * 获取某个用户API开放授权信息
  * @param integer $gid 用户GID
  * @return array
  */
 public static function getApiCompetenceById($gid)
 {
     self::initDB();
     $sql = "SELECT * FROM `" . self::$prefix . self::$table . "` WHERE apiUid = {$gid}";
     $query = self::$dbConn->query($sql);
     if ($query) {
         return self::$dbConn->fetch_array_array($query);
     } else {
         self::$errCode = 10000;
         self::$errMsg = "执行SQL语句出错";
         return false;
     }
 }