my_collect_post.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. require_once "../config.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/function.php';
  5. require_once '../collect/function.php';
  6. require_once "../ucenter/active.php";
  7. require_once "../redis/function.php";
  8. require_once __DIR__."/../public/snowflakeid.php";
  9. $snowflake = new SnowFlakeId();
  10. $respond=array("status"=>0,"message"=>"");
  11. if(!isset($_COOKIE["userid"])){
  12. #不登录不能新建
  13. $respond['status']=1;
  14. $respond['message']="no power create article";
  15. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  16. exit;
  17. }
  18. # 检查当前用户是否有修改权限
  19. $redis = redis_connect();
  20. $collection = new CollectInfo($redis);
  21. $power = $collection->getPower($_POST["id"]);
  22. if($power<20){
  23. $respond["status"]=1;
  24. $respond["message"]="No Power For Edit";
  25. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  26. exit;
  27. }
  28. add_edit_event(_COLLECTION_EDIT_,$_POST["id"]);
  29. PDO_Connect(_FILE_DB_USER_ARTICLE_,_DB_USERNAME_,_DB_PASSWORD_);
  30. $query="UPDATE "._TABLE_COLLECTION_." SET title = ? , subtitle = ? , summary = ?, article_list = ? , status = ? , lang = ? , updated_at= now() , modify_time= ? where uid = ? ";
  31. $sth = $PDO->prepare($query);
  32. $sth->execute(array($_POST["title"] , $_POST["subtitle"] ,$_POST["summary"], $_POST["article_list"] , $_POST["status"] , $_POST["lang"] , mTime() , $_POST["id"]));
  33. $respond=array("status"=>0,"message"=>"");
  34. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  35. $error = PDO_ErrorInfo();
  36. $respond['status']=1;
  37. $respond['message']=$error[2];
  38. }
  39. else{
  40. if($redis){
  41. $redis->del("collection://".$_POST["id"]);
  42. $redis->del("power://collection/".$_POST["id"]);
  43. }
  44. # 更新 article_list 表
  45. $query = "DELETE FROM "._TABLE_ARTICLE_COLLECTION_." WHERE collect_id = ? ";
  46. PDO_Execute($query,array($_POST["id"]));
  47. $arrList = json_decode($_POST["article_list"]);
  48. if(count($arrList)>0){
  49. /* 开始一个事务,关闭自动提交 */
  50. $PDO->beginTransaction();
  51. $query = "INSERT INTO "._TABLE_ARTICLE_COLLECTION_." (
  52. id,
  53. collect_id,
  54. article_id,
  55. level,
  56. title,
  57. children
  58. ) VALUES (?, ? , ?, ?, ? , ? )";
  59. $sth = $PDO->prepare($query);
  60. foreach ($arrList as $row) {
  61. $sth->execute(array(
  62. $snowflake->id(),
  63. $_POST["id"],
  64. $row->article,
  65. $row->level,
  66. $row->title,
  67. $row->children
  68. ));
  69. if($redis){
  70. #删除article权限缓存
  71. $redis->del("power://article/".$row->article);
  72. }
  73. }
  74. $PDO->commit();
  75. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  76. /* 识别错误且回滚更改 */
  77. $PDO->rollBack();
  78. $error = PDO_ErrorInfo();
  79. $respond['status']=1;
  80. $respond['message']=$error[2];
  81. }
  82. }
  83. }
  84. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  85. ?>