public function add() { $model = D('Files'); //file_put_contents('./1.txt',$_POST['content']); $_POST = json_decode($_POST['content'], 1); $_POST['create_time'] = time(); $_POST['user_id'] = $this->user['id']; $_POST['user_name'] = $this->user['nickname']; if (false === $model->create()) { $this->error($model->getError()); } //保存当前数据对象 $list = $model->add(); if ($list !== false) { //保存成功 $this->history($list); //附件处理 if ($_POST['uppicarr']) { $model = M('attachments'); foreach ($_POST['uppicarr'] as $key => $file) { $add_data['source'] = MODULE_NAME; $add_data['sourceid'] = $list; $add_data['filepath'] = $file; $file_dir = str_replace(C('IMG_URL'), C('IMG_ROOT'), $file); $add_data['size'] = filesize($file_dir); $add_data['type'] = get_file_type($file_dir); $add_data['filename'] = $add_data['title'] = $_POST['uppicname'][$key]; $add_data['create_time'] = time(); $add_data['user_id'] = $_SESSION[C('USER_AUTH_KEY')]; $model->add($add_data); } } //传阅处理 if ($_POST['user']) { $model = M('Files_user'); if ($_POST['call_time']) { $add_data['call_time'] = strtotime($_POST['call_time']); } foreach ($_POST['user'] as $key => $user) { $user_arr = explode(',', $user); //推送 $sent_array['module'] = MODULE_NAME; $sent_array['action'] = 'show'; $sent_array['id'] = $list; $custom_content = json_encode($sent_array); $result = push_msg2($user_arr[0], $_POST['title'], $custom_content); if ($result) { $add_data['sent_status'] = 1; $add_data['sent_time'] = time(); } $add_data['from_id'] = $this->user['id']; $add_data['from_name'] = $this->user['nickname']; $add_data['user_id'] = $user_arr[0]; $ids[] = $user_arr[0]; $add_data['user_name'] = $user_arr[1]; $add_data['bm_name'] = $user_arr[2]; $add_data['fid'] = $list; $add_data['title'] = $_POST['title']; $model->add($add_data); } } //$this->update_date($ids,$list);//记录 if ($_POST['type'] == 1) { $this->update_date($user_ids, $list); } else { unset($user_ids); $user_ids[] = 0; $this->update_date($user_ids, $list); } $model->query('OPTIMIZE TABLE `zy_attachments`'); $msg['status'] = 1; $msg['notice'] = '提交成功'; $msg['error_code'] = 1000; echo json_encode($msg); exit; } else { //失败提示 $msg['status'] = 0; $msg['notice'] = '修改失败'; $msg['error_code'] = 8002; echo json_encode($msg); exit; } }
function timing() { $model = M('files_user'); $data['call_time'] = array('neq', 0); $data['call_sent_status'] = 0; //$data['baiduUserId'] = array('neq',''); $data['a.status'] = 0; $list = $model->field('a.*,b.baiduUserId')->table('`zy_files_user` as a')->join('`zy_user` as b on a.user_id=b.id')->where($data)->select(); //$list = $model->where($data)->select(); //echo $model->getlastsql();dump($list);exit; if (!$list) { return false; } foreach ($list as $user) { if ($user['baiduUserId']) { //推送 $sent_array['module'] = 'Files'; $sent_array['action'] = 'show'; $sent_array['id'] = $user['fid']; $custom_content = json_encode($sent_array); $result = push_msg2($user['user_id'], $user['title'], $custom_content); if ($result) { $sdata['sent_status'] = 1; $sdata['call_sent_status'] = 1; $sdata['sent_time'] = time(); $wdata['id'] = $user['id']; $model->where($wdata)->save($sdata); } else { $error[] = $user; } } else { $error[] = $user; } } if ($error) { F('files_error', $error, './'); } else { unlink('./files_error.php'); } //dump($list); }