find($uid); if(!$user||!$user['clock']) return false; $data = ['logintime' => time(),'id'=>$uid]; Db::name('LcUser')->update($data); return true; } } /** * @description:手机号验证 * @date: 2020/5/14 0014 * @param $phone * @return bool */ function isMobile($phone){ if(preg_match("/^1[3456789]{1}\d{9}$/",$phone)) return true; return false; } function isAlphaNum($phone){ if(preg_match("/^[A-Za-z0-9]+$/",$phone)) return true; return false; } /** * @description:IP查询 * @date: 2020/5/14 0014 * @param string $ip * @return array|bool|string */ function GetIpLookup($ip = ''){ if(empty($ip)){ return ''; } $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip; $ip=json_decode(file_get_contents($url)); if((string)$ip->code=='1'){ return false; } $data = (array)$ip->data; return $data; } /** * @description:添加流水 * @date: 2020/5/13 0013 * @param $uid * @param $money * @param $type * @param $reason * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ function addFinance($uid,$money,$type,$reason){ $user = Db::name('LcUser')->find($uid); if(!$user) return false; if($user['money']<0) return false; $data = array( 'uid' => $uid, 'money' => $money, 'type' => $type, 'reason' => $reason, 'before' => $user['money'], 'time' => date('Y-m-d H:i:s') ); Db::name('LcFinance')->insert($data); } /** * @description: * @date: 2020/5/14 0014 * @param $str * @param $type * @return bool */ function judge($str, $type) { $char = ''; if ($type == 'int') { $char = '/^\\d*$/'; } else if ($type == 'email') { $char = '/([\\w\\-]+\\@[\\w\\-]+\\.[\\w\\-]+)/'; } else if ($type == 'idcard') { $char = '/[0-9]{17}([0-9]|X)/'; } else if ($type == 'name') { $char = '/^[\\x{4e00}-\\x{9fa5}]+[·•]?[\\x{4e00}-\\x{9fa5}]+$/u'; } else if ($type == 'phone') { $char = '/^1[3456789]{1}\\d{9}$/'; } else if ($type == 'tel') { $char = '/(^(\\d{3,4}-)?\\d{7,8})$/'; } else if ($type == 'date') { $char = '/^\\d{4}[\\-](0?[1-9]|1[012])[\\-](0?[1-9]|[12][0-9]|3[01])?$/'; } else if ($type == 'time') { $char = '/^\\d{4}[\\-](0?[1-9]|1[012])[\\-](0?[1-9]|[12][0-9]|3[01])(\\s+(0?[0-9]|1[0-9]|2[0-3])\\:(0?[0-9]|[1-5][0-9])\\:(0?[0-9]|[1-5][0-9]))?$/'; } else if ($type == 'exist') { } else { return false; } if (preg_match($char, $str)) { return true; } return false; } /** * @description:设置 * @date: 2020/5/13 0013 * @param $database * @param $field * @param $value * @param int $type * @param string $where * @return int|true * @throws \think\Exception */ function setNumber($database, $field, $value, $type = 1, $where = '') { if ($type != 1) { $re = Db::name($database)->where($where)->setDec($field, $value); } else { $re = Db::name($database)->where($where)->setInc($field, $value); } return $re; } /** * @description:脱敏 * @date: 2020/5/14 0014 * @param $string * @param int $start * @param int $length * @param string $re * @return bool|string */ function dataDesensitization($string, $start = 0, $length = 0, $re = '*') { if (empty($string)) { return false; } $strarr = array(); $mb_strlen = mb_strlen($string); while ($mb_strlen) { $strarr[] = mb_substr($string, 0, 1, 'utf8'); $string = mb_substr($string, 1, $mb_strlen, 'utf8'); $mb_strlen = mb_strlen($string); } $strlen = count($strarr); $begin = $start >= 0 ? $start : ($strlen - abs($start)); $end = $last = $strlen - 1; if ($length > 0) { $end = $begin + $length - 1; } elseif ($length < 0) { $end -= abs($length); } for ($i = $begin; $i <= $end; $i++) { $strarr[$i] = $re; } if ($begin >= $end || $begin >= $last || $end > $last) return false; return implode('', $strarr); } /** * @description:投资状态 * @date: 2020/5/14 0014 * @param $id * @return string */ function getInvestStatus($id) { $invest = Db::name('LcInvestList')->where("status = 0 AND iid = $id")->count(); if (0 < $invest) { return '未完成'; } return '已完成'; } /** * @description:身份认证 * @date: 2020/5/14 0014 * @param $id_card * @param $name * @param $app_code * @return array */ function idCardAuth($id_card,$name){ $host = 'http://idcard.market.alicloudapi.com'; $path = '/lianzhuo/idcard'; $method = 'GET'; $appcode = getInfo('linetoken'); $headers = array(); array_push($headers, 'Authorization:APPCODE ' . $appcode); $querys = 'cardno=' . $id_card . '&name=' . $name; $url = $host . $path . '?' . $querys; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); if (1 == strpos('$' . $host, 'https://')) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } $re = curl_exec($curl); $resp = json_decode($re, true); if ($resp['resp']['code'] == '5') return ['code'=>0,'msg'=>'姓名和身份证号码不匹配']; if ($resp['resp']['code'] == '14') return ['code'=>0,'msg'=>'无此身份证号码']; if ($resp['resp']['code'] == '96') return ['code'=>0,'msg'=>'交易失败,请稍后重试']; if ($resp['resp']['code'] != '0') return ['code'=>0,'msg'=>'网络繁忙,请稍后重试!']; return ['code'=>1,'msg'=>'认证成功']; } /** * @description:银行卡认证 * @date: 2020/5/14 0014 * @param $name * @param $account * @param $id_card * @return array */ function bankAuth($name,$account,$id_card){ $host = 'http://lundroid.market.alicloudapi.com'; $path = '/lianzhuo/verifi'; $method = 'GET'; $appcode = getInfo('banktoken'); $headers = array(); array_push($headers, 'Authorization:APPCODE ' . $appcode); $querys = 'acct_name=' . $name . '&acct_pan=' . $account . '&cert_id=' . $id_card; $url = $host . $path . '?' . $querys; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); if (1 == strpos('$' . $host, 'https://')) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } header('Content-type:text/html; charset=utf-8'); $re = curl_exec($curl); $res = json_decode($re, true); if($res['resp']['code'] == 0 && $res['resp']['desc'] == 'OK') return ['code'=>1,'bank'=>$res['data']['bank_name']]; return ['code'=>0,'msg'=>'银行卡认证失败']; } /** * Describe:会员等级 * DateTime: 2020/5/13 23:49 * @param $member * @return mixed|string */ function getUserMember($member) { $member = Db::name('LcUserMember')->where("id = {$member}")->value('name'); return $member?$member:'普通会员'; } /** * @description:获取支付方式 * @date: 2020/5/14 0014 * @param $pay * @return string */ function getPayName($pay) { switch ($pay) { case 'wechat': return '微信扫码'; case 'alipay': return '支付宝扫码'; case 'bank': return '银行入款'; case 'gz_bank': return '公账入款'; case 'alipay_bank': return '支付宝转银行卡'; case 'wx_bank': return '微信转银行卡'; case 'online_wechat': return '微信在线支付'; case 'online_alipay': return '支付宝在线支付'; case 'wechat_scan': return '微信在线扫码支付'; default: } return '未知支付'; } function gotoWechatPay($money){ $status = getInfo('qr_wechat_statustz'); $wxlianjie = getInfo('qr_wechattzlj'); if($status == 1){ $url = $wxlianjie; } else{ $url = "/index/User/scan?type=wechat&money=".$money;//扫码链接 } header("Location:".$url); } function gotoAlipay($money){ $status = getInfo('qr_alipay_statustz'); $zfblianjie = getInfo('qr_alipaytzlj'); if($status == 1){ $url = $zfblianjie; } else{ $url = "/index/User/scan?type=alipay&money=".$money;//扫码链接 } header("Location:".$url); } /** * Describe: 理财开关 * DateTime: 2020/5/13 22:44 * @param $uid * @return int * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ function getlcopen($uid = ''){ $lcopen =0; if(!$uid){ $uid = Session::get('uid'); } if (!empty($uid)){ $user = Db::name('LcUser')->where("id = $uid")->find(); if (getInfo('qdlcopen') == 0){ $lcopen = 1; }else{ if ($user['qdnum'] >= getInfo('qdnum') || $user['top'] > 0) { $lcopen = 1; }else{ $lcopen = 0; } } } return $lcopen; } /** * @description:获取网站配置 * @date: 2020/5/14 0014 * @param $value * @return mixed */ function getInfo($value){ return Db::name('LcInfo')->where('id',1)->value($value); } /** * @description:获取奖励配置 * @date: 2020/5/14 0014 * @param $value * @return mixed */ function getReward($value){ return Db::name('LcReward')->where('id',1)->value($value); } /** * @description:项目进度 * @date: 2020/5/14 0014 * @param $id * @return float|int|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ function getProjectPercent($id){ $item = Db::name('LcItem')->find($id); if($item['auto']>0){ $xc=diffBetweenTwoDays($item['time'],date('Y-m-d H:i:s')); if($xc>$item['auto']){ $total=100; }else{ $total= round($xc/$item['auto']*100); } }else{ $pid = $item['id']; $percent = $item['percent']; $investMoney = Db::name('LcInvest')->where('pid', $pid)->sum('money'); $actual = $investMoney / ($item['total'] * 10000) * 100; $total = $actual + $percent; } if (100 < $total) return 100; return $total; } function diffBetweenTwoDays ($day1, $day2) { $second1 = strtotime($day1); $second2 = strtotime($day2); if ($second1 < $second2) { $tmp = $second2; $second2 = $second1; $second1 = $tmp; } return ($second1 - $second2) / 86400; } /** * @description: * @date: 2020/5/14 0014 * @param $money * @param $rate * @param $day * @return float */ function getFuliIncome($money, $rate, $day) { $sum = $money; $i = 0; while ($i < $day) { $sum = $sum + $sum * $rate / 100; ++$i; } return round($sum - $money, 2); } /** * @description: * @date: 2020/5/14 0014 * @param $pid * @return float|int * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ function getProjectSurplus($pid) { $percent = getProjectPercent($pid); $total = Db::name('LcItem')->where('id', $pid)->value('total'); $surplus = (100 - $percent) * $total * 100; if ($surplus < 0) return 0; return $surplus; } function getProfit($day_income,$cost){ return number_format($day_income-$cost, 8, '.', ''); } function getMinerPercent($total,$stock){ return round(($total-$stock)/$total*100,2); } /** * @description:奖励设置 * @date: 2020/5/14 0014 * @param $uid * @param $money * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ function setInvestReward_old($uid, $money ) { $reward = Db::name('LcReward')->find(1); $top1 = round($reward['invest1'] * $money / 100, 2); $top2 = round($reward['invest2'] * $money / 100, 2); $top3 = round($reward['invest3'] * $money / 100, 2); $t1 = Db::name('LcUser')->where(['id'=>$uid])->value('top') ?: 0; $t2 = Db::name('LcUser')->where(['id'=>$t1])->value('top') ?: 0; $t3 = Db::name('LcUser')->where(['id'=>$t2])->value('top') ?: 0; if (0 < $top1 && !empty($t1)) { addFinance($t1, $top1, 1, '推荐会员投资' . $money . '元奖励' . $top1 . '元!'); setNumber('LcUser', 'money', $top1, 1, "id = $t1"); setNumber('LcUser', 'income', $top1, 1, "id = $t1"); } if (0 < $top2 && !empty($t2)) { addFinance($t2, $top2, 1, '二级推荐会员投资' . $money . '元奖励' . $top2 . '元!'); setNumber('LcUser', 'money', $top2, 1, "id = $t2"); setNumber('LcUser', 'income', $top2, 1, "id = $t2"); } if (0 < $top3 && !empty($t3)) { addFinance($t3, $top3, 1, '三级推荐会员投资' . $money . '元奖励' . $top3 . '元!'); setNumber('LcUser', 'money', $top3, 1, "id = $t3"); setNumber('LcUser', 'income', $top3, 1, "id = $t3"); } } function setUserMember($uid, $value) { $member = Db::name('LcUserMember')->where("value <= '{$value}'")->order('value desc')->find(); if(empty($member)){ $mid = 0; }else{ $mid = $member['id']; } Db::name('LcUser')->where("id = {$uid}")->update(array('member' => $mid)); return $mid; } function getUserField($uid, $field) { return Db::name('LcUser')->where(['id'=>$uid])->value($field); } function getUserPhone($uid) { return Db::name('LcUser')->where(['id'=>$uid])->value('phone'); } /** * @description: * @date: 2020/5/14 0014 * @param $uid * @param $money * @param $id * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ function setInvestReward($uid, $money,$id) { $reward = Db::name("LcItem")->find($id); $top1 = round($reward['invest1'] * $money / 100, 2); $top2 = round($reward['invest2'] * $money / 100, 2); $top3 = round($reward['invest3'] * $money / 100, 2); /*$red1 = round($reward['red1'], 2); $red2 = round($reward['red2'], 2); $red3 = round($reward['red3'], 2);*/ $t1 = getUserField($uid, 'top') ?: 0; $t2 = getUserField($t1, 'top') ?: 0; $t3 = getUserField($t2, 'top') ?: 0; if (0 < $top1 && !empty($t1)) { addFinance($t1,$top1,1,'推荐会员(' . getUserPhone($uid) . ')投资' . $money . '元奖励' . $top1 . '元!'); setNumber('LcUser', 'money', $top1, 1, 'id=\'' . $t1 . '\''); setNumber('LcUser', 'income', $top1, 1, 'id=\'' . $t1 . '\''); } if (0 < $top2 && !empty($t2)) { addFinance($t2, $top2,1, '二级推荐会员(' . getUserPhone($uid) . ')投资' . $money . '元奖励' . $top2 . '元!'); setNumber('LcUser', 'money', $top2, 1, 'id=\'' . $t2 . '\''); setNumber('LcUser', 'income', $top2, 1, 'id=\'' . $t2 . '\''); } if (0 < $top3 && !empty($t3)) { addFinance($t3, $top3,1, '三级推荐会员(' . getUserPhone($uid) . ')投资' . $money . '元奖励' . $top3 . '元!'); setNumber('LcUser', 'money', $top3, 1, 'id=\'' . $t3 . '\''); setNumber('LcUser', 'income', $top3, 1, 'id=\'' . $t3 . '\''); } //以下为红包奖励 /* if (0 < $red1 && !empty($t1)) { addFinance($t1, $red1, 1, '推荐会员(' . getUserPhone($uid) . ')投资' . $money . '元奖励红包' . $red1 . '元!'); setNumber('user', 'money', $red1, 1, 'id=\'' . $t1 . '\''); setNumber('user', 'income', $red1, 1, 'id=\'' . $t1 . '\''); } if (0 < $red2 && !empty($t2)) { addFinance($t2, $red2, 1, '二级推荐会员(' . getUserPhone($uid) . ')投资' . $money . '元奖励红包' . $red2 . '元!'); setNumber('user', 'money', $red2, 1, 'id=\'' . $t2 . '\''); setNumber('user', 'income', $red2, 1, 'id=\'' . $t2 . '\''); } if (0 < $red3 && !empty($t3)) { addFinance($t3, $red3, 1, '三级推荐会员(' . getUserPhone($uid) . ')投资' . $money . '元奖励红包' . $red3 . '元!'); setNumber('user', 'money', $red3, 1, 'id=\'' . $t3 . '\''); setNumber('user', 'income', $red3, 1, 'id=\'' . $t3 . '\''); }*/ } /** * @description: * @date: 2020/5/14 0014 * @param $id * @param $money * @param $uid * @return bool * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ function getInvestList($id, $money, $uid) { $item = Db::name('LcItem')->where(['id'=>$id])->find(); $title = $item['title']; $type = $item['type']; $day = $item['day']; $jfbl = $item['jfbl']; $rate = $item['rate']; $mid = Db::name('LcUser')->where(['id'=>$uid])->value('member'); $member = Db::name('LcUserMember')->where("id = $mid")->find(); if (!empty($member) && 0 < $member['rate']) { $rate += $member['rate'] ?: 0; } /*if (date('Y-m-d H:i:s') <= $item['jiaxitime']) { $rate += $item['jiaxi'] ?: 0; }*/ //赠送抽奖次数 if ($item['prize'] == 1) { $num = intval($money / $item['min']); setNumber('LcUser', 'prize', $num, 1, "id = $uid"); } //赠送积分 if ($item['integral'] == 1) { setNumber('LcUser', 'integral', intval($money)*intval($jfbl), 1, "id = $uid"); } $res=Db::name('LcInvest')->order("id desc")->find(); if($res['number']){ $number= date('ymd').sprintf("%05d", substr($res['number'],-5)+1); }else{ $number= date('ymd').'01000'; } $invest = array('uid' => $uid,'number'=>$number ,'pid' => $id, 'title' => $title, 'money' => $money, 'day' => $day, 'rate' => $rate, 'type1' => $type, 'type2' => getprojecttype($type), 'status' => 0, 'time' => date('Y-m-d H:i:s'),'time2'=>date('Y-m-d H:i:s', strtotime('+' . $item['day'] . ' day'))); setNumber('LcUser', 'value', $money, 1, "id = $uid"); setUserMember($uid, Db::name('LcUser')->where(['id'=>$uid])->value('value')); setInvestReward($uid, $money,$id); $iid = Db::name('LcInvest')->insertGetId($invest); if (!empty($iid)) { if ($type == 1) { $base = 1; } else if ($type == 2) { $base = 7; } else if ($type == 3) { $base = 30; } else if ($type == 4) { $base = 1; } else if ($type == 5) { $base = $day; } elseif ($type == 6) { $base = 1; }else{ $base = 0; } $day2 = $day / $base; $bool = false; $money2 = $money; $i = 1; while($i <= $day2){ $time1 = $i * $base; $data = array('uid' => $uid, 'iid' => $iid, 'num' => $i, 'title' => $title, 'money1' => round($money * $rate / 100 * $base, 2), 'money2' => 0, 'time1' => $type == 6?$item['fixedtime']:date('Y-m-d H:i:s', strtotime('+' . $time1 . ' day')), 'time2' => '0000-00-00 00:00:00', 'pay1' => $money * $rate / 100 * $base, 'pay2' => 0, 'status' => 0); if($type == 4){ $data['money1'] = $money2 - $money + round($money2 * $rate / 100 * $base, 2); $data['money2'] = $money; $data['pay1'] = 0; $money2 += round($money2 * $rate / 100 * $base, 2); } if($i == $day2){ $data['pay1'] += $money; $data['money2'] += $money; } if($i == $day2 && $type == 4) { $data['pay1'] = $money + $data['money1']; $data['money2'] = $money; } if(Db::name('LcInvestList')->insertGetId($data)){ $bool = true; } ++$i; } return $bool; } return false; } function getMallInvestList($id, $money, $uid,$tran_type) { $item = Db::name('LcMall')->where(['id'=>$id])->find(); $title = $item['title']; $day = $item['day']; $profit = $item['day_income']-$item['cost']; $res=Db::name('LcMallInvest')->order("id desc")->find(); if($res['number']){ $number= date('ymd').sprintf("%05d", substr($res['number'],-5)+1); }else{ $number= date('ymd').'01000'; } $invest = array( 'uid' => $uid, 'pid' => $id, 'number' => $number, 'title' => $title, 'money' => $money, 'num' => $money/$item['min'], 'day' => $day, 'day_income' => $item['day_income'], 'cost' => $item['cost'], 'profit' => $profit, 'type' => $tran_type, 'status' => 0, 'time' => date('Y-m-d H:i:s'), 'time2'=> date('Y-m-d H:i:s', strtotime('+' . $item['day'] . ' day')), ); $iid = Db::name('LcMallInvest')->insertGetId($invest); if (!empty($iid)) { $base = 1; $day2 = $day / $base; $bool = false; $i = 1; while($i <= $day2){ $time1 = $i * $base; $data = array( 'uid' => $uid, 'iid' => $iid, 'num' => $i, 'title' => $title, 'money1' => $profit, 'money2' => 0, 'time1' => date('Y-m-d H:i:s', strtotime('+' . $time1 . ' day')), 'time2' => '0000-00-00 00:00:00', 'pay1' => $profit, 'pay2' => 0, 'tran_type' => $tran_type, 'status' => 0 ); if($i == $day2){ $data['money2'] += $money; } if(Db::name('LcMallInvestList')->insertGetId($data)){ $bool = true; } ++$i; } return $bool; } return false; } /** * @description:获取项目类型 * @date: 2020/5/14 0014 * @param $pid * @return string */ function getProjectType($pid) { $str = '到期还本还息'; switch ($pid) { case 1: $str = '按日付收益,保证金到期全额返还'; break; case 2: $str = '每周返息,到期还本'; break; case 3: $str = '每月返息,到期还本'; break; case 4: $str = '每日复利,保本保息'; break; case 5: $str = '到期还本还息'; break; case 6: $str = '当天投资,当天还本付息'; break; } return $str; } function getItemField($id, $field) { return Db::name('LcItem')->where(['id'=>$id])->value($field); } function getMallItemField($id, $field) { return Db::name('LcMall')->where(['id'=>$id])->value($field); } function getInvestMoney($id) { return Db::name('LcInvestList')->where("iid = '$id' AND pay1 <> 0")->sum('money1'); } /** * @description:通用跳转 * @date: 2020/5/14 0014 * @param $msg * @param int $time * @param string $url */ function msg($msg, $time = 2, $url = '') { echo '