coop_put.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. //查询term字典
  3. require_once "../path.php";
  4. require_once "../public/_pdo.php";
  5. require_once '../public/function.php';
  6. require_once '../ucenter/function.php';
  7. require_once '../group/function.php';
  8. $respond['status']=0;
  9. $respond['message']="成功";
  10. if(isset($_POST["res_id"])){
  11. PDO_Connect(_FILE_DB_USER_SHARE_);
  12. $PDO->beginTransaction();
  13. $query = "INSERT INTO share_cooperator ('id','res_id','res_type','cooperator_id','cooperator_type','power','create_time','modify_time','is_deleted') VALUES (null,?,?,?,?,?,?,?,?) ";
  14. $sth = $PDO->prepare($query);
  15. $data = json_decode($_POST["user_info"]);
  16. foreach ($data as $key => $user) {
  17. # code...
  18. $sth->execute(array($_POST["res_id"],
  19. $_POST["res_type"],
  20. $user->id,
  21. $user->type,
  22. $_POST["power"],
  23. mTime(),
  24. mTime(),
  25. 0
  26. ));
  27. }
  28. $PDO->commit();
  29. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  30. /* 识别错误且回滚更改 */
  31. $PDO->rollBack();
  32. $error = PDO_ErrorInfo();
  33. $respond['status']=1;
  34. $respond['message']=$error[2];
  35. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  36. exit;
  37. }
  38. else{
  39. $respond['status']=0;
  40. $respond['message']="成功";
  41. }
  42. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  43. }
  44. else{
  45. $respond['status']=1;
  46. $respond['message']="no res id";
  47. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  48. }
  49. ?>