优化ctms-api语法、修复已知BUG;
主要修复ctms-api、dacms对PHP新版本的支持问题
This commit is contained in:
Executable
+1
@@ -0,0 +1 @@
|
||||
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
<title>404</title>
|
||||
<style>
|
||||
body {
|
||||
background-color: #444;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 60px;
|
||||
color: #eee;
|
||||
text-align: center;
|
||||
padding-top: 30px;
|
||||
font-weight: normal;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h3>404,您请求的文件不存在!</h3>
|
||||
</body>
|
||||
</html>
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
版本记录说明
|
||||
|
||||
2.1.20210909
|
||||
添加版本记录号;
|
||||
修复管理员表、会员表、粉丝表、API用户表的归属及统一
|
||||
修复后台管理员资料编辑错误,微调昵称等细节部分
|
||||
Executable
+2226
File diff suppressed because it is too large
Load Diff
Executable
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\assets;
|
||||
|
||||
use yii\web\AssetBundle;
|
||||
|
||||
/**
|
||||
* Main frontend application asset bundle.
|
||||
*/
|
||||
class AppAsset extends AssetBundle
|
||||
{
|
||||
public $basePath = '@webroot';
|
||||
public $baseUrl = '@web';
|
||||
public $css = [
|
||||
'css/site.css',
|
||||
];
|
||||
public $js = [
|
||||
];
|
||||
public $depends = [
|
||||
'yii\web\YiiAsset',
|
||||
'yii\bootstrap5\BootstrapAsset',
|
||||
];
|
||||
}
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/*
|
||||
* 通讯证书文件
|
||||
@status 站点状态,-1禁止 0只读 1可用
|
||||
@siteId 站点ID
|
||||
@suIp 允许访问的IP
|
||||
@suDomain 允许访问的域名
|
||||
@api 接口用户名(站点用户名)
|
||||
@code 用户授权码
|
||||
@token 接口通讯的accesstoken文件
|
||||
*/
|
||||
$cert = array();
|
||||
$cert['id'] = '17';
|
||||
$cert['siteId'] = '1534755679';
|
||||
$cert['suIp'] = array('60.166.78.33');
|
||||
$cert['siteName'] = '';
|
||||
$cert['suDomain'] = array('http:');
|
||||
$cert['siteUrl'] = '';
|
||||
$cert['api'] = '1098765230@qq.com';
|
||||
$cert['code'] = '';
|
||||
$cert['token'] = '936cb496df78da7794f8d866ab4f9e0c';
|
||||
$cert['status'] = '0';
|
||||
$cert['remark'] = '新创建待审核,创建时间:2018-08-20 17:01:19';
|
||||
$cert['updatetime'] = '更新时间:2018-08-20 17:01:19';
|
||||
return $cert;
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/*
|
||||
* 通讯证书文件
|
||||
@status 站点状态,-1禁止 0只读 1可用
|
||||
@siteId 站点ID
|
||||
@suIp 允许访问的IP
|
||||
@suDomain 允许访问的域名
|
||||
@api 接口用户名(站点用户名)
|
||||
@code 用户授权码
|
||||
@token 接口通讯的accesstoken文件
|
||||
*/
|
||||
$cert = array();
|
||||
$cert['id'] = '14';
|
||||
$cert['siteId'] = '27086';
|
||||
$cert['suIp'] = array('120.79.11.71');
|
||||
$cert['siteName'] = '';
|
||||
$cert['suDomain'] = array('');
|
||||
$cert['siteUrl'] = '';
|
||||
$cert['api'] = 'anchengjieshun';
|
||||
$cert['code'] = '';
|
||||
$cert['token'] = '9c20c06c513bcf9d8580a773d1a24124';
|
||||
$cert['status'] = '0';
|
||||
$cert['remark'] = '新创建待审核,创建时间:2018-05-02 09:56:11';
|
||||
$cert['updatetime'] = '更新时间:2019-01-20 11:40:48';
|
||||
return $cert;
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/*
|
||||
* 通讯证书文件
|
||||
@status 站点状态,-1禁止 0只读 1可用
|
||||
@siteId 站点ID
|
||||
@suIp 允许访问的IP
|
||||
@suDomain 允许访问的域名
|
||||
@api 接口用户名(站点用户名)
|
||||
@code 用户授权码
|
||||
@token 接口通讯的accesstoken文件
|
||||
*/
|
||||
$cert = array();
|
||||
$cert['id'] = '6';
|
||||
$cert['siteId'] = '27086';
|
||||
$cert['suIp'] = array('127.0.0.1');
|
||||
$cert['siteName'] = '';
|
||||
$cert['suDomain'] = array('');
|
||||
$cert['siteUrl'] = '';
|
||||
$cert['api'] = 'dongjiabing';
|
||||
$cert['code'] = '';
|
||||
$cert['token'] = '5ff8745bffe82e58547d5ae4dd157250';
|
||||
$cert['status'] = '0';
|
||||
$cert['remark'] = '新创建待审核,创建时间:2017-08-15 20:57:21';
|
||||
$cert['updatetime'] = '更新时间:2017-09-22 13:14:12';
|
||||
return $cert;
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/*
|
||||
* 通讯证书文件
|
||||
@status 站点状态,-1禁止 0只读 1可用
|
||||
@siteId 站点ID
|
||||
@suIp 允许访问的IP
|
||||
@suDomain 允许访问的域名
|
||||
@api 接口用户名(站点用户名)
|
||||
@code 用户授权码
|
||||
@token 接口通讯的accesstoken文件
|
||||
*/
|
||||
$cert = array();
|
||||
$cert['id'] = '22';
|
||||
$cert['siteId'] = '1540174304';
|
||||
$cert['suIp'] = array('110.52.216.185');
|
||||
$cert['siteName'] = '';
|
||||
$cert['suDomain'] = array('http:');
|
||||
$cert['siteUrl'] = '';
|
||||
$cert['api'] = 'howsou';
|
||||
$cert['code'] = '';
|
||||
$cert['token'] = 'ece82bff3ae54afa750872b01218df6d';
|
||||
$cert['status'] = '0';
|
||||
$cert['remark'] = '新创建待审核,创建时间:2018-10-22 10:11:44';
|
||||
$cert['updatetime'] = '更新时间:2018-10-22 10:13:56';
|
||||
return $cert;
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
return [
|
||||
'id' => '1', //证书ID
|
||||
'siteId' => '0', //站点ID
|
||||
'suIp' => ['::1', '127.0.0.1'], //允许访问的IP
|
||||
'siteName' => '本地测试站',
|
||||
'suDomain' => ['localhost'], //绑定域名
|
||||
'siteUrl' => '', //站点链接
|
||||
'api' => 'fm453_shopping', //授权API
|
||||
'sceret' => 'temp@te##453.com', //授权密钥
|
||||
'code' => 'Hiluker', //授权码
|
||||
'token' => '', //赋有有效期的Token(动态生成,此处暂不使用)
|
||||
'status' => '0', //站点状态,-1禁止0只读1可用
|
||||
'remark' => '本地测试时使用', //备注
|
||||
];
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/*
|
||||
* 通讯证书文件
|
||||
@status 站点状态,-1禁止 0只读 1可用
|
||||
@siteId 站点ID
|
||||
@suIp 允许访问的IP
|
||||
@suDomain 允许访问的域名
|
||||
@api 接口用户名(站点用户名)
|
||||
@code 用户授权码
|
||||
@token 接口通讯的accesstoken文件
|
||||
*/
|
||||
$cert = array();
|
||||
$cert['id'] = '4';
|
||||
$cert['siteId'] = '0';
|
||||
$cert['suIp'] = array('0.0.0.0/0');
|
||||
$cert['siteName'] = '公共接口站';
|
||||
$cert['suDomain'] = array('*');
|
||||
$cert['siteUrl'] = '';
|
||||
$cert['api'] = 'publicapi';
|
||||
$cert['code'] = 'Hiluker';
|
||||
$cert['token'] = '656733050cb05c7eacbd98bddab2784a';
|
||||
$cert['status'] = '1';
|
||||
$cert['remark'] = '公用接口账号';
|
||||
$cert['updatetime'] = '更新时间:2024-08-09 21:46:50';
|
||||
$cert['uniacid'] = '1';
|
||||
$cert['platid'] = '1';
|
||||
return $cert;
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/*
|
||||
* 通讯证书文件
|
||||
@status 站点状态,-1禁止 0只读 1可用
|
||||
@siteId 站点ID
|
||||
@suIp 允许访问的IP
|
||||
@suDomain 允许访问的域名
|
||||
@api 接口用户名(站点用户名)
|
||||
@code 用户授权码
|
||||
@token 接口通讯的accesstoken文件
|
||||
*/
|
||||
$cert = array();
|
||||
$cert['id'] = '12';
|
||||
$cert['siteId'] = '1548742316';
|
||||
$cert['suIp'] = array('116.62.209.203');
|
||||
$cert['siteName'] = '';
|
||||
$cert['suDomain'] = array('');
|
||||
$cert['siteUrl'] = '';
|
||||
$cert['api'] = 'ukl';
|
||||
$cert['code'] = '';
|
||||
$cert['token'] = 'fa919dafaed937db58047791efe413f7';
|
||||
$cert['status'] = '0';
|
||||
$cert['remark'] = '新创建待审核,创建时间:2019-01-29 14:11:56';
|
||||
return $cert;
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
return [
|
||||
'id' => '2', //证书ID
|
||||
'siteId' => '27086', //站点ID
|
||||
'suIp' => ['::1', '127.0.0.1', '61.147.125.206'], //允许访问的IP
|
||||
'siteName' => 'VCMS微信管理系统',
|
||||
'suDomain' => ['vcms.hiluker.com'], //绑定域名
|
||||
'siteUrl' => '', //站点链接
|
||||
'api' => 'fm453_shopping', //授权API
|
||||
'sceret' => 'temp@te##453.com', //授权密钥
|
||||
'code' => 'Hiluker', //授权码
|
||||
'token' => '', //赋有有效期的Token(动态生成,此处暂不使用)
|
||||
'status' => '1', //站点状态,-1禁止0只读1可用
|
||||
'remark' => 'VCMS微信管理系统使用', //备注
|
||||
//'platid' => '1', //直接固定platid值
|
||||
];
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/*
|
||||
* 通讯证书文件
|
||||
@status 站点状态,-1禁止 0只读 1可用
|
||||
@siteId 站点ID
|
||||
@suIp 允许访问的IP
|
||||
@suDomain 允许访问的域名
|
||||
@api 接口用户名(站点用户名)
|
||||
@code 用户授权码
|
||||
@token 接口通讯的accesstoken文件
|
||||
*/
|
||||
$cert = array();
|
||||
$cert['id'] = '2';
|
||||
$cert['siteId'] = '27086';
|
||||
$cert['suIp'] = array('61.147.111.178', '127.0.0.1', '::1');
|
||||
$cert['siteName'] = 'VCMS微信管理系统';
|
||||
$cert['suDomain'] = array('vcms.localhost');
|
||||
$cert['siteUrl'] = '';
|
||||
$cert['api'] = 'fm453_shopping';
|
||||
$cert['sceret'] = 'temp@te##453.com';
|
||||
$cert['code'] = 'Hiluker';
|
||||
$cert['token'] = 'bca3402b510ecd8e3603ebf746f4fbfa';
|
||||
$cert['status'] = '1';
|
||||
$cert['remark'] = 'VCMS微信管理本地开发测试系统';
|
||||
$cert['updatetime'] = '更新时间:2018-04-23 15:52:33';
|
||||
return $cert;
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/*
|
||||
* 通讯证书文件
|
||||
@status 站点状态,-1禁止 0只读 1可用
|
||||
@siteId 站点ID
|
||||
@suIp 允许访问的IP
|
||||
@suDomain 允许访问的域名
|
||||
@api 接口用户名(站点用户名)
|
||||
@code 用户授权码
|
||||
@token 接口通讯的accesstoken文件
|
||||
*/
|
||||
$cert = array();
|
||||
$cert['id'] = '15';
|
||||
$cert['siteId'] = '27086';
|
||||
$cert['suIp'] = array('120.79.11.71');
|
||||
$cert['siteName'] = '';
|
||||
$cert['suDomain'] = array('');
|
||||
$cert['siteUrl'] = '';
|
||||
$cert['api'] = 'www.haijumeng.com';
|
||||
$cert['code'] = '';
|
||||
$cert['token'] = '0da3957934b098592c557c6281ca4922';
|
||||
$cert['status'] = '0';
|
||||
$cert['remark'] = '新创建待审核,创建时间:2018-05-02 08:52:09';
|
||||
$cert['updatetime'] = '更新时间:2018-06-08 23:19:50';
|
||||
$cert['platid'] = '1';
|
||||
$cert['uniacid'] = '111';
|
||||
return $cert;
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/*
|
||||
* 通讯证书文件
|
||||
@status 站点状态,-1禁止 0只读 1可用
|
||||
@siteId 站点ID
|
||||
@suIp 允许访问的IP
|
||||
@suDomain 允许访问的域名
|
||||
@api 接口用户名(站点用户名)
|
||||
@code 用户授权码
|
||||
@token 接口通讯的accesstoken文件
|
||||
*/
|
||||
$cert = array();
|
||||
$cert['id'] = '21';
|
||||
$cert['siteId'] = '1528471799';
|
||||
$cert['suIp'] = array('36.57.163.170');
|
||||
$cert['siteName'] = '';
|
||||
$cert['suDomain'] = array('');
|
||||
$cert['siteUrl'] = '';
|
||||
$cert['api'] = 'xcx.hiluker.com';
|
||||
$cert['code'] = 'Hiluker.com';
|
||||
$cert['token'] = 'fda11ae350f6b1a231ce62766fd09dd6';
|
||||
$cert['status'] = '0';
|
||||
$cert['remark'] = '新创建待审核,创建时间:2018-06-08 23:29:59';
|
||||
$cert['updatetime'] = '更新时间:2018-06-08 23:29:59';
|
||||
return $cert;
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
namespace: frontend\tests
|
||||
actor: Tester
|
||||
paths:
|
||||
tests: tests
|
||||
log: tests/_output
|
||||
data: tests/_data
|
||||
helpers: tests/_support
|
||||
settings:
|
||||
bootstrap: _bootstrap.php
|
||||
colors: true
|
||||
memory_limit: 1024M
|
||||
modules:
|
||||
config:
|
||||
Yii2:
|
||||
configFile: 'config/test-local.php'
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
main-local.php
|
||||
params-local.php
|
||||
test-local.php
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
Yii::setAlias('@frontend', dirname(__DIR__));
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
global $_HI;
|
||||
$_HI['apiCertPath'] = Yii::getAlias('@frontend/cert/');
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
$config = [
|
||||
'components' => [
|
||||
'db' => [
|
||||
'class' => 'yii\db\Connection',
|
||||
'dsn' => 'mysql:host=127.0.0.1;dbname=sass',
|
||||
'username' => 'sass',
|
||||
'password' => 'ejxsrxZCP34xNjF2',
|
||||
'charset' => 'utf8',
|
||||
'tablePrefix' => '',
|
||||
'attributes' => [
|
||||
// use a smaller connection timeout
|
||||
PDO::ATTR_TIMEOUT => 10,
|
||||
//使用长链接
|
||||
PDO::ATTR_PERSISTENT => TRUE,
|
||||
],
|
||||
],
|
||||
//添加CHAT数据库配置(聊天室模块)
|
||||
'chatdb' => [
|
||||
'class' => 'yii\db\Connection',
|
||||
'dsn' => 'mysql:host=127.0.0.1;dbname=sass',
|
||||
'username' => 'sass',
|
||||
'password' => 'ejxsrxZCP34xNjF2',
|
||||
'charset' => 'utf8',
|
||||
'tablePrefix' => '',
|
||||
],
|
||||
//添加REALTY数据库配置(房地产模块)
|
||||
'realtydb' => [
|
||||
'class' => 'yii\db\Connection',
|
||||
'dsn' => 'mysql:host=127.0.0.1;dbname=sass',
|
||||
'username' => 'sass',
|
||||
'password' => 'ejxsrxZCP34xNjF2',
|
||||
'charset' => 'utf8',
|
||||
'tablePrefix' => '',
|
||||
],
|
||||
//添加PAGE数据库配置(页面模块)
|
||||
'pagedb' => [
|
||||
'class' => 'yii\db\Connection',
|
||||
'dsn' => 'mysql:host=127.0.0.1;dbname=sass',
|
||||
'username' => 'sass',
|
||||
'password' => 'ejxsrxZCP34xNjF2',
|
||||
'charset' => 'utf8',
|
||||
'tablePrefix' => '',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $config;
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2021-09-09 10:37:17
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2021-09-09 10:42:24
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
$config = [
|
||||
'components' => [
|
||||
'db' => [
|
||||
'class' => 'yii\db\Connection',
|
||||
'dsn' => 'mysql:host=127.0.0.1;dbname=dacms',
|
||||
'username' => 'dacms',
|
||||
'password' => 'CiwE5YbLnL7Yw8zs',
|
||||
'charset' => 'utf8',
|
||||
'tablePrefix' => '',
|
||||
'attributes' => [
|
||||
// use a smaller connection timeout
|
||||
PDO::ATTR_TIMEOUT => 10,
|
||||
//使用长链接
|
||||
PDO::ATTR_PERSISTENT => TRUE,
|
||||
],
|
||||
],
|
||||
//添加CHAT数据库配置(聊天室模块)
|
||||
'chatdb' => [
|
||||
'class' => 'yii\db\Connection',
|
||||
'dsn' => 'mysql:host=127.0.0.1;dbname=dacms',
|
||||
'username' => 'dacms',
|
||||
'password' => 'CiwE5YbLnL7Yw8zs',
|
||||
'charset' => 'utf8',
|
||||
'tablePrefix' => '',
|
||||
],
|
||||
//添加REALTY数据库配置(房地产模块)
|
||||
'realtydb' => [
|
||||
'class' => 'yii\db\Connection',
|
||||
'dsn' => 'mysql:host=127.0.0.1;dbname=dacms',
|
||||
'username' => 'dacms',
|
||||
'password' => 'CiwE5YbLnL7Yw8zs',
|
||||
'charset' => 'utf8',
|
||||
'tablePrefix' => '',
|
||||
],
|
||||
//添加PAGE数据库配置(页面模块)
|
||||
'pagedb' => [
|
||||
'class' => 'yii\db\Connection',
|
||||
'dsn' => 'mysql:host=127.0.0.1;dbname=dacms',
|
||||
'username' => 'dacms',
|
||||
'password' => 'CiwE5YbLnL7Yw8zs',
|
||||
'charset' => 'utf8',
|
||||
'tablePrefix' => '',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $config;
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
# @Author: 嗨噜客科技(www.hiluker.cn) <Fm453>
|
||||
# @Date: 1970-01-01T08:00:00+08:00
|
||||
# @Email: fm453@hiluker.com
|
||||
# @Last modified by: Fm453
|
||||
# @Last modified time: 2021-09-15T00:13:16+08:00
|
||||
|
||||
$params = array_merge(
|
||||
require(__DIR__ . '/../../common/config/params-api.php'),
|
||||
require(__DIR__ . '/../../common/config/params.php'),
|
||||
require(__DIR__ . '/params.php')
|
||||
);
|
||||
|
||||
$config = [
|
||||
'id' => 'app-frontend',
|
||||
'basePath' => dirname(__DIR__),
|
||||
'bootstrap' => ['log'],
|
||||
'controllerNamespace' => 'frontend\controllers',
|
||||
'modules' => [
|
||||
'data' => [
|
||||
'class' => 'vendor\fmsoft\modules\data\Module', //自动加载我的数据处理模型
|
||||
],
|
||||
],
|
||||
'language' => 'zh-CN',
|
||||
'components' => [
|
||||
'request' => [
|
||||
'csrfParam' => '_csrf-frontend',
|
||||
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
|
||||
'cookieValidationKey' => 'o_Rv6TiAxMkGII4dkFBKathreA5IEohp',
|
||||
'parsers' => [
|
||||
'application/json' => 'yii\web\JsonParser',
|
||||
]
|
||||
],
|
||||
'user' => [
|
||||
'identityClass' => 'common\models\User',
|
||||
'enableAutoLogin' => TRUE,
|
||||
'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => TRUE],
|
||||
],
|
||||
'session' => [
|
||||
'name' => 'advanced-frontend-api',
|
||||
],
|
||||
'log' => [
|
||||
'traceLevel' => YII_DEBUG ? 3 : 0,
|
||||
'targets' => [
|
||||
[
|
||||
'class' => 'yii\log\FileTarget',
|
||||
'levels' => ['error', 'warning'],
|
||||
],
|
||||
],
|
||||
],
|
||||
'errorHandler' => [
|
||||
'errorAction' => 'site/error',
|
||||
],
|
||||
'urlManager' => [
|
||||
'enablePrettyUrl' => FALSE,
|
||||
'enableStrictParsing' => TRUE,
|
||||
'showScriptName' => TRUE,
|
||||
'suffix' => '.hi',
|
||||
'rules' => [
|
||||
['class' => 'yii\rest\UrlRule', 'controller' => 'realty'], //为***控制器增加一个 URL 规则。这样, 用户的数据就能通过美化的 URL 和有意义的 http 动词进行访问和操作
|
||||
['class' => 'yii\rest\UrlRule', 'controller' => 'setting']
|
||||
],
|
||||
],
|
||||
],
|
||||
'params' => $params,
|
||||
];
|
||||
return $config;
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
# @Author: 嗨噜客科技(www.hiluker.cn) <Fm453>
|
||||
# @Date: 1970-01-01T08:00:00+08:00
|
||||
# @Email: fm453@hiluker.com
|
||||
# @Last modified by: Fm453
|
||||
# @Last modified time: 2021-09-15T00:09:07+08:00
|
||||
|
||||
return [
|
||||
'adminEmail' => 'fm453@lukegzs.com',
|
||||
'redis' => ['IP' => '127.0.0.1', 'PORT' => '6379']
|
||||
];
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
return [
|
||||
'id' => 'app-frontend-tests',
|
||||
'components' => [
|
||||
'assetManager' => [
|
||||
'basePath' => __DIR__ . '/../web/assets',
|
||||
],
|
||||
],
|
||||
];
|
||||
Executable
+235
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-06-04 11:06:07
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2019-11-11 13:11:55
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\Url;
|
||||
use vendor\aliyun\dysms\Sms;
|
||||
|
||||
require dirname(__FILE__) . '/_public/public.php';
|
||||
|
||||
class AlimsgController extends \yii\web\Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
$_HI['action'] = 'index';
|
||||
/*自定义常量*/
|
||||
|
||||
/*默认配置*/
|
||||
$_HI['accessKeyId'] = 'LTAIQrJFtHfqsyOt'; // AccessKeyId
|
||||
$_HI['accessKeySecret'] = 'tvGieI3vNI7Si3imauCB4rJ3OX4AR8'; // AccessKeySecret
|
||||
$_HI['sign'] = '嗨路客';
|
||||
$_HI['tmpl'] = 'SMS_116695055';
|
||||
|
||||
$_HI['reportQueueName'] = 'Alicom-Queue-31737903-SmsReport'; //状态报告接收
|
||||
$_HI['UpQueueName'] = 'Alicom-Queue-31737903-SmsUp'; //上行消息接收
|
||||
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
public function actionSend()
|
||||
{
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
|
||||
$_HI['action'] = 'post';
|
||||
//数据取出方法
|
||||
$dataPost = Yii::$app->request->post(); //YII应用内的真实或模拟POST数据
|
||||
$dataGet = Yii::$app->request->get(); //YII应用内的真实或模拟GET数据
|
||||
$params = Yii::$app->params;
|
||||
|
||||
$config = array();
|
||||
$config['accessKeyId'] = isset($dataPost['accessKeyId']) ? $dataPost['accessKeyId'] : '';
|
||||
$config['accessKeySecret'] = isset($dataPost['accessKeySecret']) ? $dataPost['accessKeySecret'] : '';
|
||||
$config['sign'] = isset($dataPost['sign']) ? $dataPost['sign'] : '';
|
||||
|
||||
$option = array();
|
||||
|
||||
$_content = isset($dataPost['content']) ? $dataPost['content'] : '';
|
||||
$_content = explode("\r\n", $_content);
|
||||
$content = array();
|
||||
foreach ($_content as $c) {
|
||||
$_c = explode(',', $c);
|
||||
$k = trim($_c[0]);
|
||||
$v = trim($_c[1]);
|
||||
$content[$k] = $v;
|
||||
}
|
||||
unset($_c);
|
||||
unset($k);
|
||||
unset($v);
|
||||
|
||||
$phone = isset($dataPost['phone']) ? $dataPost['phone'] : '';
|
||||
if ($phone) {
|
||||
$phone = explode(',', $phone);
|
||||
$phone = array_unique($phone); //去重
|
||||
$phone = array_filter($phone); //去空
|
||||
}
|
||||
|
||||
|
||||
$tmpl = isset($dataPost['tmpl']) ? $dataPost['tmpl'] : '';
|
||||
|
||||
if (isset($_GET['post']) && $_GET['post'] == 1) {
|
||||
$_POST = array('config' => $config, 'option' => $option, 'phone' => $phone, 'content' => $content, 'tmpl' => $tmpl);
|
||||
Yii::$app->request->setBodyParams($_POST); //重写模拟POST数据
|
||||
// Yii::$app->request->setQueryParams($_POST); //重写模拟GET数据
|
||||
return $this->actionPost($_POST);
|
||||
}
|
||||
|
||||
$sms = new Sms($option, $config);
|
||||
|
||||
$results = array();
|
||||
$msg = "";
|
||||
foreach ($phone as $p) {
|
||||
$result = $sms->send($p, $tmpl, $content);
|
||||
$results[$p] = $result;
|
||||
if (!$result) {
|
||||
$msg .= "【" . $p . "】发送失败,接口提示:" . $sms->errors . "\r\n";
|
||||
} else if (is_array($result) && $result['Code'] != 'OK') {
|
||||
$msg .= "【" . $p . "】发送失败,接口提示:" . $result['Message'] . "\r\n";
|
||||
} else {
|
||||
$msg .= "【" . $p . "】发送成功" . "\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
$message = array();
|
||||
$message['title'] = "阿里云短信发送测试";
|
||||
$message['class'] = "success";
|
||||
$message['button'] = array();
|
||||
$message['content'] = "短信发送完毕;接口返回:" . $msg;
|
||||
$message['button'][] = array("class" => "btn btn-success", "title" => "首页", "link" => Url::toRoute('site/index'));
|
||||
$message['button'][] = array("class" => "btn btn-info", "title" => "接口", "link" => Url::toRoute(['api/index', 'appid' => Yii::$app->user->identity->username]));
|
||||
return $this->render('//layouts/message.php', [
|
||||
'message' => $message
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionPost()
|
||||
{
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
|
||||
$_HI['action'] = 'post';
|
||||
//数据取出方法
|
||||
$dataPost = Yii::$app->request->post(); //YII应用内的真实或模拟POST数据
|
||||
$dataGet = Yii::$app->request->get(); //YII应用内的真实或模拟GET数据
|
||||
$params = Yii::$app->params;
|
||||
fmFunc_stat_times_in($username = $_FM['user']['name'], 1); //增加一次接口入站次数累计
|
||||
fmFunc_stat_bytes_in($username = $_FM['user']['name'], strlen(json_encode($dataPost))); //增加一次接口入站数据量累计
|
||||
|
||||
$return = array();
|
||||
$results = array();
|
||||
$msg = "";
|
||||
$errorCode = 0;
|
||||
|
||||
if (!isset($dataPost['config']) || !is_array($dataPost['config'])) {
|
||||
$errorCode = '45300403';
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
return json_encode($return);
|
||||
}
|
||||
$config = $dataPost['config'];
|
||||
|
||||
if (isset($dataPost['option'])) {
|
||||
if (!is_array($dataPost['option'])) {
|
||||
$errorCode = '45300404';
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
return json_encode($return);
|
||||
}
|
||||
$option = $dataPost['option'];
|
||||
} else {
|
||||
$option = array();
|
||||
}
|
||||
|
||||
if (!isset($dataPost['tmpl']) || !is_string($dataPost['tmpl'])) {
|
||||
$errorCode = '45300405';
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
return json_encode($return);
|
||||
}
|
||||
$tmpl = $dataPost['tmpl'];
|
||||
|
||||
if (!isset($dataPost['phone']) || !is_array($dataPost['phone'])) {
|
||||
$errorCode = '45300406';
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
return json_encode($return);
|
||||
}
|
||||
$phone = $dataPost['phone'];
|
||||
|
||||
if (isset($dataPost['content'])) {
|
||||
if (!is_array($dataPost['content'])) {
|
||||
$errorCode = '45300407';
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
return json_encode($return);
|
||||
}
|
||||
$content = $dataPost['content'];
|
||||
} else {
|
||||
$content = array();
|
||||
}
|
||||
|
||||
$sms = new Sms($option, $config);
|
||||
$error = $sms->errors;
|
||||
if ($error) {
|
||||
$errorCode = '45300402';
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode) . ";接口提示:" . $sms->errors . ";";;
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
$results = array();
|
||||
$msg = "";
|
||||
$errors = 0;
|
||||
$pn = count($phone);
|
||||
foreach ($phone as $p) {
|
||||
$result = $sms->send($p, $tmpl, $content);
|
||||
var_dump($result);
|
||||
die();
|
||||
$results[$p] = $result;
|
||||
if (!$result) {
|
||||
$msg .= "【" . $p . "】发送失败,接口提示:" . $sms->errors . ";";
|
||||
$errors += 1;
|
||||
} else if (is_array($result) && $result['Code'] != 'OK') {
|
||||
$msg .= "【" . $p . "】发送失败,接口提示:" . $result['Message'] . ";";
|
||||
$errors += 1;
|
||||
} else {
|
||||
$msg .= "【" . $p . "】发送成功" . ";";
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors > 0) {
|
||||
if ($errors == $pn) {
|
||||
$errorcode = 45300402;
|
||||
} else {
|
||||
$errorcode = 45300401;
|
||||
}
|
||||
}
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode) . ";" . $msg;
|
||||
$return['data'] = $dataPost;
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['total'] = isset($count) ? $count : 1;//总记录数
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
$return['sms_left'] = fmFunc_stat_sms_send($username = $_FM['user']['name'], $times = $pn - $errors); //统计短信发送并返回剩余条数
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\Url;
|
||||
use common\models\User;
|
||||
use common\models\CAccess;
|
||||
|
||||
require dirname(__FILE__) . '/_public/public_demo.php';
|
||||
|
||||
class ApiController extends \yii\web\Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
$_HI['action'] = 'index';
|
||||
$identity = Yii::$app->user->identity;
|
||||
if (!$identity) {
|
||||
return $this->goHome();
|
||||
}
|
||||
$_FM['user']['name'] = $identity->username;
|
||||
$_FM['user']['uid'] = $identity->id;
|
||||
|
||||
fmFunc_cert_afterLogin();
|
||||
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
public function actionTest()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'test';
|
||||
|
||||
$request = Yii::$app->request;
|
||||
$request->enableCsrfValidation = FALSE;
|
||||
|
||||
// 返回所有参数
|
||||
$params = $request->get();
|
||||
$_FM['params'] = $params;
|
||||
$accesstoken = isset($_FM['params']['accesstoken']) ? $_FM['params']['accesstoken'] : '';
|
||||
//查询用户信息(根据username)
|
||||
$user = CAccess::findOne(['accesstoken' => $accesstoken]);
|
||||
if ($user) {
|
||||
$user = $user->toArray();
|
||||
} else {
|
||||
$errorCode = 45300001; //未找到用户
|
||||
$result = array();
|
||||
$result['errorcode'] = $errorCode;
|
||||
$result['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$result = json_encode($result);
|
||||
die ($result);
|
||||
}
|
||||
$_FM['user'] = $user;
|
||||
$_FM['user']['name'] = $_FM['user']['username'];
|
||||
$cert = fmFunc_cert_exist($_FM['user']['name']);
|
||||
$_FM['apiCert'] = $cert;
|
||||
if ($request->isAjax) {
|
||||
/* 该请求是一个 AJAX 请求 */
|
||||
$result = json_encode(1);
|
||||
}
|
||||
if ($request->isGet) {
|
||||
/* 请求方法是 GET */
|
||||
|
||||
}
|
||||
if ($request->isPost) {
|
||||
/* 请求方法是 POST */
|
||||
}
|
||||
if ($request->isPut) {
|
||||
/* 请求方法是 PUT */
|
||||
|
||||
}
|
||||
|
||||
###定义内容类型###
|
||||
//header('Content-Type: text/html; charset=utf-8'); //网页编码
|
||||
//header('Content-Type: text/plain'); //纯文本格式
|
||||
//header('Content-Type: image/jpeg'); //JPG、JPEG
|
||||
//header('Content-Type: application/zip'); // ZIP文件
|
||||
//header('Content-Type: application/pdf'); // PDF文件
|
||||
//header('Content-Type: audio/mpeg'); // 音频文件
|
||||
//header('Content-type: text/css'); //css文件
|
||||
//header('Content-type: text/javascript'); //js文件
|
||||
//header('Content-Type: application/x-shockw**e-flash'); //Flash动画
|
||||
//header('Content-type: application/pdf'); //pdf
|
||||
//header('Content-type: text/xml'); //xml
|
||||
header('Content-type: application/json'); //json
|
||||
$_FM['apiCert']['timeused'] = getMillisecond() - $START_TIME;
|
||||
$_FM['apiCert']['stat'] = fmFunc_stat_get($username = $_FM['user']['username']);
|
||||
$result = json_encode($_FM['apiCert']);
|
||||
die($result);
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+292
@@ -0,0 +1,292 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\web\IdentityInterface;
|
||||
use yii\helpers\Url;
|
||||
|
||||
// use yii\imagine\Image;
|
||||
|
||||
class ImageController extends \yii\web\Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
$_HI['action'] = 'index';
|
||||
|
||||
//本方法采用GD库支持
|
||||
|
||||
//创建图片
|
||||
$height = isset($_HI['post']['h']) ? abs($_HI['post']['h']) : (isset($_HI['get']['h']) ? abs($_HI['get']['h']) : 0);
|
||||
$height = !$height ? 300 : $height;
|
||||
$width = isset($_HI['post']['w']) ? abs($_HI['post']['w']) : (isset($_HI['get']['w']) ? abs($_HI['get']['w']) : 0);
|
||||
$width = !$width ? 300 : $width;
|
||||
|
||||
$im = imagecreatetruecolor($width, $height) or die("Cannot Initialize new GD image stream"); //参数为宽度和高度
|
||||
// $im=ImageCreateFromJpg("https://public.hiluker.com/vcms/nopic.jpg"); //使用背景图片创建
|
||||
|
||||
$bc = isset($_HI['post']['bc']) ? ltrim($_HI['post']['bc']) : (isset($_HI['get']['bc']) ? ltrim($_HI['get']['bc']) : '');
|
||||
$bc = !$bc ? 'AFAFAF' : $bc;
|
||||
$fc = isset($_HI['post']['fc']) ? ltrim($_HI['post']['fc']) : (isset($_HI['get']['fc']) ? ltrim($_HI['get']['fc']) : '');
|
||||
$fc = !$fc ? '333333' : $fc;
|
||||
//添加颜色
|
||||
$bc = $this->Hex2RGB('#' . $bc);
|
||||
$fc = $this->Hex2RGB('#' . $fc);
|
||||
|
||||
|
||||
$text_color = imagecolorallocate($im, $fc['r'], $fc['g'], $fc['b']);
|
||||
$background_color = imagecolorallocate($im, $bc['r'], $bc['g'], $bc['b']);
|
||||
$default_color = imagecolorallocate($im, 5, 5, 5);
|
||||
|
||||
//绘制矩形图片
|
||||
imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $background_color); //填充
|
||||
// imagefilledrectangle($im , 0, 0, $width-1 , $height-1 , $default_color); //填充
|
||||
// imagerectangle($im , 0, 0, $width-1 , $height-1, $text_color); //边框
|
||||
|
||||
//添加文字
|
||||
$text = isset($_HI['post']['text']) ? trim($_HI['post']['text']) : (isset($_HI['get']['text']) ? trim($_HI['get']['text']) : '');
|
||||
$text = !($text) ? '' : html_entity_decode($text);
|
||||
// imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text );
|
||||
// 图片源;字体尺寸,文字方向,0从左至右,90从一至下;x、y,首字符起点位置,左下角坐标;color颜色索引。使用负的颜色索引值具有关闭防锯齿的效果;fontfile字体文件
|
||||
// imagettftext($im,10,0,$width/2,$height/2,$text_color,"/fonts/STHeiti Medium.ttc","☆"); //中心位置标记
|
||||
|
||||
$strlen = mb_strlen($text); //字符数(中文算1个字符)
|
||||
//BUG 180430 只输入一个字时,部分情况报错(中,0,1,`);无字符输入时报错
|
||||
if ($strlen == 0) {
|
||||
imagettftext($im, 10, 0, $width / 2 - 1, $height / 2 - 1, $default_color, "/fonts/STHeiti Medium.ttc", "☆"); //中心位置标记
|
||||
} else {
|
||||
//文字方向
|
||||
$fd = isset($_HI['post']['fd']) ? intval($_HI['post']['fd']) : (isset($_HI['get']['fd']) ? intval($_HI['get']['fd']) : -1);
|
||||
if ($fd == -1) {
|
||||
if ($width < $height) {
|
||||
$fd = 270;
|
||||
} else {
|
||||
$fd = 0;
|
||||
}
|
||||
}
|
||||
$dstyle = 1; //文本框长度以矩形长为限
|
||||
// $dstyle=2; //文本框长度以矩形宽为限
|
||||
if ($dstyle == 1) {
|
||||
$long = max($width, $height); //长
|
||||
$short = min($width, $height); //短
|
||||
$fd = ($width < $height) ? 270 : $fd;
|
||||
} else {
|
||||
$long = $width;
|
||||
$short = $height; //短
|
||||
}
|
||||
|
||||
//设置文字大小及位置、方向等
|
||||
$size_l = round($long / $strlen, 2) - 0.01;
|
||||
$size_l = intval($long / $strlen);
|
||||
$size_s = round($short / 3, 2) - 0.01;
|
||||
$size_s = intval($short / 3);
|
||||
$size = min($size_l, $size_s); //每个字的框宽限制
|
||||
|
||||
$f_w = imagefontwidth(6);
|
||||
$f_h = imagefontheight(6);
|
||||
|
||||
$fontsize = intval(($size - $f_w) / 1.2); //字体大小
|
||||
|
||||
$text_w = $f_w;
|
||||
if ($strlen > 1) {
|
||||
for ($i = 0; $i < $strlen; $i++) {
|
||||
$t = mb_substr($text, $i, 1, 'utf-8');
|
||||
$len = strlen($t);
|
||||
if ($len == 3) {
|
||||
$text_w += $fontsize + $f_w;
|
||||
} else if ($len == 2) {
|
||||
$text_w += $fontsize * 2 / 3;
|
||||
} else if ($len == 1) {
|
||||
$text_w += $fontsize * 2 / 3;
|
||||
}
|
||||
}
|
||||
$text_w = $text_w - $f_w;
|
||||
} else {
|
||||
$text_w = $fontsize;
|
||||
}
|
||||
|
||||
$p_l = $long / 2 - $text_w / 2;
|
||||
$p_l = intval($p_l);
|
||||
$p_s = $short / 2 + $fontsize / 2; //字符串底部-y轴高度
|
||||
$p_s = intval($p_s);
|
||||
|
||||
if ($fd == 90) {
|
||||
//90度时,右下角位置
|
||||
$x = $p_s - $f_h;
|
||||
$y = $p_l + $text_w;
|
||||
} else if ($fd == 270) {
|
||||
//270度时,左上角位置
|
||||
$x = $short / 2 - $fontsize / 2;
|
||||
$y = $p_l + $f_w;
|
||||
} else {
|
||||
//0度时,左下角位置
|
||||
$x = ($strlen == 1) ? $p_l - $f_w : $p_l - $fontsize / 2 + 2 * $f_w;
|
||||
$y = $p_s - $f_h;
|
||||
}
|
||||
|
||||
// var_dump('文本:'.$text);var_dump('字数:'.$strlen);var_dump('字框宽度:'.$size);var_dump('字体大小:'.$fontsize);var_dump('字体宽度:'.$f_w);var_dump('字体高度:'.$f_h);var_dump('文本框总宽度:'.$text_w);var_dump('字符X轴位置:'.$x);var_dump('字符Y轴位置:'.$y);var_dump('文字方向:'.$fd);die();
|
||||
imagettftext($im, $fontsize, $fd, $x + 1, $y + 1, $default_color, "/fonts/Arial Unicode.ttf", $text);
|
||||
imagettftext($im, $fontsize, $fd, $x, $y, $text_color, "/fonts/Arial Unicode.ttf", $text);
|
||||
}
|
||||
|
||||
//生成图片
|
||||
ob_clean();
|
||||
// header("Content-type:image/jpeg;");
|
||||
// imagejpeg($im,null,100);
|
||||
header("Content-type:image/png;");
|
||||
imagepng($im);
|
||||
//在根目录下生成图片文件
|
||||
// imagejpeg($im,"temp2.jpg",100);
|
||||
// imagepng($im,"temp2.png");
|
||||
//释放内存
|
||||
imagedestroy($im);
|
||||
}
|
||||
|
||||
/**
|
||||
* RGB转 十六进制
|
||||
* @param $rgb RGB颜色的字符串 如:rgb(255,255,255);
|
||||
* @return string 十六进制颜色值 如:#FFFFFF
|
||||
*/
|
||||
function RGB2Hex($rgb)
|
||||
{
|
||||
$regexp = "/^rgb\(([0-9]{0,3})\,\s*([0-9]{0,3})\,\s*([0-9]{0,3})\)/";
|
||||
$re = preg_match($regexp, $rgb, $match);
|
||||
$re = array_shift($match);
|
||||
$hexColor = "#";
|
||||
$hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$r = NULL;
|
||||
$c = $match[$i];
|
||||
$hexAr = array();
|
||||
while ($c > 16) {
|
||||
$r = $c % 16;
|
||||
$c = ($c / 16) >> 0;
|
||||
array_push($hexAr, $hex[$r]);
|
||||
}
|
||||
array_push($hexAr, $hex[$c]);
|
||||
$ret = array_reverse($hexAr);
|
||||
$item = implode('', $ret);
|
||||
$item = str_pad($item, 2, '0', STR_PAD_LEFT);
|
||||
$hexColor .= $item;
|
||||
}
|
||||
return $hexColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 十六进制 转 RGB
|
||||
*/
|
||||
function Hex2RGB($hexColor)
|
||||
{
|
||||
$color = str_replace('#', '', $hexColor);
|
||||
if (strlen($color) > 3) {
|
||||
$rgb = array(
|
||||
'r' => hexdec(substr($color, 0, 2)),
|
||||
'g' => hexdec(substr($color, 2, 2)),
|
||||
'b' => hexdec(substr($color, 4, 2))
|
||||
);
|
||||
} else {
|
||||
$color = $hexColor;
|
||||
$r = substr($color, 0, 1) . substr($color, 0, 1);
|
||||
$g = substr($color, 1, 1) . substr($color, 1, 1);
|
||||
$b = substr($color, 2, 1) . substr($color, 2, 1);
|
||||
$rgb = array(
|
||||
'r' => hexdec($r),
|
||||
'g' => hexdec($g),
|
||||
'b' => hexdec($b)
|
||||
);
|
||||
}
|
||||
return $rgb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成图片
|
||||
* @param array 参数,包括图片和文字
|
||||
* @param string $filename 生成海报文件名,不传此参数则不生成文件,直接输出图片
|
||||
* @return [type] [description]
|
||||
*/
|
||||
function createPoster($config = array(), $filename = "")
|
||||
{
|
||||
//如果要看报什么错,可以先注释调这个header
|
||||
if (empty($filename)) header("content-type: image/png");
|
||||
$imageDefault = array(
|
||||
'left' => 0,
|
||||
'top' => 0,
|
||||
'right' => 0,
|
||||
'bottom' => 0,
|
||||
'width' => 100,
|
||||
'height' => 100,
|
||||
'opacity' => 100
|
||||
);
|
||||
$textDefault = array(
|
||||
'text' => '',
|
||||
'left' => 0,
|
||||
'top' => 0,
|
||||
'fontSize' => 32, //字号
|
||||
'fontColor' => '255,255,255', //字体颜色
|
||||
'angle' => 0,
|
||||
);
|
||||
$background = $config['background'];//海报最底层得背景
|
||||
//背景方法
|
||||
$backgroundInfo = getimagesize($background);
|
||||
$backgroundFun = 'imagecreatefrom' . image_type_to_extension($backgroundInfo[2], FALSE);
|
||||
$background = $backgroundFun($background);
|
||||
$backgroundWidth = imagesx($background); //背景宽度
|
||||
$backgroundHeight = imagesy($background); //背景高度
|
||||
$imageRes = imageCreatetruecolor($backgroundWidth, $backgroundHeight);
|
||||
$color = imagecolorallocate($imageRes, 0, 0, 0);
|
||||
imagefill($imageRes, 0, 0, $color);
|
||||
// imageColorTransparent($imageRes, $color); //颜色透明
|
||||
imagecopyresampled($imageRes, $background, 0, 0, 0, 0, imagesx($background), imagesy($background), imagesx($background), imagesy($background));
|
||||
//处理了图片
|
||||
if (!empty($config['image'])) {
|
||||
foreach ($config['image'] as $key => $val) {
|
||||
$val = array_merge($imageDefault, $val);
|
||||
$info = getimagesize($val['url']);
|
||||
$function = 'imagecreatefrom' . image_type_to_extension($info[2], FALSE);
|
||||
if ($val['stream']) { //如果传的是字符串图像流
|
||||
$info = getimagesizefromstring($val['url']);
|
||||
$function = 'imagecreatefromstring';
|
||||
}
|
||||
$res = $function($val['url']);
|
||||
$resWidth = $info[0];
|
||||
$resHeight = $info[1];
|
||||
//建立画板 ,缩放图片至指定尺寸
|
||||
$canvas = imagecreatetruecolor($val['width'], $val['height']);
|
||||
imagefill($canvas, 0, 0, $color);
|
||||
//关键函数,参数(目标资源,源,目标资源的开始坐标x,y, 源资源的开始坐标x,y,目标资源的宽高w,h,源资源的宽高w,h)
|
||||
imagecopyresampled($canvas, $res, 0, 0, 0, 0, $val['width'], $val['height'], $resWidth, $resHeight);
|
||||
$val['left'] = $val['left'] < 0 ? $backgroundWidth - abs($val['left']) - $val['width'] : $val['left'];
|
||||
$val['top'] = $val['top'] < 0 ? $backgroundHeight - abs($val['top']) - $val['height'] : $val['top'];
|
||||
//放置图像
|
||||
imagecopymerge($imageRes, $canvas, $val['left'], $val['top'], $val['right'], $val['bottom'], $val['width'], $val['height'], $val['opacity']);//左,上,右,下,宽度,高度,透明度
|
||||
}
|
||||
}
|
||||
//处理文字
|
||||
if (!empty($config['text'])) {
|
||||
foreach ($config['text'] as $key => $val) {
|
||||
$val = array_merge($textDefault, $val);
|
||||
list($R, $G, $B) = explode(',', $val['fontColor']);
|
||||
$fontColor = imagecolorallocate($imageRes, $R, $G, $B);
|
||||
$val['left'] = $val['left'] < 0 ? $backgroundWidth - abs($val['left']) : $val['left'];
|
||||
$val['top'] = $val['top'] < 0 ? $backgroundHeight - abs($val['top']) : $val['top'];
|
||||
imagettftext($imageRes, $val['fontSize'], $val['angle'], $val['left'], $val['top'], $fontColor, $val['fontPath'], $val['text']);
|
||||
}
|
||||
}
|
||||
//生成图片
|
||||
if (!empty($filename)) {
|
||||
$res = imagejpeg($imageRes, $filename, 90); //保存到本地
|
||||
imagedestroy($imageRes);
|
||||
if (!$res) return FALSE;
|
||||
return $filename;
|
||||
} else {
|
||||
imagejpeg($imageRes); //在浏览器上显示
|
||||
imagedestroy($imageRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+113
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\Url;
|
||||
use dataModel;
|
||||
|
||||
//必须添加这一句,以便引入dataModel外部类库
|
||||
|
||||
require dirname(__FILE__) . '/_public/public.php';
|
||||
|
||||
class SettingController extends \yii\web\Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
public function actionGet()
|
||||
{
|
||||
global $_FM;
|
||||
$_FM['siteRoot'] = Url::base(TRUE);
|
||||
$_FM['siteUrl'] = Url::home(TRUE);
|
||||
$_FM['urlScript'] = Url::home();
|
||||
$_FM['yii']['action'] = 'get';
|
||||
//设置数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$data = array();
|
||||
|
||||
$op = isset($dataGet['op']) ? $dataGet['op'] : 'index';
|
||||
$op = in_array($op, array('index', 'deleted', 'unused')) ? $op : 'index';
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataGet);
|
||||
|
||||
$connection = yii::$app->db;
|
||||
$tablePre = 'hi';
|
||||
$table = 'setting';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = '客户端设置实例';
|
||||
$f_sn_title = '客户端系统设置实例';
|
||||
$o_sn_title = '客户端系统设置集';
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
|
||||
//依次取用,顺序不可更改
|
||||
require dirname(__FILE__) . '/_public/s_sn.php';
|
||||
require dirname(__FILE__) . '/_public/f_sn.php';
|
||||
require dirname(__FILE__) . '/_public/o_sn.php';
|
||||
require dirname(__FILE__) . '/_public/get_data.php';
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
global $_FM;
|
||||
$_FM['siteRoot'] = Url::base(TRUE);
|
||||
$_FM['siteUrl'] = Url::home(TRUE);
|
||||
$_FM['urlScript'] = Url::home();
|
||||
$_FM['yii']['action'] = 'index';
|
||||
require dirname(__FILE__) . '/SettingController/index.php';
|
||||
//return $this->render('index');
|
||||
}
|
||||
|
||||
public function actionSave()
|
||||
{
|
||||
global $_FM;
|
||||
$_FM['siteRoot'] = Url::base(TRUE);
|
||||
$_FM['siteUrl'] = Url::home(TRUE);
|
||||
$_FM['urlScript'] = Url::home();
|
||||
$_FM['yii']['action'] = 'save';
|
||||
//设置数据保存方法
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost);
|
||||
|
||||
$connection = yii::$app->db;
|
||||
$tablePre = 'hi';
|
||||
$table = 'setting';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = '客户端设置实例';
|
||||
$f_sn_title = '客户端系统设置实例';
|
||||
$o_sn_title = '客户端系统设置集';
|
||||
|
||||
//依次取用,顺序不可更改
|
||||
require dirname(__FILE__) . '/_public/s_sn.php';
|
||||
require dirname(__FILE__) . '/_public/f_sn.php';
|
||||
require dirname(__FILE__) . '/_public/o_sn.php';
|
||||
require dirname(__FILE__) . '/_public/save_data.php';
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = '已保存';
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
}
|
||||
+484
@@ -0,0 +1,484 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\Url;
|
||||
|
||||
use dataModel;
|
||||
|
||||
//必须添加这一句,以便引入dataModel外部类库
|
||||
|
||||
require dirname(__FILE__) . '/_public/public.php';
|
||||
|
||||
class MetadataController extends \yii\web\Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
$_HI['action'] = 'index';
|
||||
require dirname(__FILE__) . '/SettingController/index.php';
|
||||
}
|
||||
|
||||
public function actionGet()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'get';
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
$data['sqls'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost);
|
||||
|
||||
$connection = yii::$app->db;
|
||||
$tablePre = 's';
|
||||
$table = 'metadata';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Metadata s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Metadata f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Metadata o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //模型数据,返回self列表\param列表
|
||||
require dirname(__FILE__) . '/_public/list_self.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => $v) {
|
||||
$s_sn = $v['sn'];
|
||||
$record_self = $v;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$errorCode = 0;
|
||||
$record_param = $result;
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['title', 'status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$list[$k] = $record;
|
||||
}
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
case 'instance'; //实例数据,根据条件返回form表中的数据\param列表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
require dirname(__FILE__) . '/_public/list_form.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => &$v) {
|
||||
$record_form = $v;
|
||||
//取默认参数
|
||||
$f_sn = 0;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$f_sn = $record_form['sn'];
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_form;
|
||||
$record['params'] = $record_param;
|
||||
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$v = $record;
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
case 'content'; //内容数据,根据条件返回order表中的数据\addon列表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$o_sn = isset($data['addons']['o_sn']) ? intval($data['addons']['o_sn']) : 0;
|
||||
require dirname(__FILE__) . '/_public/list_order.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => &$v) {
|
||||
$record_form = $v;
|
||||
//取默认参数
|
||||
$o_sn = 0;
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$o_sn = $record_form['sn'];
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_form;
|
||||
$record['params'] = $record_param;
|
||||
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$v = $record;
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['total'] = isset($count) ? $count : 1;//总记录数
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'detail';
|
||||
//取单条数据详情
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost);
|
||||
|
||||
$connection = yii::$app->db;
|
||||
$tablePre = 's';
|
||||
$table = 'metadata';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Metadata s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Metadata f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Metadata o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //模型,返回self表与param表数据
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_self.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
$s_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$errorCode = 0;
|
||||
$record_param = $result;
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['title', 'status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300304;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'instance'; //实例,返回form表\param表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_form.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
//取默认参数
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$f_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
unset($record_param['default'][$kk]); //只对在模型中定义的默认参数进行重置
|
||||
}
|
||||
//unset($record_param['default']); //重置全部默认参数
|
||||
}
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300304;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'content'; //内容,返回order表\addon表数据
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_order.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
//取默认参数
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$o_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300306;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$errorCode = 4530039999;
|
||||
break;
|
||||
}
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function actionSave()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'save';
|
||||
|
||||
//数据保存方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost); //过滤后的可用值
|
||||
$inbytes = strlen(json_encode($data));//长度字节统计
|
||||
fmFunc_stat_times_in($username = $_FM['user']['name'], 1); //增加一次接口入站次数累计
|
||||
fmFunc_stat_bytes_in($username = $_FM['user']['name'], $inbytes); //增加一次接口入站数据量累计
|
||||
|
||||
$connection = yii::$app->db;
|
||||
$tablePre = 's';
|
||||
$table = 'metadata';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Page s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Page f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Page o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = '已保存';
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //模型数据,保存到self与param表
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
$s_sn = intval($data['addons']['sn']);
|
||||
require dirname(__FILE__) . '/_public/update_self.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_self.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/s_sn.php';
|
||||
}
|
||||
//写param表
|
||||
require dirname(__FILE__) . '/_public/save_param.php';
|
||||
//返回模型SN
|
||||
$record = $s_sn;
|
||||
break;
|
||||
|
||||
case 'instance'; //实例数据,保存到form与param表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
require dirname(__FILE__) . '/_public/update_form.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_form.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/f_sn.php';
|
||||
}
|
||||
//写param表
|
||||
require dirname(__FILE__) . '/_public/save_param.php';
|
||||
//返回模型SN
|
||||
$record = $f_sn;
|
||||
break;
|
||||
|
||||
case 'content'; //内容数据,保存到order与addon表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$o_sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
require dirname(__FILE__) . '/_public/update_order.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_order.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/o_sn.php';
|
||||
}
|
||||
//写addon表
|
||||
require dirname(__FILE__) . '/_public/save_addon.php';
|
||||
//返回模型SN
|
||||
$record = $o_sn;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ($errorCode > 0) {
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
}
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+142
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\web\IdentityInterface;
|
||||
use common\models\User;
|
||||
use common\models\LoginForm;
|
||||
|
||||
//use yii\helpers\Url;
|
||||
|
||||
//use dataModel; //必须添加这一句,以便引入dataModel外部类库
|
||||
|
||||
class OssController extends \yii\web\Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
$_HI['action'] = 'index';
|
||||
}
|
||||
|
||||
/**
|
||||
* Login.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionLogin()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
|
||||
$request = Yii::$app->request;
|
||||
$get = $request->get();
|
||||
$post = $request->post();
|
||||
|
||||
if (isset($_GET['api']) && $_GET['api']) {
|
||||
//API接口请求,模拟登陆
|
||||
|
||||
//查询用户信息(根据username)
|
||||
$connection = yii::$app->db;
|
||||
$sql = "SELECT * FROM c_user WHERE username = :username";
|
||||
$params[':username'] = urldecode($_GET['LoginForm']['username']);
|
||||
$_user = fmFunc_pdo_yii_fetch($connection, $sql, $params);
|
||||
if (!$_user) {
|
||||
$errorCode = 45300001; //未找到用户
|
||||
$result = array();
|
||||
$result['errorcode'] = $errorCode;
|
||||
$result['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$result = json_encode($result);
|
||||
die ($result);
|
||||
}
|
||||
|
||||
//如果cert证书文件文件存在,则判断;域名、IP不合规时,不允许访问
|
||||
$username = $_GET['LoginForm']['username'];
|
||||
$cert = fmFunc_cert_exist($username);
|
||||
$viaDomain = fmFunc_server_via_domain();
|
||||
$viaIP = fmFunc_server_via_ip();
|
||||
$_FM['viaDomain'] = $viaDomain;
|
||||
$_FM['viaIp'] = $viaIP;
|
||||
$isAvailable = $cert ? fmFunc_cert_beforeLogin($cert, $viaIP, $viaDomain) : TRUE;
|
||||
if (!$isAvailable) {
|
||||
$errorCode = 45300101; //非法访问1(来路IP或域名不在白名单中)
|
||||
$result = array();
|
||||
$result['errorcode'] = $errorCode;
|
||||
$result['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$result = json_encode($result);
|
||||
die ($result);
|
||||
}
|
||||
|
||||
//安全校验,登陆密码、授权码auth_key
|
||||
$auth_key = $_user['auth_key'];
|
||||
$hash = $_user['password_hash'];
|
||||
$password = urldecode($_GET['LoginForm']['password']);
|
||||
|
||||
$isPwdRight = Yii::$app->getSecurity()->validatePassword($password, $hash);
|
||||
if (!$isPwdRight) {
|
||||
$errorCode = 45300002; //密码错误
|
||||
$result = array();
|
||||
$result['errorcode'] = $errorCode;
|
||||
$result['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$result = json_encode($result);
|
||||
die ($result);
|
||||
}
|
||||
|
||||
if ($_user['status'] < 10) {
|
||||
$errorCode = 45300003; //账号被冻结
|
||||
$result = array();
|
||||
$result['errorcode'] = $errorCode;
|
||||
$result['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$result = json_encode($result);
|
||||
die ($result);
|
||||
}
|
||||
|
||||
//校验结束
|
||||
// 使用指定用户名获取用户身份实例
|
||||
$identity = User::findOne(['username' => $_GET['LoginForm']['username']]);
|
||||
|
||||
// 登录用户,有效期30d
|
||||
$duration = 3600 * 24 * 30;
|
||||
$_login = Yii::$app->user->login($identity, $duration);
|
||||
if ($_login) {
|
||||
//将用户信息写入全局变量
|
||||
$_FM['user']['name'] = $identity->username;
|
||||
$_FM['user']['uid'] = $identity->id;
|
||||
$result = 0;
|
||||
$result = json_encode($result);
|
||||
|
||||
//执行登陆后的证书创建/更新等工作
|
||||
fmFunc_cert_afterLogin();
|
||||
|
||||
//将token以data结果返回到客户侧
|
||||
$result = array();
|
||||
$result['errorcode'] = 0;
|
||||
$result['data'] = $_FM['token'];
|
||||
$result = json_encode($result);
|
||||
echo $result; //输出结果到前端视图渲染一次,否则客户侧的模拟登陆无法取cookie
|
||||
return; //返回,否则会继续执行最下面的未知报错
|
||||
} else {
|
||||
$errorCode = 45300004; //登陆失败
|
||||
$result = array();
|
||||
$result['errorcode'] = $errorCode;
|
||||
$result['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$result = json_encode($result);
|
||||
die ($result);
|
||||
}
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$errorCode = 4530009999; //未知错误
|
||||
$result['errorcode'] = $errorCode;
|
||||
$result['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$result = json_encode($result);
|
||||
die ($result);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+483
@@ -0,0 +1,483 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\Url;
|
||||
|
||||
use dataModel;
|
||||
|
||||
//必须添加这一句,以便引入dataModel外部类库
|
||||
|
||||
require dirname(__FILE__) . '/_public/public.php';
|
||||
|
||||
class PageController extends \yii\web\Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
$_HI['action'] = 'index';
|
||||
require dirname(__FILE__) . '/SettingController/index.php';
|
||||
}
|
||||
|
||||
public function actionGet()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'get';
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
$data['sqls'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost);
|
||||
|
||||
$connection = yii::$app->pagedb;
|
||||
$tablePre = 's';
|
||||
$table = 'page';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Page s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Page f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Page o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //模型数据,返回self列表\param列表
|
||||
require dirname(__FILE__) . '/_public/list_self.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => $v) {
|
||||
$s_sn = $v['sn'];
|
||||
$record_self = $v;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$errorCode = 0;
|
||||
$record_param = $result;
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['title', 'status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$list[$k] = $record;
|
||||
}
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
case 'instance'; //实例数据,根据条件返回form表中的数据\param列表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
require dirname(__FILE__) . '/_public/list_form.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => &$v) {
|
||||
$record_form = $v;
|
||||
//取默认参数
|
||||
$f_sn = 0;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$f_sn = $record_form['sn'];
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_form;
|
||||
$record['params'] = $record_param;
|
||||
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$v = $record;
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
case 'content'; //内容数据,根据条件返回order表中的数据\addon列表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$o_sn = isset($data['addons']['o_sn']) ? intval($data['addons']['o_sn']) : 0;
|
||||
require dirname(__FILE__) . '/_public/list_order.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => &$v) {
|
||||
$record_form = $v;
|
||||
//取默认参数
|
||||
$o_sn = 0;
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$o_sn = $record_form['sn'];
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_form;
|
||||
$record['params'] = $record_param;
|
||||
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$v = $record;
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['total'] = isset($count) ? $count : 1;//总记录数
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'detail';
|
||||
//取单条数据详情
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost);
|
||||
|
||||
$connection = yii::$app->pagedb;
|
||||
$tablePre = 's';
|
||||
$table = 'page';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Page s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Page f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Page o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //模型,返回self表与param表数据
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_self.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
$s_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$errorCode = 0;
|
||||
$record_param = $result;
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['title', 'status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300304;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'instance'; //实例,返回form表\param表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_form.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
//取默认参数
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$f_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
unset($record_param['default'][$kk]); //只对在模型中定义的默认参数进行重置
|
||||
}
|
||||
//unset($record_param['default']); //重置全部默认参数
|
||||
}
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300304;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'content'; //内容,返回order表\addon表数据
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_order.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
//取默认参数
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$o_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300306;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$errorCode = 4530039999;
|
||||
break;
|
||||
}
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function actionSave()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'save';
|
||||
|
||||
//数据保存方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost); //过滤后的可用值
|
||||
$inbytes = strlen(json_encode($data));//长度字节统计
|
||||
fmFunc_stat_times_in($username = $_FM['user']['name'], 1); //增加一次接口入站次数累计
|
||||
fmFunc_stat_bytes_in($username = $_FM['user']['name'], $inbytes); //增加一次接口入站数据量累计
|
||||
|
||||
$connection = yii::$app->pagedb;
|
||||
$tablePre = 's';
|
||||
$table = 'page';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Page s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Page f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Page o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = '已保存';
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //模型数据,保存到self与param表
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
$s_sn = intval($data['addons']['sn']);
|
||||
require dirname(__FILE__) . '/_public/update_self.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_self.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/s_sn.php';
|
||||
}
|
||||
//写param表
|
||||
require dirname(__FILE__) . '/_public/save_param.php';
|
||||
//返回模型SN
|
||||
$record = $s_sn;
|
||||
break;
|
||||
|
||||
case 'instance'; //实例数据,保存到form与param表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
require dirname(__FILE__) . '/_public/update_form.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_form.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/f_sn.php';
|
||||
}
|
||||
//写param表
|
||||
require dirname(__FILE__) . '/_public/save_param.php';
|
||||
//返回模型SN
|
||||
$record = $f_sn;
|
||||
break;
|
||||
|
||||
case 'content'; //内容数据,保存到order与addon表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$o_sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
require dirname(__FILE__) . '/_public/update_order.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_order.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/o_sn.php';
|
||||
}
|
||||
//写addon表
|
||||
require dirname(__FILE__) . '/_public/save_addon.php';
|
||||
//返回模型SN
|
||||
$record = $o_sn;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ($errorCode > 0) {
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
}
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\Url;
|
||||
use dataModel;
|
||||
|
||||
//必须添加这一句,以便引入dataModel外部类库
|
||||
|
||||
require dirname(__FILE__) . '/_public/public.php';
|
||||
|
||||
class SettingController extends \yii\web\Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
public function actionGet()
|
||||
{
|
||||
global $_FM;
|
||||
$_FM['siteRoot'] = Url::base(TRUE);
|
||||
$_FM['siteUrl'] = Url::home(TRUE);
|
||||
$_FM['urlScript'] = Url::home();
|
||||
$_FM['yii']['action'] = 'get';
|
||||
//设置数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$data = array();
|
||||
|
||||
$op = isset($dataGet['op']) ? $dataGet['op'] : 'index';
|
||||
$op = in_array($op, array('index', 'deleted', 'unused')) ? $op : 'index';
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataGet);
|
||||
|
||||
$connection = yii::$app->db;
|
||||
$tablePre = 'hi';
|
||||
$table = 'setting';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = '客户端设置实例';
|
||||
$f_sn_title = '客户端系统设置实例';
|
||||
$o_sn_title = '客户端系统设置集';
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
|
||||
//依次取用,顺序不可更改
|
||||
require dirname(__FILE__) . '/_public/s_sn.php';
|
||||
require dirname(__FILE__) . '/_public/f_sn.php';
|
||||
require dirname(__FILE__) . '/_public/o_sn.php';
|
||||
require dirname(__FILE__) . '/_public/get_data.php';
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
global $_FM;
|
||||
$_FM['siteRoot'] = Url::base(TRUE);
|
||||
$_FM['siteUrl'] = Url::home(TRUE);
|
||||
$_FM['urlScript'] = Url::home();
|
||||
$_FM['yii']['action'] = 'index';
|
||||
require dirname(__FILE__) . '/SettingController/index.php';
|
||||
//return $this->render('index');
|
||||
}
|
||||
|
||||
public function actionSave()
|
||||
{
|
||||
global $_FM;
|
||||
$_FM['siteRoot'] = Url::base(TRUE);
|
||||
$_FM['siteUrl'] = Url::home(TRUE);
|
||||
$_FM['urlScript'] = Url::home();
|
||||
$_FM['yii']['action'] = 'save';
|
||||
//设置数据保存方法
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost);
|
||||
|
||||
$connection = yii::$app->db;
|
||||
$tablePre = 'hi';
|
||||
$table = 'setting';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = '客户端设置实例';
|
||||
$f_sn_title = '客户端系统设置实例';
|
||||
$o_sn_title = '客户端系统设置集';
|
||||
|
||||
//依次取用,顺序不可更改
|
||||
require dirname(__FILE__) . '/_public/s_sn.php';
|
||||
require dirname(__FILE__) . '/_public/f_sn.php';
|
||||
require dirname(__FILE__) . '/_public/o_sn.php';
|
||||
require dirname(__FILE__) . '/_public/save_data.php';
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = '已保存';
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+394
@@ -0,0 +1,394 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2019-04-27 22:19:28
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2019-04-27 22:28:12
|
||||
*/
|
||||
|
||||
/**
|
||||
* 利用workerman制作的推送接口控制器(演示版,默认针对vcms的fm453_*系列应用)
|
||||
*/
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
|
||||
use dataModel;
|
||||
|
||||
//必须添加这一句,以便引入dataModel外部类库
|
||||
|
||||
// 引用GateWay Client
|
||||
require(__DIR__ . '/../../vendor/workerman/GatewayClient-3.0.0/Gateway.php');
|
||||
|
||||
// GatewayClient 3.0.0版本开始要使用命名空间
|
||||
use GatewayClient\Gateway;
|
||||
|
||||
// 设置GatewayWorker服务的Register服务ip和端口
|
||||
Gateway::$registerAddress = '127.0.0.1:4530';
|
||||
|
||||
class PushController extends Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
/**
|
||||
* 绑定客户端与指定客户id\分组id
|
||||
*/
|
||||
public function actionBind()
|
||||
{
|
||||
global $_FM;
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
header('Access-Control-Allow-Origin:*'); //允许任何网站通过ajax发送请求
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$group_pre = 'VCMS-IMMS';
|
||||
|
||||
//前台已经建立起长链接,取得了客户端ID号;需要绑定到当前用户,并返回用户uid,供服务侧同步绑定校验
|
||||
$viaDomain = fmFunc_server_via_domain(); //来路域名
|
||||
$viaIP = fmFunc_server_via_ip(); //来路IP
|
||||
$timestamp = isset($_FM['timestamp']) ? $_FM['timestamp'] : time();
|
||||
|
||||
//通过前端GET传入的
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : 0;
|
||||
$accessToken = isset($dataGet['accesstoken']) ? $dataGet['accesstoken'] : 0;
|
||||
|
||||
//判断accesstoken有效性
|
||||
/*
|
||||
@有效性规则判断
|
||||
*Yii::$app->user->identity->username,Yii::$app->user->identity->id 当前用户账号及id
|
||||
*domain 域名匹配
|
||||
*expiretime 有效期判断
|
||||
*$_FM['apiCert'] 服务器证书
|
||||
*/
|
||||
$connection = yii::$app->db;
|
||||
$sql = "SELECT `username` FROM c_access WHERE accesstoken = :accesstoken AND domain = :domain AND expiretime > :expiretime ORDER BY id ASC";
|
||||
$params = array();
|
||||
$params[':accesstoken'] = $accessToken;
|
||||
$params[':domain'] = $viaDomain;
|
||||
$params[':expiretime'] = $timestamp;
|
||||
$result = fmFunc_pdo_yii_fetch($connection, $sql, $params);
|
||||
if ($result) {
|
||||
$username = $result['username'];
|
||||
//加载证书文件,但无用户登陆状态
|
||||
$cert = $username . '.php';
|
||||
if (file_exists($_HI['apiCertPath'] . $cert)) {
|
||||
$_FM['apiCert'] = array_merge(include($_HI['apiCertPath'] . $cert));
|
||||
}
|
||||
}
|
||||
$_FM['apiCert']['token'] = $accessToken;
|
||||
|
||||
//处理POST数据
|
||||
$client_type = isset($dataPost['client_type']) ? $dataPost['client_type'] : 'undefined';
|
||||
$isWeb = ($client_type == 'web') ? TRUE : FALSE;
|
||||
$isApp = ($client_type == 'app') ? TRUE : FALSE;
|
||||
$isAppWeb = ($client_type == 'appweb') ? TRUE : FALSE;
|
||||
|
||||
$group_ids = array();
|
||||
|
||||
//根据当前用户身份生成可准确识别的用户ID
|
||||
$uid = isset($dataPost['uid']) ? $dataPost['uid'] : 'undefined';
|
||||
$uid = fmFunc_server_hash_id($uid);
|
||||
|
||||
$group_id = isset($dataPost['groupid']) ? $dataPost['groupid'] : 0;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
// client_id与uid绑定
|
||||
Gateway::bindUid($client_id, $uid);
|
||||
// 加入某个群组(可调用多次加入多个群组)
|
||||
Gateway::joinGroup($client_id, $group_id); //当前用户所在的会员组
|
||||
|
||||
//继续根据创建更多分组
|
||||
$do = isset($dataPost['do']) ? $dataPost['do'] : 'undefined';
|
||||
$ac = isset($dataPost['ac']) ? $dataPost['ac'] : 'undefined';
|
||||
$op = isset($dataPost['op']) ? $dataPost['op'] : 'undefined';
|
||||
|
||||
if ($isWeb) {
|
||||
$type = 'web';
|
||||
$group_id = $type . '_' . $do . '_' . $ac . '_' . $op;
|
||||
$group_id = $group_pre . $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id);
|
||||
|
||||
$group_id = $type . '_' . $do . '_' . $ac;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id);
|
||||
|
||||
$group_id = $type . '_' . $do;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id);
|
||||
|
||||
} else {
|
||||
$type = 'app';
|
||||
$group_id = $type . '_' . $do . '_' . $ac . '_' . $op;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id);
|
||||
|
||||
$group_id = $type . '_' . $do . '_' . $ac;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id);
|
||||
|
||||
$group_id = $type . '_' . $do;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id);
|
||||
|
||||
$group_id = $type;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id); //当前用户并入前台用户组
|
||||
|
||||
if ($isAppWeb) {
|
||||
$type = 'appweb';
|
||||
$group_id = $type;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id); //当前用户并入前台核销用户组
|
||||
}
|
||||
}
|
||||
|
||||
//发送反馈消息
|
||||
$message = array();
|
||||
$message = '棒,客户端绑定成功!';
|
||||
|
||||
$data = array();
|
||||
$data['type'] = 'tips';
|
||||
$data['msg'] = $message;
|
||||
$data['groupids'] = $group_ids;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收客户端数据
|
||||
*/
|
||||
public function actionIn()
|
||||
{
|
||||
$group_pre = 'VCMS-IMMS';
|
||||
header('Access-Control-Allow-Origin:*'); //允许任何网站通过ajax发送请求
|
||||
// 建立socket连接到内部推送端口
|
||||
$client = stream_socket_client('tcp://127.0.0.1:4530');
|
||||
|
||||
//如果用户已经登陆,uid和群组id存在
|
||||
//TBD 构建uid、group_id的生成方式
|
||||
$uid = isset($dataPost['uid']) ? $dataPost['uid'] : 0;
|
||||
$group_id = isset($dataPost['group']) ? $dataPost['group'] : 0;
|
||||
|
||||
//$client_id 通过前端传入
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : 0;
|
||||
|
||||
// 推送的数据,包含uid字段,表示是给这个uid推送
|
||||
$uid = isset(Yii::$app->user->identity->username) ? Yii::$app->user->identity->username : '0';
|
||||
$data = array('uid' => $uid, 'msg' => urlencode('嗯,这个是测试用的'));
|
||||
|
||||
// 发送数据,注意该端口是Text协议的端口,Text协议需要在数据末尾加上换行符
|
||||
fwrite($client, json_encode($data) . "\n");
|
||||
|
||||
// 读取推送结果
|
||||
// echo '$client=='.$client;
|
||||
//echo fread($client, 8192);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向客户端推送消息
|
||||
*/
|
||||
public function actionOut()
|
||||
{
|
||||
global $_FM;
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$params = Yii::$app->params;
|
||||
header('Access-Control-Allow-Origin:*'); //允许任何网站通过ajax发送请求
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$group_pre = 'VCMS-IMMS';
|
||||
|
||||
/*设置REDIS缓存*/
|
||||
//初始化$cache = new \Redis();
|
||||
$cache = new \Redis();
|
||||
$cache->connect($params['redis']['IP'], $params['redis']['PORT']);
|
||||
// 先检查是否存在,然后写入并设置有效时间
|
||||
$key = 'FmWebSorcketCount';
|
||||
$CACHE_PREFIX = 'DACMS';
|
||||
$count = 0;
|
||||
if ($cache->exists($CACHE_PREFIX . $key)) {
|
||||
// 读取
|
||||
$count = $cache->get($CACHE_PREFIX . $key);
|
||||
//清除
|
||||
$cache->delete($CACHE_PREFIX . $key);
|
||||
}
|
||||
|
||||
$cache->set($CACHE_PREFIX . $key, $count + 1);
|
||||
$expire = time() + 604800; //一周时间再过期
|
||||
$cache->expire($CACHE_PREFIX . $key, $expire);
|
||||
|
||||
//前台已经建立起长链接,取得了客户端ID号;需要绑定到当前用户,并返回用户uid,供服务侧同步绑定校验
|
||||
$viaDomain = fmFunc_server_via_domain(); //来路域名
|
||||
$viaIP = fmFunc_server_via_ip(); //来路IP
|
||||
$timestamp = isset($_FM['timestamp']) ? $_FM['timestamp'] : time();
|
||||
|
||||
//通过前端GET传入的
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : '7f000001b0f400000010';
|
||||
$accessToken = isset($dataGet['accesstoken']) ? $dataGet['accesstoken'] : 0;
|
||||
|
||||
//判断accesstoken有效性
|
||||
/*
|
||||
@有效性规则判断
|
||||
*Yii::$app->user->identity->username,Yii::$app->user->identity->id 当前用户账号及id
|
||||
*domain 域名匹配
|
||||
*expiretime 有效期判断
|
||||
*$_FM['apiCert'] 服务器证书
|
||||
*/
|
||||
$connection = yii::$app->db;
|
||||
$sql = "SELECT `username` FROM c_access WHERE accesstoken = :accesstoken AND domain = :domain AND expiretime > :expiretime ORDER BY id ASC";
|
||||
$params = array();
|
||||
$params[':accesstoken'] = $accessToken;
|
||||
$params[':domain'] = $viaDomain;
|
||||
$params[':expiretime'] = $timestamp;
|
||||
$result = fmFunc_pdo_yii_fetch($connection, $sql, $params);
|
||||
$hasToken = FALSE;
|
||||
$hasCert = FALSE;
|
||||
if ($result) {
|
||||
$username = $result['username'];
|
||||
$hasToken = TRUE;
|
||||
//加载证书文件,但无用户登陆状态
|
||||
$cert = $username . '.php';
|
||||
if (file_exists($_HI['apiCertPath'] . $cert)) {
|
||||
$_FM['apiCert'] = array_merge(include($_HI['apiCertPath'] . $cert));
|
||||
$hasCert = TRUE;
|
||||
}
|
||||
}
|
||||
$_FM['apiCert']['token'] = $accessToken;
|
||||
|
||||
//处理POST数据
|
||||
$client_type = isset($dataPost['client_type']) ? $dataPost['client_type'] : '';
|
||||
$msg_type = isset($dataPost['msg_type']) ? $dataPost['msg_type'] : '';
|
||||
if (!$msg_type) {
|
||||
$msg_type = isset($dataGet['msg_type']) ? $dataGet['msg_type'] : '';
|
||||
}
|
||||
$isWeb = ($client_type == 'web') ? TRUE : FALSE;
|
||||
$isApp = ($client_type == 'app') ? TRUE : FALSE;
|
||||
$isAppWeb = ($client_type == 'appweb') ? TRUE : FALSE;
|
||||
$msg = isset($dataPost['msg']) ? $dataPost['msg'] : '';
|
||||
if (!$msg) {
|
||||
$msg = isset($dataGet['msg']) ? $dataGet['msg'] : '';
|
||||
}
|
||||
|
||||
//构造反馈消息
|
||||
$data = array();
|
||||
$data['type'] = $msg_type;
|
||||
$data['msg'] = $msg;
|
||||
|
||||
if (isset($dataGet['debug'])) {
|
||||
//向全体推送数据
|
||||
$data['msg'] = empty($data['msg']) ? '第' . $count . '次测试群发' : $data['msg'];
|
||||
$count++;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToAll($data);
|
||||
return;
|
||||
}
|
||||
|
||||
$data = json_encode($data);
|
||||
|
||||
//根据情况发送消息
|
||||
switch ($hasToken) {
|
||||
case TRUE:
|
||||
//根据当前用户身份生成可准确识别的用户ID
|
||||
$uid = isset($dataPost['uid']) ? $dataPost['uid'] : '';
|
||||
if ($uid) {
|
||||
$uid = fmFunc_server_hash_id($uid);
|
||||
Gateway::sendToUid($uid, $data);
|
||||
}
|
||||
|
||||
//有证书时,可继续下一步的推送
|
||||
if (!$hasCert) {
|
||||
break; //无证书,不再继续
|
||||
}
|
||||
|
||||
//已指派分组时
|
||||
$group_id = isset($dataPost['group']) ? $dataPost['group'] : 0;
|
||||
if ($groud_id) {
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
break; //执行后结束此次推送
|
||||
}
|
||||
|
||||
//根据创建更多分组
|
||||
$do = isset($dataPost['do']) ? $dataPost['do'] : '';
|
||||
$ac = isset($dataPost['ac']) ? $dataPost['ac'] : '';
|
||||
$op = isset($dataPost['op']) ? $dataPost['op'] : '';
|
||||
|
||||
if ($client_type) {
|
||||
if ($isWeb) {
|
||||
$type = 'web';
|
||||
} else if ($isAppWeb) {
|
||||
$type = 'appweb';
|
||||
} else {
|
||||
$type = 'app';
|
||||
}
|
||||
if ($do) {
|
||||
if ($ac) {
|
||||
if ($op) {
|
||||
$group_id = $type . '_' . $do . '_' . $ac . '_' . $op;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
} else {
|
||||
$group_id = $type . '_' . $do . '_' . $ac;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
}
|
||||
} else {
|
||||
$group_id = $type . '_' . $do;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
}
|
||||
} else {
|
||||
$group_id = $type;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case FALSE;
|
||||
//只发送给指定客户端
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
break;
|
||||
}
|
||||
|
||||
// 以下是调用示例,接口与GatewayWorker环境的接口一致
|
||||
// 接口具体使用方法见《Lib\Gateway类提供的接口》一章
|
||||
// 注意除了不支持sendToCurrentClient和closeCurrentClient方法
|
||||
// 其它方法都支持
|
||||
//Gateway::sendToAll($data);
|
||||
//Gateway::sendToClient($client_id, $data);
|
||||
//Gateway::closeClient($client_id);
|
||||
//Gateway::isOnline($client_id);
|
||||
//Gateway::bindUid($client_id, $uid);
|
||||
//Gateway::isUidOnline($uid);
|
||||
//Gateway::getClientIdByUid($uid);
|
||||
//Gateway::unbindUid($client_id, $uid);
|
||||
//Gateway::sendToUid($uid, $data);
|
||||
//Gateway::joinGroup($client_id, $group);
|
||||
//Gateway::sendToGroup($group, $data);
|
||||
//Gateway::leaveGroup($client_id, $group);
|
||||
//Gateway::getClientCountByGroup($group);
|
||||
//Gateway::getClientSessionsByGroup($group);
|
||||
//Gateway::getAllClientCount();
|
||||
//Gateway::getAllClientSessions();
|
||||
//Gateway::setSession($client_id, $session);
|
||||
//Gateway::updateSession($client_id, $session);
|
||||
//Gateway::getSession($client_id);
|
||||
|
||||
}
|
||||
}
|
||||
+565
@@ -0,0 +1,565 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2019-04-27 22:19:28
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2019-04-30 10:11:22
|
||||
*/
|
||||
|
||||
/**
|
||||
* 利用workerman制作的推送接口控制器(针对嗨噜应用系统的HOFC嗨骑定向小程序)
|
||||
*/
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
|
||||
use dataModel;
|
||||
|
||||
//必须添加这一句,以便引入dataModel外部类库
|
||||
|
||||
// 引用GateWay Client
|
||||
require(__DIR__ . '/../../vendor/workerman/GatewayClient-3.0.0/Gateway.php');
|
||||
|
||||
// GatewayClient 3.0.0版本开始要使用命名空间
|
||||
use GatewayClient\Gateway;
|
||||
|
||||
// 设置GatewayWorker服务的Register服务ip和端口
|
||||
Gateway::$registerAddress = '127.0.0.1:4530';
|
||||
|
||||
class PushhofcController extends Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
/**
|
||||
* 绑定客户端与指定项
|
||||
*/
|
||||
public function actionBind()
|
||||
{
|
||||
//常规绑定(绑定到UID,未传入用户详情)
|
||||
global $_FM;
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
header('Access-Control-Allow-Origin:*'); //允许任何网站通过ajax发送请求
|
||||
|
||||
$group_pre = 'XCX-HOFC-USER';
|
||||
|
||||
//前台已经建立起长链接,取得了客户端ID号
|
||||
$viaDomain = fmFunc_server_via_domain(); //来路域名
|
||||
$viaIP = fmFunc_server_via_ip(); //来路IP
|
||||
$timestamp = isset($_FM['timestamp']) ? $_FM['timestamp'] : time();
|
||||
|
||||
//通过前端GET传入的
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : '';
|
||||
if (!$client_id) {
|
||||
return;
|
||||
}
|
||||
//处理POST数据
|
||||
$client_type = isset($dataPost['client_type']) ? $dataPost['client_type'] : 'undefined';
|
||||
|
||||
//根据当前用户身份生成可准确识别的用户ID
|
||||
$uid = isset($dataPost['uid']) ? $dataPost['uid'] : 0;
|
||||
if (!$uid) {
|
||||
$data = array();
|
||||
$data['type'] = 'toast';
|
||||
$data['msg'] = '未指定用户';
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
$uid = $group_pre . fmFunc_server_hash_id($uid);
|
||||
// client_id与uid绑定
|
||||
Gateway::bindUid($client_id, $uid);
|
||||
|
||||
//发送反馈消息
|
||||
$message = '棒,客户端绑定用户(' . $uid . ')成功!';
|
||||
|
||||
$data = array();
|
||||
$data['type'] = 'bind';
|
||||
$data['msg'] = $message;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
|
||||
public function actionBinduser()
|
||||
{
|
||||
//绑定用户及详情、APPID,同时向数据关联组发送用户信息
|
||||
global $_FM;
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
|
||||
$data = array();
|
||||
header('Access-Control-Allow-Origin:*'); //允许任何网站通过ajax发送请求
|
||||
|
||||
$group_pre = 'XCX-HOFC';
|
||||
|
||||
//绑定到当前用户组,供服务侧同步绑定校验
|
||||
$timestamp = isset($_FM['timestamp']) ? $_FM['timestamp'] : time();
|
||||
|
||||
//通过前端GET传入的
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : '';
|
||||
if (!$client_id) {
|
||||
return;
|
||||
}
|
||||
$viaDomain = fmFunc_server_via_domain(); //来路域名
|
||||
$viaIP = fmFunc_server_via_ip();
|
||||
|
||||
//处理POST数据
|
||||
$client_type = isset($dataPost['client_type']) ? $dataPost['client_type'] : 'undefined';
|
||||
|
||||
//根据当前用户身份生成可准确识别的用户ID
|
||||
$uid = isset($dataPost['uid']) ? $dataPost['uid'] : 0;
|
||||
if (!$uid) {
|
||||
$data = array();
|
||||
$data['type'] = 'toast';
|
||||
$data['msg'] = '未指定用户';
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
$uid = $group_pre . '-USER-' . fmFunc_server_hash_id($uid);
|
||||
// client_id与uid绑定
|
||||
Gateway::bindUid($client_id, $uid);
|
||||
//发送反馈消息
|
||||
$message = '棒,客户端绑定用户(' . $uid . ')成功!';
|
||||
$data = array();
|
||||
$data['type'] = 'bind';
|
||||
$data['msg'] = $message;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
|
||||
$group_ids = array();
|
||||
$group_id = '';
|
||||
//绑定小程序ID
|
||||
$appid = isset($dataPost['appid']) ? $dataPost['appid'] : 0;
|
||||
if (!$appid) {
|
||||
$data = array();
|
||||
$data['type'] = 'toast';
|
||||
$data['msg'] = '未指定小程序';
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
} else {
|
||||
$group_id = 'wxapp_' . $appid;
|
||||
$group_ids[$group_id] = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
// 加入某个群组(可调用多次加入多个群组)
|
||||
Gateway::joinGroup($client_id, $group_ids[$group_id]); //奖用户加入指定会员组
|
||||
//发送反馈消息
|
||||
$message = '棒,客户端绑定小程序(' . $appid . ')成功!';
|
||||
$data = array();
|
||||
$data['type'] = 'bind';
|
||||
$data['msg'] = $message;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
}
|
||||
|
||||
//向数据展板推送用户信息
|
||||
$user = isset($dataPost['user']) ? $dataPost['user'] : [];
|
||||
$time = time();
|
||||
//构造反馈消息
|
||||
$data = array();
|
||||
$data['type'] = 'content'; //消息反馈类型:alert,confirm,toast,content,reg
|
||||
if (isset($dataPost['new']) && $dataPost['new'] == 1) {
|
||||
$data['type'] = 'reg';
|
||||
}
|
||||
$data['msg'] = '由[' . $viaIP . ']进入了寻宝应用(' . date('H:i') . ')';
|
||||
$data['status'] = 1; //消息状态
|
||||
$data['avatar'] = isset($user['face']) ? $user['face'] : '';
|
||||
$data['username'] = $user['nick_name']; //昵称
|
||||
$data['title'] = '系统提示'; //消息标题
|
||||
$data['mid'] = isset($user['user_id']) ? $user['user_id'] : -1; //消息来源会员, -1为公众号本身
|
||||
$data['id'] = md5($time . '_' . $user['user_id']);
|
||||
$data['ctype'] = 0; //消息内容类型(-1,系统消息;-2表情;-3快捷表态;-4 红包;0,默认,文本消息;1图片;3音频; 4视频;)
|
||||
$data['createtime'] = $time;
|
||||
$data = json_encode($data);
|
||||
//推送数据
|
||||
Gateway::sendToGroup($group_ids[$group_id], $data);
|
||||
return;
|
||||
}
|
||||
|
||||
public function actionBindgroup()
|
||||
{
|
||||
//绑定用户组
|
||||
global $_FM;
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
header('Access-Control-Allow-Origin:*'); //允许任何网站通过ajax发送请求
|
||||
|
||||
$group_pre = 'XCX-HOFC';
|
||||
|
||||
//绑定到当前用户组,供服务侧同步绑定校验
|
||||
$timestamp = isset($_FM['timestamp']) ? $_FM['timestamp'] : time();
|
||||
|
||||
//通过前端GET传入的
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : '';
|
||||
if (!$client_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
//处理POST数据
|
||||
$client_type = isset($dataPost['client_type']) ? $dataPost['client_type'] : 'undefined';
|
||||
|
||||
$group_ids = array();
|
||||
|
||||
$group_id = isset($dataPost['groupid']) ? $dataPost['groupid'] : 0;
|
||||
if ($group_id) {
|
||||
$group_ids[0] = $group_pre . fmFunc_server_hash_id(0);;
|
||||
// 加入某个群组(可调用多次加入多个群组)
|
||||
Gateway::joinGroup($client_id, $group_ids[0]); //将用户加入0会员组
|
||||
}
|
||||
$group_ids[$group_id] = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
// 加入某个群组(可调用多次加入多个群组)
|
||||
Gateway::joinGroup($client_id, $group_ids[$group_id]); //奖用户加入指定会员组
|
||||
|
||||
//发送反馈消息
|
||||
$message = '棒,客户端绑定用户组成功!';
|
||||
|
||||
$data = array();
|
||||
$data['type'] = 'bind';
|
||||
$data['msg'] = $message;
|
||||
$data['groupids'] = $group_ids;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
|
||||
public function actionBindteam()
|
||||
{
|
||||
//绑定团队ID,方便同步接收
|
||||
global $_FM;
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
header('Access-Control-Allow-Origin:*'); //允许任何网站通过ajax发送请求
|
||||
|
||||
$group_pre = 'XCX-HOFC';
|
||||
|
||||
$timestamp = isset($_FM['timestamp']) ? $_FM['timestamp'] : time();
|
||||
|
||||
//通过前端GET传入的
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : '';
|
||||
if (!$client_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
//处理POST数据
|
||||
$client_type = isset($dataPost['client_type']) ? $dataPost['client_type'] : 'undefined';
|
||||
|
||||
$group_ids = array();
|
||||
|
||||
$teamid = isset($dataPost['teamid']) ? $dataPost['teamid'] : 0;
|
||||
if (!$teamid) {
|
||||
$data = array();
|
||||
$data['type'] = 'toast';
|
||||
$data['msg'] = '未指定队伍';
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
$group_id = 'team_' . $teamid;
|
||||
$group_ids[$group_id] = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
// 加入某个群组(可调用多次加入多个群组)
|
||||
Gateway::joinGroup($client_id, $group_ids[$group_id]); //奖用户加入指定会员组
|
||||
|
||||
//发送反馈消息
|
||||
$message = '棒,客户端绑定队伍(' . $teamid . ')成功!';
|
||||
|
||||
$data = array();
|
||||
$data['type'] = 'bind';
|
||||
$data['msg'] = $message;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
|
||||
public function actionBindwxapp()
|
||||
{
|
||||
//绑定小程序ID
|
||||
global $_FM;
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
header('Access-Control-Allow-Origin:*'); //允许任何网站通过ajax发送请求
|
||||
|
||||
$group_pre = 'XCX-HOFC';
|
||||
|
||||
$timestamp = isset($_FM['timestamp']) ? $_FM['timestamp'] : time();
|
||||
|
||||
//通过前端GET传入的
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : '';
|
||||
if (!$client_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
//处理POST数据
|
||||
$client_type = isset($dataPost['client_type']) ? $dataPost['client_type'] : 'undefined';
|
||||
|
||||
$group_ids = array();
|
||||
|
||||
$appid = isset($dataPost['appid']) ? $dataPost['appid'] : 0;
|
||||
if (!$appid) {
|
||||
$data = array();
|
||||
$data['type'] = 'toast';
|
||||
$data['msg'] = '未指定小程序';
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
$group_id = 'wxapp_' . $appid;
|
||||
$group_ids[$group_id] = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
// 加入某个群组(可调用多次加入多个群组)
|
||||
Gateway::joinGroup($client_id, $group_ids[$group_id]); //奖用户加入指定会员组
|
||||
|
||||
//发送反馈消息
|
||||
$message = '棒,客户端绑定小程序(' . $appid . ')成功!';
|
||||
|
||||
$data = array();
|
||||
$data['type'] = 'bind';
|
||||
$data['msg'] = $message;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收客户端数据
|
||||
*/
|
||||
public function actionIn()
|
||||
{
|
||||
$group_pre = 'XCX-HOFC';
|
||||
header('Access-Control-Allow-Origin:*'); //允许指定网站通过ajax发送请求
|
||||
// 建立socket连接到内部推送端口
|
||||
$client = stream_socket_client('tcp://127.0.0.1:4530');
|
||||
|
||||
//如果用户已经登陆,uid和群组id存在
|
||||
//TBD 构建uid、group_id的生成方式
|
||||
$uid = isset($dataPost['uid']) ? $dataPost['uid'] : 0;
|
||||
$group_id = isset($dataPost['group']) ? $dataPost['group'] : 0;
|
||||
|
||||
//$client_id 通过前端传入
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : 0;
|
||||
|
||||
// 推送的数据,包含uid字段,表示是给这个uid推送
|
||||
$uid = isset(Yii::$app->user->identity->username) ? Yii::$app->user->identity->username : '0';
|
||||
$data = array('uid' => $uid, 'msg' => urlencode('嗯,这个是测试用的'));
|
||||
|
||||
// 发送数据,注意该端口是Text协议的端口,Text协议需要在数据末尾加上换行符
|
||||
fwrite($client, json_encode($data) . "\n");
|
||||
|
||||
// 读取推送结果
|
||||
// echo '$client=='.$client;
|
||||
//echo fread($client, 8192);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向客户端推送消息
|
||||
*/
|
||||
public function actionOut()
|
||||
{
|
||||
global $_FM;
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$params = Yii::$app->params;
|
||||
header('Access-Control-Allow-Origin:*'); //允许指定网站通过ajax发送请求
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$group_pre = 'XCX-HOFC';
|
||||
|
||||
/*设置REDIS缓存*/
|
||||
//初始化$cache = new \Redis();
|
||||
$cache = new \Redis();
|
||||
$cache->connect($params['redis']['IP'], $params['redis']['PORT']);
|
||||
// 先检查是否存在,然后写入并设置有效时间
|
||||
$key = 'FmWebSorcketCount';
|
||||
$CACHE_PREFIX = 'DACMS';
|
||||
$count = 0;
|
||||
if ($cache->exists($CACHE_PREFIX . $key)) {
|
||||
// 读取
|
||||
$count = $cache->get($CACHE_PREFIX . $key);
|
||||
//清除
|
||||
$cache->delete($CACHE_PREFIX . $key);
|
||||
}
|
||||
|
||||
$cache->set($CACHE_PREFIX . $key, $count + 1);
|
||||
$expire = time() + 604800; //一周时间再过期
|
||||
$cache->expire($CACHE_PREFIX . $key, $expire);
|
||||
|
||||
//前台已经建立起长链接,取得了客户端ID号;需要绑定到当前用户,并返回用户uid,供服务侧同步绑定校验
|
||||
$viaDomain = fmFunc_server_via_domain(); //来路域名
|
||||
$viaIP = fmFunc_server_via_ip(); //来路IP
|
||||
$timestamp = isset($_FM['timestamp']) ? $_FM['timestamp'] : time();
|
||||
|
||||
//通过前端GET传入的
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : '7f000001b0f400000010';
|
||||
|
||||
//处理POST数据
|
||||
$client_type = isset($dataPost['client_type']) ? $dataPost['client_type'] : '';
|
||||
$msg_type = isset($dataPost['msg_type']) ? $dataPost['msg_type'] : '';
|
||||
if (!$msg_type) {
|
||||
$msg_type = isset($dataGet['msg_type']) ? $dataGet['msg_type'] : '';
|
||||
}
|
||||
|
||||
$msg = isset($dataPost['msg']) ? $dataPost['msg'] : '';
|
||||
if (!$msg) {
|
||||
$msg = isset($dataGet['msg']) ? $dataGet['msg'] : '';
|
||||
}
|
||||
|
||||
//构造反馈消息
|
||||
$data = array();
|
||||
$data['type'] = $msg_type;
|
||||
$data['msg'] = $msg;
|
||||
|
||||
if (isset($dataGet['debug'])) {
|
||||
//向全体推送数据
|
||||
$data['msg'] = empty($data['msg']) ? '第' . $count . '次测试群发' : $data['msg'];
|
||||
$count++;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToAll($data);
|
||||
return;
|
||||
}
|
||||
|
||||
$data = json_encode($data);
|
||||
|
||||
//根据情况发送消息
|
||||
switch ($hasToken) {
|
||||
case TRUE:
|
||||
//根据当前用户身份生成可准确识别的用户ID
|
||||
$uid = isset($dataPost['uid']) ? $dataPost['uid'] : '';
|
||||
if ($uid) {
|
||||
$uid = fmFunc_server_hash_id($uid);
|
||||
Gateway::sendToUid($uid, $data);
|
||||
}
|
||||
|
||||
//有证书时,可继续下一步的推送
|
||||
if (!$hasCert) {
|
||||
break; //无证书,不再继续
|
||||
}
|
||||
|
||||
//已指派分组时
|
||||
$group_id = isset($dataPost['group']) ? $dataPost['group'] : 0;
|
||||
if ($groud_id) {
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
break; //执行后结束此次推送
|
||||
}
|
||||
|
||||
if ($client_type) {
|
||||
$group_id = $type;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
}
|
||||
break;
|
||||
|
||||
case FALSE;
|
||||
//只发送给指定客户端
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收客户端数据并向全部客户端群发
|
||||
*/
|
||||
public function actionSend2all()
|
||||
{
|
||||
header('Access-Control-Allow-Origin:*'); //允许指定网站通过ajax发送请求
|
||||
global $_FM;
|
||||
global $_HI;
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$params = Yii::$app->params;
|
||||
|
||||
$group_pre = 'XCX-HOFC';
|
||||
|
||||
/*设置REDIS缓存*/
|
||||
//初始化$cache = new \Redis();
|
||||
$cache = new \Redis();
|
||||
$cache->connect($params['redis']['IP'], $params['redis']['PORT']);
|
||||
// 先检查是否存在,然后写入并设置有效时间
|
||||
$key = 'FmWebSorcketCount';
|
||||
$CACHE_PREFIX = 'DACMS';
|
||||
$count = 0;
|
||||
if ($cache->exists($CACHE_PREFIX . $key)) {
|
||||
// 读取
|
||||
$count = $cache->get($CACHE_PREFIX . $key);
|
||||
//清除
|
||||
$cache->delete($CACHE_PREFIX . $key);
|
||||
}
|
||||
|
||||
$cache->set($CACHE_PREFIX . $key, $count + 1);
|
||||
$expire = time() + 604800; //一周时间再过期
|
||||
$cache->expire($CACHE_PREFIX . $key, $expire);
|
||||
|
||||
//前台已经建立起长链接,取得了客户端ID号;需要绑定到当前用户,并返回用户uid,供服务侧同步绑定校验
|
||||
$viaDomain = fmFunc_server_via_domain(); //来路域名
|
||||
$viaIP = fmFunc_server_via_ip(); //来路IP
|
||||
$timestamp = isset($_FM['timestamp']) ? $_FM['timestamp'] : time();
|
||||
|
||||
//通过前端GET传入的
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : ' ';
|
||||
if (!$client_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
//处理POST数据
|
||||
$msg_type = isset($dataPost['msg_type']) ? $dataPost['msg_type'] : '';
|
||||
if (!$msg_type) {
|
||||
$msg_type = isset($dataGet['msg_type']) ? $dataGet['msg_type'] : '';
|
||||
}
|
||||
|
||||
$msg = isset($dataPost['msg']) ? $dataPost['msg'] : '';
|
||||
if (!$msg) {
|
||||
$msg = isset($dataGet['msg']) ? $dataGet['msg'] : '';
|
||||
}
|
||||
|
||||
//构造反馈消息
|
||||
$data = array();
|
||||
$data['type'] = $msg_type; //消息反馈类型:alert,confirm,toast,content
|
||||
$data['msg'] = $msg;
|
||||
$data['status'] = 1; //消息状态
|
||||
$data['avatar'] = isset($dataPost['avatar']) ? $dataPost['avatar'] : '';
|
||||
$data['username'] = '管理员'; //昵称
|
||||
$data['title'] = '系统提示'; //消息标题
|
||||
$data['mid'] = isset($dataPost['mid']) ? $dataPost['mid'] : 1; //消息来源会员, -1为公众号本身
|
||||
$time = time();
|
||||
$data['id'] = isset($dataPost['id']) ? $dataPost['id'] : md5($time . '_' . $data['mid']);
|
||||
$data['ctype'] = isset($dataPost['type']) ? $dataPost['type'] : 0; //消息内容类型(-1,系统消息;-2表情;-3快捷表态;-4 红包;0,默认,文本消息;1图片;3音频; 4视频;)
|
||||
$data['createtime'] = $time;
|
||||
if (isset($dataGet['debug'])) {
|
||||
//向全体推送数据
|
||||
$data['msg'] = empty($data['msg']) ? '第' . $count . '次测试群发' : $data['msg'];
|
||||
$count++;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToAll($data);
|
||||
return;
|
||||
}
|
||||
$data = json_encode($data);
|
||||
//向全体推送数据
|
||||
//设定群发群组
|
||||
$appid = isset($dataPost['appid']) ? $dataPost['appid'] : 0;
|
||||
$group_id = 'wxapp_' . $appid;
|
||||
$group_ids[$group_id] = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$count++;
|
||||
Gateway::sendToGroup($group_ids[$group_id], $data);
|
||||
|
||||
//构造反馈消息
|
||||
$data = array();
|
||||
$data['type'] = 'toast';
|
||||
$data['msg'] = '消息已发送';
|
||||
$data = json_encode($data);
|
||||
//发送给指定客户端
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
+516
@@ -0,0 +1,516 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2019-04-27 22:19:28
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2019-04-29 17:08:02
|
||||
*/
|
||||
|
||||
/**
|
||||
* 利用workerman制作的推送接口控制器(针对vcms的fm453_*系列应用)
|
||||
*/
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
|
||||
use dataModel;
|
||||
|
||||
//必须添加这一句,以便引入dataModel外部类库
|
||||
|
||||
// 引用GateWay Client
|
||||
require(__DIR__ . '/../../vendor/workerman/GatewayClient-3.0.0/Gateway.php');
|
||||
|
||||
// GatewayClient 3.0.0版本开始要使用命名空间
|
||||
use GatewayClient\Gateway;
|
||||
|
||||
// 设置GatewayWorker服务的Register服务ip和端口
|
||||
Gateway::$registerAddress = '127.0.0.1:4530';
|
||||
|
||||
class PushimmsController extends Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
/**
|
||||
* 绑定客户端与指定客户id\分组id
|
||||
*/
|
||||
public function actionBind()
|
||||
{
|
||||
global $_FM;
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
header('Access-Control-Allow-Origin:*'); //允许任何网站通过ajax发送请求
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$group_pre = 'VCMS-IMMS';
|
||||
|
||||
//前台已经建立起长链接,取得了客户端ID号;需要绑定到当前用户,并返回用户uid,供服务侧同步绑定校验
|
||||
$viaDomain = fmFunc_server_via_domain(); //来路域名
|
||||
$viaIP = fmFunc_server_via_ip(); //来路IP
|
||||
$timestamp = isset($_FM['timestamp']) ? $_FM['timestamp'] : time();
|
||||
|
||||
//通过前端GET传入的
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : 0;
|
||||
$accessToken = isset($dataGet['accesstoken']) ? $dataGet['accesstoken'] : 0;
|
||||
|
||||
//判断accesstoken有效性
|
||||
/*
|
||||
@有效性规则判断
|
||||
*Yii::$app->user->identity->username,Yii::$app->user->identity->id 当前用户账号及id
|
||||
*domain 域名匹配
|
||||
*expiretime 有效期判断
|
||||
*$_FM['apiCert'] 服务器证书
|
||||
*/
|
||||
$connection = yii::$app->db;
|
||||
$sql = "SELECT `username` FROM c_access WHERE accesstoken = :accesstoken AND domain = :domain AND expiretime > :expiretime ORDER BY id ASC";
|
||||
$params = array();
|
||||
$params[':accesstoken'] = $accessToken;
|
||||
$params[':domain'] = $viaDomain;
|
||||
$params[':expiretime'] = $timestamp;
|
||||
$result = fmFunc_pdo_yii_fetch($connection, $sql, $params);
|
||||
if ($result) {
|
||||
$username = $result['username'];
|
||||
//加载证书文件,但无用户登陆状态
|
||||
$cert = $username . '.php';
|
||||
if (file_exists($_HI['apiCertPath'] . $cert)) {
|
||||
$_FM['apiCert'] = array_merge(include($_HI['apiCertPath'] . $cert));
|
||||
}
|
||||
}
|
||||
$_FM['apiCert']['token'] = $accessToken;
|
||||
|
||||
//处理POST数据
|
||||
$client_type = isset($dataPost['client_type']) ? $dataPost['client_type'] : 'undefined';
|
||||
$isWeb = ($client_type == 'web') ? TRUE : FALSE;
|
||||
$isApp = ($client_type == 'app') ? TRUE : FALSE;
|
||||
$isAppWeb = ($client_type == 'appweb') ? TRUE : FALSE;
|
||||
|
||||
$group_ids = array();
|
||||
|
||||
//根据当前用户身份生成可准确识别的用户ID
|
||||
$uid = isset($dataPost['uid']) ? $dataPost['uid'] : 'undefined';
|
||||
$uid = fmFunc_server_hash_id($uid);
|
||||
// client_id与uid绑定
|
||||
Gateway::bindUid($client_id, $uid);
|
||||
|
||||
$group_id = isset($dataPost['groupid']) ? $dataPost['groupid'] : 0;
|
||||
if ($group_id) {
|
||||
$group_ids[0] = $group_pre . fmFunc_server_hash_id(0);;
|
||||
// 加入某个群组(可调用多次加入多个群组)
|
||||
Gateway::joinGroup($client_id, $group_id); //当前用户所在的会员组
|
||||
}
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
// 加入某个群组(可调用多次加入多个群组)
|
||||
Gateway::joinGroup($client_id, $group_id); //当前用户所在的会员组
|
||||
|
||||
|
||||
//继续根据创建更多分组
|
||||
$do = isset($dataPost['do']) ? $dataPost['do'] : 'undefined';
|
||||
$ac = isset($dataPost['ac']) ? $dataPost['ac'] : 'undefined';
|
||||
$op = isset($dataPost['op']) ? $dataPost['op'] : 'undefined';
|
||||
|
||||
if ($isWeb) {
|
||||
$type = 'web';
|
||||
$group_id = $type . '_' . $do . '_' . $ac . '_' . $op;
|
||||
$group_id = $group_pre . $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id);
|
||||
|
||||
$group_id = $type . '_' . $do . '_' . $ac;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id);
|
||||
|
||||
$group_id = $type . '_' . $do;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id);
|
||||
|
||||
} else {
|
||||
$type = 'app';
|
||||
$group_id = $type . '_' . $do . '_' . $ac . '_' . $op;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id);
|
||||
|
||||
$group_id = $type . '_' . $do . '_' . $ac;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id);
|
||||
|
||||
$group_id = $type . '_' . $do;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id);
|
||||
|
||||
$group_id = $type;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id); //当前用户并入前台用户组
|
||||
|
||||
if ($isAppWeb) {
|
||||
$type = 'appweb';
|
||||
$group_id = $type;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
$group_ids[$group_id] = $group_id;
|
||||
Gateway::joinGroup($client_id, $group_id); //当前用户并入前台核销用户组
|
||||
}
|
||||
}
|
||||
|
||||
//发送反馈消息
|
||||
$message = array();
|
||||
$message = '棒,客户端绑定成功!';
|
||||
|
||||
$data = array();
|
||||
$data['type'] = 'tips';
|
||||
$data['msg'] = $message;
|
||||
$data['groupids'] = $group_ids;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收客户端数据
|
||||
*/
|
||||
public function actionIn()
|
||||
{
|
||||
$group_pre = 'VCMS-IMMS';
|
||||
header('Access-Control-Allow-Origin:https://vcms.hiluker.com'); //允许指定网站通过ajax发送请求
|
||||
// 建立socket连接到内部推送端口
|
||||
$client = stream_socket_client('tcp://127.0.0.1:4530');
|
||||
|
||||
//如果用户已经登陆,uid和群组id存在
|
||||
//TBD 构建uid、group_id的生成方式
|
||||
$uid = isset($dataPost['uid']) ? $dataPost['uid'] : 0;
|
||||
$group_id = isset($dataPost['group']) ? $dataPost['group'] : 0;
|
||||
|
||||
//$client_id 通过前端传入
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : 0;
|
||||
|
||||
// 推送的数据,包含uid字段,表示是给这个uid推送
|
||||
$uid = isset(Yii::$app->user->identity->username) ? Yii::$app->user->identity->username : '0';
|
||||
$data = array('uid' => $uid, 'msg' => urlencode('嗯,这个是测试用的'));
|
||||
|
||||
// 发送数据,注意该端口是Text协议的端口,Text协议需要在数据末尾加上换行符
|
||||
fwrite($client, json_encode($data) . "\n");
|
||||
|
||||
// 读取推送结果
|
||||
// echo '$client=='.$client;
|
||||
//echo fread($client, 8192);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向客户端推送消息
|
||||
*/
|
||||
public function actionOut()
|
||||
{
|
||||
global $_FM;
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$params = Yii::$app->params;
|
||||
// header('Access-Control-Allow-Origin:https://vcms.hiluker.com'); //允许指定网站通过ajax发送请求
|
||||
header('Access-Control-Allow-Origin:*'); //允许指定网站通过ajax发送请求
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$group_pre = 'VCMS-IMMS';
|
||||
|
||||
/*设置REDIS缓存*/
|
||||
//初始化$cache = new \Redis();
|
||||
$cache = new \Redis();
|
||||
$cache->connect($params['redis']['IP'], $params['redis']['PORT']);
|
||||
// 先检查是否存在,然后写入并设置有效时间
|
||||
$key = 'FmWebSorcketCount';
|
||||
$CACHE_PREFIX = 'DACMS';
|
||||
$count = 0;
|
||||
if ($cache->exists($CACHE_PREFIX . $key)) {
|
||||
// 读取
|
||||
$count = $cache->get($CACHE_PREFIX . $key);
|
||||
//清除
|
||||
$cache->delete($CACHE_PREFIX . $key);
|
||||
}
|
||||
|
||||
$cache->set($CACHE_PREFIX . $key, $count + 1);
|
||||
$expire = time() + 604800; //一周时间再过期
|
||||
$cache->expire($CACHE_PREFIX . $key, $expire);
|
||||
|
||||
//前台已经建立起长链接,取得了客户端ID号;需要绑定到当前用户,并返回用户uid,供服务侧同步绑定校验
|
||||
$viaDomain = fmFunc_server_via_domain(); //来路域名
|
||||
$viaIP = fmFunc_server_via_ip(); //来路IP
|
||||
$timestamp = isset($_FM['timestamp']) ? $_FM['timestamp'] : time();
|
||||
|
||||
//通过前端GET传入的
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : '7f000001b0f400000010';
|
||||
$accessToken = isset($dataGet['accesstoken']) ? $dataGet['accesstoken'] : 0;
|
||||
|
||||
//判断accesstoken有效性
|
||||
/*
|
||||
@有效性规则判断
|
||||
*Yii::$app->user->identity->username,Yii::$app->user->identity->id 当前用户账号及id
|
||||
*domain 域名匹配
|
||||
*expiretime 有效期判断
|
||||
*$_FM['apiCert'] 服务器证书
|
||||
*/
|
||||
$connection = yii::$app->db;
|
||||
$sql = "SELECT `username` FROM c_access WHERE accesstoken = :accesstoken AND domain = :domain AND expiretime > :expiretime ORDER BY id ASC";
|
||||
$params = array();
|
||||
$params[':accesstoken'] = $accessToken;
|
||||
$params[':domain'] = $viaDomain;
|
||||
$params[':expiretime'] = $timestamp;
|
||||
$result = fmFunc_pdo_yii_fetch($connection, $sql, $params);
|
||||
$hasToken = FALSE;
|
||||
$hasCert = FALSE;
|
||||
if ($result) {
|
||||
$username = $result['username'];
|
||||
$hasToken = TRUE;
|
||||
//加载证书文件,但无用户登陆状态
|
||||
$cert = $username . '.php';
|
||||
if (file_exists($_HI['apiCertPath'] . $cert)) {
|
||||
$_FM['apiCert'] = array_merge(include($_HI['apiCertPath'] . $cert));
|
||||
$hasCert = TRUE;
|
||||
}
|
||||
}
|
||||
$_FM['apiCert']['token'] = $accessToken;
|
||||
|
||||
//处理POST数据
|
||||
$client_type = isset($dataPost['client_type']) ? $dataPost['client_type'] : '';
|
||||
$msg_type = isset($dataPost['msg_type']) ? $dataPost['msg_type'] : '';
|
||||
if (!$msg_type) {
|
||||
$msg_type = isset($dataGet['msg_type']) ? $dataGet['msg_type'] : '';
|
||||
}
|
||||
$isWeb = ($client_type == 'web') ? TRUE : FALSE;
|
||||
$isApp = ($client_type == 'app') ? TRUE : FALSE;
|
||||
$isAppWeb = ($client_type == 'appweb') ? TRUE : FALSE;
|
||||
$msg = isset($dataPost['msg']) ? $dataPost['msg'] : '';
|
||||
if (!$msg) {
|
||||
$msg = isset($dataGet['msg']) ? $dataGet['msg'] : '';
|
||||
}
|
||||
|
||||
//构造反馈消息
|
||||
$data = array();
|
||||
$data['type'] = $msg_type;
|
||||
$data['msg'] = $msg;
|
||||
|
||||
if (isset($dataGet['debug'])) {
|
||||
//向全体推送数据
|
||||
$data['msg'] = empty($data['msg']) ? '第' . $count . '次测试群发' : $data['msg'];
|
||||
$count++;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToAll($data);
|
||||
return;
|
||||
}
|
||||
|
||||
$data = json_encode($data);
|
||||
|
||||
//根据情况发送消息
|
||||
switch ($hasToken) {
|
||||
case TRUE:
|
||||
//根据当前用户身份生成可准确识别的用户ID
|
||||
$uid = isset($dataPost['uid']) ? $dataPost['uid'] : '';
|
||||
if ($uid) {
|
||||
$uid = fmFunc_server_hash_id($uid);
|
||||
Gateway::sendToUid($uid, $data);
|
||||
}
|
||||
|
||||
//有证书时,可继续下一步的推送
|
||||
if (!$hasCert) {
|
||||
break; //无证书,不再继续
|
||||
}
|
||||
|
||||
//已指派分组时
|
||||
$group_id = isset($dataPost['group']) ? $dataPost['group'] : 0;
|
||||
if ($groud_id) {
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
break; //执行后结束此次推送
|
||||
}
|
||||
|
||||
//根据创建更多分组
|
||||
$do = isset($dataPost['do']) ? $dataPost['do'] : '';
|
||||
$ac = isset($dataPost['ac']) ? $dataPost['ac'] : '';
|
||||
$op = isset($dataPost['op']) ? $dataPost['op'] : '';
|
||||
|
||||
if ($client_type) {
|
||||
if ($isWeb) {
|
||||
$type = 'web';
|
||||
} else if ($isAppWeb) {
|
||||
$type = 'appweb';
|
||||
} else {
|
||||
$type = 'app';
|
||||
}
|
||||
if ($do) {
|
||||
if ($ac) {
|
||||
if ($op) {
|
||||
$group_id = $type . '_' . $do . '_' . $ac . '_' . $op;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
} else {
|
||||
$group_id = $type . '_' . $do . '_' . $ac;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
}
|
||||
} else {
|
||||
$group_id = $type . '_' . $do;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
}
|
||||
} else {
|
||||
$group_id = $type;
|
||||
$group_id = $group_pre . fmFunc_server_hash_id($group_id);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case FALSE;
|
||||
//只发送给指定客户端
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收客户端数据并向全部客户端群发
|
||||
*/
|
||||
public function actionSend2all()
|
||||
{
|
||||
// header('Access-Control-Allow-Origin:https://vcms.hiluker.com'); //允许指定网站通过ajax发送请求
|
||||
header('Access-Control-Allow-Origin:*'); //允许指定网站通过ajax发送请求
|
||||
global $_FM;
|
||||
global $_HI;
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$params = Yii::$app->params;
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$group_pre = 'VCMS-IMMS';
|
||||
|
||||
/*设置REDIS缓存*/
|
||||
//初始化$cache = new \Redis();
|
||||
$cache = new \Redis();
|
||||
$cache->connect($params['redis']['IP'], $params['redis']['PORT']);
|
||||
// 先检查是否存在,然后写入并设置有效时间
|
||||
$key = 'FmWebSorcketCount';
|
||||
$CACHE_PREFIX = 'DACMS';
|
||||
$count = 0;
|
||||
if ($cache->exists($CACHE_PREFIX . $key)) {
|
||||
// 读取
|
||||
$count = $cache->get($CACHE_PREFIX . $key);
|
||||
//清除
|
||||
$cache->delete($CACHE_PREFIX . $key);
|
||||
}
|
||||
|
||||
$cache->set($CACHE_PREFIX . $key, $count + 1);
|
||||
$expire = time() + 604800; //一周时间再过期
|
||||
$cache->expire($CACHE_PREFIX . $key, $expire);
|
||||
|
||||
//前台已经建立起长链接,取得了客户端ID号;需要绑定到当前用户,并返回用户uid,供服务侧同步绑定校验
|
||||
$viaDomain = fmFunc_server_via_domain(); //来路域名
|
||||
$viaIP = fmFunc_server_via_ip(); //来路IP
|
||||
$timestamp = isset($_FM['timestamp']) ? $_FM['timestamp'] : time();
|
||||
|
||||
//通过前端GET传入的
|
||||
$client_id = isset($dataGet['client_id']) ? $dataGet['client_id'] : ' ';
|
||||
if (!$client_id) {
|
||||
return;
|
||||
}
|
||||
$accessToken = isset($dataGet['accesstoken']) ? $dataGet['accesstoken'] : '';
|
||||
if (!$accessToken) {
|
||||
//构造反馈消息
|
||||
$data = array();
|
||||
$data['type'] = 'log';
|
||||
$data['msg'] = '未指定accessToken';
|
||||
$data = json_encode($data);
|
||||
//发送给指定客户端
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
|
||||
//判断accesstoken有效性
|
||||
/*
|
||||
@有效性规则判断
|
||||
*Yii::$app->user->identity->username,Yii::$app->user->identity->id 当前用户账号及id
|
||||
*domain 域名匹配
|
||||
*expiretime 有效期判断
|
||||
*$_FM['apiCert'] 服务器证书
|
||||
*/
|
||||
$connection = yii::$app->db;
|
||||
$sql = "SELECT `username` FROM c_access WHERE accesstoken = :accesstoken ORDER BY id ASC";
|
||||
$params = array();
|
||||
$params[':accesstoken'] = $accessToken;
|
||||
// $params[':domain'] = $viaDomain;
|
||||
// $params[':expiretime'] = $timestamp;
|
||||
$result = fmFunc_pdo_yii_fetch($connection, $sql, $params);
|
||||
|
||||
$hasToken = FALSE;
|
||||
$hasCert = FALSE;
|
||||
if ($result) {
|
||||
$username = $result['username'];
|
||||
$hasToken = TRUE;
|
||||
//加载证书文件,但无用户登陆状态
|
||||
$cert = $username . '.php';
|
||||
if (file_exists($_HI['apiCertPath'] . $cert)) {
|
||||
$_FM['apiCert'] = array_merge(include($_HI['apiCertPath'] . $cert));
|
||||
$hasCert = TRUE;
|
||||
}
|
||||
} else {
|
||||
//构造反馈消息
|
||||
$data = array();
|
||||
$data['type'] = 'log';
|
||||
$data['msg'] = '无效的accessToken';
|
||||
$data = json_encode($data);
|
||||
//发送给指定客户端
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
$_FM['apiCert']['token'] = $accessToken;
|
||||
|
||||
//处理POST数据
|
||||
$msg_type = isset($dataPost['msg_type']) ? $dataPost['msg_type'] : '';
|
||||
if (!$msg_type) {
|
||||
$msg_type = isset($dataGet['msg_type']) ? $dataGet['msg_type'] : '';
|
||||
}
|
||||
|
||||
$msg = isset($dataPost['msg']) ? $dataPost['msg'] : '';
|
||||
if (!$msg) {
|
||||
$msg = isset($dataGet['msg']) ? $dataGet['msg'] : '';
|
||||
}
|
||||
|
||||
//设定群发群组
|
||||
$group_id = $group_pre . fmFunc_server_hash_id(0);
|
||||
|
||||
//构造反馈消息
|
||||
$data = array();
|
||||
$data['type'] = $msg_type;
|
||||
// $data['type'] = 'alert';
|
||||
$data['msg'] = $msg;
|
||||
|
||||
if (isset($dataGet['debug'])) {
|
||||
//向全体推送数据
|
||||
$data['msg'] = empty($data['msg']) ? '第' . $count . '次测试群发' : $data['msg'];
|
||||
$count++;
|
||||
$data = json_encode($data);
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
return;
|
||||
}
|
||||
$data = json_encode($data);
|
||||
//向全体推送数据
|
||||
$count++;
|
||||
Gateway::sendToGroup($group_id, $data);
|
||||
|
||||
//构造反馈消息
|
||||
$data = array();
|
||||
$data['type'] = 'toast';
|
||||
$data['msg'] = '消息已发送';
|
||||
$data = json_encode($data);
|
||||
//发送给指定客户端
|
||||
Gateway::sendToClient($client_id, $data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Executable
+483
@@ -0,0 +1,483 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\Url;
|
||||
|
||||
use dataModel;
|
||||
|
||||
//必须添加这一句,以便引入dataModel外部类库
|
||||
|
||||
require dirname(__FILE__) . '/_public/public.php';
|
||||
|
||||
class RealtyController extends \yii\web\Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
$_HI['action'] = 'index';
|
||||
require dirname(__FILE__) . '/SettingController/index.php';
|
||||
}
|
||||
|
||||
public function actionGet()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'get';
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
$data['sqls'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost);
|
||||
|
||||
$connection = yii::$app->realtydb;
|
||||
$tablePre = 'hi';
|
||||
$table = 'realty_basic';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Realty s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Realty f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Realty o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //房产模型实例数据,返回self列表\param列表
|
||||
require dirname(__FILE__) . '/_public/list_self.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => $v) {
|
||||
$s_sn = $v['sn'];
|
||||
$record_self = $v;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$errorCode = 0;
|
||||
$record_param = $result;
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['title', 'status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$list[$k] = $record;
|
||||
}
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
case 'house'; //楼盘数据,根据条件返回form表中的数据\param列表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
require dirname(__FILE__) . '/_public/list_form.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => &$v) {
|
||||
$record_form = $v;
|
||||
//取默认参数
|
||||
$f_sn = 0;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$f_sn = $record_form['sn'];
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_form;
|
||||
$record['params'] = $record_param;
|
||||
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$v = $record;
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
case 'room'; //房型数据,根据条件返回order表中的数据\addon列表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$o_sn = isset($data['addons']['o_sn']) ? intval($data['addons']['o_sn']) : 0;
|
||||
require dirname(__FILE__) . '/_public/list_order.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => &$v) {
|
||||
$record_form = $v;
|
||||
//取默认参数
|
||||
$o_sn = 0;
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$o_sn = $record_form['sn'];
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_form;
|
||||
$record['params'] = $record_param;
|
||||
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$v = $record;
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['total'] = isset($count) ? $count : 1;//总记录数
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
global $_FM;
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'detail';
|
||||
//取单条数据详情
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost);
|
||||
|
||||
$connection = yii::$app->realtydb;
|
||||
$tablePre = 'hi';
|
||||
$table = 'realty_basic';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Realty s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Realty f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Realty o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //房产模型实例,返回self表与param表数据
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_self.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
$s_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$errorCode = 0;
|
||||
$record_param = $result;
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['title', 'status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300304;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'house'; //数据,返回form表\param表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_form.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
//取默认参数
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$f_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300304;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'room'; //数据,返回order表\addon表数据
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_order.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
//取默认参数
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$o_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300306;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$errorCode = 4530039999;
|
||||
break;
|
||||
}
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function actionSave()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'save';
|
||||
|
||||
//数据保存方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost); //过滤后的可用值
|
||||
$inbytes = strlen(json_encode($data));//长度字节统计
|
||||
fmFunc_stat_times_in($username = $_FM['user']['name'], 1); //增加一次接口入站次数累计
|
||||
fmFunc_stat_bytes_in($username = $_FM['user']['name'], $inbytes); //增加一次接口入站数据量累计
|
||||
|
||||
$connection = yii::$app->realtydb;
|
||||
$tablePre = 'hi';
|
||||
$table = 'realty_basic';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Realty s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Realty f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Realty o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = '已保存';
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //房产模型实例数据,保存到self与param表
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
$s_sn = intval($data['addons']['sn']);
|
||||
require dirname(__FILE__) . '/_public/update_self.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_self.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/s_sn.php';
|
||||
}
|
||||
//写param表
|
||||
require dirname(__FILE__) . '/_public/save_param.php';
|
||||
//返回模型SN
|
||||
$record = $s_sn;
|
||||
break;
|
||||
|
||||
case 'house'; //楼盘数据,保存到form与param表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
require dirname(__FILE__) . '/_public/update_form.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_form.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/f_sn.php';
|
||||
}
|
||||
//写param表
|
||||
require dirname(__FILE__) . '/_public/save_param.php';
|
||||
//返回模型SN
|
||||
$record = $f_sn;
|
||||
break;
|
||||
|
||||
case 'room'; //户型数据,保存到order与addon表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$o_sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
require dirname(__FILE__) . '/_public/update_order.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_order.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/o_sn.php';
|
||||
}
|
||||
//写addon表
|
||||
require dirname(__FILE__) . '/_public/save_addon.php';
|
||||
//返回模型SN
|
||||
$record = $o_sn;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ($errorCode > 0) {
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
}
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+477
@@ -0,0 +1,477 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\Url;
|
||||
|
||||
use dataModel;
|
||||
|
||||
//必须添加这一句,以便引入dataModel外部类库
|
||||
|
||||
require dirname(__FILE__) . '/_public/public.php';
|
||||
|
||||
class SearchController extends \yii\web\Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
$_HI['action'] = 'index';
|
||||
require dirname(__FILE__) . '/SettingController/index.php';
|
||||
}
|
||||
|
||||
public function actionGet()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'get';
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
$data['sqls'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost);
|
||||
|
||||
$connection = yii::$app->db;
|
||||
$tablePre = 's';
|
||||
$table = 'metadata';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Metadata s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Metadata f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Metadata o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
|
||||
require dirname(__FILE__) . '/_public/s_sn.php'; //取$s_sn
|
||||
//搜索模型数据每个站点仅需一个,至此,s_sn已经更新
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //模型数据,返回param列表
|
||||
$sn = $s_sn;
|
||||
require dirname(__FILE__) . '/_public/get_self.php';
|
||||
$record_self = $result;
|
||||
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$errorCode = 0;
|
||||
$record_param = $result;
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['title', 'status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$list = array();
|
||||
$list[] = $record;
|
||||
$record = $list;
|
||||
|
||||
break;
|
||||
|
||||
case 'instance'; //实例数据,根据条件返回form表中的数据\param列表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
require dirname(__FILE__) . '/_public/list_form.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => &$v) {
|
||||
$record_form = $v;
|
||||
//取默认参数
|
||||
$f_sn = 0;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$f_sn = $record_form['sn'];
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_form;
|
||||
$record['params'] = $record_param;
|
||||
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
|
||||
$v = $record;
|
||||
}
|
||||
unset($v);
|
||||
$errorCode = 0;
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
case 'content'; //内容数据,根据条件返回order表中的数据\addon列表
|
||||
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$o_sn = isset($data['addons']['o_sn']) ? intval($data['addons']['o_sn']) : 0;
|
||||
require dirname(__FILE__) . '/_public/list_order.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => &$v) {
|
||||
$record_form = $v;
|
||||
//取默认参数
|
||||
$o_sn = 0;
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$o_sn = $record_form['sn'];
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_form;
|
||||
$record['params'] = $record_param;
|
||||
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$v = $record;
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['total'] = isset($count) ? $count : 1;//总记录数
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'detail';
|
||||
//取单条数据详情
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost);
|
||||
|
||||
$connection = yii::$app->db;
|
||||
$tablePre = 's';
|
||||
$table = 'metadata';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Metadata s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Metadata f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Metadata o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
require dirname(__FILE__) . '/_public/s_sn.php'; //取$s_sn
|
||||
//搜索模型数据每个站点仅需一个,至此,s_sn已经更新
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //模型,返回self表与param表数据
|
||||
$sn = $s_sn;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_self.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
$s_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$errorCode = 0;
|
||||
$record_param = $result;
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['title', 'status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$errorCode = 45300304;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'instance'; //实例,返回form表\param表
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_form.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
//取默认参数
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$f_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
unset($record_param['default'][$kk]); //只对在模型中定义的默认参数进行重置
|
||||
}
|
||||
unset($record_param['default']); //重置全部默认参数
|
||||
}
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300304;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'content'; //内容,返回order表\addon表数据
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_order.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
//取默认参数
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$o_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300306;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$errorCode = 4530039999;
|
||||
break;
|
||||
}
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function actionSave()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'save';
|
||||
|
||||
//数据保存方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost); //过滤后的可用值
|
||||
$inbytes = strlen(json_encode($data));//长度字节统计
|
||||
fmFunc_stat_times_in($username = $_FM['user']['name'], 1); //增加一次接口入站次数累计
|
||||
fmFunc_stat_bytes_in($username = $_FM['user']['name'], $inbytes); //增加一次接口入站数据量累计
|
||||
|
||||
$connection = yii::$app->db;
|
||||
$tablePre = 's';
|
||||
$table = 'metadata';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Page s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Page f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Page o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = '已保存';
|
||||
|
||||
require dirname(__FILE__) . '/_public/s_sn.php'; //取$s_sn
|
||||
//搜索模型数据每个站点仅需一个,至此,s_sn已经更新
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //模型数据,保存到self与param表
|
||||
//写param表
|
||||
require dirname(__FILE__) . '/_public/save_param.php';
|
||||
//返回模型SN
|
||||
$record = $s_sn;
|
||||
break;
|
||||
|
||||
case 'instance'; //实例数据,保存到form与param表
|
||||
$f_sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
require dirname(__FILE__) . '/_public/update_form.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_form.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/f_sn.php';
|
||||
}
|
||||
//写param表
|
||||
require dirname(__FILE__) . '/_public/save_param.php';
|
||||
//返回模型SN
|
||||
$record = $f_sn;
|
||||
break;
|
||||
|
||||
case 'content'; //内容数据,保存到order与addon表
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$o_sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
require dirname(__FILE__) . '/_public/update_order.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_order.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/o_sn.php';
|
||||
}
|
||||
//写addon表
|
||||
require dirname(__FILE__) . '/_public/save_addon.php';
|
||||
//返回模型SN
|
||||
$record = $o_sn;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ($errorCode > 0) {
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
}
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
$_goods = array(
|
||||
"title" => '产品查询',
|
||||
"value" => '',
|
||||
"status" => 1,
|
||||
"deleted" => 0,
|
||||
"params" => array(
|
||||
"timelimit" => 5,
|
||||
"reply" => array(
|
||||
"welcome" => array(
|
||||
"tips" => '请输入您想要查询的产品关键词。
|
||||
提示:您可使用 产品名称中的词语作为条件(如,××酒店,芒果等),进行模糊查询匹配;我们默认最多取符合条件的前9个作为结果,回复给您。',
|
||||
"key" => '产品'
|
||||
),
|
||||
"none" => array(
|
||||
"tips" => '您正在查询产品,关键词:{$keywords};
|
||||
查询结果:抱歉,未查询到相关产品,建议您尝试其他关键词。'
|
||||
),
|
||||
),
|
||||
"keywords" => '_goods',
|
||||
)
|
||||
);
|
||||
|
||||
$_member = array(
|
||||
"title" => '会员查询',
|
||||
"value" => '',
|
||||
"status" => 1,
|
||||
"deleted" => 0,
|
||||
"params" => array(
|
||||
"timelimit" => 5,
|
||||
"reply" => array(
|
||||
"welcome" => array(
|
||||
"tips" => '请输入您想要查询的会员关键词。
|
||||
提示:您可使用 姓名、籍贯、行业等条件,进行模糊查询匹配;我们默认最多取符合条件的前9个作为结果,回复给您。',
|
||||
"key" => '产品'
|
||||
),
|
||||
"none" => array(
|
||||
"tips" => '您正在查询会员资料,关键词:{$keywords};
|
||||
查询结果:抱歉,未查询到相关资料,建议您尝试其他关键词。'
|
||||
),
|
||||
),
|
||||
"keywords" => '_member',
|
||||
)
|
||||
);
|
||||
|
||||
$_article = array(
|
||||
"title" => '文章查询',
|
||||
"value" => '',
|
||||
"status" => 1,
|
||||
"deleted" => 0,
|
||||
"params" => array(
|
||||
"timelimit" => 5,
|
||||
"reply" => array(
|
||||
"welcome" => array(
|
||||
"tips" => '请输入您想要查询的文章内容关键词。
|
||||
提示:我们默认最多取符合条件的前9个作为结果,回复给您。',
|
||||
"key" => '文章'
|
||||
),
|
||||
"none" => array(
|
||||
"tips" => '您正在查询文章内容,关键词:{$keywords};
|
||||
查询结果:抱歉,未查询到相关资料,建议您尝试其他关键词。'
|
||||
),
|
||||
),
|
||||
"keywords" => '_article',
|
||||
)
|
||||
);
|
||||
Executable
+483
@@ -0,0 +1,483 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\Url;
|
||||
|
||||
use dataModel;
|
||||
|
||||
//必须添加这一句,以便引入dataModel外部类库
|
||||
|
||||
require dirname(__FILE__) . '/_public/public.php';
|
||||
|
||||
class SettingController extends \yii\web\Controller
|
||||
{
|
||||
public $enableCsrfValidation = FALSE;//取消对POST数据的csrf令牌验证
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
$_HI['action'] = 'index';
|
||||
require dirname(__FILE__) . '/SettingController/index.php';
|
||||
}
|
||||
|
||||
public function actionGet()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'get';
|
||||
//数据取出方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
$data['sqls'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost);
|
||||
|
||||
$connection = yii::$app->pagedb;
|
||||
$tablePre = 'hi';
|
||||
$table = 'setting';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Setting s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Setting f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Setting o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //模型数据,返回self列表\param列表
|
||||
require dirname(__FILE__) . '/_public/list_self.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => $v) {
|
||||
$s_sn = $v['sn'];
|
||||
$record_self = $v;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$errorCode = 0;
|
||||
$record_param = $result;
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['title', 'status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$list[$k] = $record;
|
||||
}
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
case 'instance'; //实例数据,根据条件返回form表中的数据\param列表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
require dirname(__FILE__) . '/_public/list_form.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => &$v) {
|
||||
$record_form = $v;
|
||||
//取默认参数
|
||||
$f_sn = 0;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$f_sn = $record_form['sn'];
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_form;
|
||||
$record['params'] = $record_param;
|
||||
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$v = $record;
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
case 'content'; //内容数据,根据条件返回order表中的数据\addon列表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$o_sn = isset($data['addons']['o_sn']) ? intval($data['addons']['o_sn']) : 0;
|
||||
require dirname(__FILE__) . '/_public/list_order.php';
|
||||
$list = $result;
|
||||
if ($errorCode == 0) {
|
||||
foreach ($list as $k => &$v) {
|
||||
$record_form = $v;
|
||||
//取默认参数
|
||||
$o_sn = 0;
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$o_sn = $record_form['sn'];
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_form;
|
||||
$record['params'] = $record_param;
|
||||
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $kk) {
|
||||
if (isset($record['params'][$kk])) {
|
||||
$record[$kk] = $record['params'][$kk];
|
||||
}
|
||||
}
|
||||
$v = $record;
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
$record = $list;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['total'] = isset($count) ? $count : 1;//总记录数
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'detail';
|
||||
//取单条数据详情
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost);
|
||||
|
||||
$connection = yii::$app->pagedb;
|
||||
$tablePre = 'hi';
|
||||
$table = 'setting';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Page s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Page f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Page o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //模型,返回self表与param表数据
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_self.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
$s_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$errorCode = 0;
|
||||
$record_param = $result;
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['title', 'status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300304;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'instance'; //实例,返回form表\param表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_form.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
//取默认参数
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$f_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_param.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
unset($record_param['default'][$kk]); //只对在模型中定义的默认参数进行重置
|
||||
}
|
||||
//unset($record_param['default']); //重置全部默认参数
|
||||
}
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300304;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'content'; //内容,返回order表\addon表数据
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
$errorCode = 0;
|
||||
if ($sn) {
|
||||
require dirname(__FILE__) . '/_public/get_order.php';
|
||||
$record_self = $result;
|
||||
if ($errorCode == 0) {
|
||||
//取默认参数
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_default = $result;
|
||||
//取当前表单的指定参数
|
||||
$o_sn = $sn;
|
||||
require dirname(__FILE__) . '/_public/get_addon.php';
|
||||
$record_param_private = $result;
|
||||
|
||||
$record_param = array_merge($record_param_default, $record_param_private);
|
||||
|
||||
//读取默认参数并在写入params后重置
|
||||
if (isset($record_param_default['default'])) {
|
||||
foreach ($record_param_default['default'] as $kk => $vv) {
|
||||
if (isset($record_param[$kk]) && is_array($record_param[$kk]) && is_array($vv)) {
|
||||
$record_param[$kk] = array_merge($vv, $record_param[$kk]);
|
||||
} else if (!isset($record_param[$kk])) {
|
||||
$record_param[$kk] = $vv;
|
||||
}
|
||||
}
|
||||
unset($record_param['default']);
|
||||
}
|
||||
|
||||
$record = $record_self;
|
||||
$record['params'] = $record_param;
|
||||
//需要重设的字段
|
||||
$reset = ['status', 'deleted'];
|
||||
foreach ($reset as $k) {
|
||||
if (isset($record['params'][$k])) {
|
||||
$record[$k] = $record['params'][$k]; //重设标题
|
||||
}
|
||||
}
|
||||
$errorCode = 0;
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300306;
|
||||
$record = $data['addons'];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$errorCode = 4530039999;
|
||||
break;
|
||||
}
|
||||
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
public function actionSave()
|
||||
{
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
global $START_TIME;
|
||||
$_HI['action'] = 'save';
|
||||
|
||||
//数据保存方法
|
||||
$dataGet = $_FM['get']; //GET进来的参数
|
||||
$dataPost = $_FM['post']; //POST进来的参数
|
||||
$data = array();
|
||||
$data['addons'] = array();
|
||||
|
||||
require dirname(__FILE__) . '/_public/plat.php';
|
||||
|
||||
$dbmodel = new dataModel;
|
||||
$data = $dbmodel->data_filter($dataPost); //过滤后的可用值
|
||||
$inbytes = strlen(json_encode($data));//长度字节统计
|
||||
fmFunc_stat_times_in($username = $_FM['user']['name'], 1); //增加一次接口入站次数累计
|
||||
fmFunc_stat_bytes_in($username = $_FM['user']['name'], $inbytes); //增加一次接口入站数据量累计
|
||||
|
||||
$connection = yii::$app->pagedb;
|
||||
$tablePre = 'hi';
|
||||
$table = 'setting';
|
||||
|
||||
$s_sn = 0;
|
||||
$f_sn = 0;
|
||||
$o_sn = 0;
|
||||
$s_sn_title = Yii::t('frontend', 'Default Page s_sn_title');
|
||||
$f_sn_title = Yii::t('frontend', 'Default Page f_sn_title');
|
||||
$o_sn_title = Yii::t('frontend', 'Default Page o_sn_title');
|
||||
|
||||
$return = array();
|
||||
$errorCode = 0;
|
||||
$return['errorcode'] = $errorCode;
|
||||
$return['msg'] = '已保存';
|
||||
|
||||
switch ($ac) {
|
||||
case 'model'; //模型数据,保存到self与param表
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
$s_sn = intval($data['addons']['sn']);
|
||||
require dirname(__FILE__) . '/_public/update_self.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_self.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/s_sn.php';
|
||||
}
|
||||
//写param表
|
||||
require dirname(__FILE__) . '/_public/save_param.php';
|
||||
//返回模型SN
|
||||
$record = $s_sn;
|
||||
break;
|
||||
|
||||
case 'instance'; //实例数据,保存到form与param表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
require dirname(__FILE__) . '/_public/update_form.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_form.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/f_sn.php';
|
||||
}
|
||||
//写param表
|
||||
require dirname(__FILE__) . '/_public/save_param.php';
|
||||
//返回模型SN
|
||||
$record = $f_sn;
|
||||
break;
|
||||
|
||||
case 'content'; //内容数据,保存到order与addon表
|
||||
$s_sn = isset($data['addons']['s_sn']) ? intval($data['addons']['s_sn']) : 0;
|
||||
$f_sn = isset($data['addons']['f_sn']) ? intval($data['addons']['f_sn']) : 0;
|
||||
$o_sn = isset($data['addons']['sn']) ? intval($data['addons']['sn']) : 0;
|
||||
if (isset($data['addons']['sn']) && intval($data['addons']['sn']) > 0) {
|
||||
//传入了非0SN,即是对指定数据进行修改
|
||||
require dirname(__FILE__) . '/_public/update_order.php';
|
||||
} else if (isset($data['addons']['sn']) && intval($data['addons']['sn']) == 0) {
|
||||
//传入了0SN,即是新建一个数据
|
||||
require dirname(__FILE__) . '/_public/new_order.php';
|
||||
} else {
|
||||
//未传入SN时,从服务器取出一个,未取到时自动新建
|
||||
require dirname(__FILE__) . '/_public/o_sn.php';
|
||||
}
|
||||
//写addon表
|
||||
require dirname(__FILE__) . '/_public/save_addon.php';
|
||||
//返回模型SN
|
||||
$record = $o_sn;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ($errorCode > 0) {
|
||||
$return['msg'] = Yii::t('errorcode', $errorCode);
|
||||
}
|
||||
$return['data'] = isset($record) ? $record : '';
|
||||
$return['timeused'] = getMillisecond() - $START_TIME;
|
||||
$return['bytes'] = strlen(json_encode($return['data']));//长度字节统计
|
||||
fmFunc_stat_times_out($username = $_FM['user']['name'], 1); //增加一次接口出站次数累计
|
||||
fmFunc_stat_bytes_out($username = $_FM['user']['name'], $return['bytes']); //增加一次接口出站数据量累计
|
||||
return json_encode($return);
|
||||
}
|
||||
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
global $_GPC;
|
||||
global $_HI;
|
||||
global $_FM;
|
||||
die(json_encode($_FM));
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
global $_FM;
|
||||
var_dump($_FM);
|
||||
return;
|
||||
Executable
+222
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2021-09-09 23:05:45
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2021-09-09 23:06:05
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\Controller;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\filters\AccessControl;
|
||||
use frontend\models\LoginForm;
|
||||
use frontend\models\PasswordResetRequestForm;
|
||||
use frontend\models\ResetPasswordForm;
|
||||
use frontend\models\SignupForm;
|
||||
use frontend\models\ContactForm;
|
||||
|
||||
/**
|
||||
* Site controller
|
||||
*/
|
||||
class SiteController extends Controller
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'access' => [
|
||||
'class' => AccessControl::className(),
|
||||
'only' => ['logout', 'signup'],
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['signup'],
|
||||
'allow' => TRUE,
|
||||
'roles' => ['?'],
|
||||
],
|
||||
[
|
||||
'actions' => ['logout'],
|
||||
'allow' => TRUE,
|
||||
'roles' => ['@'],
|
||||
],
|
||||
],
|
||||
],
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'logout' => ['post'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function actions()
|
||||
{
|
||||
return [
|
||||
'error' => [
|
||||
'class' => 'yii\web\ErrorAction',
|
||||
],
|
||||
'captcha' => [
|
||||
'class' => 'yii\captcha\CaptchaAction',
|
||||
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : NULL,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays homepage.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs in a user.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionLogin()
|
||||
{
|
||||
if (!Yii::$app->user->isGuest) {
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
$model = new LoginForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->login()) {
|
||||
return $this->goBack();
|
||||
} else {
|
||||
return $this->render('login', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out the current user.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionLogout()
|
||||
{
|
||||
Yii::$app->user->logout();
|
||||
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays contact page.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionContact()
|
||||
{
|
||||
$model = new ContactForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
|
||||
if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
|
||||
Yii::$app->session->setFlash('success', '已收到您的反馈,我们将尽快响应并联系您。');
|
||||
} else {
|
||||
Yii::$app->session->setFlash('error', '消息发送时系统遇到错误.');
|
||||
}
|
||||
|
||||
return $this->refresh();
|
||||
} else {
|
||||
return $this->render('contact', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays about page.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionAbout()
|
||||
{
|
||||
return $this->render('about');
|
||||
}
|
||||
|
||||
/**
|
||||
* Signs user up.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionSignup()
|
||||
{
|
||||
$model = new SignupForm();
|
||||
if ($model->load(Yii::$app->request->post())) {
|
||||
if ($user = $model->signup()) {
|
||||
if (Yii::$app->getUser()->login($user)) {
|
||||
return $this->goHome();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('signup', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests password reset.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionRequestPasswordReset()
|
||||
{
|
||||
$model = new PasswordResetRequestForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
|
||||
if ($model->sendEmail()) {
|
||||
Yii::$app->session->setFlash('success', '发送完毕,请登陆您的邮箱查阅并进行接下来的操作.');
|
||||
|
||||
return $this->goHome();
|
||||
} else {
|
||||
Yii::$app->session->setFlash('error', '抱歉,系统无法向您填写的邮箱发送重置邮件,请检查邮箱地址.');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('requestPasswordResetToken', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets password.
|
||||
*
|
||||
* @param string $token
|
||||
* @return mixed
|
||||
* @throws BadRequestHttpException
|
||||
*/
|
||||
public function actionResetPassword($token)
|
||||
{
|
||||
try {
|
||||
$model = new ResetPasswordForm($token);
|
||||
} catch (InvalidParamException $e) {
|
||||
throw new BadRequestHttpException($e->getMessage());
|
||||
}
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
|
||||
Yii::$app->session->setFlash('success', '新密码已保存.');
|
||||
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
return $this->render('resetPassword', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
//取form表sn
|
||||
$suffix = 'form';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$column = "sn";
|
||||
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`platid` = :platid";
|
||||
$params[':platid'] = $platid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`uniacid` = :uniacid";
|
||||
$params[':uniacid'] = $uniacid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`shopid` = :shopid";
|
||||
$params[':shopid'] = $shopid;
|
||||
|
||||
$f_sn = fmFunc_pdo_yii_fetchcolumn($connection, $tableName, $column, $condition, $params);
|
||||
if (!$f_sn) {
|
||||
$initdata = $dbmodel->data_format($data, $suffix);
|
||||
$initdata['title'] = $f_sn_title;
|
||||
$initdata['value'] = '';
|
||||
$initdata['createtime'] = $_FM['timestamp'];
|
||||
$initdata['updatetime'] = $_FM['timestamp'];
|
||||
$initdata['deleted'] = 0;
|
||||
$initdata['status'] = 1;
|
||||
$initdata['sn'] = getMillisecond() * 10;
|
||||
$initdata['sn'] = intval($initdata['sn']);
|
||||
$initdata['s_sn'] = $s_sn;
|
||||
|
||||
fmFunc_pdo_yii_insert($connection, $tableName, $initdata);
|
||||
$f_sn = $initdata['sn'];
|
||||
}
|
||||
Executable
+92
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
//OK
|
||||
//取addon表数据
|
||||
$suffix = 'addon';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$condition .= "`o_sn` = :o_sn";
|
||||
$params[':o_sn'] = $o_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`f_sn` = :f_sn";
|
||||
$params[':f_sn'] = $f_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`platid` = :platid";
|
||||
$params[':platid'] = $platid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`uniacid` = :uniacid";
|
||||
$params[':uniacid'] = $uniacid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`shopid` = :shopid";
|
||||
$params[':shopid'] = $shopid;
|
||||
|
||||
switch ($op) {
|
||||
case 'unused': //取未删除、不可用状态的数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = 0;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
|
||||
case 'deleted': //取已删除数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 1;
|
||||
break;
|
||||
|
||||
default: //默认,取未删除、可用状态的数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = 1;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
$columns = ['setfor', 'title', 'key', 'value'];
|
||||
|
||||
$result = fmFunc_pdo_yii_getall($connection, $tableName, $columns, $condition, $params, $limits = array(), $showorders = array());
|
||||
$record = array();
|
||||
if ($result) {
|
||||
foreach ($result as $_k => $_v) {
|
||||
$setfor = $_v['setfor'];
|
||||
$title = $_v['title'];
|
||||
$key = $_v['key'];
|
||||
$value = iunserializer($_v['value']);
|
||||
$str = $setfor . '_' . $title . '_' . $key . '.php';
|
||||
$len = 0 - strlen($str);
|
||||
if (!empty($value) && is_string($value) && substr($value, $len) == $str) {
|
||||
if (fmFunc_file_checkExist($value, 'data/')) {
|
||||
$value = fmFunc_file_dataLoad($value);
|
||||
}
|
||||
}
|
||||
$record[$setfor] = [];
|
||||
$record[$setfor][$title] = [];
|
||||
$record[$setfor][$title][$key] = $value;
|
||||
|
||||
if ($setfor == $title) {
|
||||
if ($title == $key) {
|
||||
$record[$setfor] = $value;
|
||||
} else {
|
||||
$record[$setfor][$key] = $value;
|
||||
}
|
||||
} else {
|
||||
if ($title == $key) {
|
||||
$record[$setfor][$title] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300307;
|
||||
}
|
||||
$result = $record;
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
//取data表数据
|
||||
$suffix = 'data';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$condition .= "`o_sn` = :o_sn";
|
||||
$params[':o_sn'] = $o_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`f_sn` = :f_sn";
|
||||
$params[':f_sn'] = $f_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`platid` = :platid";
|
||||
$params[':platid'] = $platid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`uniacid` = :uniacid";
|
||||
$params[':uniacid'] = $uniacid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`shopid` = :shopid";
|
||||
$params[':shopid'] = $shopid;
|
||||
|
||||
switch ($op) {
|
||||
case 'unused': //取未删除、不可用状态的数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = 0;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
|
||||
case 'deleted': //取已删除数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 1;
|
||||
break;
|
||||
|
||||
default: //默认,取未删除、可用状态的数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = 1;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
$columns = ['setfor', 'title', 'key', 'value'];
|
||||
|
||||
$result = fmFunc_pdo_yii_getall($connection, $tableName, $columns, $condition, $params, $limits = array(), $showorders = array());
|
||||
$record = array();
|
||||
if ($result) {
|
||||
foreach ($result as $_k => $_v) {
|
||||
$setfor = $_v['setfor'];
|
||||
$title = $_v['title'];
|
||||
$key = $_v['key'];
|
||||
$value = iunserializer($_v['value']);
|
||||
$str = $setfor . '_' . $title . '_' . $key . '.php';
|
||||
$len = 0 - strlen($str);
|
||||
if (!empty($value) && is_string($value) && substr($value, $len) == $str) {
|
||||
if (fmFunc_file_checkExist($value, 'data/')) {
|
||||
$value = fmFunc_file_dataLoad($value);
|
||||
}
|
||||
}
|
||||
$record[$setfor][$title][$key] = $value;
|
||||
|
||||
if ($setfor == $title) {
|
||||
if ($title == $key) {
|
||||
$record[$setfor] = $value;
|
||||
} else {
|
||||
$record[$setfor][$key] = $value;
|
||||
}
|
||||
} else {
|
||||
if ($title == $key) {
|
||||
$record[$setfor][$title] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300302;
|
||||
}
|
||||
$result = $record;
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
//OK
|
||||
//取form表数据
|
||||
$suffix = 'form';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$columns = array('platid', 'uniacid', 'shopid', 's_sn', 'sn', 'title', 'value', 'displayorder', 'status', 'deleted');
|
||||
|
||||
$condition .= "`sn` = :sn";
|
||||
$params[':sn'] = $sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`platid` = :platid";
|
||||
$params[':platid'] = $platid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`uniacid` = :uniacid";
|
||||
$params[':uniacid'] = $uniacid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`shopid` = :shopid";
|
||||
$params[':shopid'] = $shopid;
|
||||
|
||||
$result = fmFunc_pdo_yii_get($connection, $tableName, $columns, $condition, $params, $limits = array());
|
||||
if (!$result) {
|
||||
$errorCode = 45300305;
|
||||
}
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
//OK
|
||||
//取order表数据
|
||||
$suffix = 'order';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$columns = array('platid', 'uniacid', 'shopid', 's_sn', 'f_sn', 'sn', 'partnerid', 'mid', 'fid', 'title', 'value', 'displayorder', 'status', 'deleted');
|
||||
|
||||
$condition .= "`sn` = :sn";
|
||||
$params[':sn'] = $sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`f_sn` = :f_sn";
|
||||
$params[':f_sn'] = $f_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`platid` = :platid";
|
||||
$params[':platid'] = $platid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`uniacid` = :uniacid";
|
||||
$params[':uniacid'] = $uniacid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`shopid` = :shopid";
|
||||
$params[':shopid'] = $shopid;
|
||||
|
||||
$result = fmFunc_pdo_yii_get($connection, $tableName, $columns, $condition, $params, $limits = array());
|
||||
if (!$result) {
|
||||
$errorCode = 45300306;
|
||||
}
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
//OK
|
||||
//取param表数据
|
||||
$suffix = 'param';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$condition .= "`f_sn` = :f_sn";
|
||||
$params[':f_sn'] = $f_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`platid` = :platid";
|
||||
$params[':platid'] = $platid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`uniacid` = :uniacid";
|
||||
$params[':uniacid'] = $uniacid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`shopid` = :shopid";
|
||||
$params[':shopid'] = $shopid;
|
||||
|
||||
switch ($op) {
|
||||
case 'unused': //取未删除、不可用状态的数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = 0;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
|
||||
case 'deleted': //取已删除数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 1;
|
||||
break;
|
||||
|
||||
default: //默认,取未删除、可用状态的数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = 1;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
$columns = ['setfor', 'title', 'key', 'value'];
|
||||
|
||||
$result = fmFunc_pdo_yii_getall($connection, $tableName, $columns, $condition, $params, $limits = array(), $showorders = array());
|
||||
$record = array();
|
||||
if ($result) {
|
||||
foreach ($result as $_k => $_v) {
|
||||
$setfor = $_v['setfor'];
|
||||
$title = $_v['title'];
|
||||
$key = $_v['key'];
|
||||
$value = iunserializer($_v['value']);
|
||||
$str = $setfor . '_' . $title . '_' . $key . '.php';
|
||||
$len = 0 - strlen($str);
|
||||
if (!empty($value) && is_string($value) && substr($value, $len) == $str) {
|
||||
if (fmFunc_file_checkExist($value, 'data/')) {
|
||||
$value = fmFunc_file_dataLoad($value);
|
||||
}
|
||||
}
|
||||
$record[$setfor][$title][$key] = $value;
|
||||
|
||||
if ($setfor == $title) {
|
||||
if ($title == $key) {
|
||||
$record[$setfor] = $value;
|
||||
} else {
|
||||
$record[$setfor][$key] = $value;
|
||||
}
|
||||
} else {
|
||||
if ($title == $key) {
|
||||
$record[$setfor][$title] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$errorCode = 45300303;
|
||||
}
|
||||
|
||||
$result = $record;
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
//OK
|
||||
//取self表某站点、sn对应数据
|
||||
$suffix = 'self';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$columns = array('platid', 'uniacid', 'shopid', 'sn', 'title', 'keywords', 'displayorder', 'status', 'deleted');
|
||||
|
||||
$condition .= "`sn` = :sn";
|
||||
$params[':sn'] = $sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
|
||||
$result = fmFunc_pdo_yii_get($connection, $tableName, $columns, $condition, $params, $limits = array());
|
||||
if (!$result) {
|
||||
$errorCode = 45300304;
|
||||
}
|
||||
Executable
+190
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
//OK
|
||||
//取form数据列表
|
||||
$suffix = 'form';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$columns = array('s_sn', 'platid', 'uniacid', 'shopid', 'partnerid', 'uid', 'sn', 'title', 'value', 'displayorder', 'status', 'deleted');
|
||||
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
//跨平台搜索条件
|
||||
if (isset($data['searching']['plat']) && $data['searching']['plat'] == $platid) {
|
||||
$condition .= " AND ";
|
||||
$condition .= "`platid` = :platid";
|
||||
$params[':platid'] = $platid;
|
||||
} else {
|
||||
$condition .= " AND ";
|
||||
$condition .= "`uniacid` = :uniacid";
|
||||
$params[':uniacid'] = $uniacid;
|
||||
}
|
||||
|
||||
$condition .= " AND ";
|
||||
$condition .= "`shopid` = :shopid";
|
||||
$params[':shopid'] = $shopid;
|
||||
|
||||
//增加搜索条件,取多s_sn查询
|
||||
$issearching = isset($data['searching']) ? TRUE : FALSE;
|
||||
$searching = array();
|
||||
if ($issearching) {
|
||||
$condition_searching = $condition;
|
||||
$params_searching = $params;
|
||||
//系统自带搜索条件约定(精确匹配)
|
||||
if (isset($data['searching']['status'])) {
|
||||
$condition_searching .= " AND ";
|
||||
$condition_searching .= "`status` = :status";
|
||||
$params_searching[':status'] = intval($data['searching']['status']);
|
||||
}
|
||||
|
||||
if (isset($data['searching']['deleted'])) {
|
||||
$condition_searching .= " AND ";
|
||||
$condition_searching .= "`deleted` = :deleted";
|
||||
$params_searching[':deleted'] = intval($data['searching']['deleted']);
|
||||
}
|
||||
//搜索条件filter参数过滤
|
||||
if (isset($data['searching']['filter'])) {
|
||||
foreach ($data['searching']['filter'] as $_k => $_v) {
|
||||
$condition_searching .= " AND ";
|
||||
$condition_searching .= "`key` = :key";
|
||||
$params_searching[':key'] = $_k;
|
||||
$condition_searching .= " AND ";
|
||||
if (is_array($_v)) {
|
||||
$x_condition = "(";
|
||||
$x_i = count($_v);
|
||||
foreach ($_v as $xk => $xv) {
|
||||
$x_i--;
|
||||
$x_condition .= "'" . serialize($xv) . "'";
|
||||
if ($x_i > 0) {
|
||||
$x_condition .= ",";
|
||||
}
|
||||
}
|
||||
$x_condition .= ")";
|
||||
$condition_searching .= "`value` IN " . $x_condition;
|
||||
} else {
|
||||
$condition_searching .= "`value` LIKE :value";
|
||||
$params_searching[':value'] = '%' . serialize($_v) . '%';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//客户侧传入的额外搜索条件(模糊可选匹配)
|
||||
if (isset($data['searching']['addons'])) {
|
||||
foreach ($data['searching']['addons'] as $_k => $_v) {
|
||||
$condition_searching .= " AND ";
|
||||
$condition_searching .= "`key` = :key";
|
||||
$params_searching[':key'] = $_k;
|
||||
$condition_searching .= " AND ";
|
||||
$condition_searching .= "`value` LIKE :value";
|
||||
$params_searching[':value'] = '%' . serialize($_v) . '%';
|
||||
|
||||
$temp_tableName = $tablePre . '_' . $table . '_param';
|
||||
$result = fmFunc_pdo_yii_getall($connection, $temp_tableName, array('s_sn'), $condition_searching, $params_searching, $limits = array(), $orders = array());
|
||||
if ($result) {
|
||||
foreach ($result as $_kk => $_vv) {
|
||||
if ($_vv['s_sn'] != $s_sn) {
|
||||
$searching[] = $_vv['s_sn'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$temp_tableName = $tablePre . '_' . $table . '_param';
|
||||
$result = fmFunc_pdo_yii_getall($connection, $temp_tableName, array('s_sn'), $condition_searching, $params_searching, $limits = array(), $orders = array());
|
||||
if ($result) {
|
||||
foreach ($result as $_kk => $_vv) {
|
||||
if ($_vv['s_sn'] != $s_sn && !in_array($_vv['s_sn'], $searching)) {
|
||||
$searching[] = $_vv['s_sn'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$searching = array_unique($searching);
|
||||
$issearching = (count($searching) == 0) ? FALSE : TRUE;
|
||||
|
||||
//传入了s_sn时,也作为搜索条件
|
||||
if ($s_sn > 0) {
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
} else if ($issearching) {
|
||||
$s_sns = '';
|
||||
foreach ($searching as $temp_s_sn) {
|
||||
$s_sns .= $temp_s_sn . ",";
|
||||
}
|
||||
$s_sns .= $s_sns;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` IN (" . $s_sns . ")";
|
||||
}
|
||||
|
||||
if ($issearching) {
|
||||
$op = '';
|
||||
}
|
||||
|
||||
switch ($op) {
|
||||
case 'index': //取未删除、可用状态的数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = 1;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
|
||||
case 'unused': //取未删除、不可用状态的数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = 0;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
|
||||
case 'deleted': //取已删除数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 1;
|
||||
break;
|
||||
|
||||
case 'all': //取未删除数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
if (isset($data['searching']['status'])) {
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = $data['searching']['status'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
//补充搜索条件
|
||||
if (isset($data['searching']['keyword'])) {
|
||||
$condition .= " AND ";
|
||||
$condition .= "`title` LIKE :keyword";
|
||||
$params[':keyword'] = '%' . $data['searching']['keyword'] . '%';
|
||||
}
|
||||
|
||||
//数据分页
|
||||
$limits = !empty($data['sqls']['limits']) ? $data['sqls']['limits'] : array();
|
||||
|
||||
//数据排序
|
||||
$orders = !empty($data['sqls']['orders']) ? $data['sqls']['orders'] : array();
|
||||
|
||||
$result = fmFunc_pdo_yii_getall($connection, $tableName, $columns, $condition, $params, $limits, $orders = array());
|
||||
if (!$result) {
|
||||
$errorCode = 45300305;
|
||||
}
|
||||
|
||||
$total = FmFunc_pdo_yii_getall($connection, $tableName, $columns = array('sn'), $condition, $params, $limits = array(), $orders = array());
|
||||
$count = count($total);
|
||||
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
//OK
|
||||
//取order数据列表
|
||||
$suffix = 'order';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$columns = array('s_sn', 'f_sn', 'platid', 'uniacid', 'shopid', 'partnerid', 'mid', 'fid', 'sn', 'title', 'value', 'displayorder', 'status', 'deleted');
|
||||
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`platid` = :platid";
|
||||
$params[':platid'] = $platid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`uniacid` = :uniacid";
|
||||
$params[':uniacid'] = $uniacid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`shopid` = :shopid";
|
||||
$params[':shopid'] = $shopid;
|
||||
|
||||
//传入了s_sn时,也作为搜索条件
|
||||
if ($s_sn > 0) {
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
}
|
||||
|
||||
//增加搜索条件,取多f_sn查询
|
||||
$issearching = FALSE;
|
||||
$searching = array();
|
||||
if ($issearching) {
|
||||
if (isset($data['searching']['addons'])) {
|
||||
foreach ($data['searching']['addons'] as $_k => $_v) {
|
||||
$condition .= " AND ";
|
||||
$condition .= "`key` = :key";
|
||||
$params[':key'] = $_k;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`value` LIKE :value";
|
||||
$params[':value'] = '%' . $_v . '%';
|
||||
|
||||
$temp_tableName = $tablePre . '_' . $table . '_addon';
|
||||
$result = fmFunc_pdo_yii_getall($connection, $temp_tableName, array('f_sn'), $condition, $params, $limits = array(), $orders = array());
|
||||
if ($result) {
|
||||
foreach ($result as $_kk => $_vv) {
|
||||
$searching[] = $_vv['f_sn'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$searching = array_unique($searching);
|
||||
$issearching = (count($searching) == 0) ? FALSE : TRUE;
|
||||
|
||||
//传入了f_sn时,也作为搜索条件
|
||||
if ($f_sn > 0) {
|
||||
$condition .= " AND ";
|
||||
$condition .= "`f_sn` = :f_sn";
|
||||
$params[':f_sn'] = $f_sn;
|
||||
} else if ($issearching) {
|
||||
$f_sns = '';
|
||||
foreach ($searching as $temp_f_sn) {
|
||||
$f_sns .= $temp_f_sn . ",";
|
||||
}
|
||||
$f_sns .= $f_sns;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`f_sn` IN (" . $f_sns . ")";
|
||||
}
|
||||
|
||||
if ($issearching) {
|
||||
$op = '';
|
||||
}
|
||||
|
||||
switch ($op) {
|
||||
case 'index': //取未删除、可用状态的数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = 1;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
|
||||
case 'unused': //取未删除、不可用状态的数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = 0;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
|
||||
case 'deleted': //取已删除数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 1;
|
||||
break;
|
||||
|
||||
case 'all': //取未删除数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
if (isset($data['searching']['status'])) {
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = $data['searching']['status'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
//补充搜索条件
|
||||
if (isset($data['searching']['keyword'])) {
|
||||
$condition .= " AND ";
|
||||
$condition .= "`title` LIKE :keyword";
|
||||
$params[':keyword'] = '%' . $data['searching']['keyword'] . '%';
|
||||
}
|
||||
|
||||
$limits = !empty($data['sqls']['limits']) ? $data['sqls']['limits'] : array();
|
||||
|
||||
$result = fmFunc_pdo_yii_getall($connection, $tableName, $columns, $condition, $params, $limits, $orders = array());
|
||||
if (!$result) {
|
||||
$errorCode = 45300306;
|
||||
}
|
||||
|
||||
$total = FmFunc_pdo_yii_getall($connection, $tableName, $columns = array('sn'), $condition, $params, $limits = array(), $orders = array());
|
||||
$count = count($total);
|
||||
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
//OK
|
||||
//取self数据列表,只对应到站点即可
|
||||
$suffix = 'self';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$columns = array('platid', 'uniacid', 'shopid', 'sn', 'title', 'keywords', 'displayorder', 'status', 'deleted');
|
||||
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
|
||||
switch ($op) {
|
||||
case 'index': //取未删除、可用状态的数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = 1;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
|
||||
case 'unused': //取未删除、不可用状态的数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`status` = :status";
|
||||
$params[':status'] = 0;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
|
||||
case 'deleted': //取已删除数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 1;
|
||||
break;
|
||||
|
||||
case 'all': //取未删除数据
|
||||
$condition .= " AND ";
|
||||
$condition .= "`deleted` = :deleted";
|
||||
$params[':deleted'] = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$limits = !empty($data['sqls']['limits']) ? $data['sqls']['limits'] : array();
|
||||
|
||||
$result = fmFunc_pdo_yii_getall($connection, $tableName, $columns, $condition, $params, $limits, $orders = array());
|
||||
if (!$result) {
|
||||
$errorCode = 45300304;
|
||||
}
|
||||
|
||||
$total = FmFunc_pdo_yii_getall($connection, $tableName, $columns = array('sn'), $condition, $params, $limits = array(), $orders = array());
|
||||
$count = count($total);
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
//OK
|
||||
$suffix = 'form';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$partnerid = isset($data['partnerid']) ? $data['partnerid'] : 0;
|
||||
$uid = isset($data['uid']) ? $data['uid'] : 0;
|
||||
|
||||
$initdata = $dbmodel->data_format($data['addons'], $suffix);
|
||||
$initdata['title'] = isset($initdata['title']) ? $initdata['title'] : $s_sn_title;
|
||||
$initdata['value'] = isset($initdata['value']) ? $initdata['value'] : '';
|
||||
$initdata['createtime'] = $_FM['timestamp'];
|
||||
$initdata['updatetime'] = $_FM['timestamp'];
|
||||
$initdata['deleted'] = isset($initdata['deleted']) ? $initdata['deleted'] : 0;
|
||||
$initdata['status'] = isset($initdata['status']) ? $initdata['status'] : 1;
|
||||
$initdata['statuscode'] = isset($data['statuscode']) ? $data['statuscode'] : 64;
|
||||
$initdata['displayorder'] = isset($initdata['displayorder']) ? $initdata['displayorder'] : 0;
|
||||
$initdata['sn'] = getMillisecond() * 10;
|
||||
$initdata['sn'] = intval($initdata['sn']);
|
||||
$initdata['s_sn'] = $s_sn;
|
||||
|
||||
$result = fmFunc_pdo_yii_insert($connection, $tableName, $initdata);
|
||||
$f_sn = $initdata['sn'];
|
||||
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
//OK
|
||||
$suffix = 'order';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$partnerid = isset($data['partnerid']) ? $data['partnerid'] : 0;
|
||||
$mid = isset($data['mid']) ? $data['mid'] : 0;
|
||||
$fid = isset($data['fid']) ? $data['fid'] : 0;
|
||||
|
||||
$initdata = $dbmodel->data_format($data['addons'], $suffix);
|
||||
$initdata['title'] = isset($initdata['title']) ? $initdata['title'] : $s_sn_title;
|
||||
$initdata['value'] = isset($initdata['value']) ? $initdata['value'] : '';
|
||||
$initdata['createtime'] = $_FM['timestamp'];
|
||||
$initdata['updatetime'] = $_FM['timestamp'];
|
||||
$initdata['deleted'] = isset($initdata['deleted']) ? $initdata['deleted'] : 0;
|
||||
$initdata['status'] = isset($initdata['status']) ? $initdata['status'] : 1;
|
||||
$initdata['statuscode'] = isset($data['statuscode']) ? $data['statuscode'] : 64;
|
||||
$initdata['displayorder'] = isset($initdata['displayorder']) ? $initdata['displayorder'] : 0;
|
||||
$initdata['sn'] = getMillisecond() * 10;
|
||||
$initdata['sn'] = intval($initdata['sn']);
|
||||
$initdata['s_sn'] = $s_sn;
|
||||
$initdata['f_sn'] = $f_sn;
|
||||
|
||||
$result = fmFunc_pdo_yii_insert($connection, $tableName, $initdata);
|
||||
$o_sn = $initdata['sn'];
|
||||
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
//OK
|
||||
$suffix = 'self';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$initdata = $dbmodel->data_format($data['addons'], $suffix);
|
||||
$initdata['title'] = isset($initdata['title']) ? $initdata['title'] : $s_sn_title;
|
||||
$initdata['keywords'] = isset($initdata['keywords']) ? $initdata['keywords'] : '';
|
||||
$initdata['createtime'] = $_FM['timestamp'];
|
||||
$initdata['updatetime'] = $_FM['timestamp'];
|
||||
$initdata['deleted'] = isset($initdata['deleted']) ? $initdata['deleted'] : 0;
|
||||
$initdata['status'] = isset($initdata['status']) ? $initdata['status'] : 1;
|
||||
$initdata['displayorder'] = isset($initdata['displayorder']) ? $initdata['displayorder'] : 0;
|
||||
$initdata['sn'] = getMillisecond() * 10;
|
||||
$initdata['sn'] = intval($initdata['sn']);
|
||||
|
||||
$result = fmFunc_pdo_yii_insert($connection, $tableName, $initdata);
|
||||
$s_sn = $initdata['sn'];
|
||||
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
//取order表sn
|
||||
$suffix = 'order';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$column = "sn";
|
||||
|
||||
$condition .= "`f_sn` = :f_sn";
|
||||
$params[':f_sn'] = $f_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`platid` = :platid";
|
||||
$params[':platid'] = $platid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`uniacid` = :uniacid";
|
||||
$params[':uniacid'] = $uniacid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`shopid` = :shopid";
|
||||
$params[':shopid'] = $shopid;
|
||||
|
||||
$o_sn = fmFunc_pdo_yii_fetchcolumn($connection, $tableName, $column, $condition, $params);
|
||||
if (!$o_sn) {
|
||||
$initdata = $dbmodel->data_format($data, $suffix);
|
||||
$initdata['title'] = $o_sn_title;
|
||||
$initdata['value'] = '';
|
||||
$initdata['createtime'] = $_FM['timestamp'];
|
||||
$initdata['updatetime'] = $_FM['timestamp'];
|
||||
$initdata['deleted'] = 0;
|
||||
$initdata['status'] = 1;
|
||||
$initdata['sn'] = getMillisecond() * 10;
|
||||
$initdata['sn'] = intval($initdata['sn']);
|
||||
$initdata['s_sn'] = $s_sn;
|
||||
$initdata['f_sn'] = $f_sn;
|
||||
|
||||
fmFunc_pdo_yii_insert($connection, $tableName, $initdata);
|
||||
$o_sn = $initdata['sn'];
|
||||
}
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
$op = isset($dataGet['op']) ? $dataGet['op'] : 'index';
|
||||
$op = in_array($op, array('index', 'deleted', 'unused')) ? $op : 'index';
|
||||
|
||||
$setfor = isset($dataGet['setfor']) ? $dataGet['setfor'] : 'index';
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
//OK
|
||||
//TBD uniacid的更复杂逻辑处理,以便平台模式切换
|
||||
|
||||
$op = isset($dataGet['op']) ? $dataGet['op'] : 'null';
|
||||
|
||||
$ac = isset($dataGet['ac']) ? $dataGet['ac'] : 'null';
|
||||
|
||||
$siteId = isset($_FM['apiCert']['siteId']) ? $_FM['apiCert']['siteId'] : 0;
|
||||
|
||||
$platid = (isset($dataGet['platid']) && intval($dataGet['platid']) > 0) ? intval($dataGet['platid']) : 0;
|
||||
//TBD 进一步校验platid是否合法
|
||||
$platid = (isset($_FM['platid'])) ? $_FM['platid'] : $platid;
|
||||
|
||||
$uniacid = (isset($dataGet['uniacid']) && intval($dataGet['uniacid']) > 0) ? intval($dataGet['uniacid']) : 0;
|
||||
//TBD 进一步校验uniacid是否合法
|
||||
$uniacid = (isset($_FM['uniacid'])) ? $_FM['uniacid'] : $uniacid;
|
||||
|
||||
$shopid = (isset($dataGet['shopid']) && intval($dataGet['shopid']) > 0) ? intval($dataGet['shopid']) : 0;
|
||||
//TBD 进一步校验shopid是否合法
|
||||
$shopid = (isset($_FM['shopid'])) ? $_FM['shopid'] : $shopid;
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
global $START_TIME;
|
||||
$START_TIME = getMillisecond();
|
||||
//加载变量设置
|
||||
global $_FM;
|
||||
|
||||
//记录请求日志-20170629
|
||||
$dologs = new common\components\DoLogs;
|
||||
$dologs->record();
|
||||
|
||||
//授权服务器通讯检查,排除前台登陆演示'我的接口'时的判断
|
||||
$errorCode = 0;
|
||||
|
||||
if (substr($_GET['r'], -6) != '/index') {
|
||||
$errorCode = fmFunc_cert_checkAuth();
|
||||
}
|
||||
|
||||
if ($errorCode != 0) {
|
||||
die (json_encode(array('errorcode' => $errorCode, 'msg' => Yii::t('errorcode', $errorCode))));
|
||||
}
|
||||
|
||||
//未登陆不返回数据!
|
||||
if (!isset($_FM['user']['name'])) {
|
||||
$errorCode = 45300201;
|
||||
die (json_encode(array('errorcode' => $errorCode, 'msg' => Yii::t('errorcode', $errorCode))));
|
||||
} else if (Yii::$app->user->isGuest) {
|
||||
$errorCode = 45300201;
|
||||
die (json_encode(array('errorcode' => $errorCode, 'msg' => Yii::t('errorcode', $errorCode))));
|
||||
}
|
||||
|
||||
//补充添加平台号关联
|
||||
$_FM['platid'] = isset($_GET['platid']) ? intval($_GET['platid']) : 0;
|
||||
if (isset($_FM['apiCert']['platid'])) {
|
||||
$_FM['platid'] = $_FM['apiCert']['platid'];
|
||||
}
|
||||
$_FM['uniacid'] = isset($_GET['uniacid']) ? intval($_GET['uniacid']) : 0;
|
||||
if (isset($_FM['apiCert']['uniacid'])) {
|
||||
$_FM['uniacid'] = $_FM['apiCert']['uniacid'];
|
||||
}
|
||||
$_FM['shopid'] = isset($_GET['shopid']) ? intval($_GET['shopid']) : 0;
|
||||
if (isset($_FM['apiCert']['shopid'])) {
|
||||
$_FM['shopid'] = $_FM['apiCert']['shopid'];
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
global $START_TIME;
|
||||
$START_TIME = getMillisecond();
|
||||
//加载变量设置
|
||||
global $_FM;
|
||||
|
||||
//记录请求日志-20170629
|
||||
$dologs = new common\components\DoLogs;
|
||||
$dologs->record();
|
||||
|
||||
//授权服务器通讯检查,排除前台登陆演示我的接口时的判断
|
||||
$errorCode = 0;
|
||||
|
||||
//未登陆不返回数据!
|
||||
// if(!isset($_FM['user']['name']))
|
||||
// {
|
||||
// $errorCode = 45300201;
|
||||
// die (json_encode(array('errorcode'=>$errorCode,'msg'=>Yii::t('errorcode',$errorCode))));
|
||||
// }elseif (Yii::$app->user->isGuest)
|
||||
// {
|
||||
// $errorCode = 45300201;
|
||||
// die (json_encode(array('errorcode'=>$errorCode,'msg'=>Yii::t('errorcode',$errorCode))));
|
||||
// }
|
||||
|
||||
//补充添加平台号关联
|
||||
$_FM['platid'] = isset($_GET['platid']) ? intval($_GET['platid']) : 0;
|
||||
if (isset($_FM['apiCert']['platid'])) {
|
||||
$_FM['platid'] = $_FM['apiCert']['platid'];
|
||||
}
|
||||
$_FM['uniacid'] = isset($_GET['uniacid']) ? intval($_GET['uniacid']) : 0;
|
||||
if (isset($_FM['apiCert']['uniacid'])) {
|
||||
$_FM['uniacid'] = $_FM['apiCert']['uniacid'];
|
||||
}
|
||||
$_FM['shopid'] = isset($_GET['shopid']) ? intval($_GET['shopid']) : 0;
|
||||
if (isset($_FM['apiCert']['shopid'])) {
|
||||
$_FM['shopid'] = $_FM['apiCert']['shopid'];
|
||||
}
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
//OK
|
||||
//取self表sn,SELF对应到客户端站点系统级——每个站点均支持多个主模型存在
|
||||
$suffix = 'self';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$column = "sn";
|
||||
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
|
||||
$s_sn = fmFunc_pdo_yii_fetchcolumn($connection, $tableName, $column, $condition, $params);
|
||||
if (!$s_sn) {
|
||||
$initdata = $dbmodel->data_format($data['addons'], $suffix);
|
||||
$initdata['title'] = isset($initdata['title']) ? $initdata['title'] : $s_sn_title;
|
||||
$initdata['keywords'] = isset($initdata['keywords']) ? $initdata['keywords'] : '';
|
||||
$initdata['createtime'] = $_FM['timestamp'];
|
||||
$initdata['updatetime'] = $_FM['timestamp'];
|
||||
$initdata['deleted'] = 0;
|
||||
$initdata['status'] = 1;
|
||||
$initdata['sn'] = getMillisecond() * 10;
|
||||
$initdata['sn'] = intval($initdata['sn']);
|
||||
|
||||
fmFunc_pdo_yii_insert($connection, $tableName, $initdata);
|
||||
$s_sn = $initdata['sn'];
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
//OK
|
||||
//设置addon表数据
|
||||
$suffix = 'addon';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$partnerid = isset($data['partnerid']) ? $data['partnerid'] : 0;
|
||||
$mid = isset($data['mid']) ? $data['mid'] : 0;
|
||||
$fid = isset($data['fid']) ? $data['fid'] : 0;
|
||||
$settingData = $dbmodel->data_format($data['addons'], $suffix);
|
||||
|
||||
$column = "id";
|
||||
|
||||
$condition .= "`o_sn` = :o_sn";
|
||||
$params[':o_sn'] = $o_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`f_sn` = :f_sn";
|
||||
$params[':f_sn'] = $f_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`platid` = :platid";
|
||||
$params[':platid'] = $platid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`uniacid` = :uniacid";
|
||||
$params[':uniacid'] = $uniacid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`shopid` = :shopid";
|
||||
$params[':shopid'] = $shopid;
|
||||
|
||||
$i = 0;
|
||||
$temp = array();
|
||||
$temp['keys'] = array();
|
||||
$temp['titles'] = array();
|
||||
$temp_condition = $condition;
|
||||
foreach ($settingData as $v_k => $value) {
|
||||
$i++;
|
||||
$record = array();
|
||||
$_temp_condition = '';
|
||||
$condition = '';
|
||||
$condition .= " AND ";
|
||||
$condition .= "`setfor` = :setfor";
|
||||
$params[':setfor'] = $value['setfor'];
|
||||
if (!isset($temp['keys'][$value['setfor']])) {
|
||||
$temp['keys'][$value['setfor']] = [];
|
||||
}
|
||||
if (!isset($temp['titles'][$value['setfor']])) {
|
||||
$temp['titles'][$value['setfor']] = [];
|
||||
}
|
||||
//170702补充——增强修复参数title键为数字时的保存命令
|
||||
|
||||
if (is_numeric($value['title'])) {
|
||||
$_temp_titles = $temp['titles'][$value['setfor']];
|
||||
if (count($_temp_titles) == 0) {
|
||||
$record['deleted'] = 1;
|
||||
$record['updatetime'] = $_FM['timestamp'];
|
||||
$_temp_condition = $temp_condition . $condition;
|
||||
unset($params[':key']);
|
||||
$result = fmFunc_pdo_yii_update($connection, $tableName, $record, $_temp_condition, $params);
|
||||
}
|
||||
array_push($temp['titles'][$value['setfor']], $value['title']);
|
||||
}
|
||||
|
||||
$condition .= " AND ";
|
||||
$condition .= "`title` = :title";
|
||||
$params[':title'] = $value['title'];
|
||||
|
||||
if (!isset($temp['keys'][$value['setfor']][$value['title']])) {
|
||||
$temp['keys'][$value['setfor']][$value['title']] = [];
|
||||
}
|
||||
//170419补充——针对参数key键为数字的情况(判定其父级数组需完全被该次所传入之的参数数组替代),因为要删除掉无关键(设置deleted为1)
|
||||
//170501补充——增强修复参数key键为数字时的保存命令
|
||||
|
||||
if (is_numeric($value['key'])) {
|
||||
$_temp_keys = $temp['keys'][$value['setfor']][$value['title']];
|
||||
if (count($_temp_keys) == 0) {
|
||||
$record['deleted'] = 1;
|
||||
$record['updatetime'] = $_FM['timestamp'];
|
||||
$_temp_condition = $temp_condition . $condition;
|
||||
unset($params[':key']);
|
||||
$result = fmFunc_pdo_yii_update($connection, $tableName, $record, $_temp_condition, $params);
|
||||
}
|
||||
array_push($temp['keys'][$value['setfor']][$value['title']], $value['key']);
|
||||
}
|
||||
|
||||
$condition .= " AND ";
|
||||
$condition .= "`key` = :key";
|
||||
$params[':key'] = $value['key'];
|
||||
$condition = $temp_condition . $condition;
|
||||
|
||||
$id = fmFunc_pdo_yii_fetchcolumn($connection, $tableName, $column, $condition, $params);
|
||||
$record['value'] = $value['value'];
|
||||
//170722 补充-value键值超过mysql的text最大长度65535时,改为使用文件存储的方式
|
||||
if (isset($value['value']{65535})) {
|
||||
$filename = $siteId . '/' . $uniacid . '/' . $platid . '_' . $shopid . '_' . $o_sn . '_' . $f_sn . '_' . $s_sn . '_' . $suffix . '_' . $value['setfor'] . '_' . $value['title'] . '_' . $value['key'];
|
||||
fmFunc_file_dataWrite($filename, $value['value'], $uri = NULL, $origin_cache_key = NULL);
|
||||
$record['value'] = $filename . '.php';
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$record['deleted'] = 0;
|
||||
$record['updatetime'] = $_FM['timestamp'];
|
||||
fmFunc_pdo_yii_update($connection, $tableName, $record, $condition, $params);
|
||||
} else {
|
||||
$record['setfor'] = $value['setfor'];
|
||||
$record['title'] = $value['title'];
|
||||
$record['key'] = $value['key'];
|
||||
$record['o_sn'] = $o_sn;
|
||||
$record['f_sn'] = $f_sn;
|
||||
$record['s_sn'] = $s_sn;
|
||||
$record['sn'] = getMillisecond() * 10;
|
||||
$record['sn'] = intval($record['sn']);
|
||||
$record['siteid'] = $siteId;
|
||||
$record['platid'] = $platid;
|
||||
$record['uniacid'] = $uniacid;
|
||||
$record['shopid'] = $shopid;
|
||||
$record['partnerid'] = $partnerid;
|
||||
$record['mid'] = $mid;
|
||||
$record['fid'] = $fid;
|
||||
$record['displayorder'] = isset($data['displayorder']) ? $data['displayorder'] : 0;
|
||||
$record['status'] = isset($data['status']) ? $data['status'] : 1;
|
||||
$record['statuscode'] = isset($data['statuscode']) ? $data['statuscode'] : 64;
|
||||
$record['deleted'] = 0;
|
||||
$record['createtime'] = $_FM['timestamp'];
|
||||
$record['updatetime'] = $_FM['timestamp'];
|
||||
|
||||
fmFunc_pdo_yii_insert($connection, $tableName, $record);
|
||||
}
|
||||
}
|
||||
Executable
+135
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
//OK
|
||||
//设置data表数据
|
||||
$suffix = 'data';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$partnerid = isset($data['partnerid']) ? $data['partnerid'] : 0;
|
||||
$mid = isset($data['mid']) ? $data['mid'] : 0;
|
||||
$fid = isset($data['fid']) ? $data['fid'] : 0;
|
||||
$settingData = $dbmodel->data_format($data['addons'], $suffix);
|
||||
|
||||
$column = "id";
|
||||
|
||||
$condition .= "`o_sn` = :o_sn";
|
||||
$params[':o_sn'] = $o_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`f_sn` = :f_sn";
|
||||
$params[':f_sn'] = $f_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`platid` = :platid";
|
||||
$params[':platid'] = $platid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`uniacid` = :uniacid";
|
||||
$params[':uniacid'] = $uniacid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`shopid` = :shopid";
|
||||
$params[':shopid'] = $shopid;
|
||||
|
||||
$i = 0;
|
||||
$temp = array();
|
||||
$temp['keys'] = array();
|
||||
$temp['titles'] = array();
|
||||
$temp_condition = $condition;
|
||||
foreach ($settingData as $v_k => $value) {
|
||||
$i++;
|
||||
$record = array();
|
||||
$_temp_condition = '';
|
||||
$condition = '';
|
||||
$condition .= " AND ";
|
||||
$condition .= "`setfor` = :setfor";
|
||||
$params[':setfor'] = $value['setfor'];
|
||||
if (!isset($temp['keys'][$value['setfor']])) {
|
||||
$temp['keys'][$value['setfor']] = [];
|
||||
}
|
||||
if (!isset($temp['titles'][$value['setfor']])) {
|
||||
$temp['titles'][$value['setfor']] = [];
|
||||
}
|
||||
//170702补充——增强修复参数title键为数字时的保存命令
|
||||
|
||||
if (is_numeric($value['title'])) {
|
||||
$_temp_titles = $temp['titles'][$value['setfor']];
|
||||
if (count($_temp_titles) == 0) {
|
||||
$record['deleted'] = 1;
|
||||
$record['updatetime'] = $_FM['timestamp'];
|
||||
$_temp_condition = $temp_condition . $condition;
|
||||
unset($params[':key']);
|
||||
$result = fmFunc_pdo_yii_update($connection, $tableName, $record, $_temp_condition, $params);
|
||||
}
|
||||
array_push($temp['titles'][$value['setfor']], $value['title']);
|
||||
}
|
||||
|
||||
$condition .= " AND ";
|
||||
$condition .= "`title` = :title";
|
||||
$params[':title'] = $value['title'];
|
||||
|
||||
if (!isset($temp['keys'][$value['setfor']][$value['title']])) {
|
||||
$temp['keys'][$value['setfor']][$value['title']] = [];
|
||||
}
|
||||
//170419补充——针对参数key键为数字的情况(判定其父级数组需完全被该次所传入之的参数数组替代),因为要删除掉无关键(设置deleted为1)
|
||||
//170501补充——增强修复参数key键为数字时的保存命令
|
||||
|
||||
if (is_numeric($value['key'])) {
|
||||
$_temp_keys = $temp['keys'][$value['setfor']][$value['title']];
|
||||
if (count($_temp_keys) == 0) {
|
||||
$record['deleted'] = 1;
|
||||
$record['updatetime'] = $_FM['timestamp'];
|
||||
$_temp_condition = $temp_condition . $condition;
|
||||
unset($params[':key']);
|
||||
$result = fmFunc_pdo_yii_update($connection, $tableName, $record, $_temp_condition, $params);
|
||||
}
|
||||
array_push($temp['keys'][$value['setfor']][$value['title']], $value['key']);
|
||||
}
|
||||
|
||||
$condition .= " AND ";
|
||||
$condition .= "`key` = :key";
|
||||
$params[':key'] = $value['key'];
|
||||
$condition = $temp_condition . $condition;
|
||||
|
||||
$id = fmFunc_pdo_yii_fetchcolumn($connection, $tableName, $column, $condition, $params);
|
||||
$record['value'] = $value['value'];
|
||||
//170722 补充-value键值超过mysql的text最大长度65535时,改为使用文件存储的方式
|
||||
if (isset($value['value']{65535})) {
|
||||
$filename = $siteId . '/' . $uniacid . '/' . $platid . '_' . $shopid . '_' . $o_sn . '_' . $f_sn . '_' . $s_sn . '_' . $suffix . '_' . $value['setfor'] . '_' . $value['title'] . '_' . $value['key'];
|
||||
fmFunc_file_dataWrite($filename, $value['value'], $uri = NULL, $origin_cache_key = NULL);
|
||||
$record['value'] = $filename . '.php';
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$record['deleted'] = 0;
|
||||
$record['updatetime'] = $_FM['timestamp'];
|
||||
fmFunc_pdo_yii_update($connection, $tableName, $record, $condition, $params);
|
||||
} else {
|
||||
$record['setfor'] = $value['setfor'];
|
||||
$record['title'] = $value['title'];
|
||||
$record['key'] = $value['key'];
|
||||
$record['o_sn'] = $o_sn;
|
||||
$record['f_sn'] = $f_sn;
|
||||
$record['s_sn'] = $s_sn;
|
||||
$record['sn'] = getMillisecond() * 10;
|
||||
$record['sn'] = intval($record['sn']);
|
||||
$record['siteid'] = $siteId;
|
||||
$record['platid'] = $platid;
|
||||
$record['uniacid'] = $uniacid;
|
||||
$record['shopid'] = $shopid;
|
||||
$record['partnerid'] = $partnerid;
|
||||
$record['mid'] = $mid;
|
||||
$record['fid'] = $fid;
|
||||
$record['displayorder'] = isset($data['displayorder']) ? $data['displayorder'] : 0;
|
||||
$record['status'] = isset($data['status']) ? $data['status'] : 1;
|
||||
$record['statuscode'] = isset($data['statuscode']) ? $data['statuscode'] : 64;
|
||||
$record['deleted'] = 0;
|
||||
$record['createtime'] = $_FM['timestamp'];
|
||||
$record['updatetime'] = $_FM['timestamp'];
|
||||
|
||||
fmFunc_pdo_yii_insert($connection, $tableName, $record);
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
//OK
|
||||
//设置param表数据
|
||||
$suffix = 'param';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$partnerid = isset($data['partnerid']) ? $data['partnerid'] : 0;
|
||||
$settingData = $dbmodel->data_format($data['addons'], $suffix);
|
||||
|
||||
$column = "id";
|
||||
|
||||
$condition .= "`f_sn` = :f_sn";
|
||||
$params[':f_sn'] = $f_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`platid` = :platid";
|
||||
$params[':platid'] = $platid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`uniacid` = :uniacid";
|
||||
$params[':uniacid'] = $uniacid;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`shopid` = :shopid";
|
||||
$params[':shopid'] = $shopid;
|
||||
|
||||
$i = 0;
|
||||
$temp = array();
|
||||
$temp['keys'] = array();
|
||||
$temp['titles'] = array();
|
||||
$temp_condition = $condition;
|
||||
foreach ($settingData as $v_k => $value) {
|
||||
$i++;
|
||||
$record = array();
|
||||
$_temp_condition = '';
|
||||
$condition = '';
|
||||
$condition .= " AND ";
|
||||
$condition .= "`setfor` = :setfor";
|
||||
$params[':setfor'] = $value['setfor'];
|
||||
if (!isset($temp['keys'][$value['setfor']])) {
|
||||
$temp['keys'][$value['setfor']] = [];
|
||||
}
|
||||
if (!isset($temp['titles'][$value['setfor']])) {
|
||||
$temp['titles'][$value['setfor']] = [];
|
||||
}
|
||||
//170702补充——增强修复参数title键为数字时的保存命令
|
||||
|
||||
if (is_numeric($value['title'])) {
|
||||
$_temp_titles = $temp['titles'][$value['setfor']];
|
||||
if (count($_temp_titles) == 0) {
|
||||
$record['deleted'] = 1;
|
||||
$record['updatetime'] = $_FM['timestamp'];
|
||||
$_temp_condition = $temp_condition . $condition;
|
||||
unset($params[':key']);
|
||||
$result = fmFunc_pdo_yii_update($connection, $tableName, $record, $_temp_condition, $params);
|
||||
}
|
||||
array_push($temp['titles'][$value['setfor']], $value['title']);
|
||||
}
|
||||
|
||||
$condition .= " AND ";
|
||||
$condition .= "`title` = :title";
|
||||
$params[':title'] = $value['title'];
|
||||
|
||||
if (!isset($temp['keys'][$value['setfor']][$value['title']])) {
|
||||
$temp['keys'][$value['setfor']][$value['title']] = [];
|
||||
}
|
||||
//170419补充——针对参数key键为数字的情况(判定其父级数组需完全被该次所传入之的参数数组替代),因为要删除掉无关键(设置deleted为1)
|
||||
//170501补充——增强修复参数key键为数字时的保存命令
|
||||
|
||||
if (is_numeric($value['key'])) {
|
||||
$_temp_keys = $temp['keys'][$value['setfor']][$value['title']];
|
||||
if (count($_temp_keys) == 0) {
|
||||
$record['deleted'] = 1;
|
||||
$record['updatetime'] = $_FM['timestamp'];
|
||||
$_temp_condition = $temp_condition . $condition;
|
||||
unset($params[':key']);
|
||||
$result = fmFunc_pdo_yii_update($connection, $tableName, $record, $_temp_condition, $params);
|
||||
}
|
||||
array_push($temp['keys'][$value['setfor']][$value['title']], $value['key']);
|
||||
}
|
||||
|
||||
$condition .= " AND ";
|
||||
$condition .= "`key` = :key";
|
||||
$params[':key'] = $value['key'];
|
||||
$condition = $temp_condition . $condition;
|
||||
|
||||
$id = fmFunc_pdo_yii_fetchcolumn($connection, $tableName, $column, $condition, $params);
|
||||
$record['value'] = $value['value'];
|
||||
//170722 补充-value键值超过mysql的text最大长度65535时,改为使用文件存储的方式
|
||||
if (isset($value['value']{65535})) {
|
||||
$filename = $siteId . '/' . $uniacid . '/' . $platid . '_' . $shopid . '_' . $f_sn . '_' . $s_sn . '_' . $suffix . '_' . $value['setfor'] . '_' . $value['title'] . '_' . $value['key'];
|
||||
fmFunc_file_dataWrite($filename, $value['value'], $uri = NULL, $origin_cache_key = NULL);
|
||||
$record['value'] = $filename . '.php';
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$record['deleted'] = 0;
|
||||
$record['updatetime'] = $_FM['timestamp'];
|
||||
fmFunc_pdo_yii_update($connection, $tableName, $record, $condition, $params);
|
||||
} else {
|
||||
$record['setfor'] = $value['setfor'];
|
||||
$record['title'] = $value['title'];
|
||||
$record['key'] = $value['key'];
|
||||
$record['f_sn'] = $f_sn;
|
||||
$record['s_sn'] = $s_sn;
|
||||
$record['sn'] = getMillisecond() * 10;
|
||||
$record['sn'] = intval($record['sn']);
|
||||
$record['siteid'] = $siteId;
|
||||
$record['platid'] = $platid;
|
||||
$record['uniacid'] = $uniacid;
|
||||
$record['shopid'] = $shopid;
|
||||
$record['partnerid'] = $partnerid;
|
||||
$record['displayorder'] = isset($data['displayorder']) ? $data['displayorder'] : 0;
|
||||
$record['status'] = isset($data['status']) ? $data['status'] : 1;
|
||||
$record['statuscode'] = isset($data['statuscode']) ? $data['statuscode'] : 64;
|
||||
$record['deleted'] = 0;
|
||||
$record['createtime'] = $_FM['timestamp'];
|
||||
$record['updatetime'] = $_FM['timestamp'];
|
||||
|
||||
fmFunc_pdo_yii_insert($connection, $tableName, $record);
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
//OK
|
||||
//更新form表
|
||||
$suffix = 'form';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$columns = array('title', 'value', 'displayorder', 'status', 'deleted');
|
||||
|
||||
$condition .= "`sn` = :sn";
|
||||
$params[':sn'] = $f_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
|
||||
$initdata = $dbmodel->data_format($data['addons'], $suffix);
|
||||
$updateData = array();
|
||||
foreach ($columns as $col) {
|
||||
if (isset($initdata[$col])) {
|
||||
$updateData[$col] = $initdata[$col];
|
||||
} else if (isset($data[$col])) {
|
||||
$updateData[$col] = $data[$col];
|
||||
}
|
||||
}
|
||||
|
||||
//根据传参op进行数据微调
|
||||
switch ($op) {
|
||||
case 'param':
|
||||
//指定为param操作时,不对form表进行写操作
|
||||
$unset = ['title', 'keywords', 'displayorder', 'status', 'deleted'];
|
||||
$updateData = array();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($updateData)) {
|
||||
$updateData['updatetime'] = $_FM['timestamp'];
|
||||
$result = fmFunc_pdo_yii_update($connection, $tableName, $updateData, $condition, $params);
|
||||
} else {
|
||||
$result = FALSE;
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
//更新order表
|
||||
$suffix = 'order';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$columns = array('title', 'value', 'displayorder', 'status', 'deleted');
|
||||
|
||||
$condition .= "`sn` = :sn";
|
||||
$params[':sn'] = $o_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`f_sn` = :f_sn";
|
||||
$params[':f_sn'] = $f_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`s_sn` = :s_sn";
|
||||
$params[':s_sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
|
||||
$initdata = $dbmodel->data_format($data['addons'], $suffix);
|
||||
$updateData = array();
|
||||
foreach ($columns as $col) {
|
||||
if (isset($initdata[$col])) {
|
||||
$updateData[$col] = $initdata[$col];
|
||||
} else if (isset($data[$col])) {
|
||||
$updateData[$col] = $data[$col];
|
||||
}
|
||||
}
|
||||
|
||||
//根据传参op进行数据微调
|
||||
switch ($op) {
|
||||
case 'param':
|
||||
//指定为param操作时,不对order表进行写操作
|
||||
$unset = ['title', 'keywords', 'displayorder', 'status', 'deleted'];
|
||||
$updateData = array();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($updateData)) {
|
||||
$updateData['updatetime'] = $_FM['timestamp'];
|
||||
$result = fmFunc_pdo_yii_update($connection, $tableName, $updateData, $condition, $params);
|
||||
} else {
|
||||
$result = FALSE;
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
//OK
|
||||
//更新self表
|
||||
$suffix = 'self';
|
||||
$tableName = $tablePre . '_' . $table . '_' . $suffix;
|
||||
$condition = "";
|
||||
$params = array();
|
||||
|
||||
$columns = array('title', 'keywords', 'displayorder', 'status', 'deleted');
|
||||
|
||||
$condition .= "`sn` = :sn";
|
||||
$params[':sn'] = $s_sn;
|
||||
$condition .= " AND ";
|
||||
$condition .= "`siteid` = :siteid";
|
||||
$params[':siteid'] = $siteId;
|
||||
|
||||
$initdata = $dbmodel->data_format($data['addons'], $suffix);
|
||||
$updateData = array();
|
||||
foreach ($columns as $col) {
|
||||
if (isset($initdata[$col])) {
|
||||
$updateData[$col] = $initdata[$col];
|
||||
} else if (isset($data[$col])) {
|
||||
$updateData[$col] = $data[$col];
|
||||
}
|
||||
}
|
||||
|
||||
//根据传参op进行数据微调
|
||||
switch ($op) {
|
||||
case 'param':
|
||||
//指定为param操作时,不对self表进行写操作
|
||||
$unset = ['title', 'keywords', 'displayorder', 'status', 'deleted'];
|
||||
$updateData = array();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($updateData)) {
|
||||
$updateData['updatetime'] = $_FM['timestamp'];
|
||||
$result = fmFunc_pdo_yii_update($connection, $tableName, $updateData, $condition, $params);
|
||||
} else {
|
||||
$result = FALSE;
|
||||
}
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
api账号
|
||||
账号:publicapi
|
||||
密码:api.hiluker
|
||||
|
||||
——————————————————————————
|
||||
admin超级账号
|
||||
账号: fm453
|
||||
密码: Lukegzs168.com
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>恭喜,站点创建成功!</title>
|
||||
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css">
|
||||
<script src="//cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
|
||||
<script src="//cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container" style="margin-top:9%;">
|
||||
<div class="jumbotron">
|
||||
<div class="panel panel-success">
|
||||
<div class="panel-heading"><h1>恭喜, 站点创建成功!</h1></div>
|
||||
</div>
|
||||
<p>
|
||||
<h3>站点创建成功,本页面由系统自动生成。</h3></p>
|
||||
<p>
|
||||
<li>本页面在FTP根目录下的index.html</li>
|
||||
</p>
|
||||
<p>
|
||||
<li>您可以删除或覆盖本页面</li>
|
||||
</p>
|
||||
<p>
|
||||
<li>FTP相关信息,请到宝塔后台查看</li>
|
||||
</p>
|
||||
<p>
|
||||
<li>我们为您提供了完善的数据备份功能,请到后台进行相关设置</li>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
|
||||
/**
|
||||
* ContactForm is the model behind the contact form.
|
||||
*/
|
||||
class ContactForm extends Model
|
||||
{
|
||||
public $name;
|
||||
public $email;
|
||||
public $subject;
|
||||
public $body;
|
||||
public $verifyCode;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
// name, email, subject and body are required
|
||||
[['name', 'email', 'subject', 'body'], 'required'],
|
||||
// email has to be a valid email address
|
||||
['email', 'email'],
|
||||
// verifyCode needs to be entered correctly
|
||||
['verifyCode', 'captcha'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'verifyCode' => Yii::t('frontend', 'Verify Code'),
|
||||
'name' => Yii::t('frontend', 'Name'),
|
||||
'email' => Yii::t('frontend', 'Email'),
|
||||
'subject' => Yii::t('frontend', 'Subject'),
|
||||
'body' => Yii::t('frontend', 'Body'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an email to the specified email address using the information collected by this model.
|
||||
*
|
||||
* @param string $email the target email address
|
||||
* @return bool whether the email was sent
|
||||
*/
|
||||
public function sendEmail($email)
|
||||
{
|
||||
return Yii::$app->mailer->compose()
|
||||
->setTo($email)
|
||||
->setFrom(Yii::$app->params['noticeEmail'])
|
||||
->setSubject($this->subject)
|
||||
->setTextBody($this->body)
|
||||
->send();
|
||||
}
|
||||
}
|
||||
Executable
+134
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2021-09-09 22:18:46
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2021-09-09 23:01:13
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use common\models\User;
|
||||
use common\models\CLog;
|
||||
|
||||
/**
|
||||
* Login form
|
||||
*/
|
||||
class LoginForm extends Model
|
||||
{
|
||||
public $username;
|
||||
public $password;
|
||||
public $rememberMe = TRUE;
|
||||
|
||||
private $_user;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
// username and password are both required
|
||||
[['username', 'password'], 'required'],
|
||||
// rememberMe must be a boolean value
|
||||
['rememberMe', 'boolean'],
|
||||
// password is validated by validatePassword()
|
||||
['password', 'validatePassword'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'username' => Yii::t('common', 'Username'),
|
||||
'password' => Yii::t('common', 'Password'),
|
||||
'rememberMe' => Yii::t('common', 'Remember Me'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the password.
|
||||
* This method serves as the inline validation for password.
|
||||
*
|
||||
* @param string $attribute the attribute currently being validated
|
||||
* @param array $params the additional name-value pairs given in the rule
|
||||
*/
|
||||
public function validatePassword($attribute, $params)
|
||||
{
|
||||
if (!$this->hasErrors()) {
|
||||
$user = $this->getUser();
|
||||
if (!$user || !$user->validatePassword($this->password)) {
|
||||
$this->addError($attribute, Yii::t('common', 'Incorrect username or password.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs in a user using the provided username and password.
|
||||
*
|
||||
* @return bool whether the user is logged in successfully
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
if ($this->validate()) {
|
||||
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
|
||||
}
|
||||
|
||||
return FALSE; //如果为true 将允许任意密码登陆
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds user by [[username]]
|
||||
*
|
||||
* @return User|null
|
||||
*/
|
||||
protected function getUser()
|
||||
{
|
||||
if ($this->_user === NULL) {
|
||||
$this->_user = User::findByUsername($this->username); //千万注意后端的登陆使用的是Adminer模型,不是User
|
||||
}
|
||||
|
||||
return $this->_user;
|
||||
}
|
||||
|
||||
//登录记录
|
||||
public function loginLog()
|
||||
{
|
||||
$request = Yii::$app->getRequest();
|
||||
$nowFile = $request->getScriptFile();
|
||||
$data = "登陆系统|途径:" . $nowFile;
|
||||
|
||||
$model = new CLog();
|
||||
$model->username = $this->username;
|
||||
$model->ip = Yii::$app->request->userIP;
|
||||
$model->data = $data;
|
||||
$model->create_time = time();
|
||||
$model->save();
|
||||
|
||||
//编制邮件发送通知
|
||||
$message = Yii::$app->mailer->compose();
|
||||
$message->setFrom(Yii::$app->params['noticeEmail']);
|
||||
//给登陆者发送
|
||||
$subject = "账号登陆提醒";
|
||||
$body = "您的账号【" . $this->username . "】刚刚登陆了网站:" . Yii::$app->getRequest()->absoluteUrl;
|
||||
$message->setTo(Yii::$app->user->identity->email)
|
||||
->setSubject($subject)
|
||||
->setTextBody($body)
|
||||
->send();
|
||||
//给管理人员发送
|
||||
$subject = "账号登陆提醒";
|
||||
$body = "API站账号【" . $this->username . "】刚刚登陆了网站:" . Yii::$app->getRequest()->absoluteUrl;
|
||||
$message->setTo('1280880631@qq.com')
|
||||
->setSubject($subject)
|
||||
->setTextBody($body)
|
||||
->send();
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2021-09-10 18:17:47
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2021-09-10 18:19:01
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use common\models\User;
|
||||
|
||||
/**
|
||||
* Password reset request form
|
||||
*/
|
||||
class PasswordResetRequestForm extends Model
|
||||
{
|
||||
public $email;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['email', 'trim'],
|
||||
['email', 'required'],
|
||||
['email', 'email'],
|
||||
['email', 'exist',
|
||||
'targetClass' => '\common\models\User',
|
||||
'filter' => ['status' => User::STATUS_ACTIVE],
|
||||
'message' => 'There is no user with this email address.'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an email with a link, for resetting the password.
|
||||
*
|
||||
* @return bool whether the email was send
|
||||
*/
|
||||
public function sendEmail()
|
||||
{
|
||||
/* @var $user User */
|
||||
$user = User::findOne([
|
||||
'status' => User::STATUS_ACTIVE,
|
||||
'email' => $this->email,
|
||||
]);
|
||||
|
||||
if (!$user) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
|
||||
$user->generatePasswordResetToken();
|
||||
if (!$user->save()) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return Yii::$app
|
||||
->mailer
|
||||
->compose(
|
||||
['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'],
|
||||
['user' => $user]
|
||||
)
|
||||
->setFrom([Yii::$app->params['noticeEmail'] => Yii::$app->name . ' robot'])
|
||||
->setTo($this->email)
|
||||
->setSubject('Password reset for ' . Yii::$app->name)
|
||||
->send();
|
||||
}
|
||||
}
|
||||
Executable
+65
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use yii\base\Model;
|
||||
use yii\base\InvalidParamException;
|
||||
use common\models\User;
|
||||
|
||||
/**
|
||||
* Password reset form
|
||||
*/
|
||||
class ResetPasswordForm extends Model
|
||||
{
|
||||
public $password;
|
||||
|
||||
/**
|
||||
* @var \common\models\User
|
||||
*/
|
||||
private $_user;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a form model given a token.
|
||||
*
|
||||
* @param string $token
|
||||
* @param array $config name-value pairs that will be used to initialize the object properties
|
||||
* @throws \yii\base\InvalidParamException if token is empty or not valid
|
||||
*/
|
||||
public function __construct($token, $config = [])
|
||||
{
|
||||
if (empty($token) || !is_string($token)) {
|
||||
throw new InvalidParamException('Password reset token cannot be blank.');
|
||||
}
|
||||
$this->_user = User::findByPasswordResetToken($token);
|
||||
if (!$this->_user) {
|
||||
throw new InvalidParamException('Wrong password reset token.');
|
||||
}
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['password', 'required'],
|
||||
['password', 'string', 'min' => 6],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets password.
|
||||
*
|
||||
* @return bool if password was reset.
|
||||
*/
|
||||
public function resetPassword()
|
||||
{
|
||||
$user = $this->_user;
|
||||
$user->setPassword($this->password);
|
||||
$user->removePasswordResetToken();
|
||||
|
||||
return $user->save(FALSE);
|
||||
}
|
||||
}
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use common\models\User;
|
||||
|
||||
/**
|
||||
* Signup form
|
||||
*/
|
||||
class SignupForm extends Model
|
||||
{
|
||||
public $username;
|
||||
public $email;
|
||||
public $password;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['username', 'trim'],
|
||||
['username', 'required'],
|
||||
['username', 'unique', 'targetClass' => '\common\models\User', 'message' => '该用户名已经有人注册了.'],
|
||||
['username', 'string', 'min' => 2, 'max' => 255],
|
||||
|
||||
['email', 'trim'],
|
||||
['email', 'required'],
|
||||
['email', 'email'],
|
||||
['email', 'string', 'max' => 255],
|
||||
['email', 'unique', 'targetClass' => '\common\models\User', 'message' => '该邮箱地址已经有人使用了.'],
|
||||
|
||||
['password', 'required'],
|
||||
['password', 'string', 'min' => 6],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'username' => Yii::t('frontend', 'Username'),
|
||||
'password' => Yii::t('frontend', 'Password'),
|
||||
'email' => Yii::t('frontend', 'Email'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Signs user up.
|
||||
*
|
||||
* @return User|null the saved model or null if saving fails
|
||||
*/
|
||||
public function signup()
|
||||
{
|
||||
if (!$this->validate()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$user->username = $this->username;
|
||||
$user->email = $this->email;
|
||||
$user->setPassword($this->password);
|
||||
$user->generateAuthKey();
|
||||
|
||||
return $user->save() ? $user : NULL;
|
||||
}
|
||||
}
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', TRUE);
|
||||
defined('YII_ENV') or define('YII_ENV', 'test');
|
||||
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__ . '/../../');
|
||||
|
||||
require_once(YII_APP_BASE_PATH . '/vendor/autoload.php');
|
||||
require_once(YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php');
|
||||
require_once(YII_APP_BASE_PATH . '/common/config/bootstrap.php');
|
||||
require_once(__DIR__ . '/../config/bootstrap.php');
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
return [
|
||||
[
|
||||
'username' => 'erau',
|
||||
'auth_key' => 'tUu1qHcde0diwUol3xeI-18MuHkkprQI',
|
||||
// password_0
|
||||
'password_hash' => '$2y$13$nJ1WDlBaGcbCdbNC5.5l4.sgy.OMEKCqtDQOdQ2OWpgiKRWYyzzne',
|
||||
'password_reset_token' => 'RkD_Jw0_8HEedzLk7MM-ZKEFfYR7VbMr_1392559490',
|
||||
'created_at' => '1392559490',
|
||||
'updated_at' => '1392559490',
|
||||
'email' => 'sfriesen@jenkins.info',
|
||||
],
|
||||
];
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'username' => 'okirlin',
|
||||
'auth_key' => 'iwTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
|
||||
'password_hash' => '$2y$13$CXT0Rkle1EMJ/c1l5bylL.EylfmQ39O5JlHJVFpNn618OUS1HwaIi',
|
||||
'password_reset_token' => 't5GU9NwpuGYSfb7FEZMAxqtuz2PkEvv_' . time(),
|
||||
'created_at' => '1391885313',
|
||||
'updated_at' => '1391885313',
|
||||
'email' => 'brady.renner@rutherford.com',
|
||||
],
|
||||
[
|
||||
'username' => 'troy.becker',
|
||||
'auth_key' => 'EdKfXrx88weFMV0vIxuTMWKgfK2tS3Lp',
|
||||
'password_hash' => '$2y$13$g5nv41Px7VBqhS3hVsVN2.MKfgT3jFdkXEsMC4rQJLfaMa7VaJqL2',
|
||||
'password_reset_token' => '4BSNyiZNAuxjs5Mty990c47sVrgllIi_' . time(),
|
||||
'created_at' => '1391885313',
|
||||
'updated_at' => '1391885313',
|
||||
'email' => 'nicolas.dianna@hotmail.com',
|
||||
'status' => '0',
|
||||
],
|
||||
];
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
_generated
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void expect($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class FunctionalTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\FunctionalTesterActions;
|
||||
|
||||
|
||||
public function seeValidationError($message)
|
||||
{
|
||||
$this->see($message, '.help-block');
|
||||
}
|
||||
|
||||
public function dontSeeValidationError($message)
|
||||
{
|
||||
$this->dontSee($message, '.help-block');
|
||||
}
|
||||
}
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void expect($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class UnitTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\UnitTesterActions;
|
||||
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class_name: AcceptanceTester
|
||||
modules:
|
||||
enabled:
|
||||
- WebDriver:
|
||||
url: http://localhost:8080
|
||||
browser: firefox
|
||||
- Yii2:
|
||||
part: init
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\acceptance;
|
||||
|
||||
use Yii;
|
||||
use frontend\tests\AcceptanceTester;
|
||||
use yii\helpers\Url;
|
||||
|
||||
class HomeCest
|
||||
{
|
||||
public function checkHome(AcceptanceTester $I)
|
||||
{
|
||||
$I->amOnPage(Url::toRoute('/site/index'));
|
||||
$I->see('My Company');
|
||||
|
||||
$I->seeLink('About');
|
||||
$I->click('About');
|
||||
$I->wait(2); // wait for page to be opened
|
||||
|
||||
$I->see('This is the About page.');
|
||||
}
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Here you can initialize variables via \Codeception\Util\Fixtures class
|
||||
* to store data in global array and use it in Cepts.
|
||||
*
|
||||
* ```php
|
||||
* // Here _bootstrap.php
|
||||
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
|
||||
* ```
|
||||
*
|
||||
* In Cept
|
||||
*
|
||||
* ```php
|
||||
* \Codeception\Util\Fixtures::get('user1');
|
||||
* ```
|
||||
*/
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
class_name: FunctionalTester
|
||||
modules:
|
||||
enabled:
|
||||
- Filesystem
|
||||
- Yii2
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
class AboutCest
|
||||
{
|
||||
public function checkAbout(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/about');
|
||||
$I->see('About', 'h1');
|
||||
}
|
||||
}
|
||||
Executable
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
/* @var $scenario \Codeception\Scenario */
|
||||
class ContactCest
|
||||
{
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnPage(['site/contact']);
|
||||
}
|
||||
|
||||
public function checkContact(FunctionalTester $I)
|
||||
{
|
||||
$I->see('Contact', 'h1');
|
||||
}
|
||||
|
||||
public function checkContactSubmitNoData(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#contact-form', []);
|
||||
$I->see('Contact', 'h1');
|
||||
$I->seeValidationError('Name cannot be blank');
|
||||
$I->seeValidationError('Email cannot be blank');
|
||||
$I->seeValidationError('Subject cannot be blank');
|
||||
$I->seeValidationError('Body cannot be blank');
|
||||
$I->seeValidationError('The verification code is incorrect');
|
||||
}
|
||||
|
||||
public function checkContactSubmitNotCorrectEmail(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#contact-form', [
|
||||
'ContactForm[name]' => 'tester',
|
||||
'ContactForm[email]' => 'tester.email',
|
||||
'ContactForm[subject]' => 'test subject',
|
||||
'ContactForm[body]' => 'test content',
|
||||
'ContactForm[verifyCode]' => 'testme',
|
||||
]);
|
||||
$I->seeValidationError('Email is not a valid email address.');
|
||||
$I->dontSeeValidationError('Name cannot be blank');
|
||||
$I->dontSeeValidationError('Subject cannot be blank');
|
||||
$I->dontSeeValidationError('Body cannot be blank');
|
||||
$I->dontSeeValidationError('The verification code is incorrect');
|
||||
}
|
||||
|
||||
public function checkContactSubmitCorrectData(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#contact-form', [
|
||||
'ContactForm[name]' => 'tester',
|
||||
'ContactForm[email]' => 'tester@example.com',
|
||||
'ContactForm[subject]' => 'test subject',
|
||||
'ContactForm[body]' => 'test content',
|
||||
'ContactForm[verifyCode]' => 'testme',
|
||||
]);
|
||||
$I->seeEmailIsSent();
|
||||
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');
|
||||
}
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
class HomeCest
|
||||
{
|
||||
public function checkOpen(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnPage(\Yii::$app->homeUrl);
|
||||
$I->see('My Company');
|
||||
$I->seeLink('About');
|
||||
$I->click('About');
|
||||
$I->see('This is the About page.');
|
||||
}
|
||||
}
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
use common\fixtures\User as UserFixture;
|
||||
|
||||
class LoginCest
|
||||
{
|
||||
function _before(FunctionalTester $I)
|
||||
{
|
||||
$I->haveFixtures([
|
||||
'user' => [
|
||||
'class' => UserFixture::className(),
|
||||
'dataFile' => codecept_data_dir() . 'login_data.php'
|
||||
]
|
||||
]);
|
||||
$I->amOnRoute('site/login');
|
||||
}
|
||||
|
||||
protected function formParams($login, $password)
|
||||
{
|
||||
return [
|
||||
'LoginForm[username]' => $login,
|
||||
'LoginForm[password]' => $password,
|
||||
];
|
||||
}
|
||||
|
||||
public function checkEmpty(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#login-form', $this->formParams('', ''));
|
||||
$I->seeValidationError('Username cannot be blank.');
|
||||
$I->seeValidationError('Password cannot be blank.');
|
||||
}
|
||||
|
||||
public function checkWrongPassword(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#login-form', $this->formParams('admin', 'wrong'));
|
||||
$I->seeValidationError('Incorrect username or password.');
|
||||
}
|
||||
|
||||
public function checkValidLogin(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#login-form', $this->formParams('erau', 'password_0'));
|
||||
$I->see('Logout (erau)', 'form button[type=submit]');
|
||||
$I->dontSeeLink('Login');
|
||||
$I->dontSeeLink('Signup');
|
||||
}
|
||||
}
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
class SignupCest
|
||||
{
|
||||
protected $formId = '#form-signup';
|
||||
|
||||
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/signup');
|
||||
}
|
||||
|
||||
public function signupWithEmptyFields(FunctionalTester $I)
|
||||
{
|
||||
$I->see('Signup', 'h1');
|
||||
$I->see('Please fill out the following fields to signup:');
|
||||
$I->submitForm($this->formId, []);
|
||||
$I->seeValidationError('Username cannot be blank.');
|
||||
$I->seeValidationError('Email cannot be blank.');
|
||||
$I->seeValidationError('Password cannot be blank.');
|
||||
|
||||
}
|
||||
|
||||
public function signupWithWrongEmail(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm(
|
||||
$this->formId, [
|
||||
'SignupForm[username]' => 'tester',
|
||||
'SignupForm[email]' => 'ttttt',
|
||||
'SignupForm[password]' => 'tester_password',
|
||||
]
|
||||
);
|
||||
$I->dontSee('Username cannot be blank.', '.help-block');
|
||||
$I->dontSee('Password cannot be blank.', '.help-block');
|
||||
$I->see('Email is not a valid email address.', '.help-block');
|
||||
}
|
||||
|
||||
public function signupSuccessfully(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, [
|
||||
'SignupForm[username]' => 'tester',
|
||||
'SignupForm[email]' => 'tester.email@example.com',
|
||||
'SignupForm[password]' => 'tester_password',
|
||||
]);
|
||||
|
||||
$I->seeRecord('common\models\User', [
|
||||
'username' => 'tester',
|
||||
'email' => 'tester.email@example.com',
|
||||
]);
|
||||
|
||||
$I->see('Logout (tester)', 'form button[type=submit]');
|
||||
}
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Here you can initialize variables via \Codeception\Util\Fixtures class
|
||||
* to store data in global array and use it in Cests.
|
||||
*
|
||||
* ```php
|
||||
* // Here _bootstrap.php
|
||||
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
|
||||
* ```
|
||||
*
|
||||
* In Cests
|
||||
*
|
||||
* ```php
|
||||
* \Codeception\Util\Fixtures::get('user1');
|
||||
* ```
|
||||
*/
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
class_name: UnitTester
|
||||
modules:
|
||||
enabled:
|
||||
- Yii2:
|
||||
part: [ orm, email, fixtures ]
|
||||
- Asserts
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Here you can initialize variables via \Codeception\Util\Fixtures class
|
||||
* to store data in global array and use it in Tests.
|
||||
*
|
||||
* ```php
|
||||
* // Here _bootstrap.php
|
||||
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
|
||||
* ```
|
||||
*
|
||||
* In Tests
|
||||
*
|
||||
* ```php
|
||||
* \Codeception\Util\Fixtures::get('user1');
|
||||
* ```
|
||||
*/
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\unit\models;
|
||||
|
||||
use Yii;
|
||||
use frontend\models\ContactForm;
|
||||
|
||||
class ContactFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
public function testSendEmail()
|
||||
{
|
||||
$model = new ContactForm();
|
||||
|
||||
$model->attributes = [
|
||||
'name' => 'Tester',
|
||||
'email' => 'tester@example.com',
|
||||
'subject' => 'very important letter subject',
|
||||
'body' => 'body of current message',
|
||||
];
|
||||
|
||||
expect_that($model->sendEmail('admin@example.com'));
|
||||
|
||||
// using Yii2 module actions to check email was sent
|
||||
$this->tester->seeEmailIsSent();
|
||||
|
||||
$emailMessage = $this->tester->grabLastSentEmail();
|
||||
expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
|
||||
expect($emailMessage->getTo())->hasKey('admin@example.com');
|
||||
expect($emailMessage->getFrom())->hasKey('tester@example.com');
|
||||
expect($emailMessage->getSubject())->equals('very important letter subject');
|
||||
expect($emailMessage->toString())->contains('body of current message');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\unit\models;
|
||||
|
||||
use Yii;
|
||||
use frontend\models\PasswordResetRequestForm;
|
||||
use common\fixtures\User as UserFixture;
|
||||
use common\models\User;
|
||||
|
||||
class PasswordResetRequestFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \frontend\tests\UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
public function _before()
|
||||
{
|
||||
$this->tester->haveFixtures([
|
||||
'user' => [
|
||||
'class' => UserFixture::className(),
|
||||
'dataFile' => codecept_data_dir() . 'user.php'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function testSendMessageWithWrongEmailAddress()
|
||||
{
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = 'not-existing-email@example.com';
|
||||
expect_not($model->sendEmail());
|
||||
}
|
||||
|
||||
public function testNotSendEmailsToInactiveUser()
|
||||
{
|
||||
$user = $this->tester->grabFixture('user', 1);
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = $user['email'];
|
||||
expect_not($model->sendEmail());
|
||||
}
|
||||
|
||||
public function testSendEmailSuccessfully()
|
||||
{
|
||||
$userFixture = $this->tester->grabFixture('user', 0);
|
||||
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = $userFixture['email'];
|
||||
$user = User::findOne(['password_reset_token' => $userFixture['password_reset_token']]);
|
||||
|
||||
expect_that($model->sendEmail());
|
||||
expect_that($user->password_reset_token);
|
||||
|
||||
$emailMessage = $this->tester->grabLastSentEmail();
|
||||
expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
|
||||
expect($emailMessage->getTo())->hasKey($model->email);
|
||||
expect($emailMessage->getFrom())->hasKey(Yii::$app->params['supportEmail']);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\unit\models;
|
||||
|
||||
use common\fixtures\User as UserFixture;
|
||||
use frontend\models\ResetPasswordForm;
|
||||
|
||||
class ResetPasswordFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \frontend\tests\UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
public function _before()
|
||||
{
|
||||
$this->tester->haveFixtures([
|
||||
'user' => [
|
||||
'class' => UserFixture::className(),
|
||||
'dataFile' => codecept_data_dir() . 'user.php'
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testResetWrongToken()
|
||||
{
|
||||
$this->tester->expectException('yii\base\InvalidParamException', function () {
|
||||
new ResetPasswordForm('');
|
||||
});
|
||||
|
||||
$this->tester->expectException('yii\base\InvalidParamException', function () {
|
||||
new ResetPasswordForm('notexistingtoken_1391882543');
|
||||
});
|
||||
}
|
||||
|
||||
public function testResetCorrectToken()
|
||||
{
|
||||
$user = $this->tester->grabFixture('user', 0);
|
||||
$form = new ResetPasswordForm($user['password_reset_token']);
|
||||
expect_that($form->resetPassword());
|
||||
}
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\unit\models;
|
||||
|
||||
use common\fixtures\User as UserFixture;
|
||||
use frontend\models\SignupForm;
|
||||
|
||||
class SignupFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \frontend\tests\UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
public function _before()
|
||||
{
|
||||
$this->tester->haveFixtures([
|
||||
'user' => [
|
||||
'class' => UserFixture::className(),
|
||||
'dataFile' => codecept_data_dir() . 'user.php'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function testCorrectSignup()
|
||||
{
|
||||
$model = new SignupForm([
|
||||
'username' => 'some_username',
|
||||
'email' => 'some_email@example.com',
|
||||
'password' => 'some_password',
|
||||
]);
|
||||
|
||||
$user = $model->signup();
|
||||
|
||||
expect($user)->isInstanceOf('common\models\User');
|
||||
|
||||
expect($user->username)->equals('some_username');
|
||||
expect($user->email)->equals('some_email@example.com');
|
||||
expect($user->validatePassword('some_password'))->true();
|
||||
}
|
||||
|
||||
public function testNotCorrectSignup()
|
||||
{
|
||||
$model = new SignupForm([
|
||||
'username' => 'troy.becker',
|
||||
'email' => 'nicolas.dianna@hotmail.com',
|
||||
'password' => 'some_password',
|
||||
]);
|
||||
|
||||
expect_not($model->signup());
|
||||
expect_that($model->getErrors('username'));
|
||||
expect_that($model->getErrors('email'));
|
||||
|
||||
expect($model->getFirstError('username'))
|
||||
->equals('This username has already been taken.');
|
||||
expect($model->getFirstError('email'))
|
||||
->equals('This email address has already been taken.');
|
||||
}
|
||||
}
|
||||
Executable
+151
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/* @var $this yii\web\View */
|
||||
|
||||
use yii\helpers\Url;
|
||||
|
||||
global $_FM;
|
||||
global $_HI;
|
||||
$username = Yii::$app->user->identity->username;
|
||||
$cert = fmFunc_cert_exist($username);
|
||||
$_FM['apiCert'] = $cert ? $cert : array();
|
||||
$errorCode = 0;
|
||||
|
||||
if ($errorCode > 0) {
|
||||
die (json_encode(array('errorcode' => $errorCode, 'msg' => Yii::t('errorcode', $errorCode))));
|
||||
}
|
||||
|
||||
//错误代码集合
|
||||
$errorcodes = require(Yii::getAlias('@common') . '/messages/zh-CN/errorcode.php');
|
||||
foreach ($errorcodes as $k => $v) {
|
||||
$_k = substr($k, 0, 6);
|
||||
if ($_k !== '453004') {
|
||||
unset($errorcodes[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
$accessKeyId = isset($_FM['apiCert']['aliDySms']['accessKeyId']) ? $_FM['apiCert']['aliDySms']['accessKeyId'] : '';
|
||||
$accessKeySecret = isset($_FM['apiCert']['aliDySms']['accessKeySecret']) ? $_FM['apiCert']['aliDySms']['accessKeySecret'] : '';
|
||||
$sign = isset($_FM['apiCert']['aliDySms']['code']) ? $_FM['apiCert']['aliDySms']['code'] : '';
|
||||
|
||||
$postUrl = Url::to(['alimsg/send', 'appid' => $username]);
|
||||
if (isset($_GET['post']) && $_GET['post'] == 1) {
|
||||
$postUrl = Url::to(['alimsg/send', 'appid' => $username, 'post' => 1]);
|
||||
}
|
||||
?>
|
||||
|
||||
<div class='container' style='margin-top:50px;'>
|
||||
<p>
|
||||
<h3 style="text-align: center;">阿里大鱼短信【转发】接口演示</h3></p>
|
||||
<form class="form-horizontal" action="<?php echo $postUrl; ?>" method="post">
|
||||
<div class="form-group">
|
||||
<label for="inputEmail3" class="col-sm-2 control-label">手机号</label>
|
||||
<div class="col-sm-10">
|
||||
<?php if (isset($_GET['post']) && $_GET['post'] == 1) { ?>
|
||||
<input type="phone" name="phone" class="form-control" id="phone" required="required" value=""
|
||||
placeholder="请输入手机号"/>
|
||||
<?php } else { ?>
|
||||
<textarea type="text" name="phone" class="form-control" id="phone" required="required"
|
||||
placeholder="请输入手机号,多个手机号时用英文(,)分开;"/></textarea>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="accessKeyId" class="col-sm-2 control-label">accessKeyId</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" name="accessKeyId" class="form-control" id="accessKeyId" required="required"
|
||||
value="<?php echo $accessKeyId; ?>" placeholder="输入在阿里云短信获取的accessKeyId"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="accessKeySecret" class="col-sm-2 control-label">accessKeySecret</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" name="accessKeySecret" class="form-control" id="accessKeySecret" required="required"
|
||||
value="<?php echo $accessKeySecret; ?>" placeholder="输入在阿里云短信获取的accessKeySecret"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="sign" class="col-sm-2 control-label">短信签名</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" name="sign" class="form-control" id="sign" required="required"
|
||||
value="<?php echo $sign; ?>" placeholder="填写所申请的短信签名"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="tmpl" class="col-sm-2 control-label">短信模板</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" name="tmpl" class="form-control" id="tmpl" required="required"
|
||||
placeholder="填写所申请的短信模板"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="inputEmail3" class="col-sm-2 control-label">短信内容</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea type="text" name="content" class="form-control" id="content" required="required"
|
||||
placeholder="输入要发送的内容;格式:短信变量码[code],对应的替换内容;(变量及替换值之前用逗号分隔开,每行一组)"/>code1,替换值1<?php echo "\r\n"; ?>
|
||||
code2,替换值2</textarea>
|
||||
<span class="help-block">阿里大鱼”登陆确认验证码“模板(SMS_116695054)的变量为'code'。这里建议您使用该模板,上述文本框中输入 <code>code,1234</code> 即可</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<button type="submit" class="btn btn-success">发送</button>
|
||||
<button type="reset" class="btn btn-danger">重新填写</button>
|
||||
<a class="btn btn-default" href="<?php echo Url::to(['alimsg/index', 'post' => 1]) ?>" target="_self">以POST接口形式测试</a>
|
||||
<a class="btn btn-default" href="<?php echo Url::toRoute('alimsg/index') ?>"
|
||||
target="_self">仅本地演示</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<hr>
|
||||
|
||||
<h1 style="text-align: center;">接口使用简易说明</h1>
|
||||
<span class="form-control">注:本处主要说明本API的基础规则及一些常用的接口使用方法,更多细节可参考我们的实际使用案例(我们基于<a
|
||||
href="http://s.we7.cc/index.php?c=home&a=author&do=index&uid=662" target="_blank">微擎</a>开发的嗨旅行应用、小程序管理模块等。)</span>
|
||||
<p>
|
||||
<ol>
|
||||
<li>
|
||||
<kbd>单发方式</kbd>:支持向一个手机号发送短信,通常用于发送验证码等情景;或向一组手机发送相同短信,通常用于发送通知等情景<br>
|
||||
<code>准备数据:</code>手机号(数组形式)、短信内容(数组形式,键为短信模板中的code,键值为要code对应的替换内容)、阿里大鱼短信账号对应的accessKeyId与accessKeySecret及短信签名sign、所使用的短信模板tmpl、阿里大鱼接口的额外配置项(如果有)、接口连接TOKEN(登陆本接口系统后返回的accesstoken)<br>
|
||||
<code>接口地址:</code> <?php echo Url::to(['alimsg/post'], TRUE); ?>
|
||||
<pre>数据示范————
|
||||
array('phone'=>array('18608981880'),
|
||||
'content'=>array('code'=>'123456'),
|
||||
'config'=>array(
|
||||
'accessKeyId'=>'XXXXXXXXXXXXXXX',
|
||||
'accessKeySecret'=>'XXXXXXXXXXX',
|
||||
'sign'=>'Hiluker'
|
||||
),
|
||||
'option'=>array(),
|
||||
'tmpl'=>'SMS_123456789',
|
||||
'accesstoken'=>'XXXXXXXXXXXXXXX',
|
||||
);
|
||||
</pre>
|
||||
<code>数据返回:</code> JSON字符串,解码后得到结果数组。根据结果数组中的errorcode来表示短信发送是否成功。转接接口有一定的延时,因此我们会做短信发送记录并根据情况进行记录。<br>
|
||||
<pre>
|
||||
$return['errorcode']:结果状态码,正常情况下为0
|
||||
$return['msg']:返回的消息(接口报错时会使用到,消息中会将阿里大鱼接口的返回提示一并显示)
|
||||
$return['data']:用户侧应获得的数据(实际上即是接口请求时POST的数据)
|
||||
$return['timeused']:接口耗时
|
||||
$return['total']:接口调用统计总记录数
|
||||
$return['bytes']:本次返回数据的字节长度统计
|
||||
$return['sms_left']:剩余可用短信条数
|
||||
</pre>
|
||||
<br>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<kbd>群发方式</kbd>:暂不开放<br>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<kbd>错误代码</kbd>:(客户侧可直接将接口站返回的结果打印出来查看,以下仅列出服务侧程序正确运行情况下返回的错误及提示;其他情况可直接打印结果进行查看)<br>
|
||||
<textarea class="form-control"><?php foreach ($errorcodes as $k => $v) {
|
||||
echo '"' . $k . '" : ' . $v . ";\r\n";
|
||||
}
|
||||
?>
|
||||
</textarea>
|
||||
<br>
|
||||
</li>
|
||||
</ol>
|
||||
</p>
|
||||
</div>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user