public function actionUse()
 {
     $uid = yii::$app->user->id;
     $raise_card_id = $_GET['id'];
     //使用礼券
     try {
         AloneMethod::useRaise($uid, $raise_card_id);
         echo "<script>alert('您使用了一张礼券');</script>";
         echo "<script>location.href='" . \yii\helpers\Url::to(['coupon/nouse']) . "'</script>";
         exit;
     } catch (ErrorException $e) {
         $error = $e->getMessage();
         echo "<script>alert('" . $error . "');</script>";
         echo "<script>location.href='" . \yii\helpers\Url::to(['coupon/nouse']) . "'</script>";
         exit;
     }
 }
 public function actionIndex()
 {
     $betime = strtotime(date('Y-m-d' . ' 00:00:00', time()));
     $endtime = strtotime(date('Y-m-d' . ' 23:59:59', time()));
     $order = Order::find()->andWhere(['between', 'start_at', $betime, $endtime])->asArray()->count();
     $payment = SinaDeposit::find()->andWhere(['status' => SinaDeposit::STATUS_SUCCESS])->andWhere(['between', 'create_at', $betime, $endtime])->asArray()->count();
     $withdraw = SinaWithdraw::find()->andWhere(['status' => SinaWithdraw::STATUS_SINA_SUCCESS])->andWhere(['between', 'create_at', $betime, $endtime])->asArray()->count();
     $product = Thirdproduct::find()->andWhere(['status' => Thirdproduct::STATUS_ACTIVE])->andWhere(['intent' => Thirdproduct::INTENT_CHECK])->andWhere(['create_user_id' => Yii::$app->user->identity->getId()])->asArray()->all();
     $user = UcenterMember::find()->andWhere(['between', 'created_at', $betime, $endtime])->asArray()->count();
     $log = TradeLog::find()->orderBy('t_date desc');
     $pages = new Pagination(['totalCount' => $log->count(), 'pageSize' => '10']);
     $log = $log->offset($pages->offset)->limit($pages->limit)->all();
     AloneMethod::trade_log();
     $cur_recharge = TradeLog::find()->sum('t_recharge');
     $cur_invest = TradeLog::find()->sum('t_invest');
     $cur_redeem = TradeLog::find()->sum('t_redeem');
     $cur_withdraw = TradeLog::find()->sum('t_withdraw');
     $cur_profit = TradeLog::find()->sum('t_profit');
     $cur_glod = TradeLog::find()->sum('t_gold');
     $cur_red = TradeLog::find()->sum('t_red');
     $ret_msg = '当前总额: 充值【' . $cur_recharge . '】 投资【' . $cur_invest . '】 赎回【' . $cur_redeem . '】 提现【' . $cur_withdraw . '】 在投【' . $cur_profit . '】 体验金收益【' . $cur_glod . '】 红包【' . $cur_red . '】';
     return $this->render('index', ['withdraw' => $withdraw, 'payment' => $payment, 'order' => $order, 'user' => $user, 'product' => $product, 'log' => $log, 'pages' => $pages, 'ret_msg' => $ret_msg]);
 }
Exemple #3
0
 /**
  * 通过分类获取文章列表
  * @return array|string
  */
 public static function actionGetcategoryarticles()
 {
     $result = App::AppGet();
     try {
         if ($result['errorNum']) {
             $result = array('errorNum' => $result['errorNum'], 'errorMsg' => $result['errorMsg'], 'data' => null);
         } else {
             $data = $result['data'];
             if (array_key_exists('title', $data)) {
                 $title = $data['title'];
                 $result = AloneMethod::get_category_article($title);
             } else {
                 $result = array('errorNum' => '1', 'errorMsg' => '参数错误', 'data' => null);
             }
         }
     } catch (ErrorException $e) {
         Yii::error(" 通过分类获取文章列表---异常 方法:actionGetcategoryarticles 参数:" . json_encode($result['data']), "app");
         Yii::trace($e->getMessage(), "app");
         $result = array('errorNum' => '7', 'errorMsg' => '服务器异常,请联系管理员', 'data' => null);
     }
     $result = App::AppReturn($result);
     return $result;
 }
 public function actionIncomelist()
 {
     if ($_REQUEST) {
         $uid = yii::$app->user->id;
         $page = intval($_REQUEST[page]);
         $page_num = intval($_REQUEST[num]);
         try {
             $result = AloneMethod::profit_log($uid, $page, $page_num);
         } catch (ErrorException $ex) {
             $result = '';
         }
         $datas = json_encode($result);
         echo $datas;
     }
 }
 public function actionIndex()
 {
     error_reporting(0);
     //取出后台设置最大红包
     $maxincome = Setting::getCode('maxincome');
     //取出后台设置的每人最大红白
     $maxpeople = Setting::getCode('maxpeople');
     //后台设置体验金利率
     $goldrate = Setting::getCode('goldrate');
     //设定时区
     date_default_timezone_set('PRC');
     //取出当前时间
     $btime = date('Y-m-d' . '00:00:00', time());
     //转换成“开始”的时间戳
     $btimestr = strtotime($btime);
     //
     //判定今日是否已经计算了收益---防止收益被多次计算
     $count = Income::find()->where(['>', 'created_at', $btimestr])->count();
     if ($count) {
         return '收益已经计算过了';
     }
     //查询昨天以前所有的投资订单,查询order表
     $order = Order::find()->select('member_id,sum(money) as smoney,product_id')->andWhere(['<', 'start_at', Utils::alldaytostr($btimestr)[1]])->andWhere(['status' => 1])->groupBy(['member_id', 'product_id'])->asArray()->all();
     $arrnew = array();
     //循环所有投资
     //        $test = 0;
     foreach ($order as $k => $v) {
         //查询订单下对应项目
         $product = Product::findOne($v['product_id']);
         //查询昨天的生成的利息
         $income = Income::find()->andWhere(['member_id' => $v['member_id']])->andWhere(['between', 'created_at', Utils::alldaytostr($btimestr)[0], Utils::alldaytostr($btimestr)[1]])->one();
         //查询增值卡昨天信息
         //            $railscard = RaiseCard::find()
         //                ->select('member_id,sum(rate) as srate')
         //                ->andWhere(['member_id'=>$v['member_id']])
         //                ->andWhere(['<', 'use_at',Utils::alldaytostr($btimestr)[1]])
         //                ->andWhere(['>', 'use_end_time',Utils::alldaytostr($btimestr)[1]])
         //                ->andWhere(['status'=>RaiseCard::STATUS_USE])
         //                ->groupBy(['member_id'])
         //                ->asArray()
         //                ->one();
         //昨日签到人数
         $count = SignIn::find()->joinWith(['info' => function ($query) {
             /** @var \yii\db\ActiveQuery $query */
             $query->andWhere(['>', 'asset_info.invest', '1000']);
         }])->andWhere(['between', 'sign_in.sign_in_time', Utils::alldaytostr($btimestr)[0], Utils::alldaytostr($btimestr)[1]])->asArray()->count();
         //每人赠送利息,如果每人分的利息大于设置的每人获得的最大利息,就用设置的每人利息,如果小于就用分的利息
         $everyincome = 0;
         if ($count) {
             $everyincome = $maxincome / $count > $maxpeople ? $maxpeople : $maxincome / $count;
         }
         //取出昨天这个人有没有签到
         $rails = SignIn::find()->andWhere(['uid' => $v['member_id']])->andWhere(['between', 'sign_in_time', Utils::alldaytostr($btimestr)[0], Utils::alldaytostr($btimestr)[1]])->asArray()->one();
         //判断订单是否有总金额
         $smoney = isset($v['smoney']) ? $v['smoney'] : 0;
         //查询该用户体验金
         //            $all = Gold::find()->select('experience_gold.id,experience_gold.rid,sum(experience_gold.money) as gmoney')->andWhere(['uid'=>$v['member_id']])->joinWith(['rule' => function ($query) {
         //                /** @var \yii\db\ActiveQuery $query */
         //                $query->andWhere(['experience_rule.status'=>Rule::STATUS_ACTIVE]);
         //            }])->asArray()->all();
         //
         //            //查询发放给该用户体验金昨天信息
         //            $sendgold = RaiseCard::find()
         //                ->select('member_id,sum(rate) as srate')
         //                ->andWhere(['member_id'=>$v['member_id']])
         //                ->andWhere(['<', 'validity_start_at',Utils::alldaytostr($btimestr)[1]])
         //                ->andWhere(['>', 'validity_out_at',Utils::alldaytostr($btimestr)[1]])
         //                ->andWhere(['status'=>RaiseCard::STATUS_USE])
         //                ->asArray()
         //                ->one();
         //查询该用户体验金-----TODO
         $all = Gold::find()->select('uid,sum(money) as smoney')->andWhere(['uid' => $v['member_id'], 'status' => Gold::STATUS_ACTIVE])->andWhere(['<', 'created_at', time()])->andWhere(['>', 'end_at', time()])->asArray()->one();
         //            $summoney = 0;
         //            foreach($all as $kmmy=>$vmmy){
         //                $newbetime = strtotime(date('Y-m-d'.' 00:00:00',time()));
         //                $endtime = $vmmy['created_at'] + 3600 * 24 * $vmmy['time'];
         //                if($vmmy['created_at']<$newbetime && $endtime>$newbetime){
         //                    $summoney +=$all[$kmmy]['money'];
         //                }
         //            }
         //            var_dump($summoney);
         //            var_dump($all);
         //查询发放给该用户体验金昨天信息
         //            $sendgold = RaiseCard::find()
         //                ->select('member_id,sum(rate) as srate')
         //                ->andWhere(['member_id'=>$v['member_id']])
         //                ->andWhere(['<', 'validity_start_at',Utils::alldaytostr($btimestr)[1]])
         //                ->andWhere(['>', 'validity_out_at',Utils::alldaytostr($btimestr)[1]])
         //                ->groupBy(['member_id'])
         //                ->asArray()
         //                ->one();
         //计算利率,增息卡的利率+项目的利率
         //            $railscardrate = isset($railscard)? $railscard['srate']+$product->rate/365:$product->rate/365;
         //TODO
         $railscardrate = isset($railscard) ? $railscard['srate'] + $product->rate : $product->rate;
         //活动期间利率调整TODO
         date_default_timezone_set('PRC');
         //活动开始时间
         $begin_time = strtotime('2015-10-1');
         //活动结束时间
         $end_time = strtotime('2015-10-7');
         //当前时间
         $now_time = time();
         if ($now_time > $begin_time && $now_time < $end_time) {
             $railscardrate = '0.101';
         }
         $railscardrate = '0.08';
         //组成新数组,用户的id
         $arrnew[$v['member_id']]['member_id'] = $v['member_id'];
         //用户昨日利息,因利息也会产生利息,所以昨日利息乘以利率
         // $arrnew[$v['member_id']]['smoney'] += isset($income)?($smoney+$income->smoney)*Utils::moneyFormat($railscardrate) :$smoney*Utils::moneyFormat($railscardrate);
         //投资总额---记录当前再投资金
         $arrnew[$v['member_id']]['money'] += $v['smoney'];
         //计算收益--TODO
         $arrnew[$v['member_id']]['smoney'] += ceil($smoney * $railscardrate * 100 / 365) / 100;
         //取不包含红包体验金收益
         $arrnew[$v['member_id']]['iincome'] += ceil($smoney * $railscardrate * 100 / 365) / 100;
         //用户的昨日之前的累计利息
         // isset($income)? $arrnew[$v['member_id']]['newmoney'] = $arrnew[$v['member_id']]['smoney']+$income->newmoney : $arrnew[$v['member_id']]['newmoney'] += $smoney*Utils::moneyFormat($railscardrate);
         // TODO
         isset($income) ? $arrnew[$v['member_id']]['newmoney'] = $arrnew[$v['member_id']]['smoney'] + $income->newmoney : ($arrnew[$v['member_id']]['newmoney'] += ceil($smoney * $railscardrate * 100 / 365) / 100);
         //签到获取的利息
         $arrnew[$v['member_id']]['railscard'] = $rails ? $everyincome : 0;
         //在投金额大于1元--计算体验金收益
         if ($smoney >= 1) {
             //计算该用户体验金获取的利息
             $arrnew[$v['member_id']]['goldincome'] = ceil($all['smoney'] * $railscardrate * 100 / 365) / 100;
         }
         //每人的利率
         $arrnew[$v['member_id']]['rate'] = $railscardrate;
     }
     foreach ($arrnew as $k => &$v) {
         //求出每个用户的昨日利率
         $v['rate'] = Utils::moneyFormat(($v['smoney'] + $v['railscard']) * 365 / $v['money']);
         //总利息加上签到获取的利息
         $v['newmoney'] = $v['railscard'] + $v['newmoney'] + $v['goldincome'];
         //利息加上签到获取的利息
         $v['smoney'] = $v['railscard'] + $v['smoney'] + $v['goldincome'];
         //利息计算时的投资---
         //            $v['money'] = $v['money']  + $v['goldincome'] + $v['railscard'];
         // -- 计算在投金额不应该增加利息产生的金额
         $v['money'] = $v['money'];
     }
     //循环数组
     foreach ($arrnew as $vs) {
         $_model = new Income();
         //查出用户表的余额
         $Info = Info::find()->where(['member_id' => $vs['member_id']])->one();
         if ($Info) {
             $Info->profit = $Info->profit + $vs['smoney'];
             $Info->total_revenue = $Info->total_revenue + $vs['smoney'];
             $Info->save();
         }
         //取出昨天这个人有没有签到
         $signin = SignIn::find()->andWhere(['uid' => $vs['member_id']])->andWhere(['between', 'sign_in_time', Utils::alldaytostr($btimestr)[0], Utils::alldaytostr($btimestr)[1]])->one();
         if ($signin && $vs['money'] >= 1000) {
             $signin->sign_in_money = $vs['railscard'];
             $signin->status = SignIn::STATUS_FINISH;
             $signin->save();
             $_model->railscard = $vs['railscard'];
         }
         $_model->member_id = $vs['member_id'];
         $_model->smoney = $vs['smoney'];
         $_model->money = $vs['money'];
         $_model->rate = $vs['rate'];
         $_model->newmoney = $vs['newmoney'];
         $_model->goldincome = $vs['goldincome'];
         $_model->iincome = $vs['iincome'];
         //生成每日利息表的数据
         $_model->save();
     }
     //推荐大师活动
     //获取所有用户信息
     $users = UcenterMember::find()->select(['id'])->asArray()->all();
     if ($users !== null) {
         //获取所有用户id值
         foreach ($users as $key => $value) {
             //循环用户信息--判定其推荐人中是否有符合奖励规则的人--有进行推荐表中状态更改
             AloneMethod::produce_red_packet($value['id']);
         }
     }
     //判定推荐表中用户是否符合拿取奖励规则
     if ($users !== null) {
         foreach ($users as $key => $value) {
             AloneMethod::send_red_packet($value['id']);
         }
     }
     echo "成功";
 }
Exemple #6
0
 public static function trade_log()
 {
     $t_date = date('Y-m-d');
     $days = 20;
     while ($days-- != 0) {
         //            $t_date = date($t_date,'-1 day');
         AloneMethod::trade_date_log($t_date);
         $t_date = date('Y-m-d', strtotime("-1 day", strtotime($t_date)));
     }
 }
Exemple #7
0
 /**
  *推广大师注册方法
  * @param $phone 手机号
  * @param $pwd  密码
  * @param $phone_code 手机验证码
  * @param $from 用户来源
  * @param string $invite_code 邀请码
  * @return array
  */
 public static function the_master_register($phone, $pwd, $phone_code, $invitation_id, $userIp = '')
 {
     $from = 1015;
     //开启推广大师
     $recommend_the_master = 1;
     //判定手机号是否注册
     $flag = self::phoneIsRegister($phone);
     if ($flag) {
         $return = array('errorNum' => '1', 'errorMsg' => '此手机号已注册,请直接登录', 'data' => null);
         return $return;
     } elseif (!preg_match('/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)[0-9a-zA-Z]{6,16}$/', $pwd)) {
         $return = array('errorNum' => '1', 'errorMsg' => '密码应该是数字、字母组成的6到16位字符', 'data' => null);
         return $return;
     }
     //邀请者id
     $user = UcenterMember::findOne(['id' => $invitation_id]);
     //不存在邀请者
     if ($user == null) {
         $return = array('errorNum' => '1', 'errorMsg' => '邀请者不存在', 'data' => null);
         return $return;
     }
     //手机短息验证码验证
     $check = Port::checkPhnoe($phone, $phone_code);
     $session_key = "";
     //生成app的密码
     $app_pwd = md5(sha1($pwd) . time());
     // 根据ip获取地区
     $area = self::get_area($userIp);
     $area = $area ? $area : '地球';
     if (!$check['errorNum']) {
         //事物回滚
         $transaction = \Yii::$app->db->beginTransaction();
         try {
             $user = new UcenterMember();
             $user->username = $phone;
             $user->phone = $phone;
             $user->setPassword(trim($pwd));
             $user->create_ip = $userIp;
             $user->create_area = $area;
             $user->create_channel = (int) $from;
             $user->invitation_code = self::random();
             $user->invitation_id = (int) $invitation_id;
             $user->status = UcenterMember::STATUS_ACTIVE;
             $user->lock = UcenterMember::TYPE_UNLOCK;
             //app密码设定
             $user->app_pwd = $app_pwd;
             ///
             $user->generateAuthKey();
             if ($user->save()) {
                 //生成邀请码
                 $new_uid = $user->id;
                 $invitation_code = 'v' . $new_uid * 99;
                 $user->invitation_code = $invitation_code;
                 $user->save();
                 //初始换用户账户
                 $asset_info = new Info();
                 $asset_info->member_id = $user['id'];
                 $asset_info->balance = 0;
                 $asset_info->freeze = 0;
                 if ($asset_info->save()) {
                     $uid = $user['id'];
                     if ($recommend_the_master) {
                         //推荐大师活动开启了
                         //用户注册--增加数据表
                         $produce = \frontend\actions\AloneMethod::produce_recommend($uid);
                         if ($produce['errorNum'] == '1') {
                             $return = array('errorNum' => '1', 'errorMsg' => '推荐大师活动错误', 'data' => null);
                             return $return;
                         }
                     }
                     //注册动作完成---进行登录操作
                     $log = new Log();
                     $log->member_id = $uid;
                     $log->login_ip = Yii::$app->request->userIp;
                     $log->login_time = time();
                     $log->login_area = $area;
                     $log->status = self::LOG_CONFIM;
                     $res = $log->save();
                     if ($res) {
                         $session_key = self::verification($uid) . '--' . $from;
                         $session = new Sessionkey();
                         $session->uid = $uid;
                         $session->sessionkey = $session_key;
                         $session->status = self::STATUS_ACTIVE;
                         $res = $session->save();
                         if ($res) {
                             $log->status = self::LOG_SUSSESS;
                             $log->save();
                             //新用户注册送体验金---区分推荐用户和非推荐用户
                             if ($invitation_id == 0) {
                                 //普通注册
                                 self::give_experience_gold(1, $user['id']);
                             } else {
                                 self::give_experience_gold(7, $user['id']);
                             }
                         } else {
                             $return = array('errorNum' => '1', 'errorMsg' => '登陆失败', 'data' => null);
                             return $return;
                         }
                     } else {
                         $return = array('errorNum' => '1', 'errorMsg' => '登陆记录失败', 'data' => null);
                         return $return;
                     }
                 } else {
                     $return = array('errorNum' => '1', 'errorMsg' => '账户初始化失败', 'data' => null);
                     return $return;
                 }
             } else {
                 $return = array('errorNum' => '1', 'errorMsg' => '注册失败', 'data' => null);
                 return $return;
             }
             $transaction->commit();
             //事务成功提交后返回数据
             $data = array('sessionkey' => $session_key, 'balance' => 0, 'phone' => $phone, 'app_pwd' => $app_pwd);
             $return = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => $data);
             return $return;
         } catch (\Exception $e) {
             $transaction->rollBack();
             $remark = $e->getMessage();
             $result = array('errorNum' => '1', 'errorMsg' => $remark, 'data' => null);
             return $result;
         }
     } else {
         $return = array('errorNum' => '1', 'errorMsg' => $check['errorMsg'], 'data' => null);
         return $return;
     }
 }