暫無描述
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.

shop_centre.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. $( function() {
  2. // 小程序查询调用
  3. wx.miniProgram.getEnv( function(res) {
  4. if(res.miniprogram) {
  5. // 小程序
  6. var i = 0;
  7. i = setInterval('AppletsPay()', 1000);
  8. }
  9. });
  10. });
  11. // 小程序查询
  12. function AppletsPay() {
  13. var unified_id = $('#unified_id').val();
  14. var unified_number = $('#unified_number').val();
  15. var transaction_type = $('#transaction_type').val();
  16. if (unified_id && unified_number && transaction_type) {
  17. $.ajax({
  18. url: eyou_basefile + "?m=user&c=Pay&a=ajax_applets_pay&_ajax=1",
  19. data: {unified_id:unified_id, unified_number:unified_number, transaction_type:transaction_type},
  20. type:'post',
  21. dataType:'json',
  22. success:function(res){
  23. if (1 == res.code) {
  24. if (!res.data.mobile && !res.data.email) window.location.href = res.url;
  25. if (res.data.mobile) SendMobile(res.data.mobile);
  26. if (res.data.email) SendEmail(res.data.email);
  27. window.location.href = res.url;
  28. }
  29. }
  30. });
  31. }
  32. }
  33. // 判断支付类型是否一致并且更新支付方式
  34. function wechatJsApiPay(unified_id, unified_number, transaction_type) {
  35. layer_loading('正在处理');
  36. $.ajax({
  37. url : eyou_basefile + "?m=user&c=Pay&a=update_pay_method&_ajax=1",
  38. data: {unified_id:unified_id,unified_number:unified_number,pay_method:'WeChatInternal',transaction_type:transaction_type,order_source:2},
  39. type:'post',
  40. dataType:'json',
  41. success:function(res){
  42. layer.closeAll();
  43. if (0 == res.code) {
  44. showErrorAlert(res.msg, 0);
  45. }else{
  46. if (1 == res.data.is_gourl) {
  47. window.location.href = res.url;
  48. }else{
  49. $('#unified_id').val(unified_id);
  50. $('#unified_number').val(unified_number);
  51. $('#transaction_type').val(transaction_type);
  52. WeChatInternal(unified_id, unified_number, transaction_type);
  53. }
  54. }
  55. }
  56. });
  57. }
  58. // 微信内部中进行支付
  59. function WeChatInternal(unified_id, unified_number, transaction_type) {
  60. wx.miniProgram.getEnv( function(res) {
  61. if (res.miniprogram) {
  62. // 小程序
  63. wx.miniProgram.navigateTo({
  64. url: '/pages/pay/pay?unified_id='+ unified_id +'&unified_number=' + unified_number + '&type=' + transaction_type
  65. });
  66. } else {
  67. // 微信端
  68. $.ajax({
  69. url : eyou_basefile + "?m=user&c=Pay&a=wechat_pay&_ajax=1",
  70. data: {unified_id:unified_id,unified_number:unified_number,transaction_type:transaction_type},
  71. type:'post',
  72. dataType:'json',
  73. success:function(res){
  74. layer.closeAll();
  75. if (1 == res.code) {
  76. callpay(res.msg);
  77. }else{
  78. showErrorAlert(res.msg, 0);
  79. }
  80. }
  81. });
  82. }
  83. });
  84. }
  85. function jsApiCall(data) {
  86. WeixinJSBridge.invoke(
  87. 'getBrandWCPayRequest',data,
  88. function(res){
  89. if(res.err_msg == "get_brand_wcpay_request:ok"){
  90. layer.msg('微信支付完成!', {time: 1000}, function(){
  91. pay_deal_with();
  92. });
  93. }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
  94. showErrorAlert('用户取消支付!', 0);
  95. }else{
  96. showErrorAlert('支付失败,原因可能是订单号已支付!', 0);
  97. }
  98. }
  99. );
  100. }
  101. // 微信内部支付时,先进行数据判断
  102. function callpay(data) {
  103. if (typeof WeixinJSBridge == "undefined"){
  104. if ( document.addEventListener ) {
  105. document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
  106. } else if (document.attachEvent) {
  107. document.attachEvent('WeixinJSBridgeReady', jsApiCall);
  108. document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
  109. }
  110. } else {
  111. jsApiCall(data);
  112. }
  113. }
  114. // 微信订单查询
  115. function pay_deal_with() {
  116. var unified_number = $('#unified_number').val();
  117. var transaction_type = $('#transaction_type').val();
  118. $.ajax({
  119. url : eyou_basefile + "?m=user&c=Pay&a=pay_deal_with&_ajax=1",
  120. data: {unified_number:unified_number,transaction_type:transaction_type},
  121. type:'post',
  122. dataType:'json',
  123. success:function(res){
  124. if (1 == res.data.status) {
  125. if (!res.data.mobile && !res.data.email) window.location.href = res.url;
  126. if (res.data.mobile) SendMobile(res.data.mobile);
  127. if (res.data.email) SendEmail(res.data.email);
  128. window.location.href = res.url;
  129. }
  130. }
  131. });
  132. }
  133. // 发送短信
  134. function SendMobile(result) {
  135. if (result) {
  136. $.ajax({
  137. url: result.url,
  138. data: result.data,
  139. type:'post',
  140. dataType:'json'
  141. });
  142. }
  143. }
  144. // 发送邮件
  145. function SendEmail(result) {
  146. if (result) {
  147. $.ajax({
  148. url: result.url,
  149. data: result.data,
  150. type:'post',
  151. dataType:'json'
  152. });
  153. }
  154. }
  155. // 订单号复制
  156. function orderCopy() {
  157. var clipboard1 = new Clipboard(".order_code");
  158. clipboard1.on("success", function(e) {
  159. layer.msg("复制成功");
  160. });
  161. clipboard1.on("error", function(e) {
  162. layer.msg("复制失败!请手动复制", {icon: 5});
  163. });
  164. }
  165. // 判断是核销码否存在img子元素
  166. if ($("#qrcode img").length === 0) {
  167. // 隐藏代码
  168. $("#qrcode").hide();
  169. }