| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765 | 
							- <?php
 
- namespace app\api\controller;
 
- use addons\epay\library\Service;
 
- use app\api\controller\Common;
 
- use app\common\model\GiftUserParty;
 
- use app\common\model\UserExchangeLog;
 
- use app\common\model\UserExchsoundLog;
 
- use applebuy\applebuy;
 
- use fast\Random;
 
- use app\common\model\RecharOrder;
 
- use kjpay\kjpay;
 
- use kjwithdraw\kjwithdraw;
 
- use think\Exception;
 
- use think\exception\PDOException;
 
- use think\exception\ValidateException;
 
- use think\Request;
 
- use think\Db;
 
- use app\common\library\Sms as Smslib;
 
- /**
 
-  * 钱包接口
 
-  */
 
- class Money extends Common
 
- {
 
-     protected $noNeedLogin = ['getRecharConfig', 'getRateMoney', 'getExchangeConfig', 'getExchsoundConfig', 'rebateDuty', 'kjRecharge', 'changeWithDrawStatus'];
 
-     protected $noNeedRight = '*';
 
-     public function _initialize()
 
-     {
 
-         parent::_initialize();
 
-     }
 
-     /**
 
-      * 获取用户财富信息
 
-      */
 
-     public function getUserMoney()
 
-     {
 
-         $this->success("获取成功!", \app\common\model\User::field("money,rebate_money,score,jewel,sound_coin,hammer")->find($this->auth->id));
 
-     }
 
-     /**
 
-      * 充值
 
-      */
 
-     public function recharge()
 
-     {
 
-         $rechar_id = $this->request->request("rechar_id",0);// 充值金额配置ID
 
-         $type = $this->request->request("type", "wechat");// 充值类型:wechat:微信支付,alipay:支付宝支付
 
-         $method = $this->request->request("method", "miniapp");// 支付方式:app:app支付,miniapp:小程序支付
 
-         $openid = $this->request->request("openid", "");// 非小程序支付无需传值
 
-         $params_from = $this->request->request("params_from");// 平台参数
 
-         $amounts = $this->request->request("amounts",0);// 自定义金额
 
-         if (!$rechar_id && empty($amounts)) {
 
-             $this->error(__('Invalid parameters'));
 
-         }
 
-         if (!preg_match("/^-?\d+$/",$amounts)) {
 
-             $this->error('金额必须是整数');
 
-         }
 
-         if ($this->auth->is_auth != 2) {//实名后允许充值
 
-             throw new Exception('请先实名认证');
 
-         }
 
-         if ($this->power->recharge == 1) {//禁止充值
 
-             throw new Exception('禁止充值');
 
-         }
 
-         $user_id = $this->auth->id;
 
-         // 获取充值金额配置信息
 
-         if (!empty($rechar_id)) {
 
-             $recharMode = new \app\common\model\RecharConfig();
 
-             $recharInfo = $recharMode->where(["id" => $rechar_id])->find();
 
-         } else {
 
-             $amountsNew = $amounts * 100;
 
-             $recharInfo = [
 
-                 'money' => $amountsNew,
 
-                 'jewel' => $amountsNew,
 
-                 'jewel_full' => $amountsNew,
 
-             ];
 
-         }
 
-         if (!$recharInfo) $this->error("金额配置信息未找到!");
 
-         $out_trade_no = date("YmdHis") . rand(100000, 999999);
 
-         $title = "充值钻石";
 
-         $amount = $recharInfo["money"] / 100;
 
-         if ($params_from == "ios") {
 
-             $jewel = $recharInfo['jewel'];
 
-         } else {
 
-             $jewel = $recharInfo['jewel_full'];
 
-         }
 
-         $notifyurl = request()->root(true) . '/api/notify/' . $type . 'notify';
 
-         $returnurl = request()->root(true) . '/addons/epay/index/' . $type . 'return/out_trade_no/' . $out_trade_no;
 
-         if (!$amount || $amount < 0) {
 
-             $this->error("支付金额必须大于0");
 
-         }
 
-         if (!$type || !in_array($type, ['alipay', 'wechat'])) {
 
-             $this->error("支付类型错误");
 
-         }
 
-         $time = time();
 
-         $money = (float)bcadd($amount, 0, 2);
 
-         // 生成订单
 
-         $recharOrderMode = new \app\common\model\RecharOrder();
 
- //        $data = [];
 
- //        $data["user_id"] = $user_id;
 
- //        $data["order_no"] = $out_trade_no;
 
- //        $data["money"] = $money;
 
- //        $data["jewel"] = $recharInfo["jewel"];
 
- //        $data["createtime"] = time();
 
-         $orderid = $recharOrderMode->execute("INSERT INTO `hx_rechar_order` (`user_id` , `order_no` , `money` , `jewel` , `createtime`) VALUES ($user_id , $out_trade_no , $money , " . $jewel . " , $time)");
 
-         if (!$orderid) $this->error("订单创建失败!");
 
-         $params = [
 
-             'type'      => $type,
 
-             'orderid'   => $out_trade_no,
 
-             'title'     => $title,
 
-             'amount'    => $money,
 
-             'method'    => $method,
 
-             'openid'    => $openid,
 
-             'notifyurl' => $notifyurl,
 
-             'returnurl' => $returnurl,
 
-         ];
 
-         $result = Service::submitOrder($params);
 
-         // 首充赠送
 
-         $userInfo = \app\common\model\User::get($user_id);
 
-         if ($userInfo->is_recharge == 0) { // 首充
 
-             Db::startTrans();
 
-             try {
 
-                 // 赠送消息尾灯
 
-                 $res1 = \app\common\model\AttireBack::addToMyBack(15, $user_id);
 
-                 $userInfo->is_recharge = 1;
 
-                 $res2 = $userInfo->save();
 
-                 if ($res1 && $res2) Db::commit();
 
-             } catch (ValidateException $e) {
 
-                 Db::rollback();
 
-                 $this->error($e->getMessage());
 
-             }
 
-         }
 
-         $this->rebate($user_id, $amount);
 
-         // +EXP
 
-         \app\common\model\TaskLog::tofinish($user_id, "5EMwg7la", 1);
 
-         // 查询今日充值记录
 
-         $today = strtotime(date("Y-m-d 00:00:00"));
 
-         $rechargeMoney = \app\common\model\RecharOrder::where(["user_id" => $user_id, "createtime" => ["gt", $today]])->sum("money");
 
-         if ($rechargeMoney >= 100) {
 
-             // +EXP
 
-             \app\common\model\TaskLog::tofinish($user_id, "DaCVgOLu", 1);
 
-         }
 
-         // 查询新人礼包
 
-         $this->addBagGift($user_id, $amount);
 
-         /*if ($method == "app") {
 
-             $this->success("", json_decode($result, true));
 
-         } else {
 
-             $this->success("", $result);
 
-         }*/
 
-         if($type == 'wechat'){
 
-             $this->success('success',json_decode($result,true));
 
-         }else{
 
-             $this->success('success',$result);
 
-         }
 
-     }
 
-     /**
 
-      * 聚合支付充值
 
-      */
 
-     public function kjRecharge()
 
-     {
 
-         $rechar_id = $this->request->request("rechar_id");// 充值金额配置ID
 
-         $u_id = $this->request->request("u_id");// 用户ID
 
-         $type = $this->request->request("type", "wechat");// 充值类型:wechat:微信支付,alipay:支付宝支付
 
-         $method = $this->request->request("method", "miniapp");// 支付方式:app:app支付,miniapp:小程序支付,public:公众号支付
 
-         $openid = $this->request->request("openid", "");// 非小程序支付无需传值
 
-         $params_from = $this->request->request("params_from");// 平台参数
 
-         $custom_money = $this->request->request("custom_money", 0, "intval");// 自定义充值金额
 
-         if (!$rechar_id && !$custom_money) {
 
-             $this->error(__('Invalid parameters'));
 
-         }
 
-         if ($custom_money > 0) {
 
-             $amount = $custom_money;
 
-             $jewel = $custom_money * 100;
 
-             if ($amount < 10) $this->error('支付金额必须大于10');
 
-             if ($amount > 30000) $this->error('支付金额超出单笔交易限额');
 
-         } else {
 
-             // 获取充值金额配置信息
 
-             $recharMode = new \app\common\model\RecharConfig();
 
-             $recharInfo = $recharMode->where(["id" => $rechar_id])->find();
 
-             if (!$recharInfo) $this->error("金额配置信息未找到!");
 
-             $amount = $recharInfo["money"] / 100;
 
-             if (!$amount || $amount < 0) {
 
-                 $this->error("支付金额必须大于0");
 
-             }
 
-             if ($params_from == "ios") {
 
-                 $jewel = $recharInfo['jewel'];
 
-             } else {
 
-                 $jewel = $recharInfo['jewel_full'];
 
-             }
 
-         }
 
-         $platformArr = ["android" => 1, "ios" => 2, "wxweb" => 3];
 
-         $platform = isset($platformArr[$params_from]) ? $platformArr[$params_from] : 1;
 
-         if ($method == "public") {
 
-             if (!$u_id) $this->error(__('Invalid parameters'));
 
-             $user_id = \app\common\model\User::where(["u_id" => $u_id])->value("id");
 
-         } else {
 
-             $user_id = $this->auth->id;
 
-         }
 
-         if (!$user_id) $this->error("数据缺失,请重新登录!");
 
-         $out_trade_no = date("YmdHis") . rand(100000, 999999);
 
-         $title = "充值钻石";
 
-         $content = "充值钻石";
 
-         $request = Request::instance();
 
-         $user_ip = $request->ip();
 
-         $notifyurl = request()->root(true) . '/api/notify/wechatkjnotify';
 
-         $returnurl = "https://voicew.bansheng-live.com/pages/index/index";
 
-         $time = time();
 
-         $money = (float)bcadd($amount, 0, 2);
 
-         // 生成订单
 
-         $recharOrderMode = new \app\common\model\RecharOrder();
 
-         $orderid = $recharOrderMode->execute("INSERT INTO `hx_rechar_order` (`user_id` , `order_no` , `money` , `platform`, `jewel` , `createtime`) VALUES ($user_id , $out_trade_no , $money , $platform, " . $jewel . " , $time)");
 
-         if (!$orderid) $this->error("订单创建失败!");
 
-         // 获取公共参数
 
-         $config = config("kjPay");
 
-         //商户号
 
-         $merchant_no = $config["merchant_no"];
 
-         //密钥
 
-         $key = $config["key"];
 
-         // 实例化支付类
 
-         $kjpay = new kjpay();
 
-         // 公众号分账参数
 
-         $publicreceivers = [];
 
-         $publicamount = $money - $money * 0.005;
 
-         $publicreceivers[] = [
 
-             "member_id" => $config["receivers_member_id"],
 
-             "amount"    => floor($publicamount * 100) / 100,
 
-         ];
 
-         // app分账参数
 
-         $appreceivers = [];
 
-         $appamount = $money * (1 - 0.006) * 0.3 - $money * 0.002;
 
- //        $appreceivers[] = [
 
- //            "type" => "PERSONAL_OPENID",
 
- //            "account" => "oSepO0jXj8CLlEsb9v4Gw9sbzQqU",
 
- //            "name" => "石国华",
 
- //            "amount" => floor($appamount*100)/100,
 
- //            "description" => "分账",
 
- //        ];
 
-         $appreceivers[] = [
 
-             "type"        => "PERSONAL_OPENID",
 
-             "account"     => "oSepO0nhtkSxiCoAhZFlnydDEzoA",
 
-             "name"        => "石国华",
 
-             "amount"      => floor($appamount * 100) / 100,
 
-             "description" => "分账",
 
-         ];
 
-         //请求的参数(注:不同支付接口请求参数略有不同,具体请参照接口文档)
 
-         $param = array(
 
-             'merchant_no'       => $merchant_no,
 
-             'merchant_order_no' => $out_trade_no,
 
-             //异步通知的地址
 
-             'notify_url'        => $notifyurl,
 
-             'start_time'        => date('YmdHis'),
 
-             'trade_amount'      => $money,
 
-             'goods_name'        => $title,
 
-             'goods_desc'        => $content,
 
-             'user_ip'           => $user_ip,
 
-             'sign_type'         => 1
 
-         );
 
-         if ($method == "public") {
 
-             $param['open_id'] = $openid;
 
-             //同步跳转的地址
 
-             $param['return_url'] = $returnurl;
 
-         }
 
-         if ($method == "public" || $method == "miniapp") {
 
-             $param['receivers'] = json_encode($publicreceivers);
 
-         }
 
-         if ($method == "app") {
 
-             if ($type == "alipay") {
 
- //                $param['receivers'] = json_encode($publicreceivers);
 
-             } else {
 
-                 $param['receivers'] = json_encode($appreceivers);
 
-             }
 
-         }
 
-         //签名
 
-         $sign = $kjpay->local_sign($param, $key);
 
-         $param['sign'] = $sign;
 
-         $typeArr = ["wechat" => "wechar", "alipay" => "alipay"];
 
-         if ($type == "wechat" && $method == "app") {
 
-             $method = "app_wechat";
 
-         } elseif ($type == "alipay" && $method == "app") {
 
-             $method = "app_alipay";
 
-         }
 
-         $res = $kjpay->getdata("http://" . $config["url"] . "/" . $typeArr[$type] . "/" . $config["pay_params"][$method], $param);
 
-         $list = json_decode($res, true);
 
-         if ($list["status"] != 1) $this->error($list['data']['error']);
 
-         //对响应结果进行验签,
 
-         if ($kjpay->local_sign($list['data'], $key) == $list['data']['sign']) {
 
-             $this->success("支付验证通过!", $list["data"]);
 
-         } else {
 
-             $this->error("支付验证失败!");
 
-         }
 
-     }
 
-     /**
 
-      * 聚合支付提现
 
-      */
 
-     public function kjout()
 
-     {
 
-         $this->error(__('功能暂时关闭!'));
 
-         // 接口防并发
 
-         if (!$this->apiLimit(1, 2000)) {
 
-             $this->error(__('Operation frequently'));
 
-         }
 
-         // 获取用户信息
 
-         $user_id = $this->auth->id;
 
-         $money = $this->request->request("money");// 申请提现的金额
 
-         if ($money < 30) {
 
-             $this->error(__('提现金额至少30元'));
 
-         }
 
-         if (bcsub($money, intval($money), 2) > 0) {
 
-             $this->error(__('提现金额必须为整数'));
 
-         }
 
- //        if (!$this->withdrawVerify($user_id)) {
 
- //            $this->error(__('账户验证失败!请联系管理员!'));
 
- //        }
 
-         // 判断当前用户是否实名认证
 
-         $userAuthInfo = \app\common\model\UserAuth::where(["user_id" => $user_id])->find();
 
-         if ($userAuthInfo) {
 
-             if ($userAuthInfo->status == 0) {
 
-                 $this->error("您的实名认证还在这审核中...,请耐心等待!");
 
-             } elseif ($userAuthInfo->status == 2) {
 
-                 $this->error("您的实名认证审核未通过,请重新审核!");
 
-             }
 
-         } else {
 
-             $this->error("请先申请实名认证!");
 
-         }
 
-         // 查询资金余额
 
-         $userModel = new \app\common\model\User();
 
-         $userInfo = $userModel->where('id',$user_id)->lock(true)->find();
 
-         if (bcsub($money, $userInfo["money"], 2) > 0) {
 
-             $this->error("资金余额不足!", [], 100);
 
-         }
 
-         // 增加提现收益记录
 
-         $withdrawRate = (100 - config("site.withdrawRate")) / 100;
 
-         $promoney = bcmul($money, $withdrawRate, 2);
 
-         $redmoney = bcsub($money, $promoney, 2);
 
-         // 查询银行卡信息
 
-         $bankInfo = \app\common\model\UserBank::where(["user_id" => $user_id])->find();
 
-         if (!$bankInfo) $this->error("请先绑定银行卡!");
 
-         $bankno = $bankInfo->bank_no;
 
-         $bankname = $bankInfo->bank_name;
 
-         $username = $bankInfo->realname;
 
-         $mobile = $bankInfo->mobile;
 
-         // 获取公共参数
 
-         $config = config("kjPay");
 
-         //商户号
 
-         $merchant_no = $config["merchant_no"];
 
-         //密钥
 
-         $key = $config["key"];
 
-         $out_trade_no = date("YmdHis") . rand(100000, 999999);
 
-         // 实例化支付类
 
-         $kjwithdraw = new kjwithdraw();
 
-         //请求的参数(注:不同支付接口请求参数略有不同,具体请参照接口文档)
 
-         $param = array(
 
-             'merchant_no'       => $merchant_no, // 商户号
 
-             'merchant_order_no' => $out_trade_no,// 商户订单号
 
-             'payment_days'      => date("Y-m-d", strtotime("-1 day")), // 账期
 
- //            'payment_days'     => "2021-04-19", // 账期
 
-             'pay_channel'       => "ali_wap_pay", // 支付通道
 
-             'trade_amount'      => $redmoney, // 提现金额 单位为元,精确到小数点后两位,取值范围[0.01,100000000]
 
-             'bank_no'           => $bankno, // 银行卡号
 
-             'bank_acct_name'    => $username, // 银行账户名称
 
-             'bank_mobile'       => $mobile, // 银行预留手机号
 
-             'account_attr'      => "0", // 账户类型 0-对私,默认0
 
-             'bank_name'         => $bankname, //银行名称
 
-             'remarks'           => "伴声公众号提现", // 提现备注
 
-             'sign_type'         => 1
 
-         );
 
-         //签名
 
-         $sign = $kjwithdraw->sign($param, $key);
 
-         $param['sign'] = $sign;
 
-         $res = $kjwithdraw->getdata($config["cashOutForSelf"]["url"], $param);
 
- //        $this->error($res);exit;
 
-         $list = json_decode($res, true);
 
-         // 提现申请成功 添加申请记录
 
-         if (isset($list["status"])) {
 
-             if ($list["status"] == 1) {
 
-                 Db::startTrans();
 
-                 try {
 
-                     $withdrawallogModel = new \app\common\model\UserWithdrawalLog();
 
-                     // 减去用户可用资金余额
 
-                     $res1 = $userModel->where(["id" => $user_id])->setDec("money", $money);
 
-                     // 增加用户冻结资金余额
 
-                     $res2 = $userModel->where(["id" => $user_id])->setInc("frozen", $money);
 
-                     // 新增用户提现记录申请
 
-                     $data = [];
 
-                     $data["user_id"] = $user_id;
 
-                     $data["money"] = $money * 100;
 
-                     $data["out_trade_no"] = $out_trade_no;
 
-                     $data["status"] = 0; // 提现状态:-1=审核拒绝,0=待审核,1=审核通过
 
-                     $data["createtime"] = time();
 
-                     $res3 = $withdrawallogModel->insert($data);
 
-                     if ($res1 && $res2 && $res3) {
 
-                         Db::commit();
 
-                         $this->success("提现申请发送成功!");
 
-                     } else {
 
-                         $this->error("操作失败!");
 
-                     }
 
-                 } catch (ValidateException $e) {
 
-                     Db::rollback();
 
-                     $this->error($e->getMessage());
 
-                 } catch (PDOException $e) {
 
-                     Db::rollback();
 
-                     $this->error($e->getMessage());
 
-                 } catch (Exception $e) {
 
-                     Db::rollback();
 
-                     $this->error($e->getMessage());
 
-                 }
 
-                 $this->success("恭喜,提现成功!请留意预留银行账户资金变动!");
 
-             } else {
 
-                 $this->error("商户账户异常,请联系管理员!");
 
-             }
 
-         } else {
 
-             $this->error("提现失败,请联系客服处理!");
 
-         }
 
-     }
 
-     /**
 
-      * 获取用户比例提现金额
 
-      */
 
-     public function getRateMoney()
 
-     {
 
-         $money = $this->request->request("money");// 申请提现的金额
 
-         if ($money <= 0) {
 
-             $this->error(__('提现金额不合法'));
 
-         }
 
-         // 增加提现收益记录
 
-         $money = bcsub($money, 0, 2);
 
-         $rate = 100 - config("site.withdrawRate");
 
-         $withdrawRate = $rate / 100;
 
-         $promoney = bcmul($money, $withdrawRate, 2);
 
-         $redmoney = bcsub($money, $promoney, 2);
 
-         $res = [];
 
-         $res["rate"] = $rate . "%";
 
-         $res["money"] = $money;
 
-         $res["promoney"] = $promoney;
 
-         $res["redmoney"] = $redmoney;
 
-         $this->success("获取成功!", $res);
 
-     }
 
-     public function aa()
 
-     {
 
-         $this->addBagGift(86, 100);
 
-     }
 
-     /**
 
-      * 更新新人礼包
 
-      */
 
-     private function addBagGift($user_id, $amount)
 
-     {
 
-         if (!$user_id || !$amount) return false;
 
-         // 先看该用户是否有新人礼包特权
 
-         $have = \app\common\model\NewBagHave::where(["user_id" => $user_id])->find();
 
- //        print_r($have);exit;
 
-         if ($have && time() - $have->createtime <= 7 * 86400) {
 
-             $where = [];
 
-             $where["value"] = ["elt", $amount];
 
-             $bagInfo = \app\common\model\NewBag::where($where)->order("value", "desc")->select();
 
-             if (!$bagInfo) return false;
 
-             $res1 = false;
 
-             foreach ($bagInfo as $k => $v) {
 
-                 // 查询完成情况
 
-                 $bagfinish = \app\common\model\NewBagFinish::where(["user_id" => $user_id, "bag_id" => $v["id"]])->find();
 
-                 if (!$bagfinish || $bagfinish->status <= 0) {
 
-                     if ($bagfinish) {
 
-                         $bagfinish->status = 1;
 
-                         $bagfinish->updatetime = time();
 
-                         $res1 = $bagfinish->save();
 
-                     } else {
 
-                         $res1 = \app\common\model\NewBagFinish::insert(["user_id" => $user_id, "bag_id" => $v["id"], "status" => 1, "updatetime" => time()]);
 
-                     }
 
-                     break;
 
-                 }
 
-             }
 
-             return $res1;
 
-         }
 
-     }
 
-     /**
 
-      * 更新提现状态 定时任务
 
-      */
 
-     public function changeWithDrawStatus()
 
-     {
 
-         // 获取公共参数
 
-         $config = config("kjPay");
 
-         //商户号
 
-         $merchant_no = $config["merchant_no"];
 
-         //密钥
 
-         $key = $config["key"];
 
-         // 查询 有哪些 提现未审核的提现记录
 
-         $log = \app\common\model\UserWithdrawalLog::where(["status" => 0])->order("doit", "asc")->find();
 
-         if (!$log) exit;
 
-         $log->doit = $log->doit + 1;
 
-         $log->save();
 
-         // 实例化支付类
 
-         $kjwithdraw = new kjwithdraw();
 
-         //请求的参数(注:不同支付接口请求参数略有不同,具体请参照接口文档)
 
-         $param = array(
 
-             'merchant_no'       => $merchant_no, // 商户号
 
-             'merchant_order_no' => $log->out_trade_no,// 商户订单号
 
-             'sign_type'         => 1
 
-         );
 
-         $money = $log->money / 100;
 
-         // 增加提现收益记录
 
-         $withdrawRate = (100 - config("site.withdrawRate")) / 100;
 
-         $promoney = bcmul($money, $withdrawRate, 2) - 1;
 
- //        $redmoney = bcsub($money,$promoney,2);
 
-         // 查询资金余额
 
-         $userModel = new \app\common\model\User();
 
-         $userInfo = $userModel->get($log->user_id);
 
-         if ($money > $userInfo["frozen"]) {
 
-             exit;
 
-         }
 
-         //签名
 
-         $sign = $kjwithdraw->sign($param, $key);
 
-         $param['sign'] = $sign;
 
-         $res = $kjwithdraw->getdata($config["cashOutForSelf"]["check_url"], $param);
 
-         $list = json_decode($res, true);
 
-         // 查询成功
 
-         if (isset($list["status"])) {
 
-             if ($list["status"] == 1) {
 
-                 Db::startTrans();
 
-                 try {
 
-                     $userModel = new \app\common\model\User();
 
-                     $userInfo = $userModel->where(["id" => $log->user_id])->find();
 
-                     if ($list["data"]["status"] == 4) {// 更新状态为审核通过
 
-                         // 减去用户冻结资金余额
 
-                         $res1 = (new \app\common\model\User())->execute("update hx_user set frozen = frozen - $money where id = " . $log->user_id);
 
-                         $time = time();
 
-                         $res2 = (new \app\common\model\UserWithdrawalProfitLog())->execute("INSERT INTO `hx_user_withdrawal_profit_log`(`u_id`, `nickname`, `plat_value`, `createtime`) VALUES ($userInfo->u_id, '$userInfo->nickname', $promoney, $time)");
 
-                         // 更改用户提现记录状态
 
-                         $res3 = \app\common\model\UserWithdrawalLog::update(["status" => 1, "updatetime" => time()], ["out_trade_no" => $log->out_trade_no]);
 
-                         if ($res1 && $res2 && $res3) {
 
-                             Smslib::send($userInfo->mobile, $money, "drowsuccess");
 
-                             Db::commit();
 
-                         }
 
-                     } elseif ($list["data"]["status"] == 5) {  // 更新状态为审核拒绝
 
-                         // 增加用户资金余额
 
-                         $res1 = (new \app\common\model\User())->execute("update hx_user set money = money + $money where id = " . $log->user_id);
 
-                         // 减去用户冻结资金余额
 
-                         $res2 = (new \app\common\model\User())->execute("update hx_user set frozen = frozen - $money where id = " . $log->user_id);
 
-                         // 更改用户提现记录状态
 
-                         $res3 = \app\common\model\UserWithdrawalLog::update(["status" => -1, "updatetime" => time()], ["out_trade_no" => $log->out_trade_no]);
 
-                         if ($res1 && $res2 && $res3) {
 
-                             Smslib::send($userInfo->mobile, $money, "drowFalse");
 
-                             Db::commit();
 
-                         }
 
-                     }
 
-                 } catch (ValidateException $e) {
 
-                     Db::rollback();
 
-                 }
 
-             }
 
-         }
 
-     }
 
-     /**
 
-      * 充值返利 定时任务
 
-      */
 
-     public function rebateDuty()
 
-     {
 
-         // 获取本周所有充值记录
 
-         // 上个周一
 
-         $preweek = $this->firstOfWeek(date("Y-m-d H:i:s",bcsub(time(),604800)));
 
-         $weekstart = strtotime($preweek." 00:00:00"); // 上周一时间
 
-         $weekend = bcadd($weekstart,604800); // 上周天时间
 
-         $where = [];
 
-         $where["createtime"] = ["between", "$weekstart,$weekend"];
 
-         $where["status"] = 1;
 
-         $rechargeOrder = \app\common\model\RecharOrder::field("id,sum(money) as money,user_id")->where($where)->group("user_id")->select();
 
-         $usercharge = [];
 
-         // 获取上级用户的所有下级用户
 
-         $preuser = [];
 
-         if ($rechargeOrder) foreach ($rechargeOrder as $k => $v) {
 
-             // 上级用户
 
-             $pre_userid = \app\common\model\User::where(["id"=>$v["user_id"]])->value("pre_userid");
 
-             if($pre_userid > 0) {
 
-                 // 所有下级用户
 
-                 $userids = \app\common\model\User::where(["pre_userid"=>$pre_userid])->column("id");
 
-                 $where = [];
 
-                 $where["createtime"] = ["between", "$weekstart,$weekend"];
 
-                 $where["status"] = 1;
 
-                 $where["user_id"] = ["in",$userids];
 
-                 $preuser[$v["user_id"]] = \app\common\model\RecharOrder::where($where)->sum("money");
 
-             }
 
-         }
 
-         if ($rechargeOrder) foreach ($rechargeOrder as $k => $v) {
 
-             $user_id = $v["user_id"];
 
-             $money = isset($preuser[$v["user_id"]])?$preuser[$v["user_id"]]:0;
 
-             // 获取配置信息
 
-             $config = \app\common\model\RebateConfig::where(["recharge" => ["lt", $money]])->order("recharge", "desc")->select();
 
-             if (!$config) continue;
 
-             $config = $config[0];
 
-             // 找到当前用户的上级和上上级
 
-             $userInfo = \app\common\model\User::where(["id" => $user_id])->find();
 
-             if ($userInfo->pre_userid > 0) {
 
-                 $usercharge[1][$user_id] = $config["preget"];
 
-                 $preUserInfo = \app\common\model\User::where(["id" => $userInfo->pre_userid])->find();// 上一级用户
 
-                 if ($preUserInfo->pre_userid > 0) {
 
-                     $usercharge[2][$user_id] = $config["prepreget"];
 
-                 }
 
-             }
 
-         }
 
-         // 获取返利列表信息
 
-         $where = [];
 
-         $where["createtime"] = ["between", "$weekstart,$weekend"];
 
-         $where["is_rebate"] = 0;
 
-         $RebateLog = \app\common\model\RebateLog::where($where)->select();
 
-         $week = intval(date('W', time()));
 
-         $year = intval(date('Y', time()));
 
-         $time = $year . $week;
 
-         $rank = time() . rand(1000, 999);
 
-         if ($RebateLog && $usercharge) foreach ($RebateLog as $k => $v) {
 
-             if (isset($usercharge[$v["rebate_type"]][$v["by_user_id"]]) && $usercharge[$v["rebate_type"]][$v["by_user_id"]] > 0) {
 
-                 $rate = bcdiv($usercharge[$v["rebate_type"]][$v["by_user_id"]], 1000, 5);
 
-                 $rebatemoney = $v["money"] * $rate;
 
-                 (new \app\common\model\RebateLog)->execute("update hx_rebate_log set rebate_rate = $rate,is_rebate = 1, rebate_money = $rebatemoney where id = " . $v['id']);
 
-                 $uInfo = \app\common\model\User::where(["id" => $v["user_id"], "finish_rebate" => $time])->find();
 
-                 if ($uInfo) {
 
-                     if ($rank == $uInfo->finish_rank) {
 
-                         (new \app\common\model\User)->execute("update hx_user set rebate_money = rebate_money + $rebatemoney,rebatecount = rebatecount + $rebatemoney,finish_rebate = $time, finish_rank = $rank where id = " . $v["user_id"]);
 
-                     }
 
-                 } else {
 
-                     (new \app\common\model\User)->execute("update hx_user set rebate_money = rebate_money + $rebatemoney,rebatecount = rebatecount + $rebatemoney,finish_rebate = $time, finish_rank = $rank where id = " . $v["user_id"]);
 
-                 }
 
-             }
 
-         }
 
-     }
 
-     /**
 
-      * 充值返利
 
-      */
 
-     private function rebate($user_id, $money)
 
-     {
 
- //        // 获取配置信息
 
- //        $config = \app\common\model\RebateConfig::where(["recharge"=>$money])->find();
 
- //        if(!$config) return true;
 
-         // 找到当前用户的上级和上上级
 
-         $userInfo = \app\common\model\User::get($user_id);
 
-         if ($userInfo->pre_userid > 0) {
 
-             $preUserInfo = \app\common\model\User::where(["id" => $userInfo->pre_userid])->find();// 上一级用户
 
-             $this->addRebateMoney($preUserInfo->id, $user_id, $money, 1);
 
-             if ($preUserInfo->pre_userid > 0) {
 
-                 $this->addRebateMoney($preUserInfo->pre_userid, $user_id, $money, 2);
 
-             } else {
 
-                 return true;
 
-             }
 
-         } else {
 
-             return true;
 
-         }
 
-     }
 
-     /**
 
-      * 添加返利金额
 
-      */
 
-     private function addRebateMoney($preUserId, $user_id, $money, $type)
 
-     {
 
-         if ($money <= 0) return false;
 
-         Db::startTrans();
 
-         try {
 
-             // 添加返利记录表
 
-             $data = [];
 
-             $data["user_id"] = $user_id;
 
-             $data["by_user_id"] = $preUserId;
 
-             $data["money"] = $money;
 
-             $data["rebate_money"] = 0.00;
 
-             $data["rebate_type"] = $type;
 
-             $data["createtime"] = time();
 
-             $res1 = \app\common\model\RebateLog::insertGetId($data);
 
- //            $res2 = (new \app\common\model\RebateLog)->execute("update hx_rebate_log set rebate_money = $rebatemoney where id = $res1");
 
-             if ($res1) {
 
-                 Db::commit();
 
-             }
 
-         } catch (ValidateException $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         } catch (PDOException $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         } catch (Exception $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         }
 
-     }
 
-     /**
 
-      * 声币兑换钻石
 
-      */
 
-     public function exchangeSoundcoin()
 
-     {
 
-         // 接口防并发
 
-         if (!$this->apiLimit(1, 1000)) {
 
-             $this->error(__('Operation frequently'));
 
-         }
 
-         $exchange_id = $this->request->request("exchsound_id");// 兑换声币配置ID
 
-         $sound_coin = $this->request->request("sound_coin");// 输入具体声币数量
 
-         if (!$sound_coin && !$exchange_id) {
 
-             $this->error(__('Invalid parameters'));
 
-         }
 
-         if ($sound_coin > 0) {
 
-             $scoin = $sound_coin;
 
-             // 获取配置信息
 
-             $conf = 100;//config("site.soundcoinTojewel");
 
-             $exchangeMoney = round($sound_coin * ($conf / 100));
 
-             if ($exchangeMoney < 1) $this->error(__('声币兑换数量太小啦!'));
 
-         } else {
 
-             // 获取兑换配置信息
 
-             $exchangeModel = new \app\common\model\ExchsoundConfig();
 
-             $exchangeInfo = $exchangeModel->get($exchange_id);
 
-             if (!$exchangeInfo) $this->error("配置信息未找到");
 
-             $exchangeMoney = $exchangeInfo["jewel"];
 
-             $scoin = $exchangeInfo["sound_coin"];
 
-         }
 
-         Db::startTrans();
 
-         try {
 
-             // 查询声币余额
 
-             $userModel = new \app\common\model\User();
 
-             $userInfo = $userModel->lock('lock in share mode')->find($this->auth->id);
 
-             if ($scoin > $userInfo["sound_coin"]) {
 
-                 $this->error("声币余额不足!", [], 100);
 
-             }
 
-             $soundlogModel = new \app\common\model\UserSoundcoinLog();
 
-             $jewellogModel = new \app\common\model\UserJewelLog();
 
-             $exchexsoundlogModel = new \app\common\model\UserExchsoundLog();
 
-             $detail = "声币兑换钻石";
 
-             // 添加钻石流水记录
 
-             $res1 = $jewellogModel->addUserJewelLog($this->auth->id, $exchangeMoney, "+", $userInfo["jewel"], $detail, 4);
 
-             // 添加兑换记录
 
-             $res2 = $exchexsoundlogModel->addExchsoundLog($this->auth->id, $scoin, $exchangeMoney);
 
-             // 添加声币流水记录
 
-             $res3 = $soundlogModel->addUserSoundcoinLog($this->auth->id, $scoin, "-", $userInfo["sound_coin"], $detail, 2, $res2);
 
-             // 减去用户声币余额
 
-             $res4 = $userModel->where(["id" => $this->auth->id])->setDec("sound_coin", $scoin);
 
-             // 增加用户钻石余额
 
-             $res5 = $userModel->where(["id" => $this->auth->id])->setInc("jewel", $exchangeMoney);
 
-             if ($res1 && $res2 && $res3 && $res4 && $res5) {
 
-                 Db::commit();
 
-                 $this->success("兑换成功!");
 
-             } else {
 
-                 $this->error("操作失败!");
 
-             }
 
-         } catch (ValidateException $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         } catch (PDOException $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         } catch (Exception $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         }
 
-     }
 
-     /**
 
-      * 声币兑换余额
 
-      */
 
-     public function exchange()
 
-     {
 
-         $this->error('接口作废');
 
-         exit;//作废
 
-         // 接口防并发
 
-         if (!$this->apiLimit(1, 1000)) {
 
-             $this->error(__('Operation frequently'));
 
-         }
 
-         $exchange_id = $this->request->request("exchange_id");// 兑换声币配置ID
 
-         $sound_coin = $this->request->request("sound_coin");// 输入具体声币数量
 
-         if (!$sound_coin && !$exchange_id) {
 
-             $this->error(__('Invalid parameters'));
 
-         }
 
-         if ($sound_coin > 0) {
 
-             $scoin = $sound_coin;
 
-             // 获取配置信息
 
-             $conf = 100;//config("site.soundcoinTomoney");
 
-             $exchangeMoney = round(($sound_coin * ($conf / 100)) / 100, 2);
 
-             if ($exchangeMoney < 0.01) $this->error(__('声币兑换数量太小啦!'));
 
-         } else {
 
-             // 获取兑换配置信息
 
-             $exchangeModel = new \app\common\model\ExchangeConfig();
 
-             $exchangeInfo = $exchangeModel->get($exchange_id);
 
-             if (!$exchangeInfo) $this->error("配置信息未找到");
 
-             $exchangeMoney = $exchangeInfo["money"] / 100;
 
-             $scoin = $exchangeInfo["sound_coin"];
 
-         }
 
-         Db::startTrans();
 
-         try {
 
-             // 查询声币余额
 
-             $userModel = new \app\common\model\User();
 
-             $userInfo = $userModel->lock('lock in share mode')->find($this->auth->id);
 
-             if ($scoin > $userInfo["sound_coin"]) {
 
-                 $this->error("声币余额不足!", [], 100);
 
-             }
 
-             $moneylogModel = new \app\common\model\UserMoneyLog();
 
-             $soundlogModel = new \app\common\model\UserSoundcoinLog();
 
-             $exchangelogModel = new \app\common\model\UserExchangeLog();
 
-             $detail = "声币兑换余额";
 
-             // 添加资金流水记录
 
-             $res1 = $moneylogModel->addRecord($this->auth->id, $exchangeMoney, "+", $userInfo["money"], $detail);
 
-             // 添加兑换记录
 
-             $res2 = $exchangelogModel->addExchangeLog($this->auth->id, $scoin, $exchangeMoney);
 
-             // 添加声币流水记录
 
-             $res3 = $soundlogModel->addUserSoundcoinLog($this->auth->id, $scoin, "-", $userInfo["sound_coin"], $detail, 3, $res2);
 
-             // 减去用户声币余额
 
-             $res4 = $userModel->where(["id" => $this->auth->id])->setDec("sound_coin", $scoin);
 
-             // 增加用户资金余额
 
-             $res5 = $userModel->where(["id" => $this->auth->id])->setInc("money", $exchangeMoney);
 
-             if ($res1 && $res2 && $res3 && $res4 && $res5) {
 
-                 Db::commit();
 
-                 $this->success("兑换成功!");
 
-             } else {
 
-                 $this->error("操作失败!");
 
-             }
 
-         } catch (ValidateException $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         } catch (PDOException $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         } catch (Exception $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         }
 
-     }
 
-     /**
 
-      * 余额兑换钻石
 
-      */
 
-     public function jewelExchange()
 
-     {
 
-         Db::startTrans();
 
-         try {
 
-             // 接口防并发
 
-             if (!$this->apiLimit(1, 1000)) {
 
-                 throw new Exception(__('Operation frequently'));
 
-             }
 
-             $exchange_id = $this->request->request("exchange_id");// 兑换声币配置ID
 
-             $money = $this->request->request("money");// 输入具体声币数量
 
-             if (!$money && !$exchange_id) {
 
-                 throw new Exception(__('Invalid parameters'));
 
-             }
 
-             if ($money && $money < 1) {
 
-                 throw new Exception('兑换金额异常');
 
-             }
 
-             if ($money > 0) {
 
-                 $exchangeMoney = $money;
 
-                 // 获取配置信息
 
-                 $conf = config("site.money_to_jewel");
 
-                 $scoin = $money * $conf;
 
-             } else {
 
-                 // 获取兑换配置信息
 
-                 $exchangeModel = new \app\common\model\ExchmoneyConfig();
 
-                 $exchangeInfo = $exchangeModel->get($exchange_id);
 
-                 if (!$exchangeInfo) throw new Exception("配置信息未找到");
 
-                 $exchangeMoney = $exchangeInfo["money"] / 100;
 
-                 $scoin = $exchangeInfo["jewel"];
 
-             }
 
-             $userId = $this->auth->id;
 
-             // 查询余额
 
-             $userModel = new \app\common\model\User();
 
-             $userInfo = $userModel->lock('lock in share mode')->find($userId);
 
-             if ($scoin > $userInfo["money"]) {
 
-                 throw new Exception("余额不足!");
 
-             }
 
-             $moneylogModel = new \app\common\model\UserMoneyLog();
 
-             $jewellogModel = new \app\common\model\UserJewelLog();
 
-             $exchangelogModel = new \app\common\model\UserExchangeLog();
 
-             $detail = "余额兑换钻石";
 
-             // 添加资金流水记录
 
-             $res1 = $moneylogModel->addRecord($userId, $exchangeMoney, "-", $userInfo["money"], $detail,14);
 
-             // 添加兑换记录
 
-             $res2 = $exchangelogModel->addExchangeLog($userId, $scoin, $exchangeMoney);
 
-             // 添加钻石流水记录
 
-             $res3 = $jewellogModel->addUserJewelLog($userId, $scoin, "+", $userInfo["jewel"], $detail, 14);
 
-             // 减去用户余额
 
-             $res4 = $userModel->where(["id" => $userId])->setDec("money", $exchangeMoney);
 
-             // 增加用户钻石余额
 
-             $res5 = $userModel->where(["id" => $userId])->setInc("jewel", $scoin);
 
-             if ($res1 && $res2 && $res3 && $res4 && $res5) {
 
-                 Db::commit();
 
-                 $this->success("兑换成功!");
 
-             } else {
 
-                 $this->error("操作失败!");
 
-             }
 
-         } catch (ValidateException $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         } catch (PDOException $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         } catch (Exception $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         }
 
-     }
 
- //    /**
 
- //     * 兑换
 
- //     */
 
- //    public function exchange() {
 
- //        $exchange_id = $this->request->request("exchange_id");// 兑换钻石配置ID
 
- //        if(!$exchange_id) {
 
- //            $this->error(__('Invalid parameters'));
 
- //        }
 
- //
 
- //        // 获取兑换配置信息
 
- //        $exchangeModel = new \app\common\model\ExchangeConfig();
 
- //        $exchangeInfo = $exchangeModel->get($exchange_id);
 
- //        if(!$exchangeInfo) $this->error("配置信息未找到");
 
- //        $exchangeMoney = $exchangeInfo["money"]/100;
 
- //        // 查询钻石余额
 
- //        $userModel = new \app\common\model\User();
 
- //        $userInfo = $userModel->get($this->auth->id);
 
- //        if($exchangeInfo["jewel"] > $userInfo["jewel"]) {
 
- //            $this->error("钻石余额不足!",[],100);
 
- //        }
 
- //
 
- //        Db::startTrans();
 
- //        try{
 
- //            $moneylogModel = new \app\common\model\UserMoneyLog();
 
- //            $jewellogModel = new \app\common\model\UserJewelLog();
 
- //            $exchangelogModel = new \app\common\model\UserExchangeLog();
 
- //            $detail = "兑换";
 
- //            // 添加资金流水记录
 
- //            $res1 = $moneylogModel->addRecord($this->auth->id,$exchangeMoney,"-",$userInfo["money"],$detail);
 
- //            // 添加钻石流水记录
 
- //            $res2 = $jewellogModel->addUserJewelLog($this->auth->id,$exchangeMoney,"+",$userInfo["money"],$detail);
 
- //            // 添加兑换记录
 
- //            $res3 = $exchangelogModel->addExchangeLog($this->auth->id,$exchangeInfo["jewel"],$exchangeMoney);
 
- //            // 减去用户钻石余额
 
- //            $res4 = $userModel->where(["id"=>$this->auth->id])->setDec("jewel",$exchangeInfo["jewel"]);
 
- //            // 增加用户资金余额
 
- //            $res5 = $userModel->where(["id"=>$this->auth->id])->setInc("money",$exchangeMoney);
 
- //            if($res1 && $res2 && $res3 && $res4  && $res5) {
 
- //                Db::commit();
 
- //                $this->success("兑换成功!");
 
- //            } else {
 
- //                $this->error("操作失败!");
 
- //            }
 
- //        }catch (ValidateException $e) {
 
- //            Db::rollback();
 
- //            $this->error($e->getMessage());
 
- //        } catch (PDOException $e) {
 
- //            Db::rollback();
 
- //            $this->error($e->getMessage());
 
- //        } catch (Exception $e) {
 
- //            Db::rollback();
 
- //            $this->error($e->getMessage());
 
- //        }
 
- //    }
 
-     /**
 
-      * 提现
 
-      */
 
-     public function withdrow()
 
-     {
 
-         $money = $this->request->request("money");// 申请提现的金额
 
-         if ($money <= 0) {
 
-             $this->error(__('提现金额不合法'));
 
-         }
 
-         // 判断当前用户是否实名认证
 
-         $userAuthInfo = \app\common\model\UserAuth::where(["user_id" => $this->auth->id])->find();
 
-         if ($userAuthInfo) {
 
-             if ($userAuthInfo->status == 0) {
 
-                 $this->error("您的实名认证还在这审核中...,请耐心等待!");
 
-             } elseif ($userAuthInfo->status == 2) {
 
-                 $this->error("您的实名认证审核未通过,请重新审核!");
 
-             }
 
-         } else {
 
-             $this->error("请先申请实名认证!");
 
-         }
 
-         // 查询资金余额
 
-         $userModel = new \app\common\model\User();
 
-         $userInfo = $userModel->get($this->auth->id);
 
-         if ($money > $userInfo["money"]) {
 
-             $this->error("资金余额不足!", [], 100);
 
-         }
 
-         Db::startTrans();
 
-         try {
 
-             $withdrawallogModel = new \app\common\model\UserWithdrawalLog();
 
-             // 减去用户可用资金余额
 
-             $res1 = $userModel->where(["id" => $this->auth->id])->setDec("money", $money);
 
-             // 增加用户冻结资金余额
 
-             $res2 = $userModel->where(["id" => $this->auth->id])->setInc("frozen", $money);
 
-             // 新增用户提现记录申请
 
-             $data = [];
 
-             $data["user_id"] = $this->auth->id;
 
-             $data["money"] = $money * 100;
 
-             $data["status"] = 0; // 提现状态:-1=审核拒绝,0=待审核,1=审核通过
 
-             $data["createtime"] = time();
 
-             $res3 = $withdrawallogModel->insert($data);
 
-             if ($res1 && $res2 && $res3) {
 
-                 Db::commit();
 
-                 $this->success("提现申请发送成功!");
 
-             } else {
 
-                 $this->error("操作失败!");
 
-             }
 
-         } catch (ValidateException $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         } catch (PDOException $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         } catch (Exception $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         }
 
-     }
 
-     /**
 
-      * 获取充值金额配置信息
 
-      */
 
-     public function getRecharConfig()
 
-     {
 
-         $params_from = $this->request->request("params_from",'');// 平台参数
 
-         $where = [];
 
-         if($params_from == 'ios'){
 
-             $where['money'] = ['<=', 3000];
 
-         }
 
-         $list = \app\common\model\RecharConfig::where($where)->order("weight", "asc")->select();
 
-         if (!$list) $this->error("配置信息为空!");
 
-         foreach ($list as $k => $v) {
 
-             $money = $v["money"] / 100;
 
-             $list[$k]["money"] = $money;
 
-             $list[$k]["desId"] = "banshengvoice" . $money;
 
-             if ($params_from != "ios") $list[$k]["jewel"] = $v["jewel_full"];
 
-             $list[$k]['ratio'] = $list[$k]["jewel"] / $money;
 
-             unset($list[$k]["jewel_full"]);
 
-         }
 
-         $this->success("获取成功!", $list);
 
-     }
 
-     /**
 
-      * 获取声币兑换余额配置信息
 
-      */
 
-     public function getExchangeConfig()
 
-     {
 
-         $list = \app\common\model\ExchangeConfig::field("id,sound_coin,money,updatetime,createtime")->select();
 
-         if (!$list) $this->error("配置信息为空!");
 
-         foreach ($list as $k => $v) $list[$k]["money"] = $v["money"] / 100;
 
-         $this->success("获取成功!", $list);
 
-     }
 
-     /**
 
-      * 获取钻石兑换余额配置信息
 
-      */
 
-     public function getExchmoneyConfig()
 
-     {
 
-         $list = \app\common\model\ExchmoneyConfig::field("id,jewel,money")->select();
 
-         if (!$list) $this->error("配置信息为空!");
 
-         foreach ($list as $k => $v) {
 
-             $list[$k]["id"] = (int)$v["id"];
 
-             $list[$k]["jewel"] = (int)$v["jewel"];
 
-             $list[$k]["money"] = $v["money"] / 100;
 
-         }
 
-         $this->success("获取成功!", $list);
 
-     }
 
-     /**
 
-      * 获取声币兑换钻石配置信息
 
-      */
 
-     public function getExchsoundConfig()
 
-     {
 
-         $list = \app\common\model\ExchsoundConfig::field("id,sound_coin,jewel,updatetime,createtime")->select();
 
-         if (!$list) $this->error("配置信息为空!");
 
-         $this->success("获取成功!", $list);
 
-     }
 
-     /**
 
-      * 获取用户充值记录
 
-      */
 
-     public function rechargeRecord()
 
-     {
 
-         $page = $this->request->request('page', 1); // 分页
 
-         $pageNum = $this->request->request('pageNum', 10); // 分页
 
-         // 分页搜索构建
 
-         $pageStart = ($page - 1) * $pageNum;
 
-         $res = \app\common\model\UserRechargeLog::where(["user_id" => $this->auth->id])->limit($pageStart, $pageNum)->order("createtime", "desc")->select();
 
-         if ($res): foreach ($res as $k => &$v) $v["createtime"] = date("Y-m-d H:i:s", $v["createtime"]);endif;
 
-         $this->success("获取成功!", $res);
 
-     }
 
-     /**
 
-      * 获取用户兑换记录
 
-      */
 
-     public function exchangeRecord()
 
-     {
 
-         $page = $this->request->request('page', 1); // 分页
 
-         $pageNum = $this->request->request('pageNum', 10); // 分页
 
-         // 分页搜索构建
 
-         $pageStart = ($page - 1) * $pageNum;
 
-         $res = \app\common\model\UserExchangeLog::field("*,sound_coin as jewel")->where(["user_id" => $this->auth->id])->limit($pageStart, $pageNum)->order("createtime", "desc")->select();
 
-         if ($res): foreach ($res as $k => &$v) $v["createtime"] = date("Y-m-d H:i:s", $v["createtime"]);endif;
 
-         $this->success("获取成功!", $res);
 
-     }
 
-     /**
 
-      * 获取用户声币兑换钻石记录
 
-      */
 
-     public function exchsoundRecord()
 
-     {
 
-         $page = $this->request->request('page', 1); // 分页
 
-         $pageNum = $this->request->request('pageNum', 10); // 分页
 
-         // 分页搜索构建
 
-         $pageStart = ($page - 1) * $pageNum;
 
-         $res = \app\common\model\UserExchsoundLog::where(["user_id" => $this->auth->id])->limit($pageStart, $pageNum)->order("createtime", "desc")->select();
 
-         if ($res): foreach ($res as $k => &$v) $v["createtime"] = date("Y-m-d H:i:s", $v["createtime"]);endif;
 
-         $this->success("获取成功!", $res);
 
-     }
 
-     /**
 
-      * 获取用户提现记录
 
-      */
 
-     public function withdrowRecord()
 
-     {
 
-         $page = $this->request->request('page', 1); // 分页
 
-         $pageNum = $this->request->request('pageNum', 10); // 分页
 
-         // 分页搜索构建
 
-         $pageStart = ($page - 1) * $pageNum;
 
-         $res = \app\common\model\UserWithdrawalLog::where(["user_id" => $this->auth->id])->limit($pageStart, $pageNum)->order("createtime", "desc")->select();
 
-         if ($res) {
 
-             $statusTxt = array("-1" => "审核拒绝", "0" => "待审核", "1" => "审核通过");
 
-             foreach ($res as $k => &$v) {
 
-                 $v["status"] = $statusTxt[$v["status"]];
 
-                 $v["money"] = $v["money"] > 0 ? $v["money"] / 100 : 0;
 
-                 $v["createtime"] = date("Y-m-d H:i:s", $v["createtime"]);
 
-             }
 
-         }
 
-         $this->success("获取成功!", $res);
 
-     }
 
-     /**
 
-      * 获取返利列表
 
-      */
 
-     public function getRebateList()
 
-     {
 
-         $pretype = $this->request->request('pretype', 0); // 下属类型:1=直属,2=下属
 
-         if (!in_array($pretype, [0, 1, 2])) $this->error("参数错误!");
 
-         $page = $this->request->request('page', 1); // 分页
 
-         $pageNum = $this->request->request('pageNum', 10); // 分页
 
-         // 分页搜索构建
 
-         $pageStart = ($page - 1) * $pageNum;
 
-         $where = [];
 
-         $where["a.user_id"] = $this->auth->id;
 
-         $pretype && $where["a.rebate_type"] = $pretype;
 
-         $where["a.is_rebate"] = 1;
 
-         $list = \app\common\model\RebateLog::alias("a")
 
-             ->field("a.*,u.nickname")
 
-             ->join("hx_user u", "u.id = a.by_user_id")
 
-             ->limit($pageStart, $pageNum)
 
-             ->order("createtime", "desc")
 
-             ->where($where)->select();
 
-         if ($list) foreach ($list as $k => &$v) {
 
-             $v["createtime"] = date("Y-m-d H:i:s", $v["createtime"]);
 
-             $v["nickname"] = mb_substr($v["nickname"], 0, 1, "utf-8") . "***";
 
-         }
 
-         $this->success("获取成功!", $list);
 
-     }
 
-     /**
 
-      * 获取剩余返利总额
 
-      */
 
-     public function getRebateMoney()
 
-     {
 
-         $this->success("获取成功!", \app\common\model\User::where(["id" => $this->auth->id])->value("rebate_money"));
 
-     }
 
-     /**
 
-      * 获取返利统计
 
-      */
 
-     public function getRebateCount()
 
-     {
 
-         // 直属推荐收益
 
-         $where = [];
 
-         $where["user_id"] = $this->auth->id;
 
-         $where["rebate_type"] = 1;
 
-         $preRebate = \app\common\model\RebateLog::where($where)->sum("rebate_money");
 
-         // 下属推荐收益
 
-         $where = [];
 
-         $where["user_id"] = $this->auth->id;
 
-         $where["rebate_type"] = 2;
 
-         $prepreRebate = \app\common\model\RebateLog::where($where)->sum("rebate_money");
 
-         // 上周收益总计
 
-         $preweek = $this->firstOfWeek(date("Y-m-d H:i:s",bcsub(time(),604800)));
 
-         $starttime = strtotime($preweek." 00:00:00"); // 上周一时间
 
-         $endtime = bcadd($starttime,604800); // 上周天时间
 
-         $where = [];
 
-         $where["user_id"] = $this->auth->id;
 
-         $where["createtime"] = ["between", "$starttime,$endtime"];
 
-         $weekRebate = \app\common\model\RebateLog::where($where)->sum("rebate_money");
 
-         // 历史收益总计
 
-         $where = [];
 
-         $where["user_id"] = $this->auth->id;
 
-         $where["createtime"] = ["lt", $starttime];
 
-         $allRebate = \app\common\model\RebateLog::where($where)->sum("rebate_money");
 
-         $res = [];
 
-         $res["preRebate"] = number_format($preRebate, 2);
 
-         $res["prepreRebate"] = number_format($prepreRebate, 2);
 
-         $res["weekRebate"] = number_format($weekRebate, 2);
 
-         $res["allRebate"] = number_format($allRebate, 2);
 
-         $this->success("获取成功!", $res);
 
-     }
 
-     /**
 
-      * 返利提现
 
-      */
 
-     public function rebateWithdraw()
 
-     {
 
-         $money = $this->request->request('money'); // 提现金额
 
-         if (!$money) $this->error("参数缺失!");
 
-         if ($money > 50000) $this->error("单笔上限50000元哦,超过50000元请联系客服处理!");
 
-         if ($money % 10 > 0) $this->error("提现金额必须为10的倍数!");
 
-         $user_id = $this->auth->id;
 
-         // 获取用户返利金额
 
-         $rebateMoney = \app\common\model\User::where(['id' => $user_id])->value("rebate_money");
 
-         if ($rebateMoney <= 100) $this->error("返利金额需要大于100元才能提现哦!");
 
-         $rdsMoney = bcsub($rebateMoney, $money);
 
-         if ($rdsMoney < 0) {
 
-             $this->error("余额不足,不能提现!", null, 100);
 
-         }
 
-         // 可以提现
 
-         Db::startTrans();
 
-         try {
 
-             $data = [];
 
-             $data["user_id"] = $user_id;
 
-             $data["money"] = $money;
 
-             $data["before"] = $rebateMoney;
 
-             $data["after"] = $rdsMoney;
 
-             $data["status"] = 1;
 
-             $data["createtime"] = time();
 
-             $res1 = \app\common\model\RebateWithdraw::insert($data);
 
-             $res2 = \app\common\model\User::update(["rebate_money" => $rdsMoney], ["id" => $user_id]);
 
-             if ($res1 && $res2) {
 
-                 Db::commit();
 
-                 $this->success("提现成功!");
 
-             } else {
 
-                 $this->error("网络繁忙,请稍后重试!");
 
-             }
 
-         } catch (ValidateException $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         } catch (PDOException $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         } catch (Exception $e) {
 
-             Db::rollback();
 
-             $this->error($e->getMessage());
 
-         }
 
-     }
 
-     /**
 
-      * 提现余额记录验证
 
-      */
 
-     public function withdrawVerify($user_id)
 
-     {
 
-         if (!$user_id) return false;
 
-         // 统计用户所有兑换记录和提现记录 是否与余额匹配
 
-         $moneylog = \app\common\model\UserMoneyLog::where(["user_id" => $user_id, "mode" => "+"])->sum('value');
 
-         $withdraw = \app\common\model\UserWithdrawalLog::where(["user_id" => $user_id, "status" => ["in", [0, 1]]])->sum("money");
 
-         $withdraw = bcdiv($withdraw, 100,2);
 
-         $sum = bcsub($moneylog, $withdraw,2);
 
-         $usermoney = \app\common\model\User::where(["id" => $user_id])->value("money");
 
-         if ($usermoney == $sum) {
 
-             return true;
 
-         } else {
 
-             return false;
 
-         }
 
-     }
 
-     /**
 
-      * 获取声币记录
 
-      */
 
-     public function getMySoundCoinRecord()
 
-     {
 
-         $type = $this->request->request('type', 1); // 类型
 
-         $page = $this->request->request('page', 1); // 分页
 
-         $pageNum = $this->request->request('pageNum', 10); // 分页
 
-         // 分页搜索构建
 
-         $pageStart = ($page - 1) * $pageNum;
 
-         $where = [];
 
-         $where["user_id"] = $this->auth->id;
 
-         $where["obj_id"] = ['>', 0];
 
-         if ($type == 1) { //收益记录
 
-             $where["type"] = 1;
 
-         } else {// 提现记录,后台调整划到提现记录
 
-             $where["type"] = ['in', '2,3,10000'];
 
-         }
 
-         $res = \app\common\model\UserSoundcoinLog::field('id,type,obj_id,value,mode,detail,createtime')->where($where)->limit($pageStart, $pageNum)->order("createtime", "desc")->select();
 
-         if ($res) {
 
-             foreach ($res as $k => &$v) {
 
-                 $subject = $v['detail'];
 
-                 if ($v['type'] == 1) {
 
-                     // 查询礼物赠送记录
 
-                     $giftInfo = GiftUserParty::alias('a')->join('user u', 'a.user_id = u.id')->where('a.id', $v['obj_id'])->field('user_id,nickname,gift_id,gift_name,number')->find();
 
-                     $subject = $giftInfo['nickname'] . '送你';
 
-                     $subject_notes = "{$giftInfo['gift_name']} * {$giftInfo['number']}";
 
-                 } elseif ($v['type'] == 2) {
 
-                     // 查询礼物赠送记录
 
-                     $jewel = UserExchsoundLog::where('id', $v['obj_id'])->value('jewel');
 
-                     $subject_notes = "已兑换{$jewel}砖石";
 
-                 } elseif ($v['type'] == 3) {
 
-                     // 查询礼物赠送记录
 
-                     $money = UserExchangeLog::where('id', $v['obj_id'])->value('money');
 
-                     $subject_notes = "已兑换{$money}余额";
 
-                 } elseif ($v['type'] == 5 || $v['type'] == 10000) {
 
-                     $modeText = $v['mode'] == '+' ? '调增' : '调减';
 
-                     $subject_notes = "已{$modeText}{$v['value']}声币";
 
-                 }
 
-                 $v['subject'] = $subject;
 
-                 $v['subject_notes'] = $subject_notes;
 
-                 $v["createtime"] = date("m月d日 H时i分", $v["createtime"]);
 
-             }
 
-         }
 
-         $this->success("获取成功!", $res);
 
-     }
 
-     /**
 
-      * 获取收益
 
-      * @return void
 
-      */
 
-     public function getMySoundCoinRecordNew()
 
-     {
 
-         try {
 
-             $userId = $this->auth->id;
 
-             $field = 'id,type,detail,mode,value,createtime';
 
-             $where['user_id'] = $userId;
 
-             $where['mode'] = '+';
 
-             //$where['type'] = [101,102,103,105,106];//101=>'获赠礼物',102=>'房间礼物抽成',103=>'邀请推广',105=>'申请提现驳回',106=>'接单收益',
 
-             $result = model('UserMoneyLog')->field($field)->where($where)->autopage()->order('createtime desc')->select();
 
-             if (!empty($result)) {
 
-                 $logType = config('wallet.logtype');
 
-                 foreach ($result as $key => &$value) {
 
-                     $value['type_text'] = isset($logType[$value['type']]) ? $logType[$value['type']] : '';
 
-                     $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i',$value['createtime']) : '';
 
-                 }
 
-             }
 
-             $this->success('获取成功',$result);
 
-         } catch (Exception $e) {
 
-             $this->error($e->getMessage());
 
-         }
 
-     }
 
-     /**
 
-      * 内购参数验证
 
-      */
 
-     public function applebuy()
 
-     {
 
-         $receiptdata = $this->request->request('receiptdata'); // 验证参数
 
-         $rechar_id = $this->request->request("rechar_id");// 充值金额配置ID
 
-         if (!$receiptdata || !$rechar_id) $this->error("参数缺失!");
 
-         // 获取密钥配置
 
-         $configInfo = config("applebuy_url");
 
-         $applebuy = new applebuy($configInfo);
 
-         $ret = $applebuy->toSendVeify($receiptdata);
 
-         if (!$ret || !isset($ret["status"])) $this->error("网络请求失败,请稍后重试!");
 
-         if ($ret["status"] != 0) $this->error("支付验证失败!");
 
- //        print_r($ret);exit;
 
-         $user_id = $this->auth->id;
 
-         // 获取充值金额配置信息
 
-         $recharMode = new \app\common\model\RecharConfig();
 
-         $recharInfo = $recharMode->where(["id" => $rechar_id])->find();
 
-         if (!$recharInfo) $this->error("金额配置信息未找到!");
 
-         $amount = $recharInfo["money"] / 100;
 
-         $retkey = end($ret["receipt"]["in_app"]);
 
-         if ($retkey["product_id"] != "banshengvoice" . $amount) $this->error("支付验证失败!");
 
-         if (!$amount || $amount < 0) {
 
-             $this->error("支付金额必须大于0");
 
-         }
 
-         if($amount > 30){
 
-             $this->error("充值维护中");
 
-         }
 
-         $time = time();
 
-         $money = (float)bcadd($amount, 0, 2);
 
-         $recharOrderMode = new \app\common\model\RecharOrder();
 
-         $resrepeatid = $retkey["transaction_id"];
 
-         // 查询订单是否重复
 
-         $repeatOrderId = $recharOrderMode->where(["transaction_id" => $resrepeatid])->value("id");
 
-         if ($repeatOrderId > 0) $this->error("请勿重复操作!");
 
-         // 生成订单
 
-         $out_trade_no = date("YmdHis") . rand(100000, 999999);
 
-         $orderid = $recharOrderMode->execute("INSERT INTO `hx_rechar_order` (`user_id` , `order_no` , `money` , `jewel` , `transaction_id`, `createtime`) VALUES ($user_id , $out_trade_no , $money , " . $recharInfo['jewel'] . ", $resrepeatid, $time)");
 
-         if (!$orderid) $this->error("订单创建失败!");
 
-         // 添加充值记录等
 
-         $dores = $this->applePayNotify($out_trade_no, $money);
 
-         if (!$dores) $this->error("状态更新失败,请联系客服!");
 
-         // 首充赠送
 
-         $userInfo = \app\common\model\User::get($user_id);
 
-         if ($userInfo->is_recharge == 0) { // 首充
 
-             Db::startTrans();
 
-             try {
 
-                 // 赠送消息尾灯
 
-                 $res1 = \app\common\model\AttireBack::addToMyBack(15, $user_id);
 
-                 $userInfo->is_recharge = 1;
 
-                 $res2 = $userInfo->save();
 
-                 if ($res1 && $res2) Db::commit();
 
-             } catch (ValidateException $e) {
 
-                 Db::rollback();
 
-                 $this->error($e->getMessage());
 
-             }
 
-         }
 
-         $this->rebate($user_id, $amount);
 
-         // +EXP
 
-         \app\common\model\TaskLog::tofinish($user_id, "5EMwg7la", 1);
 
-         // 查询今日充值记录
 
-         $today = strtotime(date("Y-m-d 00:00:00"));
 
-         $rechargeMoney = \app\common\model\RecharOrder::where(["user_id" => $user_id, "createtime" => ["gt", $today]])->sum("money");
 
-         if ($rechargeMoney >= 100) {
 
-             // +EXP
 
-             \app\common\model\TaskLog::tofinish($user_id, "DaCVgOLu", 1);
 
-         }
 
-         // 查询新人礼包
 
-         $this->addBagGift($user_id, $amount);
 
-         $this->success("购买成功!");
 
-     }
 
-     /**
 
-      * 内购逻辑
 
-      */
 
-     private function applePayNotify($out_trade_no, $payamount)
 
-     {
 
-         Db::startTrans();
 
-         try {
 
-             $orderModel = new \app\common\model\RecharOrder();
 
-             $userModel = new \app\common\model\User();
 
-             $jewellogModel = new \app\common\model\UserJewelLog();
 
-             $rechargelogModel = new \app\common\model\UserRechargeLog();
 
-             $orderInfo = $orderModel->where(["order_no" => $out_trade_no])->find();
 
-             $userInfo = $userModel->where(["id" => $orderInfo["user_id"]])->find();
 
-             // 修改订单状态
 
-             $res1 = $orderModel->update(["status" => 1, 'platform' => 2], ["order_no" => $out_trade_no]);
 
-             // 修改用户钻石余额
 
-             $res2 = $userModel->where(["id" => $orderInfo["user_id"]])->setInc("jewel", $orderInfo["jewel"]);
 
-             // 添加钻石流水记录
 
-             $detail = "充值";
 
-             $res3 = $jewellogModel->addUserJewelLog($userInfo["id"], $orderInfo["jewel"], "+", $userInfo["jewel"], $detail, 1);
 
-             $rechargeCount = $rechargelogModel->where('user_id',$orderInfo["user_id"])->count();
 
-             $isFirstRecharge = $rechargeCount > 0 ? 0 : 1;
 
-             // 添加充值记录
 
-             $res4 = $rechargelogModel->addRecord($userInfo["id"], $orderInfo["jewel"], $payamount, bcadd($userInfo["jewel"], $orderInfo["jewel"], 2), $userInfo["money"], 2, 4, $isFirstRecharge, $userInfo["pre_userid"]);
 
-             if ($res1 && $res2 && $res3 && $res4) {
 
-                 // 添加统计
 
-                 $time = time();
 
-                 (new \app\common\model\User)->execute("update hx_user set chargecount = chargecount + $payamount,chargetime = $time where id = " . $userInfo["id"]);
 
-                 Db::commit();
 
-                 return true;
 
-             }
 
-         } catch (ValidateException $e) {
 
-             Db::rollback();
 
-             return false;
 
-         } catch (PDOException $e) {
 
-             Db::rollback();
 
-             return false;
 
-         } catch (Exception $e) {
 
-             Db::rollback();
 
-             return false;
 
-         }
 
-     }
 
-     /**
 
-      * 获取我的推荐列表
 
-      */
 
-     public function getMyUsers() {
 
-         $thispage = $this->request->request('thispage',1); // 当前页
 
-         $pageNum = $this->request->request('pageNum', 10); // 分页
 
-         $page = [];
 
-         $page["page"] = $thispage;
 
-         $page["list_rows"] = $pageNum;
 
-         $user_id = $this->auth->id;
 
-         $userList = \app\common\model\User::field("id,nickname,u_id,bindtime")->where(["pre_userid"=>$user_id])->paginate($page);
 
-         if($userList) foreach($userList as $k => $v) $userList[$k]["bindtime"] = date("Y-m-d H:i:s",$v["bindtime"]);
 
-         $this->success("获取成功!",$userList);
 
-     }
 
-     /**
 
-      * 获取下级/下下级充值记录
 
-      */
 
-     public function getRechargeLog() {
 
-         $user_type = $this->request->request('user_type'); // 类型:1=直属,2=下属
 
-         $thispage = $this->request->request('thispage',1); // 当前页
 
-         $user_id = $this->auth->id;
 
-         $users = \app\common\model\User::where(["pre_userid"=>$user_id])->column("id");
 
-         if(!$users) $this->success("获取成功!",$users);
 
-         $ids = $users;
 
-         // 下下级
 
-         if($user_type == 2) {
 
-             $usersusers = [];
 
-             foreach($users as $v) {
 
-                 $user_id = $v;
 
-                 $userspre = \app\common\model\User::where(["pre_userid"=>$user_id])->column("id");
 
-                 if(!$userspre) continue;
 
-                 foreach($userspre as $n) {
 
-                     $usersusers[] = $n;
 
-                 }
 
-             }
 
-             $ids = $usersusers;
 
-         }
 
-         // 上个周一
 
-         $preweek = $this->firstOfWeek(date("Y-m-d H:i:s",bcsub(time(),604800)));
 
-         $starttime = strtotime($preweek." 00:00:00"); // 上周时间
 
-         $page = [];
 
-         $page["page"] = $thispage;
 
-         $page["list_rows"] = 10;
 
-         $where = [];
 
-         $where["a.user_id"] = ["in",$ids];
 
-         $where["a.createtime"] = ["gt",$starttime];
 
-         // 获取充值记录
 
-         $rechargeList = \app\common\model\UserRechargeLog::alias("a")
 
-             ->field("a.id,a.user_id,u.nickname,u.bindtime,a.createtime,a.money")
 
-             ->join("hx_user u","u.id = a.user_id")
 
-             ->where($where)
 
-             ->order("a.createtime","desc")
 
-             ->paginate($page);
 
-         if($rechargeList) foreach($rechargeList as $k => $v) {
 
-             if($v["createtime"] < $v["bindtime"]) {
 
-                 unset($rechargeList[$k]);
 
-                 continue;
 
-             }
 
-             $rechargeList[$k]["createtime"] = date("Y-m-d H:i:s",$v["createtime"]);
 
-             $rechargeList[$k]["nickname"] = mb_substr($v["nickname"], 0, 1, "utf-8") . "***";
 
-         }
 
-         $this->success("获取成功!",$rechargeList);
 
-     }
 
-     /**
 
-      * 获取上周收益
 
-      */
 
-     public function getLastweekProfit() {
 
-         $user_id = $this->auth->id;
 
-         $result = [];
 
-         // 上个周一
 
-         $preweek = $this->firstOfWeek(date("Y-m-d H:i:s",bcsub(time(),604800)));
 
-         $starttime = strtotime($preweek." 00:00:00"); // 上周一时间
 
-         $endtime = bcadd($starttime,604800); // 上周天时间
 
-         // 直属收益
 
-         $where = [];
 
-         $where["user_id"] = $user_id;
 
-         $where["is_rebate"] = 1;
 
-         $where["rebate_type"] = 1;
 
-         $where["createtime"] = ["between",[$starttime,$endtime]];
 
-         $rebate_rate = \app\common\model\RebateLog::where($where)->value("rebate_rate");
 
-         $rebate_rate = bcmul($rebate_rate,100,2);
 
-         $result["pre"]["money"] = \app\common\model\RebateLog::where($where)->sum("money");
 
-         $result["pre"]["rate"] = (float)$rebate_rate;
 
-         $result["pre"]["rebate_money"] = \app\common\model\RebateLog::where($where)->sum("rebate_money");
 
-         // 下属收益
 
-         $where = [];
 
-         $where["user_id"] = $user_id;
 
-         $where["is_rebate"] = 1;
 
-         $where["rebate_type"] = 2;
 
-         $where["createtime"] = ["between",[$starttime,$endtime]];
 
-         $rebate_rate = \app\common\model\RebateLog::where($where)->value("rebate_rate");
 
-         $rebate_rate = bcmul($rebate_rate,100,2);
 
-         $result["prepre"]["money"] = \app\common\model\RebateLog::where($where)->sum("money");
 
-         $result["prepre"]["rate"] = (float)$rebate_rate;
 
-         $result["prepre"]["rebate_money"] = \app\common\model\RebateLog::where($where)->sum("rebate_money");
 
-         // 上周收益总计
 
-         $result['weekRebate'] = (float)bcadd($result["pre"]["rebate_money"],$result["prepre"]["rebate_money"],2);
 
-         $this->success("获取成功!",$result);
 
-     }
 
-     ////////////////////////////////////
 
-     /**
 
-      * 消息-聊天-更多-转账-钻石
 
-      */
 
-     public function givejeweltouser(){
 
-         $money = intval(input('money',0));
 
-         $user_id = input('user_id',0);
 
-         $pay_password = input('paypassword','');
 
-         //验证用户权限是否能转账
 
-         if($this->auth->power->transfer == 1){
 
-             $this->error('您已经被限制消费-转账');
 
-         }
 
-         //验证被转账用户存在
 
-         $check = Db::name('user')->where('id',$user_id)->find();
 
-         if(empty($check)){
 
-             $this->error('不存在的用户');
 
-         }
 
-         //验证操作密码
 
-         if(!$this->auth->pay_password){
 
-             $this->error('请先设置支付密码');
 
-         }
 
-         if ($this->auth->pay_password != $this->getEncryptPassword($pay_password, $this->auth->pay_salt)) {
 
-             $this->error('支付密码有误');
 
-         }
 
-         Db::startTrans();
 
-         //减少和增加余额
 
-         $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,$money,'-',0,'私聊转账给:'.$check['nickname'],11,'jewel');
 
-         if($rs_wallet['status'] === false){
 
-             Db::rollback();
 
-             $this->error($rs_wallet['msg']);
 
-         }
 
-         $rs_wallet = model('wallet')->lockChangeAccountRemain($user_id,$money,'+',0,$this->auth->nickname.':私聊到账',12,'jewel');
 
-         if($rs_wallet['status'] === false){
 
-             Db::rollback();
 
-             $this->error($rs_wallet['msg']);
 
-         }
 
-         Db::commit();
 
-         $this->success('转账成功');
 
-     }
 
-     /**
 
-      * 获取密码加密后的字符串
 
-      * @param string $password 密码
 
-      * @param string $salt 密码盐
 
-      * @return string
 
-      */
 
-     private function getEncryptPassword($password, $salt = '')
 
-     {
 
-         return md5(md5($password) . $salt);
 
-     }
 
- }
 
 
  |