Commit b763b6a3 authored by rlgy's avatar rlgy

start

parent aa4de274
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Class MinerTableAsset
* @package backend\assets
*/
class MinerTableAsset extends AssetBundle
{
public $sourcePath = '@common/metronic';
public $css = [
];
public $js = [
'global/plugins/CryptoJS_v3.1.2/components/core-min.js',
'global/plugins/CryptoJS_v3.1.2/components/hmac-min.js',
'global/plugins/CryptoJS_v3.1.2/components/md5-min.js',
'global/plugins/CryptoJS_v3.1.2/components/sha256-min.js',
'global/plugins/bootstrap-table/bootstrap-table.min.js',
'../../js/bootstrap-table-zh-CN-Miner.js'
];
public $depends = [
'backend\assets\JqueryAsset'
];
public $jsOptions = [
'position' => \yii\web\View::POS_HEAD,
];
}
<?php
namespace backend\controllers;
use Yii;
/**
* AppController Controller
* App控制器
* --------------------------------
* @version 1.0
* @author coldwind
*/
class AppController extends BaseController {
public $enableCsrfValidation = false;
/**
* actionList
* 列表
* ------------------
* @return Object
* @author coldwind
*/
public function actionList() {
$model = Yii::$app->app->app;
if (Yii::$app->request->isGet&&!empty(Yii::$app->request->get('create_time'))) {
$create_time = Yii::$app->request->get('create_time');
$time = explode('~',$create_time);
$model->start_time = rtrim($time[0]);
$model->end_time = ltrim($time[1]);
}
$model->setAttributes(Yii::$app->request->get());
$model->page_size = 10;
$model->list1();
$data = $model->data;
return $this->render('manage', [
'data' => $data,
'limit' => $model->page_size
]);
}
/**
* actionAdd
* 添加
* -----------------
* @return Object
* @author coldwind
*/
public function actionAdd() {
$model = Yii::$app->app->app;
$model->setAttributes(Yii::$app->request->post());
$model->log = !empty($model->log)? explode(PHP_EOL, $model->log):null;
if ($model->create()) {
return json_encode(['code' => 200]);
}
$response = $model->response;
return json_encode(['code' => $response['content']['code'], 'message' => $response['content']['message']]);
}
/**
* actionInfo
* 详情
* ---------------
* @return Object
* @author coldwind
*/
public function actionInfo() {
$model = Yii::$app->app->app;
$model->id = Yii::$app->request->get('id');
if ($model->view()) {
return json_encode($model->data);
}
$response = $model->response;
return json_encode(['code' => $response['content']['code'], 'message' => $response['content']['message']]);
}
/**
* actionEdit
* 编辑
* ---------------
* @return Object
* @author coldwind
*/
public function actionEdit() {
$model = Yii::$app->app->app;
$model->setAttributes(Yii::$app->request->post());
$model->log = !empty($model->log)? explode(PHP_EOL, $model->log):null;
if ($model->update()) {
return json_encode(['code' => 200]);
}
$response = $model->response;
return json_encode(['code' => $response['content']['code'], 'message' => $response['content']['message']]);
}
}
\ No newline at end of file
<?php
namespace backend\controllers;
use Yii;
/**
* Created by PhpStorm.
* Author: libingke
* Date: 2017/10/30
* Time: 9:41
*/
class AssetController extends BaseController
{
public $enableCsrfValidation = false;
/**
* [充币查询]
* @author libingke
* @return string
*/
public function actionCoinIn()
{
return $this->render('coin-in', [
'url_table1' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['充币查询记录'],
'url_export1' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['充币查询记录导出']
]);
}
/**
* [手工入币列表]
*/
public function actionHandInCoinList()
{
}
/**
* [手工入账单 列表]
* @author libingke
* @return string
*/
public function actionHandInCashList()
{
return $this->render('cash-in', [
'url_hand_in'=> Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['手工入金'],
'url_table1' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['手工入金列表'],
'url_table2' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['手工入金记录'],
'url_fh' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['手工入金_复核'],
'url_cx' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['手工入金_撤销'],
'url_last_record' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['匹配最新入金'],
'url_tail_num' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['入金尾号'],
]);
}
/**
* [大额提币 列表]
* @return mixed
*/
public function actionLargeCoinOut()
{
return $this->render('coin-out', [
'url_hot' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['热钱包余额'],
'url_table1' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['待审核提币列表'],
'url_table2' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['提币查询记录'],
'url_cs' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['提币_初审'],
'url_fs' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['提币_复审'],
'url_cx' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['提币_撤销'],
'url_ct' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['提币审核撤提'],
'url_export2' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['提币查询记录导出']
]);
}
/**
* [资产信息]
*/
public function actionDetail()
{
return $this->render('risk-user');
}
/**
* [提款查询]
* @return mixed
*/
public function actionCashOut()
{
return $this->render('cash-out', [
'url_table1' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['出金记录'],
'url_setPlan' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['设置导出计划'],
'url_getPlan' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['获取导出计划'],
'url_delPlan' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['删除导出计划'],
'url_showPlan' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['导出文件列表'],
'url_ct' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['提币审核撤提']
]);
}
/**
* [薪资发放]
* @return mixed
*/
public function actionPaySalary()
{
return $this->render('pay', [
'url_table' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['资金数据列表'],
'url_add_row' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['添加资金发放数据'],
'url_add_file' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['资金数据文件处理'],
'url_type' => Yii::$app->params['fxee_domain'] . Yii::$app->params['fxee_backend']['资金类型']
]);
}
}
\ No newline at end of file
<?php
namespace backend\controllers;
use common\models\gli\Cache;
use common\service\MinerException;
use Yii;
/**
*
* Class ChatController
* @package backend\controllers
*/
class ChatController extends BaseController
{
public $layout = false;
public $groupChat = 'fzmcwxfd';
/**
* 确认页面
* @author: libingke
* @param string $access
*/
public function actionFinanceConfirm($access = '', $type = '')
{
$url = '/';
$error = '';
$message = '';
try {
if ($access !== 'lhBub4yhASfXNnOhhkxBVRBuSiVG2a')
throw new MinerException('无访问权限');
switch ($type)
{
case 'tb':
$url = "asset/large-coin-out";
$message = $this->_confirmHandle('tb');
break;
case 'tk':
$url = "asset/cash-out";
$message = $this->_confirmHandle('tk');
break;
default:
throw new MinerException('无效参数');
}
} catch (MinerException $e) {
$error = "【error】 {$e->getMessage()}";
} catch (\yii\db\Exception $e) {
$error = "【DB错误】 {$e->getMessage()}";
}
return $this->render('confirm', [
'url' => $url,
'message' => $message,
'error' => $error
]);
}
/**
* _confirmHandle
* @param $key
* @return string
* @throws MinerException
*/
private function _confirmHandle($key)
{
$char = $key == 'tk' ? '提款' : '提币';
$sign = $key == 'tk' ? "####################" : "***************************";
$request = Yii::$app->request;
$count = $request->get('count');
$maxId = $request->get('maxId');
$minId = $minTemp = $request->get('minId');
if (!is_numeric($count) || !is_numeric($maxId)) {
throw new MinerException('错误的请求参数');
}
$cache = Cache::getData("weChat_{$key}_max");
if ($cache > $minId && $cache < $maxId) {
$minId = $cache;
}
if (is_numeric($cache) && $maxId <= $cache) {
$str = "<br><br>"
. "<center><span style='color:#ff6c3a;'><b>已被确认过!</b></span><br><br>"
. "确认数量:{$count}<br><br>"
. "流水编号范围:<br>{$minId} - {$maxId} </center>";
} else {
Cache::setData("weChat_{$key}_history", 0);
Cache::setData("weChat_{$key}_max", $maxId);
Cache::setData("weChat_{$key}_min", $maxId);
$str = "<br><br>"
. "<center><span style='color:#61a73a;'><b>确认成功!</b></span><br><br>"
. "确认数量:{$count}<br><br>"
. "流水编号范围:<br>{$minId} - {$maxId} </center>";
if ($request->get('handle', 'handle') == 'auto' && $minTemp >= $cache) {
$msg = "{$char}申请已确认\n"
. "$sign\n"
. " 确认数:{$count}\n"
. " 流水编号范围:\n"
. " {$minId} - {$maxId}\n{$sign}";
$chat = Yii::$app->getWeChat()->compose();
$chat->setSendType(4);
$chat->setTo($this->groupChat);
$chat->setSendBody($msg);
$chat->send();
}
}
return $str;
}
}
<?php
namespace backend\controllers;
use Yii;
use backend\models\Campaign;
use yii\base\Model;
/**
* OperationsController Controller
* 运营控制器
* --------------------------------
* @version 1.0
* @author coldwind
*/
class OperationsController extends BaseController {
public $enableCsrfValidation = false;
/**
* actionList
* 列表
* ---------------
* @return Object
* @author coldwind
*/
public function actionList() {
$page = Yii::$app->request->get('page');
$limit = 5;
$model = Yii::$app->marketing->activity;
$model->list1(['page' => $page, 'pageSize' => $limit]);
$data = $model->data;
$header= $model->header;
$totalPage = ceil($header['X-Pagination-Total-Count'] / $limit);
return $this->render('manage', [
'data' => $data,
'totalPage' => $totalPage,
'limit' => $limit,
]);
}
/**
* actionAdd
* 添加数据
* ---------------
* @return Object
* @author coldwind
*/
public function actionAdd() {
if (Yii::$app->request->isPost) {
$plan = Yii::$app->marketing->plan;
$post = Yii::$app->request->post();
$online_time = $post['online_time'];
$online_time = explode('~',$online_time);
$plan->start = strtotime($online_time[0]);
$plan->end = strtotime($online_time[1]);
$plan->status = $plan::STATUS_DISABLED;
if ($plan->create()) {
$activity = Yii::$app->marketing->activity;
$activity->setAttributes($post);
$activity->plan_id = $plan->id;
if ($activity->create()){
return json_encode(['code' => 200]);
}
$errors = $activity->error;
}else {
$errors = $plan->error;
}
$error = reset($errors);
return json_encode(['message' => $error[0]]);
}
}
/**
* actionDetail
* 详情
* ---------------
* @return Object
* @author coldwind
*/
public function actionDetail() {
$activity = Yii::$app->marketing->activity;
$activity->id = Yii::$app->request->get('id');
if ($activity->view()) {
$data_activity = $activity->data;
if (!empty($data_activity['plan_id'])) {
$plan = Yii::$app->marketing->plan;
$plan->id = $data_activity['plan_id'];
if ($plan->view()) {
return json_encode(['activity' => $data_activity, 'plan' => $plan->data]);
}
}
}else {
$errors = $activity->error;
}
$error = reset($errors);
return json_encode(['message' => $error]);
}
/**
* actionDelete
* 删除
* ---------------
* @return Object
* @author coldwind
*/
public function actionDelete() {
$model = Yii::$app->marketing->activity;
$model->id = Yii::$app->request->post('id');
if ($model->delete()) {
return json_encode(['code' => 200]);
}
}
/**
* actionEdit
* 编辑
* ---------------
* @return Object
* @author coldwind
*/
public function actionEdit() {
$activity = Yii::$app->marketing->activity;
$post = Yii::$app->request->post();
$activity->setAttributes($post);
$activity->id = $post['id'];
if ($activity->update()) {
$plan = Yii::$app->marketing->plan;
$plan->id = $post['plan_id'];
$plan->start = strtotime($post['start']);
$plan->end = strtotime($post['end']);
if ($plan->update()) {
return json_encode(['code' => 200]);
}
$errors = $plan->error;
}else {
$errors = $activity->error;
}
$error = reset($errors);
return json_encode(['message' => $error]);
}
}
<?php
namespace backend\controllers;
use Yii;
/**
* 矿机份额控制器
* Class PoolShareController
* @package backend\controllers
*/
class PoolShareController extends BaseController
{
//public $enableCsrfValidation = false;
/**
* actionList
* 列表
* ------------------
* @return Object
* @author coldwind
*/
public function actionListBak() {
$model = Yii::$app->pool->pool;
if (Yii::$app->request->isGet&&!empty(Yii::$app->request->get('create_time'))) {
$create_time = Yii::$app->request->get('create_time');
$time = explode('~',$create_time);
$model->start_time = rtrim($time[0]);
$model->end_time = ltrim($time[1]);
}
$model->setAttributes(Yii::$app->request->get());
$model->page_size = 20;
$model->list1();
$data = $model->data;;
return $this->render('manage', [
'data' => $data,
'limit' => $model->page_size,
'params' => Yii::$app->request->get()
]);
}
/**
* 矿池份额
* @author: libingke
* @return string
*/
public function actionList()
{
return $this->render('list', [
'url_key' => Yii::$app->params['miner_api']['pool_key'],
'url_table1' => Yii::$app->params['miner_domain'] . Yii::$app->params['miner_api']['矿池列表'],
]);
}
}
\ No newline at end of file
<?php
namespace backend\controllers;
use common\helpers\PublicHelper;
use Yii;
/**
* Class QueryController
* @package backend\controllers
*/
class QueryController extends BaseController
{
public $layout = false;
/**
* @return mixed
*/
public function actionFormatParams()
{
$from = Yii::$app->request->get('from');
$newParams = [];
if ($from) {
$params = Yii::$app->request->queryParams;
switch ($from)
{
case 'search_uid':
isset($params['uid']) && $params['uid'] != '' ? $newParams['uid'] = $this->_getUid($params['uid']) : null;
break;
}
}
$response = Yii::$app->response;
$response->format = \yii\web\Response::FORMAT_JSON;
return $response->data = $newParams;
}
private function _getUid($uid)
{
$user = PublicHelper::getInFilterByUser($uid, 'string');
return $user == false ? '-1' : $user;
}
}
<?php
namespace backend\controllers;
use common\models\parse\search\OrderSearch;
use Yii;
/**
* Class TradeController
* @package backend\controllers
*/
class TradeController extends BaseController
{
/**
* [交易管理]
* @return mixed
*/
public function actionIndex()
{
try {
$params = Yii::$app->request->queryParams;
$searchModel = new OrderSearch();
$searchModel->setScenario('order');
$dataProvider = $searchModel->searchOrder($params);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'tBody' => $searchModel->getTBody(),
//'tip' => $searchModel->getTip()
]);
} catch (\yii\db\Exception $e) {
print_r("[ MESSAGE ]<br> ".$e->getMessage());exit;
}
}
/**
* [导出excel]
* @author libingke
* @return bool
*/
public function actionExport()
{
//todo
echo '暂未开放';
}
}
<?php
namespace backend\models;
use common\models\Campaign as BaseCampaign;
/**
* Campaign Model
* 活动模型
* -------------------
* @version 1.0.0
* @author coldwind
*/
class campaign extends BaseCampaign {
public function rules() {
return [
[['name', 'start_time', 'end_time', 'amount', 'online_time', 'offline_time'], 'trim', 'on' => 'add'],
['name', 'required', 'message' => '姓名不能为空', 'on' => 'add'],
['start_time', 'required', 'message' => '活动开始时间不能为空', 'on' => 'add'],
['end_time', 'required', 'message' => '活动截止时间不能为空', 'on' => 'add'],
['amount', 'required', 'message' => '总量不能为空', 'on' => 'add'],
['currencies', 'required', 'message' => '币种类型不能为空', 'on' => 'add'],
['online_time', 'required', 'message' => '上线时间不能为空', 'on' => 'add'],
['offline_time', 'required', 'message' => '下线时间不能为空', 'on' => 'add'],
['name', 'string', 'max' => 20, 'tooLong' => '活动名称不能大于20字符', 'message' => '活动名称格式不符合', 'on' => 'add'],
['start_time', 'date', 'format' => 'yyyy-MM-dd', 'timestampAttribute' => 'start_time', 'message' => '开始时间格式错误', 'on' => 'add'],
['end_time', 'date', 'format' => 'yyyy-MM-dd', 'timestampAttribute' => 'end_time', 'message' => '截止时间格式错误', 'on' => 'add'],
['online_time', 'date', 'format' => 'yyyy-MM-dd HH:mm', 'timestampAttribute' => 'online_time', 'message' => '上线时间格式错误', 'on' => 'add'],
['offline_time', 'date', 'format' => 'yyyy-MM-dd HH:mm', 'timestampAttribute' => 'offline_time', 'message' => '下线时间格式错误', 'on' => 'add'],
['web_url', 'url', 'defaultScheme' => 'http', 'message' => '页面URL格式错误', 'on' => 'add'],
['api_url', 'url', 'defaultScheme' => 'http', 'message' => '接口URL格式错误', 'on' => 'add'],
];
}
}
\ No newline at end of file
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
/**
* UploadForm Model
* 上传模型
* -------------------
* @version 1.0.0
* @author coldwind
*/
class UploadForm extends Model
{
/**
* @var UploadedFile file attribute
*/
public $file;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
['file', 'file'],
];
}
/**
* upload()
* 上传
* ----------------
* @return Boolean
* @author coldwind
*/
public function getData() {
if ($path = $this->upload()) {
return $this->getCsv($path);
}
}
/**
* upload()
* 上传
* ----------------
* @return Boolean
* @author coldwind
*/
protected function upload() {
$name = date("Ymd", time()). '_'. Yii::$app->security->generateRandomString(5). '.'. 'csv';
$path = Yii::$app->getBasePath() . "/web/upload". DIRECTORY_SEPARATOR. 'csv'. DIRECTORY_SEPARATOR. $name;
if ($this->file->saveAs($path)) {
return $path;
}
return false;
}
/**
* upload()
* 上传
* ----------------
* @return object
* @author coldwind
*/
protected function getCsv($path) {
$handle = fopen($path, 'r');
$uid = [];
$key = null;
while (! feof($handle)) {
$file = fgetcsv($handle,0, ',');
if (is_array($file)) {
if (empty($key)) {
$key = array_search('uid', $file);
}
$uid[] = $file[$key];
}
}
unset($uid[0]);
fclose($handle);
return $uid;
}
}
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-1
* Time: 下午2:25
*/
namespace backend\models\coin;
use common\models\upload\uploader\LoadUploader;
class IconUploader
{
}
\ No newline at end of file
This diff is collapsed.
<?php
\backend\assets\TableAsset::register($this);
$this->registerJs(<<< JS
var url_hand_in="{$url_hand_in}";
var url_last_record="{$url_last_record}";
var url_tail_num="{$url_tail_num}";
var url_table1="{$url_table1}";
var url_table2="{$url_table2}";
var url_fh="{$url_fh}";
var url_cx="{$url_cx}";
JS
,\yii\web\View::POS_BEGIN);
$this->registerJsFile('@web/js/asset/cash-in.js?201801');
?>
<div class="layui-row">
<div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
<form id="form-cash" class="layui-form" onkeydown="if(event.keyCode==13){return false;}" onsubmit="return false;">
<div class="layui-form-item">
<div class="layui-inline">
<label class="my-label" style="width: 60px">UID</label>
<div class="layui-input-inline">
<input id="user" name="user" type="text" class="my-input clear-cash" placeholder="回车查询最近入金信息" autocomplete="off" onkeyup="if(event.keyCode==13)(getCashLastRecord(this))">
</div>
</div>
<div class="layui-inline">
<label class="my-label" style="width: 60px">姓名</label>
<div class="layui-input-inline">
<input id="name" name="name" type="text" class="my-input clear-cash" autocomplete="off">
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="my-label" style="width: 60px">渠道</label>
<div class="layui-input-inline">
<?= \yii\helpers\Html::dropDownList('way', null,
\common\business\FxeeBusiness::getPayList(false),
['class' => 'my-select select-hand', 'style'=>'width:182px']) ?>
</div>
</div>
<div class="layui-inline">
<label class="my-label" style="width: 60px">金额</label>
<div class="layui-input-inline">
<input id="amount" name="amount" type="text" class="my-input clear-cash" autocomplete="off">
</div>
</div>
<div class="layui-inline">
<div class="layui-input-inline">
<button class="layui-btn " onclick="cashIn()">确认入金</button>
<button class="layui-btn layui-btn-primary" onclick='$(".clear-cash").val("");'>重置信息</button>
</div>
</div>
</div>
</form>
</div>
<span id="add-cash-recode" style="color: red;"></span> <span id="add-cash-tail" style="color: #337ab7;"></span>
</div><hr>
<div>
<div class="layui-form">
<form id="form1" class="layui-form-item">
<div class="layui-unselect layui-form-select">
<label class="my-label">渠道</label>
<div class="layui-input-inline">
<?= yii\helpers\Html::dropDownList('way', null,
\common\business\FxeeBusiness::getPayList(),
['class' => 'my-select select1']) ?>
</div>
</div>
<div class="layui-unselect layui-form-select">
<label class="my-label">操作员</label>
<div class="layui-input-inline">
<?= yii\helpers\Html::dropDownList('opuid', null,
common\models\fxee\Member::getOperatorList(true),
['class' => 'my-select select1']) ?>
</div>
</div>
<div>
<label class="my-label">处理时间</label>
<div class="layui-input-inline">
<input type="text" class="my-input clear1" id="date_range" name="date_range" placeholder="选择日期范围">
</div>
</div>
<div class="layui-inline">
<div class="layui-input-inline">
<input id="uid1" name="user" type="text" class="my-input clear1" placeholder="UID/姓名/手机/邮箱" autocomplete="off" >
</div>
</div>
<div class="layui-inline">
<button type="button" class="btn btn-primary" onclick="query(1)">搜索</button>
<button type="button" class="btn btn-default" onclick='$(".clear1").val("");$(".select1").val("");query(1)'>重置筛选</button>
</div>
</form>
<table id="table1" class="table table-striped table-bordered"></table>
<span id="tip1"></span>
</div>
<hr>
<div class="layui-form">
<form id="form2" class="layui-form-item">
<div class="layui-unselect layui-form-select">
<label class="my-label">渠道</label>
<div class="layui-input-inline">
<?= yii\helpers\Html::dropDownList('way', null,
\common\business\FxeeBusiness::getPayList(),
['class' => 'my-select select2']) ?>
</div>
</div>
<div class="layui-unselect layui-form-select">
<label class="my-label">操作员</label>
<div class="layui-input-inline">
<?= yii\helpers\Html::dropDownList('opuid', null,
common\models\fxee\Member::getOperatorList(true),
['class' => 'my-select select2']) ?>
</div>
</div>
<div class="layui-unselect layui-form-select">
<label class="my-label">初审员</label>
<div class="layui-input-inline">
<?= yii\helpers\Html::dropDownList('checkuid', null,
\common\models\fxee\Member::getOperatorList(true),
['class' => 'my-select select2']) ?>
</div>
</div>
<div>
<label class="my-label">处理时间</label>
<div class="layui-input-inline">
<input type="text" class="my-input clear2" id="date_range2" name="date_range" placeholder="选择日期范围">
</div>
</div>
<div class="layui-inline">
<div class="layui-input-inline">
<input id="uid2" name="user" type="text" class="my-input clear2" placeholder="UID/姓名/手机/邮箱" autocomplete="off" >
</div>
</div>
<div class="layui-inline">
<button type="button" class="btn btn-primary" onclick="query(2,1)">搜索</button>
<button type="button" class="btn btn-default" onclick='$(".clear2").val("");$(".select2").val("");query(2,1)'>重置筛选</button>
</div>
</form>
<table id="table2" class="table table-striped table-bordered"></table>
<span id="tip2"></span>
</div>
</div>
\ No newline at end of file
<?php
\backend\assets\TableAsset::register($this);
$url_params = \yii\helpers\Url::toRoute('/query/format-params?from=search_uid');
$this->registerJs(<<< JS
var url_table1="{$url_table1}";
var url_setPlan="{$url_setPlan}";
var url_getPlan="{$url_getPlan}";
var url_delPlan="{$url_delPlan}";
var url_showPlan="{$url_showPlan}";
var url_params="{$url_params}";
var url_ct="{$url_ct}";
JS
,\yii\web\View::POS_BEGIN);
$this->registerJsFile('@web/js/asset/cash-out.js?20180209');
?>
<div class="layui-form">
<form id="form1" class="layui-form-item">
<div class="layui-unselect layui-form-select">
<label class="my-label">状态</label>
<div class="layui-input-inline">
<?= \yii\helpers\Html::dropDownList('statu', null,
\common\models\fxee\CashRecord::getStatuList(true),
['class' => 'my-select select1', 'style' => 'width:100px']) ?>
</div>
</div>
<div>
<label class="my-label">完成时间</label>
<div class="layui-input-inline">
<input type="text" class="my-input clear1" id="date_range" name="date_range" placeholder="选择日期范围">
</div>
</div>
<div class="layui-inline">
<div class="layui-input-inline">
<input id="uid" name="uid" type="text" class="my-input clear1" placeholder="UID/姓名/手机/邮箱" autocomplete="off" >
</div>
</div>
<div class="layui-inline">
<button type="button" class="btn btn-primary" onclick="query(1)">搜索</button>
<button type="button" class="btn btn-default" onclick='$(".clear1").val("");$(".select1").val("");query(1)'>重置筛选</button>
<button type="button" class="btn btn-primary" onclick='set_export_plan()'>设置导出时间</button>
<button type="button" class="btn btn-primary" onclick='get_export_plan()'>计划表</button>
<button type="button" class="btn btn-primary" onclick='show_plan()'>已导出数据</button>
</div>
</form>
<table id="table1" class="table table-striped table-bordered"></table>
<span id="tip1"></span>
</div>
\ No newline at end of file
<?php
\backend\assets\TableAsset::register($this);
$this->registerJs(<<< JS
var url_table1="{$url_table1}";
var url_export1="{$url_export1}";
JS
,\yii\web\View::POS_BEGIN);
$this->registerJsFile('@web/js/asset/coin-in.js?201801');
?>
<div class="layui-form">
<form id="form1" class="layui-form-item">
<div class="layui-unselect layui-form-select">
<label class="my-label">币种</label>
<div class="layui-input-inline">
<?= \yii\helpers\Html::dropDownList('coin', null,
\common\helpers\CurrencyHelper::getCurrencyList(true, 'name'),
['class' => 'my-select select1', 'id' => 'coin']) ?>
</div>
</div>
<div>
<label class="my-label">完成时间</label>
<div class="layui-input-inline">
<input type="text" class="my-input clear1" id="date_range" name="date_range" placeholder="选择日期范围">
</div>
</div>
<div class="layui-inline">
<div class="layui-input-inline">
<input id="user" name="user" type="text" class="my-input clear1" placeholder="UID/金额/姓名/手机/邮箱" autocomplete="off" >
</div>
</div>
<div class="layui-inline">
<button type="button" class="btn btn-primary" onclick="query(1)">搜索</button>
<button type="button" class="btn btn-default" onclick='$(".clear1").val("");$(".select1").val("");query(1)'>重置筛选</button>
<button type="button" class="btn btn-danger" onclick="exportTable1()">导出</button>
</div>
<div class="columns columns-right btn-group pull-right">
<button class="btn btn-default" type="button" name="refresh" title="Refresh" onclick="query(1)">
<i class="glyphicon glyphicon-refresh icon-refresh"></i>
</button>
</div>
</form>
<table id="table1" class="table table-striped table-bordered"></table>
<span id="tip1"></span>
</div>
\ No newline at end of file
<?php
\backend\assets\TableAsset::register($this);
$this->registerJs(<<< JS
var coin=["BCC","BTC","BTS","DCR","ETC","ETH","LTC","SC","ZEC"];
var url_hot="{$url_hot}";
var url_export2="{$url_export2}";
var url_table1="{$url_table1}";
var url_table2="{$url_table2}";
var url_cs="{$url_cs}";
var url_fs="{$url_fs}";
var url_cx="{$url_cx}";
var url_ct="{$url_ct}";
JS
,\yii\web\View::POS_BEGIN);
$this->registerJsFile('@web/js/asset/coin-out.js?20180322');
?>
<div>
<div id="freshen_hot" class="columns columns-right btn-group pull-right" style="display: none">
<button class="btn btn-default" type="button" name="refresh" title="Refresh" onclick="getHot()">
<i class="glyphicon glyphicon-refresh icon-refresh"></i>
</button>
</div>
<table id="hot" class="table table-striped table-bordered">
<thead><tr id="hot-head"></tr></thead>
<tbody><tr id="hot-body"></tr></tbody>
</table>
<fieldset class="layui-elem-field layui-field-title">
<legend><b style="color: #e7505a">审核</b> </legend>
</fieldset>
<div class="layui-form">
<form id="form1" class="layui-form-item">
<div class="layui-unselect layui-form-select">
<label class="my-label">币种</label>
<div class="layui-input-inline">
<?= yii\helpers\Html::dropDownList('coin', null,
\common\helpers\CurrencyHelper::getCurrencyList(true, 'name'),
['class' => 'my-select select1']) ?>
</div>
</div>
<div>
<label class="my-label">提交时间</label>
<div class="layui-input-inline">
<input type="text" class="my-input clear1" id="date_range" name="date_range" placeholder="选择日期范围">
</div>
</div>
<div class="layui-inline">
<div class="layui-input-inline">
<input id="uid1" name="user" type="text" class="my-input clear1" placeholder="UID/ 姓名/ 手机/ 邮箱" autocomplete="off" >
</div>
</div>
<div class="layui-inline">
<button type="button" class="btn btn-primary" onclick="query(1)">搜索</button>
<button type="button" class="btn btn-default" onclick='$(".clear1").val("");$(".select1").val("");query(1)'>重置筛选</button>
</div>
</form>
<table id="table1" class="table table-striped table-bordered"></table>
<span id="tip1"></span>
</div>
<fieldset class="layui-elem-field layui-field-title">
<legend><b style="color: #2ab4c0">查询</b> </legend>
</fieldset>
<div class="layui-form">
<form id="form2" class="layui-form-item">
<div class="layui-unselect layui-form-select">
<label class="my-label">币种</label>
<div class="layui-input-inline">
<?= yii\helpers\Html::dropDownList('coin', null,
\common\helpers\CurrencyHelper::getCurrencyList(true, 'name'),
['class' => 'my-select select2']) ?>
</div>
</div>
<div class="layui-unselect layui-form-select">
<label class="my-label">初审员</label>
<div class="layui-input-inline">
<?= yii\helpers\Html::dropDownList('checkuid', null,
\common\models\fxee\Member::getOperatorList(true),
['class' => 'my-select select2']) ?>
</div>
</div>
<div class="layui-unselect layui-form-select">
<label class="my-label">复审员</label>
<div class="layui-input-inline">
<?= yii\helpers\Html::dropDownList('recheckuid', null,
\common\models\fxee\Member::getOperatorList(true),
['class' => 'my-select select2']) ?>
</div>
</div>
<div>
<label class="my-label">提交时间</label>
<div class="layui-input-inline">
<input type="text" class="my-input clear2" id="date_range2" name="date_range" placeholder="选择日期范围">
</div>
</div>
<div class="layui-inline">
<div class="layui-input-inline">
<input id="uid2" name="user" type="text" class="my-input clear2" placeholder="UID/ 姓名/ 手机/ 邮箱" autocomplete="off" >
</div>
</div>
<div class="layui-inline">
<button type="button" class="btn btn-primary" onclick="query(2,1)">搜索</button>
<button type="button" class="btn btn-default" onclick='$(".clear2").val("");$(".select2").val("");query(2,1)'>重置筛选</button>
<button type="button" class="btn btn-danger" onclick="exportTable2()">导出</button>
</div>
</form>
<table id="table2" class="table table-striped table-bordered"></table>
<span id="tip2"></span>
</div>
</div>
\ No newline at end of file
<?php
\backend\assets\TableAsset::register($this);
$this->registerJs(<<< JS
var url_table1="{$url_table}";
var url_add_row="{$url_add_row}";
var url_add_file="{$url_add_file}";
var url_type="{$url_type}";
JS
,\yii\web\View::POS_BEGIN);
$this->registerJsFile('@web/js/asset/pay.js?201801');
?>
<div class="layui-form" style="max-width: 1400px">
<form id="form1" class="layui-form-item">
<div class="layui-unselect layui-form-select">
<label class="my-label">状态</label>
<div class="layui-input-inline">
<?= \yii\helpers\Html::dropDownList('status', null,
[''=>'全部','0'=>'未处理','1'=>'已处理'],
['class' => 'my-select select1', 'style' => 'width:100px']) ?>
</div>
</div>
<div>
<label class="my-label">添加时间</label>
<div class="layui-input-inline">
<input type="text" class="my-input clear1" id="date_range" name="date_range" placeholder="选择日期范围">
</div>
</div>
<div class="layui-inline">
<div class="layui-input-inline">
<input id="uid" name="uid" type="text" class="my-input clear1" placeholder="UID" autocomplete="off" >
</div>
</div>
<div class="layui-inline">
<button type="button" class="btn btn-primary" onclick="query(1)">搜索</button>
<button type="button" class="btn btn-default" onclick='$(".clear1").val("");$(".select1").val("");query(1)'>重置筛选</button>
<button type="button" class="btn btn-primary" onclick="loadRow()"><i class="fa fa-plus"></i>添加数据</button>
<button id="loadFile" type="button" class="btn btn-primary" onclick="layui.layer.msg('请选择csv文件格式')"><i class="fa fa-plus"></i>导入文件</button>
</div>
</form>
<table id="table1" class="table table-striped table-bordered"></table>
<span id="tip1"></span>
</div>
\ No newline at end of file
<!-- <button id="jump" class="layui-btn" onclick="jump()">跳转风控详情页</button>
<br><br>密码已修改,@张峰 索要 -->
<!--<br><br>如需登录则输入:
<br>demo
<br>demo-->
<script>
//layer.tips('密码已修改,@张峰 索要', '#jump', {tips: [1, '#009688']});
//jump();
function jump() {
var index = layer.open({
//skin: 'layui-layer-lan',
//title: '风控页面,点击右侧关闭可返回',
title: false,
offset: 'lb',
shade: 0,
type: 2,
content: 'http://zrisk.33.cn/',
maxmin: true
});
//layer.full(index);
//重新给指定层设定width、top等
layer.style(index, {
width: $(window).width()-8,
height: $(window).height()-48,
top: '51px',
zIndex:1
});
}
</script>
\ No newline at end of file
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<div class="container">
<br>
<br>
<h3><?= $message ?></h3>
<h3 style="color: red"><?= $error ?></h3>
<br>
<br>
<br>
<br>
<b id="wait"><?= 3 ?></b> 秒后自动跳转
</div>
<script type="text/javascript">
(function(){
var wait = document.getElementById('wait'),href = "<?=\yii\helpers\Url::toRoute($url)?>";
var interval = setInterval(function(){
var time = --wait.innerHTML;
if(time <= 0) {
location.href = href;
clearInterval(interval);
};
}, 1000);
window.stop = function (){
clearInterval(interval);
}
})();
</script>
</body>
</html>
<!DOCTYPE HTML>
<html>
<body>
<div class="page-container">
<div class="my-container">
<div class="layui-row">
<div class="col-md-12">
<form id="add" class="form-horizontal" action="/admin/operations/add" method="post" enctype="multipart/form-data">
<input type="hidden" name="_csrf" value="2oCKn31CnElfOlF7lmF10pWN8oMxUlU09xjozkTBdWuK187GKnvqJwt0GCT6MROVrc-j0gQ1Fn6CLoabK7EmOg==" />
<div class="form-group field-campaign-name">
<label class="col-lg-2 control-label" for="campaign-name">活动名称</label>
<div class="col-lg-5">
<input type="text" id="campaign-name" class="form-control" name="campaign[name]" maxlength="20" style="width:500px" value="<?= isset($data['start_time'])?$data['start_time']:'' ?>"/>
</div>
<div class="col-lg-3">
<div class="help-block"></div>
</div>
</div>
<div class="form-group field-campaign-web_url">
<label class="col-lg-2 control-label" for="campaign-web_url">页面URL</label>
<div class="col-lg-5">
<input type="text" id="campaign-web_url" class="form-control" name="campaign[web_url]" maxlength="20" style="width:500px" value="<?= isset($data['start_time'])?$data['start_time']:'' ?>"/>
</div>
<div class="col-lg-3">
<div class="help-block"></div>
</div>
</div>
<div class="form-group field-campaign-api_url">
<label class="col-lg-2 control-label" for="campaign-api_url">接口URL</label>
<div class="col-lg-5">
<input type="text" id="campaign-api_url" class="form-control" name="campaign[api_url]" maxlength="20" style="width:500px" value="<?= isset($data['start_time'])?$data['start_time']:'' ?>"/>
</div>
<div class="col-lg-3">
<div class="help-block"></div>
</div>
</div>
<div class="form-group field-campaign-currencies">
<label class="col-lg-2 control-label">活动币种</label>
<div class="col-lg-5">
<input type="hidden" name="campaign[currencies]" value="" />
<div id="campaign-currencies">
<label><input type="radio" name="campaign[currencies]" value="1" /> BTY</label>
<label><input type="radio" name="campaign[currencies]" value="2" /> YCC</label>
</div>
</div>
<div class="col-lg-3">
<div class="help-block"></div>
</div>
</div>
<div class="form-group field-campaign-amount">
<label class="col-lg-2 control-label" for="campaign-amount">总量</label>
<div class="col-lg-5">
<input type="text" id="campaign-amount" class="form-control" name="campaign[amount]" maxlength="20" style="width:500px" />
</div>
<div class="col-lg-3">
<div class="help-block"></div>
</div>
</div>
<div class="form-group field-campaign-online_time">
<label class="col-lg-2 control-label" for="campaign-online_time">上线时间</label>
<div class="col-lg-5">
<input type="text" class="my-input clear1" id="start_time" name="start_time" placeholder="上线时间" style="width:500px" >
</div>
<div class="col-lg-3">
<div class="help-block">&nbsp;</div>
</div>
</div>
<div class="form-group field-campaign-online_time">
<label class="col-lg-2 control-label" for="campaign-online_time">下线时间</label>
<div class="col-lg-5">
<input type="text" class="my-input clear1" id="end_time" name="end_time" placeholder="下线时间" style="width:500px">
</div>
<div class="col-lg-3">
<div class="help-block">&nbsp;</div>
</div>
</div>
<div class="form-group" style="margin-left: 250px;">
<button type="submit" class="btn btn-primary" name="submit-button" id = "submit">提交</button>
<button type="reset" class="btn btn-primary" name="submit-button">重置</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
var error = "<?= $error ?>";
layerErr(error);
function layerErr(error) {
if (error != "") {
layer.msg(error, {anim:6});
}
}
layui.use('laydate', function(){
var laydate = layui.laydate;
laydate.render({
elem: '#start_time'
});
});
layui.use('laydate', function(){
var laydate = layui.laydate;
laydate.render({
elem: '#end_time'
});
});
document.getElementById("submit").onclick = submit();
function submit() {
document.getElementById('add').submit();
}
</script>
</body>
</html>
\ No newline at end of file
<?php
use yii\helpers\Html;
$this->title = '活动内容';
?>
<h1><?= Html::encode($this->title) ?></h1>
<p>
</p>
<!DOCTYPE html>
<html>
<body>
<table class="table table-striped table-bordered table-hover">
<thead>
<?php
// var_dump($data);die;
echo <<<EOF
<tr>
<th>活动名称</th>
<th>{$data[0]['name']}</th>
</tr>
<tr>
<th>活动币种</th>
<th>{$data[0]['currency']}</th>
</tr>
<tr>
<th>总量</th>
<th>{$data[0]['limit']}</th>
</tr>
<tr>
<th>上线时间</th>
<th>{$data[0]['plan']['start']}</th>
</tr>
<tr>
<th>下线时间</th>
<th>{$data[0]['plan']['end']}</th>
</tr>
EOF;
?>
</thead>
This diff is collapsed.
<?php
\backend\assets\MinerTableAsset::register($this);
$this->registerJs(<<< JS
var url_key="{$url_key}";
var url_table1="{$url_table1}";
JS
,\yii\web\View::POS_BEGIN);
$this->registerJsFile('@web/js/pool-share/list.js?20180509');
?>
<br>
<div style="max-width: 1600px">
<div class="layui-form">
<form id="form1" class="layui-form-item">
<div class="layui-unselect layui-form-select">
<label class="my-label">发起人uid</label>
<div class="layui-input-inline">
<input id="user_id" name="user_id" type="text" class="my-input clear1" style="max-width: 120px" placeholder="发起人" autocomplete="off">
</div>
</div>
<div class="layui-unselect layui-form-select">
<label class="my-label">矿池编号</label>
<div class="layui-input-inline">
<input type="text" id="pool_id" name="pool_id" class="my-input clear1" style="min-width: 280px" placeholder="输入矿池编号" autocomplete="off">
</div>
</div>
<div>
<label class="my-label">创建时间</label>
<div class="layui-input-inline">
<input type="text" class="my-input clear1" id="date_range" style="width: 200px" placeholder="开始-结束">
</div>
</div>
<div class="layui-inline">
<button type="button" class="btn btn-primary" onclick="query(1)">搜索</button>
<button type="button" class="btn btn-default" onclick='sortFunc.init();$(".clear1").val("");query(1)'>重置筛选</button>
</div>
</form>
</div>
<table id="table1" class="table table-striped table-bordered"></table>
</div>
<br>
<?php
use yii\helpers\Html;
use yii\widgets\Pjax;
use backend\assets\AppAsset;
AppAsset::addCss($this, '@web/css/miner/add.css');
$p[1] = isset($params['user_id']) ? $params['user_id'] : '';
$p[2] = isset($params['id']) ? $params['id'] : '';
$p[3] = isset($params['create_time']) ? $params['create_time'] : '';
$p[4] = isset($params['sort']) ? $params['sort'] : '';
$query = $p[1] == '' ? '' : 'user_id=' . $p[1];
$query .= $p[2] == '' ? '' : ($query == '' ? 'id=' . $p[2] : '&' . 'id=' . $p[2]);
$query .= $p[3] == '' ? '' : ($query == '' ? 'create_time=' . $p[3] : '&' . 'create_time=' . $p[3]);
$query .= $p[4] == '' ? '' : ($query == '' ? 'sort=' . $p[4] : '&' . 'sort=' . $p[4]);
?>
<!DOCTYPE html>
<html>
<script>
$(document).ready(function(){
var laydate = layui.laydate;
laydate.render({
elem: '.create_time' //指定元素
,type: 'datetime'
,range: '~'
});
var laypage = layui.laypage;
//执行一个laypage实例
laypage.render({
elem: 'page'
,count: <?= isset($data['count']) ? $data['count'] : 0 ?> //数据总数,从服务端得到
,limit: <?= isset($limit) ? $limit : 20 ?>
,curr: <?= isset($_GET['page'])?$_GET['page']:1?>
,theme: "#337ab7"
,jump: function(obj, first){
//首次不执行
if(!first){
window.location.href = "/admin/pool-share/list?<?= $query ? $query . "&" : "" ?>page="+obj.curr;
}
}
});
//提交搜索
$(".btn_search").click(function(){
$('.form_search').submit();
});
});
</script>
<body>
<div class="layui-row">
<form class="layui-form form_search" action="list" method="get">
<div class="layui-col-md2">
<div class="layui-form-item">
<label class="my-label">发起人ID</label>
<div class="layui-input-block">
<input type="text" name="user_id" required lay-verify="required" placeholder="" autocomplete="off" class="form-control user_id">
</div>
</div>
</div>
<div class="layui-col-md2">
<div class="layui-form-item">
<label class="my-label">矿池编号</label>
<div class="layui-input-block">
<input type="text" name="id" required lay-verify="required" placeholder="" autocomplete="off" class="form-control id">
</div>
</div>
</div>
<div class="layui-col-md2">
<div class="layui-form-item">
<label class="my-label">创建时间</label>
<div class="layui-input-block">
<input type="text" name="create_time" id = "create_time" required lay-verify="required" placeholder="" autocomplete="off" class="form-control create_time">
</div>
</div>
</div>
<div class="layui-col-md2">
<div class="layui-input-block">
<a class="btn btn-primary btn_search">搜索<i class="glyphicon glyphicon-search"></i></a>
</div>
</div>
</form>
</div>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>编号</th>
<th>矿池编号</th>
<th>已售台数</th>
<th>总台数</th>
<th>发起人ID</th>
<th>创建时间</th>
<th>
<span>过期时间</span>
<div style="display: inline-block">
<a href="/admin/pool-share/list?sort=expires" style="display: block; height: 12px"><i class="glyphicon glyphicon glyphicon-triangle-top" aria-hidden="true"></i></a>
<a href="/admin/pool-share/list?sort=-expires"><i class="glyphicon glyphicon glyphicon-triangle-bottom" aria-hidden="true"></i></a>
</div>
</th>
</tr>
</thead>
<tbody>
<?php
$r = isset($data['rows']) ? $data['rows'] : [];
if ($r) {
foreach ($r as $key => $value) {
$value['created_at'] = date("Y-m-d H:i:s",strtotime($value['created_at']));
$value['expires'] = date("Y-m-d H:i:s", $value['expires']);
echo <<<EOF
<tr>
<td>{$value['friendly_id']}</td>
<td>{$value['id']}</td>
<td>{$value['sold']}</td>
<td>{$value['miner_count']}</td>
<td>{$value['user_id']}</td>
<td>{$value['created_at']}</td>
<td>{$value['expires']}</td>
EOF;
}
}
?>
</table>
<div id = "page"></div>
</body>
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\parse\search\OrderSearch;
$all = ['' => '全部'];
$form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
'options'=>[
'class'=>"form-inline",
'data-pjax' => false,
]
]); ?>
<style>
.trade-row > div{
padding-left: 5px;
padding-right: 10px;
}
</style>
<div class="trade-row">
<div class="col-md-1 col-sm-1" style='width:185px'>
<?=$form->field($model, 'symbol_couple')
->dropDownList(\common\models\parse\Order::getSymbolCouple(false), ['style'=>'width:110px'])->label('货币对'); ?>
</div>
<div class="col-md-1 col-sm-1" style='width:160px'>
<?=$form->field($model, 'status')
->dropDownList(OrderSearch::getStatusList(true, false), ['style'=>'width:75px'])->label('订单状态'); ?>
</div>
<div class="col-md-1 col-sm-1" style='width:155px'>
<?=$form->field($model, 'ty')
->dropDownList(OrderSearch::getTyList(true), ['class'=>'form-control'])->label('交易类型'); ?>
</div>
<div class="col-md-3 col-sm-2" style='width:330px'>
<?php
$layout = <<< HTML
<span class="input-group-addon">成交时间</span>
{input1}
{separator}
{input2}
<span class="input-group-addon kv-date-remove">
<i class="glyphicon glyphicon-remove"></i>
</span>
HTML;
echo \kartik\widgets\DatePicker::widget([
'type' => \kartik\widgets\DatePicker::TYPE_RANGE,
'language' => 'zh-CN',
'name' => 'OrderSearch[from_date]',
'value' => $model->from_date,
'options' => ['class'=>'clear', 'placeholder' => '选择日期', 'autocomplete'=>'off'],
'name2' => 'OrderSearch[to_date]',
'value2' => $model->to_date,
'options2' => ['class'=>'clear', 'placeholder' => '选择日期', 'autocomplete'=>'off'],
'layout' => $layout,
'pluginOptions' => [
'autoclose' => true,
'format' => 'yyyy-mm-dd',
'todayHighlight' => true
],
'pluginEvents' => ["change" => "function(e) { $('form').submit(); }"]
]);
?>
</div>
<div class="col-md-2 col-sm-2" style='width:210px'>
<?= $form->field($model, 'uid')->textInput(['class'=>'form-control clear', 'placeholder'=>'UID / 姓名 / 手机 / 邮箱', 'style'=>'width:170px', 'autocomplete'=>'off'])->label(false) ?>
</div>
<div class="col-md-3 col-sm-3" style='width:265px;'>
<div class="form-group">
<?= Html::submitButton('搜索', ['class' => 'btn btn-primary']) ?>
<?= Html::button('重置筛选', ['class' => 'btn btn-default', 'onclick' => '$(".clear").val("");$("select").val("");']) ?>
<?= Html::button('导出', ['class' => 'btn btn-danger', 'onclick' => 'exportOrder()']) ?>
</div>
</div>
</div>
<?php ActiveForm::end(); ?>
<script> $("select").bind("change",function(){ $('form').submit(); }); </script>
<?php
use yii\grid\GridView;
use common\widgets\Pjax;
$jsAsset = $this->getAssetManager()->getBundle(\backend\assets\AppAsset::className())->baseUrl;
$columns = [
['class' => 'yii\grid\SerialColumn', 'headerOptions'=>['style'=>'width:2%;']],
[
'label' => 'UID',
'attribute' => 'uid',
'options' => ['width' => '80px;'],
/*'headerOptions' => ['class' => 'sort-numerical']*/
],
[
'label' => '订单号',
'attribute' => 'order_id',
'options' => ['width' => '80px;']
],
[
'label' => '货币对',
'attribute' => 'symbol_couple',
'contentOptions' => ['style' => 'white-space: nowrap;'],
'options' => ['width' => '60px;']
],
[
'label' => '订单状态',
'attribute' => 'status',
'options' => ['width' => '60px;']
],
[
'label' => '交易类型',
'attribute' => 'ty',
'options' => ['width' => '50px;']
],
[
'label' => '委托时间',
'attribute' => 'create_time',
'contentOptions' => ['style' => 'white-space: nowrap;'],
'options' => ['width' => '120px'],
],
[
'label' => '委托数量',
'attribute' => 'place_quantity',
'options' => ['width' => '80px;'],
],
[
'label' => '委托价格',
'attribute' => 'place_price',
'options' => ['width' => '100px;'],
],
[
'label' => '委托金额',
'attribute' => 'place_cost',
'options' => ['width' => '100px;'],
],
[
'label' => '成交时间',
'attribute' => 'update_time',
'options' => ['width' => '120px'],
'contentOptions' => ['style' => 'white-space: nowrap;'],
],
[
'label' => '成交数量',
'attribute' => 'done_amount',
'options' => ['width' => '10%'],
'contentOptions' => ['style' => 'white-space: nowrap;'],
],
[
'label' => '成交价格',
'attribute' => 'done_price',
'options' => ['width' => '100px;'],
],
[
'label' => '成交金额',
'attribute' => 'done_cost',
'options' => ['width' => '10%;'],
'contentOptions' => ['style' => 'white-space: nowrap;'],
],
[
'label' => '手续费',
'attribute' => 'poundage',
'options' => ['width' => '10px;'],
],
[
'label' => '返还比例',
'attribute' => 'poundage_return_ratio',
'options' => ['width' => '10px;'],
]
];
$layout = <<< HTML
{items}
<div class="col-md-4 col-sm-4" style="padding-top: 15px;">
<select id="freshen-order" style="color: #ce9795">
<!--<option value="15">15</option>-->
<option value="30">30</option>
<option value="60">1分钟</option>
<option value="300">5分钟</option>
<option value="0" selected>停止</option>
</select> <span style="color: #ce9795">自动刷新</span>&nbsp;&nbsp;&nbsp;&nbsp;
{summary}
</div>
<div class="col-md-8 col-sm-8">
<div style="text-align:right;">{pager}</div>
</div>
HTML;
?>
<div class="portlet-body">
<?php Pjax::begin(['timeout' => 1000]); ?>
<?= $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'formatter' => ['class' => 'yii\i18n\Formatter', 'nullDisplay' => ' -'],
'options' => ['class' => 'grid-view table-scrollable'],
'tableOptions' => ['class' => 'table table-striped table-bordered table-hover table-checkable order-column dataTable no-footer'],
'layout' => $layout,
'summaryOptions' => ['class' => 'pagination'],
'pager' => Yii::$app->params['pager'],
'columns' => $columns
]); ?>
</div>
<?php $this->registerJsFile($jsAsset.'/global/plugins/js.cookie.min.js');?>
<script>
var totalCount = <?= $dataProvider->getTotalCount() ? $dataProvider->getTotalCount() : 0 ?>;
var Loop = {
"_tmp" : null,
"_key" : 'freshen_cycle',
"_timer" : null,
"setTimer" : function () {
var that=this;
if (Cookies.get(that._key)>0) {
that._timer = Cookies.get(that._key)*1000;
} else {
that._timer = document.getElementById("freshen-order").value;
Cookies.set(Loop._name, that._timer);
}
},
"run" : function() {
var that=this;
//设置间隔
that.setTimer();
//清除上次循环设置
that.stop();
that._tmp = setInterval("$('form').submit()", that._timer);
},
"stop" : function() {
var that=this;
if (that._tmp != null) {
clearInterval(that._tmp);
}
},
"init" : function () {
if (Cookies.get(Loop._key) != document.getElementById("freshen-order").value) {
if (Cookies.get(Loop._key) == 'undefined') {
$("#freshen-order").find("option[value='0']").attr("selected", true);
} else {
$("#freshen-order").find("option[value='"+Cookies.get(Loop._key)+"']").attr("selected", true);
}
} else {
Loop.run();
}
}
};
function exportOrder() {
layer.confirm("将导出 " + totalCount + " 条记录,是否继续?", {
title: '导出提示',
//skin: 'layui-layer-lan',
btn: ['确认','取消'],
btnAlign: 'r',
closeBtn: 1
}, function(){
$(this).attr('disabled', true);
var url = window.location.href;
var href = url.replace('/trade/index', '/trade/export');
if (totalCount != 'undefinded' && totalCount >= 3000) {
layer.confirm("导出总数超过3000条,继续将只导出部分记录? \u000d(需要全部请联系后台开发)", {
title: '再次提示',
btnAlign: 'r'
}, function(){
window.location.href = href;
});
} else {
window.location.href = href;
}
layer.closeAll('dialog');
$(this).attr('disabled', false);
});
}
</script>
<?php
$tBody = isset($tBody) && is_string($tBody) ? $tBody : '';
$js = <<<JS
$(document).ready(function(){
Loop.init();
$('tbody').prepend('$tBody');
$("#freshen-order").change(function() {
if ($(this).val() == 0) {
Cookies.remove(Loop._key);
Loop.stop();
} else {
Cookies.set(Loop._key, $(this).val());
Loop.run();
}
return true;
});
/*$("#manageordersearch-status").bind("change", function () {
layer.tips('<span style="color:red">因紧急,暂只提供查询仅用户已成交记录<span><br><span style="color:grey">看不到此行提示则说明可查询全部类型</span>', '#manageordersearch-status', {tips: 3, time:2000});
});*/
});
JS;
$this->registerJs($js);
?>
<?php Pjax::end(); ?>
<?php
namespace common\business;
use common\models\parse\Currency;
use common\models\gli\AssetsFlow;
use common\models\gli\AssetsWallet;
use common\helpers\CurrencyHelper;
use common\helpers\PublicHelper;
use common\models\gli\Cache;
use common\models\parse\Order;
use common\models\parse\Transfer;
use yii\helpers\ArrayHelper;
use Yii;
/**
* 推算资产
* Class AssetBusiness
* @package common\business
*/
class AssetBusiness
{
const INIT_DATE = '2017-11-03 00:00:00';//初始化时间
const LAST_TIME_KEY = 'AssetsFlow_LastTime';//用于存储最大时间的缓存键
protected $filterSymbol = []; //用于过滤计算特殊币种
protected $coinMap = null;
protected function getCoinMap()
{
if ($this->coinMap == null)
$this->coinMap = Currency::find()->select('symbol_id')->column();
return $this->coinMap;
}
/**
* procedure init
* @note 程序计算数据正确的前提是:order表和transfer表正常,Market价格可以获取到
* @date 2017/06/20
*/
public function work()
{
Cache::deleteData(static::LAST_TIME_KEY);//todo
try {
/* transfer 最大时间 */
$time1 = Transfer::find()->select('create_time')->orderBy('id desc')->limit(1)->scalar();
$conn = Yii::$app->trade_db;
$dbArray = $conn->createCommand("SHOW DATABASES LIKE 'trade\_%\_%'")->queryColumn();
/* order 最大时间 */
$temp1 = [];
foreach ($dbArray as $dk => $dbName) {
if (in_array($dbName, ['trade_BTC_CNY', 'trade_BTC_ETH'])) {
unset($dbArray[$dk]);
continue;
}
$temp1[] = "(SELECT max(update_time) time FROM {$dbName}.`orderr` where status = 1)";
}
$sql = "SELECT max(temp.time) FROM (" . implode(' UNION ALL ', $temp1) . ") AS temp";
$time2 = $conn->createCommand($sql)->queryScalar();
/* stop时间 */
$stopTime = strtotime(max($time1, $time2)) - 3;
$stopDate = date('Y-m-d H:i:s', $stopTime);
/* 机器人账号 todo */
$robots = PublicHelper::getRobotUserIds();
while(1) {
/* gli_assets_flow 最大时间 */
$lastTime = ($mt = Cache::getData(static::LAST_TIME_KEY)) ? $mt : strtotime(static::INIT_DATE);
/* 单次 计算范围 */
$batchRange = is_numeric($lastTime) && ($stopTime - $lastTime) < 600 ? 60 : 21600;
/* 开始时间,结束时间 */
list($st, $ed) = [$lastTime, min($lastTime + $batchRange, $stopTime)];
if ($st == $ed)
break;
printf("%s ~ %s \r\n", date('Y-m-d H:i:s', $st), date('m-d H:i:s', $ed));
$addTmp = [];
/* 交易 */
$where = 'and `update_time` between :st and :ed';
foreach ($dbArray as $dbName) {
$arr = explode('_', $dbName);
$temp[] = "(SELECT *,'" . $arr[2] . "' symbol_base FROM {$dbName}.`orderr` where status = 1 {$where})";
}
$sql = "SELECT temp.* FROM (" . implode(' UNION ', $temp) . ") AS temp";
$query1 = $conn->createCommand($sql,
[':st' => date('Y-m-d H:i:s', $st), ':ed' => date('Y-m-d H:i:s', $ed)]
)->queryAll();
foreach ($query1 as $item) {
$symbol_name = CurrencyHelper::getCurrencyName($item['symbol_id']>>16);
if (in_array($symbol_name, $this->filterSymbol))
continue;
$addTime = strtotime($item['update_time']);
$coinSign = $item['ty'] == Order::TY_BUY ? 1 : -1;
$symbol_baseId = CurrencyHelper::getCurrencyId($item['symbol_base']);
$orderTmp = [];
$orderTmp['key'] = 'bind_order';
$orderTmp['bind_order'] = $item['order_id'];
$orderTmp['symbol_id'] = $item['symbol_id']>>16;
$orderTmp['symbol_name']= $symbol_name;
$orderTmp['price'] = $item['cost'] / ($item['done_quantity'] / 1e4) * 1e4;
$orderTmp['type'] = $item['ty'] == Order::TY_BUY ? AssetsFlow::TYPE_BUY : AssetsFlow::TYPE_SELL;
$orderTmp['change_amount'][$item['symbol_id']>>16] = $item['done_quantity'] * $coinSign;
$orderTmp['change_amount'][$symbol_baseId] = $item['cost'] * $coinSign * -1;
$orderTmp['addtime'] = $addTime;
$orderTmp['remark'] = "order [{$symbol_name} ~ " . $item['symbol_base'] . ']:[' .
$orderTmp['change_amount'][$item['symbol_id']>>16] . ' ~ '. $orderTmp['change_amount'][$symbol_baseId] . ']';
$addTmp[$item['user_id']][$addTime][] = $orderTmp;
}
/* 转账 */
$query2 = Transfer::find()
->select('log_id,symbol_id,from_uid, to_uid, amount, create_time')
->where(['is_ok' => 1])
->andFilterWhere(['between', 'create_time', date('Y-m-d H:i:s', $st), date('Y-m-d H:i:s', $ed)]);
foreach ($query2->asArray()->all() as $item) {
$symbol_name = CurrencyHelper::getCurrencyName($item['symbol_id']);
if (in_array($symbol_name, $this->filterSymbol))
continue;
$addTime = strtotime($item['create_time']);
foreach (['from_uid', 'to_uid'] as $uidTemp) {
$coinSign = $uidTemp == 'to_uid' ? 1 : -1;
$transferTmp = [];
$transferTmp['key'] = 'bind_transfer';
$transferTmp['bind_transfer'] = $item['log_id'];
$transferTmp['symbol_id'] = $item['symbol_id'];
$transferTmp['symbol_name'] = $symbol_name;
//$transferTmp['price'] = null;
$transferTmp['type'] = AssetsFlow::getType($item['from_uid'], $item['to_uid']);
$transferTmp['change_amount'][$item['symbol_id']] = $item['amount'] * $coinSign;
$transferTmp['addtime'] = $addTime;
$transferTmp['remark'] = "transfer [{$symbol_name}]:[" .
$transferTmp['change_amount'][$item['symbol_id']] . ']';
$addTmp[$item[$uidTemp]][$addTime][] = $transferTmp;
}
}
Cache::setData(static::LAST_TIME_KEY, $ed);//设置下一次循环初始时间
/* 停止检测 */
if (!$addTmp) {
$maxFlow = AssetsFlow::find()->max('addtime');
if ($maxFlow >= $stopTime) {
break;
} else {
continue;
}
}
if (isset($addTmp2) && $addTmp2 == $addTmp) {
break;
}
$addTmp2 = $addTmp;
foreach ($addTmp as $user_id => $info) {
$lastOne = null;
ksort($info);//按时间递增排序
foreach ($info as $time => $rows) {
ArrayHelper::multisort($rows,
['bind_order', 'bind_transfer'],
[SORT_ASC, SORT_ASC]
);//按单号递增排序
$lastOne = AssetsFlow::find()
->with('wallet')
->where(['and',
['user_id' => $user_id],
['<=', 'addtime', $time],
])
->orderBy(['id' => SORT_DESC])
->limit(1)
->asArray()
->one();
$flowId = isset($lastOne['flow_id']) ? $lastOne['flow_id']+1 : 1;
foreach ($rows as $row) {
$one = AssetsFlow::findOne([ $row['key'] => $row[ $row['key'] ] ]);
if (!$one)
$one = new AssetsFlow();
$one->$row['key'] = $row[ $row['key'] ];
$one->flow_id = $flowId;
$one->user_id = $user_id;
$one->symbol_id = $row['symbol_id'];
$one->symbol_name = $row['symbol_name'];
$one->price = isset($row['price']) ? $row['price'] : null;
$one->type = $row['type'];
$one->amount = $row['change_amount'][ $row['symbol_id'] ];
$one->addtime = $row['addtime'];
$one->remark = $row['remark'];
if ($one->save(false)) {
printf("save %s : %s \r\n", $row['key'], $row[$row['key']]);
/* 保存wallet变化 */
foreach ($this->getWalletInfo($user_id, $flowId -1) as $symbolKey => $symbolVal) {
if (!isset($row['change_amount'][$symbolKey]))
continue;
$wOne = AssetsWallet::findOne(['relation_id' => $one->id, 'symbol_id' => $symbolKey]);
if (!$wOne)
$wOne = new AssetsWallet();
$wOne->relation_id = $one->id;
$wOne->user_id = $user_id;
$wOne->symbol_id = $symbolKey;
$wOne->amount = $symbolVal + (isset($row['change_amount'][$symbolKey]) ? $row['change_amount'][$symbolKey] : 0);
if ($wOne->save()) {
//printf("save wallet : %s - %s \r\n", $one->id, $symbolKey);
}
}
}
}
}
}
}
} catch (\Exception $e) {
$err = $e->getMessage().PHP_EOL;
$err .= $e->getLine().PHP_EOL;
$err .= $e->getFile().PHP_EOL;
var_dump($err);die;
}
}
/**
* [获取该id的资产信息]
* @param $userId
* @param $flowId
* @return array
*/
protected function getWalletInfo($userId, $flowId)
{
$id = AssetsFlow::find()->select('id')->where(['user_id' => $userId, 'flow_id' => $flowId])->scalar();
$one = AssetsWallet::find()->select('amount, symbol_id')->where(['relation_id' => $id])->indexBy('symbol_id')->column();
$info = [];
foreach ($this->getCoinMap() as $symbol) {
$info[$symbol] = isset($one[$symbol]) ? $one[$symbol] : 0;
}
return $info;
}
}
\ No newline at end of file
<?php
namespace common\business;
/**
* Created by PhpStorm.
* Author: libingke
* Date: 2017/11/3
* Time: 11:53
*/
class UserBusiness
{
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/27
* Time: 10:45
*/
namespace weChat;
use yii\base\InvalidCallException;
/**
* Class AttributeSet
* @package weChat
*/
class AttributeSet implements AttributeSetInterface
{
/**
* @var array
*/
private $_attributes;
/**
* @param string $name
* @param bool $isAttribute
* @throws WeChatException
*/
public function has($name, $isAttribute = true)
{
if (is_string($name)) {
if ($isAttribute !== true) {
if (property_exists($this, $name)) {
return true;
}
} else {
if (isset($this->_attributes[$name])) {
return true;
}
}
return false;
} else {
throw new WeChatException('不支持的属性类型:' . gettype($name));
}
}
public function set($field, $value)
{
$setter = 'set' . $field;
if (method_exists($this, $setter)) {
// set property
$this->$setter($value);
}
if (method_exists($this, 'get' . $field)) {
throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $field);
}
$this->setAttribute($field, $value);
}
public function get($field)
{
$getter = 'get' . $field;
if (method_exists($this, $getter)) {
return $this->$getter();
}
if (method_exists($this, 'set' . ucfirst($field))) {
throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $field);
}
return $this->getAttribute($field);
}
public function setAttribute($field, $value)
{
if (is_string($field)) {
$this->_attributes[$field] = $value;
}
return $this;
}
public function getAttribute($field)
{
if (isset($this->_attributes[$field])) {
return $this->_attributes[$field];
}
return null;
}
public function setAttributes(array $array)
{
foreach ($array as $key => $value) {
$this->setAttribute($key, $value);
}
return $this;
}
public function getAttributes()
{
return $this->_attributes;
}
public function generateId()
{
return $this->getRandomId();
}
/**
* Returns a random Content-ID or Message-ID.
*
* @return string
*/
protected function getRandomId()
{
$idLeft = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true));
$idRight = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'wechat.generated';
$id = $idLeft.'@'.$idRight;
try {
$this->_assertValidId($id);
} catch (WeChatException $e) {
$id = $idLeft.'@swift.generated';
}
return $id;
}
/**
* Throws an Exception if the id passed does not comply with RFC 2822.
*
* @param string $id
*
* @throws WeChatException
*/
private function _assertValidId($id)
{
throw new WeChatException('Invalid ID given <'.$id.'>');
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/27
* Time: 10:45
*/
namespace weChat;
/**
* Interface AttributeSetInterface
* @package weChat
*/
interface AttributeSetInterface
{
public function has($name);
public function set($field, $value);
public function get($field);
public function setAttribute($array, $value);
public function getAttribute($field);
public function setAttributes(array $array);
public function getAttributes();
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/27
* Time: 10:45
*/
namespace weChat;
use yii\base\ErrorHandler;
use yii\base\Object;
use Yii;
/**
* Class BaseMessage
* @package weChat
*/
abstract class BaseMessage extends Object implements MessageInterface
{
/**
* @var WeChatInterface the weChat instance that created this message.
*/
public $weChat;
/**
* Sends this email message.
* @param WeChatInterface $weChat the weChat that should be used to send this message.
* @return bool whether this message is sent successfully.
*/
public function send(WeChatInterface $weChat = null)
{
if ($weChat === null && $this->weChat === null) {
$weChat = Yii::$app->get('weChat');
} elseif ($weChat === null) {
$weChat = $this->weChat;
}
return $weChat->send($this);
}
/**
* PHP magic method that returns the string representation of this object.
* @return string the string representation of this object.
*/
public function toString()
{
try {
return $this->toString();
} catch (\Exception $e) {
ErrorHandler::convertExceptionToError($e);
return '';
}
}
}
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/27
* Time: 10:45
*/
namespace weChat;
use Yii;
use yii\base\Component;
use yii\base\InvalidConfigException;
abstract class BaseWeChat extends Component implements WeChatInterface
{
/**
* @event MailEvent an event raised right before send.
* You may set [[WeChatEvent::isValid]] to be false to cancel the send.
*/
const EVENT_BEFORE_SEND = 'beforeSend';
/**
* @event MailEvent an event raised right after send.
*/
const EVENT_AFTER_SEND = 'afterSend';
public $messageConfig = [];
/**
* @var string the default class name of the new message instances created by [[createMessage()]]
*/
public $messageClass = 'weChat\Message';
/**
* Creates a new message instance
*/
public function compose()
{
return $this->createMessage();
}
/**
* Creates a new message instance.
* @return Object | MessageInterface message instance.
*/
protected function createMessage()
{
$config = $this->messageConfig;
if (!array_key_exists('class', $config)) {
$config['class'] = $this->messageClass;
}
$config['weChat'] = $this;
return Yii::createObject($config);
}
/**
* Sends the given email message.
* @param MessageInterface $message email message instance to be sent
* @return bool whether the message has been sent successfully
*/
public function send($message)
{
if (!$this->beforeSend($message)) {
return false;
}
$isSuccessful = $this->sendMessage($message);
$this->afterSend($message, $isSuccessful);
return $isSuccessful;
}
/**
* @param array $messages list of email messages, which should be sent.
* @return int number of messages that are successfully sent.
*/
public function sendMultiple(array $messages)
{
$successCount = 0;
foreach ($messages as $message) {
if ($this->send($message)) {
$successCount++;
}
}
return $successCount;
}
/**
* @param MessageInterface $message the message to be sent
* @return bool whether the message is sent successfully
*/
abstract protected function sendMessage($message);
public function beforeSend($message)
{
$event = new WeChatEvent(['message' => $message]);
$this->trigger(self::EVENT_BEFORE_SEND, $event);
return $event->isValid;
}
public function afterSend($message, $isSuccessful)
{
$event = new WeChatEvent(['message' => $message, 'isSuccessful' => $isSuccessful]);
$this->trigger(self::EVENT_AFTER_SEND, $event);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/27
* Time: 10:45
*/
namespace weChat;
class Connect
{
/** The Transport used to send messages */
private $_transport;
/**
* @param WeChat_Transport $transport
*/
public function __construct(WeChat_Transport $transport)
{
$this->_transport = $transport;
}
/**
* Create a new WeChat conn instance.
*
* @param WeChat_Transport $transport
*
* @return self
*/
public static function newInstance($config)
{
return new self($config);
}
/**
* @param Message $message
*/
public function send($message)
{
if (!$this->getTransport()->isStarted()) {
$this->getTransport()->start();
}
return $this->getTransport()->send($message);
}
/**
* createGroupChat
* @param $name
* @param $owner
* @param $userList
* @param null $chatId
* @return array
*/
public function createGroupChat($name, $owner, $userList, $chatId = null)
{
if (!$this->getTransport()->isStarted()) {
$this->getTransport()->start();
}
return $this->getTransport()->createGroupChat($name, $owner, $userList, $chatId);
}
/**
* The Transport used to send messages.
*
* @return WeChat_Transport
*/
public function getTransport()
{
return $this->_transport;
}
}
\ No newline at end of file
This diff is collapsed.
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/27
* Time: 10:45
*/
namespace weChat;
/**
* Class Message
* @package weChat
*/
class Message extends BaseMessage
{
/**
* @var MimeMessageInterface
*/
public $setter = 'weChat/MimeMessage';
private $_chatMessage;
/**
* __clone
*/
public function __clone()
{
if (is_object($this->_chatMessage)) {
$this->_chatMessage = clone $this->_chatMessage;
}
}
/**
* @return MimeMessageInterface instance.
*/
public function getSetter()
{
if (!is_object($this->_chatMessage)) {
$this->_chatMessage = $this->createChatMessage(new $this->setter());
}
return $this->_chatMessage;
}
/**
* @return MimeMessageInterface instance.
*/
protected function createChatMessage(MimeMessageInterface $setter)
{
return $setter;
}
/******** 配置 *******/
/**
* @inheritdoc
*/
public function getSendType()
{
return $this->getSetter()->getSendType();
}
/**
* @inheritdoc
*/
public function setSendType($type)
{
$this->getSetter()->setSendType($type);
return $this;
}
/**
* @inheritdoc
*/
public function isToAll()
{
return $this->getSetter()->isToAll();
}
/**
* @inheritdoc
*/
public function getTitle()
{
return $this->getSetter()->getTitle();
}
/**
* @inheritdoc
*/
public function setTitle($title)
{
$this->getSetter()->setTitle($title);
return $this;
}
/**
* @inheritdoc
*/
public function getUrl()
{
return $this->getSetter()->getUrl();
}
/**
* @inheritdoc
*/
public function setUrl($url)
{
$this->getSetter()->setUrl($url);
return $this;
}
/**
* @inheritdoc
*/
public function getParam($k)
{
return $this->getSetter()->getParam($k);
}
/**
* @inheritdoc
*/
public function setParam($k, $v)
{
$this->getSetter()->setParam($k, $v);
return $this;
}
/**
* @inheritdoc
*/
public function getTo()
{
return $this->getSetter()->getTo();
}
/**
* @inheritdoc
*/
public function setTo($to)
{
$this->getSetter()->setTo($to);
return $this;
}
/**
* @inheritdoc
*/
public function setMessageType($type)
{
$this->getSetter()->setMessageType($type);
return $this;
}
/**
* @inheritdoc
*/
public function getMessageType()
{
return $this->getSetter()->getMessageType();
}
/**
* @inheritdoc
*/
public function setSendBody($body)
{
$this->getSetter()->setSendBody($body);
return $this;
}
/**
* @inheritdoc
*/
public function getSendBody()
{
return $this->getSetter()->getSendBody();
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/27
* Time: 10:45
*/
namespace weChat;
/**
* Interface MessageInterface
* @package weChat
*/
interface MessageInterface
{
public function isToAll();
public function getSendType();
/**
* @param integer $type [0:all 1:按成员to user 2:按部门to party 3:按标签to tag 4:群聊]
*/
public function setSendType($type);
public function getMessageType();
public function setTitle($title);
public function getTitle();
public function setUrl($url);
public function getUrl();
public function setParam($k, $v);
public function getParam($k);
/**
* @param integer $type 默认text,其它再说[0:text 1:image 2:voice 3:video 4:file 5:textcard 6:news 7:mpnews]
*/
public function setMessageType($type);
public function getTo();
/**
* @param string $to 多个接收者用‘|’分隔
*/
public function setTo($to);
public function setSendBody($body);
public function getSendBody();
public function send(WeChatInterface $weChat = null);
public function toString();
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/27
* Time: 10:45
*/
namespace weChat;
/**
* Class MimeMessage
* @package weChat
*/
class MimeMessage extends AttributeSet implements MimeMessageInterface
{
const SEND_TO_ALL = '@all';
const SEND_TYPE_DEFAULT = 'touser';
const MESSAGE_TYPE_DEFAULT = 'text';
private $_send_type_map = [
0 => '@all',
1 => 'touser',
2 => 'toparty',
3 => 'totag',
4 => 'groupChat',
];
private $_message_type_map = [
0 => 'text',
1 => 'image',
2 => 'voice',
3 => 'video',
4 => 'file',
5 => 'textcard',
6 => 'news',
7 => 'mpnews'
];
public function isToAll()
{
if ($this->getSendType() == self::SEND_TO_ALL) {
return true;
}
return false;
}
/**
* @return $this
*/
public function setSendType($type)
{
if (!is_numeric($type)) {
throw new WeChatException(__FUNCTION__ . ' 参数类型必须是numeric');
} elseif (isset($this->_send_type_map[$type])) {
$this->set('send-type', $this->_send_type_map[$type]);
} else {
throw new WeChatException(__FUNCTION__ . ' 参数范围无效');
}
return $this;
}
/**
* @return integer
*/
public function getSendType()
{
$type = $this->get('send-type');
return $type ?: self::SEND_TYPE_DEFAULT;
}
/**
* @return $this
*/
public function setMessageType($type)
{
if (!is_numeric($type)) {
throw new WeChatException(__FUNCTION__ . ' 参数类型必须是numeric');
} elseif (isset($this->_message_type_map[$type])) {
$this->set('message-type', $this->_message_type_map[$type]);
} else {
throw new WeChatException(__FUNCTION__ . ' 参数范围无效');
}
return $this;
}
/**
* @return integer
*/
public function getMessageType()
{
$type = $this->get('message-type');
return $type ? : self::MESSAGE_TYPE_DEFAULT;
}
/**
* @return $this
*/
public function setTitle($title)
{
if (!is_string($title)) {
throw new WeChatException(__FUNCTION__ . ' 参数类型必须是string');
}
$this->set('message-title', $title);
return $this;
}
/**
* @return integer
*/
public function getTitle()
{
$title = $this->get('message-title');
return $title ? : '';
}
/**
* @return $this
*/
public function setParam($k, $v)
{
$this->set("params-$k", $v);
return $this;
}
/**
* @return integer
*/
public function getParam($k)
{
return $this->get("params-$k");
}
/**
* @return $this
*/
public function setUrl($url)
{
if (!is_string($url)) {
throw new WeChatException(__FUNCTION__ . ' 参数类型必须是string');
}
$this->set('card-url', $url);
return $this;
}
/**
* @return integer
*/
public function getUrl()
{
$url = $this->get('card-url');
return $url ? : '';
}
/**
* @return $this
*/
public function setTo($to)
{
if (is_string($to)) {
$this->set('send-address', $to);
} else {
throw new WeChatException(__FUNCTION__ . ' 参数类型必须是string');
}
return $this;
}
/**
* @return array
*/
public function getTo()
{
return $this->get('send-address');
}
/**
* @return $this
*/
public function setSendBody($body)
{
$this->set('send-body', $body);
return $this;
}
/**
* @return null
*/
public function getSendBody()
{
return $this->get('send-body');
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/27
* Time: 10:45
*/
namespace weChat;
/**
* Interface MimeMessageInterface
* @package weChat
*/
interface MimeMessageInterface
{
public function isToAll();
public function getSendType();
public function setSendType($type);
public function getMessageType();
public function setMessageType($type);
public function setTitle($title);
public function getTitle();
public function setUrl($url);
public function getUrl();
public function setParam($k, $v);
public function getParam($k);
public function getTo();
public function setTo($to);
public function setSendBody($body);
public function getSendBody();
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/27
* Time: 10:45
*/
namespace weChat;
use Yii;
use yii\base\InvalidConfigException;
/**
* Class WeChat
* @package weChat
*/
class WeChat extends BaseWeChat
{
/**
* @var string message default class name.
*/
public $messageClass = 'weChat\Message';
/**
* @var connect instance.
*/
private $_connect;
/**
* @var WeChat_Transport|array
*/
private $_transport = [];
/**
* @param Message $message
* @return bool
*/
protected function sendMessage($message)
{
return $this->getWeChatConnect()->send($message);
}
/**
* @return array|Connect instance or array configuration.
*/
public function getWeChatConnect()
{
if (!is_object($this->_connect)) {
$this->_connect = $this->createWeChatConn();
}
return $this->_connect;
}
/**
* @param array|WeChat_Transport $transport
* @throws InvalidConfigException
*/
public function setTransport($transport)
{
if (!is_array($transport) && !is_object($transport)) {
throw new InvalidConfigException('"' . get_class($this) . '::transport" should be either object or array, "' . gettype($transport) . '" given.');
}
$this->_transport = $transport;
}
/**
* @return Object|WeChat_Transport
*/
public function getTransport()
{
if (!is_object($this->_transport)) {
$this->_transport = $this->createTransport($this->_transport);
}
return $this->_transport;
}
/**
* Creates WeChat Connect instance.
* @return Connect instance.
*/
protected function createWeChatConn()
{
return Connect::newInstance($this->getTransport());
}
/**
* Creates email transport instance by its array configuration.
* @param array $config transport configuration.
* @throws \yii\base\InvalidConfigException on invalid transport configuration.
* @return Object WeChat_Transport instance.
*/
protected function createTransport(array $config)
{
if (!isset($config['class'])) {
$config['class'] = 'weChat\WeChat_Transport';
}
return $this->createChatObject($config);
}
/**
* @param array $config object configuration
* @return Object created object
* @throws \yii\base\InvalidConfigException on invalid configuration.
*/
protected function createChatObject(array $config)
{
if (isset($config['class'])) {
$className = $config['class'];
unset($config['class']);
} else {
throw new InvalidConfigException('Object configuration must be an array containing a "class" element.');
}
$object = Yii::createObject($className);
if (!empty($config)) {
$reflection = new \ReflectionObject($object);
foreach ($config as $name => $value) {
if ($reflection->hasProperty($name) && $reflection->getProperty($name)->isPublic()) {
$object->$name = $value;
} else {
$setter = 'set' . $name;
if ($reflection->hasMethod($setter) || $reflection->hasMethod('__call')) {
$object->$setter($value);
} else {
throw new InvalidConfigException('Setting unknown property: ' . $className . '::' . $name);
}
}
}
}
return $object;
}
/**
* 创建群聊
* @param $name
* @param $owner
* @param $userList
* @param null $chatId
* @return array
*/
public function createGroupChat($name, $owner, $userList, $chatId = null)
{
return $this->getWeChatConnect()->createGroupChat($name, $owner, $userList, $chatId);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/27
* Time: 10:45
*/
namespace weChat;
use yii\base\Event;
/**
* Class WeChatEvent
* @package weChat
*/
class WeChatEvent extends Event
{
/**
* @var MessageInterface the mail message being send.
*/
public $message;
/**
* @var bool if message was sent successfully.
*/
public $isSuccessful;
/**
* @var bool whether to continue sending an email. Event handlers of
* [[\yii\mail\BaseMailer::EVENT_BEFORE_SEND]] may set this property to decide whether
* to continue send or not.
*/
public $isValid = true;
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/28
* Time: 14:16
*/
namespace weChat;
/**
* Class WeChatException
* @package weChat
*/
class WeChatException extends \Exception
{
/**
* WeChatException constructor.
* @param string $message
* @param int $code
* @param \Exception|null $previous
*/
public function __construct($message, $code = 0, \Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
public function getName()
{
return "WeChat Exception";
}
}
<?php
/**
* Created by PhpStorm.
* User: libingke
* Date: 2018/4/27
* Time: 10:45
*/
namespace weChat;
/**
* Interface WeChatInterface
* @package weChat
*/
interface WeChatInterface
{
/**
* Creates a new message instance
* @return MessageInterface message instance.
*/
public function compose();
/**
* @param MessageInterface
* @return bool whether the message has been sent successfully
*/
public function send($message);
/**
* Sends multiple messages at once.
* @param array $messages list
* @return int number of messages that are successfully sent.
*/
public function sendMultiple(array $messages);
/**
* createGroupChat
* @param $name
* @param $owner
* @param $userList
* @param $chatId
* @return mixed
*/
public function createGroupChat($name, $owner, $userList, $chatId);
}
\ No newline at end of file
<?php
namespace weChat;
use \yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "{{wechat_token}}".
*
* @property string $corp_id
* @property string $access_token
* @property integer $expires_in
* @property integer $apply_time
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
*/
class WeChatToken extends ActiveRecord
{
const STATUS_DEFAULT = 0; //default
const STATUS_SEND = 1; //已发送
const LEVEL_DEFAULT = 0; //default
const LEVEL_SEND = 1; //报错级别
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
],
'value' => function () {return date('Y-m-d H:i:s');}
]
];
}
public static function tableName()
{
return 'wechat_token';
}
/**
* saveToken
* @param $appId
* @param $params
*/
public static function saveToken($appId, $params)
{
$one = WeChatToken::findOne(['corp_id' => $appId]);
if (!$one) {
$one = new WeChatToken();
$one->corp_id = $appId;
}
$one->access_token = $params['access_token'];
$one->expires_in = $params['expires_in'];
$one->apply_time = $params['apply_time'];
$one->save();
}
}
\ No newline at end of file
This diff is collapsed.
<?php
namespace common\components\app;
/**
* App
* app表
* -----------------
* @author Verdient。
* @version 1.0.0
*/
class App extends Curd
{
/**
* init()
* 初始化
* --------------
* @author Verdient。
*/
public function init(){
parent::init();
$this->_url = $this->_url . '/manage-app-version';
}
}
\ No newline at end of file
<?php
namespace common\components\app;
use Yii;
use yii\base\Component;
/**
* AppInterface
* app接口
* ------------------
* @author Verdient。
* @version 1.0.0
*/
class AppInterface extends Component
{
/**
* @var public String $key
* 签名密钥
* -----------------------
* @method Config
* @author Verdient。
*/
public $key;
/**
* @var public $protocol
* 访问协议
* ---------------------
* @method Config
* @author Verdient。
*/
public $protocol = '';
/**
* @var public $host
* 域名
* -----------------
* @method Config
* @author Verdient。
*/
public $host = '';
/**
* @var public $port
* 端口
* -----------------
* @method Config
* @author Verdient。
*/
public $port = '';
/**
* @var public $_urlPrefix
* URL 路径前缀
* -----------------------
* @author Verdient。
*/
protected $_urlPrefix;
/**
* init()
* 初始化
* ------
* @param String $publicKey 公钥
* -----------------------------
* @return Array / false
* @author Verdient。
*/
public function init(){
parent::init();
if(!$this->protocol){
$this->protocol = Yii::$app->request->isSecureConnection ? 'https' : 'http';
}
if(!$this->host){
$this->host = explode(':', $_SERVER['HTTP_HOST'])[0];
}
$this->_urlPrefix = $this->protocol . '://' . $this->host . ($this->port ? (($this->protocol == 'https' && $this->port == 443) || ($this->protocol == 'http' && $this->port == 80) ? '' : (':' . $this->port)) : '');
}
/**
* getApp(Mixed $id)
* 获取app实例
* ----------------------
* @param Mixed $id 活动编号
* ------------------------
* @return Object
* @author Verdient。
*/
public function getApp($id = null){
return new App($this->key, $this->_urlPrefix, $id);
}
}
\ No newline at end of file
<?php
namespace common\components\app;
use Yii;
use yii\base\Model;
use yii\base\InvalidCallException;
use yii\helpers\ArrayHelper;
use yii\helpers\Inflector;
use yii\base\InvalidParamException;
use common\components\Base;
/**
* Curd
* 增删改查
* -------
* @author Verdient。
* @version 1.0.0
*/
class Curd extends Base
{
/**
* @var protected $_id
* 活动编号
* -------------------
* @author Verdient。
*/
protected $_id;
/**
* @var protected $_expand
* 扩展模型
* -----------------------
* @author Verdient。
*/
protected $_expand;
/**
* @var public $page
* 页码
* -----------------------
* @author Verdient。
*/
public $page;
/**
* @var public $page
* 分页大小
* -----------------------
* @author Verdient。
*/
public $page_size;
/**
* @var public $version
* 版本
* -------------------
* @author Verdient。
*/
public $version;
/**
* @var public $type
* 类型
* -------------------
* @author Verdient。
*/
public $type;
/**
* @var public $status
* 状态
* -------------------
* @author Verdient。
*/
public $status;
/**
* @var public $download_url
* 下载链接
* -------------------
* @author Verdient。
*/
public $download_url;
/**
* @var public $log
* 更新日志
* -------------------
* @author Verdient。
*/
public $log;
/**
* @var public $id
* 编号
* -------------------
* @author Verdient。
*/
public $id;
/**
* __construct(String $key, String $url[, Mixed $id = null])
* 初始化
* ---------------------------------------------------------
* @param String $key 签名密钥
* @param String $url url
* @param Mixed $id 实例编号
* --------------------------
* @author Verdient。
*/
public function __construct($key, $url, $id = nul){
$this->_id = $id;
parent::__construct($key, $url);
}
/**
* getResponse()
* 获取响应原文
* -------------
* @return Array
* @author Verdient。
*/
public function getId(){
return $this->_id;
}
/**
* setId(Mixed $id)
* 设置编号
* ----------------
* @param Mixed $id 编号
* --------------------
* @author Verdient。
*/
public function setId($id){
if($this->_id){
throw new InvalidCallException('Can not set id when id is not empty');
}
$this->_id = $id;
}
/**
* setExpand(Mixed $model)
* 设置扩展模型
* -----------------------
* @param Mixed $model 扩展的模型
* -----------------------------
* @author Verdient。
*/
public function setExpand($model){
if(is_string($model)){
$this->_expand = $model;
}else if(is_array($model)){
$this->_expand = $model;
}else{
throw new InvalidParamException('expand must be a string or an array');
}
}
/**
* getExpand(Mixed $model)
* 获取扩展模型
* -----------------------
* @return String
* @author Verdient。
*/
public function getExpand(){
return $this->_expand;
}
/**
* create()
* 创建
* ----
* @return Boolean
* @author Verdient。
*/
public function create(){
$data = [];
foreach($this->attributes() as $attribute){
if($this->$attribute){
$data[$attribute] = $this->$attribute;
}
}
$this->_url = $this->_url.'/create';
$this->_send('post', $this->_url, $data);
return $this->_code == 200;
}
/**
* update()
* 更新
* ----
* @return Boolean
* @author Verdient。
*/
public function update(){
$data = [];
foreach($this->attributes() as $attribute){
if($this->$attribute){
$data[$attribute] = $this->$attribute;
}
}
$this->_url = $this->_url.'/update';
$this->_send('post', $this->_url, $data);
return $this->_code == 200;
}
/**
* delete()
* 删除
* ----
* @return Boolean
* @author Verdient。
*/
public function delete(){
if(!$this->user_id){
throw new InvalidParamException('Model user_id must be set');
}
$this->_url = $this->_url.'/delete';
$this->_send('post', $this->_url, ['user_id' => $this->user_id]);
return $this->_code == 200;
}
/**
* list1()
* 查看多条记录
* -----------------
* @return Boolean
* @author Verdient。
*/
public function list1(Array $options = []){
$data = [];
foreach($this->attributes() as $attribute){
if($this->$attribute){
$data[$attribute] = $this->$attribute;
}
}
$this->_url = $this->_url.'/list';
$this->_send('get', $this->_url, [], $data);
return $this->_code == 200;
}
}
\ No newline at end of file
<?php
namespace common\components\marketing;
/**
* Activity
* 活动
* --------
* @author Verdient。
* @version 1.0.0
*/
class Activity extends Curd
{
/**
* @status const STATUS_OFFLINE
* 下线
* ----------------------------
* @author Verdient。
*/
const STATUS_OFFLINE = 1;
/**
* @status const STATUS_ONLINE
* 上线
* ---------------------------
* @author Verdient。
*/
const STATUS_ONLINE = 2;
/**
* @status const STATUS_FINISHED
* 已结束
* -----------------------------
* @author Verdient。
*/
const STATUS_FINISHED = 3;
/**
* @currency CURRENCY_BTY
* 比特元
* ----------------------
* @author Verdient。
*/
const CURRENCY_BTY = 1;
/**
* @currency CURRENCY_YCC
* YCC
* ----------------------
* @author Verdient。
*/
const CURRENCY_YCC = 2;
/**
* @var public $status
* 状态
* -------------------
* @author Verdient。
*/
public $status;
/**
* @var public $name
* 名称
* -----------------
* @author Verdient。
*/
public $name;
/**
* @var public $currency
* 币种
* ---------------------
* @author Verdient。
*/
public $currency;
/**
* @var public $limit
* 额度
* ------------------
* @author Verdient。
*/
public $limit;
/**
* @var public $page_url
* 页面地址
* ---------------------
* @author Verdient。
*/
public $page_url;
/**
* @var public $api_url
* 接口地址
* --------------------
* @author Verdient。
*/
public $api_url;
/**
* @var public $plan_id
* 接口编号
* --------------------
* @author Verdient。
*/
public $plan_id;
/**
* init()
* 初始化
* --------------
* @author Verdient。
*/
public function init(){
parent::init();
$this->_url = $this->_url . '/activities';
}
/**
* StatusNameMap()
* 状态名称映射关系
* ---------------
* @return Array
* @author Verdient。
*/
public static function StatusNameMap(){
return [
static::STATUS_OFFLINE => '下线',
static::STATUS_ONLINE => '上线',
static::STATUS_FINISHED => '已结束'
];
}
/**
* CurrencyNameMap()
* 币种名称映射关系
* -----------------
* @return Array
* @author Verdient。
*/
public static function CurrencyNameMap(){
return [
static::CURRENCY_BTY => 'BTY',
static::CURRENCY_YCC => 'YCC'
];
}
}
\ No newline at end of file
<?php
namespace common\components\marketing;
/**
* Award
* 奖励
* -----
* @author Verdient。
* @version 1.0.0
*/
class Award extends Curd
{
/**
* @status const STATUS_INACTIVE
* 未激活
* -----------------------------
* @author Verdient。
*/
const STATUS_INACTIVE = 1;
/**
* @status const STATUS_FROZEN
* 冻结的
* ---------------------------
* @author Verdient。
*/
const STATUS_FROZEN = 2;
/**
* @status const STATUS_WAITING_RELEASE
* 待发放
* ------------------------------------
* @author Verdient。
*/
const STATUS_WAITING_RELEASE = 3;
/**
* @status const STATUS_RELEASED
* 已发放
* -----------------------------
* @author Verdient。
*/
const STATUS_RELEASED = 4;
/**
* @status const STATUS_RELEASE_FAILED
* 发放失败
* -----------------------------------
* @author Verdient。
*/
const STATUS_RELEASE_FAILED = 5;
/**
* @currency CURRENCY_BTY
* 比特元
* ----------------------
* @author Verdient。
*/
const CURRENCY_BTY = 1;
/**
* @currency CURRENCY_YCC
* YCC
* ----------------------
* @author Verdient。
*/
const CURRENCY_YCC = 2;
/**
* @var public $status
* 状态
* -------------------
* @author Verdient。
*/
public $status;
/**
* @var public $currency
* 货币对
* ---------------------
* @author Verdient。
*/
public $currency;
/**
* @var public $userId
* 用户编号
* -------------------
* @author Verdient。
*/
public $userId;
/**
* @var public $amount
* 金额
* -------------------
* @author Verdient。
*/
public $amount;
/**
* @var public $activityId
* 活动编号
* -----------------------
* @author Verdient。
*/
public $activityId;
/**
* @var public $createId
* 创建编号
* ---------------------
* @author Verdient。
*/
public $createId;
/**
* init()
* 初始化
* --------------
* @author Verdient。
*/
public function init(){
parent::init();
$this->_url = $this->_url . '/awards';
}
/**
* StatusNameMap()
* 状态名称映射关系
* ---------------
* @return Array
* @author Verdient。
*/
public static function StatusNameMap(){
return [
static::STATUS_INACTIVE => '未激活',
static::STATUS_FROZEN => '冻结',
static::STATUS_WAITING_RELEASE => '待发放',
static::STATUS_RELEASED => '已发放',
static::STATUS_RELEASE_FAILED => '发放失败'
];
}
/**
* CurrencyNameMap()
* 币种名称映射关系
* -----------------
* @return Array
* @author Verdient。
*/
public static function CurrencyNameMap(){
return [
static::CURRENCY_BTY => 'BTY',
static::CURRENCY_YCC => 'YCC'
];
}
}
\ No newline at end of file
<?php
namespace common\components\marketing;
use Yii;
use yii\base\Model;
/**
* Base
* 基本类
* -----
* @author Verdient。
* @version 1.0.0
*/
class Base extends Model
{
/**
* @var protected String $_key
* 签名密钥
* ---------------------------
* @method Config
* @author Verdient。
*/
protected $_key;
/**
* @var public $_url
* URL 路径
* -----------------
* @author Verdient。
*/
protected $_url;
/**
* @var protected $_code
* 状态码
* ---------------------
* @author Verdient。
*/
protected $_code;
/**
* @var protected $_data
* 数据
* ---------------------
* @author Verdient。
*/
protected $_data;
/**
* @var protected $_header
* 响应头部信息
* -----------------------
* @author Verdient。
*/
protected $_header;
/**
* @var protected $_response
* 响应原文
* -------------------------
* @author Verdient。
*/
protected $_response;
/**
* @var protected $_error
* 错误信息
* ----------------------
* @author Verdient。
*/
protected $_error;
/**
* __construct(String $key, String $url[, Mixed $id = null])
* 初始化
* ---------------------------------------------------------
* @param String $key 签名密钥
* @param String $url url
* @param Mixed $id 实例编号
* --------------------------
* @author Verdient。
*/
public function __construct($key, $url){
$this->_key = $key;
$this->_url = $url;
parent::__construct();
}
/**
* getCode()
* 获取响应码
* ---------
* @return Integer
* @author Verdient。
*/
public function getCode(){
return $this->_code;
}
/**
* getData()
* 获取响应数据
* -----------
* @return Array
* @author Verdient。
*/
public function getData(){
return $this->_data;
}
/**
* getHeader()
* 获取响应头数据
* -------------
* @return Array
* @author Verdient。
*/
public function getHeader(){
return $this->_header;
}
/**
* getError()
* 获取响应错误
* -----------
* @return Array
* @author Verdient。
*/
public function getError(){
return $this->_error;
}
/**
* getResponse()
* 获取响应原文
* -------------
* @return Array
* @author Verdient。
*/
public function getResponse(){
return $this->_response;
}
/**
* formName()
* 获取表单名称
* -----------
* @inheritdoc
* -----------
* @return String
* @author Verdient。
*/
public function formName(){
return '';
}
/**
* setAttributes(Array $values[, Boolean $safeOnly = false])
* 设置属性
* ---------------------------------------------------------
* @param Array $values 要设置的属性值
* @param Boolean $safeOnly 是否仅设置安全的属性
* -------------------------------------------
* @inheritdoc
* -----------
* @author Verdient。
*/
public function setAttributes($values, $safeOnly = false){
return parent::setAttributes($values, $safeOnly);
}
/**
* _formatError(Array $errors)
* 格式化错误
* ---------------------------
* @return Array
* @author Verdient。
*/
protected function _formatError(Array $errors){
$errorMap = [];
foreach($errors as $error){
$errorMap[$error['field']][] = $error['message'];
}
return $errorMap;
}
/**
* _send(String $method, String $url[, Array $data = [], Array $query = []])
* 发送数据
* -------------------------------------------------------------------------
* @param String $method 访问方法
* @param String $url URL路径
* @param Array $data 发送的数据
* @param Array $query 查询条件
* ------------------------------
* @return Array
* @author Verdient。
*/
protected function _send($method, $url, Array $data = [], Array $query = []){
$method = strtolower($method);
if(!empty($query)){
Yii::$app->cUrl->setQuery($query);
}
$signature = new Signature();
$signature->key = $this->_key;
$signature->verb = $method;
$signature->contentType = 'application/json';
$signature->signatureMethod = 'sha256';
if(!empty($data)){
Yii::$app->cUrl->setData($data, 'JSON');
}
$signature->content = $data;
Yii::$app->cUrl->setHeader([
'Signature' => $signature->signature,
'Date' => $signature->date,
'Verb' => $signature->verb,
'Signature-Method' => $signature->signatureMethod,
'Signature-Version' => $signature->signatureVersion
]);
$options = Yii::$app->cUrl->getOptions();
$response = Yii::$app->cUrl->$method($url, 'JSON');
Yii::trace(['url' => $url, 'cUrl' => $options, 'response' => $response], __METHOD__);
$this->_response = $response;
$this->_code = isset($response['code']) ? $response['code'] : null;
if($this->_code == 422){
$this->_error = $this->_formatError($response['content']);
}else if($this->_code == 404){
$this->_error = [
'id' => [$response['content']['message']]
];
}else{
if(isset($response['content']['id'])){
$this->_id = $response['content']['id'];
}
$this->_data = isset($response['content']) ? $response['content'] : null;
$this->_header = isset($response['header']) ? $response['header'] : null;
}
}
}
\ No newline at end of file
<?php
namespace common\components\marketing;
use Yii;
use yii\base\Model;
use yii\base\InvalidCallException;
use yii\helpers\ArrayHelper;
use yii\helpers\Inflector;
use yii\base\InvalidParamException;
/**
* Curd
* 增删改查
* -------
* @author Verdient。
* @version 1.0.0
*/
class Curd extends Base
{
/**
* @var protected $_id
* 活动编号
* -------------------
* @author Verdient。
*/
protected $_id;
/**
* @var protected $_expand
* 扩展模型
* -----------------------
* @author Verdient。
*/
protected $_expand;
/**
* __construct(String $key, String $url[, Mixed $id = null])
* 初始化
* ---------------------------------------------------------
* @param String $key 签名密钥
* @param String $url url
* @param Mixed $id 实例编号
* --------------------------
* @author Verdient。
*/
public function __construct($key, $url, $id = nul){
$this->_id = $id;
parent::__construct($key, $url);
}
/**
* getResponse()
* 获取响应原文
* -------------
* @return Array
* @author Verdient。
*/
public function getId(){
return $this->_id;
}
/**
* setId(Mixed $id)
* 设置编号
* ----------------
* @param Mixed $id 编号
* --------------------
* @author Verdient。
*/
public function setId($id){
if($this->_id){
throw new InvalidCallException('Can not set id when id is not empty');
}
$this->_id = $id;
}
/**
* setExpand(Mixed $model)
* 设置扩展模型
* -----------------------
* @param Mixed $model 扩展的模型
* -----------------------------
* @author Verdient。
*/
public function setExpand($model){
if(is_string($model)){
$this->_expand = $model;
}else if(is_array($model)){
$this->_expand = $model;
}else{
throw new InvalidParamException('expand must be a string or an array');
}
}
/**
* getExpand(Mixed $model)
* 获取扩展模型
* -----------------------
* @return String
* @author Verdient。
*/
public function getExpand(){
return $this->_expand;
}
/**
* create()
* 创建
* ----
* @return Boolean
* @author Verdient。
*/
public function create(){
$data = [];
foreach($this->attributes() as $attribute){
if($this->$attribute){
$data[$attribute] = $this->$attribute;
}
}
$this->_send('post', $this->_url, $data);
return $this->_code == 201;
}
/**
* update()
* 更新
* ----
* @return Boolean
* @author Verdient。
*/
public function update(){
if(!$this->_id){
throw new InvalidParamException('Model id must be set');
}
$data = [];
foreach($this->attributes() as $attribute){
if($this->$attribute){
$data[$attribute] = $this->$attribute;
}
}
$this->_send('put', $this->_url . '/' . $this->_id, $data);
return $this->_code == 200;
}
/**
* delete()
* 删除
* ----
* @return Boolean
* @author Verdient。
*/
public function delete(){
if(!$this->_id){
throw new InvalidParamException('Model id must be set');
}
$this->_send('delete', $this->_url . '/' . $this->_id);
return $this->_code == 204;
}
/**
* view()
* 查看单条记录
* -----------
* @return Boolean
* @author Verdient。
*/
public function view(){
if(!$this->_id){
throw new InvalidParamException('Model id must be set');
}
$query = [];
if($this->expand){
$query['expand'] = $this->expand;
}
$this->_send('get', $this->_url . '/' . $this->_id, [], $query);
return $this->_code == 200;
}
/**
* list1([Array $options = []])
* 获取记录列表
* ---------------------------
* @param Array $options [
* page => Integer
* pageSize => Integer
* sort => [
* {attribute} => ASC,
* {-attribute} => DESC
* ]
* ----------------------
* @return Boolean
* @author Verdient。
*/
public function list1(Array $options = []){
$defalutOptions = [
'page' => 1,
'pageSize' => 20,
];
$options = ArrayHelper::merge($defalutOptions, $options);
foreach($options as $key => $value){
$newKey = Inflector::camel2id($key, '_');
if($key != $newKey){
$options[$newKey] = $value;
unset($options[$key]);
}
}
if($this->expand){
$options['expand'] = $this->expand;
}
$this->_send('get', $this->_url, [], $options);
return $this->_code == 200;
}
}
\ No newline at end of file
<?php
namespace common\components\marketing;
use Yii;
use yii\base\Component;
/**
* MarketingInterface
* 营销中心 接口
* ------------------
* @author Verdient。
* @version 1.0.0
*/
class MarketingInterface extends Component
{
/**
* @var public String $key
* 签名密钥
* -----------------------
* @method Config
* @author Verdient。
*/
public $key;
/**
* @var public $protocol
* 访问协议
* ---------------------
* @method Config
* @author Verdient。
*/
public $protocol = '';
/**
* @var public $host
* 域名
* -----------------
* @method Config
* @author Verdient。
*/
public $host = '';
/**
* @var public $port
* 端口
* -----------------
* @method Config
* @author Verdient。
*/
public $port = '';
/**
* @var public $_urlPrefix
* URL 路径前缀
* -----------------------
* @author Verdient。
*/
protected $_urlPrefix;
/**
* init()
* 初始化
* ------
* @param String $publicKey 公钥
* -----------------------------
* @return Array / false
* @author Verdient。
*/
public function init(){
parent::init();
if(!$this->protocol){
$this->protocol = Yii::$app->request->isSecureConnection ? 'https' : 'http';
}
if(!$this->host){
$this->host = explode(':', $_SERVER['HTTP_HOST'])[0];
}
$this->_urlPrefix = $this->protocol . '://' . $this->host . ($this->port ? (($this->protocol == 'https' && $this->port == 443) || ($this->protocol == 'http' && $this->port == 80) ? '' : (':' . $this->port)) : '');
}
/**
* getActivity(Mixed $id)
* 获取活动实例
* ----------------------
* @param Mixed $id 活动编号
* ------------------------
* @return Object
* @author Verdient。
*/
public function getActivity($id = null){
return new Activity($this->key, $this->_urlPrefix, $id);
}
/**
* getPlan(Mixed $id)
* 获取计划实例
* ------------------
* @param Mixed $id 活动编号
* ------------------------
* @return Object
* @author Verdient。
*/
public function getPlan($id = null){
return new Plan($this->key, $this->_urlPrefix, $id);
}
/**
* getAward(Mixed $id)
* 获取奖励实例
* ------------------
* @param Mixed $id 奖励编号
* ------------------------
* @return Object
* @author Verdient。
*/
public function getAward($id = null){
return new Award($this->key, $this->_urlPrefix, $id);
}
/**
* getStatistics()
* 获取统计实例
* ---------------
* @return Object
* @author Verdient。
*/
public function getStatistics(){
return new Statistics($this->key, $this->_urlPrefix);
}
}
\ No newline at end of file
<?php
namespace common\components\marketing;
/**
* Plan
* 计划
* ----
* @author Verdient。
* @version 1.0.0
*/
class Plan extends Curd
{
/**
* @status const STATUS_ENABLED
* 启用的
* ----------------------------
* @author Verdient。
*/
const STATUS_ENABLED = 1;
/**
* @status const STATUS_DISABLED
* 禁用的
* -----------------------------
* @author Verdient。
*/
const STATUS_DISABLED = 2;
/**
* @var public $status
* 状态
* -------------------
* @author Verdient。
*/
public $status;
/**
* @var public $start
* 开始时间
* ------------------
* @author Verdient。
*/
public $start;
/**
* @var public $end
* 结束时间
* -------------------
* @author Verdient。
*/
public $end;
/**
* @var public $dayStart
* 每天的开始时间
* ---------------------
* @author Verdient。
*/
public $dayStart;
/**
* @var public $dayEnd
* 每天的结束时间
* -------------------
* @author Verdient。
*/
public $dayEnd;
/**
* init()
* 初始化
* --------------
* @author Verdient。
*/
public function init(){
parent::init();
$this->_url = $this->_url . '/plans';
}
/**
* StatusNameMap()
* 状态名称映射关系
* ---------------
* @return Array
* @author Verdient。
*/
public static function StatusNameMap(){
return [
static::STATUS_ENABLED => '启用',
static::STATUS_DISABLED => '已禁用'
];
}
}
\ No newline at end of file
<?php
namespace common\components\marketing;
use yii\base\Component;
use yii\base\InvalidParamException;
use yii\base\InvalidValueException;
/**
* Signature
* 签名
* ---------
* @author Verdient。
* @version 1.0.0
*/
class Signature extends Component
{
/**
* @var public String $key
* 签名密钥
* -----------------------
* @author Verdient。
*/
public $key;
/**
* @var protected String $_verb
* 访问方式
* ----------------------------
* @author Verdient。
*/
protected $_verb;
/**
* @var protected String $_contentType
* 消息体类型
* -----------------------------------
* @author Verdient。
*/
protected $_contentType = 'application/json';
/**
* @var protected String $_content
* 消息体
* -------------------------------
* @author Verdient。
*/
protected $_content = [];
/**
* @var protected String $_contentMd5
* 消息体MD5值
* ----------------------------------
* @author Verdient。
*/
protected $_contentMd5 = null;
/**
* @var protected String $_date
* 日期
* ----------------------------
* @author Verdient。
*/
protected $_date;
/**
* @var protected String $_signature
* 签名
* ---------------------------------
* @author Verdient。
*/
protected $_signature;
/**
* @var protected String $_signatureMethod
* 签名方法
* ---------------------------------------
* @author Verdient。
*/
protected $_signatureMethod;
/**
* @var protected String $_signatureVersion
* 签名版本
* ----------------------------------------
* @author Verdient。
*/
protected $_signatureVersion = '1.0';
/**
* @var protected String $_enabledVerb
* 允许的访问方式
* -----------------------------------
* @author Verdient。
*/
protected $_enabledVerb = ['get', 'post', 'put', 'patch', 'delete', 'options'];
/**
* @var protected String $_enabledContentType
* 允许的消息体类型
* ------------------------------------------
* @author Verdient。
*/
protected $_enabledContentType = ['application/json'];
/**
* @var protected String $_enabledSignatureMethod
* 允许的签名方法
* ----------------------------------------------
* @author Verdient。
*/
protected $_enabledSignatureMethod = ['sha1', 'sha256'];
/**
* @var protected String $_enabledSignatureMethod
* 允许的签名版本
* ----------------------------------------------
* @author Verdient。
*/
protected $_enabledSignatureVersion = ['1.0'];
/**
* setVerb(String $verb)
* 设置访问方式
* ---------------------
* @author Verdient。
*/
public function setVerb($verb){
if(!$verb){
throw new InvalidValueException('Verb can not be empty');
}
if(!is_string($verb)){
throw new InvalidValueException('Verb must be a string');
}
$verb = strtolower($verb);
if(!in_array($verb, $this->_enabledVerb)){
throw new InvalidValueException('Verb must in: [' . implode(', ', $this->_enabledVerb) . ']');
}
$this->_verb = $verb;
}
/**
* getVerb(String $verb)
* 获取访问方式
* ---------------------
* @return String
* @author Verdient。
*/
public function getVerb(){
return $this->_verb;
}
/**
* setContentType(String $contentType)
* 设置消息体类型
* -----------------------------------
* @author Verdient。
*/
public function setContentType($contentType){
if(!$contentType){
throw new InvalidValueException('ContentType can not be empty');
}
if(!is_string($contentType)){
throw new InvalidValueException('ContentType must be a string');
}
$contentType = strtolower($contentType);
if(!in_array($contentType, $this->_enabledContentType)){
throw new InvalidValueException('ContentType must in: [' . implode(', ', $this->_enabledContentType) . ']');
}
$this->_contentType = $contentType;
}
/**
* getContentType()
* 获取消息体类型
* ----------------
* @return String
* @author Verdient。
*/
public function getContentType(){
return $this->_contentType;
}
/**
* setContent(Array $content)
* 设置消息体
* --------------------------
* @param Array $content 消息体
* ----------------------------
* @author Verdient。
*/
public function setContent(Array $content){
static::_prepareContent($content);
$this->_content = $content;
}
/**
* getContent()
* 获取消息体
* ------------
* @return Array
* @author Verdient。
*/
public function getContent(){
return $this->_content;
}
/**
* setDate(Mixed $date)
* 设置日期
* --------------------
* @param Mixed $date 日期
* -----------------------
* @author Verdient。
*/
public function setDate($date){
if(is_numeric($date) && ctype_digit($str) && $str <= 2147483647){
$this->_date = gmdate('D, d M Y H:i:s \G\M\T', $date);
}else if(is_string($date)){
$this->_date = gmdate('D, d M Y H:i:s \G\M\T', strtotime($date));
}else{
throw new InvalidParamException('Data must be a timestamp or date string');
}
}
/**
* getDate()
* 获取日期
* ---------
* @return String
* @author Verdient。
*/
public function getDate(){
if(!$this->_date){
$this->_date = gmdate('D, d M Y H:i:s \G\M\T');
}
return $this->_date;
}
/**
* setSignatureMethod()
* 获取签名方法
* --------------------
* @return String
* @author Verdient。
*/
public function setSignatureMethod($signatureMethod){
if(!$signatureMethod){
throw new InvalidValueException('SignatureMethod can not be empty');
}
if(!is_string($signatureMethod)){
throw new InvalidValueException('SignatureMethod must be a string');
}
$signatureMethod = strtolower($signatureMethod);
if(!in_array($signatureMethod, $this->_enabledSignatureMethod)){
throw new InvalidValueException('SignatureMethod must in: [' . implode(', ', $this->_enabledSignatureMethod) . ']');
}
$this->_signatureMethod = $signatureMethod;
}
/**
* getSignatureMethod()
* 获取签名方法
* --------------------
* @return String
* @author Verdient。
*/
public function getSignatureMethod(){
return $this->_signatureMethod;
}
/**
* setSignatureVersion()
* 获取签名版本
* --------------------
* @return String
* @author Verdient。
*/
public function setSignatureVersion($signatureVersion){
if(!$signatureVersion){
throw new InvalidValueException('SignatureVersion can not be empty');
}
if(!is_string($signatureVersion)){
throw new InvalidValueException('SignatureVersion must be a string');
}
$signatureVersion = strtolower($signatureVersion);
if(!in_array($signatureVersion, $this->_enabledSignatureVersion)){
throw new InvalidValueException('SignatureVersion must in: [' . implode(', ', $this->_enabledSignatureMethod) . ']');
}
$this->_signatureVersion = $signatureVersion;
}
/**
* getSignatureVersion()
* 获取签名版本
* ---------------------
* @return String
* @author Verdient。
*/
public function getSignatureVersion(){
return $this->_signatureVersion;
}
/**
* getContentMd5()
* 获取消息体MD5值
* ---------------
* @return String
* @author Verdient。
*/
public function getContentMd5(){
if(!$this->_contentMd5 !== null){
if(!is_array($this->content)){
throw new InvalidParamException('Content must be an Array');
}
$this->_contentMd5 = empty($this->content) ? '' : md5(json_encode($this->content));
}
return $this->_contentMd5;
}
/**
* getSignature()
* 获取签名
* --------------
* @return String
* @author Verdient。
*/
public function getSignature(){
if(!$this->_signature){
if(!$this->key){
throw new InvalidParamException('Signature key must be set');
}
if(!$this->signatureMethod){
throw new InvalidConfigException('SignatureMethod must be set');
}
$this->_signature = md5(hash_hmac($this->signatureMethod, $this->_buildSignatureString(), $this->key, false));
}
return $this->_signature;
}
/**
* _buildSignatureString()
* 构建待签名的字符串
* -----------------------
* @return String
* @author Verdient。
*/
protected function _buildSignatureString(){
return strtoupper($this->verb) .
"\n\n" .
$this->contentMd5 .
"\n" .
$this->contentType .
"\n" .
$this->date .
"\n" .
$this->signatureMethod .
"\n" .
$this->signatureVersion .
"\n\n" .
$this->key .
"\n";
}
/**
* _prepareContent(Array &$content)
* 准备消息体
* --------------------------------
* @param Array &$content 消息体
* ----------------------------
* @author Verdient。
*/
protected static function _prepareContent(&$content){
ksort($content);
foreach($content as $key => $value){
if(empty($value)){
unset($content[$key]);
}else if(is_array($value)){
static::_prepareContent($content[$key]);
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment