Commit 42c32953 authored by rlgy's avatar rlgy

添加用户api

parent f45601a2
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-13
* Time: 上午10:41
*/
namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\models\pwallet\Member;
class MemberController extends BaseController
{
/**
* @return array
* @throws \Exception
*/
public function actionAddOne()
{
$post = Yii::$app->request->post();
$member = new Member();
$member->scenario = Member::SCENARIO_ADD;
$post['register_at'] = date('Y-m-d H:i:s');
if ($member->load($post) && $member->validate()) {
//加密password
//加盐
try {
$member->salt = Yii::$app->security->generateRandomString();
$member->password = Yii::$app->security->generatePasswordHash($member->password . $member->salt);
$member->save();
return ['code' => 0, 'msg' => 'succeed'];
} catch (\Exception $exception) {
throw $exception;
}
}
if ($member->hasErrors()) {
$errors = $member->errors;
foreach ($errors as $error) {
throw new \Exception($error[0], 1);
}
}
}
}
\ No newline at end of file
...@@ -7,4 +7,22 @@ namespace common\core; ...@@ -7,4 +7,22 @@ namespace common\core;
*/ */
class BaseActiveRecord extends \yii\db\ActiveRecord class BaseActiveRecord extends \yii\db\ActiveRecord
{ {
public static function getList($page = 1, $limit = 10, $condition = [])
{
$query = self::find();
foreach ($condition as $item) {
$query = $query->andWhere($item);
}
$count = $query->count();
$data = $query->offset(($page - 1) * 10)->limit($limit)->asArray()->all();
// $sql = $query->createCommand()->getSql();
$data = ['count' => $count, 'data' => $data];
if ($count > 0) {
$data['code'] = 0;
} else {
$data['code'] = 1;
$data['msg'] = '数据为空';
}
return $data;
}
} }
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-13
* Time: 上午9:50
*/
namespace common\models\pwallet;
use Yii;
use common\core\BaseActiveRecord;
/**
* Class Member
* @property integer $uid
* @property string $username
* @property string $password
* @property string $salt
* @property string $realname
* @property string $nickname
* @property string $phone
* @property string $email
* @property double $capital
* @property string $register_at
* @property integer $recommend_id
* @property integer $recommend_number
* @property string $account_address
* @package common\models\pwallet
*/
class Member extends BaseActiveRecord
{
const SCENARIO_ADD = 'add';
/**
* @return null|object|\yii\db\Connection
* @throws \yii\base\InvalidConfigException
*/
public static function getDb()
{
return Yii::$app->get('db_pwallet');
}
public function formName()
{
return '';
}
public function rules()
{
return [
[['uid', 'recommend_id', 'recommend_number'], 'integer'],
[['username', 'realname', 'nickname'], 'string', 'min' => 0, 'max' => 64],
[['phone'], 'string', 'max' => 16],
[['password', 'email'], 'string', 'max' => 255],
[['register_at'], 'date', 'type' => 'datetime', 'format' => 'php:Y-m-d H:i:s'],
[['capital'], 'number'],
[['account_address'], 'string'],
[['username'], 'usernameExistsValidate'],
[['username', 'password', 'register_at'], 'required', 'on' => self::SCENARIO_ADD],
];
}
public function scenarios()
{
return [
self::SCENARIO_ADD => [
'username',
'password',
'realname',
'nickname',
'phone',
'email',
'capital',
'register_at',
'recommend_id',
'recommend_number',
'account_address'
],
];
}
public function attributeLabels()
{
return [
'uid' => '用户ID',
'username' => '用户名',
'password' => '密码',
'realname' => '真实姓名',
'nickname' => '昵称',
'phone' => '电话号码',
'email' => '邮箱',
'capital' => '资产',
'register_at' => '注册时间',
'recommend_id' => '推介人ID',
'recommend_number' => '推介人数',
'account_address' => '托管账户地址',
];
}
public static function usernameExists($username)
{
return (bool)self::findOne(['username' => $username]);
}
public function usernameExistsValidate($attribute, $params)
{
if (self::usernameExists($this->$attribute)) {
$this->addError($attribute, 'Username Exists!');
}
}
}
\ No newline at end of file
...@@ -155,19 +155,26 @@ class CoinService ...@@ -155,19 +155,26 @@ class CoinService
'circulate_count' => '',//流通总量 'circulate_count' => '',//流通总量
]; ];
$ch = curl_init('https://api2.mytoken.org/currency/currencydetail?com_id=bty_CNY&market_id=1303&market_name=cmc&symbol=BTY&anchor=CNY&timestamp=1528775656509&code=c368f591b57e93011cb9c853555a9126&v=1.4.0&platform=m&language=zh_CN&'); $ch = curl_init('https://kdata.zhaobi.com:4062/kdata?datafile=db&c=BTYUSDT&p=H1&action=init&count=24&ind=volumes&out=json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HEADER, 0);
$content = curl_exec($ch); $content = curl_exec($ch);
$content = json_decode($content, true); $content = json_decode($content, true);
if ($content['code'] == 0) { $content = $content['main']['y'];
$content = $content['data'];
$result['rank'] = '第' . $content['rank'] . '名';
$result['price'] = $content['price_display']; $min = 10e9;
$result['dollar'] = sprintf("$%0.6f", $content['price_usd']); $max = 0;
$result['change'] = sprintf("%0.6f%%", $content['percent_change_display']); foreach ($content as $item) {
for ($i = 0; $i < 4; $i++) {
$min = min($min, $item[$i]);
$max = max($max, $item[$i]);
} }
}
$change = ($content[23][3] - $content[0][0]) / $content[0][0] * 100;
$result['dollar'] = $content[23][3];
$result['low'] = $min;
$result['high'] = $max;
$result['change'] = sprintf("%0.2f%%", $change);
return $result; return $result;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment