Files
你的名字 0483b4b364 1
2025-07-14 10:22:40 +08:00

1411 lines
52 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | ThinkAdmins
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库3https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库3https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\index\controller\api;
use library\Controller;
use think\Db;
use think\facade\Request;
/**
* 用户
* Class Index
* @package app\index\controller\api
*/
class User extends Controller
{
/**
* @var mixed
*/
private $uid;
public function __construct()
{
$token = Request::header('token');
$uid = Db::name('LcUser')->where(['token' => $token])->value('id');
if (!$uid) {
$this->error('', '', 1002);
} else {
Db::name('LcUser')->where(['token' => $token])->update([
'access_time' => time(),
]);
$this->uid = $uid;
}
}
/**
* @description个人中心
* @date: 2020/5/13 0013
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function index()
{
$uid = $this->uid;;
//自动更新真实姓名
$real_name = Db::name('LcBank')->where(['uid' => $uid])->value('name');
$user = Db::name('LcUser')->find($uid);
$tt = $user;
if ($tt['name'] <> $real_name) {
Db::name('LcUser')->where(['id' => $uid])->update(['name' => $real_name]);
}
$this->chicang = Db::name('LcOrder')->where("uid = $uid AND ostaus = 0")->sum('fee');
$this->wait_money = $user['money'] + $this->chicang;
$this->msg = Db::name('LcMsg')->alias('msg')->where('(msg.uid = ' . $uid . ' or msg.uid = 0 ) and (select count(*) from lc_msg_is as msg_is where msg.id = msg_is.mid and ((msg.uid = 0 and msg_is.uid = ' . $uid . ') or ( msg.uid = ' . $uid . ' and msg_is.uid = ' . $uid . ') )) = 0')->count();
$this->qiandao = 1;
$today = date('Y-m-d 00:00:00');
if ($today <= $user['qiandao'])
$this->qiandao = 2;
$this->lcopen = getlcopen();
$this->top = Db::name('LcUser')->where(['top' => $uid])->count();
$now = date('Y-m-d H:i:s');
$this->yxkj = Db::name('LcMallInvest')->where("time2 >= '$now' and uid = $uid")->count();
$this->zqhy = Db::name('LcInvest')->where("time2 >= '$now' and uid = $uid")->count();
$userleveltile = Db::name('LcUserMember')->find($user['member']);
$this->assign('userleveltile', $userleveltile);
$this->success(json_lang("操作成功"), [
'user' => $user,
'wait_money' => $this->wait_money,
'chicang' => $this->chicang,
'yingkui' => 0,
'qiandao' => $this->qiandao,
'userleveltile' => $userleveltile
]);
}
public function account()
{
$uid = $this->uid;
$user = Db::name('LcUser')->find($uid);
if (!$user) $this->error(json_lang("用户不存在"));
//自动更新真实姓名
// $real_name = Db::name('LcBank')->where(['uid' => $uid])->value('name');
// $tt = $user;
// if ($tt['name'] <> $real_name) {
// Db::name('LcUser')->where(['id' => $uid])->update(['name' => $real_name]);
// }
$this->chicang = Db::name('LcOrder')->where("uid = $uid AND ostaus = 0")->sum('fee');
$this->wait_money = $user['money'] + $this->chicang;
$this->msg = Db::name('LcMsg')->alias('msg')->where('(msg.uid = ' . $uid . ' or msg.uid = 0 ) and (select count(*) from lc_msg_is as msg_is where msg.id = msg_is.mid and ((msg.uid = 0 and msg_is.uid = ' . $uid . ') or ( msg.uid = ' . $uid . ' and msg_is.uid = ' . $uid . ') )) = 0')->count();
$this->qiandao = 1;
$today = date('Y-m-d 00:00:00');
if ($today <= $user['qiandao'])
$this->qiandao = 2;
$this->lcopen = getlcopen($uid);
$this->top = Db::name('LcUser')->where(['top' => $uid])->count();
$now = date('Y-m-d H:i:s');
$this->yxkj = Db::name('LcMallInvest')->where("time2 >= '$now' and uid = $uid")->count();
$this->zqhy = Db::name('LcInvest')->where("time2 >= '$now' and uid = $uid")->count();
$userleveltile = Db::name('LcUserMember')->find($user['member']);
$this->success(json_lang("操作成功"), [
'user' => $user,
'wait_money' => $this->wait_money,
'chicang' => $this->chicang,
'yingkui' => 0,
'msg' => Db::name('LcMsg')->where(['uid' => $uid, 'status' => 0])->count(),
'qiandao' => $this->qiandao,
'lcopen' => $this->lcopen,
'userleveltile' => $userleveltile,
'todayincome' => round( Db::name('LcOrder')->where([
['buytime', '>', strtotime(date('Y-m-d 00:00:00'))],
['buytime', '<', strtotime(date('Y-m-d 23:59:59'))],
['uid', '=', $user['id']]
])->sum('ploss'),3),
'yesterdayincome' =>round( Db::name('LcOrder')->where([
['buytime', '>', strtotime(date('Y-m-d 00:00:00')) - 86400],
['buytime', '<', strtotime(date('Y-m-d 23:59:59')) - 86400],
['uid', '=', $user['id']]
])->sum('ploss'),3),
'yueincome' => round(Db::name('lc_yuebao_lists')->where([
['uid', '=', $user['id']]
])->sum('nowprofit'),3),
]);
}
/**
* Describe:签到
* DateTime: 2020/5/13 23:17
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function sign()
{
$uid = $this->uid;
$this->error('请先登录后再签到');
$user = Db::name('LcUser')->find($uid);
$today = date('Y-m-d 00:00:00');
if ($today <= $user['qiandao'])
$this->error('每天只能签到一次');
$money = getReward('qiandao');
Db::name('LcUser')->where(['id' => $uid])->update(['qiandao' => date('Y-m-d H:i:s')]);
addFinance($uid, $money, 1, "每日签到,获得奖励{$money}");
setNumber('LcUser', 'money', $money, 1, "id=$uid");
setNumber('LcUser', 'income', $money, 1, "id=$uid");
setNumber('LcUser', 'qdnum', 1, 1, "id=$uid");
$this->success("签到成功,获得{$money}");
}
/**
* Describe:站内消息
* DateTime: 2020/5/14 0:01
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function msg()
{
$uid = $this->uid;
$this->msgtop = Db::name('LcMsg')->alias('msg')->where('(msg.uid = ' . $uid . ' or msg.uid = 0 ) and (select count(*) from lc_msg_is as msg_is where msg.id = msg_is.mid and ((msg.uid = 0 and msg_is.uid = ' . $uid . ') or ( msg.uid = ' . $uid . ' and msg_is.uid = ' . $uid . ') )) = 0')->select();
$this->msgfoot = Db::name('LcMsg')->alias('msg')->where('(select count(*) from lc_msg_is as msg_is where msg.id = msg_is.mid and msg_is.uid = ' . $uid . ') > 0')->select();
$this->fetch();
}
/**
* Describe: 信息详情
* DateTime: 2020/5/14 0:31
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function msg_view()
{
$id = $this->request->param('id');
$uid = $this->uid;
if (!$id || !$uid)
msg('系统忙碌!', 2, '/index/user/index');
$where['uid'] = $this->uid;
$where['mid'] = $id;
$ret = Db::name('LcMsgIs')->where($where)->find();
if (!$ret)
Db::name('LcMsgIs')->insertGetId(['uid' => $uid, 'mid' => $id]);
$this->msg = Db::name('LcMsg')->find($id);
$this->fetch();
}
/**
* Describe: 账户安全
* DateTime: 2020/5/14 0:48
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function set_account()
{
$uid = $this->uid;
$user = Db::name('LcUser')->find($uid);
$this->fetch();
}
/**
* @description交易密码设置
* @date: 2020/5/14 0014
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function pwd_pay()
{
$uid = $this->uid;;
$user = Db::name('LcUser')->find($uid);
if ($this->request->isPost()) {
if (!input('oldpwd', '')) $this->error('原支付密码不能为空');
if (!input('pwd', '')) $this->error('新密码不能为空');
if (!input('pwd2', '')) $this->error('确认密码不能为空');
$data = $this->request->param();
if ($user['password'] != md5($data['oldpwd']))
$this->error('原支付密码错误!');
if ($user['password'] == md5($data['pwd']))
$this->error('新密码不能与原密码相同!');
if (strlen($data['pwd']) < 6 || 16 < strlen($data['pwd']))
$this->error(json_lang("请输入6-16位密码"));
if ($data['pwd'] != $data['pwd2'])
$this->error('两次密码不一致!');
if (Db::name('LcUser')->where(['id' => $user['id']])->update(['password2' => md5($data['pwd']), 'mwpassword2' => $data['pwd2']])) {
$this->success('修改成功!');
} else {
$this->error('修改失败!');
}
}
}
/**
* Describe: 登录密码设置
* DateTime: 2020/5/14 1:00
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function pwd_login()
{
$uid = $this->uid;
$user = Db::name('LcUser')->find($uid);
if ($this->request->isPost()) {
if (!input('oldpwd', '')) $this->error('原登录密码不能为空');
if (!input('pwd', '')) $this->error('新密码不能为空');
if (!input('pwd2', '')) $this->error('确认密码不能为空');
$data = $this->request->param();
if ($user['password'] != md5($data['oldpwd']))
$this->error('原登录密码错误!');
if ($user['password'] == md5($data['pwd']))
$this->error('新密码不能与原密码相同!');
if (strlen($data['pwd']) < 6 || 16 < strlen($data['pwd']))
$this->error(json_lang("请输入6-16位密码"));
if ($data['pwd'] != $data['pwd2'])
$this->error('两次密码不一致!');
if (Db::name('LcUser')->where(['id' => $user['id']])->update(['password' => md5($data['pwd']), 'mwpassword' => $data['pwd2']])) {
$this->success('修改成功!');
} else {
$this->error('修改失败!');
}
}
}
/**
* @description身份认证
* @date: 2020/5/14 0014
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function certification()
{
$uid = $this->uid;
$user = Db::name('LcUser')->find($uid);
if ($this->request->isPost()) {
$data = $this->request->param();
if ($user['auth'] == 1)
$this->error('你已认证,请勿重复认证!');
$check = Db::name('LcUser')->where("idcard = '{$data['idcard']}' AND id <> $uid")->find();
if ($check)
$this->error('身份证号码已存在,请勿重复注册!');
if (getInfo('cert') == 1) {
$auth_check = idCardAuth($data['idcard'], $data['name']);
if ($auth_check['code'] == 0)
$this->error($auth_check['msg']);
} else {
if (!judge($data['name'], 'name'))
$this->error('名字不正确!');
if (!judge($data['idcard'], 'idcard'))
$this->error('身份证号码不正确!');
}
$money = getReward('shimingsong');
addFinance($uid, $money, 1, "实名成功,系统赠送{$money}");
setNumber('LcUser', 'money', $money, 1, "id = $uid");
setNumber('LcUser', 'income', $money, 1, "id = $uid");
if (Db::name('LcUser')->where(['id' => $uid])->update(['name' => $data['name'], 'idcard' => $data['idcard'], 'auth' => 1])) {
$this->success('认证成功!');
} else {
$this->error('认证失败!');
}
}
$this->fetch();
}
/**
* @description银行卡管理
* @date: 2020/5/14 0014
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function bank_card()
{
$uid = $this->uid;;
$this->bank = Db::name('LcBank')->where('uid', $uid)->order("id desc")->select();
$this->success(json_lang("操作成功"), ['banks' => $this->bank]);
}
/**
* @description添加银行卡
* @date: 2020/5/14 0014
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function add_card()
{
$uid = $this->uid;;
if (Request::isPost()) {
$data = Request::param();
if (Db::name('LcBank')->where('uid', $uid)->find()) $this->error(json_lang('银行卡已绑定,请勿重复添加!'));
$add = $data;
$add['uid'] = $uid;
if (Db::name('LcBank')->insert($add))
$this->success('添加成功!');
$this->error('操作失败!');
}
$this->fetch();
}
public function add_usdt()
{
$uid = $this->uid;;
if (Request::isPost()) {
$data = Request::param();
if (Db::name('LcUsdt')->where('uid', $uid)->find()) $this->error(json_lang('地址已绑定,请勿重复添加!'));
$add = ['uid' => $uid, 'address' => $data['address'], 'create_time' => time()];
if (Db::name('LcBank')->insert($add)) {
$this->success('添加成功!');
}
$this->error('操作失败!');
}
$this->fetch();
}
/**
* @description删除银行卡
* @date: 2020/5/14 0014
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function del_card()
{
$this->applyCsrfToken();
$uid = $this->uid;
$id = $this->request->param('id');
if (Db::name('LcBank')->where(['uid' => $uid, 'id' => $id])->delete()) {
msg('删除成功!', 2, '/index/user/index');
}
msg('操作失败!', 2, '/index/user/index');
}
/**
* @description支付宝设置
* @date: 2020/5/14 0014
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function alipay()
{
$uid = $this->uid;
$user = Db::name('LcUser')->find($uid);
if ($this->request->isPost()) {
$data = $this->request->param();
if (Db::name('LcUser')->where(['id' => $uid])->update(['alipay' => $data['alipay']])) {
msg('操作成功!', 2, '/index/user/index');
} else {
msg('操作失败!', 2, '/index/user/index');
}
}
$this->fetch();
}
/**
* @description资金流水
* @date: 2020/5/14 0014
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function fund()
{
$uid = $this->uid;;
$page = Request::param('page', 1);
$num = Request::param('num', 10);
$this->finance = Db::name('LcFinance')->where('uid', $uid)->order("id desc")->page($page, $num)->select();
$this->success(json_lang("操作成功"), $this->finance);
}
/**
* @description投资记录
* @date: 2020/5/14 0014
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function invest()
{
$uid = $this->uid;
$this->invest = Db::name('LcInvest')->where('uid', $uid)->order("id desc")->select();
$this->fetch();
}
/**
* @description收益记录
* @date: 2020/5/14 0014
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function interest()
{
$uid = $this->uid;
$this->interest = Db::name('LcInvestList')->where("uid = $uid AND status = 1 AND pay1 <> 0")->order("time2 desc")->select();
$this->fetch();
}
/**
* @description充值记录
* @date: 2020/5/14 0014
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function recharge_record()
{
$uid = $this->uid;
$page = Request::param('page', 1);
$num = Request::param('num', 10);
$recharge = Db::name('LcRecharge')->where('uid', $uid)->order("id desc")->page($page, $num)->select();
$this->success(json_lang("操作成功"), $recharge);
}
/**
* @description提现记录
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author: DeeBoo <chan@deeboo.cn>
* @date: 2020/5/14 0014
*/
public function cash_record()
{
$uid = $this->uid;;
$page = Request::param('page', 1);
$num = Request::param('num', 10);
$cash = Db::name('LcCash')->where('uid', $uid)->order("id desc")->page($page, $num)->select();
$this->success(json_lang("操作成功"), $cash);
}
/**
* @description推广记录
* @date: 2020/5/14 0014
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function extend()
{
$uid = $this->uid;
$this->results = Db::name('LcUser')->field("id,name,phone,time")->where('top', $uid)->order("id desc")->select();
foreach ($this->results as &$vo) {
$vo['recharge'] = Db::name('LcRecharge')->where(['uid' => $vo['id'], 'status' => 1])->sum('money');
$vo['cash'] = Db::name('LcCash')->where(['uid' => $vo['id'], 'status' => 1])->sum('money');
}
$this->fetch();
}
/**
* @description邀请好友
* @date: 2020/5/14 0014
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function recommend()
{
$uid = $this->uid;
$user = Db::name('LcUser')->find($uid);
// if($user['auth'] != 1) msg('请实名认证后再进行邀请!', 2, '/index/User/certification');
$domain = getInfo('domain');
$this->url = $domain ? $domain : $uid = Request::host();
$this->fetch();
}
/**
* @description提现
* @date: 2020/5/14 0014
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function cash()
{
$uid = $this->uid;
$user = Db::name('LcUser')->find($uid);
$cashConfig = [
'user' => $user,
"bank" => Db::name('LcBank')->where('uid', $uid)->order("id desc")->select(),
'txsxf' => getInfo('cash_charge'),
'cash_start' => getInfo('cash_start'),
'cash_end' => getInfo('cash_end'),
'cash_min' => getInfo('cash_min'),
'cash_max' => getInfo('cash_max'),
'cash_day_max' => getInfo('cash_day_max'),
'cash_max_num' => getInfo('cash_max_num')
];
if (Request::isPost()) {
if ($user['rz_status'] != 2) {
$this->error(json_lang("请先完成实名认证!"));
}
if ($user['isjy'] == 1) {
$this->error(json_lang("账号被锁定,请联系管理员!"));
}
$time = time();
$cash_start = strtotime(date('Y-m-d ' . $cashConfig['cash_start'] . ':00'));
$cash_end = strtotime(date('Y-m-d ' . $cashConfig['cash_end'] . ':00'));
if ($time < $cash_start || $time > $cash_end) {
$this->error(json_lang("提现时间为") . $cashConfig['cash_start'] . '-' . $cashConfig['cash_end']);
}
$data = Request::param();
$money = $data['money'];
if (!$money) $this->error(json_lang("提现金额不能为空!"));
$pwd = $data['pwd'];
if (!$pwd) $this->error(json_lang("提现密码不能为空!"));
$today = date('Y-m-d 00:00:00');
if ($user['password2'] != md5($data['pwd']))
$this->error(json_lang("交易密码不正确!"));
if ($data['money'] < $cashConfig['cash_min'])
$this->error(json_lang("提现金额不能小于") . $cashConfig['cash_min']);
if ($data['money'] > $cashConfig['cash_max'])
$this->error(json_lang("提现金额不能大于") . $cashConfig['cash_max']);
if ($user['money'] < $data['money'])
$this->error(json_lang("账户余额不足,请确认"));
$day_num = Db::name('LcCash')->where("uid = $uid AND time > '$today'")->count();
if ($day_num >= $cashConfig['cash_max_num'])
$this->error(json_lang('每日提现次数') . $cashConfig['cash_max_num']);
$day_sum = Db::name('LcCash')->where("uid = $uid AND time > '$today'")->sum('money');
if ($day_sum >= $cashConfig['cash_day_max'])
$this->error(json_lang('当日累计最高提现金额不能大于') . $cashConfig['cash_day_max']);
if ($data['bank'] != 0) {
$bank = Db::name('LcBank')->where('id', $data['bank'])->find();
if ($bank['uid'] != $uid || empty($bank))
$this->error('请先绑定提现银行卡!');
}
$cash_charge = getInfo('cash_charge');
$sxf = $data['money'] * $cash_charge * 0.01;
$dzje = $data['money'] - $sxf;
$sxfbfb = $cash_charge;
if ($data['bank'] == 0) {
$add = array(
'uid' => $uid,
'sxf' => $sxf,
'dzje' => $dzje,
'sxfbfb' => $sxfbfb,
'name' => $user['name'],
'bid' => $data['bank'],
'bank' => '支付宝',
'area' => 0,
'account' => $user['alipay'],
'money' => $data['money'],
'status' => 0,
'time' => date('Y-m-d H:i:s'), 'time2' => '0000-00-00 00:00:00');
}
else {
$add = array('uid' => $uid,
'sxf' => $sxf,
'dzje' => $dzje,
'sxfbfb' => $sxfbfb,
'name' => $user['name'],
'bid' => $data['bank'],
'bank' => $bank['bank'],
'area' => $bank['area'] ?: 0,
'account' => $bank['account'],
'money' => $data['money'], 'status' => 0, 'time' => date('Y-m-d H:i:s'), 'time2' => '0000-00-00 00:00:00');
}
if (Db::name('LcCash')->insert($add)) {
addFinance($uid, $data['money'], 2, "余额提现{$data['money']}");
setNumber('LcUser', 'money', $data['money'], 2, "id = $uid");
$this->success(json_lang("提现申请成功!"));
} else {
$this->error(json_lang("提现失败!"));
}
}
$this->success(json_lang("操作成功"), $cashConfig);
}
/**
* @description充值
* @date: 2020/5/14 0014
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function recharge()
{
$uid = $this->uid;
$user = Db::name('LcUser')->find($uid);
$min_recharge = 1;
if (Request::isPost()) {
$data = Request::param();
if ($data['money'] < $min_recharge) {
$this->error('最低充值' . $this->min_recharge . '元');
}
$add = [
'uid' => $uid,
'money' => $data['money'],
'type' => "TRC20",
'status' => 0,
'time' => date('Y-m-d H:i:s'),
'time2' => '0000-00-00 00:00:00'
];
Db::name('LcRecharge')->insertGetId($add);
$this->success(json_lang('操作成功'));
}
$this->success(json_lang('操作成功'), ['user' => $user, 'min_recharge' => $min_recharge, 'address' => "TZEGFjVuHmGJCxc31e1GxgdonJEZVopJy4"]);
}
/**
* @description扫描充值
* @date: 2020/5/14 0014
*/
public function scan()
{
$type = $this->request->param('type');
$this->money = $this->request->param('money');
$this->qr = getInfo('qr_alipay_img');
if ($type == 'wechat')
$this->qr = getInfo('qr_wechat_img');
$this->fetch();
}
/**
* Describe:提现银行
* DateTime: 2020/5/14 21:44
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function bank()
{
$uid = $this->uid;
if (Request::isPost()) {
$data = $this->request->param();
$update = array('reason' => '付款人:' . $data['name'] . '<br/>转账附言:' . $data['reason']);
if (Db::name('LcRecharge')->where(['uid' => $uid, 'status' => 0, 'orderid' => $data['orderid']])->update($update)) {
msg('操作成功!', 2, '/index/user/index');
} else {
msg('操作失败!', 2, '/index/user/index');
}
}
$this->type = $this->request->param('type');
$this->orderid = $this->request->param('orderid');
$this->money = $this->request->param('money');
if (empty($this->orderid))
msg('充值失败!', 2, '/index/user/index');
$this->fetch();
}
/**
* Describe:合同详情
* DateTime: 2020/5/14 21:44
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function contract()
{
$this->uid = $this->uid;
if (!$this->uid)
$id = $this->request->param('id');
if (empty($id))
msg('参数缺失!', 2, '/index/user/index');
$this->invest = Db::name('LcInvest')->where(['uid' => $this->uid, 'id' => $id])->find();
$this->list = Db::name('LcInvestList')->where(['uid' => $this->uid, 'iid' => $id])->order('id desc')->select();
//if(!$this->invest||!$this->list) msg('暂无数据!', 2, '/index/user/index');
$this->fetch();
}
public function mall_contract()
{
$this->uid = $this->uid;
if (!$this->uid)
$id = $this->request->param('id');
if (empty($id))
msg('参数缺失!', 2, '/index/user/index');
$this->invest = Db::name('LcMallInvest')->where(['uid' => $this->uid, 'id' => $id])->find();
$this->list = Db::name('LcMallInvestList')->where(['uid' => $this->uid, 'iid' => $id])->order('id desc')->select();
$this->fetch();
}
public function details()
{
$this->uid = $this->uid;
if (!$this->uid)
$id = $this->request->param('id');
if (empty($id))
msg('参数缺失!', 2, '/index/user/index');
$this->invest = Db::name('LcInvest')->where(['uid' => $this->uid, 'id' => $id])->find();
$this->list = Db::name('LcInvestList')->where(['uid' => $this->uid, 'iid' => $id])->order('id asc')->select();
if (!$this->invest || !$this->list)
msg('暂无数据!', 2, '/index/user/index');
$this->fetch();
}
public function wallet()
{
$this->uid = $this->uid;
if (!$this->uid)
$user = Db::name('LcUser')->find($this->uid);
$now = date('Y-m-d H:i:s');
$this->kjbz = Db::name('LcMallInvest')->where('uid', $this->uid)->where("time2 >= '$now'")->sum('money');
$this->hybz = Db::name('LcInvest')->where('uid', $this->uid)->where("time2 >= '$now'")->sum('money');
$this->kjcl = Db::name('LcMallInvestList')->where(['uid' => $this->uid, 'status' => 1])->sum('money1');
$this->hysy = Db::name('LcInvestList')->where(['uid' => $this->uid, 'status' => 1])->sum('money1');
$this->kjsy = Db::name('LcFinance')->where("uid = {$this->uid} AND reason LIKE '%BTC兑换%'")->sum('money');
$this->fetch();
}
public function trade()
{
$this->uid = $this->uid;
if (!$this->uid)
$user = Db::name('LcUser')->find($this->uid);
$this->fetch();
}
public function tradeBTC()
{
$uid = $this->uid;
$user = Db::name('LcUser')->find($uid);
$data = $this->request->param();
if ($data['buynum'] <= 0)
$this->error("无效数量");
if ($data['buynum'] > $user['btc'])
$this->error("BTC不足");
$btc_price = 393848.54;
$money = round($btc_price * $data['buynum'], 2);
addFinance($uid, $money, 1, "BTC兑换交易{$money}");
setNumber('LcUser', 'money', $money, 1, "id = {$uid}");
setNumber('LcUser', 'btc', $data['buynum'], 2, "id = {$uid}");
$this->success("交易成功");
}
/**
* @description:退出登录
* @date: 2020/5/13 23:57
*/
public function logout()
{
$uid = $this->uid;
Db::table('lc_user')->where('id', $uid)->limit(1)->update(['access_time' => 0]);
session('uid', null);
//$this->app->session->clear();
//$this->app->session->destroy();
$this->redirect('/index');
}
public function hold()
{
$uid = $this->uid;
$page = Request::param('page', 1);
$num = Request::param('num', 10);
$this->type = $this->request->param('type');
$this->hold = Db::name('LcOrder')->where(array('uid' => $uid, 'ostaus' => 0))->order('id desc')->page($page, $num)->select();
//->field('id,ptitle,buytime,fee,ostyle')
//var_dump($this->hold);die;
$this->success(json_lang("操作成功"), $this->hold);
}
/**
* 下单
* @return void [type] [description]
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author lukui 2017-07-20
*/
public function addorder()
{
$data = Request::param();
$uid = $this->uid;
//用户信息
$user = Db::name('LcUser')->find($uid);
if (!$user) $this->error(json_lang("用户不存在"));
//验证用户是否被冻结
if ($user['clock'] == 1) {
// return WPreturn('您的账户已被冻结',-1);
}
if ($user['isjy'] == 1) {
$this->error(json_lang("账号被锁定,请联系管理员!"));
}
$adddata['uid'] = $uid;
$pro = Db::name('LcProduct')->find($data['order_pid']);
if (!$pro)
$this->error(json_lang("产品未找到"));
//验证是否开市
if ($pro['isopen']) {
$isopen = ChickIsOpen($pro['id']);
if ($isopen == 0) {
$this->error(json_lang("休市中"));
}
} else {
$this->error(json_lang("休市中"));
}
if (getinfo('order_max_amount') > 0) {
$allfee = Db::name('LcOrder')->where(array('ostaus' => 0, 'uid' => $data['uid']))->sum('fee');
$allfee = $allfee ? $allfee : 0;
if ($allfee + $data['order_price'] > getinfo('order_max_amount')) {
$this->error(json_lang("持仓最大金额为") . getinfo('order_max_amount') . '');
}
}
if ($data['order_price'] < getinfo('order_min')) {
$this->error(json_lang("持仓最小金额为") . getinfo('order_min') . '');
}
//持仓限制
if (getinfo('order_max_amount') > 0) {
$allfee = Db::name('LcOrder')->where(array('ostaus' => 0, 'uid' => $data['uid']))->sum('fee');
$allfee = $allfee ? $allfee : 0;
if ($allfee + $data['order_price'] > getinfo('order_max_amount')) {
$this->error(json_lang("持仓最大金额为") . getinfo('order_max_amount') . '');
}
}
if (getinfo('order_max_count') > 0) {
Db::name('LcOrder')->where(array('ostaus' => 0, 'uid' => $data['uid']))->count();
}
//手续费
$web_poundage = 0;
if (getinfo('order_charge') > 0) {
$web_poundage = round($data['order_price'] * getinfo('order_charge') / 100, 2);
}
$moneyfrom = 1;
//验证余额是否够
if ($user['money'] < $data['order_price'] + $web_poundage) {
$this->error(json_lang("账户余额不足,请确认"));
}
if (floatval($data['newprice']) <= 0) {
$this->error(json_lang("操作失败"));
}
//建仓
$adddata['buytime'] = time();
$adddata['endprofit'] = $data['order_sen'];
$adddata['pid'] = $data['order_pid'];
$adddata['ostyle'] = $data['order_type'];
$adddata['buyprice'] = $data['newprice'];
$adddata['endloss'] = $data['order_shouyi'];
$adddata['lossrate'] = $data['order_kuishun'];
$adddata['eid'] = 2;
$adddata['selltime'] = $adddata['buytime'] + $adddata['endprofit'];
$adddata['fee'] = $data['order_price'];
$adddata['ptitle'] = $pro['title'];
$adddata['ostaus'] = '0';
$adddata['sx_fee'] = $web_poundage;
$allfee = $adddata['fee'] + $adddata['sx_fee'];
//会员建仓后金额
$adddata['commission'] = $user['money'] - $allfee;
//订单号
$adddata['orderno'] = date('YmdHis') . $uid . rand(1111, 9999);
//var_dump($adddata);
//下单
$id = Db::name('LcOrder')->insertGetId($adddata);
if ($id) {
//下单成功减用户余额
if ($moneyfrom == 1) {
addFinance($uid, $allfee, 2, '下单[' . $adddata['orderno'] . ']从账户扣除金额 ' . $allfee . '元');
setNumber('LcUser', 'money', $allfee, 2, "id = $uid");
}
if ($moneyfrom == 2) {
addFinance($uid, $allfee, 2, '下单[' . $adddata['orderno'] . ']从余额宝扣除金额 ' . $allfee . '元');
setNumber('LcUser', 'money', $allfee, 2, "id = $uid");
//Db::table('lc_yuebao_uc')->where('uid = '.$uid)->update(['balance'])
}
$nowmoney = $adddata['commission'];
if ($nowmoney < 0) {
$nowmoney = 0;
}
$adddata['oid'] = $id;
$order_rand = rand(1, 1000);
$adddata['order_rand'] = $order_rand;
$this->success(json_lang("操作成功"), $adddata);
} else {
$this->error(json_lang("操作失败"));
}
}
public function goorder()
{
// {
// "price": "275.661",
// "oid": "463",
// "order_rand": "547"
// }
$data = $this->request->param();
$oid = $data['oid'];
$price = $data['price'];
$order_rand = $data['order_rand'];
$static = 1; //1成功返回并继续运行 0失败返回不运行 2 失败返回继续轮询
if (!$oid || !$price || !$order_rand) {
die('0' . $oid . '-' . $price . '-' . $order_rand);
}
$order = Db::name('LcOrder')->find($oid);
//没有此订单
if (!$order) {
die('1' . $oid . '-' . $price . '-' . $order_rand);
}
//没有平仓
if (isset($order['ostyle']) && $order['ostaus'] == 0) {
die('2');
}
//已平仓 但是价格相同
if (isset($order['sellprice']) && $order['sellprice'] == $price) {
cache('goorder_' . $order['id'], null);
die('1');
}
//已平仓 但是无效交易
if (isset($order['is_win']) && $order['is_win'] == 3) {
cache('goorder_' . $order['id'], null);
die('1');
}
//该订单指定赢亏
if (isset($order['kong_type']) && $order['kong_type'] != 0) {
cache('goorder_' . $order['id'], null);
die('1');
}
die('1');
}
public function get_price()
{
//此刻产品价格
$pro = Db::name('LcProduct')->field('id,Price')->where(array('isdelete' => 0))->select();
$prodata = array();
foreach ($pro as $k => $v) {
$prodata[$v['id']] = $v['Price'];
}
return base64_encode(json_encode($prodata));;
}
/**
* ajax 通过产品id 获取用户订单,
* @return [type] [description]
* @author lukui 2017-07-22
*/
public function ajaxorder()
{
$uid = $this->uid;
$pid = $this->request->param('pid');
if (empty($uid) || empty($pid)) {
return false;
}
//持仓信息
$map = [];
$map[] = ['uid', '=', $uid];
$map[] = ['pid', '=', $pid];
$map[] = ['ostaus', '=', 0];
$map[] = ['selltime', '>', time()];
$list = Db::name('LcOrder')->where($map)->order('id desc')->select();
foreach ($list as $key => $value) {
$list[$key]['time'] = time();
}
if ($list) {
return base64_encode(json_encode($list));
// return json_encode($list);
} else {
return false;
}
}
/**
* ajax 通过产品id 平仓后弹框提示,
* @return [type] [description]
* @author lukui 2017-07-22
*/
public function ajaxalert()
{
$uid = $this->uid;
$pid = $this->request->param('pid');
if (empty($uid) || empty($pid)) {
return false;
}
//持仓信息
$hold = Db::name('LcOrder')->field('id,ploss,fee,eid')->where(array('uid' => $uid, 'ostaus' => 1, 'pid' => $pid, 'isshow' => 0))->order('id desc')->find();
//修改持仓信息
$isedit = Db::name('LcOrder')->where('id', $hold['id'])->setField('isshow', '1');
if ($hold && $isedit) {
return $hold;
} else {
return false;
}
}
/**
* 交易记录
* @return [type] [description]
* @author lukui 2017-07-22
*/
public function ajaxorder_list()
{
$uid = $this->uid;
if (empty($uid)) {
$this->error('用户ID不能为空');
}
$type = input('type', 0);
$page = Request::param('page', 1);
$num = Request::param('num', 10);
//持仓信息
$map = [];
$map[] = ['ostaus', '=', $type];
$map[] = ['uid', '=', $uid];
$list = Db::name('LcOrder')->where($map)->order('id desc')->page($page, $num)->select();
foreach ($list as $key => $value) {
$list[$key]['time'] = time();
$list[$key]['ploss'] = round($value['ploss'], 2);
}
if ($list) {
$this->success(json_lang("操作成功"), $list);
} else {
$this->success('暂无数据', []);
}
}
public function getchart()
{
$data['hangqing'] = '商品行情';
$data['jiaoyijilu'] = '交易记录';
$data['jiaoyilishi'] = '历史委托';
$data['chicangmingxi'] = '持仓明细';
$data['lishimingxi'] = '历史明细';
$data['gendanjiaoyi'] = '跟单交易';
$res = base64_encode(json_encode($data));
return $res;
}
public function orderlist()
{
$uid = $this->uid;
if (empty($uid)) {
return false;
}
$map = [];
$map[] = ['uid', '=', $uid];
$map[] = ['ostaus', '=', 1];
$hold = Db::name('LcOrder')->where($map)->order('id desc')->paginate(20);
return base64_encode(json_encode($hold));
}
/**
* 已平仓订单详情
* @return [type] [description]
* @author lukui 2017-07-21
*/
public function orderinfo()
{
$uid = $this->uid;
$oid = $this->request->param('oid');
if (!$oid) {
$this->redirect('orderlist');
}
$order = Db::name('LcOrder')->where('id', $oid)->find();
$this->assign($order);
return $this->fetch();
}
/**
* 实时获取以平仓订单
* @return [type] [description]
*/
public function get_this_order()
{
$oid = $this->request->param('oid');
$map['id'] = $oid;
$map['ostaus'] = 1;
$order = Db::name('LcOrder')->where($map)->find();
return base64_encode(json_encode($order));
}
/**
* 实时获取以平仓订单
* @return [type] [description]
*/
public function get_hold_order()
{
$oid = $this->request->param('oid');
$map['id'] = $oid;
$map['ostaus'] = 1;
$order = Db::name('LcOrder')->where($map)->find();
return base64_encode(json_encode($order));
}
public function inquiries()
{
$uid = $this->uid;
$map['uid'] = $uid;
$map['ostaus'] = 1;
$this->list = Db::name('LcOrder')->where($map)->order('id desc')->select();
$this->fetch();
}
public function yeb()
{
$yuebao = Db::name('lc_yuebao')->where('status = 1')->order('id desc')->select();
$this->success(json_lang("操作成功"), $yuebao);
}
public function yebtrans()
{
Db::startTrans();
try {
$uid = $this->uid;
$money = (float)input('post.money');
if ($money <= 0) {
return json(['code' => 500, 'msg' => '转出金额错误!']);
}
$uc = Db::table('lc_yuebao_uc')->lock(true)->where('uid', $uid)->find();
if ($money > $uc['trans_balance']) {
return json(['code' => 500, 'msg' => '大于可转出金额!']);
}
Db::table('lc_yuebao_uc')->where('id', $uc['id'])->limit(1)->update(['trans_balance' => round($uc['trans_balance'] - $money, 1)]);
$userMoney = DB::table('lc_user')->where('id', $uid)->value('money');
Db::table('lc_user')->where('id', $uid)->limit(1)->update(['money' => round($userMoney + $money, 1)]);
DB::table('lc_finance')->insert(['uid' => $uid, 'money' => $money, 'type' => 1, 'reason' => '利息宝转出', 'before' => $userMoney, 'time' => date('Y-m-d H:i:s')]);
return json(['code' => 200, 'msg' => '转出成功!']);
Db::commit();
} catch (Exception $e) {
Db::rollback();
return json(['code' => 500, 'msg' => '转出失败!']);
}
}
public function yebjoinnow()
{
//
$param = Request::param();
$uid = $this->uid;
//优先核对账户余额,并扣减。
$where['id'] = $uid;
$userinfo = Db::table('lc_user')->where($where)->find();
if ($userinfo['money'] < $param['money']) {
$this->error(json_lang("账户余额不足,请确认"));
}
//查找余额宝理财方案信息,并校检。
$where['id'] = $param['yebid'];
$yebinfo = Db::table('lc_yuebao')->where($where)->find();
if ($yebinfo['lowmoney'] > $param['money']) {
$this->error(json_lang("您办理的方案有最低存入:") . $yebinfo['lowmoney']);
}
$newmoney = $userinfo['money'] - $param['money'];
$res = Db::table('lc_user')->where('id', $userinfo['id'])->update(['money' => $newmoney]);
if (!$res) {
$this->error(json_lang("网络异常,请稍后再试:"));
}
$res = DB::table('lc_finance')->insert(['uid' => $userinfo['id'], 'money' => $param['money'], 'type' => 2, 'reason' => '利息宝转入', 'before' => $userinfo['money'], 'time' => date('Y-m-d H:i:s')]);
if (!$res) {
$this->error(json_lang("网络异常,请稍后再试:"));
}
//保存办理记录。
$savelist = array('uid' => $uid,
'username' => $userinfo['phone'],
'yuebaoid' => $yebinfo['id'],
'yebtitle' => $yebinfo['title'],
'lily' => $yebinfo['lily'],
'money' => $param['money'],
'days' => $yebinfo['days'],
'start_time' => time(),
'profit_time' => time(),
'end_time' => time() + $yebinfo['days']*86400,
'nowprofit' => 0, 'finishprofit' => round(($param['money'] * $yebinfo['lily']/ 100) * $yebinfo['days'], 4), 'status' => 1);
$newid = Db::table('lc_yuebao_lists')->insertGetId($savelist);
if (!$newid) {
$this->error(json_lang("网络异常,请稍后再试:"));
}
//再做UC
unset($where['id']);
$where['uid'] = $uid;
$yebucinfo = Db::table('lc_yuebao_uc')->where($where)->find();
$newbalance = $yebucinfo['balance'] + $param['money'];
Db::table('lc_yuebao_uc')->where($where)->update(['balance' => $newbalance]);
//再做UCLOG
$yebuclog = array('uid' => $uid, 'balance' => $yebucinfo['balance'], 'money' => $param['money'], 'addtime' => time(), 'remarks' => "用户购买理财方案:" . $yebinfo['title']);
Db::table('lc_yuebao_uclog')->insert($yebuclog);
$this->success(json_lang("操作成功"));
}
public function yebstop()
{
$uid = $this->uid;
$param = Request::param();
$getlistinfo = Db::table('lc_yuebao_lists')->where('id=' . $param['id'])->find();
if ($getlistinfo['status'] != 1 or empty($getlistinfo)) {
return "操作失败:订单无法操作!";
die;
}
$getuserinfo = Db::table('lc_user')->where('id=' . $getlistinfo['uid'])->find();
//var_dump($getlistinfo,$getuserinfo);die;
if (!empty($getuserinfo)) {
Db::table('lc_yuebao_lists')->where('id=' . $param['id'])->update(['status' => 2, 'end_time' => time()]);
//记录日志!
unset($getlistinfo['id']);
$getlistinfo['status'] = 2;
$getlistinfo['end_time'] = time();
$getlistinfo['balance'] = $getuserinfo['money'];
$getlistinfo['closetime'] = time();
$getlistinfo['remarks'] = "客户手动结算";
Db::table('lc_yuebao_log')->insert($getlistinfo);
//更新用户余额
$newbalance = $getuserinfo['money'] + $getlistinfo['nowprofit'] + $getlistinfo['money'];
Db::table('lc_user')->where('id=' . $getlistinfo['uid'])->update(['money' => $newbalance]);
//更新UC
$where['uid'] = $uid;
$yebucinfo = Db::table('lc_yuebao_uc')->where($where)->find();
$newbalance = $yebucinfo['balance'] - $getlistinfo['money'];
Db::table('lc_yuebao_uc')->where($where)->update(['balance' => $newbalance]);
//再做UCLOG
$yebuclog = array('uid' => $uid, 'balance' => $yebucinfo['balance'], 'money' => $getlistinfo['money'], 'addtime' => time(), 'remarks' => "用户购买理财方案:" . $getlistinfo['title']);
Db::table('lc_yuebao_uclog')->insert($yebuclog);
return "ok";
die;
} else {
return "操作失败:订单无法操作!";
die;
}
}
public function yebkeep()
{
$uid = $this->uid;
$param = Request::param();
$getlistinfo = Db::table('lc_yuebao_lists')->where('id=' . $param['id'])->find();
if ($getlistinfo['status'] == 2) {
return "操作失败:订单无法操作!";
die;
} elseif ($getlistinfo['status'] == 1) {
$getlistinfo['end_time'] = $getlistinfo['end_time'] + $getlistinfo['days'] * 86400;
}
unset($getlistinfo['id']);
Db::table('lc_yuebao_lists')->where('id=' . $param['id'])->update(['end_time' => $getlistinfo['end_time']]);
return "操作成功";
die;
}
/**
* @description身份认证
* @date: 2020/5/14 0014
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function verified()
{
$uid = $this->uid;
$user = Db::name('LcUser')->field('rz_status,name,idcard,z_id_card,f_id_card')->find($uid);
if (Request::isPost()) {
$param = Request::param();
if ($user['rz_status'] == 2) {
$this->error(json_lang('已认证请勿重复提交!'));
}
$name = $param['name'];
if (!$name) $this->error(json_lang('名字不能为空!'));
$idcard = $param['idcard'];
if (!$idcard) $this->error(json_lang('身份证号码不能为空!'));
$z_id_card = $param['z_id_card'];
if (!$z_id_card) $this->error(json_lang('身份证正面照不能为空!'));
$f_id_card = $param['f_id_card'];
if (!$f_id_card) $this->error(json_lang('身份证反面照不能为空!'));
// $country = $param['country'];
// if (!$country) $this->error(json_lang('地址不能为空!'));
$data = $param;
$check = Db::name('LcUser')->where("idcard = '{$data['idcard']}' AND id <> " . $uid)->find();
if ($check)
$this->error(json_lang('身份证号码已被其他账号绑定!'));
if (Db::name('LcUser')->where(['id' => $uid])->update([
'name' => $data['name'],
'idcard' => $data['idcard'],
'z_id_card' => $data['z_id_card'],
'f_id_card' => $data['f_id_card'],
// 'country' => $data['country'],
'rz_status' => 1
])) {
$this->success(json_lang('认证信息提交成功!'));
} else {
$this->error(json_lang('认证信息提交失败!'));
}
}
$this->success(json_lang('操作成功'), $user);
}
}