update.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /*
  3. get xml doc from db
  4. */
  5. require_once "../path.php";
  6. require_once "../public/_pdo.php";
  7. require_once "../public/function.php";
  8. require_once "../ucenter/active.php";
  9. require_once "../redis/function.php";
  10. require_once "../channal/function.php";
  11. require_once "../db/wbw_block.php";
  12. $respond['status'] = 0;
  13. $respond['message'] = "";
  14. $redis = redis_connect();
  15. $channelInfo = new Channal($redis);
  16. $_WbwBlock = new WbwBlock($redis);
  17. if (isset($_POST["data"])) {
  18. $aData = json_decode($_POST["data"]);
  19. } else {
  20. $respond['status'] = 1;
  21. $respond['message'] = "no data";
  22. echo json_encode(array(), JSON_UNESCAPED_UNICODE);
  23. exit;
  24. }
  25. if (count($aData) > 0) {
  26. add_edit_event(_WBW_EDIT_, "{$aData[0]->book}-{$aData[0]->para}-{$aData[0]->word_id}");
  27. PDO_Connect(_FILE_DB_USER_WBW_);
  28. #确定block id 的写入权限
  29. $listBlockId=array();
  30. foreach ($aData as $data) {
  31. $listBlockId[$data->block_id]=0;
  32. }
  33. #查询channel 的 权限
  34. $maxPower=0;
  35. foreach ($listBlockId as $key => $value) {
  36. $listBlockId[$key] = $_WbwBlock->getPower($key);
  37. if($listBlockId[$key]>$maxPower){
  38. $maxPower = $listBlockId[$key];
  39. }
  40. }
  41. /* 开始一个事务,关闭自动提交 */
  42. $PDO->beginTransaction();
  43. $query = "UPDATE "._TABLE_USER_WBW_." SET data= ? , receive_time= ? , modify_time= ? where block_id= ? and wid= ? ";
  44. $sth = $PDO->prepare($query);
  45. foreach ($aData as $data) {
  46. if($listBlockId[$data->block_id]>=20){
  47. $sth->execute(array($data->data, mTime(), $data->time, $data->block_id, $data->word_id));
  48. }
  49. }
  50. $PDO->commit();
  51. $respond = array("status" => 0, "message" => "");
  52. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  53. /* 识别错误且回滚更改 */
  54. $PDO->rollBack();
  55. $error = PDO_ErrorInfo();
  56. $respond['status'] = 1;
  57. $respond['message'] = $error[2];
  58. } else {
  59. $respond['status'] = 0;
  60. $respond['message'] = "成功";
  61. }
  62. if($maxPower<20){
  63. $respond['status'] = 1;
  64. $respond['message'] = "没有修改权限";
  65. }
  66. if (count($aData) ==1){
  67. try {
  68. #将数据插入redis 作为自动匹配最新数据
  69. if($redis){
  70. $xmlString = "<root>" . $data->data . "</root>";
  71. $xmlWord = simplexml_load_string($xmlString);
  72. $wordsList = $xmlWord->xpath('//word');
  73. foreach ($wordsList as $word) {
  74. $pali = $word->real->__toString();
  75. $newword[]=array( "0",
  76. $pali,
  77. $word->type->__toString(),
  78. $word->gramma->__toString(),
  79. $word->parent->__toString(),
  80. $word->mean->__toString(),
  81. "",
  82. $word->org->__toString(),
  83. $word->om->__toString(),
  84. "7",
  85. "100",
  86. "my",
  87. "none"
  88. );
  89. $redis->hSet("wbwdict://new/".$_COOKIE["userid"],$pali,json_encode($newword, JSON_UNESCAPED_UNICODE));
  90. }
  91. }
  92. } catch (Throwable $e) {
  93. echo "Captured Throwable: " . $e->getMessage();
  94. }
  95. }
  96. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  97. } else {
  98. $respond['status'] = 1;
  99. $respond['message'] = "no data";
  100. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  101. }