/**
  * 保存一条记录,注意:此处会对应增加或减少用户的云豆数!!
  * @param $userId
  * @param $bitcoin
  * @param $usageModeId
  * @param $type
  * @param $fromUserId
  * @throws Exception
  * @throws \Exception
  */
 public static function saveRecord($userId, $bitcoin, $usageModeId, $type, $fromUserId = null)
 {
     $record = new IncomeConsume();
     $record->userId = $userId;
     $record->bitcoin = $bitcoin;
     $record->usageModeId = $usageModeId;
     $record->type = $type;
     $record->fromUserId = $fromUserId;
     $record->createDate = DateFunctions::getCurrentDate();
     if (!$record->save()) {
         throw new Exception("IncomeConsume save error");
     }
     $user = Users::findOne($userId);
     if ($type == IncomeConsume::TYPE_INCOME) {
         $user->bitcoin += $bitcoin;
     } elseif ($type == IncomeConsume::TYPE_CONSUME) {
         if ($user->bitcoin < $bitcoin) {
             throw new Exception("IncomeConsume user bitcoin less than need error");
         } else {
             $user->bitcoin -= $bitcoin;
         }
     }
     if (!$user->save()) {
         throw new Exception("IncomeConsume user update error");
     }
 }
Example #2
0
 public function register()
 {
     if ($this->provinceId == "" || $this->majorJobId == "") {
         CommonFunctions::createAlertMessage("省份或者专业类型不能为空", "error");
         return false;
     }
     $majorJob = MajorJob::findOne($this->majorJobId);
     if ($this->provinceId != $majorJob['provinceId']) {
         CommonFunctions::createAlertMessage("专业类型与所处省份不一致,请重新选择", "error");
         return false;
     }
     $openId = Yii::$app->session->get('openId');
     $user = Users::findByWeiXin($openId);
     if (!$user) {
         //如果用户不存在,即关注的时候没有把微信的相关信息存入
         $user = new Users();
         $user->weixin = $openId;
     }
     if (!$user->registerDate || $user->registerDate == 0) {
         //如果用户注册日期不存在或为0,表明用户第一次实名认证
         $user->bitcoin = 0;
         $user->registerDate = DateFunctions::getCurrentDate();
         $user->role = Users::ROLE_A;
         $user->state = Users::STATE_NORMAL;
         do {
             //保证生成的推荐码的唯一
             $recommendCode = CommonFunctions::createCommonRecommendCode();
         } while (Users::findUserByRecommendCode($recommendCode));
         $user->recommendCode = $recommendCode;
         if ($this->tjm) {
             //推荐码绑定推荐人
             $this->recommendUser = Users::findUserByRecommendCode($this->tjm);
             if ($this->recommendUser) {
                 if ($this->recommendUser['userId'] != $user['userId']) {
                     //推荐人不是自己
                     $user->recommendUserID = $this->recommendUser['userId'];
                 }
             }
         }
     }
     $user->nickname = $this->nickname;
     $user->realname = $this->realname;
     $user->provinceId = $this->provinceId;
     $user->majorJobId = $this->majorJobId;
     $user->cellphone = $this->cellphone;
     $user->company = $this->company;
     $user->address = $this->address;
     if (!$user->save()) {
         throw new Exception("RegisterForm register Save Error");
     }
     Yii::$app->cache->delete($user->cellphone);
     //注册成功后将验证码缓存清除
     Yii::$app->session->set('user', $user);
     return true;
 }
 /**
  * 记录支付记录
  * @param $userId
  * @param $scheme \common\models\Scheme
  * @throws Exception
  */
 public static function saveRecord($userId, $scheme)
 {
     $record = new PracticeRecord();
     $record->userId = $userId;
     $record->bitcoin = $scheme['payBitcoin'];
     $record->startDate = DateFunctions::getCurrentDate();
     $record->endDate = date('y-m-d H:i:s', strtotime('+' . $scheme['hour'] . ' hour'));
     if (!$record->save()) {
         throw new Exception("PracticeRecord save error");
     }
 }
Example #4
0
 /**
  * 记录模拟考试信息
  * @param $finalScore
  * @param $totalScore
  */
 public static function recordOne($finalScore, $totalScore)
 {
     $user = Yii::$app->session->get('user');
     $record = new ExamScore();
     $record->userId = $user['userId'];
     $record->provinceId = $user['provinceId'];
     $record->majorJobId = $user['majorJobId'];
     $record->score = $finalScore;
     $record->totalScore = $totalScore;
     $record->createDate = DateFunctions::getCurrentDate();
     $record->save();
 }
Example #5
0
 public function record()
 {
     $user = Yii::$app->session->get('user');
     $service = new Service();
     $service->userId = $user['userId'];
     $service->content = $this->content;
     $service->state = Service::STATE_UNREPLY;
     $service->createDate = DateFunctions::getCurrentDate();
     if (!$service->save()) {
         throw new Exception("ConsultForm save error");
     }
 }
 public function updateInvoice($state)
 {
     $user = Yii::$app->session->get('user');
     $invoice = Invoice::findOne($this->invoiceId);
     /** @var $invoice \common\models\Invoice */
     $invoice->state = $state;
     $invoice->replyContent = $this->replyContent;
     $invoice->replyDate = DateFunctions::getCurrentDate();
     $invoice->replyUserId = $user['userId'];
     if (!$invoice->save()) {
         throw new Exception("invoice update error");
     }
 }
 public function update()
 {
     /** @var $testLibrary \common\models\TestLibrary */
     $testLibrary = TestLibrary::findOne($this->testLibraryId);
     $testLibrary->problem = $this->problem;
     $testLibrary->question = $this->question;
     $testLibrary->options = $this->options;
     $testLibrary->answer = $this->answer;
     $testLibrary->createDate = DateFunctions::getCurrentDate();
     $user = \Yii::$app->session->get('user');
     $testLibrary->createUserId = $user['userId'];
     if (!$testLibrary->update()) {
         throw new Exception("UpdateTestLibraryForm update error");
     }
 }
Example #8
0
 /**
  * 保存或删除一个收藏
  * @param $userId
  * @param $testLibraryId
  * @return string
  * @throws Exception
  * @throws \Exception
  */
 public static function saveOrDelete($userId, $testLibraryId)
 {
     $collection = Collection::find()->where(['userId' => $userId, 'testLibraryId' => $testLibraryId])->one();
     if ($collection) {
         if (!$collection->delete()) {
             throw new Exception("Collection delete error");
         }
         return "delete";
     } else {
         $collection = new Collection();
         $collection->userId = $userId;
         $collection->testLibraryId = $testLibraryId;
         $collection->createDate = DateFunctions::getCurrentDate();
         if (!$collection->save()) {
             throw new Exception("Collection save error");
         }
         return "collected";
     }
 }
 public function record()
 {
     $user = Yii::$app->session->get('user');
     $invoice = Invoice::findApplyingByUser($user['userId']);
     if ($invoice) {
         return false;
     }
     $invoice = new Invoice();
     $user = Yii::$app->session->get('user');
     $invoice->userId = $user['userId'];
     $invoice->money = $this->money;
     $invoice->address = $user['address'];
     $invoice->createDate = DateFunctions::getCurrentDate();
     $invoice->state = Invoice::STATE_ING;
     $invoice->address = $this->address;
     if (!$invoice->save()) {
         throw new Exception("Invoice save error");
     }
     return true;
 }
 public function record()
 {
     $user = Yii::$app->session->get('user');
     $model = Withdraw::find()->where(['userId' => $user['userId'], 'state' => Withdraw::STATE_APPLYING])->one();
     if ($model) {
         return false;
     }
     $withdraw = new Withdraw();
     $withdraw->userId = $user['userId'];
     $withdraw->money = $this->money;
     $withdraw->bitcoin = ceil(Scheme::calculateWithdrawBitcoin($user, $this->money));
     //扣除云豆数为向上取整,有小数就整数部分加1
     $withdraw->invoiceMoney = $this->invoiceMoney;
     $withdraw->invoiceNo = $this->invoiceNo;
     $withdraw->createDate = DateFunctions::getCurrentDate();
     $withdraw->state = Withdraw::STATE_APPLYING;
     if (!$withdraw->save()) {
         throw new Exception("Withdraw save error");
     }
     return true;
 }
 public function record()
 {
     $user = Yii::$app->session->get('user');
     $invoice = Invoice::findApplyingByUser($user['userId']);
     if ($invoice) {
         CommonFunctions::createAlertMessage("发票申请失败,您已经有正在申请中的发票了,一次只能申请一张", "error");
         return false;
     } else {
         $invoice = new Invoice();
         $invoice->userId = $user['userId'];
         $invoice->address = $this->address;
         $invoice->money = $this->money;
         $invoice->description = $this->description;
         $invoice->createDate = DateFunctions::getCurrentDate();
         $invoice->state = Invoice::STATE_ING;
         if (!$invoice->save()) {
             throw new Exception("Apply Invoice save error");
         }
         return true;
     }
 }
Example #12
0
 public static function saveOrUpdate($userId, $testLibraryId)
 {
     //查询用户是否有错误记录,有则更新记录时间,无则插入
     $errorQuestion = self::findByUserAndTestLibraryId($userId, $testLibraryId);
     if ($errorQuestion) {
         $errorQuestion->createDate = DateFunctions::getCurrentDate();
         if ($errorQuestion->update()) {
             return true;
         } else {
             throw new Exception('ErrorQuestion update wrong');
         }
     } else {
         $errorQuestion = new ErrorQuestion();
         $errorQuestion->userId = $userId;
         $errorQuestion->testLibraryId = $testLibraryId;
         $errorQuestion->createDate = DateFunctions::getCurrentDate();
         if ($errorQuestion->save()) {
             return true;
         } else {
             throw new Exception('ErrorQuestion save wrong');
         }
     }
 }
Example #13
0
 /**
  * 回复咨询
  * @param $serviceId
  * @param $reply
  * @param bool|false $publish
  * @throws Exception
  * @throws \Exception
  */
 public static function replyService($serviceId, $reply, $publish = false)
 {
     $user = Yii::$app->session->get('user');
     if (!$user) {
         throw new Exception("Service replyService session user not exist!");
     }
     $service = Service::findOne($serviceId);
     if ($publish) {
         $service->state = Service::STATE_PUBLISH;
     } else {
         $service->state = Service::STATE_REPLIED;
     }
     $service->reply = $reply;
     $service->replyUserId = $user['userId'];
     $service->replyDate = DateFunctions::getCurrentDate();
     if (!$service->update()) {
         throw new Exception("Service replyService update error!");
     }
 }
Example #14
0
 /**
  * 针对大客户充值,大客户充值自己没有返点
  * 记录用户的充值,包含返点、用户余额的改变和云豆收入支出记录的记录
  * @param $user
  * @param $money
  * @param $bitcoin
  * @param $from
  * @param null $operateUserId
  * @param null $agreement
  * @throws Exception
  */
 public static function recordOneForBig($user, $money, $bitcoin, $from, $operateUserId = null, $agreement = null)
 {
     $moneyModel = new Money();
     $moneyModel->userId = $user['userId'];
     $moneyModel->money = $money;
     $moneyModel->type = Money::TYPE_PAY;
     $moneyModel->bitcoin = $bitcoin;
     $moneyModel->createDate = DateFunctions::getCurrentDate();
     $moneyModel->from = $from;
     $moneyModel->operateUserId = $operateUserId;
     $moneyModel->agreement = $agreement;
     if (!$moneyModel->save()) {
         throw new Exception("money save error");
     }
     //云豆收入支出记录+用户余额改变
     IncomeConsume::saveRecord($user['userId'], $bitcoin, UsageMode::USAGE_PAY, IncomeConsume::TYPE_INCOME, $operateUserId);
     $recommendUser = Users::findRecommendUser($user['recommendUserID']);
     if ($recommendUser) {
         //存在推荐用户
         $rebateScheme = Scheme::findRebateScheme(Users::ROLE_BIG);
         if ($rebateScheme && $money >= $rebateScheme['payMoney']) {
             //存在返点方案,并且达到当前返点的起始要求
             $proportion = Yii::$app->params['proportion'];
             $addBitcoin = $money * $proportion * $rebateScheme['rebate'];
             //返点云豆,返给推荐人
             IncomeConsume::saveRecord($recommendUser['userId'], $addBitcoin, UsageMode::USAGE_REBATE_BIG, IncomeConsume::TYPE_INCOME, $user['userId']);
         }
     }
 }
Example #15
0
 /**
  * 查询所有可使用的线练习支付方案,缓存1分钟
  * @return array|null|\yii\db\ActiveRecord
  */
 public static function findPracticeScheme()
 {
     $scheme = Yii::$app->cache->get('practiceScheme');
     if (!$scheme) {
         $currentDate = DateFunctions::getCurrentDate();
         $scheme = (new Query())->from(Scheme::tableName())->where('usageModeId=:usageModeId and state=:state and (startDate is null or (startDate<=:currentDate and endDate>=:currentDate))', [':usageModeId' => Scheme::USAGE_PRACTICE, ':state' => Scheme::STATE_ABLE, ':currentDate' => $currentDate])->orderBy(['payBitcoin' => SORT_ASC])->all();
         Yii::$app->cache->set('practiceScheme', $scheme, 60);
     }
     return $scheme;
 }
Example #16
0
 public static function saveOne($provinceId, $majorJobId, $name, $createUserId)
 {
     $examTemplate = new ExamTemplate();
     $examTemplate->name = $name;
     $examTemplate->provinceId = $provinceId;
     $examTemplate->majorJobId = $majorJobId;
     $examTemplate->createUserId = $createUserId;
     $examTemplate->pa1 = "0|0";
     $examTemplate->pa2 = "0|0";
     $examTemplate->pa3 = "0|0";
     $examTemplate->pa4 = "0|0";
     $examTemplate->pb1 = "0|0";
     $examTemplate->pb2 = "0|0";
     $examTemplate->pb3 = "0|0";
     $examTemplate->pb4 = "0|0";
     $examTemplate->createDate = DateFunctions::getCurrentDate();
     $examTemplate->state = ExamTemplate::STATE_DISABLE;
     if (!$examTemplate->save()) {
         throw new Exception("模拟试卷模板保存错误");
     }
     return $examTemplate->examTemplateId;
 }
Example #17
0
    } elseif ($incomeConsume['type'] == IncomeConsume::TYPE_CONSUME) {
        $icon = '-';
    } else {
        $icon = '';
    }
    ?>
                <td><?php 
    echo $icon . $incomeConsume['bitcoin'];
    ?>
</td>
                <td><?php 
    echo $incomeConsume->usageMode['usageModeName'];
    ?>
</td>
                <td><?php 
    echo DateFunctions::getDate($incomeConsume['createDate']);
    ?>
</td>
            </tr>
        <?php 
}
?>
        </tbody>
    </table>
    <nav class="pull-right pagination_footer">
        <?php 
echo \yii\widgets\LinkPager::widget(['pagination' => $pages]);
?>
    </nav>
    <div class="clearfix"></div>
Example #18
0
    <table class="table table-striped text-center no-margin-bottom table-font-small">
        <thead>
        <tr>
            <th class="text-center">申请日期</th>
            <th class="text-center">金额</th>
            <th class="text-center">状态</th>
            <th class="text-center">快递单号</th>
        </tr>
        </thead>
        <tbody>
        <?php 
foreach ($invoices as $i => $invoice) {
    ?>
            <tr>
                <td><?php 
    echo DateFunctions::getDate($invoice['createDate']);
    ?>
</td>
                <td><?php 
    echo $invoice['money'];
    ?>
</td>
                <td><?php 
    echo $invoice->stateName;
    ?>
</td>
                <td><?php 
    echo $invoice->orderNumber;
    ?>
</td>
            </tr>
Example #19
0
 public function recordOne()
 {
     if (!$this->userId) {
         //新添加
         $user = new Users();
         $user->bitcoin = 0;
         $user->password = CommonFunctions::encrypt("123456");
         //初始密码设置为123456
         $user->state = Users::STATE_NORMAL;
         do {
             if ($this->role == Users::ROLE_AA) {
                 $recommendCode = CommonFunctions::create2ARecommendCode();
             } elseif ($this->role == Users::ROLE_AAA) {
                 $recommendCode = CommonFunctions::create3ARecommendCode();
             } elseif ($this->role == Users::ROLE_BIG) {
                 $recommendCode = CommonFunctions::createBigRecommendCode();
             } else {
                 throw new Exception("未知的角色类型");
             }
         } while (Users::findUserByRecommendCode($recommendCode));
         $user->recommendCode = $recommendCode;
         $recommendUser = Users::findUserByRecommendCode($this->recommendCode);
         $user->recommendUserID = $recommendUser['userId'];
         $user->registerDate = DateFunctions::getCurrentDate();
     } else {
         //已存在
         $user = Users::findOne($this->userId);
     }
     $user->role = $this->role;
     $user->departmentId = $this->departmentId;
     $user->username = $this->username;
     $user->nickname = $this->nickname;
     $user->address = $this->address;
     $user->realname = $this->realname;
     $user->cellphone = $this->cellphone;
     $user->email = $this->email;
     $user->qq = $this->qq;
     $user->weixin = $this->weixin;
     if (!$user->save()) {
         throw new Exception("add-user-form user save error");
     } else {
         /** @var $bankCard \common\models\BankCard */
         $bankCard = BankCard::findOne(['userId' => $user->userId]);
         if (!$bankCard) {
             //如果没有
             $bankCard = new BankCard();
             $bankCard->userId = $user->userId;
             $bankCard->state = BankCard::STATE_DEFAULT;
         }
         $bankCard->bankName = $this->bankName;
         $bankCard->cardNumber = $this->cardNumber;
         $bankCard->cardName = $this->cardName;
         $bankCard->save();
     }
 }
Example #20
0
 /**
  * 修改状态,有错误会返回错误
  * @param $infoId
  * @param $state
  * @return bool|string
  */
 public static function changeState($infoId, $state, $replyContent = null)
 {
     $info = Info::findOne($infoId);
     if ($info) {
         $info->state = $state;
         $user = Yii::$app->session->get('user');
         $info->replyUserId = $user['userId'];
         $info->replyDate = DateFunctions::getCurrentDate();
         $info->replyContent = $replyContent;
         $info->save();
         return false;
     } else {
         return "不存在该信息";
     }
 }
Example #21
0
 public function record()
 {
     $user = Yii::$app->session->get('user');
     $info = Info::findRefusedByUserId($user['userId']);
     if (!$info) {
         $info = new Info();
         $info->password = CommonFunctions::createRandPassword();
     }
     $info->userId = $this->userId;
     $info->IDCard = $this->IDCard;
     $info->realName = $this->realName;
     $info->cellphone = $this->cellphone;
     $info->education = $this->education;
     $info->major = $this->major;
     $info->workTime = $this->workTime;
     $info->technical = $this->technical;
     $info->signUpMajor = $this->signUpMajor;
     $info->company = $this->company;
     $info->findPasswordQuestion = $this->findPasswordQuestion;
     $info->findPasswordAnswer = $this->findPasswordAnswer;
     $info->headImg = $this->headImg;
     $info->educationImg = $this->educationImg;
     $info->createDate = DateFunctions::getCurrentDate();
     $info->state = Info::STATE_RECORD;
     if (!$info->save()) {
         throw new Exception("Sign Up Info save error");
     }
 }
Example #22
0
 public static function changeState($invoiceId, $state, $replyContent)
 {
     $user = Yii::$app->session->get('user');
     $invoice = Invoice::findOne($invoiceId);
     $invoice->state = $state;
     $invoice->replyContent = $replyContent;
     $invoice->replyDate = DateFunctions::getCurrentDate();
     $invoice->replyUserId = $user['userId'];
     if (!$invoice->update()) {
         throw new Exception("Invoice update error");
     }
 }