project.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?php
  2. if(!defined('IN_T')){
  3. die('hacking attempt');
  4. }
  5. $act = Common::sfilter($_REQUEST['act']);
  6. $input=null;
  7. if (empty($act)) {
  8. $input = $Json->decode(file_get_contents("php://input"));
  9. if (!empty($input)) {
  10. $act = $input['act'];
  11. }
  12. }
  13. //编辑时查询用户的场景
  14. if($act=="list_scenes"){
  15. $page = intval($_REQUEST['page'])<1 ? 1 : intval($_REQUEST['page']);
  16. $pageSize = 210;
  17. $res = list_scenes( $page,$pageSize,$user['pk_user_main']);
  18. echo $Json->encode($res);
  19. exit;
  20. }
  21. //查看项目列表,ajax动态获取数据
  22. else if($act=="list_data"){
  23. $page = intval($_REQUEST['page'])<1 ? 1 : intval($_REQUEST['page']);
  24. $pageSize = intval($_REQUEST['pageSize'])<1 ? 10 : intval($_REQUEST['pageSize']);
  25. if($pageSize>30){
  26. $pageSize=10;
  27. }
  28. $name = Common::sfilter($_REQUEST['name']);
  29. $atlas = intval($_REQUEST['atlas']);
  30. $time_s = Common::sfilter($_REQUEST['time_s']);
  31. $time_e = Common::sfilter($_REQUEST['time_e']);
  32. $list = get_list_project($user['pk_user_main'],$page,$pageSize,$name,$atlas,$time_s,$time_e);
  33. echo $Json->encode($list);
  34. exit;
  35. }
  36. //添加或者更新图册
  37. else if($act == "atlas_update"){
  38. $atlas_id = intval($_REQUEST['atlas_id']);
  39. $name = Common::sfilter($_REQUEST['name']);
  40. $re['flag'] = 0;
  41. if (mb_strlen($name)<=0||mb_strlen($name)>200) {
  42. $re['msg'] = "请输入0到200个长度的名称";
  43. }
  44. if ($atlas_id<=0) {
  45. if($Db->getCount($Base->table('atlasmain'),'pk_atlas_main',array('pk_user_main'=>$user['pk_user_main']))>=20){
  46. $re['msg'] = '每个用户最多只能创建20个图册';
  47. }else{
  48. //插入
  49. $Db->insert($Base->table('atlasmain'),array('pk_user_main'=>$user['pk_user_main'],'name'=>$name,'create_time'=>date('Y-m-d H:i:s',Common::gmtime()),'atlas_type'=>1 ));
  50. $re['flag'] = 1;
  51. }
  52. }else{
  53. //更新
  54. if($Db->getCount($Base->table('atlasmain'),'pk_atlas_main',array('pk_atlas_main'=>$atlas_id,'pk_user_main'=>$user['pk_user_main'],'atlas_type'=>1))>0){
  55. $Db->update($Base->table('atlasmain'),array('name'=>$name),array('pk_atlas_main'=>$atlas_id));
  56. $re['flag'] = 1;
  57. }else{
  58. $re['msg'] = "非法操作";
  59. }
  60. }
  61. echo $Json->encode($re,JSON_NUMERIC_CHECK);
  62. exit;
  63. }
  64. //删除图册
  65. else if($act == "atlas_del"){
  66. $atlas_id = intval($_REQUEST['atlas_id']);
  67. $re['flag'] = 0;
  68. if($Db->getCount($Base->table('atlasmain'),'pk_atlas_main',array('pk_atlas_main'=>$atlas_id,'pk_user_main'=>$user['pk_user_main'],'atlas_type'=>1))<=0){
  69. $re['msg'] = "非法操作";
  70. }else{
  71. if($Db->getCount($Base->table('worksmain'),'pk_works_main',array('pk_atlas_main'=>$atlas_id))>0){
  72. $default_aid = $Db->query("SELECT pk_atlas_main FROM ".$Base->table('atlasmain')." WHERE pk_user_main = ".$user['pk_user_main']." AND atlas_type =0","One");
  73. $Db->update($Base->table('worksmain'),array("pk_atlas_main"=>$default_aid),array("pk_atlas_main"=>$atlas_id));
  74. }
  75. $Db->delete($Base->table('atlasmain'),array('pk_atlas_main'=>$atlas_id));
  76. $re['flag'] = 1;
  77. }
  78. echo $Json->encode($re,JSON_NUMERIC_CHECK);
  79. exit;
  80. }
  81. //删除项目
  82. else if($act == "works_del"){
  83. $pid = intval($_REQUEST['pid']);
  84. $re['flag'] = 0 ;
  85. //用户限制了上传数量,则无法删除
  86. if($limit_num = $Db->query("select limit_num from ".$Base->table('user')." where pk_user_main=".$user['pk_user_main']."","One")){
  87. $re['msg'] = "你当前只能上传".$limit_num."个项目,请联系客服删除!";
  88. }
  89. else if($pid==0 || $Db->getCount($Base->table('worksmain'),'pk_works_main',array('pk_works_main'=>$pid,'pk_user_main'=>$user['pk_user_main']))<=0){
  90. $re['msg'] = "非法操作";
  91. }else{
  92. $Db->beginTransaction();
  93. try{
  94. //删除 项目与图片的中间表
  95. $Db->delete($Base->table('imgs_works'),array('pk_works_main'=>$pid));
  96. //删除 项目与标签的中间表
  97. // $Db->delete($Base->table("tag_works"),array('works_id'=>$pid));
  98. //删除评论 TODO
  99. // $Db->delete($Base->table('comment'),array('pk_works_main'=>$pid));
  100. //删除项目
  101. $Db->delete($Base->table('worksmain'),array('pk_works_main'=>$pid));
  102. //删除panoconfig
  103. // $Db->delete($Base->table('pano_config'),array('pk_works_main'=>$pid));
  104. $Db->commit();
  105. $re['flag'] = 1;
  106. }catch(Exception $e){
  107. $Db->rollback();
  108. $re['msg'] = '操作失败!';
  109. }
  110. }
  111. echo $Json->encode($re,JSON_NUMERIC_CHECK);
  112. exit;
  113. }
  114. //移动项目到某个图册
  115. else if($act =="move_project"){
  116. $pids =$Json->decode(Common::sfilter($_REQUEST['pids']));
  117. $atlas_id = intval($_REQUEST['atlas_id']);
  118. $re['flag'] = 0 ;
  119. if ($pids == null||$atlas_id<=0) {
  120. $re['msg'] = '参数有误';
  121. }else{
  122. $Db->execSql("update ".$Base->table("worksmain")." SET pk_atlas_main = ".$atlas_id." WHERE pk_user_main = ".$user['pk_user_main']." AND pk_works_main IN (".implode(",", $pids).")");
  123. $re['flag'] = 1;
  124. }
  125. echo $Json->encode($re,JSON_NUMERIC_CHECK);
  126. exit;
  127. }
  128. //跳转到视频列表
  129. else if($act == "videos"){
  130. $tp->assign("total",$Db->getCount($Base->table('video'),"id",array('pk_user_main'=>$user['pk_user_main'])));
  131. $tp->assign('act','videos');
  132. }
  133. //前台获取视频的json数据
  134. else if($act == "list_videos"){
  135. $page = intval($_REQUEST['page'])<1 ? 1 : intval($_REQUEST['page']);
  136. $pageSize = intval($_REQUEST['pageSize'])<1 ? 10 : intval($_REQUEST['pageSize']);
  137. if($pageSize>30){
  138. $pageSize=10;
  139. }
  140. $vname = Common::sfilter($_REQUEST['vname']);
  141. $time_s = Common::sfilter($_REQUEST['time_s']);
  142. $time_e = Common::sfilter($_REQUEST['time_e']);
  143. $list = get_video_list($user['pk_user_main'],$page,$pageSize,$vname,$time_s,$time_e);
  144. echo $Json->encode($list);
  145. exit;
  146. }
  147. //删除一个视频项目
  148. else if($act == "video_del"){
  149. $vid = intval($_REQUEST['vid']);
  150. $re['flag'] = 0;
  151. //用户限制了上传数量,则无法删除
  152. if($limit_num = $Db->query("select limit_num from ".$Base->table('user')." where pk_user_main=".$user['pk_user_main']."","One")){
  153. $re['msg'] = "你当前只能上传".$limit_num."个项目,请联系客服删除!";
  154. }
  155. else{
  156. $Db->delete($Base->table("video"),array("id"=>$vid,"pk_user_main"=>$user['pk_user_main']));
  157. $re['flag'] = 1;
  158. }
  159. echo $Json->encode($re);
  160. exit;
  161. }else if($act =="edit_sort_recommend"){
  162. //type 1 : 修改全景图片 2:修改视频
  163. //edit 1: 修改排序 2:修改推荐
  164. $re['status'] = 0;
  165. $type = intval($_REQUEST['type']);
  166. $edit = intval($_REQUEST['edit']);
  167. $id = intval($_REQUEST['id']);
  168. if ($id<=0||$type<=0||$edit<=0) {
  169. $re['msg'] = '非法参数';
  170. }else{
  171. $param = array();
  172. if ($edit==1) {
  173. $param['user_sort'] = intval($_REQUEST['user_sort']);
  174. if ($param['user_sort']<=0||$param['user_sort']>999) {
  175. $re['msg'] = '请输入1到999之间的值';
  176. echo $Json->encode($re);
  177. exit;
  178. }
  179. }else{
  180. $pro = $Db->query("SELECT user_recommend FROM ".($type==1?$Base->table('worksmain'):$Base->table('video'))." WHERE ".($type==1?"pk_works_main":"id").' = '.$id,"Row" );
  181. if (empty($pro)) {
  182. $re['msg'] = '非法参数';
  183. echo $Json->encode($re);
  184. exit;
  185. }else{
  186. $param['user_recommend'] = $pro['user_recommend']==0?1:0;
  187. $re['recommend'] = $param['user_recommend'];
  188. }
  189. }
  190. if($type == 1) {
  191. $Db->update($Base->table('worksmain'),$param,array('pk_works_main'=>$id,'pk_user_main'=>$user['pk_user_main']) );
  192. }else if ($type == 2) {
  193. $Db->update($Base->table('video'),$param,array('id'=>$id,'pk_user_main'=>$user['pk_user_main']) );
  194. }
  195. $re['status'] = 1;
  196. }
  197. echo $Json->encode($re);
  198. exit;
  199. }
  200. //跳转到project查看列表
  201. else{
  202. $tp->assign("atlas",$Db->query("SELECT a.name ,COUNT(w.pk_works_main) AS num ,a.atlas_type,a.pk_atlas_main FROM ".$Base->table('atlasmain')." a LEFT JOIN ".$Base->table('worksmain')." w ON a.pk_atlas_main = w.pk_atlas_main WHERE a.pk_user_main=".$user['pk_user_main']." GROUP BY a.pk_atlas_main "));
  203. $tp->assign("total",$Db->getCount($Base->table("worksmain"),"pk_works_main",array("pk_user_main"=>$user["pk_user_main"])));
  204. $tp->assign('act','list');
  205. }
  206. //分页
  207. function list_scenes( $page = 1,$pageSize = 210, $uid=0){
  208. $sql = 'FROM'.$GLOBALS['Base']->table('imgsmain');
  209. if($uid >0){
  210. $sql.=' WHERE pk_user_main='.$uid;
  211. }
  212. $list = $GLOBALS['Db']->query('SELECT * '.$sql.' ORDER BY pk_img_main DESC LIMIT '.($page-1)*$pageSize.','.$pageSize);
  213. $itemCount = $GLOBALS['Db']->query(" SELECT COUNT(*) AS num ".$sql,"One");
  214. $pageCount = ceil($itemCount/$pageSize);
  215. $res = array(
  216. 'pageCount'=>$pageCount,
  217. 'currentPage'=>$page,
  218. 'pageSize'=>$pageSize,
  219. 'list'=>$list,
  220. );
  221. return $res;
  222. // if($uid==0){
  223. // $list = $GLOBALS['Db']->query("SELECT * FROM ".$GLOBALS['Base']->table('imgsmain')." WHERE pk_user_main = $uid ORDER BY pk_img_main DESC LIMIT $start,$pageSize");
  224. // $all = $GLOBALS['Db']->query("SELECT * FROM ".$GLOBALS['Base']->table('imgsmain')." WHERE pk_user_main = ".$uid;
  225. // $pageCount = ceil(count($all)/$pageSize);
  226. // $res = array(
  227. // 'pageCount'=>$pageCount,
  228. // 'currentPage'=>$page,
  229. // 'pageSize'=>$pageSize,
  230. // 'list'=>$list,
  231. // );
  232. // return json_encode($res);
  233. // }else if($type == 'all'){
  234. // $list = $GLOBALS['Db']->query("SELECT * FROM ".$GLOBALS['Base']->table('imgsmain').'ORDER BY pk_img_main DESC');
  235. // $res = array(
  236. // 'list'=>$list,
  237. // );
  238. // return json_encode($res);
  239. // }
  240. }
  241. //获取视频列表
  242. function get_video_list($uid , $page ,$pageSize,$vname,$time_s,$time_e){
  243. $sql = " FROM ".$GLOBALS['Base']->table('video')." WHERE pk_user_main = $uid";
  244. if (!empty($vname)) {
  245. $sql .= " AND vname LIKE '%$vname%'";
  246. }
  247. if(!empty($time_s)&&!empty($time_e)){
  248. $sql .= " AND create_time between '$time_s' AND '$time_e' ";
  249. }
  250. $itemCount = $GLOBALS['Db']->query(" SELECT COUNT(id) AS num ".$sql,"One");
  251. $pageCount = ceil($itemCount/$pageSize);
  252. $list = $GLOBALS['Db']->query(" SELECT * ".$sql.' ORDER BY id DESC limit '.($page-1)*$pageSize.','.$pageSize);
  253. $res = array(
  254. 'itemCount'=>$itemCount,
  255. 'pageCount'=>$pageCount,
  256. 'currentPage'=>$page,
  257. 'pageSize'=>$pageSize,
  258. 'list'=>$list,
  259. );
  260. return $res;
  261. }
  262. //提取图片列表
  263. function get_list_project($uid,$page,$pageSize,$name,$atlas,$time_s,$time_e){
  264. $list_sql = "SELECT * ";
  265. $count_sql = "SELECT count(*) as num ";
  266. $sql = "FROM ".$GLOBALS['Base']->table('worksmain')." WHERE pk_user_main=$uid ";
  267. //搜索項目名稱
  268. if(!empty($name)){
  269. $sql .= "AND name like '%$name%' ";
  270. }
  271. //搜索分類
  272. if($atlas>0){
  273. $sql .= "AND pk_atlas_main=$atlas ";
  274. }
  275. //搜索時間
  276. if(!empty($time_s) && !empty($time_e)){
  277. $sql .= "AND create_time between '$time_s' AND '$time_e' ";
  278. }
  279. //取得總條數
  280. $itemCount = $GLOBALS['Db']->query($count_sql.$sql,"Row");
  281. $itemCount = $itemCount['num'];
  282. //取得總頁數
  283. $pageCount = ceil($itemCount/$pageSize);
  284. //echo $sql;
  285. $list = $GLOBALS['Db']->query($list_sql.$sql.' ORDER BY pk_works_main DESC limit '.($page-1)*$pageSize.','.$pageSize);
  286. $res = array(
  287. 'itemCount'=>$itemCount,
  288. 'pageCount'=>$pageCount,
  289. 'currentPage'=>$page,
  290. 'pageSize'=>$pageSize,
  291. 'list'=>$list,
  292. );
  293. return $res;
  294. }
  295. $tp->assign('title','全景图片');
  296. ?>