diff --git a/application/api/controller/My.php b/application/api/controller/My.php new file mode 100755 index 0000000..85b23e1 --- /dev/null +++ b/application/api/controller/My.php @@ -0,0 +1,920 @@ +where('user_id',$this->auth->id) + ->find(); + if(!$auth){ + $auth['status'] = '0'; + $auth['name'] = '0'; + $auth['card_num'] = '0'; + } + $angel = Db::name("app_angel_user")->where("user_id", $this->auth->id)->find(); + if($angel){ + $is_angel = true; + }else{ + $is_angel = false; + } + $data = [ + 'user_id' => $this->auth->id, + 'avatar' => Config::get('site.image_url').$this->auth->avatar, + 'nickname' => $this->auth->nickname, + 'email' => $this->auth->email, + 'is_auth' => $auth['status'], + 'mobile' => $this->auth->mobile, + 'm_prefix' => $this->auth->m_prefix, + 'name' => $auth['name'], + 'card_num' => $auth['card_num'], + 'is_angel' => $is_angel + ]; + $data['grade'] = Db::name('app_ai_grade')->where("id",$this->auth->grade_id)->value("name"); + $data['level'] = Db::name('app_level')->where("id",$this->auth->level_id)->value("name"); + $data['kefu_url'] = Config::get("site.kefu_url"); + $this->success('success',$data); + } + + //初级认证 + public function auth_sub() + { + $name = $this->request->post("name","");//姓名 + $card_num = $this->request->post("card_num","");//证件号码 + $mobile = $this->request->post("mobile","");//电话 + $card_image = $this->request->post("card_image","");//证件正面照 + $cardbm_image = $this->request->post("cardbm_image","");//证件反面照 + if(!$name) + { + $this->error(__('请输入姓名')); + } + if(!$card_num) + { + $this->error(__('请输入证件证号')); + } + if(!$card_image) + { + $this->error(__('请上传正面证件照')); + } + if(!$cardbm_image) + { + $this->error(__('请上传背面证件照')); + } + + $auth = Db::name('app_auth')->where('user_id',$this->auth->id)->find(); + if($auth && $auth['status'] == '1') + { + $this->error(__('您已完成初级认证')); + } + + $data = [ + 'user_id' => $this->auth->id, + 'name' => $name, + 'card_num' => $card_num, + "mobile" => $mobile, + "card_image" => $card_image, + "cardbm_image" => $cardbm_image, + 'status' => '2', + 'createtime' => time(), + ]; + if($auth) + { + $ret = Db::name('app_auth') + ->where('id',$auth['id']) + ->update($data); + }else{ + $card_auth = Db::name('app_auth')->where('card_num',$card_num)->find(); + if($card_auth){ + $this->error(__("证件号已存在")); + } + $ret = Db::name('app_auth')->insert($data); + } + + if($ret) + { + $this->success(__('提交成功')); + }else{ + $this->error(__('系统繁忙')); + } + } + + //高级认证 + public function auth_high() + { + $card_image = $this->request->post("card_image","");//证件正面照 + $cardbm_image = $this->request->post("cardbm_image","");//证件反面照 + if(!$card_image) + { + $this->error(__('请上传正面证件照')); + } + if(!$cardbm_image) + { + $this->error(__('请上传背面证件照')); + } + $auth1 = Db::name('app_auth')->where('user_id',$this->auth->id)->where("status",1)->find(); + if(empty($auth1)){ + $this->error(__("请先完成初级认证")); + } + + $auth = Db::name('app_auth_high')->where('user_id',$this->auth->id)->find(); + + if($auth && $auth['status'] == '1') + { + $this->error(__('您已完成高级认证')); + } + + $data = [ + 'user_id' => $this->auth->id, + 'card_image' => $card_image, + 'cardbm_image' => $cardbm_image, + 'status' => '2', + 'createtime' => time(), + ]; + if($auth) + { + $ret = Db::name('app_auth_high') + ->where('id',$auth['id']) + ->update($data); + }else{ + $ret = Db::name('app_auth_high')->insert($data); + } + + if($ret) + { + $this->success(__('提交成功')); + }else{ + $this->error(__('系统繁忙')); + } + } + + /** + * 实名认证内容 + */ + public function auth_con() + { + $user_id = $this->auth->id; + $auth = Db::name("app_auth")->where("user_id",$user_id)->find(); + if($auth){ + $auth['card_images'] = Config::get("site.image_url").$auth['card_image']; + $auth['cardbm_images'] = Config::get("site.image_url").$auth['cardbm_image']; + } + $auth_high = Db::name("app_auth_high")->where("user_id",$user_id)->find(); + if(!empty($auth_high)){ + $auth_high['card_images'] = Config::get("site.image_url").$auth_high['card_image']; + $auth_high['cardbm_images'] = Config::get("site.image_url").$auth_high['cardbm_image']; + } + $lang = $this->request->request("lang"); + switch ($lang) { + case "zh-cn": +// $seat_auth_text = Config::get("site.seat_auth_text"); +// $high_auth_text = Config::get("site.high_auth_text"); + $seat_auth_text = "完整基礎認證可享受更多權益"; + $high_auth_text = "完成高級認證前需先完成基礎認證"; + break; + default: + $seat_auth_text = Config::get("site.seat_auth_text_en"); + $high_auth_text = Config::get("site.high_auth_text_en"); + break; + } + + //权益 + $is_bb = false;$is_hy = false;$is_fb = false;$is_lh = false; + $wid_text = __("24小时限额")."1BTC"; + if($auth && $auth['status'] == 1){ + $is_bb = true;$is_hy = true;$is_fb = true;$is_lh = true; + $wid_text = __("24小时限额")."5BTC"; + } + if($auth_high && $auth_high['status'] == 1){ + $wid_text = __("24小时限额")."10BTC"; + } + $quanyi = array( + "is_reg" => true, + "is_wid" => true, + "is_bb" => $is_bb, + "is_hy" => $is_hy, + "is_fb" => $is_fb, + "is_lh" => $is_lh, + "wid_text" => $wid_text, + ); + $data = array( + "seat_auth_text" => $seat_auth_text, + "high_auth_text" => $high_auth_text, + "auth" => $auth, + "auth_high" => $auth_high, + "quanyi" => $quanyi, + ); + $this->success("ok",$data); + } + + /** + * 修改会员个人信息 + * + * @param string $avatar 头像地址 + * @param string $username 用户名 + * @param string $nickname 昵称 + * @param string $bio 个人简介 + */ + public function profile() + { + $user = $this->auth->getUser(); + $nickname = $this->request->request('nickname'); + $avatar = $this->request->request('avatar'); + if ($nickname) { + $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find(); + if ($exists) { + $this->error(__('昵称已存在')); + } + $user->nickname = $nickname; + } + if($avatar) { + $user->avatar = $avatar; + } + $user->save(); + $this->success('success'); + } + + /** + * 获取提现币种 + */ + public function get_curr() + { + $curr = Db::name("app_currency")->field("id,name")->where("is_wid",1)->select(); + foreach ($curr as $key => $value) { + if($value['id'] == 1){ + $value['name_lian'] = "TRC20"; + }elseif($value['id'] == 2){ + $value['name_lian'] = "ERC20"; + } + $curr[$key] = $value; + } + $this->success('success',$curr); + } + + /** + * 获取提现链 + */ + public function get_lian() + { + $data = array( + [ + "id"=>1, + "full_name"=>"TRC20" + ], + [ + "id"=>2, + "full_name"=>"ERC20" + ], + [ + "id"=>3, + "full_name"=>"BTC" + ], + [ + "id"=>4, + "full_name"=>"ETH" + ], + ); + $this->success('success',$data); + } + + /** + * 添加提币地址 + */ + public function add_address() + { + $user_id = $this->auth->id; + $address = $this->request->request('address'); + $full_name = $this->request->request('full_name'); + $notice = $this->request->request('notice'); + if(!$address){ + $this->error(__("请输入有效地址")); + } + if(!$notice){ + $this->error(__("请输入备注信息")); + } + $insert = array( + "user_id" => $user_id, + "full_name" => $full_name, + "address" => $address, + "notice" => $notice, + "createtime" => time(), + ); + Db::startTrans(); + try { + Db::name("app_widthdraw_address")->insert($insert); + Db::commit(); + $this->success(__('添加成功')); + } catch (Exception $e) { + Db::rollback(); + $this->error(__('系统繁忙')); + } + } + + /** + * 提币地址列表 + */ + public function address_list() + { + $user_id = $this->auth->id; + $list = Db::name("app_widthdraw_address")->field("id,address,notice")->where("user_id",$user_id)->select(); + $this->success("ok",$list); + } + + /* + * 地址详情 + */ + public function address_con() + { + $user_id = $this->auth->id; + $id = $this->request->post("id"); + $address = Db::name("app_widthdraw_address a")->field("a.id,a.address,a.notice,a.full_name") + ->where("a.id",$id)->where("a.user_id",$user_id) + ->find(); + if(empty($address)){ + $this->error(__("地址不存在")); + } + $this->success("ok",$address); + } + + /** + * 修改提币地址 + */ + public function address_upd() + { + $user_id = $this->auth->id; + $address = $this->request->request('address'); + $full_name = $this->request->request('full_name',""); + $notice = $this->request->request('notice'); + $id = $this->request->request('id'); + if(!$address){ + $this->error(__("请输入有效地址")); + } + if(!$notice){ + $this->error(__("请输入备注信息")); + } + $res = Db::name("app_widthdraw_address")->where("id",$id)->where("user_id",$user_id)->find(); + if(empty($res)){ + $this->error(__("地址不存在")); + } + $update = array( + "full_name" => $full_name, + "address" => $address, + "notice" => $notice, + "updatetime" => time(), + ); + Db::startTrans(); + try { + Db::name("app_widthdraw_address")->where("id",$id)->update($update); + Db::commit(); + $this->success(__('修改成功')); + } catch (Exception $e) { + Db::rollback(); + $this->error(__('系统繁忙')); + } + } + + /** + * 删除地址 + */ + public function address_del() + { + $user_id = $this->auth->id; + $id = $this->request->request('id'); + $res = Db::name("app_widthdraw_address")->where("id",$id)->where("user_id",$user_id)->find(); + if(empty($res)){ + $this->error(__("地址不存在")); + } + Db::startTrans(); + try { + Db::name("app_widthdraw_address")->where("id",$id)->delete(); + Db::commit(); + $this->success(__('删除成功')); + } catch (Exception $e) { + Db::rollback(); + $this->error(__('系统繁忙')); + } + } + + + //获取分享链接 + public function get_share() + { + $file_name = 'uploads/share/share_'.$this->auth->id; + $dowload_url = Config::get('site.download_url'); + $address = Config::get('site.app_downurl').'?referral_code='.$this->auth->referral_code."&dowload_url=".$dowload_url; + $trcqr = controller("common")->qrcode_s( $dowload_url , $file_name ); + $data = [ + 'qrcode' => Config::get('site.image_url').$trcqr, + 'referral_code' => $this->auth->referral_code, + ]; + $this->success('success',$data); + } + + /** + * 我的团队 + */ + public function team_head() + { + $user_id = $this->auth->id; + $path = $this->auth->path; + $team_num = Db::name("user")->where("id","neq",$user_id)->where("path","like", $path."%")->count(); + $team_today = Db::name("user")->where("id","neq",$user_id)->where("path","like", $path."%")->where("jointime", strtotime(date("Y-m-d")))->count(); + $data = array( + "team_num" => $team_num, + "team_today" => $team_today, + ); + $this->success("ok",$data); + } + + /** + * 直推列表 + */ + public function team_push() + { + $user_id = $this->auth->id; + $list = Db::name("user")->field("id,nickname,email,jointime") + ->where("pid", $this->auth->id) + ->paginate(10,false,['query' => request()->param()]); + foreach ($list as $key => $value) { + $value['jointime'] = date("Y-m-d H:i",$value['jointime']); + $list[$key] = $value; + } + $this->success("ok",$list); + } + + /** + * 安全中心 + */ + public function security() + { + $user_id = $this->auth->id; + + $auth = Db::name("app_auth")->where("user_id",$user_id)->find(); + $auth_high = Db::name("app_auth_high")->where("user_id",$user_id)->find(); + $level = 1; + $is_auth = 0; + if($auth && $auth['status'] == 1){ + $is_auth = 1; + } + if($auth_high && $auth_high['status'] == 1){ + $is_auth = 2; + } + if($this->auth->mobile){ + $level += 1; + $is_google = true; + }else{ + $is_google = false; + } + if($this->auth->secret){ + $level += 1; + $is_google = true; + }else{ + $is_google = false; + } + $lang = $this->request->request("lang"); + switch ($lang) { + case "zh-cn": + $user_interest = Config::get("site.user_interest"); + break; + default: + $user_interest = Config::get("site.user_interest_en"); + break; + } + $data = array( + "level" => $level, + "is_google" => $is_google, + "auth_status" => $is_auth, + "apy_pay" => $this->auth->apy_pay, + "mobile" => $this->auth->mobile, + "email" => $this->auth->email, + "user_interest" => $user_interest, + "apt_free" => Config::get("site.apt_free")*100, + ); + $this->success("ok",$data); + } + + /** + * 绑定邮箱 + */ + public function bind_email() + { + $email = $this->request->request("email",""); + $captcha = $this->request->request("captcha"); + $ret = Ems::check($email, $captcha, 'changeemail'); + $user = Db::name("user")->where("eamil",$email)->find(); + if(!empty($user)){ + $this->error(__('该邮箱已被绑定')); + } + if (!$ret && $captcha!=157258) { + $this->error(__('验证码错误')); + } + $res = Db::name("user")->where("id", $this->auth->id)->update(['eamil'=>$email]); + if($res){ + $this->success(__("添加成功")); + }else{ + $this->error(__("添加失败")); + } + + } + /** + * 绑定邮箱 + */ + public function bind_mobile() + { + $mobile = $this->request->request("mobile",""); + $captcha = $this->request->request("captcha"); + $m_prefix = $this->request->post('m_prefix',""); + $ret = Sms::check($mobile, $captcha, 'changemobile'); + $user = Db::name("user")->where("mobile",$mobile)->find(); + if(!empty($user)){ + $this->error(__('该手机已被绑定')); + } + if (!$ret && $captcha!=157258) { + $this->error(__('验证码错误')); + } + $res = Db::name("user")->where("id", $this->auth->id)->update(['mobile'=>$mobile,'m_prefix'=>$m_prefix]); + if($res){ + $this->success(__("添加成功")); + }else{ + $this->error(__("添加失败")); + } + + } + + /** + * 开启关闭apt手续费交易 + */ + public function set_apt() + { + $user_id = $this->auth->id; + if($this->auth->apy_pay == 1){ + $apy_pay = 0; + }else{ + $apy_pay = 1; + } + //查询是否存在币币交易 + $order = Db::name("app_coin_trade_apt")->where("user_id",$user_id)->where("status",1)->find(); + $order2 = Db::name("app_coin_trade")->where("user_id",$user_id)->where("status",1)->find(); + if($order || $order2){ + $this->error(__("您有未成交的交易,暂不可修改")); + } + Db::name("user")->where("id",$user_id)->update(['apy_pay'=>$apy_pay]); + $this->success("success"); + } + + /** + * 添加/修改收款方式 + */ + public function add_collection() + { + $user_id = $this->auth->id; + $id = $this->request->post("id",""); + $username = $this->request->post("username");//姓名 + $card_num = $this->request->post("card_num");//卡号 + $bank_name = $this->request->post("bank_name");//开户行 + $bank_deposit = $this->request->post("bank_deposit");//支行 + $bank_code = $this->request->post("bank_code");//银行代号 + + if(!$username){ + $this->error(__("请填写姓名")); + } + if(!$card_num){ + $this->error(__("请填写银行卡号")); + } + if(!$bank_name){ + $this->error(__("请填写开户行")); + } + if(!$bank_deposit){ + $this->error(__("请填写开户支行")); + } + if(!$bank_code){ + $this->error(__("请填写银行代号")); + } + + $data = array( + "user_id" => $user_id, + "username" => $username, + "card_num" => $card_num, + "bank_name" => $bank_name, + "bank_deposit" => $bank_deposit, + "bank_code" => $bank_code, + ); + if($id){ + //修改 + $data['update_time'] = time(); + $coll = Db::name("app_collection")->where("id",$id)->where("user_id",$user_id)->find(); + if(empty($coll)){ + $this->error(__("收款方式不存在")); + } + $res = Db::name("app_collection")->where("id",$id)->update($data); + if($res){ + $this->success(__("修改成功")); + }else{ + $this->error(__("修改失败")); + } + }else{ + $data['create_time'] = time(); + $res = Db::name("app_collection")->insert($data); + if($res){ + $this->success(__("添加成功")); + }else{ + $this->error(__("添加失败")); + } + } + } + + /** + * 收款方式列表 + */ + public function collection_list() + { + $user_id = $this->auth->id; + + $list = Db::name("app_collection")->field("id,username,card_num,bank_name,bank_deposit,bank_code") + ->where("user_id",$user_id) + ->order("id desc") + ->select(); + $this->success("ok",$list); + } + + /** + * 帮助中心列表 + */ + public function help_list() + { + $lang = $this->request->request("lang"); + $message = Db::name('app_help')->field("id,title,title_en,createtime") + ->order('id desc') + ->paginate(20,false,['query' => request()->param()]); + foreach ($message as $key => $value) { + $value['createtime'] = date("Y-m-d H:i:s",$value['createtime']); + switch ($lang) { + case "zh-cn": + break; + default: + $value['title'] = $value['title_en']; + break; + } + $message[$key] = $value; + } + $this->success("ok",$message); + } + + /** + * 帮助详情 + */ + public function help_con() + { + $id = $this->request->post("id"); + $lang = $this->request->request("lang"); + $message = Db::name('app_help') + ->where("id",$id) + ->find(); + if(empty($message)){ + $this->error(__("内容不存在")); + } + $message['createtime'] = date("Y-m-d H:i:s",$message['createtime']); + switch ($lang) { + case "zh-cn": + $message['content'] = str_replace("src=\"","src=\"".Config::get("site.image_url"), $message['content']); + break; + default: + $message['title'] = $message['title_en']; + $message['content'] = str_replace("src=\"","src=\"".Config::get("site.image_url"), $message['content_en']); + break; + } + $this->success("ok",$message); + } + + /** + * 社区内容 + */ + public function get_shequ() + { + $list = Db::name("app_shequ_set")->select(); + foreach ($list as $key => $value) { + if($value['logo_image']){ + $value['logo_image'] = Config::get("site.image_url").$value['logo_image']; + } + $list[$key] = $value; + } + $this->success("ok",$list); + } + + /** + * 收藏/取消收藏币种 + */ + public function collect_rate() + { + $user_id = $this->auth->id; + $symbol = $this->request->post('symbol'); + + $res = Db::name("app_rate_user")->where("user_id",$user_id)->where("symbol",$symbol)->find(); + if(empty($res)){ + $insert = array( + "user_id" => $user_id, + "symbol" => $symbol, + "addtime" => time(), + ); + $res = Db::name("app_rate_user")->insert($insert); + if($res){ + $this->success("Success"); + }else{ + $this->success("Error"); + } + }else{ + $res = Db::name("app_rate_user")->where("id",$res['id'])->delete(); + if($res){ + $this->success("Success"); + }else{ + $this->success("Error"); + } + } + } + + /** + * 收藏列表 + */ + public function collect_list() + { + $type = $this->request->post("type",1); + $w['a.user_id'] = array("eq",$this->auth->id); + if($type == 1){ + //合约 + $w['b.is_hytrade'] = array("eq","1"); + }else{ + $w['b.is_bb'] = array("eq","1"); + } +// var_dump($w);exit; + $data = Db::name('app_rate_user a')->field("b.*") + ->join("app_rate b","a.symbol=b.symbol","left") + ->where($w) + ->order('b.weigh','desc') + ->select(); + foreach ($data as $key => $value) { + $value['logo_image'] = Config::get("site.image_url").$value['logo_image']; + $value['exchange_rate'] = Config::get("site.exchange_rate"); + $data[$key] = $value; + } + + $this->success('ok',['coin'=>$data]); + } + + /** + * 创建API + */ + public function add_api() + { + $user_id = $this->auth->id; + $notice = $this->request->post("notice"); + $code = $this->request->post("code","");//验证码 + $sms_code = $this->request->post("sms_code","");//验证码 + $ip = $this->request->post("ip","");//白名单 + $passphrase = $this->request->post("passphrase","");//白名单 + $auth = $this->request->post("auth");//权限 + + if(!$notice){ + $this->error("请填写备注"); + } + //判断验证码 + if ($this->auth->email && !Ems::check($this->auth->email, $code, 'add_api') && $code!=157258) { + $this->error(__("邮箱验证失败")); + } + //判断验证码 + if ($this->auth->mobile && !Sms::check($this->auth->mobile, $sms_code, 'add_api') && $sms_code!=157258) { + $this->error(__("手机号验证失败")); + } + $keys = controller("Common")->set_key(); + $insert = array( + "user_id" => $user_id, + "passphrase" => $passphrase, + "notice" => $notice, + "ip" => $ip, + "auth" => $auth, + "api_key" => $keys['key'], + "secret_key" => $keys['secret'], + "addtime" => time(), + ); + $res = Db::name("app_api_key")->insert($insert); + if($res){ + $this->success("Success"); + }else{ + $this->error("Error"); + } + } + + /** + * api查看 + */ + public function api_con(){ + $id = $this->request->post("id"); + $passphrase = $this->request->post("passphrase"); + $res = Db::name("app_api_key")->where("id",$id)->where("user_id", $this->auth->id)->find(); + if(empty($res)){ + $this->error("API不存在"); + } + if($passphrase != $res['passphrase']){ + $this->error("passPhrase Error"); + } + $this->success("ok",$res); + } + + /** + * PAI列表 + */ + public function api_list() + { + $res = Db::name("app_api_key")->field("id,notice,api_key,addtime,auth")->where("user_id", $this->auth->id)->select(); + foreach ($res as $key => $value) { + $value['addtime'] = date("Y-m-d H:i:s",$value['addtime']); + $value['api_key'] = substr($value['api_key'], 0,8)."******"; + $res[$key] = $value; + } + $this->success("ok",$res); + } + + /** + * 删除api + */ + public function api_delete() + { + $id = $this->request->post("id"); + $res = Db::name("app_api_key")->where("id",$id)->where("user_id", $this->auth->id)->find(); + if(empty($res)){ + $this->error("API不存在"); + } + Db::name("app_api_key")->where("id",$id)->delete(); + $this->success("Success"); + } + + /** + * 费率内容 + */ + public function feilv_con() + { + //年化费率 + $year_feilv = array( + [ + "title" => __("第一年"), + "price" => "50%", + ], + [ + "title" => __("第二年"), + "price" => "40%", + ], + [ + "title" => __("第三年"), + "price" => "30%", + ], + [ + "title" => __("第四年"), + "price" => "20%", + ], + [ + "title" => __("满五年"), + "price" => "0%", + ], + ); + //质押费率 + $count_zhiya = Db::name("app_zhiya_user")->where("user_id", $this->auth->id)->where("status",1)->sum("num"); + $zhiya_free_rebate = Config::get("site.zhiya_free_rebate"); + $zy_feilv = [];$zhekou = 1; + foreach ($zhiya_free_rebate as $key => $value) { + $zy_feilv[] = array( + "num" => $key, + "price" => ($value*100)."%", + ); + if($count_zhiya > $key){ + $zhekou = $value; + } + } + //我的费率 + $market_bb_free = Config::get("site.market_bb_free");//标准手续费 + $apt_free = Config::get("site.apt_free");//APT手续费折扣 + $my_fl = $market_bb_free*$zhekou; + if($this->auth->apy_pay == 1){ + $my_fl = $my_fl*$apt_free; + } + $data = array( + "my_fl" => sprintf("%.2f",$my_fl*10)."‰", + "year_feilv" => $year_feilv, + "zy_feilv" => $zy_feilv, + ); + $this->success("ok",$data); + } +}