Commit e96349c0 authored by 蒋林's avatar 蒋林

记录日志; 配置文件

parent 02b3b5bd
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the 'Database Connection'
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| ['dsn'] The full DSN string describe a connection to the database.
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
| ['dbdriver'] The database driver. e.g.: mysqli.
| Currently supported:
| cubrid, ibase, mssql, mysql, mysqli, oci8,
| odbc, pdo, postgre, sqlite, sqlite3, sqlsrv
| ['dbprefix'] You can add an optional prefix, which will be added
| to the table name when using the Query Builder class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
| ['cachedir'] The path to the folder where cache files should be stored
| ['char_set'] The character set used in communicating with the database
| ['dbcollat'] The character collation used in communicating with the database
| NOTE: For MySQL and MySQLi databases, this setting is only used
| as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
| (and in table creation queries made with DB Forge).
| There is an incompatibility in PHP with mysql_real_escape_string() which
| can make your site vulnerable to SQL injection if you are using a
| multi-byte character set and are running versions lower than these.
| Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
| ['encrypt'] Whether or not to use an encrypted connection.
|
| 'mysql' (deprecated), 'sqlsrv' and 'pdo/sqlsrv' drivers accept TRUE/FALSE
| 'mysqli' and 'pdo/mysql' drivers accept an array with the following options:
|
| 'ssl_key' - Path to the private key file
| 'ssl_cert' - Path to the public key certificate file
| 'ssl_ca' - Path to the certificate authority file
| 'ssl_capath' - Path to a directory containing trusted CA certificats in PEM format
| 'ssl_cipher' - List of *allowed* ciphers to be used for the encryption, separated by colons (':')
| 'ssl_verify' - TRUE/FALSE; Whether verify the server certificate or not ('mysqli' only)
|
| ['compress'] Whether or not to use client compression (MySQL only)
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
| - good for ensuring strict SQL while developing
| ['ssl_options'] Used to set various SSL options that can be used when making SSL connections.
| ['failover'] array - A array with 0 or more data for connections if the main should fail.
| ['save_queries'] TRUE/FALSE - Whether to "save" all executed queries.
| NOTE: Disabling this will also effectively disable both
| $this->db->last_query() and profiling of DB queries.
| When you run a query, with this setting set to TRUE (default),
| CodeIgniter will store the SQL statement for debugging purposes.
| However, this may cause high memory usage, especially if you run
| a lot of SQL queries ... disable this to avoid that problem.
|
| The $active_group variable lets you choose which connection group to
| make active. By default there is only one group (the 'default' group).
|
| The $query_builder variables lets you determine whether or not to load
| the query builder class.
*/
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => '192.168.1.181',
'username' => 'pp_share',
'password' => '123456',
'database' => 'pp_wxh',
'dbdriver' => 'mysqli',
'dbprefix' => 'wxh_',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the 'Database Connection'
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| ['dsn'] The full DSN string describe a connection to the database.
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
| ['dbdriver'] The database driver. e.g.: mysqli.
| Currently supported:
| cubrid, ibase, mssql, mysql, mysqli, oci8,
| odbc, pdo, postgre, sqlite, sqlite3, sqlsrv
| ['dbprefix'] You can add an optional prefix, which will be added
| to the table name when using the Query Builder class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
| ['cachedir'] The path to the folder where cache files should be stored
| ['char_set'] The character set used in communicating with the database
| ['dbcollat'] The character collation used in communicating with the database
| NOTE: For MySQL and MySQLi databases, this setting is only used
| as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
| (and in table creation queries made with DB Forge).
| There is an incompatibility in PHP with mysql_real_escape_string() which
| can make your site vulnerable to SQL injection if you are using a
| multi-byte character set and are running versions lower than these.
| Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
| ['encrypt'] Whether or not to use an encrypted connection.
|
| 'mysql' (deprecated), 'sqlsrv' and 'pdo/sqlsrv' drivers accept TRUE/FALSE
| 'mysqli' and 'pdo/mysql' drivers accept an array with the following options:
|
| 'ssl_key' - Path to the private key file
| 'ssl_cert' - Path to the public key certificate file
| 'ssl_ca' - Path to the certificate authority file
| 'ssl_capath' - Path to a directory containing trusted CA certificats in PEM format
| 'ssl_cipher' - List of *allowed* ciphers to be used for the encryption, separated by colons (':')
| 'ssl_verify' - TRUE/FALSE; Whether verify the server certificate or not ('mysqli' only)
|
| ['compress'] Whether or not to use client compression (MySQL only)
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
| - good for ensuring strict SQL while developing
| ['ssl_options'] Used to set various SSL options that can be used when making SSL connections.
| ['failover'] array - A array with 0 or more data for connections if the main should fail.
| ['save_queries'] TRUE/FALSE - Whether to "save" all executed queries.
| NOTE: Disabling this will also effectively disable both
| $this->db->last_query() and profiling of DB queries.
| When you run a query, with this setting set to TRUE (default),
| CodeIgniter will store the SQL statement for debugging purposes.
| However, this may cause high memory usage, especially if you run
| a lot of SQL queries ... disable this to avoid that problem.
|
| The $active_group variable lets you choose which connection group to
| make active. By default there is only one group (the 'default' group).
|
| The $query_builder variables lets you determine whether or not to load
| the query builder class.
*/
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => '192.168.1.181',
'username' => 'pp_share',
'password' => '123456',
'database' => 'pp_wxh',
'dbdriver' => 'mysqli',
'dbprefix' => 'wxh_',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the 'Database Connection'
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| ['dsn'] The full DSN string describe a connection to the database.
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
| ['dbdriver'] The database driver. e.g.: mysqli.
| Currently supported:
| cubrid, ibase, mssql, mysql, mysqli, oci8,
| odbc, pdo, postgre, sqlite, sqlite3, sqlsrv
| ['dbprefix'] You can add an optional prefix, which will be added
| to the table name when using the Query Builder class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
| ['cachedir'] The path to the folder where cache files should be stored
| ['char_set'] The character set used in communicating with the database
| ['dbcollat'] The character collation used in communicating with the database
| NOTE: For MySQL and MySQLi databases, this setting is only used
| as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
| (and in table creation queries made with DB Forge).
| There is an incompatibility in PHP with mysql_real_escape_string() which
| can make your site vulnerable to SQL injection if you are using a
| multi-byte character set and are running versions lower than these.
| Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
| ['encrypt'] Whether or not to use an encrypted connection.
|
| 'mysql' (deprecated), 'sqlsrv' and 'pdo/sqlsrv' drivers accept TRUE/FALSE
| 'mysqli' and 'pdo/mysql' drivers accept an array with the following options:
|
| 'ssl_key' - Path to the private key file
| 'ssl_cert' - Path to the public key certificate file
| 'ssl_ca' - Path to the certificate authority file
| 'ssl_capath' - Path to a directory containing trusted CA certificats in PEM format
| 'ssl_cipher' - List of *allowed* ciphers to be used for the encryption, separated by colons (':')
| 'ssl_verify' - TRUE/FALSE; Whether verify the server certificate or not ('mysqli' only)
|
| ['compress'] Whether or not to use client compression (MySQL only)
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
| - good for ensuring strict SQL while developing
| ['ssl_options'] Used to set various SSL options that can be used when making SSL connections.
| ['failover'] array - A array with 0 or more data for connections if the main should fail.
| ['save_queries'] TRUE/FALSE - Whether to "save" all executed queries.
| NOTE: Disabling this will also effectively disable both
| $this->db->last_query() and profiling of DB queries.
| When you run a query, with this setting set to TRUE (default),
| CodeIgniter will store the SQL statement for debugging purposes.
| However, this may cause high memory usage, especially if you run
| a lot of SQL queries ... disable this to avoid that problem.
|
| The $active_group variable lets you choose which connection group to
| make active. By default there is only one group (the 'default' group).
|
| The $query_builder variables lets you determine whether or not to load
| the query builder class.
*/
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => '192.168.1.35',
'username' => 'test_wxh',
'password' => '8v@XRSQ#EMVo!JdRUK@xvZ#Lk',
'database' => 'test_wxh',
'dbdriver' => 'mysqli',
'dbprefix' => 'wxh_',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
...@@ -17,7 +17,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); ...@@ -17,7 +17,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
* @property api_log_model api_log_model * @property api_log_model api_log_model
* @property ReceiveGalanz ReceiveGalanz * @property ReceiveGalanz ReceiveGalanz
*/ */
class Galanz extends CI_Controller class Galanz extends BaseController
{ {
protected static $receiveGalanzObj = null; protected static $receiveGalanzObj = null;
......
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Class Galanz
*
* @property galanz_model galanz_model
*/
class Galanz extends CI_Controller {
//cookie保存文件
protected static $cookieFile = '';
//当前账号信息
protected static $account = [];
public function __construct()
{
parent::__construct();
//$this->load->model('galanz_model');
}
//推送订单到维修汇
public function pushOrder()
{
$this->galanz_model->pushOrder();
}
//推送结束, 更改格兰仕后台订单状态
public function updateGalanzOrderStatus()
{
}
public function index()
{
ini_set("max_execution_time", 1200);
$config = $this->config();
foreach ($config as $v) {
self::$cookieFile = PUBDIR . "cookie/galanz_{$v['username']}.cookie";
self::$account = $v;
$url = 'http://202.104.26.131:3081/Complaint/new_srv_callinMP.aspx?type=unsubscribe';
$result = $this->getUrlContents($url);
if (!$result || strlen(addslashes($result)) < 2000) {
$this->login();
}
$content = $this->queryOrder();
var_dump($content);
}
}
private function config() {
$config = [
[
'username' => 'c01000005', //用户名
'pwd' => 'weixiuhui010', //密码
'city' => '北京', //地区
'product' => '热水器', //产品
]
];
return $config;
}
private function queryOrder()
{
$url = 'http://202.104.26.131:3081/Complaint/new_srv_callinMP.aspx?type=unsubscribe';
$content = $this->getUrlContents($url);
$post = [
'__EVENTTARGET' => 'ctl00$ContentQuery$btnQuery',
'__EVENTARGUMENT' => '',
'__LASTFOCUS' => '',
'__VIEWSTATE' => '',
'ctl00$hidPageSiteMapTitle' => '派工单',
'ctl00$ContentQuery$hidMainId' => '',
'ctl00$ContentQuery$hidAttrCode' => '',
'ctl00$ContentQuery$hidMainIdName' => '',
'ctl00$ContentQuery$new_name' => '',
'ctl00$ContentQuery$new_custname' => '',
'ctl00$ContentQuery$ddlfinishstatus' => '',
'ctl00$ContentQuery$startTime' => '',
'ctl00$ContentQuery$endTime' => '',
'ctl00$ContentQuery$ddlIsAccept' => '',
'ctl00$ContentQuery$new_custtel' => '',
'ctl00$ContentQuery$new_address' => '',
'ctl00$ContentQuery$ddlcallintype' => '',
'ctl00$ContentQuery$new_isReminder' => '',
'ctl00$ContentQuery$new_ServicePersonnel' => '',
'ctl00$ContentData$PagerToolBar1$ctl00' => 500,
'ctl00$ContentData$PagerToolBar1$ctl05' => 1
];
//调取最近的数据
$maxTimeOrder = $this->galanz_model->infoMaxDaytime();
if ($maxTimeOrder) {
$startTime = strtotime(date("Y/m/d", $maxTimeOrder['new_callintime']));
$endTime = $startTime + 86400;
$post['ctl00$ContentQuery$startTime'] = date("Y/m/d", $startTime);
$post['ctl00$ContentQuery$endTime'] = date("Y/m/d", $endTime);
}
preg_match('/<input[^>]+name="__VIEWSTATE"[^>]+value="([^"]*)"/', $content, $arr);
$post['__VIEWSTATE'] = $arr[1];
$headers = [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding: gzip, deflate',
'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Cache-Control: max-age=0',
'Connection: keep-alive',
'Host: 202.104.26.131:3081',
'Referer: http://202.104.26.131:3081/Complaint/new_srv_callinMP.aspx?type=unsubscribe',
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:47.0) Gecko/20100101 Firefox/47.0',
];
$result = $this->curlPost($url, $post, $headers);
$result = gzdecode($result['data']);
$result = $this->addOrder($result);
return $result;
}
private function addOrder($order)
{
$tempData = [];
preg_match_all('/(<tr>\s+<td class="checkbox">[\s\S]+?<\/tr>)/', $order, $tr);
if (empty($tr[0])) {
return false;
}
foreach ($tr[0] as $k => $v) {
preg_match_all('/(<td[^>]*>[\s\S]+?<\/td>)/', $v, $td);
foreach ($td[0] as $kk => $vv) {
if ($kk == 0) {
preg_match('/value="([^"]+)"/', $vv, $temp);
$vv = $temp[1];
} else {
$vv = preg_replace('/<[^>]+>/', '', $vv);
$vv = trim($vv);
}
$td[0][$kk] = $vv;
}
$tempData[$k] = $td[0];
}
$tempOrder = [];
foreach ($tempData as $k => $v) {
$tempOrder[] = $this->order($v[0], $v);
}
return $tempOrder;
}
private function order($id, $order)
{
$orderField = [
'new_name', //受理单号
'new_callintime', //受理时间
'new_sentstatus', //派工状态
'new_custname', //顾客姓名
'new_custmobile', //顾客手机
'new_custtel', //顾客电话
'new_provinceidName', //省份
'new_cityidName', //城市
'new_countyidname', //区/县
'new_townidName', //街道/镇
'new_address',//地址
'new_visittime', //要求上门时间
'new_producttype', //机型
'new_csnumber', //机器条码
'new_installsiteidname', //安装网点
'new_broughtdate', //购买日期
'new_installdate', //安装日期
'new_errormoduleidName', // 故障现象
'new_custdescription', //顾客描述
'new_remarks', //投诉处理单备注
'new_callintype', //受理类型
'new_productqty', //机器台数
'new_market', //购买商场
];
$orderField = array_fill_keys($orderField, '');
$url = 'http://202.104.26.131:3081/Complaint/new_srv_callinEP.aspx?mainid=&mainidname=&attrcode=&id=' . $id;
$content = $this->getUrlContents($url);
preg_match_all('/<input[^>]+id="([^"]+)"[^>]+value="([^"]*)"/', $content, $arr);
$data = [];
foreach ($arr[1] as $k => $v) {
$data[$v] = $arr[2][$k];
}
$data = array_intersect_key($data, $orderField);
$temp = array_diff_key($orderField, $data);
$data = array_merge($data, $temp);
$data['new_id'] = $id;
$data['new_callintype'] = $order[3];
$data['new_sentstatus'] = $order[6];
$data['new_product'] = self::$account['product'];
$result = false;
//数据入库
if ($data) {
$isNewName = $this->galanz_model->infoByNewName($data['new_name']);
if (!$isNewName) {
$insertData = [
'new_id' => $data['new_id'],
'new_callintype' => $data['new_callintype'],
'new_name' => $data['new_name'],
'new_custname' => $data['new_custname'],
'new_custmobile' => $data['new_custmobile'],
'new_provinceidName' => $data['new_provinceidName'],
'new_cityidName' => $data['new_cityidName'],
'new_countyidname' => $data['new_countyidname'],
'new_broughtdate' => $data['new_broughtdate'] ? strtotime($data['new_broughtdate']) : 0,
'new_installdate' => $data['new_installdate'] ? strtotime($data['new_installdate']) : 0,
'new_callintime' => $data['new_callintime'] ? strtotime($data['new_callintime']) : 0,
'new_productqty' => $data['new_productqty'],
'new_sentstatus' => $data['new_sentstatus'],
'data' => json_encode($data),
];
$this->galanz_model->add($insertData);
$result = true;
}
}
return $result;
}
private function login()
{
$captchaPath = PUBDIR . "captcha/galanz_". self::$account['username'] .".gif";
$loginUrl = "http://202.104.26.131:3081/FLoginNew.aspx";
$captchaUrl = "http://202.104.26.131:3081/SystemSetting/CheckCode.aspx";
$content = $this->setUrlCookie($loginUrl);
$this->saveUrlCaptcha($captchaUrl, $captchaPath);
$post = [
'__EVENTTARGET' => '',
'__EVENTARGUMENT' => '',
'loguser' => '',
'txtUserCode' => self::$account['username'],
'txtPassword' => self::$account['pwd'],
'txtCheckCode' => get_uuapi($captchaPath),
];
preg_match_all('/<input[^>]+name="([^"]+)"[^>]+value="([^"]*)"/', $content, $arr);
foreach ($arr[1] as $k => $v) {
$post[$v] = $arr[2][$k];
}
$headers = [
'Host: 202.104.26.131:3081',
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:47.0) Gecko/20100101 Firefox/47.0',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding: gzip, deflate',
'Referer: http://202.104.26.131:3081/FLoginNew.aspx',
'Connection: keep-alive',
'Content-Type: application/x-www-form-urlencoded',
];
return $this->curlPost($loginUrl, $post, $headers);
}
private function setUrlCookie($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_COOKIEJAR, self::$cookieFile); //获取COOKIE并存储
$contents = curl_exec($curl);
curl_close($curl);
return $contents;
}
private function saveUrlCaptcha($url, $imagePath)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_COOKIEFILE, self::$cookieFile);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$img = curl_exec($curl);
curl_close($curl);
write_file($imagePath, $img);
return $imagePath;
}
private function curlPost($url, $post, $headers)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_COOKIEFILE, self::$cookieFile);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
$result = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
return ['code' => $code, 'data' => $result];
}
private function getUrlContents($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEFILE, self::$cookieFile); //读取cookie
$rs = curl_exec($curl); //执行cURL抓取页面内容
curl_close($curl);
return $rs;
}
}
<?php
/**
* Created by PhpStorm.
* User: LinJiangL
* Date: 16/8/18
* Time: 下午2:00
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Class Galanz 计划任务
*
* @property galanz_model galanz_model
* @property PushGalanz PushGalanz
* @property SourceGalanz SourceGalanz
*/
class Galanz extends BaseController
{
public function __construct()
{
parent::__construct();
}
/**
* 定时抓取订单数据
*/
public function index()
{
ini_set("max_execution_time", 12000);
//账号配置
$accountConfig = [
[
'username' => 'c01000005', //用户名
'pwd' => 'weixiuhui010', //密码
'city' => '北京', //地区
'category' => '热水器', //产品类型
]
];
$orders = [];
foreach ($accountConfig as $v) {
$orders[] = $this->galanzHandle($v);
}
echo "<pre>";
print_r($orders);
}
private function galanzHandle($account)
{
$this->load->model('galanz_model');
$this->load->library('Source/SourceGalanz', $account, 'SourceGalanz');
//调取最近的数据
$maxTimeOrder = $this->galanz_model->infoMaxDaytime();
$nowTime = date("Y/m/d", time());
if ($maxTimeOrder) {
$startTime = strtotime(date("Y/m/d", $maxTimeOrder['new_callintime']));
$startTime = date("Y/m/d", $startTime);
} else {
//前三天的时间
$startTime = date("Y/m/d", strtotime($nowTime) - 86400 * 2);
}
$endTime = date("Y/m/d", strtotime($nowTime) + 86400);
$orders = $this->SourceGalanz->SearchOrder($startTime, $endTime);
if (empty($orders)) {
return false;
}
$result = [];
foreach ($orders as $k => $v) {
$order = $this->SourceGalanz->OrderDetail($v[0]);
//如果订单存在, 不需要保存
$info = $this->galanz_model->infoByNewName($order['new_name']);
if (empty($info)) {
$id = $this->galanz_model->add($order);
//记录插入的订单
$order['id'] = $id;
$result[$k] = $order;
}
}
return $result;
}
/**
* 推送订单到维修汇
*/
public function pushOrder()
{
$this->load->model('galanz_model');
$this->load->library('Push/PushGalanz', null, 'PushGalanz');
$orders = $this->galanz_model->getOrderList();
foreach ($orders as $k => $v) {
$result = $this->PushGalanz->PushOrder($v);
//推送成功, 修改推送状态
if ($result['code'] == 200 && $result['data'] == 'OK') {
$this->galanz_model->updatePushStatus($v['id']);
}
}
}
}
...@@ -4,13 +4,14 @@ defined('BASEPATH') OR exit('No direct script access allowed'); ...@@ -4,13 +4,14 @@ defined('BASEPATH') OR exit('No direct script access allowed');
/** /**
* Class Welcome * Class Welcome
*/ */
class Welcome extends CI_Controller { class Welcome extends BaseController {
public function index() public function order()
{ {
$this->load->config('account', true); $this->load->config('account', true);
$account = $this->config->item('account'); $account = $this->config->item('account');
$galanzAccount = $account['galanz']; $galanzAccount = $account['galanz'];
var_dump($galanzAccount);die();
$this->load->library('Source/SourceGalanz', $galanzAccount['c01000005'], 'SourceGalanz'); $this->load->library('Source/SourceGalanz', $galanzAccount['c01000005'], 'SourceGalanz');
...@@ -18,9 +19,15 @@ class Welcome extends CI_Controller { ...@@ -18,9 +19,15 @@ class Welcome extends CI_Controller {
echo "<pre>"; echo "<pre>";
print_r($order); print_r($order);
}
public function t()
{
$this->load->library('Push/PushGalanz', null, 'PushGalanz');
$result = $this->PushGalanz->GetToken();
print_r($result);
$this->load->model('api_log_model');
$this->api_log_model->add($order['new_id'], '', $order);
} }
public function api() public function api()
...@@ -29,16 +36,18 @@ class Welcome extends CI_Controller { ...@@ -29,16 +36,18 @@ class Welcome extends CI_Controller {
$this->load->library('Receive/ReceiveGalanz', null, 'ReceiveGalanz'); $this->load->library('Receive/ReceiveGalanz', null, 'ReceiveGalanz');
$data['appid'] = '10001'; $data['appid'] = '10001';
$data['out_trade_no'] = '320423402834023'; $data['out_trade_no'] = 'CALL2016082200544';
$data['nonce_str'] = $this->ReceiveGalanz->GetNonceStr(); $data['nonce_str'] = $this->ReceiveGalanz->GetNonceStr();
$this->ReceiveGalanz->SetValues($data); $this->ReceiveGalanz->SetValues($data);
//$this->ReceiveGalanz->SetSign(); $this->ReceiveGalanz->SetSign();
$values = $this->ReceiveGalanz->GetValues(); $values = $this->ReceiveGalanz->GetValues();
$url = "http://wxh.pp.cn/api/galanz/saveOrder"; $url = "http://testwxh.pp.cc/api/galanz/getOrderDetail";
$result = $this->curlPost($url, $values); $result = $this->curlPost($url, $values);
$result['data'] = json_decode($result['data'], true); $result['data'] = json_decode($result['data'], true);
echo "<pre>";
print_r($result); print_r($result);
} }
......
<?php
/**
* Created by PhpStorm.
* User: LinJiangL
* Date: 16/8/19
* Time: 上午11:14
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Class Galanz 格兰仕相关接口
*
* @property galanz_model galanz_model
* @property PushGalanz PushGalanz
* @property SourceGalanz SourceGalanz
* @property api_log_model api_log_model
* @property ReceiveGalanz ReceiveGalanz
*/
class Galanz extends BaseController
{
protected static $receiveGalanzObj = null;
public function __construct()
{
parent::__construct();
$this->load->library('Receive/ReceiveGalanz', null, 'ReceiveGalanz');
self::$receiveGalanzObj = $this->ReceiveGalanz;
}
private function getAccount($username)
{
$this->load->config('account', true);
$account = $this->config->item('account');
$galanzAccount = $account['galanz'];
return $galanzAccount[$username];
}
public function getOrderDetail()
{
$param = $this->input->post();
//验证参数
self::$receiveGalanzObj->SetValues($param);
self::$receiveGalanzObj->CheckGetOrderDetailValues();
$values = self::$receiveGalanzObj->GetValues();
$this->saveLog('', 'getOrderDetail', $param);
$this->load->model('galanz_model');
$info = $this->galanz_model->infoByNewName($values['out_trade_no']);
if (empty($info)) {
self::$receiveGalanzObj->ReturnMessage('10101', '订单不存在');
}
//订单账号
$account = $this->getAccount($info['new_username']);
//获取订单详情
$this->load->library('Source/SourceGalanz', $account, 'SourceGalanz');
$order = $this->SourceGalanz->OrderDetail($info['new_id']);
self::$receiveGalanzObj->ReturnMessage('10000', '', $order);
}
//保存订单
public function saveOrder()
{
$param = $this->input->post();
//验证参数
self::$receiveGalanzObj->SetValues($param);
self::$receiveGalanzObj->CheckSaveOrderValues();
$this->saveLog('', 'saveOrder', $param);
self::$receiveGalanzObj->ReturnMessage('10000');
}
//拒绝订单
public function refuseOrder()
{
$param = $this->input->post();
//验证参数
self::$receiveGalanzObj->SetValues($param);
self::$receiveGalanzObj->CheckRefuseOrderValues();
$this->saveLog('', 'refuseOrder', $param);
self::$receiveGalanzObj->ReturnMessage('10000');
}
//接受订单
public function acceptOrder()
{
$param = $this->input->post();
//验证参数
self::$receiveGalanzObj->SetValues($param);
self::$receiveGalanzObj->CheckAcceptOrderValues();
$this->saveLog('', 'acceptOrder', $param);
self::$receiveGalanzObj->ReturnMessage('10000');
}
//转录维修单
public function createWorkOrder()
{
$param = $this->input->post();
//验证参数
self::$receiveGalanzObj->SetValues($param);
self::$receiveGalanzObj->CheckCreateWorkOrderValues();
$this->saveLog('', 'createWorkOrder', $param);
self::$receiveGalanzObj->ReturnMessage('10000');
}
//转录安装单
public function createUserprofileOrder()
{
$param = $this->input->post();
//验证参数
self::$receiveGalanzObj->SetValues($param);
self::$receiveGalanzObj->CheckCreateUserprofileOrderValues();
$this->saveLog('', 'createUserprofileOrder', $param);
self::$receiveGalanzObj->ReturnMessage('10000');
}
private function saveLog($search, $method, $data)
{
//记录日志
$this->load->model('api_log_model');
$this->api_log_model->add($search, 'galanz', $method, $data);
}
}
\ No newline at end of file
...@@ -14,40 +14,35 @@ defined('BASEPATH') OR exit('No direct script access allowed'); ...@@ -14,40 +14,35 @@ defined('BASEPATH') OR exit('No direct script access allowed');
* @property galanz_model galanz_model * @property galanz_model galanz_model
* @property PushGalanz PushGalanz * @property PushGalanz PushGalanz
* @property SourceGalanz SourceGalanz * @property SourceGalanz SourceGalanz
* @property order_log_model order_log_model
* @property push_log_model push_log_model
*/ */
class Galanz extends CI_Controller class Galanz extends BaseController
{ {
public function __construct()
{
parent::__construct();
}
/** /**
* 定时抓取订单数据 * 定时抓取订单数据
*/ */
public function index() public function index()
{ {
ini_set("max_execution_time", 12000); ini_set("max_execution_time", 12000);
//账号配置 $this->load->config('account', true);
$accountConfig = [ $account = $this->config->item('account');
[ $galanzAccount = $account['galanz'];
'username' => 'c01000005', //用户名
'pwd' => 'weixiuhui010', //密码 $this->load->model('order_log_model');
'city' => '北京', //地区 foreach ($galanzAccount as $v) {
'category' => '热水器', //产品类型 $orders = $this->galanzHandle($v);
]
]; //添加订单入库日志
if ($orders) {
$orders = []; foreach ($orders as $vv) {
foreach ($accountConfig as $v) { $this->order_log_model->add($vv['new_name'], 'galanz', $vv, $v['username']);
$orders[] = $this->galanzHandle($v); }
}
} }
echo "<pre>";
print_r($orders);
} }
private function galanzHandle($account) private function galanzHandle($account)
...@@ -57,16 +52,18 @@ class Galanz extends CI_Controller ...@@ -57,16 +52,18 @@ class Galanz extends CI_Controller
//调取最近的数据 //调取最近的数据
$maxTimeOrder = $this->galanz_model->infoMaxDaytime(); $maxTimeOrder = $this->galanz_model->infoMaxDaytime();
$nowTime = date("Y/m/d", time());
if ($maxTimeOrder) { if ($maxTimeOrder) {
$startTime = strtotime(date("Y/m/d", $maxTimeOrder['new_callintime'])); $startTime = strtotime(date("Y/m/d", $maxTimeOrder['new_callintime']));
$startTime = date("Y/m/d", $startTime); $startTime = date("Y/m/d", $startTime);
$endTime = date("Y/m/d", time() + 86400);
} else { } else {
$startTime = ''; //前三天的时间
$endTime = ''; $startTime = date("Y/m/d", strtotime($nowTime) - 86400 * 30);
} }
$endTime = date("Y/m/d", strtotime($nowTime) + 86400);
$orders = $this->SourceGalanz->SearchOrder($startTime, $endTime); $orders = $this->SourceGalanz->SearchOrder($startTime, $endTime);
if (empty($orders)) { if (empty($orders)) {
...@@ -84,7 +81,7 @@ class Galanz extends CI_Controller ...@@ -84,7 +81,7 @@ class Galanz extends CI_Controller
//记录插入的订单 //记录插入的订单
$order['id'] = $id; $order['id'] = $id;
$result[$k] = $order; $result[] = $order;
} }
} }
...@@ -98,10 +95,14 @@ class Galanz extends CI_Controller ...@@ -98,10 +95,14 @@ class Galanz extends CI_Controller
{ {
$this->load->model('galanz_model'); $this->load->model('galanz_model');
$this->load->library('Push/PushGalanz', null, 'PushGalanz'); $this->load->library('Push/PushGalanz', null, 'PushGalanz');
$this->load->model('push_log_model');
$orders = $this->galanz_model->getOrderList(); $orders = $this->galanz_model->getOrderList();
foreach ($orders as $k => $v) { foreach ($orders as $k => $v) {
//添加订单推送日志
$this->push_log_model->add($v['new_name'], 'galanz', $v);
$result = $this->PushGalanz->PushOrder($v); $result = $this->PushGalanz->PushOrder($v);
//推送成功, 修改推送状态 //推送成功, 修改推送状态
......
<?php
/**
* 基础父控制器
*/
class BaseController extends CI_Controller {
public function __construct() {
parent::__construct();
//自动加载数据库连接
$this->load->database();
}
}
File mode changed from 100644 to 100755
...@@ -10,23 +10,30 @@ class Push ...@@ -10,23 +10,30 @@ class Push
{ {
protected static $token = ''; protected static $token = '';
public function SetAccessToken($appid, $appsecret) public function SetToken($appid, $appsecret)
{ {
$url = "http://www.weixiuhui.cn:8080/STS/rest/partner/token?appid={$appid}&appsecret={$appsecret}"; $url = "http://www.weixiuhui.cn:8080/STS/rest/partner/token?appid={$appid}&appsecret={$appsecret}";
$result = $this->CurlGet($url); $result = $this->CurlGet($url);
if ($result && $result['code'] == 200) { if ($result && $result['code'] == 200) {
$result['data'] = json_decode($result['data'], true);
self::$token = $result['data']['token']; self::$token = $result['data']['token'];
} else { } else {
die('token获取失败'); die('token获取失败');
} }
} }
public function GetToken()
{
return self::$token;
}
protected function CurlGet($url) { protected function CurlGet($url) {
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl); //执行cURL抓取页面内容 $result = curl_exec($curl); //执行cURL抓取页面内容
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE); $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
...@@ -39,6 +46,7 @@ class Push ...@@ -39,6 +46,7 @@ class Push
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
$result = curl_exec($curl); $result = curl_exec($curl);
......
...@@ -16,10 +16,9 @@ class PushGalanz extends Push ...@@ -16,10 +16,9 @@ class PushGalanz extends Push
$appid = 1; $appid = 1;
$appsecret = 'e10adc3949ba59abbe56e057f20f883f'; $appsecret = 'e10adc3949ba59abbe56e057f20f883f';
$this->SetAccessToken($appid, $appsecret); $this->SetToken($appid, $appsecret);
} }
public function PushOrder($order) public function PushOrder($order)
{ {
$url = "http://www.weixiuhui.cn:8080/STS/rest/partner/order/". self::$token ."/createOrderFromLocoy"; $url = "http://www.weixiuhui.cn:8080/STS/rest/partner/order/". self::$token ."/createOrderFromLocoy";
...@@ -34,7 +33,7 @@ class PushGalanz extends Push ...@@ -34,7 +33,7 @@ class PushGalanz extends Push
'contact_community_name' => $order['new_countyidname'], 'contact_community_name' => $order['new_countyidname'],
'contact_street_name' => $order['new_townidName'] ?: '-', 'contact_street_name' => $order['new_townidName'] ?: '-',
'contact_address' => $order['new_address'], 'contact_address' => $order['new_address'],
'category_name' => $order['new_product'], 'category_name' => $order['new_category'],
'brand_name' => '格兰仕', 'brand_name' => '格兰仕',
'product_certificate_number' => $order['new_producttype'] ?: '-', 'product_certificate_number' => $order['new_producttype'] ?: '-',
'product_serial_number' => $order['new_csnumber'] ?: '-', 'product_serial_number' => $order['new_csnumber'] ?: '-',
......
...@@ -165,6 +165,19 @@ class Receive ...@@ -165,6 +165,19 @@ class Receive
* @return array * @return array
*/ */
public function ReturnMessage($code = '10000', $msg = '', $data = '') public function ReturnMessage($code = '10000', $msg = '', $data = '')
{
echo $this->SetErrorCode($code, $msg, $data);
die();
}
/**
* 返回数据
* @param string $code
* @param string $data
* @param string $msg
* @return array
*/
public function SetErrorCode($code = '10000', $msg = '', $data = '')
{ {
$error = [ $error = [
'10000' => 'OK', '10000' => 'OK',
...@@ -173,9 +186,9 @@ class Receive ...@@ -173,9 +186,9 @@ class Receive
'10999' => '参数错误', '10999' => '参数错误',
]; ];
$msg = $error[$code] ? : $msg; $msg = isset($error[$code]) ? $error[$code] : $msg;
echo json_encode(['code' => $code, 'msg' => $msg, 'data' => $data]); return json_encode(['code' => $code, 'msg' => $msg, 'data' => $data], JSON_UNESCAPED_UNICODE);
die();
} }
} }
\ No newline at end of file
...@@ -26,6 +26,18 @@ class ReceiveGalanz extends Receive ...@@ -26,6 +26,18 @@ class ReceiveGalanz extends Receive
} }
} }
/**
* 订单详情
*/
public function CheckGetOrderDetailValues()
{
$this->CheckPublicValues();
if (!array_key_exists('out_trade_no', $this->values) || $this->values['out_trade_no'] == '') {
$this->ReturnMessage('10003', '缺少out_trade_no参数!');
}
}
/** /**
* 保存订单 * 保存订单
*/ */
......
...@@ -31,7 +31,7 @@ class SourceGalanz extends Source ...@@ -31,7 +31,7 @@ class SourceGalanz extends Source
$this->IsLogin(); $this->IsLogin();
} }
public function SearchOrder($startTime = '', $endTime = '', $limit = 500) public function SearchOrder($startTime = '', $endTime = '', $limit = 500)
{ {
$url = 'http://202.104.26.131:3081/Complaint/new_srv_callinMP.aspx?type=unsubscribe'; $url = 'http://202.104.26.131:3081/Complaint/new_srv_callinMP.aspx?type=unsubscribe';
......
File mode changed from 100644 to 100755
...@@ -9,16 +9,11 @@ class Api_log_model extends CI_Model ...@@ -9,16 +9,11 @@ class Api_log_model extends CI_Model
public $table = 'api_log'; //表名 public $table = 'api_log'; //表名
function __construct() public function add($search, $sys, $method, $data)
{
parent::__construct();
$this->load->database();
}
public function add($search, $method, $data)
{ {
$insertData = [ $insertData = [
'search' => $search, 'search' => $search,
'sys_name' => $sys,
'method' => $method, 'method' => $method,
'data' => $data ? json_encode($data) : '', 'data' => $data ? json_encode($data) : '',
'created_time' => time() 'created_time' => time()
......
...@@ -9,12 +9,6 @@ class Galanz_model extends CI_Model ...@@ -9,12 +9,6 @@ class Galanz_model extends CI_Model
public $table = 'galanz'; //表名 public $table = 'galanz'; //表名
function __construct()
{
parent::__construct();
$this->load->database();
}
public function add($data) public function add($data)
{ {
...@@ -63,6 +57,11 @@ class Galanz_model extends CI_Model ...@@ -63,6 +57,11 @@ class Galanz_model extends CI_Model
return $this->db->insert_id(); return $this->db->insert_id();
} }
public function update($id, $data)
{
$this->db->update($this->table, $data, ['id' => $id]);
}
public function updatePushStatus($id) public function updatePushStatus($id)
{ {
$this->db->update($this->table, ['push_status' => 1], ['id' => $id]); $this->db->update($this->table, ['push_status' => 1], ['id' => $id]);
...@@ -89,63 +88,4 @@ class Galanz_model extends CI_Model ...@@ -89,63 +88,4 @@ class Galanz_model extends CI_Model
return $result; return $result;
} }
public function getAccessToken()
{
$appid = 1;
$appsecret = 'e10adc3949ba59abbe56e057f20f883f';
$url = "http://www.weixiuhui.cn:8080/STS/rest/partner/token?appid={$appid}&appsecret={$appsecret}";
return curl_get($url);
}
public function pushOrder()
{
$token = $this->getAccessToken();
if (empty($token)) {
return 10001;
}
$orders = $this->db->get_where($this->table, ['push_status' => 0, 'new_callintype' => '咨询'])->result_array();
if (empty($orders)) {
return 10002;
}
$url = "http://www.weixiuhui.cn:8080/STS/rest/partner/order/{$token['token']}/createOrderFromLocoy";
foreach ($orders as $v) {
$v['data'] = json_decode($v['data'], true);
$pushData = [
'serial_number' => $v['data']['new_name'],
'contact_name' => $v['data']['new_custname'],
'contact_phone' => $v['data']['new_custmobile'],
'contact_tel' => $v['data']['new_custtel'] ?: '-',
'contact_province_name' => $v['data']['new_provinceidName'],
'contact_city_name' => $v['data']['new_cityidName'],
'contact_community_name' => $v['data']['new_countyidname'],
'contact_street_name' => $v['data']['new_townidName'] ?: '-',
'contact_address' => $v['data']['new_address'],
'category_name' => $v['data']['new_product'],
'brand_name' => '格兰仕',
'product_certificate_number' => $v['data']['new_producttype'] ?: '-',
'product_serial_number' => $v['data']['new_csnumber'] ?: '-',
'product_sales_date' => $v['data']['new_broughtdate'],
'service_content' => $v['data']['new_custdescription'] ?: '-',
'order_service_type' => $v['data']['new_callintype'],
'order_product_count' => $v['data']['new_productqty'] ?: 1,
'partner_code' => 'galanz',
'order_commit_from' => '合作商转单',
];
$temp = curl_post($url, $pushData);
if ($temp['code'] == 200 && $temp['data'] == 'OK') {
$this->updatePushStatus($v['id']);
}
}
return 10000;
}
} }
\ No newline at end of file
<?php
/**
* 推送订单日志模型
* Class Api_log_model
*/
class Push_log_model extends CI_Model
{
public $table = 'push_log'; //表名
public function add($search, $sys, $data)
{
$insertData = [
'search' => $search,
'sys_name' => $sys,
'data' => $data ? json_encode($data) : '',
'created_time' => time()
];
$this->db->insert($this->table, $insertData);
return $this->db->insert_id();
}
public function getLogs($search)
{
return $this->db->get_where($this->table, ['search' => $search])->result_array();
}
}
\ No newline at end of file
<?php
/**
* 订单入库日志模型
* Class Order_log_model
*/
class Order_log_model extends CI_Model
{
public $table = 'order_log'; //表名
public function add($search, $sys, $data, $remark = '')
{
$insertData = [
'search' => $search,
'sys_name' => $sys,
'data' => $data ? json_encode($data) : '',
'remark' => $remark,
'created_time' => time()
];
$this->db->insert($this->table, $insertData);
return $this->db->insert_id();
}
public function getLogs($search)
{
return $this->db->get_where($this->table, ['search' => $search])->result_array();
}
}
\ No newline at end of file
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
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