Files
OMS/app/ome/lib/collection/request.php
2025-12-28 23:13:25 +08:00

122 lines
4.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Copyright © ShopeX http://www.shopex.cn. All rights reserved.
* See LICENSE file for license details.
*/
define('COLLECTION_URL','http://openapi.ishopex.cn/api/dcinput/data/insert');
define('CUSTOMER_URL','http://openapi.ishopex.cn/api/dccrm/customer/queryid_ensure');
/**
* collection 数据请求类
* @author chenjun 2013.04.15
* @copyright shopex.cn
*/
class ome_collection_request extends ome_collection_rpc{
public $beginTime;
public $endTime;
public $serverName;
/**
* 发起
* @access public
* @return result
*/
public function request($serverName = ''){
if($serverName == '') return false;
$result = array();
$lastRequestTime = '';
kernel::single('base_kvstore_filesystem','ome')->fetch('request_collection_last_time',$lastRequestTime);
$this->beginTime = $lastRequestTime ? $lastRequestTime : strtotime(date('Y-m-d',time()-24*60*60));
$this->endTime = strtotime(date('Y-m-d',time()));
$this->serverName = $serverName;
$days = $this->preTime($this->beginTime,$this->endTime);
if(!$days) return true;
$email = $this->get_manage_email();
$customerid = $this->get_customerid($email);
$aDay = $days-7;
$startDay = $aDay > 0 ? $aDay : 0;
for($day=$startDay;$day<$days;$day++){
$beginTime = $this->beginTime + (3600*24*$day);
$endTime = strtotime(date('Y-m-d',$beginTime).' 23:59:59');
#参数
$key = array(
'requiredproductid' => 33,
'requiredcustomerid' => $customerid,
'requireddate' => $endTime,
);
/*------------------订单相关数据------------------*/
kernel::single('ome_collection_func_order')->beginTime = $beginTime;
kernel::single('ome_collection_func_order')->endTime = $endTime;
$orderData = kernel::single('ome_collection_func_order')->getData();
/*------------------订单相关数据------------------*/
foreach($orderData as $shop_id => $data){
$key['shop_id'] = $shop_id;
$queryParams = array(
'json' => json_encode(array('key' => $key,'data' => $data)),
);
$sign = $this->sign(COLLECTION_URL,$queryParams);
$apiurl = COLLECTION_URL.'?'.$sign;
#请求
$result[] = $this->http($apiurl,5,$queryParams);
}
}
kernel::single('base_kvstore_filesystem','ome')->store('request_collection_last_time',$this->endTime);
return $result;
}
/**
* 检查上次同步时间 与这次 同步时间 是否只相隔一天
* 每相隔一天发起一次同步
* @params $beginTime 上次同步时间
* @params $endTime 当前时间
* @return number
*/
public function preTime($beginTime,$endTime){
$count = ($endTime - $beginTime) / (60*60*24);
if ($count == 0) return false;
return $count;
}
/**
* 获取customerid
* 首次获取发起接口 获取之后缓存到本地
* @params $shopex_id
* @return array
*/
public function get_customerid($email = ''){
$customerid = '';
$customer_info = '';
kernel::single('base_kvstore_filesystem','ome')->fetch('request_collection_customer_info',$customer_info);
if(!$customer_info[$email]){
$params = array(
'customerinfo' => '{"contact_email":"'.$email.'"}',
'contact_email' => $email,
);
$sign = $this->sign(CUSTOMER_URL,$params);
$apiurl = CUSTOMER_URL.'?'.$sign;
$result = $this->http($apiurl,5,$params);
$customerid = $result['result']['customerinfo_id'];
$customer_info[$email] = $customerid;
kernel::single('base_kvstore_filesystem','ome')->store('request_collection_customer_info',$customer_info);
}else{
$customerid = $customer_info[$email];
}
return $customerid;
}
/**
* manage平台获取email客户信息
* 首次获取发起接口 获取之后缓存到本地
* @return string
*/
public function get_manage_email(){
// SaaS 功能已禁用,密钥已删除
// 此功能不再可用,返回空字符串
return '';
}
}