Commit 253bbd7d authored by 吴贤德's avatar 吴贤德

站点改造:

1.实时下线接口修改 2.媒资更新接口 3.媒资推送接口
parent f193b0ef
...@@ -97,30 +97,33 @@ class CenterAction extends Action ...@@ -97,30 +97,33 @@ class CenterAction extends Action
* 返回说明: * 返回说明:
* {"code":0,"msg":"ok"} * {"code":0,"msg":"ok"}
* code : 0-成功,101,1001-传入的媒资参数有问题,2001-下线失败 * code : 0-成功,101,1001-传入的媒资参数有问题,2001-下线失败
* 注意:
* 站点改造:spid传入siteid
* key从站点表获取 offline_key
* 下线云端片库,下线关联站点的所以合作方酒店片库
*/ */
public function media_offline(){ public function media_offline(){
$spid = $_GET["spid"]; $siteid = $_GET["spid"];
$mid = $_GET["mid"]; $mid = $_GET["mid"];
$sw_time = $_GET["sw_time"]; $sw_time = $_GET["sw_time"];
$sw_sign =$_GET["sw_sign"]; $sw_sign =$_GET["sw_sign"];
$status = 2; $status = 2;
$modelSP=D("Conf"); $modelSite=D("Site");
$whereSP["sp_id"]=$spid; $whereSite["id"]=$siteid;
$whereSP["type_code"]="api_key"; $spConf=$modelSite->field("offline_key")->where($whereSite)->find();
$spConf=$modelSP->field("v")->where($whereSP)->find(); $key = $spConf["offline_key"];
$key = $spConf["v"];
if ($key) { if ($key) {
$pre_sign = "$spid&$mid&$sw_time&$key"; $pre_sign = "$siteid&$mid&$sw_time&$key";
// echo "pre:".$pre_sign; // echo "pre:".$pre_sign;
$my_sign = md5($pre_sign); $my_sign = md5($pre_sign);
$result = $this->valid($sw_time,$sw_sign,$my_sign); $result = $this->valid($sw_time,$sw_sign,$my_sign);
if ($result["code"]==0) {//valid ok if ($result["code"]==0) {//valid ok
$model = D("Media"); $model = D("Media");
$where["code"] = $mid; $where["code"] = $mid;
$where["sp_id"] = $spid; $where["site_id"] = $siteid;
$tmp = $model->field("id")->where($where)->find(); $tmp = $model->field("id")->where($where)->find();
$id = $tmp["id"]; $id = $tmp["id"];
if ($id) { if ($id) {
...@@ -131,11 +134,20 @@ class CenterAction extends Action ...@@ -131,11 +134,20 @@ class CenterAction extends Action
$data["updatetime"] = date('Y-m-d H:i:s'); $data["updatetime"] = date('Y-m-d H:i:s');
$r = $model->save($data); $r = $model->save($data);
//下线酒店片库 //下线该站点下所有关联合作方的酒店片库
$sql = "select id from sh_sp where site_id=$siteid";
$sps = M("")->query($sql);
$total = count($sps);
$nok = 0;
foreach ($sps as $sp){
$spid = $sp["id"];
$tb = "sh_hotel_media_map_$spid"; $tb = "sh_hotel_media_map_$spid";
$sql = "update $tb set status=$status,updatetime='" . $data["updatetime"] . "' where media_id=$id"; $sql = "update $tb set status=$status,updatetime='" . $data["updatetime"] . "' where media_id=$id";
$r = M("")->execute($sql); $r = M("")->execute($sql);
if ($r) { if ($r)
$nok ++;
}
if ($total==$nok) {
$result["code"] = 0; $result["code"] = 0;
$result["msg"] = "ok"; $result["msg"] = "ok";
} else { } else {
...@@ -159,7 +171,7 @@ class CenterAction extends Action ...@@ -159,7 +171,7 @@ class CenterAction extends Action
/** /**
* 修改云端片库媒资信息 * 修改云端片库媒资信息
* 参数: * 参数:
* spid * site_id
* push_mode : 是否转推:0不转推,1转推(写入酒店片库) * push_mode : 是否转推:0不转推,1转推(写入酒店片库)
* url : 华数媒资详情url * url : 华数媒资详情url
*/ */
...@@ -167,7 +179,7 @@ class CenterAction extends Action ...@@ -167,7 +179,7 @@ class CenterAction extends Action
$rawData = @file_get_contents("php://input"); $rawData = @file_get_contents("php://input");
//echo $rawData."\n"; //echo $rawData."\n";
$inputJson = json_decode($rawData,true); $inputJson = json_decode($rawData,true);
$spid=$inputJson["spid"]; $site_id=$inputJson["site_id"];
$pushMode = $inputJson["push_mode"]; // $pushMode = $inputJson["push_mode"]; //
$url = $inputJson["jsonUrl"]; $url = $inputJson["jsonUrl"];
...@@ -192,12 +204,19 @@ class CenterAction extends Action ...@@ -192,12 +204,19 @@ class CenterAction extends Action
$data["_updatetime"]=$this->null2str($json["updateTime"]); $data["_updatetime"]=$this->null2str($json["updateTime"]);
$data["programType"]=$json["programType"]; $data["programType"]=$json["programType"];
$data["nodeId"]=intval($json["nodeId"]); $data["nodeId"]=intval($json["nodeId"]);
$data["sp_id"]=intval($spid); $data["site_id"]=intval($site_id);
$data["nodeName"]=$this->null2str($json["nodeName"]); $data["nodeName"]=$this->null2str($json["nodeName"]);
//圆动和互动新增字段()
$data['newsImage_1'] = $this->null2str($json["newsImage_1"]);
$data['newsImage_2'] = $this->null2str($json["newsImage_2"]);
$data['newsImage_3'] = $this->null2str($json["newsImage_3"]);
$data['englishTitle'] = $this->null2str($json["englishTitle"]);
//end
$model = D("Media"); $model = D("Media");
$where["code"]=$data["code"]; $where["code"]=$data["code"];
$where["sp_id"]=$data["sp_id"]; $where["site_id"]=$data["site_id"];
$tmp = $model->field("id")->where($where)->find(); $tmp = $model->field("id")->where($where)->find();
$id= $tmp["id"]; $id= $tmp["id"];
// var_dump($tmp);exit; // var_dump($tmp);exit;
...@@ -224,9 +243,9 @@ class CenterAction extends Action ...@@ -224,9 +243,9 @@ class CenterAction extends Action
$code=1002; $code=1002;
} }
} }
if ($pushMode=="1") { //修改酒店片库
$this->media_auto_push($data); $this->media_auto_push($data,&$inputJson);
}
if ($code){ //更新媒资失败: 记录拉取失败日志 if ($code){ //更新媒资失败: 记录拉取失败日志
$this->log_pull_failture($code,$inputJson); $this->log_pull_failture($code,$inputJson);
...@@ -235,8 +254,7 @@ class CenterAction extends Action ...@@ -235,8 +254,7 @@ class CenterAction extends Action
exit; exit;
} }
function log_pull_failture($code,&$json){ function log_pull_failture($code,&$json){
$data["sp_id"]=intval($json["spid"]); $data["site_id"]=intval($json["site_id"]);
$data["push_mode"]=intval($json["push_mode"]);
$data["jsonUrl"]=$json["jsonUrl"]; $data["jsonUrl"]=$json["jsonUrl"];
$data["newsId"]=$json["newsId"]; $data["newsId"]=$json["newsId"];
$data["newsName"]=$json["newsName"]; $data["newsName"]=$json["newsName"];
...@@ -256,29 +274,34 @@ class CenterAction extends Action ...@@ -256,29 +274,34 @@ class CenterAction extends Action
* 批量修改媒资状态 * 批量修改媒资状态
* 批量推送添加 * 批量推送添加
*/ */
function media_auto_push(&$data){ function media_auto_push(&$data,&$json){
$sp_id=$data["sp_id"]; $sps = $json["sps"];
foreach ($sps as $sp) {
$push_mode = $sp["push_mode"];
if ($push_mode==1) {
$sp_id = $sp["sp_id"];
$media_id = $data["id"]; $media_id = $data["id"];
$status = $data["status"]; $status = $data["status"];
$updateSQL="UPDATE sh_hotel_media_map_$sp_id SET status=$status WHERE media_id=$media_id;"; $updateSQL = "UPDATE sh_hotel_media_map_$sp_id SET status=$status WHERE media_id=$media_id;";
M('')->execute($updateSQL); M('')->execute($updateSQL);
$sql ="SELECT h.id,hm.media_id FROM sh_hotel h" $sql = "SELECT h.id,hm.media_id FROM sh_hotel h"
." LEFT JOIN (SELECT media_id,hotel_id FROM sh_hotel_media_map_$sp_id WHERE media_id=$media_id) hm ON h.id=hm.hotel_id" . " LEFT JOIN (SELECT media_id,hotel_id FROM sh_hotel_media_map_$sp_id WHERE media_id=$media_id) hm ON h.id=hm.hotel_id"
." WHERE h.sp_id=$sp_id AND media_id IS NULL;"; . " WHERE h.sp_id=$sp_id AND media_id IS NULL;";
$arr = M("")->query($sql); $arr = M("")->query($sql);
// var_dump($arr); foreach ($arr as $item) {
$dataList[] = array("media_id" => $media_id, "hotel_id" => $item["id"], "status" => $status, "status_inject" => 0);
foreach ($arr as $item){
$dataList[]=array("media_id"=>$media_id,"hotel_id"=>$item["id"],"status"=>$status,"status_inject"=>0);
} }
if (!empty($dataList)){ if (!empty($dataList)) {
M("$sp_id","sh_hotel_media_map_")->addAll($dataList); M("$sp_id", "sh_hotel_media_map_")->addAll($dataList);
}
} }
} }
}
public function test_auto_push(){ public function test_auto_push(){
$data["sp_id"]=1; $data["sp_id"]=1;
$data["id"]=300; $data["id"]=300;
...@@ -415,9 +438,13 @@ class CenterAction extends Action ...@@ -415,9 +438,13 @@ class CenterAction extends Action
if($url!=""&&$key!="") { if($url!=""&&$key!="") {
$limit_from = ($page - 1) * $page_size; $limit_from = ($page - 1) * $page_size;
$sql = "SELECT mw.code id,mw.title,mw.description,mw.programType,mw.url_pic picUrl"
$fields = "mw.code id,mw.title,mw.description,mw.programType,mw.url_pic picUrl"
. ",mw.year,mw.type,mw.score,mw.region,mw.actor,mw.director" . ",mw.year,mw.type,mw.score,mw.region,mw.actor,mw.director"
. ",hm.code hotelId,hm.status,hm.status_inject statusInject" . ",hm.code hotelId,hm.status,hm.status_inject statusInject"
. ",mw.newsImage_1,mw.newsImage_2,mw.newsImage_3,mw.englishTitle";
$sql = "SELECT $fields"
. " FROM (SELECT hm.media_id,h.code,hm.status,hm.status_inject FROM sh_hotel_media_map_$spid hm,sh_hotel h" . " FROM (SELECT hm.media_id,h.code,hm.status,hm.status_inject FROM sh_hotel_media_map_$spid hm,sh_hotel h"
. " WHERE hm.updatetime AND hm.status_inject=1 BETWEEN '$start' AND '$end' AND h.id=hm.hotel_id ORDER BY hm.updatetime,hm.media_id ASC LIMIT $limit_from,$page_size) hm" . " WHERE hm.updatetime AND hm.status_inject=1 BETWEEN '$start' AND '$end' AND h.id=hm.hotel_id ORDER BY hm.updatetime,hm.media_id ASC LIMIT $limit_from,$page_size) hm"
. " JOIN sh_media_wasu mw ON mw.id=hm.media_id"; . " JOIN sh_media_wasu mw ON mw.id=hm.media_id";
......
<?php
class SiteModel extends RelationModel{
protected $tableName = 'sh_site'; //重新定义表名
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment