/** * Creates a new SignIn model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new SignIn(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * 用户签到 * @param $uid * @param $from * @return array */ public static function signIn($uid, $from) { //正式上线再定 $info = Info::findOne(['member_id' => $uid]); if (!$info) { $return = array('errorNum' => '1', 'errorMsg' => "用户不存在", 'data' => null); return $return; } //获取在投资金 $invest = $info->invest; // if ($invest < 1000) { $return = array('errorNum' => '1', 'errorMsg' => "在投金额大于1000的用户才能签到", 'data' => null); return $return; } //获取最新签到记录 $get_sign = SignIn::find()->where(['uid' => $uid])->orderBy('sign_in_time DESC')->one(); if ($get_sign) { $sign_time = $get_sign->sign_in_time; //今日零时时间 $zero_time = strtotime(date("Y-m-d")); //明日零时时间 // $tom_zero_time = $zero_time + 86400; if ($sign_time < $zero_time) { //最后一次签到时间小于当日零时--可以签到 $log = new SignIn(); $log->uid = $uid; $log->sign_in_time = time(); $log->sign_in_money = 0; $log->sign_in_ip = Yii::$app->request->userIp; $log->sign_in_from = $from; $log->status = SignIn::STATUS_ACTIVE; if ($log->save()) { $result = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null); return $result; } else { $result = array('errorNum' => '1', 'errorMsg' => '签到失败', 'data' => null); return $result; } } else { $result = array('errorNum' => '1', 'errorMsg' => '已经签到', 'data' => null); return $result; } } else { //直接签到 $log = new SignIn(); $log->uid = $uid; $log->sign_in_time = time(); $log->sign_in_money = 0; $log->sign_in_ip = Yii::$app->request->userIp; $log->sign_in_from = $from; $log->status = SignIn::STATUS_ACTIVE; if ($log->save()) { $result = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null); return $result; } else { $result = array('errorNum' => '1', 'errorMsg' => '签到失败', 'data' => null); return $result; } } }