/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = HoldActivity::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'activity_begin' => $this->activity_begin, 'activity_end' => $this->activity_end, 'gold_money' => $this->gold_money, 'activity_rate' => $this->activity_rate, 'gold_day' => $this->gold_day, 'red_bothway' => $this->red_bothway, 'status' => $this->status, 'create_at' => $this->create_at, 'update_at' => $this->update_at]); $query->andFilterWhere(['like', 'activity_name', $this->activity_name])->andFilterWhere(['like', 'red_money_rang', $this->red_money_rang]); return $dataProvider; }
/** * Finds the HoldActivity model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return HoldActivity the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = HoldActivity::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function goldtwo($member_id, $money) { //获取举办活动 $holdactivity = HoldActivity::find()->where(['id' => 7])->asArray()->one(); //获取使用的规则 $ridearray = array(); $ridearray = explode(',', $holdactivity['rid_list']); //获取应该得到的体验金数量 $experience_gold = 0; $experience_gold = $holdactivity['gold_money']; //体验金的有效时间 $gold_day = 0; $gold_day = $holdactivity['gold_day']; //活动开始时间 $activity_begin = time(); $activity_begin = $holdactivity['activity_begin']; //活动结束时间 $activity_end = time(); $activity_end = $holdactivity['activity_end']; //首次投资送体验金规则 if (in_array('3', $ridearray)) { //获取规则情况 $flag = Rule::find()->where(['id' => '3', 'status' => Rule::STATUS_ACTIVE])->asArray()->one(); //存在规则 if ($flag) { $info = Info::find()->where(['member_id' => $member_id])->one(); //获取再投资金 $invest = $info->invest; //用户注册时间 $create_at = $info->create_at; //再投资金大于1元 if ($invest >= 1 && $create_at > $activity_begin && $create_at < $activity_end) { //判断规则是否生效 $now = time(); if ($now > $activity_begin && $now < $activity_end) { //判定用户是否领取了体验金 $is_get = Gold::find()->where(['rid' => 3, 'uid' => $member_id, 'title' => '国庆佳节新用户投资送体验金'])->asArray()->one(); if (!$is_get) { //计算体验金截止时间 $end_at = time() + $gold_day * 24 * 3600; //给用户发体验金 $gold = new Gold(); $gold->uid = $member_id; $gold->rid = '3'; $gold->money = $experience_gold; $gold->end_at = $end_at; $gold->status = Gold::STATUS_ACTIVE; $gold->title = '国庆佳节新用户投资送体验金'; $gold->save(); } } //判断是否有邀请人 $member = UcenterMember::find()->where(['id' => $member_id])->asArray()->one(); if ($member['invitation_id']) { if (in_array('5', $ridearray)) { $rule = Rule::find()->where(['id' => '5', 'status' => Rule::STATUS_ACTIVE])->asArray()->one(); //规则启用 if ($rule) { //判断规则是否在时间内 $now = time(); if ($now > $activity_begin && $now < $activity_end) { //判定用户是否领取了体验金 $is_get = Gold::find()->where(['rid' => 3, 'uid' => $member_id, 'title' => '国庆佳节推荐用户投资送体验金'])->asArray()->one(); if (!$is_get) { //计算体验金截止时间 $end_at = time() + $gold_day * 24 * 3600; //给用户发体验金 $gold = new Gold(); $gold->uid = $member_id; $gold->rid = '3'; $gold->money = $experience_gold; $gold->end_at = $end_at; $gold->status = Gold::STATUS_ACTIVE; $gold->title = '国庆佳节推荐用户投资送体验金'; $gold->save(); } } } } } } } } }
/** * 用户分享生成红包奖励表 * @param $invite_phone 分享者手机号 * @param $sum_count 生成红包的数量 * @param $actibity_source 红包对应的活动 * @return array */ public static function create_read_packet($invite_phone, $sum_count, $actibity_source) { //获取用户id $invite_id = self::phoneIsRegister($invite_phone); if (!$invite_id) { $return = array('errorNum' => '1', 'errorMsg' => '邀请用户不存在', 'data' => null); return $return; } //判定是否有必要进行生成 ---已经生成 //$count = ActivityLog::find()->where(['status' => ActivityLog::STATUS_ACTIVITY,'invite_phone' => $invite_phone])->andWhere(['>','end_at',time()])->count(); // $count = ActivityLog::find()->where(['invite_phone' => $invite_phone])->one(); //计算当前活动产生的红包数目 $flag = ActivityLog::find()->where(['invite_phone' => $invite_phone, 'actibity_source' => $actibity_source])->count(); if ($flag == 0) { // 设定活动时间--以天计算 $continue_time = 100; //处理分配金额--设置奖励规则 // $prize_arr = array( // '0' => array('id'=>1,'prize'=>'5','v'=>1), // '1' => array('id'=>2,'prize'=>'4.5','v'=>5), // '2' => array('id'=>3,'prize'=>'4','v'=>10), // '3' => array('id'=>4,'prize'=>'3.5','v'=>20), // '4' => array('id'=>5,'prize'=>'3','v'=>30), // '5' => array('id'=>6,'prize'=>'2.5','v'=>40), // '6' => array('id'=>7,'prize'=>'2','v'=>50), // '7' => array('id'=>8,'prize'=>'1.5','v'=>60), // '8' => array('id'=>9,'prize'=>'1','v'=>70), // '9' => array('id'=>10,'prize'=>'0.5','v'=>100), // ); //活动设置奖项--- //读取奖项设定 $prize = array(); $holdactivity = HoldActivity::find()->where(['id' => 7])->asArray()->one(); $radearray = explode('/', $holdactivity['red_money_rang']); if (count($radearray)) { foreach ($radearray as $key => $value) { $v1 = explode(',', $value); if (count($v1)) { $v2 = explode('-', $v1['0']); $money = round(rand($v2['0'] * 1000, $v2['1'] * 1000) / 10) / 100; $prize[$key] = array('id' => $key + 1, 'prize' => $money, 'v' => $v1['1']); } } } //判定红包是否是双向红包 $red_bothway = $holdactivity['red_bothway']; /////////////////////////////////////// foreach ($prize as $key => $val) { $arr[$val['id']] = $val['v']; } //数据处理记录 $sum_count = $sum_count ? $sum_count : 1; for ($i = 1; $i <= $sum_count; $i++) { //概率取出奖励红包 $rid = self::get_rand($arr); $red_packet = $prize[$rid - 1]['prize']; //记录数据 $log = new ActivityLog(); $log->invite_id = $invite_id; $log->invite_phone = $invite_phone; $log->red_packet = $red_packet; $log->status = ActivityLog::STATUS_ACTIVITY; $log->end_at = time() + $continue_time * 24 * 3600; $log->type = (int) $red_bothway; $log->actibity_source = $actibity_source; $log->inviter_draw = ActivityLog::STATUS_INVITER_DRAW_SUCC; $log->invitee_draw = ActivityLog::STATUS_INVITEE_DRAW_SUCC; $log->save(); } } }