confirmOrderOnly.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. var app = getApp() //实例化小程序,从而获取全局数据或者使用全局函数
  2. var MD5Util = require('../../utils/md5.js');
  3. // let URLINDEX=util.prefix();
  4. var addressList = [];
  5. var addressAll = [];
  6. Page({
  7. data: {
  8. hidden: 'hidden',
  9. addressAll: addressAll,
  10. addressList: addressList,
  11. addressBg: "../../images/address_line.png",
  12. addressVal: "../../images/address_logo.png",
  13. addressAddImg: "../../images/add_address.png",
  14. addressEditImg: "../../images/gray_back.png",
  15. checkState: true,
  16. carts: [],
  17. gotJson2: {},
  18. total: 0,
  19. value: 0,
  20. checked: false,//发票默认不选中
  21. servalue: 1,
  22. serchecked: true,//服务协议默认选中
  23. isShow: false,
  24. address: '',
  25. total1: 0,
  26. total2: 0,
  27. province: '',
  28. city: '',
  29. area: '',
  30. adress: '',
  31. consignee: '',
  32. phone: '',
  33. hiddenmodal: true,
  34. minNum: 0,//优惠金额
  35. coupon_id: '',
  36. couponName: '', //优惠劵名称
  37. invoice: false,
  38. invCont: '我要开发票',
  39. //发票信息
  40. invoice_send_flag: 3,
  41. invoice_flag: 3, //发票标志位,如果为3,则为不开发票
  42. invoice_type_name: '',//发票类型名称
  43. invoice_company_name: '',//发票公司名字(纸质单位和增值单位的公司名称相同)
  44. invoice_number: '', //纳税人识别号
  45. invoice_address: '',//注册地址
  46. invoice_telphone: '',//注册电话
  47. invoice_brandName: '',//开户银行
  48. invoice_brandNum: '',//银行账户
  49. invoice_company_content: '',//增值发票内容
  50. invoice_price: '',//发票金额
  51. invoice_title: '',//纸质个人发票抬头
  52. invoice_company_title: '',//纸质单位和增值发票抬头
  53. invoice_takeName: '',//收货姓名
  54. invoice_takeTelphone: '',//收货人联系方式
  55. invoice_takeAddress: '',//收货人地址
  56. invoiceTypeFlag: 0,
  57. orderState: 0,
  58. orderState1: 0,
  59. stateNum: 0,
  60. maskBg: false,//支付提示蒙层
  61. agrService: true,//同意服务协议
  62. upViewShow : false
  63. },
  64. onLoad: function (options) {
  65. wx.showNavigationBarLoading();
  66. var that = this;
  67. var carts = JSON.parse(options.carts);
  68. for (var i = 0; i < carts.length; i++) {
  69. var name = carts[i].name;
  70. name = name.replace(/zss/g, "&");
  71. carts[i].name = name;
  72. }
  73. that.setData({
  74. carts: carts
  75. })
  76. var carts = that.data.carts;
  77. var total = 0;
  78. var total2 = 0;
  79. for (var i = 0; i < that.data.carts.length; i++) {
  80. var boxPrice = that.data.carts[i].box_price;
  81. var goodsPrice = that.data.carts[i].cost;
  82. if (boxPrice == '' && boxPrice == null) {
  83. boxPrice = 0;
  84. }
  85. total += (parseFloat(goodsPrice) + parseFloat(boxPrice)) * (that.data.carts[i].num);
  86. }
  87. total2 = total - that.data.minNum;
  88. if (total == 0) {
  89. total = 0.01;
  90. }
  91. if (total2 == 0) {
  92. total2 = 0.01;
  93. }
  94. that.setData({
  95. carts: carts,
  96. total1: total,
  97. total2: total2
  98. })
  99. var host = getApp().globalData.servsers;
  100. var un_id = getApp().globalData.un_id;
  101. if (un_id != undefined && un_id != '' && un_id != null) {
  102. wx.request({
  103. url: host + "/adressapi/adressview",//收货地址
  104. data: {
  105. user_id: un_id
  106. },
  107. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  108. header: {
  109. 'Accept': 'application/json'
  110. },
  111. success: function (res) {
  112. that.setData({
  113. addressAll: res.data.rows
  114. });
  115. var len = that.data.addressAll.length;
  116. for (var i = 0; i < len; i++) {
  117. if (that.data.addressAll[i].adress_flag == 1) {
  118. that.setData({
  119. consignee: that.data.addressAll[i].consignee,
  120. phone: that.data.addressAll[i].phone,
  121. province: that.data.addressAll[i].province,
  122. city: that.data.addressAll[i].city,
  123. area: that.data.addressAll[i].area,
  124. adress: that.data.addressAll[i].adress
  125. })
  126. }
  127. }
  128. if (res == null || res.data == null) {
  129. console.error('网络请求失败');
  130. return;
  131. }
  132. wx.hideNavigationBarLoading(//加载完成后显示页面
  133. that.setData({
  134. hidden: ''
  135. })
  136. )
  137. }
  138. });
  139. //查询是否有默认地址,如有则直接返回默认地址所有信息
  140. //查询是否有发票信息
  141. wx.request({
  142. url: host + "invoiceapi/adressview",//发票
  143. data: {
  144. user_id: un_id
  145. },
  146. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  147. header: {
  148. 'Accept': 'application/json'
  149. },
  150. success: function (res) {
  151. var flag = res.data.rows;
  152. if (res.data.total > 0) {
  153. if (res.data.rows[0].invoice_flag == 0) {
  154. that.setData({
  155. invoice_flag: 0,
  156. invoice_send_flag: 0,
  157. invCont: '纸质普通发票',
  158. invoice: true,
  159. invoice_type_name: '纸质普通发票',
  160. invoice_title: '个人',
  161. invoice_name: res.data.rows[0].invoice_name,//个人姓名
  162. invoice_content: res.data.rows[0].invoice_content,//发票内容
  163. invoice_price: res.data.rows[0].invoice_price//金额
  164. })
  165. } else if (res.data.rows[0].invoice_flag == 1) {
  166. that.setData({
  167. invoice_flag: 1,
  168. invoice_send_flag: 1,
  169. invCont: '纸质普通发票',
  170. invoice: true,
  171. invoice_type_name: '纸质普通发票',
  172. invoice_company_title: '单位',
  173. invoice_company_name: res.data.rows[0].invoice_company_name,//单位名称
  174. invoice_number: res.data.rows[0].invoice_number,//纳税人识别号
  175. invoice_content: res.data.rows[0].invoice_content,//发票内容
  176. invoice_price: res.data.rows[0].invoice_price //金额
  177. })
  178. } else {
  179. that.setData({
  180. invoice_flag: 2,
  181. invoice_send_flag: 2,
  182. invCont: '增值税专用发票',
  183. invoice: true,
  184. invoice_type_name: '增值税专用发票',
  185. invoice_company_title: '单位',
  186. invoice_company_name: res.data.rows[0].invoice_company_name,//单位名称
  187. invoice_number: res.data.rows[0].invoice_number,//纳税人识别号
  188. invoice_address: res.data.rows[0].invoice_address,//注册地址
  189. invoice_telphone: res.data.rows[0].invoice_telphone,//注册电话
  190. invoice_brandName: res.data.rows[0].invoice_brandName,//开户银行
  191. invoice_brandNum: res.data.rows[0].invoice_brandNum,//银行账户
  192. invoice_company_content: '明细',//发票内容
  193. invoice_price: res.data.rows[0].invoice_price, //金额
  194. invoice_takeName: res.data.rows[0].invoice_takeName,
  195. invoice_takeTelphone: res.data.rows[0].invoice_takeTelphone,
  196. invoice_takeAddress: res.data.rows[0].invoice_takeAddress
  197. })
  198. }
  199. }
  200. if (res == null || res.data == null) {
  201. console.error('网络请求失败');
  202. return;
  203. }
  204. }
  205. })
  206. }
  207. },
  208. coupon: function () {//选择优惠劵
  209. wx.navigateTo({//把总价带过去,直接返回优惠之后的总价
  210. url: '/pages/mineCoupon/coupon?total2=' + this.data.total1
  211. })
  212. },
  213. invoice: function () {//我要开发票,把商品价钱带过来
  214. wx.navigateTo({
  215. url: '/pages/invoiceInfor/invoiceInfor?total1=' + this.data.total1
  216. })
  217. },
  218. checkboxChange: function (e) {
  219. var that = this;
  220. var datavalue = e.currentTarget.dataset.value;
  221. var invoice = this.data.invoice;
  222. if (invoice) {
  223. if (datavalue == 0) {
  224. that.setData({
  225. 'value': 1,
  226. 'checked': true,
  227. 'isShow': true,
  228. invCont: that.data.invoice_type_name
  229. })
  230. } else {
  231. that.setData({
  232. 'value': 0,
  233. 'checked': false,
  234. 'isShow': true,
  235. invCont: that.data.invoice_type_name
  236. })
  237. }
  238. }
  239. },
  240. agrService: function (e) {
  241. var that = this;
  242. var datavalue = e.currentTarget.dataset.value;
  243. if (datavalue == 0) {
  244. that.setData({
  245. servalue: 1,
  246. 'serchecked': true
  247. })
  248. } else {
  249. that.setData({
  250. servalue: 0,
  251. 'serchecked': false
  252. })
  253. }
  254. },
  255. save: function (e) {
  256. var that = this;
  257. var pages = getCurrentPages();
  258. var currPage = pages[pages.length - 1]; //当前页面
  259. var prevPage = pages[pages.length - 2]; //上一个页面
  260. var prevPageUrl = prevPage.route;
  261. that.setData({
  262. upViewShow : true
  263. })
  264. var province = that.data.province;
  265. if (province == '') {
  266. that.setData({
  267. hiddenmodal: false,
  268. })
  269. setTimeout(function () {
  270. that.setData({
  271. hiddenmodal: true
  272. })
  273. }, 1000)
  274. return false;
  275. }
  276. if (that.data.value == 0) {
  277. that.setData({
  278. invoice_flag: 3,
  279. invoice_send_flag: 3,
  280. invoice_type_name: '',//发票类型名称
  281. invoice_name: '',//个人名字
  282. invoice_content: '',//纸质发票内容
  283. invoice_company_name: '',//发票公司名字(纸质单位和增值单位的公司名称相同)
  284. invoice_number: '', //纳税人识别号
  285. invoice_address: '',//注册地址
  286. invoice_telphone: '',//注册电话
  287. invoice_brandName: '',//开户银行
  288. invoice_brandNum: '',//银行账户
  289. invoice_company_content: '',//增值发票内容
  290. invoice_price: '',//发票金额
  291. invoice_title: '',//纸质个人发票抬头
  292. invoice_company_title: '',//纸质单位和增值发票抬头
  293. invoice_takeName: '',//收货姓名
  294. invoice_takeTelphone: '',//收货人联系方式
  295. invoice_takeAddress: ''//收货人地址
  296. })
  297. }
  298. var timestamp = Date.parse(new Date());
  299. timestamp = timestamp / 1000;
  300. var timestamp1 = timestamp;
  301. var host = getApp().globalData.servsers;
  302. var un_id = getApp().globalData.un_id;
  303. var user_num = parseInt(that.data.carts[0].user_num) - parseInt(that.data.carts[0].num);//上线数量
  304. if (user_num <= -1){
  305. that.setData({
  306. hiddenmodal: false,
  307. modalCont: '数量已达上限'
  308. })
  309. setTimeout(function () {
  310. that.setData({
  311. hiddenmodal: true
  312. })
  313. }, 1000)
  314. return false;
  315. }else{
  316. if (un_id != undefined && un_id != '' && un_id != null){
  317. //获取该用户下的该商品限购数量
  318. wx.request({
  319. url: host + "userapi/user_fake_split_view",
  320. data: {
  321. user_id: that.data.user_id
  322. },
  323. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  324. header: {
  325. 'Accept': 'application/json'
  326. },
  327. success: function (res) {
  328. that.setData({
  329. user_allow_num: res.data.rows[0].user_num
  330. })
  331. if (res.data.rows[0].user_num <= 0) {
  332. that.setData({
  333. hiddenmodal: false,
  334. modalCont: '数量已达上限'
  335. })
  336. setTimeout(function () {
  337. that.setData({
  338. hiddenmodal: true
  339. })
  340. }, 1000)
  341. return false;
  342. } else {
  343. }
  344. }
  345. })
  346. wx.request({
  347. url: host + "orderapi/insertorder",
  348. data: {
  349. order_userid: un_id,
  350. order_sta: '1',
  351. order_number: timestamp,
  352. order_type: '0',
  353. order_Consignee: that.data.consignee,
  354. order_phone: that.data.phone,
  355. order_address: that.data.province +
  356. that.data.city + that.data.area + that.data.adress,
  357. order_commodityid: that.data.carts[0].id,
  358. order_num: that.data.carts[0].num,
  359. order_Price: 0,//////
  360. orderr_Coupon: that.data.minNum,
  361. coupon_id: that.data.coupon_id,
  362. order_Specifications: '',
  363. order_gixbox: '',
  364. invoice_send_flag: that.data.invoice_send_flag,
  365. invoice_flag: that.data.invoice_flag, //发票标志位
  366. invoice_type_name: that.data.invoice_type_name,//发票类型名称
  367. invoice_name: that.data.invoice_name,//个人名字
  368. invoice_content: that.data.invoice_content,//纸质发票内容
  369. invoice_company_name: that.data.invoice_company_name,//发票公司名字(纸质单位和增值单位的公司名称相同)
  370. invoice_number: that.data.invoice_number, //纳税人识别号
  371. invoice_address: that.data.invoice_address,//注册地址
  372. invoice_telphone: that.data.invoice_telphone,//注册电话
  373. invoice_brandName: that.data.invoice_brandName,//开户银行
  374. invoice_brandNum: that.data.invoice_brandNum,//银行账户
  375. invoice_company_content: that.data.invoice_company_content,//增值发票内容
  376. invoice_price: that.data.invoice_price,//发票金额
  377. invoice_title: that.data.invoice_title,//纸质个人发票抬头
  378. invoice_company_title: that.data.invoice_company_title,//纸质单位和增值发票抬头
  379. invoice_takeName: that.data.invoice_takeName,//收货姓名
  380. invoice_takeTelphone: that.data.invoice_takeTelphone,//收货人联系方式
  381. invoice_takeAddress: that.data.invoice_takeAddress//收货人地址
  382. },
  383. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  384. header: {
  385. 'Accept': 'application/json'
  386. },
  387. success: function (res) {
  388. if (res == null || res.data == null) {
  389. console.error('网络请求失败');
  390. return;
  391. }
  392. }
  393. });
  394. for (var i = 0; i < that.data.carts.length; i++) {
  395. wx.request({
  396. url: host + "orderaffapi/insertOrderAff",
  397. data: {
  398. order_number: timestamp,
  399. cost: that.data.carts[i].cost,
  400. com_id: that.data.carts[i].com_id,
  401. logo: that.data.carts[i].logo,
  402. name: that.data.carts[i].name,
  403. num: that.data.carts[i].num,
  404. process: that.data.carts[i].process,
  405. giftbox_name: that.data.carts[i].giftbox_name,
  406. giftbox_id: that.data.carts[i].giftbox,
  407. box_price: that.data.carts[i].box_price,
  408. process_name: that.data.carts[i].process_name,
  409. process_id: that.data.carts[i].process,
  410. logo: that.data.carts[i].logo,
  411. style1: that.data.carts[i].style1,
  412. style1_name: that.data.carts[i].style1_name,
  413. style2: that.data.carts[i].style2,
  414. style2_name: that.data.carts[i].style2_name,
  415. style3: that.data.carts[i].style3,
  416. style3_name: that.data.carts[i].style3_name,
  417. style4: that.data.carts[i].style4,
  418. style4_name: that.data.carts[i].style4_name,
  419. style5: that.data.carts[i].style5,
  420. style5_name: that.data.carts[i].style5_name,
  421. },
  422. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  423. header: {
  424. 'Accept': 'application/json'
  425. },
  426. success: function (res) {
  427. var stateNum = 0;
  428. for (var i = 0; i < that.data.carts.length; i++) {
  429. if ((that.data.carts[i].process_name != '') && (that.data.carts[i].process != -1)) {
  430. stateNum++;
  431. }
  432. }
  433. if (stateNum > 0) {
  434. that.setData({
  435. orderState1: 2
  436. })
  437. } else {
  438. that.setData({
  439. orderState1: 3
  440. })
  441. }
  442. if (res == null || res.data == null) {
  443. console.error('网络请求失败');
  444. return;
  445. }
  446. }
  447. })
  448. }
  449. //获取用户登录状态
  450. wx.login({
  451. success: function (res) {
  452. //发起网络请求,发起的是HTTPS请求,向服务端请求预支付
  453. var code = res.code;
  454. var title = that.data.carts[0].name;
  455. var price = that.data.total2 * 100;
  456. price = 1;
  457. var timestamp = String(Date.parse(new Date())) //时间戳
  458. wx.request({
  459. url: host + 'prepay',
  460. data: {
  461. code: code,
  462. price: price,
  463. title: title,
  464. order_number: timestamp1
  465. },
  466. success: function (res) {
  467. wx.hideLoading()
  468. that.setData({
  469. maskBg: false
  470. })
  471. if (res.data.result == true) {
  472. var nonceStr = res.data.nonceStr;
  473. var prepayId = res.data.prepayId;
  474. console.log("1:" + nonceStr);
  475. // 按照字段首字母排序组成新字符串
  476. var payDataA = "appId=wx9e3f68fa2172f1c7&nonceStr=" + res.data.nonceStr + "&package=prepay_id=" + res.data.prepayId + "&signType=MD5&timeStamp=" + timestamp;
  477. var payDataB = payDataA + "&key=MlxMZWpZidKxCPPaOOztMP84XvQzqSOh";
  478. // 使用MD5加密算法计算加密字符串
  479. paySign = MD5Util.MD5(payDataB).toUpperCase();
  480. // 使用MD5加密算法计算加密字符串
  481. var paySign = MD5Util.MD5(payDataB).toUpperCase();
  482. wx.request({
  483. url: host + "orderapi/update",
  484. data: {
  485. order_sta: that.data.orderState1,
  486. order_number: timestamp1,
  487. orderState: that.data.orderState1
  488. },
  489. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  490. header: {
  491. 'Accept': 'application/json'
  492. },
  493. success: function (res) {
  494. //获取该用户下的该商品限购数量
  495. wx.request({
  496. url: host + "userapi/user_fake_split_update",
  497. data: {
  498. user_id: un_id,
  499. user_num: user_num,
  500. },
  501. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  502. header: {
  503. 'Accept': 'application/json'
  504. },
  505. success: function (res) {
  506. // that.setData({
  507. // user_allow_num: res.data.result
  508. // })
  509. }
  510. })
  511. wx.redirectTo({
  512. url: '/pages/orderList/orderList?isSelect=0'
  513. })
  514. if (res == null || res.data == null) {
  515. console.error('网络请求失败');
  516. return;
  517. }
  518. }
  519. });
  520. } else {
  521. console.log('请求失败' + res.data.info)
  522. }
  523. }
  524. })
  525. }
  526. });
  527. }
  528. }
  529. }
  530. })
  531. var that;
  532. var Util = require('../../utils/util.js');