trade.js 36 KB

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