Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

536 rindas
14 KiB

  1. const config = require('../../config/config.js')
  2. const Http = require('../../utils/HttpBasics.js')
  3. const util = require('../../utils/util.js')
  4. const app = getApp();
  5. Page({
  6. data: {
  7. recentlyList: [],
  8. Switch: true,
  9. todayTimer: '',
  10. todayMoney: '',
  11. money: '',
  12. loading: false,
  13. flag: true,
  14. val: '',
  15. submitText: '确认收款',
  16. submitDisabled: false,
  17. timeCount: 0,
  18. showDetailIf: false,
  19. copenid: '',
  20. subappid: '',
  21. receiverAccount: "",
  22. haveData: '',
  23. haveIf: false,
  24. shijiNum: '',
  25. shiji1: ''
  26. },
  27. hideKey() {
  28. this.setData({
  29. flag: false
  30. })
  31. },
  32. search() {
  33. this.setData({
  34. flag: true
  35. })
  36. },
  37. countChange(e) {
  38. console.log(e)
  39. let a = [];
  40. a = e.detail.value.split('.');
  41. if (a.length > 1) {
  42. a[1] = a[1].substring(0, 2)
  43. }
  44. // wx.navigateTo({
  45. // url: '/pages/payment/mjCoupon/mjCoupon?val=' + this.data.val + '&END=' + this.data.END + '&ID=' + this.data.ID + '&TYPE=' + this.data.TYPE + '&coupon_id=' + this.data.coupon_id,
  46. // })
  47. this.setData({
  48. val: a.join('.'),
  49. coupon_id: '',
  50. ID: '',
  51. price: 0,
  52. title: '',
  53. shiji1: a.join('.'),
  54. phone: ''
  55. })
  56. if (this.data.price) {
  57. this.setData({
  58. haveIf: false
  59. })
  60. }
  61. },
  62. //查看收银记录
  63. searchDetail() {
  64. wx.redirectTo({
  65. url: '../record/list/index',
  66. })
  67. },
  68. //补充会员信息
  69. addMember() {
  70. wx.redirectTo({
  71. url: '../membersinfo/index?copenid=' + this.data.copenid + '&subappid=' + this.data.subappid,
  72. })
  73. },
  74. //扫码支付
  75. submit(e) {
  76. console.log(this.data.composeOrderId, "composeOrderId")
  77. console.log(e, Number(this.data.val))
  78. let _this = this;
  79. console.log(_this.data.val, _this.data.price / 100, _this.data.orderId)
  80. if (!_this.data.price) {
  81. // 只允许从相机扫码
  82. if (_this.data.val.split('.')[0] && Number(_this.data.val) > 0 && Number(_this.data.val) <= 10000000) {
  83. wx.scanCode({
  84. onlyFromCamera: true,
  85. success(res) {
  86. let postData = {
  87. authCode: res.result,
  88. totalFee: _this.data.val,
  89. }
  90. _this.setData({
  91. submitText: '收款中',
  92. submitDisabled: true
  93. })
  94. wx.showLoading({
  95. title: '收款中!',
  96. })
  97. if (res.result) {
  98. _this.orderCreate(_this, postData)
  99. } else {
  100. console.log(333)
  101. }
  102. }
  103. })
  104. } else {
  105. wx.showToast({
  106. title: '请输入有效金额!',
  107. icon: 'none',
  108. duration: 2000,
  109. mask: false
  110. });
  111. }
  112. } else {
  113. // 只允许从相机扫码
  114. if (_this.data.val.split('.')[0] && Number(_this.data.val) > 0 && Number(_this.data.val) <= 10000000 && this.data.shiji1 > 0) {
  115. wx.scanCode({
  116. onlyFromCamera: true,
  117. success(res) {
  118. let postData = {
  119. authCode: res.result,
  120. payPrice: _this.data.val,
  121. couponOrderId: _this.data.coupon_id,
  122. orderId: _this.data.composeOrderId,
  123. }
  124. _this.setData({
  125. submitText: '收款中',
  126. submitDisabled: true,
  127. })
  128. wx.showLoading({
  129. title: '收款中!',
  130. })
  131. if (res.result) {
  132. _this.orderCreate2(_this, postData)
  133. } else {
  134. console.log(333)
  135. }
  136. }
  137. })
  138. } else if (_this.data.val.split('.')[0] && Number(_this.data.val) > 0 && Number(_this.data.val) <= 10000000 && this.data.shiji1 == 0) {
  139. let postData = {
  140. authCode: '',
  141. payPrice: _this.data.val,
  142. couponOrderId: _this.data.coupon_id,
  143. orderId: _this.data.composeOrderId,
  144. }
  145. _this.setData({
  146. submitText: '收款中',
  147. submitDisabled: true,
  148. })
  149. wx.showLoading({
  150. title: '收款中!',
  151. })
  152. _this.orderCreate2(_this, postData)
  153. } else {
  154. wx.showToast({
  155. title: '请输入有效金额!',
  156. icon: 'none',
  157. duration: 2000,
  158. mask: false
  159. });
  160. }
  161. }
  162. // wx.showLoading({
  163. // title: '收款中',
  164. // })
  165. },
  166. // 刷卡支付订单
  167. orderCreate(_this, postData) {
  168. Http.post({
  169. url: config.api.orderCreate,
  170. data: postData
  171. })
  172. .then(res => {
  173. console.log(res, 666)
  174. let postData = {
  175. payOrderId: res.data.payOrderId,
  176. orderId: res.data.orderId
  177. }
  178. _this.orderQuery(_this, postData)
  179. })
  180. .catch(err => {
  181. if (err.code == '1002') {
  182. wx.showToast({
  183. title: err.message,
  184. icon: "none",
  185. duration: 2000
  186. })
  187. _this.setData({
  188. submitText: '收款',
  189. submitDisabled: false
  190. })
  191. }
  192. let postData = {
  193. payOrderId: err.data.payOrderId,
  194. orderId: err.data.orderId
  195. }
  196. if (err.data.err_code == 'USERPAYING') {
  197. setTimeout(function () {
  198. _this.orderQuery(_this, postData);
  199. // 调用超过三次
  200. _this.setData({
  201. timeCount: _this.data.timeCount + 1
  202. })
  203. }, 3000);
  204. } else if (err.data.err_code == 'SYSTEMERROR' || err.data.err_code == 'BANKERROR') {
  205. setTimeout(function () {
  206. _this.orderQuery(_this, postData);
  207. // 调用超过三次
  208. _this.setData({
  209. timeCount: _this.data.timeCount + 1
  210. })
  211. }, 1000);
  212. }
  213. else {
  214. _this.orderReverse(_this, postData)
  215. wx.showToast({
  216. title: err.message,
  217. icon: 'none',
  218. duration: 2000,
  219. mask: false
  220. });
  221. }
  222. });
  223. },
  224. // 使用券刷卡支付订单
  225. orderCreate2(_this, postData) {
  226. Http.post({
  227. url: config.api.orderCreate2,
  228. data: postData
  229. })
  230. .then(res => {
  231. if (res && res.data.end == 1) {
  232. _this.setData({
  233. submitDisabled: false,
  234. submitText: '确认收款',
  235. haveIf: false
  236. })
  237. wx.hideLoading()
  238. wx.showLoading({
  239. title: '收款成功!',
  240. })
  241. setTimeout(function () {
  242. wx.hideLoading()
  243. }, 2000);
  244. return
  245. }
  246. console.log(res, 666)
  247. let postData = {
  248. payOrderId: res.data.payOrderId,
  249. orderId: res.data.orderId
  250. }
  251. _this.orderQuery(_this, postData)
  252. })
  253. .catch(err => {
  254. console.log(err)
  255. if (err.code == 4008) {
  256. wx.showModal({
  257. title: "提示",
  258. content: err.message,
  259. showCancel: false,
  260. success: function (res) {
  261. console.log(res)
  262. if (res.confirm) {
  263. _this.setData({
  264. submitDisabled: false,
  265. submitText: '确认收款',
  266. haveIf: false
  267. })
  268. }
  269. }
  270. })
  271. // _this.setData({
  272. // submitDisabled: false,
  273. // submitText: '确认收款',
  274. // })
  275. }
  276. let postData = {
  277. payOrderId: err.data.payOrderId,
  278. orderId: err.data.orderId
  279. }
  280. if (err.data.err_code == 'USERPAYING') {
  281. setTimeout(function () {
  282. _this.orderQuery(_this, postData);
  283. // 调用超过三次
  284. _this.setData({
  285. timeCount: _this.data.timeCount + 1
  286. })
  287. }, 3000);
  288. } else if (err.data.err_code == 'SYSTEMERROR' || err.data.err_code == 'BANKERROR') {
  289. setTimeout(function () {
  290. _this.orderQuery(_this, postData);
  291. // 调用超过三次
  292. _this.setData({
  293. timeCount: _this.data.timeCount + 1
  294. })
  295. }, 1000);
  296. }
  297. else {
  298. _this.orderReverse(_this, postData)
  299. wx.showToast({
  300. title: err.message,
  301. icon: 'none',
  302. duration: 2000,
  303. mask: false
  304. });
  305. }
  306. });
  307. },
  308. // 查询刷卡支付订单
  309. orderQuery(_this, postData) {
  310. Http.post({
  311. url: config.api.orderQuery,
  312. data: postData
  313. })
  314. .then(res => {
  315. console.log(666)
  316. if (this.data.price) { }
  317. _this.setData({
  318. subappid: res.data.sub_appid,
  319. copenid: res.data.sub_openid,
  320. submitText: '继续收款',
  321. submitDisabled: false,
  322. showDetailIf: true,
  323. timeCount: 0,
  324. val: '',
  325. // orderId: this.data.orderId
  326. // loading:true
  327. })
  328. wx.hideLoading()
  329. wx.showLoading({
  330. title: '收款成功!',
  331. })
  332. setTimeout(function () {
  333. wx.hideLoading()
  334. }, 2000);
  335. })
  336. .catch(err => {
  337. if (err.data.trade_state == 'USERPAYING') {
  338. if (_this.data.timeCount < 10) {
  339. setTimeout(function () {
  340. _this.orderQuery(_this, postData);
  341. // USERPAYING状态下, 且不超过30秒时继续调用查询
  342. _this.setData({
  343. timeCount: _this.data.timeCount + 1
  344. })
  345. }, 3000);
  346. } else {
  347. _this.orderReverse(_this, postData)
  348. }
  349. } else if (err.data.trade_state == 'BANKERROR') {
  350. setTimeout(function () {
  351. _this.orderQuery(_this, postData);
  352. }, 5000)
  353. } else if (err.data.trade_state == 'SYSTEMERROR') {
  354. setTimeout(function () {
  355. _this.orderQuery(_this, postData);
  356. }, 3000);
  357. }
  358. else {
  359. _this.orderReverse(_this, postData)
  360. wx.showToast({
  361. title: err.message,
  362. icon: 'none',
  363. duration: 2000,
  364. mask: false
  365. });
  366. _this.setData({
  367. submitText: '继续收款',
  368. submitDisabled: false,
  369. // loading:true
  370. })
  371. }
  372. });
  373. },
  374. // 撤销刷卡支付订单
  375. orderReverse(_this, postData) {
  376. wx.hideLoading()
  377. Http.post({
  378. url: config.api.orderReverse,
  379. data: postData
  380. })
  381. .then(res => {
  382. console.log(666)
  383. wx.showToast({
  384. title: res.message,
  385. icon: 'none',
  386. duration: 2000,
  387. mask: false
  388. });
  389. _this.setData({
  390. submitText: '继续收款',
  391. submitDisabled: false,
  392. timeCount: 0,
  393. val: ''
  394. // loading:true
  395. })
  396. })
  397. .catch(err => {
  398. wx.showToast({
  399. title: err.message,
  400. icon: 'none',
  401. duration: 2000,
  402. mask: false
  403. });
  404. });
  405. },
  406. onLoad: function (options) {
  407. console.log(options)
  408. },
  409. onShow: function (options) {
  410. let that = this;
  411. console.log(that.data)
  412. console.log(that.data.price, (that.data.val * 100).toFixed(2))
  413. if (that.data.price) {
  414. let shiji = ((that.data.val * 100).toFixed(2) - that.data.price) / 100
  415. that.setData({
  416. haveIf: true,
  417. shiji1: shiji
  418. })
  419. }
  420. app.globalData.userInfo().then(res => {
  421. that.setData({
  422. userInfo: res
  423. })
  424. if (res && res.merchant_id) {
  425. that.findAccountById(res);
  426. that.findJurisdiction()
  427. }
  428. })
  429. },
  430. /**
  431. * 查询是否有修改账户权限
  432. */
  433. findJurisdiction() {
  434. Http.get({
  435. url: config.api.permitModifiy,
  436. }).then(res => {
  437. // console.log(res)
  438. /**
  439. * data:true
  440. * 如有:显示
  441. * 没有;不显示
  442. */
  443. if (res && res.data == true) {
  444. this.setData({
  445. haveData: true,
  446. })
  447. } else {
  448. this.setData({
  449. haveData: false,
  450. })
  451. }
  452. }).catch(error => {
  453. console.log(error)
  454. })
  455. },
  456. /**
  457. * 查询收款账户状态
  458. */
  459. findAccountById(response) {
  460. let that = this;
  461. Http.get({
  462. url: config.api.findAccountById,
  463. data: {
  464. id: response.merchant_id
  465. }
  466. }).then(res => {
  467. /**
  468. * receiverAccount
  469. * 如有:已设置收款账户
  470. * 没有;未设置收款账户
  471. */
  472. if (res && res.data && res.data.receiver) {
  473. that.setData({
  474. receiverAccount: res.data.receiver.receiverAccount
  475. })
  476. } else {
  477. wx.showModal({
  478. title: '提醒',
  479. content: '您暂未配置收款账户,请配置',
  480. showCancel: false,
  481. success: function (res) {
  482. console.log(res)
  483. if (res.confirm) {
  484. if (that.data.haveData == true) {
  485. wx.switchTab({
  486. url: '/pages/main/main',
  487. })
  488. } else {
  489. wx.switchTab({
  490. url: '/pages/main/main',
  491. })
  492. }
  493. }
  494. }
  495. })
  496. }
  497. }).catch(error => {
  498. console.log(error)
  499. })
  500. },
  501. /**
  502. * 跳转获得券
  503. */
  504. change() {
  505. console.log(this.data)
  506. console.log(this.data.val)
  507. let _this = this;
  508. if (_this.data.val.split('.')[0] && Number(_this.data.val) > 0 && Number(_this.data.val) <= 10000000) {
  509. if (this.data.phone) {
  510. wx.navigateTo({
  511. url: '/pages/payment/mjCoupon/mjCoupon?val=' + this.data.val + '&phone=' + this.data.phone + '&coupon_id=' + this.data.coupon_id,
  512. })
  513. } else if (this.data.END) {
  514. wx.navigateTo({
  515. url: '/pages/payment/mjCoupon/mjCoupon?val=' + this.data.val + '&END=' + this.data.END + '&ID=' + this.data.ID + '&TYPE=' + this.data.TYPE + '&coupon_id=' + this.data.coupon_id,
  516. })
  517. } else {
  518. wx.navigateTo({
  519. url: '/pages/payment/mjCoupon/mjCoupon?val=' + this.data.val,
  520. })
  521. }
  522. } else {
  523. wx.showToast({
  524. title: '抱歉,您还没填收款金额',
  525. icon: 'none',
  526. duration: 2000,
  527. mask: false
  528. });
  529. }
  530. },
  531. })