/** * @return bool|string */ public function addGift() { if ($this->validate()) { $gift = new Gift(); $gift->setAttributes($this->getAttributes()); $gift->validation_code = $this->_setValidationCode(); if ($gift->save()) { $gift->sendValidationCode(); return $gift->id; } } else { return $this->getErrors(); } }
/** * Finds the Gift model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Gift the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Gift::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return bool */ public function checkIdentity() { if ($this->validate()) { $gift = Gift::findOne(['id' => intval($this->id)]); if ($this->validation_code == $gift->validation_code) { $gift->success = 1; $gift->save(); return true; } else { $gift->addError('validation_code', 'Код подтверждения неверен'); return $gift->getErrors(); } } else { return $this->getErrors(); } }
/** * @return bool */ public function addPhoneTo() { if ($this->validate()) { $gift = Gift::findOne(['id' => intval($this->id)]); $gift->setAttributes($this->getAttributes()); $gift->sendGiftResult(); if ($gift->success && $gift->send_success) { $gift->save(); return true; } else { $gift->addError('to', 'Информация отправлена в SMS на ваш номер телефона'); return $gift->getErrors(); } } else { return $this->getErrors(); } }
/** * 发布资金活动 * @return boolean */ public function publish() { //生成随机数据 $total = $this->gift_price; //红包总金额 $num = $this->gift_nums; // 分成10个红包,支持10人随机领取 $moneyArray = []; $time = time(); $addip = \Yii::$app->request->userIP; for ($i = 0; $i < $num; $i++) { $money = $this->gift_price; $moneyArray[$i] = [0, $this->activity_id, $this->gift_name, $money, 0, $time, 0, 0, $addip]; } \Yii::$app->db->createCommand()->batchInsert(Gift::tableName(), ['user_id', 'activity_id', 'gift_name', 'gift_price', 'gift_status', 'addtime', 'updatetime', 'fittime', 'addip'], $moneyArray)->execute(); Activity::updateAll(['ac_status' => 1], 'id=' . $this->activity_id); return true; }
/** * 发布资金活动 * @return boolean */ public function publish() { //生成随机数据 $total = $this->gift_price; //红包总金额 $num = $this->gift_nums; // 分成10个红包,支持10人随机领取 $min = $this->gift_min; //每个人最少能收到0.01元 $max = $this->gift_max; $moneyArray = []; $time = time(); $addip = \Yii::$app->request->userIP; for ($i = 1; $i < $num; $i++) { $safe_total = ($total - ($num - $i) * $min) / ($num - $i); //随机安全上限 if ($max < $safe_total) { $safe_total = $max; } $money = mt_rand($min * 100, $safe_total * 100) / 100; $moneyArray[$i] = [0, $this->activity_id, $this->gift_name, $money, 0, $time, 0, 0, $addip]; $total = $total - $money; } $moneyArray[$num] = [0, $this->activity_id, $this->gift_name, $total, 0, $time, 0, 0, $addip]; \Yii::$app->db->createCommand()->batchInsert(Gift::tableName(), ['user_id', 'activity_id', 'gift_name', 'gift_price', 'gift_status', 'addtime', 'updatetime', 'fittime', 'addip'], $moneyArray)->execute(); Activity::updateAll(['ac_status' => 1], 'id=' . $this->activity_id); return true; }