/** * 定时app发送通知 */ public function crontabpush() { // 首先获取需要推送的通知 之后根据用户的设备类型 调用不同接口 $this->load->model('user_model'); $this->load->model('score_model'); $this->load->helper('push'); $userlist = $this->user_model->getUserList(['updatetime' => ['$lte', date('Y-m-d H:i:s', time() - INTVALTIMENOTLOGINPUSH)]]); if ($userlist) { foreach ($userlist as $k => $v) { if ($v['device_tokens'] && $v['receivepoints_push']) { // 含有设备TOKEN 并且push开关开启 $userscorelistTotal = $this->score_model->getScoreListTotal(['userid' => $v['id'], 'status' => 0, 'createtime' => ['$gte', date('Y-m-d H:i:s', strtotime('-2 days'))]]); if ($userscorelistTotal) { sendAppPush($v['platform'], $v['device_tokens'], 2, '您有' . $userscorelistTotal . '积分尚未领取'); // push } } } } }
/** * 添加/修改 */ public function ajaxUpdateActivity() { $id = intval(true == isset($_POST['id']) ? $_POST['id'] : 0); $this->load->library('form'); $this->form->setHandler('filter_strip_tags_and_clear_space|filter_replace_escape_char'); $this->load->helper('form/activity'); $this->load->model('activity_model'); $postData = $this->form->check(activityupdateform_get_selector()); $errors = $this->form->getLastMessage(); if (false == empty($errors)) { response_to_json(5, $errors); } $data = array('name' => $postData['name']['value'], 'score' => $postData['score']['value'], 'fromdate' => date("Y-m-d H:i:s", strtotime($postData['fromdate']['value'])), 'enddate' => date("Y-m-d H:i:s", strtotime($postData['enddate']['value']) + 86400), 'status' => $postData['status']['value'], 'type' => $postData['type']['value']); if ($id) { $affected = $this->activity_model->updateActivity(array('id' => $id), $data); $errors = $this->activity_model->getLastMessage(); $code = 0 == $affected || false == empty($errors) ? 4 : 0; $message = false == empty($errors) ? $errors : (0 == $affected ? '操作失败' : '操作成功'); } else { $data['createtime'] = date('Y-m-d H:i:s', time()); $id = $this->activity_model->createActivity($data); // 推送通知PUSH $this->load->helper('push'); $this->load->model('user_model'); $userlist = $this->user_model->getUserList(['status' => 1, 'sys_push' => 1]); if ($userlist) { foreach ($userlist as $k => $v) { if ($v['sys_push'] && $v['device_tokens']) { sendAppPush($v['platform'], $v['device_tokens'], 3, $postData['name']['value']); // push } } } $code = 0 == $id || false == empty($errors) ? 4 : 0; $message = false == empty($errors) ? $errors : (0 == $id ? '操作失败' : '操作成功'); } response_to_json($code, $message); }
/** * 用户注册 * @date: 2016年1月10日 下午10:54:46 * * @author : Elliot * @param * : variable * @return : */ public function register_post() { $this->load->model('user_model'); $data = $this->_post_args; try { // 手机号必须 if (!isset($data['tel'])) { throw new Exception('手机号必须', 400); } // test code // 判断手机号是否合法 if (!preg_match("/1[3458]{1}\\d{9}\$/", $data['tel'])) { throw new Exception('不符合规范的手机号码', 400); } // 判断此手机号是否存在 $user_ifexist = $this->user_model->getUser(array('tel' => $data['tel'])); if ($user_ifexist) { throw new Exception('手机号码已存在', 409); // test code } // 判断验证码 是否正确 $usercode = $this->user_model->getUserCode(array('tel' => $data['tel'], 'type' => 1)); if ($usercode['code'] != $data['verifycode']) { throw new Exception('验证码错误', 409); // test code } unset($data['verifycode']); // 邀请码 if (isset($data['invitationcode']) && $data['invitationcode'] !== '') { $userInvitation = $this->user_model->getUser(array('invitationcode' => $data['invitationcode'])); if (!$userInvitation) { throw new Exception('您填写的邀请码用户不存在', 400); } $data['ref_userid'] = $userInvitation['id']; // 推送通知PUSH $this->load->helper('push'); if ($userInvitation['invter_push'] && $userInvitation['device_tokens']) { sendAppPush($userInvitation['platform'], $userInvitation['device_tokens'], 4, '您推荐的手机号' . $data['tel'] . '用户注册成功'); // push } } // 随机生成 username password $this->load->helper('encrypt'); $uaUserPwd = encrypt_build_rand_password(3); $data['username'] = '******' . generate_username(6); // 用户名字规则user+6位数字随机 $data['passwd'] = encrypt_md5($uaUserPwd); // 默认省市位置 北京朝阳 $data['provice_sid'] = '001001'; $data['provice_name'] = '北京'; $data['city_sid'] = '001001005'; $data['city_name'] = '朝阳'; $data['createtime'] = date('Y-m-d H:i:s', time()); // 生成唯一邀请码 $this->load->helper('common'); $data['invitationcode'] = getInviteCode(); // 随机用户头像 $data['sysavatarid'] = rand(1, MAXRANDAVATARID); //判断新注册的手机号是否存在预关系 $inventdetail = $this->user_model->getinventrel(['phone' => $data['tel']]); if ($inventdetail) { $data['ref_userid'] = $inventdetail['uid']; } $id = $this->user_model->createUser($data); } catch (Exception $e) { $this->response(array('error' => $e->getMessage()), $e->getCode()); } if ($id) { $user = $this->user_model->getUser(array('id' => $id)); $user['passwd'] = $uaUserPwd; // 返回原始密码 $this->response($user, 201); // 201 being the HTTP response code } else { $this->response(array('error' => '用户注册失败'), 404); } }