Exemple #1
0
 public function handle_request_internal()
 {
     $mobile = $this->_params['mobile'];
     $brokerInfo = Model_Broker_AjkBrokerExtend::data_access()->filter('userMobile', $mobile)->find_only();
     if (!$brokerInfo) {
         return API_Result::create()->error()->errorCode('9999')->message('经纪人不存在')->toArray();
     }
     $userId = $brokerInfo->userId;
     $userAccountId = Bll_Fyk_Payment_User::getInstance()->getUserAccountId($userId);
     if (empty($userAccountId)) {
         return API_Result::create()->error()->message('没有用户支付中心ID')->toArray();
     }
     $time = date('Y-m-d H:i:s');
     $data['userId'] = $brokerInfo->userId;
     $data['brokerId'] = $brokerInfo->brokerId;
     $data['cityId'] = $brokerInfo->cityId;
     $data['createTime'] = $time;
     $insertUserId = Model_Fyk_Users::getInstance()->insertData($data);
     unset($data);
     if ($insertUserId) {
         do {
             $code = rand(100000, 999999);
             $arr = Model_Fyk_InvitationCodes::data_access()->load_field('id')->filter('code', $code)->get_row();
         } while ($arr !== NULL);
         $data['code'] = $code;
         //生成邀请码
         $data['bindTo'] = $userId;
         $data['createTime'] = $time;
         $insertInvitationCodeId = Model_Fyk_InvitationCodes::getInstance()->insertData($data);
         if ($insertInvitationCodeId) {
             return API_Result::create()->ok()->data(array('status' => 1))->toArray();
         }
     }
 }
Exemple #2
0
 /**
  * 获取数据
  * @param $id
  * @param $status
  * @param string $orderby
  * @param string $sort
  * @param int $offSet
  * @param int $pageSize
  * @return array
  */
 public function getDataByBiggerThanId($id, $status, $orderby = 'id', $sort = 'asc', $offSet = 0, $pageSize = 100)
 {
     return Model_Fyk_Users::getInstance()->getDataByBiggerThanId($id, $status, $orderby, $sort, $offSet, $pageSize);
 }
 public function handle_request_internal()
 {
     $userId = $this->_params['userId'];
     $brokerId = $this->_params['brokerId'];
     $cityId = $this->_params['cityId'];
     // TODO 校验用户是否存在
     $brokerInfo = Model_Broker_AjkBrokerExtend::data_access()->filter('userId', $userId)->find_only();
     if (!$brokerInfo) {
         throw new Exception_BrokerNotFoundException('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS);
     }
     //查询用户是否存在fyk_users表
     $userInfo = Bll_Fyk_User_User::getInstance()->getUsersByUserId($userId);
     if (empty($userInfo)) {
         //不存在则插入
         $data = array('userId' => $userId, 'brokerId' => $brokerId, 'cityId' => $cityId, 'status' => Model_Fyk_Users::INIT, 'openDate' => 0, 'activeTime' => 0, 'createTime' => date('Y-m-d h:i;s', time()));
         do {
             $tableId = Model_Fyk_Users::getInstance()->insertData($data);
         } while (empty($tableId));
     } else {
         //判断用户是否未激活
         $isInIt = $this->_isUserInIt($userInfo);
         if ($isInIt === false) {
             //该用户已激活,返回错误信息
             return array('status' => 'error', 'errcode' => Const_APIStatus::E_FYK_USER_ALREADY_ACTIVATE, 'message' => '该用户已报名');
         }
     }
     $result = array();
     $result['hasActivity'] = 1;
     $result['isStart'] = 1;
     $result['canActivate'] = 1;
     $result['activateMessage'] = '立即激活';
     if (Const_Fyk::ACTIVATE_START_HOUR < 12) {
         $result['startMessage'] = '每天' . '早上' . Const_Fyk::ACTIVATE_START_HOUR . '点开抢';
     } else {
         $result['startMessage'] = '每天' . '下午' . Const_Fyk::ACTIVATE_START_HOUR . '点开抢';
     }
     //获取当先正在进行的活动配置信息
     $onActivateConfig = Bll_Fyk_User_User::getInstance()->getOnActivateConfig($cityId);
     if (empty($onActivateConfig)) {
         //如果没有正在进行的活动,则查询最近且最新的一条将要进行的活动
         $result['isStart'] = 0;
         $result['canActivate'] = 0;
         $result['activateNumMessage'] = '';
         $result['activateMessage'] = '暂未开启';
         $nearActivateConfig = Bll_Fyk_User_User::getInstance()->getNearActivateConfig($cityId);
         if (empty($nearActivateConfig)) {
             //如果近期都没有活动,则返回固定文案
             $result['hasActivity'] = 0;
             $result['activateMessage'] = '本期活动已结束';
             $result['startMessage'] = '';
             $result['dateMessage'] = '下期具体开放时间会另行通知!';
             return array('status' => 'ok', 'data' => $result);
         }
         $result['dateMessage'] = $this->_assembleDate($nearActivateConfig['startDate'], $nearActivateConfig['endDate']);
         return array('status' => 'ok', 'data' => $result);
     }
     $result['dateMessage'] = $this->_assembleDate($onActivateConfig['startDate'], $onActivateConfig['endDate']);
     $nowHour = intval(date('H', time()));
     if ($nowHour < Const_Fyk::ACTIVATE_START_HOUR) {
         //当天有活动,但活动没开始
         $result['isStart'] = 0;
         $result['canActivate'] = 0;
         $result['activateNumMessage'] = '';
         $result['activateMessage'] = '暂未开启';
         return array('status' => 'ok', 'data' => $result);
     }
     //当天有活动且活动开始
     $today = intval(date('Ymd', time()));
     $activateInfo = Bll_Fyk_User_User::getInstance()->getActivateInfoByCityIdAndDate($cityId, $today);
     $activateNum = intval($activateInfo['activateNum']);
     $dayNum = intval($onActivateConfig['dayNum']);
     $num = $dayNum - $activateNum;
     $num = $num > 0 ? $num : 0;
     $result['activateNumMessage'] = '今日剩余名额: ' . $num;
     if ($activateNum >= $dayNum) {
         //本日报名人数达到上限
         $result['canActivate'] = 0;
         $result['activateMessage'] = '今日已抢完';
         return array('status' => 'ok', 'data' => $result);
     }
     return array('status' => 'ok', 'data' => $result);
 }