You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

60 lines
2.0 KiB

  1. <?php
  2. require_once '../Common/Config.php';
  3. require_once '../Common/Function.php';
  4. $pdo = new PDO("sqlsrv:Server=".HOST.";Database=".DB, USER, PASSWORD);//5.6版本pdo连接sqlsrv
  5. if ($_POST){
  6. $method=htmlspecialchars($_POST['method']);
  7. if ($method =='shareTimeLine'){
  8. $sharTimeLine=htmlspecialchars($_POST['shareTimeLine']);
  9. if ($sharTimeLine ==0){
  10. $updateId=htmlspecialchars($_POST['updateId']);
  11. $openId=htmlspecialchars($_POST['openId']);
  12. $sql="SELECT sharTimeLine FROM lottery_user WHERE openId='".$openId."'";
  13. $result=$pdo->query($sql);
  14. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  15. $sharTime=$rowset[0]['sharTimeLine'];
  16. if ($sharTime !=0){
  17. exit;
  18. }
  19. write_log("method:shareTimeLine有调用");
  20. $addCode="SELECT TOP 1 id,lotteryCode FROM lottery_code";
  21. $addResult=$pdo->query($addCode);
  22. $addRowset = $addResult->fetchAll(PDO::FETCH_ASSOC);
  23. $addErrinfo=$pdo->errorInfo();
  24. if ($addErrinfo[0] =="00000"){
  25. $addLotteryCode=$addRowset[0]['lotteryCode'];
  26. $addId=$addRowset[0]['id'];
  27. //$id=2;
  28. try {
  29. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  30. $pdo->beginTransaction();
  31. $updateSql="UPDATE lottery_user SET sharTimeLine=1 WHERE id=".$updateId;
  32. write_log($updateSql);
  33. $updateResult=$pdo->exec($updateSql);
  34. $insertSql="INSERT INTO lottery_friends(openId,lotteryCode,createtime) VALUES('".$openId."',".$addLotteryCode.",'".date("Y-m-d H:i:s",time())."')";
  35. $insertResult=$pdo->exec($insertSql);
  36. $delSql="DELETE FROM lottery_code WHERE id=".$addId;
  37. $delResult=$pdo->exec($delSql);
  38. $pdo->commit();
  39. $result= json_encode(array("errorcode"=>0,"errorcode"=>"分享朋友圈成功"));
  40. } catch (Exception $e) {
  41. $pdo->rollBack();
  42. //echo "Failed: " . $e->getMessage();
  43. write_log($e->getMessage());
  44. }
  45. }
  46. }else{
  47. $result= json_encode(array("errorcode"=>0,"errorcode"=>"多次分享朋友圈只能获得一个抽奖码"));
  48. }
  49. }
  50. echo $result;
  51. }
  52. ?>