Exemplo n.º 1
0
 /**
  * 创建一个会员卡
  * 每个账号只有一个会员卡
  * 所以若没有则创建一个,若有则直接返回
  *
  */
 public function get($mpid)
 {
     $q = array('*', 'xxt_member_card', "mpid='{$mpid}'");
     if (!($card = parent::query_obj_ss($q))) {
         parent::insert('xxt_member_card', array('mpid' => $mpid), false);
         $card = parent::query_obj_ss($q);
     }
     return $card;
 }
Exemplo n.º 2
0
 /**
  * 参加活动赚取积分
  *
  * $mpid
  * $mid member's id
  *
  * return $gain array(credits,times)
  * 积分(credits):增量,总数
  * 次数(times):累计参加的次数
  * 是否继续开放(open):每个人每天只能参加一次
  */
 public function participate($mpid, $mid)
 {
     /**
      * 获得上一次签到记录
      */
     $q = array('checkin_at,times_accumulated', 'xxt_checkin_log', "mid='{$mid}' and last=1");
     $last = parent::query_obj_ss($q);
     /**
      *
      */
     if (!$this->isOpen($mpid, $mid, $last)) {
         return false;
     }
     /**
      * 签到记录表,记录用户的每一次签到行为
      * 每一次签到行为上记录,已经累计签到的次数和是否为最后一次的标识
      *
      * 获得最近一次签到时间
      * 判断是否超过了1填,如果超过,重新计算有效累计次数
      */
     if (!$last) {
         $times_accumulated = 0;
     } else {
         /**
          * 检查是否属于连续签到
          */
         if ($this->isBreak($last)) {
             $times_accumulated = 0;
         } else {
             $times_accumulated = (int) $last->times_accumulated;
         }
         if (!parent::update('xxt_checkin_log', array('last' => 0), "mid='{$mid}' and last=1")) {
             die('unknown exception.');
         }
     }
     $new_credits = $this->earnCredits($times_accumulated + 1);
     /**
      * insert new one
      */
     $newone['mid'] = $mid;
     $newone['mpid'] = $mpid;
     $newone['checkin_at'] = time();
     $newone['times_accumulated'] = $times_accumulated + 1;
     $newone['last'] = 1;
     parent::insert('xxt_checkin_log', $newone, false);
     /**
      * get current credits
      */
     $q = array('credits', 'xxt_member', "mid='{$mid}'");
     $existing_credits = (int) parent::query_val_ss($q);
     $all_credits = $existing_credits + $new_credits;
     parent::update('xxt_member', array('credits' => $all_credits), "mid='{$mid}'");
     /**
      * return
      */
     $gain = array();
     $gain['credits_new'] = $new_credits;
     $gain['times_accumulated'] = $times_accumulated + 1;
     $gain['credits_all'] = $all_credits;
     $level = $this->calcLevel($all_credits);
     $gain['level'] = $level[0];
     $gain['level_title'] = $level[1];
     $gain['open'] = 0;
     return $gain;
 }