Ejemplo n.º 1
0
 /**
  * CarrierOpenAct::act_delCarrierOpen()
  * 删除开放运输方式
  * @param int $id 开放运输方式ID
  * @return  bool
  */
 public function act_delCarrierOpen()
 {
     $id = isset($_POST["id"]) ? abs(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 = 10001;
         self::$errMsg = "对不起,您无数据删除权限!";
         return false;
     }
     if (empty($id) || !is_numeric($id)) {
         self::$errCode = 10000;
         self::$errMsg = "ID有误!";
         return false;
     }
     $res = CarrierOpenModel::delCarrierOpen($id);
     self::$errCode = CarrierOpenModel::$errCode;
     self::$errMsg = CarrierOpenModel::$errMsg;
     return $res;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 /**
  * CarrierOpenModel::delCarrierOpen()
  * 开放运输方式删除
  * @param integer $id 运输方式开放ID
  * @return bool
  */
 public static function delCarrierOpen($id)
 {
     self::initDB();
     $sql = "UPDATE `" . self::$prefix . self::$table . "` SET is_delete = 1 WHERE id = {$id}";
     $query = self::$dbConn->query($sql);
     if ($query) {
         $rows = self::$dbConn->affected_rows();
         if ($rows) {
             return $res;
         } else {
             self::$errCode = 10001;
             self::$errMsg = "删除数据失败";
             return false;
         }
     } else {
         self::$errCode = 10000;
         self::$errMsg = "执行SQL语句失败!";
         return false;
     }
 }