trade.js 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  1. define([], function () {
  2. var trade = {};
  3. var reg_credit = /^[+-]?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/i;
  4. var reg_int = /^[0-9]\d*$/i;
  5. trade.init = function () {
  6. $('.modal-trade-credit1, .modal-trade-credit2, .modal-trade-consume, .modal-trade-card, .modal-trade-cardsn, .modal-trade-cardconsume').on('click', function () {
  7. $('#consume-Modal, #credit-Modal, #card-Modal, #card-edit-Modal, #group-Modal, #cardconsume-Modal').remove();
  8. var type = $(this).data('type');
  9. var uid = parseInt($(this).data('uid'));
  10. var title = $(this).data('title');
  11. if (type == 'consume') {
  12. trade.consume(uid);
  13. } else if (type == 'credit1' || type == 'credit2') {
  14. trade.credit(type, uid, title);
  15. } else if (type == 'card') {
  16. trade.card(uid);
  17. } else if (type == 'cardsn') {
  18. trade.card_edit(uid);
  19. } else if (type == 'cardconsume') {
  20. trade.cardconsume();
  21. }
  22. });
  23. };
  24. trade.consume = function (uid) {
  25. var html = '<div class="modal fade" id="consume-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">' +
  26. ' <div class="modal-dialog modal-lg" role="document">' +
  27. ' <div class="modal-content">' +
  28. ' <form class="table-responsive form-inline" method="post" action="" id="form-consume">' +
  29. ' <div class="modal-header">' +
  30. ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
  31. ' <h4 class="modal-title" id="myModalLabel">会员消费</h4>' +
  32. ' </div>' +
  33. ' <div class="modal-body">' +
  34. ' <table class="table table-hover table-bordered">' +
  35. ' <tr>' +
  36. ' <th width="150">' +
  37. ' <select name="type" id="type">' +
  38. ' <option value="mobile">手机号</option>' +
  39. ' <option value="uid">会员UID</option>' +
  40. ' </select>' +
  41. ' </th>' +
  42. ' <td>' +
  43. ' <div class="form-group">' +
  44. ' <input type="text" value="" name="username" id="username" class="form-control"/>' +
  45. ' </div>' +
  46. ' </td>' +
  47. ' </tr>' +
  48. ' <tr id="user" style="display: none">' +
  49. ' <th>会员信息</th>' +
  50. ' <td>' +
  51. ' <div class="form-group">' +
  52. ' <div class="input-group">' +
  53. ' <strong class="form-control-static"></strong>' +
  54. ' </div>' +
  55. ' </div>' +
  56. ' </td>' +
  57. ' </tr>' +
  58. ' <tr>' +
  59. ' <th>消费总计</th>' +
  60. ' <td>' +
  61. ' <div class="form-group">' +
  62. ' <div class="input-group">' +
  63. ' <input type="text" value="" name="total" id="total" class="form-control"/>' +
  64. ' <span class="input-group-addon">元</span>' +
  65. ' </div>' +
  66. ' </div>' +
  67. ' </td>' +
  68. ' </tr>' +
  69. ' <tr>' +
  70. ' <th>实收金额</th>' +
  71. ' <td>' +
  72. ' <div class="input-group">' +
  73. ' <input type="text" value="" name="money" id="money" class="form-control" readonly/>' +
  74. ' <span class="input-group-addon">元</span>' +
  75. ' </div>' +
  76. ' </td>' +
  77. ' </tr>' +
  78. ' <tr>' +
  79. ' <th rowspan="3">支付方式</th>' +
  80. ' <td>' +
  81. ' <label class="checkbox-inline">' +
  82. ' <input type="checkbox" name="is_credit2_pay" id="is_credit2_pay" value="1" /> 余额支付' +
  83. ' </label>' +
  84. ' <div class="form-group">' +
  85. ' <div class="input-group">' +
  86. ' <input type="text" value="0" name="credit2" id="credit2" disabled class="form-control"/>' +
  87. ' <span class="input-group-addon">元</span>' +
  88. ' </div>' +
  89. ' </div>' +
  90. ' </td>' +
  91. ' </tr>' +
  92. ' <tr>' +
  93. ' <td>' +
  94. ' <label class="checkbox-inline">' +
  95. ' <input type="checkbox" name="is_credit1_pay" id="is_credit1_pay" value="1" /> 积分抵现' +
  96. ' </label>' +
  97. ' <div class="form-group">' +
  98. ' <div class="input-group">' +
  99. ' <input type="text" value="0" name="credit1" id="credit1" disabled class="form-control"/>' +
  100. ' <span class="input-group-addon">积分 抵消</span>' +
  101. ' <input type="text" value="0" name="offset_money" id="offset_money" disabled class="form-control"/>' +
  102. ' <span class="input-group-addon">元</span>' +
  103. ' </div>' +
  104. ' </div>' +
  105. ' </td>' +
  106. ' </tr>' +
  107. ' <tr>' +
  108. ' <td>' +
  109. ' <label class="checkbox-inline">' +
  110. ' <input type="checkbox" value="1" name="is_cash_pay" id="is_cash_pay" /> 现金支付' +
  111. ' </label>' +
  112. ' <div class="form-group">' +
  113. ' <div class="input-group">' +
  114. ' <input type="text" value="0" name="cash" id="cash" disabled class="form-control"/>' +
  115. ' <span class="input-group-addon">元  找零</span>' +
  116. ' <input type="text" value="0" name="return_cash" id="return_cash" disabled class="form-control"/>' +
  117. ' <span class="input-group-addon">元</span>' +
  118. ' </div>' +
  119. ' </div>' +
  120. ' </td>' +
  121. ' </tr>' +
  122. ' <tr>' +
  123. ' <th>备注</th>' +
  124. ' <td>' +
  125. ' <textarea name="remark" class="form-control" cols="81"></textarea>' +
  126. ' </td>' +
  127. ' </tr>' +
  128. ' </table>' +
  129. ' </div>' +
  130. ' <div class="modal-footer">' +
  131. ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>' +
  132. ' <input type="button" class="btn btn-primary" id="submit-form" value="提交">' +
  133. ' </div>' +
  134. ' </form>' +
  135. ' </div>' +
  136. ' </div>' +
  137. '</div>';
  138. require(['validator'], function () {
  139. $('#consume-Modal').remove();
  140. $(document.body).append(html);
  141. var dialog = $('#consume-Modal');
  142. dialog.modal('show');
  143. $('#username').focus();
  144. $('#form-consume').bootstrapValidator({
  145. fields: {
  146. username: {
  147. validators: {
  148. notEmpty: {
  149. message: '请填写用户手机或UID'
  150. }
  151. }
  152. },
  153. total: {
  154. validators: {
  155. notEmpty: {
  156. message: '请填写消费总计'
  157. },
  158. regexp: {
  159. regexp: reg_credit,
  160. message: '最多只保留小数点后2位的正数'
  161. }
  162. }
  163. },
  164. credit2: {
  165. validators: {
  166. notEmpty: {
  167. message: '请填写余额支付金额'
  168. },
  169. regexp: {
  170. regexp: reg_credit,
  171. message: '最多只保留小数点后2位的正数'
  172. },
  173. between: {
  174. min: 0,
  175. max: 100000000,
  176. money: 0,
  177. message: '超出可用余额'
  178. }
  179. }
  180. },
  181. credit1: {
  182. validators: {
  183. notEmpty: {
  184. message: '请填写积分数量'
  185. },
  186. regexp: {
  187. regexp: reg_int,
  188. message: '积分数量只能是正整数'
  189. },
  190. between: {
  191. min: 0,
  192. max: 1000000000,
  193. message: '超出会员所拥有的积分或超出最多可抵消金额'
  194. }
  195. }
  196. },
  197. cash: {
  198. validators: {
  199. notEmpty: {
  200. message: '请填写现金支付金额'
  201. },
  202. regexp: {
  203. regexp: reg_credit,
  204. message: '最多只保留小数点后2位的正数'
  205. }
  206. }
  207. }
  208. }
  209. });
  210. var Validator = $('#form-consume').data('bootstrapValidator');
  211. var consume = {
  212. 'user': {},
  213. 'card': {},
  214. 'total': 0,
  215. 'money': 0,
  216. 'last_money': 0,
  217. 'return_cash': 0,
  218. 'is_credit1_pay': false,
  219. 'is_credit2_pay': false,
  220. 'is_cash_pay': false,
  221. 'credit1': 0,
  222. 'credit2': 0,
  223. 'cash': 0,
  224. 'offset_money': 0,
  225. 'password': '',
  226. 'init': function (uid) {
  227. Validator.enableFieldValidators('credit2');
  228. Validator.enableFieldValidators('credit1');
  229. Validator.enableFieldValidators('cash');
  230. this.getuser();
  231. if (uid > 0) {
  232. $('#type').val('uid');
  233. $('#username').val(uid);
  234. $('#username').trigger('blur');
  235. $('#username, #type').attr('disabled', true);
  236. }
  237. this.initmoney();
  238. this.initconsume();
  239. this.submit();
  240. },
  241. 'checkuser': function () {
  242. if (this.user.uid == undefined || !this.user.uid) {
  243. this.user = {};
  244. this.card = {};
  245. $('#username').focus();
  246. Validator.updateMessage('username', 'notEmpty', '未找到对应会员');
  247. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  248. //util.message('未找到对应会员');
  249. return false;
  250. }
  251. return true;
  252. },
  253. 'getuser': function () {
  254. var _this = this;
  255. $('#username').blur(function () {
  256. Validator.validateField('username');
  257. var username = $.trim($('#username').val());
  258. var type = $('#type').val();
  259. if (username) {
  260. $.post('./index.php?c=mc&a=trade&do=user&', {
  261. 'type': type,
  262. 'username': username
  263. }, function (data) {
  264. var data = $.parseJSON(data);
  265. if (data.error != 'none') {
  266. _this.user = {};
  267. _this.card = {};
  268. $('#user').hide();
  269. Validator.updateMessage('username', 'notEmpty', data.message);
  270. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  271. return false;
  272. } else {
  273. _this.user = data.user;
  274. _this.card = data.card;
  275. $('#user strong').html(data.html);
  276. $('#user').show();
  277. }
  278. });
  279. }
  280. });
  281. },
  282. 'initmoney': function () {
  283. var _this = this;
  284. $('#total').blur(function () {
  285. if (!_this.checkuser()) {
  286. return false;
  287. }
  288. var total = parseFloat($(this).val());
  289. _this.total = total;
  290. money = total;
  291. if (_this.user.discount && total >= _this.user.discount.condition) {
  292. if (_this.card.discount_type == 1) {
  293. money = total - _this.user.discount.discount;
  294. } else {
  295. if (!_this.user.discount.discount) {
  296. _this.user.discount.discount = 1;
  297. }
  298. money = total * _this.user.discount.discount;
  299. money = money.toFixed(1);
  300. }
  301. if (money < 0) {
  302. money = 0;
  303. }
  304. }
  305. $('#money').val(money);
  306. _this.money = money;
  307. _this.last_money = money;
  308. });
  309. },
  310. 'initcredit1': function () {
  311. var _this = this;
  312. $('#credit1').keyup(function () {
  313. if (!_this.checkuser()) {
  314. return false;
  315. }
  316. _this.credit1 = parseInt($(this).val());
  317. if (isNaN(_this.credit1)) {
  318. _this.credit1 = 0;
  319. }
  320. if (_this.credit1 >= 0 && _this.card.offset_rate > 0 && _this.card.offset_max > 0) {
  321. $('#offset_money').val(_this.credit1 / _this.card.offset_rate);
  322. _this.offset_money = _this.credit1 / _this.card.offset_rate;
  323. }
  324. var credit1 = parseInt($(this).val());
  325. if (_this.user.credit1 < credit1) {
  326. Validator.updateOption('credit1', 'between', 'max', _this.user.credit1);
  327. Validator.updateMessage('credit1', 'between', '超出会员账户可用积分');
  328. Validator.updateStatus('credit1', 'INVALID', 'between');
  329. } else if (_this.card && (_this.card.offset_rate > 0) && (_this.card.offset_max > 0) && (credit1 > (_this.card.offset_rate * _this.card.offset_max))) {
  330. Validator.updateOption('credit1', 'between', 'max', _this.card.offset_rate * _this.card.offset_max);
  331. Validator.updateMessage('credit1', 'between', '积分最多可抵消' + _this.card.offset_max);
  332. Validator.updateStatus('credit1', 'INVALID', 'between');
  333. }
  334. _this.updatereturn();
  335. });
  336. },
  337. 'initcredit2': function () {
  338. var _this = this;
  339. $('#credit2').keyup(function () {
  340. if (!_this.checkuser()) {
  341. return false;
  342. }
  343. var money = $('#money').val();
  344. if (money > 0) {
  345. var credit2 = parseFloat($('#credit2').val());
  346. if (_this.user.credit2 < credit2) {
  347. Validator.updateOption('credit2', 'between', 'max', _this.user.credit2);
  348. Validator.updateMessage('credit2', 'between', '超出会员账户可用余额');
  349. Validator.updateStatus('credit2', 'INVALID', 'between');
  350. } else if (credit2 > money) {
  351. Validator.updateOption('credit2', 'between', 'max', money);
  352. Validator.updateMessage('credit2', 'between', '使用余额不能大于应付金额');
  353. Validator.updateStatus('credit2', 'INVALID', 'between');
  354. }
  355. _this.credit2 = credit2;
  356. _this.updatereturn();
  357. }
  358. });
  359. },
  360. 'initcash': function () {
  361. var _this = this;
  362. $('#cash').keyup(function () {
  363. if (!_this.checkuser()) {
  364. return false;
  365. }
  366. var money = $('#money').val();
  367. if (money > 0) {
  368. var cash = parseFloat($('#cash').val());
  369. _this.cash = cash;
  370. _this.updatereturn();
  371. }
  372. });
  373. },
  374. 'updatereturn': function () {
  375. var _this = this;
  376. _this.return_cash = _this.money - _this.credit2 - _this.offset_money - _this.cash;
  377. if (_this.return_cash > 0) {
  378. _this.last_money = _this.return_cash;
  379. $('#return_cash').val(0);
  380. } else {
  381. _this.last_money = 0;
  382. $('#return_cash').val(Math.abs(_this.return_cash));
  383. }
  384. },
  385. 'updatecredit1': function () {
  386. var _this = this;
  387. if (_this.card.offset_rate > 0 && _this.card.offset_max > 0 && _this.last_money > 0) {
  388. var min = Math.min.apply(null, [_this.user.credit1, _this.card.offset_rate * _this.card.offset_max, _this.card.offset_rate * _this.last_money]);
  389. $('#credit1').val(min).focus().select();
  390. $('#offset_money').val(min / _this.card.offset_rate);
  391. _this.credit1 = min;
  392. _this.offset_money = min / _this.card.offset_rate;
  393. }
  394. },
  395. 'updatecredit2': function () {
  396. var _this = this;
  397. var min = Math.min(_this.user.credit2, _this.last_money);
  398. $('#credit2').val(min);
  399. _this.credit2 = min;
  400. },
  401. 'updatecash': function () {
  402. var _this = this;
  403. $('#cash').val(_this.last_money);
  404. _this.cash = _this.last_money;
  405. },
  406. 'initconsume': function () {
  407. var _this = this;
  408. _this.is_credit1_pay = $('#is_credit1_pay').prop('checked');
  409. _this.is_credit2_pay = $('#is_credit2_pay').prop('checked');
  410. _this.is_cash_pay = $('#is_cash_pay').prop('checked');
  411. _this.credit1 = parseInt($('#credit1').val());
  412. _this.credit2 = parseFloat($('#credit2').val());
  413. _this.cash = parseFloat($('#cash').val());
  414. _this.initcredit1();
  415. _this.initcredit2();
  416. _this.initcash();
  417. $('#is_credit1_pay').click(function () {
  418. if (!_this.checkuser()) {
  419. return false;
  420. }
  421. if (!_this.money) {
  422. Validator.updateStatus('total', 'INVALID', 'regexp');
  423. $('#total').focus().select();
  424. return false;
  425. }
  426. if (!$(this).prop('checked')) {
  427. //如果是非选中状态
  428. Validator.updateStatus('credit1', 'VALID');
  429. $('#credit1').attr('disabled', true);
  430. Validator.enableFieldValidators('credit1', false);
  431. $('#credit1').val(0);
  432. $('#offset_money').val(0);
  433. $(this).prop('checked', false);
  434. _this.is_credit1_pay = false;
  435. _this.credit1 = 0;
  436. _this.offset_money = 0;
  437. } else if (_this.last_money >= 0) {
  438. if (_this.last_money == 0) {
  439. return false;
  440. }
  441. _this.is_credit1_pay = true;
  442. $('#credit1').removeAttr('disabled');
  443. Validator.enableFieldValidators('credit1', true);
  444. _this.updatecredit1();
  445. }
  446. _this.updatereturn();
  447. });
  448. $('#is_credit2_pay').click(function () {
  449. if (!_this.checkuser()) {
  450. return false;
  451. }
  452. if (!_this.money) {
  453. Validator.updateStatus('total', 'INVALID', 'regexp');
  454. $('#total').focus().select();
  455. return false;
  456. }
  457. if (!$(this).prop('checked')) {
  458. //如果是非选中状态
  459. Validator.updateStatus('credit2', 'VALID');
  460. $('#credit2').attr('disabled', true);
  461. Validator.enableFieldValidators('credit2', false);
  462. $('#credit2').val(0);
  463. $(this).prop('checked', false);
  464. _this.is_credit2_pay = false;
  465. _this.credit2 = 0;
  466. } else if (_this.last_money >= 0) {
  467. if (_this.last_money == 0) {
  468. return false;
  469. }
  470. $('#credit2').removeAttr('disabled');
  471. Validator.enableFieldValidators('credit2', true);
  472. _this.is_credit2_pay = true;
  473. _this.updatecredit2();
  474. }
  475. _this.updatereturn();
  476. });
  477. $('#is_cash_pay').click(function () {
  478. if (!_this.checkuser()) {
  479. return false;
  480. }
  481. if (!_this.money) {
  482. Validator.updateStatus('total', 'INVALID', 'regexp');
  483. $('#total').focus().select();
  484. return false;
  485. }
  486. if (!$(this).prop('checked')) {
  487. //如果是非选中状态
  488. Validator.updateStatus('cash', 'VALID');
  489. $('#cash').attr('disabled', true);
  490. Validator.enableFieldValidators('cash', false);
  491. $('#cash').val(0);
  492. $(this).prop('checked', false);
  493. _this.is_cash_pay = false;
  494. _this.cash = 0;
  495. } else if (_this.last_money >= 0) {
  496. if (_this.last_money == 0) {
  497. return false;
  498. }
  499. $('#cash').removeAttr('disabled');
  500. Validator.enableFieldValidators('cash', true);
  501. _this.is_cash_pay = true;
  502. _this.updatecash();
  503. }
  504. _this.updatereturn();
  505. });
  506. },
  507. 'submit': function () {
  508. var _this = this;
  509. _this.updatereturn();
  510. $('#form-consume #submit-form').click(function () {
  511. Validator.validate();
  512. if (Validator.isValid()) {
  513. if (_this.last_money > 0) {
  514. util.message('支付金额小于实收金额,请检查表单');
  515. return false;
  516. }
  517. _this.password = $.trim($(':input[name="password"]').val());
  518. _this.remark = $.trim($('textarea[name="remark"]').val());
  519. var param = {
  520. 'uid': _this.user.uid,
  521. 'total': _this.total,
  522. 'money': _this.money,
  523. 'credit2': _this.credit2,
  524. 'credit1': _this.credit1,
  525. 'cash': _this.cash,
  526. 'offset_money': _this.offset_money,
  527. 'return_cash': _this.return_cash,
  528. 'password': _this.password,
  529. 'remark': _this.remark
  530. }
  531. $.post('./index.php?c=mc&a=trade&do=consume', param, function (data) {
  532. if (data != 'success') {
  533. util.message(data, '', 'error');
  534. return false;
  535. } else {
  536. dialog.modal('hide');
  537. util.message('交易成功', 'refresh', 'success');
  538. return false;
  539. }
  540. });
  541. }
  542. });
  543. }
  544. };
  545. consume.init(uid);
  546. });
  547. };
  548. trade.credit = function (type, uid, title) {
  549. var html = '<div class="modal fade" id="credit-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">' +
  550. ' <div class="modal-dialog modal-lg" role="document">' +
  551. ' <div class="modal-content">' +
  552. ' <form class="table-responsive form-inline" method="post" action="" id="form-credit">' +
  553. ' <div class="modal-header">' +
  554. ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
  555. ' <h4 class="modal-title" id="myModalLabel">会员' + title + '操作</h4>' +
  556. ' </div>' +
  557. ' <div class="modal-body">' +
  558. ' <table class="table table-hover table-bordered">' +
  559. ' <tr>' +
  560. ' <th width="150">' +
  561. ' <select name="type" id="type">' +
  562. ' <option value="mobile">手机号</option>' +
  563. ' <option value="uid">会员UID</option>' +
  564. ' </select>' +
  565. ' </th>' +
  566. ' <td>' +
  567. ' <div class="form-group">' +
  568. ' <input type="text" value="" name="username" id="username" class="form-control"/>' +
  569. ' </div>' +
  570. ' </td>' +
  571. ' </tr>' +
  572. ' <tr id="user" style="display: none">' +
  573. ' <th>会员信息</th>' +
  574. ' <td>' +
  575. ' <div class="form-group">' +
  576. ' <div class="input-group">' +
  577. ' <strong class="form-control-static"></strong>' +
  578. ' </div>' +
  579. ' </div>' +
  580. ' </td>' +
  581. ' </tr>' +
  582. ' <tr>' +
  583. ' <th>修改' + title + '(增减)</th>' +
  584. ' <td>' +
  585. ' <div class="form-group">' +
  586. ' <input type="text" value="" name="num" id="total" class="form-control"/>' +
  587. ' <div class="help-block">输入500,则标识增加500;输入-500则表示减少500</div>' +
  588. ' </div>' +
  589. ' </td>' +
  590. ' </tr>' +
  591. ' <tr>' +
  592. ' <th>备注</th>' +
  593. ' <td>' +
  594. ' <textarea name="remark" class="form-control" cols="96"></textarea>' +
  595. ' </td>' +
  596. ' </tr>' +
  597. ' </table>' +
  598. ' </div>' +
  599. ' <div class="modal-footer">' +
  600. ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>' +
  601. ' <input type="submit" class="btn btn-primary" id="submit" name="提交"value="提交">' +
  602. ' </div>' +
  603. ' </form>' +
  604. ' </div>' +
  605. ' </div>' +
  606. '</div>';
  607. require(['validator'], function () {
  608. $('#credit-Modal').remove();
  609. $(document.body).append(html);
  610. var dialog = $('#credit-Modal');
  611. dialog.modal('show');
  612. $('#form-credit').bootstrapValidator({
  613. fields: {
  614. username: {
  615. validators: {
  616. notEmpty: {
  617. message: '请填写用户手机或UID'
  618. }
  619. }
  620. },
  621. num: {
  622. validators: {
  623. notEmpty: {
  624. message: '请填写数量'
  625. },
  626. regexp: {
  627. regexp: /^[+-]?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/i,
  628. message: '最多只保留小数点后2位的正数'
  629. }
  630. }
  631. }
  632. }
  633. });
  634. var Validator = $('#form-credit').data('bootstrapValidator');
  635. var credit = {
  636. 'user': {},
  637. 'card': {},
  638. 'init': function (type, uid) {
  639. this.type = type,
  640. this.getuser();
  641. if (uid > 0) {
  642. $('#type').val('uid');
  643. $('#username').val(uid);
  644. $('#username').trigger('blur');
  645. $('#username, #type').attr('disabled', true);
  646. }
  647. this.submit();
  648. },
  649. getuser: function () {
  650. var _this = this;
  651. $('#username').blur(function () {
  652. Validator.validateField('username');
  653. var username = $.trim($('#username').val());
  654. var type = $('#type').val();
  655. if (username) {
  656. $.post('./index.php?c=mc&a=trade&do=user&', {
  657. 'type': type,
  658. 'username': username
  659. }, function (data) {
  660. var data = $.parseJSON(data);
  661. if (data.error != 'none') {
  662. _this.user = {};
  663. _this.card = {};
  664. $('#user').hide();
  665. Validator.updateMessage('username', 'notEmpty', data.message);
  666. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  667. return false;
  668. } else {
  669. _this.user = data.user;
  670. _this.card = data.card;
  671. $('#user strong').html(data.html);
  672. $('#user').show();
  673. }
  674. });
  675. }
  676. });
  677. },
  678. 'checkuser': function () {
  679. if (this.user.uid == undefined || !this.user.uid) {
  680. this.user = {};
  681. this.card = {};
  682. $('#username').focus();
  683. Validator.updateMessage('username', 'notEmpty', '未找到对应会员');
  684. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  685. //util.message('未找到对应会员');
  686. return false;
  687. }
  688. return true;
  689. },
  690. 'submit': function () {
  691. var _this = this;
  692. $('#form-credit .btn-primary').click(function () {
  693. _this.checkuser();
  694. Validator.validate();
  695. if (Validator.isValid()) {
  696. _this.password = $.trim($(':input[name="password"]').val());
  697. _this.num = $.trim($(':text[name="num"]').val());
  698. _this.remark = $.trim($('textarea[name="remark"]').val());
  699. var param = {
  700. 'uid': _this.user.uid,
  701. 'num': _this.num,
  702. 'password': _this.password,
  703. 'remark': _this.remark,
  704. 'type': _this.type
  705. }
  706. $.post('./index.php?c=mc&a=trade&do=credit', param, function (data) {
  707. if (data != 'success') {
  708. util.message(data, '', 'error');
  709. return false;
  710. } else {
  711. dialog.modal('hide');
  712. util.message('操作成功', 'refresh', 'success');
  713. return false;
  714. }
  715. });
  716. }
  717. });
  718. }
  719. };
  720. credit.init(type, uid);
  721. });
  722. };
  723. trade.card = function (uid) {
  724. var html = '<div class="modal fade" id="card-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">' +
  725. ' <div class="modal-dialog modal-lg" role="document">' +
  726. ' <div class="modal-content">' +
  727. ' <form class="table-responsive form-inline" method="post" action="" id="form-card">' +
  728. ' <div class="modal-header">' +
  729. ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
  730. ' <h4 class="modal-title" id="myModalLabel">发放会员卡</h4>' +
  731. ' </div>' +
  732. ' <div class="modal-body">' +
  733. ' <table class="table table-hover table-bordered">' +
  734. ' <tr>' +
  735. ' <th width="150">' +
  736. ' <select name="type" id="type" class="form-control">' +
  737. ' <option value="mobile">手机号</option>' +
  738. ' <option value="uid">会员UID</option>' +
  739. ' </select>' +
  740. ' </th>' +
  741. ' <td>' +
  742. ' <div class="form-group">' +
  743. ' <input type="text" value="" name="username" id="username" class="form-control"/>' +
  744. ' </div>' +
  745. ' </td>' +
  746. ' </tr>' +
  747. ' <tr id="user" style="display: none">' +
  748. ' <th>会员信息</th>' +
  749. ' <td>' +
  750. ' <div class="form-group">' +
  751. ' <div class="input-group">' +
  752. ' <strong class="form-control-static"></strong>' +
  753. ' </div>' +
  754. ' </div>' +
  755. ' </td>' +
  756. ' </tr>' +
  757. ' </table>' +
  758. ' </div>' +
  759. ' <div class="modal-footer">' +
  760. ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>' +
  761. ' <input type="submit" class="btn btn-primary" id="submit" name="提交"value="提交">' +
  762. ' </div>' +
  763. ' </form>' +
  764. ' </div>' +
  765. ' </div>' +
  766. '</div>';
  767. require(['validator'], function () {
  768. $('#card-Modal').remove();
  769. $(document.body).append(html);
  770. var dialog = $('#card-Modal');
  771. dialog.modal('show');
  772. $('#form-card').bootstrapValidator({
  773. fields: {
  774. username: {
  775. validators: {
  776. notEmpty: {
  777. message: '请填写用户手机或UID'
  778. }
  779. }
  780. }
  781. }
  782. });
  783. var Validator = $('#form-card').data('bootstrapValidator');
  784. var card = {
  785. 'user': {},
  786. 'card': {},
  787. 'init': function (uid) {
  788. this.getuser();
  789. if (uid > 0) {
  790. $('#type').val('uid');
  791. $('#username').val(uid);
  792. $('#username').trigger('blur');
  793. if (this.user.uid > 0) {
  794. $('#username, #type').attr('disabled', true);
  795. }
  796. }
  797. this.submit();
  798. },
  799. getuser: function () {
  800. var _this = this;
  801. $('#username').blur(function () {
  802. Validator.validateField('username');
  803. var username = $.trim($('#username').val());
  804. var type = $('#type').val();
  805. if (username) {
  806. $.post('./index.php?c=mc&a=trade&do=user&', {
  807. 'type': type,
  808. 'username': username
  809. }, function (data) {
  810. var data = $.parseJSON(data);
  811. if (data.error != 'none') {
  812. _this.user = {};
  813. _this.card = {};
  814. $('#user').hide();
  815. Validator.updateMessage('username', 'notEmpty', data.message);
  816. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  817. return false;
  818. } else {
  819. _this.user = data.user;
  820. _this.card = data.card;
  821. $('#user strong').html(data.html);
  822. $('#user').show();
  823. }
  824. });
  825. }
  826. });
  827. },
  828. 'checkuser': function () {
  829. if (this.user.uid == undefined || !this.user.uid) {
  830. this.user = {};
  831. this.card = {};
  832. $('#username').focus();
  833. Validator.updateMessage('username', 'notEmpty', '未找到对应会员');
  834. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  835. return false;
  836. }
  837. if (this.card.id > 0) {
  838. util.message('该会员已领取会员卡');
  839. return false;
  840. }
  841. return true;
  842. },
  843. 'submit': function () {
  844. var _this = this;
  845. $('#form-card .btn-primary').click(function () {
  846. _this.checkuser();
  847. Validator.validate();
  848. if (Validator.isValid()) {
  849. _this.password = $.trim($(':input[name="password"]').val());
  850. _this.username = $.trim($('#username').val());
  851. var param = {
  852. 'uid': _this.user.uid,
  853. 'password': _this.password,
  854. 'username': _this.username
  855. }
  856. $.post('./index.php?c=mc&a=trade&do=card', param, function (data) {
  857. if (data != 'success') {
  858. util.message(data, '', 'error');
  859. return false;
  860. } else {
  861. dialog.modal('hide');
  862. util.message('发放会员卡成功', 'refresh', 'success');
  863. return false;
  864. }
  865. });
  866. }
  867. });
  868. }
  869. };
  870. card.init(uid);
  871. });
  872. }
  873. trade.cardconsume = function () {
  874. var html = '<div class="modal fade" id="card-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">' +
  875. ' <div class="modal-dialog modal-lg" role="document">' +
  876. ' <div class="modal-content">' +
  877. ' <form class="table-responsive form-inline" method="post" action="" id="form-card">' +
  878. ' <div class="modal-header">' +
  879. ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
  880. ' <h4 class="modal-title" id="myModalLabel">卡券核销</h4>' +
  881. ' </div>' +
  882. ' <div class="modal-body">' +
  883. ' <table class="table table-hover table-bordered">' +
  884. ' <tr height="100">' +
  885. ' <th width="150">' +
  886. ' 卡券code码' +
  887. ' </th>' +
  888. ' <td>' +
  889. ' <div class="form-group">' +
  890. ' <input type="text" value="" name="code" id="code" class="form-control"/>' +
  891. ' <div class="help-block">请输入卡券code码</div>' +
  892. ' </div>' +
  893. ' </div>' +
  894. ' </td>' +
  895. ' </tr>' +
  896. ' </table>' +
  897. ' </div>' +
  898. ' <div class="modal-footer">' +
  899. ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>' +
  900. ' <input type="submit" class="btn btn-primary" id="submit" name="核销"value="核销">' +
  901. ' </div>' +
  902. ' </form>' +
  903. ' </div>' +
  904. ' </div>' +
  905. '</div>';
  906. require(['validator'], function () {
  907. $('#card-Modal').remove();
  908. $(document.body).append(html);
  909. var dialog = $('#card-Modal');
  910. dialog.modal('show');
  911. $('#card-Modal').on('shown.bs.modal', function () {
  912. $('#code').focus();
  913. });
  914. $('#form-card').bootstrapValidator({
  915. fields: {
  916. code: {
  917. validators: {
  918. notEmpty: {
  919. message: '请填写卡券code码'
  920. }
  921. }
  922. }
  923. }
  924. });
  925. var Validator = $('#form-card').data('bootstrapValidator');
  926. var card = {
  927. 'user': {},
  928. 'card': {},
  929. 'init': function (uid) {
  930. if (uid > 0) {
  931. $('#type').val('uid');
  932. $('#code').val(uid);
  933. $('#code').trigger('blur');
  934. if (this.user.uid > 0) {
  935. $('#code, #type').attr('disabled', true);
  936. }
  937. }
  938. this.submit();
  939. },
  940. 'submit': function () {
  941. var _this = this;
  942. $('#form-card .btn-primary').click(function () {
  943. Validator.validate();
  944. if (Validator.isValid()) {
  945. _this.code = $.trim($(':input[name="code"]').val());
  946. var param = {
  947. 'code': _this.code,
  948. }
  949. $.post('./index.php?c=mc&a=trade&do=cardconsume', param, function (data) {
  950. if (data != 'success') {
  951. util.message(data, '', 'error');
  952. return false;
  953. } else {
  954. dialog.modal('hide');
  955. util.message('核销成功', 'refresh', 'success');
  956. return false;
  957. }
  958. });
  959. }
  960. });
  961. }
  962. };
  963. card.init();
  964. });
  965. }
  966. trade.card_edit = function (uid) {
  967. var html = '<div class="modal fade" id="card-edit-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">' +
  968. ' <div class="modal-dialog modal-lg" role="document">' +
  969. ' <div class="modal-content">' +
  970. ' <form class="table-responsive form-inline" method="post" action="" id="form-card">' +
  971. ' <div class="modal-header">' +
  972. ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
  973. ' <h4 class="modal-title" id="myModalLabel">更改会员卡号</h4>' +
  974. ' </div>' +
  975. ' <div class="modal-body">' +
  976. ' <table class="table table-hover table-bordered">' +
  977. ' <tr>' +
  978. ' <th width="150">' +
  979. ' <select name="type" id="type" class="form-control">' +
  980. ' <option value="mobile">手机号</option>' +
  981. ' <option value="uid">会员UID</option>' +
  982. ' </select>' +
  983. ' </th>' +
  984. ' <td>' +
  985. ' <div class="form-group">' +
  986. ' <input type="text" value="" name="username" id="username" class="form-control"/>' +
  987. ' </div>' +
  988. ' </td>' +
  989. ' </tr>' +
  990. ' <tr id="user" style="display: none">' +
  991. ' <th>会员信息</th>' +
  992. ' <td>' +
  993. ' <div class="form-group">' +
  994. ' <div class="input-group">' +
  995. ' <strong class="form-control-static"></strong>' +
  996. ' </div>' +
  997. ' </div>' +
  998. ' </td>' +
  999. ' </tr>' +
  1000. ' <tr>' +
  1001. ' <th>原卡号</th>' +
  1002. ' <td>' +
  1003. ' <div class="form-group">' +
  1004. ' <p class="label label-danger" id="old_cardsn"></p>' +
  1005. ' </div>' +
  1006. ' </td>' +
  1007. ' </tr>' +
  1008. ' <tr>' +
  1009. ' <th>设置新卡号</th>' +
  1010. ' <td>' +
  1011. ' <div class="form-group">' +
  1012. ' <input type="text" name="cardsn" id="cardsn" value="" class="form-control">' +
  1013. ' </div>' +
  1014. ' </td>' +
  1015. ' </tr>' +
  1016. ' </table>' +
  1017. ' </div>' +
  1018. ' <div class="modal-footer">' +
  1019. ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>' +
  1020. ' <input type="submit" class="btn btn-primary" id="submit" name="提交"value="提交">' +
  1021. ' </div>' +
  1022. ' </form>' +
  1023. ' </div>' +
  1024. ' </div>' +
  1025. '</div>';
  1026. require(['validator'], function () {
  1027. $('#card-edit-Modal').remove();
  1028. $(document.body).append(html);
  1029. var dialog = $('#card-edit-Modal');
  1030. dialog.modal('show');
  1031. $('#form-card').bootstrapValidator({
  1032. fields: {
  1033. username: {
  1034. validators: {
  1035. notEmpty: {
  1036. message: '请填写用户手机或UID'
  1037. }
  1038. }
  1039. },
  1040. cardsn: {
  1041. validators: {
  1042. notEmpty: {
  1043. message: '新卡号不能为空'
  1044. },
  1045. remote: {
  1046. url: "./index.php?c=mc&a=trade&do=cardsn&type=check",
  1047. data: function (validator) {
  1048. return {
  1049. data: validator.getFieldElements('cardsn').val()
  1050. };
  1051. },
  1052. message: '卡号已经被其他用户使用'
  1053. }
  1054. }
  1055. }
  1056. }
  1057. });
  1058. var Validator = $('#form-card').data('bootstrapValidator');
  1059. var card_edit = {
  1060. 'user': {},
  1061. 'card': {},
  1062. 'init': function (uid) {
  1063. this.getuser();
  1064. if (uid > 0) {
  1065. $('#type').val('uid');
  1066. $('#username').val(uid);
  1067. $('#username').trigger('blur');
  1068. if (this.user.uid > 0) {
  1069. $('#username, #type').attr('disabled', true);
  1070. }
  1071. }
  1072. this.submit();
  1073. },
  1074. getuser: function () {
  1075. var _this = this;
  1076. $('#username').blur(function () {
  1077. Validator.validateField('username');
  1078. var username = $.trim($('#username').val());
  1079. var type = $('#type').val();
  1080. if (username) {
  1081. $.post('./index.php?c=mc&a=trade&do=user&', {
  1082. 'type': type,
  1083. 'username': username
  1084. }, function (data) {
  1085. var data = $.parseJSON(data);
  1086. if (data.error != 'none') {
  1087. _this.user = {};
  1088. _this.card = {};
  1089. $('#user').hide();
  1090. Validator.updateMessage('username', 'notEmpty', data.message);
  1091. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  1092. return false;
  1093. } else {
  1094. _this.user = data.user;
  1095. _this.card = data.card;
  1096. $('#user strong').html(data.html);
  1097. $('#old_cardsn').html(data.user.cardsn);
  1098. $('#user').show();
  1099. }
  1100. });
  1101. }
  1102. });
  1103. },
  1104. 'checkuser': function () {
  1105. if (this.user.uid == undefined || !this.user.uid) {
  1106. this.user = {};
  1107. this.card = {};
  1108. $('#username').focus();
  1109. Validator.updateMessage('username', 'notEmpty', '未找到对应会员');
  1110. Validator.updateStatus('username', 'INVALID', 'notEmpty');
  1111. return false;
  1112. }
  1113. return true;
  1114. },
  1115. 'submit': function () {
  1116. var _this = this;
  1117. $('#form-card .btn-primary').click(function () {
  1118. _this.checkuser();
  1119. Validator.validate();
  1120. if (Validator.isValid()) {
  1121. var param = {
  1122. 'uid': _this.user.uid,
  1123. 'cardsn': $.trim($('#cardsn').val()),
  1124. 'password': $.trim($(':input[name="password"]').val())
  1125. }
  1126. $.post('./index.php?c=mc&a=trade&do=cardsn', param, function (data) {
  1127. if (data != 'success') {
  1128. util.message(data, '', 'error');
  1129. return false;
  1130. } else {
  1131. dialog.modal('hide');
  1132. util.message('更改卡号成功', 'refresh', 'success');
  1133. return false;
  1134. }
  1135. });
  1136. }
  1137. });
  1138. }
  1139. };
  1140. card_edit.init(uid);
  1141. });
  1142. }
  1143. return trade;
  1144. });