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.

bind.php 1.8 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * wechat 2.0
  4. * Copyright (c) 2016 Redstop http://zhizhuchuxing.com/
  5. * Date: 2016.10.19
  6. */
  7. require_once '../../Common/Mysql.php';
  8. if (ALLOW_ORIGIN)
  9. header("Access-Control-Allow-Origin:*");
  10. date_default_timezone_set('PRC');
  11. $member_id = isset($_COOKIE['user_id'])?$_COOKIE['user_id']:false;
  12. if ( !$member_id ) {
  13. echo json_encode(array("code" => 1,"iflogin"=>1, "info" => "未登录"));
  14. exit ;
  15. }
  16. //$userid=1;
  17. $order_no = isset($_POST['order_no']) ? $_POST['order_no'] : false;
  18. $phone_no = isset($_POST['phone_no']) ? $_POST['phone_no'] : false;
  19. if( $order_no == false || $phone_no == false ){
  20. echo json_encode(array("code" => '1', "info" => "请输入正确的订单号和联系人手机号"));
  21. exit ;
  22. }
  23. $pdo=conn();
  24. $sql = "SELECT ID,OPENID FROM wechat_user WHERE ID = {$member_id}";
  25. $result=$pdo->query($sql);
  26. if( $result ) {
  27. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  28. $user_info = $rowset[0];
  29. $result->closeCursor();
  30. } else {
  31. echo json_encode(array("code" => 1,"iflogin"=>1, "info" => "未登录"));
  32. exit ;
  33. }
  34. $sql="CALL DRIVER_WEICHAT_BOND(".$order_no.",".$phone_no.",'".$user_info['OPENID']."')";
  35. $result=$pdo->query($sql);
  36. if( $result ) {
  37. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  38. $result->closeCursor();
  39. } else {
  40. $rowset = false;
  41. }
  42. if ( $rowset == false || $rowset[0]['code'] != 0){
  43. $contentStr = "绑定订单失败";
  44. if( $rowset != false && isset($rowset[0]['info']) ) {
  45. $contentStr .= ":".$rowset[0]['info'];
  46. }
  47. echo json_encode(array("code" => '1', "info" => $contentStr ));
  48. exit ;
  49. }
  50. $update_sql = "UPDATE order_main SET MEMBER_ID = (SELECT id FROM wechat_user WHERE OPENID = '{$user_info['OPENID']}' ) WHERE order_id = {$order_no} OR parent_order_id = {$phone_no}";
  51. $pdo_update = conn();
  52. $pdo_update->exec($update_sql);
  53. echo json_encode(array("code" => '0', "info" => "绑定订单成功" ));
  54. exit ;