public static function getCode($code) { if (!$code) { return; } $setting = Setting::find()->where(['code' => $code])->one(); if ($setting) { return $setting->value; } else { return; } }
public function actionIndex() { if (\App::$app->request->isPost) { $siteRoot = str_replace('\\', '/', realpath(dirname(dirname(dirname(__FILE__))) . '/')) . "/www/web/upload/"; if (!empty($_FILES)) { if ($_FILES['Setting']['tmp_name']['img']) { $tempPath = $_FILES['Setting']['tmp_name']['img']; $filesName = uniqid() . '.' . pathinfo($_FILES['Setting']['name']['img'], PATHINFO_EXTENSION); $uploadPath = $siteRoot . $filesName; move_uploaded_file($tempPath, $uploadPath); Setting::updateAll(['value' => $filesName], ['code' => 'img']); } } $setting = \App::$app->request->post('Setting'); foreach ($setting as $key => $value) { Setting::updateAll(['value' => $value], ['code' => $key]); } } $settingParent = Setting::find()->where(['parent_id' => 0])->orderBy(['sort_order' => SORT_ASC])->all(); return $this->render('index', ['settingParent' => $settingParent]); }
// footer数据表 try { $tel1 = Setting::findOne(['code' => 'phone'])->value; $tel2 = Setting::findOne(['code' => 'tell'])->value; $email = Setting::findOne(['code' => 'email'])->value; $work = Setting::findOne(['code' => 'work'])->value; } catch (ErrorException $e) { $tel1 = ""; $tel2 = ""; $email = ""; $work = ""; } //关键词 $keywords = ''; try { $keywords = Setting::findOne(['code' => 'siteKeyword'])->value; } catch (ErrorException $e) { } ?> <?php $this->beginPage(); ?> <!DOCTYPE html> <html lang="<?php echo Yii::$app->language; ?> "> <head> <meta charset="<?php echo Yii::$app->charset;
public function actionSignup() { //判断注册URL中是否包含邀请码参数 if (isset($_GET['code'])) { $code = $_GET['code']; //$_code_source = UcenterMember::find()->where(['invitation_code'=>$code])->one(); //if(count($_code_source) != 1) $flag = \frontend\actions\app\member::verify_code($code); if (!$flag) { header("Content-type: text/html; charset=utf-8"); echo "<script>alert('来源链接不合法!')</script>"; echo "<script>window.location.href='" . \yii\helpers\Url::to(['site/signup']) . "'</script>"; exit; } } $model = new SignupForm(); //是否邀请注册 $test_invite = 1; if ($model->load(Yii::$app->request->post())) { if ($_POST['SignupForm']['username'] && $_POST['SignupForm']['validate_code'] && $_POST['SignupForm']['password'] && $_POST['SignupForm']['password_repeat']) { $invite_code = $_POST["SignupForm"]['invitation_code']; //使用测试邀请码 if ($test_invite) { //使用测试邀请 $flag = \frontend\actions\app\member::verify_code($invite_code); //验证码通过 if (!$flag) { echo "<script>alert('" . '邀请码错误' . "')</script>"; } } $_phone = $_POST['SignupForm']['username']; $_code = $_POST['SignupForm']['validate_code']; try { $result = Port::checkPhnoe($_phone, $_code); if (is_bool($result)) { } } catch (ErrorException $e) { header("Content-type: text/html; charset=utf-8"); echo "<script>alert('" . $e->getMessage() . "')</script>"; echo "<script>location.href='" . \yii\helpers\Url::to(['site/signup']) . "'</script>"; exit; } $user = new UcenterMember(); $user->username = $_POST["SignupForm"]['username']; $user->phone = $_POST["SignupForm"]['username']; $user->invitation_code = $_POST["SignupForm"]['invitation_code']; $password = $_POST["SignupForm"]['password']; $user->setPassword($password); $user->create_ip = Yii::$app->request->userIp; $app_pwd = md5(sha1($password) . time()); $user->app_pwd = $app_pwd; try { $area = self::get_area(Yii::$app->request->userIp); $user->create_area = $area; } catch (ErrorException $e) { } $user->generateAuthKey(); if ($user->save()) { $uid = $user['id']; if ($test_invite) { //使用验证码 $flag = \frontend\actions\app\member::verify_code($invite_code); $invite_flag = \frontend\actions\app\member::use_code($flag, $uid); if (!$invite_flag) { $return = array('errorNum' => '1', 'errorMsg' => '注册失败', 'data' => null); return $return; } } if (Yii::$app->getUser()->login($user)) { $newModel = UcenterMember::find()->where(['id' => Yii::$app->user->id])->one(); //$newModel->invitation_id= \yii::$app->params['invitation_id']; $invitation_code = Utils::createcode(); $newModel->invitation_code = $invitation_code; $newModel->person_face = Setting::find()->where("code='img'")->one()->value; if ($_POST['url_code']) { $code_source = UcenterMember::find()->where(['invitation_code' => $_POST["url_code"]])->asArray()->one(); if ($code_source) { $newModel->invitation_id = $code_source['id']; } //好友注册领取体验金 $rule = Rule::find()->where(['title' => '好友注册', 'status' => Rule::STATUS_ACTIVE])->one(); if ($rule) { $rid = $rule->id; $r_money = $rule->money; $model_gold = new Gold(); $model_gold->rid = $rid; $model_gold->money = $r_money; $model_gold->uid = $code_source['id']; $model_gold->created_at = strtotime("now"); $model_gold->save(); } } elseif ($_POST['SignupForm']['invitation_code']) { $code_source = UcenterMember::find()->where(['invitation_code' => $_POST["SignupForm"]["invitation_code"]])->asArray()->one(); if ($code_source) { $newModel->invitation_id = $code_source['id']; } //好友注册领取体验金 $rule = Rule::find()->where(['title' => '好友注册', 'status' => Rule::STATUS_ACTIVE])->one(); if ($rule) { $rid = $rule->id; $r_money = $rule->money; $model_gold = new Gold(); $model_gold->rid = $rid; $model_gold->money = $r_money; $model_gold->uid = $code_source['id']; $model_gold->created_at = strtotime("now"); $model_gold->save(); } } $newModel->save(false); $model_asset_info = new Info(); $model_asset_info->member_id = yii::$app->user->id; $model_asset_info->create_at = strtotime("now"); $model_asset_info->save(false); //手机号注册领取体验金 $rule = Rule::find()->where(['title' => '手机号注册', 'status' => Rule::STATUS_ACTIVE])->one(); if ($rule) { $rid = $rule->id; $r_money = $rule->money; $model_gold = new Gold(); $model_gold->rid = $rid; $model_gold->money = $r_money; $model_gold->uid = $code_source['id']; $model_gold->created_at = strtotime("now"); $model_gold->save(); } return $this->goHome(); } } } } return $this->render('signup', compact("model", "code")); }
public function actionSetting() { if (\yii::$app->user->isGuest) { $this->redirect(['site/login']); } $uid = yii::$app->user->id; $is_Authentic = member::isAuthentic($uid); $model = UcenterMember::find()->where("id=" . $uid)->one(); if (isset($_POST['prepassword']) && isset($_POST['newpassword']) && isset($_POST['repeatpassword'])) { $_model = UcenterMember::findIdentity($uid); if (!yii::$app->security->validatePassword($_POST['prepassword'], $_model->password_hash)) { echo '原始密码错误'; exit; } elseif ($_POST['newpassword'] == $_POST['repeatpassword']) { $_model->password_hash = Yii::$app->security->generatePasswordHash($_POST['newpassword']); $app_pwd = md5(sha1($_POST['newpassword']) . time()); $_model->app_pwd = $app_pwd; $_model->save(false); echo '密码修改成功'; exit; } else { echo '两次密码不一致'; exit; } } if (isset($_POST['realname']) && isset($_POST['idcard'])) { $realname = $_POST['realname']; $idcard = $_POST['idcard']; try { $idcard_result = Port::baiduIdentity($idcard); if (!$idcard) { echo '身份认号不匹配,请核对后重新输入'; exit; } } catch (ErrorException $e) { echo '认证失败'; exit; } try { $result = member::authentication($uid, $realname, $idcard); if ($result) { echo '身份认证成功'; exit; } } catch (ErrorException $e) { echo $e->getMessage(); exit; } } if (isset($_POST['UcenterMember']['person_face'])) { $model->person_face = UploadedFile::getInstance($model, 'person_face'); if ($model->person_face) { if ($model->validate()) { $old_face = UcenterMember::findOne(['id' => $uid])->person_face; //旧头像 $init_face = Setting::findOne(['code' => 'img'])->value; //初始头像 $Name = mt_rand(1100, 9900) . time() . '.' . $model->person_face->extension; $model->person_face->saveAs('upload/' . $Name); //保存头像名到数据表 $model->person_face = $Name; if ($model->update()) { //若不是初始头像,删除旧头像。 if ($old_face != $init_face) { @unlink('../web/upload/' . $old_face); } header("Content-type: text/html; charset=utf-8"); echo '<script>alert("头像修改完成~");</script>'; } } } } $infos_rar = $this->Ucenter(); //用户数据包 return $this->render('setting', compact("infos_rar", "model", "model_password", "is_Authentic")); }
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 "成功"; }
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use common\models\setting\Setting; use common\models\base\activity\Card; use yii\helpers\Url; use kartik\file\FileInput; $this->title = Yii::t('app', 'Setting'); $this->params['breadcrumbs'][] = $this->title; $items = []; foreach ($settingParent as $parent) { $item['label'] = Yii::t('app', $parent->code); $str = ''; $children = Setting::find()->where(['parent_id' => $parent->id])->orderBy(['sort_order' => SORT_ASC, 'id' => SORT_ASC])->all(); foreach ($children as $child) { $str .= '<div class="form-group field-blogcatalog-parent_id"><label class="col-lg-2 control-label" for="blogcatalog-parent_id">' . Yii::t('app', $child->code) . '</label><div class="col-lg-3">'; if ($child->type == 'text') { $str .= Html::textInput("Setting[{$child->code}]", $child->value, ["class" => "form-control"]); } elseif ($child->type == 'password') { $str .= Html::passwordInput("Setting[{$child->code}]", $child->value, ["class" => "form-control"]); } elseif ($child->type == 'select') { $options = []; $arrayOptions = explode(',', $child->store_range); foreach ($arrayOptions as $option) { $options[$option] = Yii::t('app', $option); } $str .= Html::dropDownList("Setting[{$child->code}]", $child->value, $options, ["class" => "form-control"]); } elseif ($child->type == 'checkrate') { $str .= Html::dropDownList("Setting[{$child->code}]", $child->value, ArrayHelper::map(Card::find()->asArray()->all(), 'id', 'title'), ["class" => "form-control"]);