Exemplo n.º 1
0
 /**
  * Creates a new ActivityLog model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new ActivityLog();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 /**
  * 判定用户是否符合推广规则--进行奖励机制--为用户发放红包--在形成红包之后操作
  * 用户满足条件后就进行红包的发放
  * @param $uid
  */
 public static function send_red_packet($uid)
 {
     //判定当前用户是否是符合推广新手的规则
     $money = 3000;
     $days = 30;
     $count = self::get_continue_money($uid, $money, $days);
     if ($count['count'] >= $days) {
         //获取用户手机号
         $info = UcenterMember::find()->where(['id' => $uid])->asArray()->one();
         $invite_phone = $info['phone'];
         //符合规则--可以发放红包了
         //产生的红包--一级推荐关系---》》活动红包列表
         $red_list = UserRecommend::find()->where(['owner_uid' => $uid, 'level' => 1, 'is_grant' => UserRecommend::GRANT_FALSE])->asArray()->all();
         if ($red_list !== null) {
             foreach ($red_list as $key => $value) {
                 $sender_uid = $value['sender_uid'];
                 $phone = $value['sender_phone'];
                 $actibity_source = $value['red_packet_name'];
                 $red_packet = $value['red_packet'];
                 //判定红包表数据库里面是否有数据
                 $flag = ActivityLog::find()->where(['uid' => $sender_uid, 'phone' => $phone, 'invite_id' => $uid, 'actibity_source' => $actibity_source, 'red_packet' => $red_packet])->one();
                 if ($flag == null) {
                     //增加红包记录
                     $log = new ActivityLog();
                     $log->uid = $sender_uid;
                     $log->phone = $phone;
                     $log->red_packet = $red_packet;
                     $log->actibity_source = $actibity_source;
                     $log->invite_id = $uid;
                     $log->invite_phone = $invite_phone;
                     $log->inviter_draw = ActivityLog::STATUS_INVITER_DRAW_SUCC;
                     $log->invitee_draw = ActivityLog::STATUS_INVITEE_DRAW_SUCC;
                     $log->status = ActivityLog::STATUS_SUCCESS;
                     $log->type = ActivityLog::RED_BOTHWAY_TO_INVITER;
                     $log->end_at = time() + 100 * 86400;
                     if ($log->save()) {
                         //更新推荐注册表里的数据
                         UserRecommend::updateAll(['is_grant' => UserRecommend::GRANT_TRUE], ['owner_uid' => $uid, 'level' => 1, 'is_grant' => UserRecommend::GRANT_FALSE, 'red_packet' => $red_packet, 'sender_uid' => $sender_uid]);
                     }
                 }
             }
         }
     }
     //判定用户是否符合’推广大师‘的资格  60天连续投资6000元
     $money = 6000;
     $days = 60;
     $count = self::get_continue_money($uid, $money, $days);
     if ($count['count'] >= $days) {
         //获取用户手机号
         $info = UcenterMember::find()->where(['id' => $uid])->asArray()->one();
         $invite_phone = $info['phone'];
         //符合规则--可以发放红包了
         //产生的红包--二级推荐关系---》》活动红包列表
         $red_list = UserRecommend::find()->where(['owner_uid' => $uid, 'level' => 2, 'is_grant' => UserRecommend::GRANT_FALSE])->asArray()->all();
         if ($red_list !== null) {
             foreach ($red_list as $key => $value) {
                 $sender_uid = $value['sender_uid'];
                 $phone = $value['sender_phone'];
                 $actibity_source = $value['red_packet_name'];
                 $red_packet = $value['red_packet'];
                 //判定红包表中是否已经有数据
                 $flag = ActivityLog::find()->where(['uid' => $sender_uid, 'phone' => $phone, 'invite_id' => $uid, 'actibity_source' => $actibity_source, 'red_packet' => $red_packet])->one();
                 if ($flag == null) {
                     //增加红包记录
                     $log = new ActivityLog();
                     $log->uid = $sender_uid;
                     $log->phone = $phone;
                     $log->red_packet = $red_packet;
                     $log->actibity_source = $actibity_source;
                     $log->invite_id = $uid;
                     $log->invite_phone = $invite_phone;
                     $log->inviter_draw = ActivityLog::STATUS_INVITER_DRAW_SUCC;
                     $log->invitee_draw = ActivityLog::STATUS_INVITEE_DRAW_SUCC;
                     $log->status = ActivityLog::STATUS_SUCCESS;
                     $log->type = ActivityLog::RED_BOTHWAY_TO_INVITER;
                     $log->end_at = time() + 100 * 86400;
                     if ($log->save()) {
                         //更新推荐注册表里的数据
                         UserRecommend::updateAll(['is_grant' => UserRecommend::GRANT_TRUE], ['owner_uid' => $uid, 'level' => 2, 'is_grant' => UserRecommend::GRANT_FALSE, 'red_packet' => $red_packet, 'sender_uid' => $sender_uid]);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * 用户分享生成红包奖励表
  * @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();
         }
     }
 }