File size: 24,379 Bytes
0d5b03e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
<?php
/**

 * 商户信息

**/
include("../includes/common.php");
$title='商户信息';
include './head.php';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>
  <div class="container" style="padding-top:70px;">

<?php

$usergroup = [];

$select = '';

$rs = $DB->getAll("SELECT * FROM pre_group");

foreach($rs as $row){
	$usergroup[$row['gid']] = $row['name'];
	$select.='<option value="'.$row['gid'].'">'.$row['name'].'</option>';
}
unset($rs);
$settle_select = '';
if($conf['settle_alipay'])$settle_select.='<option value="1">支付宝</option>';
if($conf['settle_wxpay'])$settle_select.='<option value="2">微信</option>';
if($conf['settle_qqpay'])$settle_select.='<option value="3">QQ钱包</option>';
if($conf['settle_bank'])$settle_select.='<option value="4">银行卡</option>';

$my=isset($_GET['my'])?$_GET['my']:null;

if($my=='add')
{
?>
<div class="col-sm-12 col-md-10 col-lg-8 center-block" style="float: none;">

<div class="panel panel-primary">

<div class="panel-heading"><h3 class="panel-title">添加商户</h3></div>

<div class="panel-body">

<form method="POST" onsubmit="return addUser(this)">

<h4><font color="blue">基本信息</font></h4>

<div class="form-group">

<label>手机号(登录账号):</label><br>

<input type="text" class="form-control" name="phone" value="" placeholder="可留空">

</div>

<div class="form-group">

<label>邮箱(登录账号):</label><br>

<input type="text" class="form-control" name="email" value="" placeholder="可留空">

</div>

<div class="form-group">

<label>登录密码:</label><br>

<input type="text" class="form-control" name="pwd" value="" placeholder="留空则只能使用密钥登录">

</div>

<div class="form-group">

<label>用户组:</label><br>

<select class="form-control" name="gid"><?php echo $select?></select>

</div>

<div class="form-group">

<label>QQ:</label><br>

<input type="text" class="form-control" name="qq" value="" placeholder="可留空">

</div>

<div class="form-group">

<label>网站域名:</label><br>

<input type="text" class="form-control" name="url" value="" placeholder="可留空">

</div>

<h4><font color="blue">结算信息</font></h4>

<div class="form-group">

<label>结算方式:</label><br><select class="form-control" name="settle_id"><?php echo $settle_select?></select>

</div>

<div class="form-group">

<label>*结算账号:</label><br>

<input type="text" class="form-control" name="account" value="" required>

</div>

<div class="form-group">

<label>*结算账号姓名:</label><br>

<input type="text" class="form-control" name="username" value="" required>

</div>

<h4><font color="blue">功能开关</font></h4>

<div class="form-group">

<label>手续费扣除模式:</label><br><select class="form-control" name="mode"><option value="0">余额扣费</option><option value="1">订单加费</option></select>

</div>

<div class="row">

	<div class="col-md-4 col-sm-12">

		<div class="form-group">

		<label>商户状态:</label><br><select class="form-control" name="status"><option value="1">1_正常</option><option value="0">0_封禁</option><option value="2">2_未审核</option></select>

		</div>

	</div>

	<div class="col-md-4 col-sm-12">

		<div class="form-group">

		<label>支付权限:</label><br><select class="form-control" name="pay"><option value="1">1_开启</option><option value="0">0_关闭</option></select>

		</div>

	</div>

	<div class="col-md-4 col-sm-12">

		<div class="form-group">

		<label>结算权限:</label><br><select class="form-control" name="settle"><option value="1">1_开启</option><option value="0">0_关闭</option></select>

		</div>

	</div>

</div>

<input type="submit" class="btn btn-primary btn-block" value="确定添加"></form>

<br/><a href="./ulist.php">>>返回商户列表</a>

</div></div>

<?php }

elseif($my=='edit')

{
$uid=intval($_GET['uid']);
$row=$DB->getRow("select * from pre_user where uid='$uid' limit 1");
if(!$row)showmsg('该商户不存在',4);
$group=\lib\Channel::getGroup($row['gid']);
?>
<div class="col-md-12 col-lg-10 center-block" style="float: none;">

<div class="panel panel-primary">

<div class="panel-heading"><h3 class="panel-title">修改商户信息 UID:<?php echo $uid?></h3></div>

<div class="panel-body">

<ul class="nav nav-tabs">

<li align="center" class="active"><a href="#">基本信息</a></li>

<?php if($group['settings']){?><li align="center"><a href="./uset.php?my=edit2&uid=<?php echo $uid?>">自定义接口信息</a></li><?php }?>
<?php if($group['subchannel_type']){?><li align="center"><a href="./uset.php?my=subchannel&uid=<?php echo $uid?>">自定义子通道</a></li><?php }?>
</ul>
<form onsubmit="return editUser(this, <?php echo $uid?>)" method="POST">
<div class="row">

<div class="col-sm-12 col-md-6">

<h4><font color="blue">基本信息</font></h4>

<div class="form-group">

<label>手机号(登录账号):</label><br>

<input type="text" class="form-control" name="phone" value="<?php echo $row['phone']?>" placeholder="可留空">

</div>

<div class="form-group">

<label>邮箱(登录账号):</label><br>

<input type="text" class="form-control" name="email" value="<?php echo $row['email']?>" placeholder="可留空">

</div>

<div class="form-group">

<label>商户余额:</label><br>

<input type="text" class="form-control" name="money" value="<?php echo $row['money']?>" required>

</div>

<div class="form-group">

<label>用户组:</label><br>

<select class="form-control" name="gid" default="<?php echo $row['gid']?>"><?php echo $select?></select>

</div>

<div class="form-group">

<label>QQ:</label><br>

<input type="text" class="form-control" name="qq" value="<?php echo $row['qq']?>" placeholder="可留空">

</div>

<div class="form-group">

<label>网站域名:</label><br>

<input type="text" class="form-control" name="url" value="<?php echo $row['url']?>" placeholder="可留空">

</div>

<div class="form-group">

<label>商品名称自定义:</label><br>

<input type="text" class="form-control" name="ordername" value="<?php echo $row['ordername']?>" placeholder="默认以系统设置里面的为准">

<font color="green">支持变量值:[name]原商品名称,[order]支付订单号,[outorder]商户订单号,[time]时间戳,[qq]当前商户的联系QQ</font>

</div>

<h4><font color="blue">结算信息</font></h4>

<div class="form-group">

<label>结算方式:</label><br><select class="form-control" name="settle_id" default="<?php echo $row['settle_id']?>"><?php echo $settle_select?></select>

</div>

<div class="form-group">

<label>结算账号:</label><br>

<input type="text" class="form-control" name="account" value="<?php echo $row['account']?>" required>

</div>

<div class="form-group">

<label>结算账号姓名:</label><br>

<input type="text" class="form-control" name="username" value="<?php echo $row['username']?>" required>

</div>

</div>

<div class="col-sm-12 col-md-6">

<h4><font color="blue">实名信息</font></h4>

<div class="form-group">

<label>是否实名认证:</label><br><select class="form-control" name="cert" default="<?php echo $row['cert']?>"><option value="0">0_未实名</option><option value="1">1_已实名</option></select>

</div>

<div class="form-group">

<label>认证类型:</label><br><select class="form-control" name="certtype" default="<?php echo $row['certtype']?>"><option value="0">个人实名认证</option><option value="1">企业实名认证</option></select>

</div>

<div class="form-group">

<label>认证方式:</label><br><select class="form-control" name="certmethod" default="<?php echo $row['certmethod']?>"><option value="0">支付宝快捷认证</option><option value="1">微信快捷认证</option><option value="2">手机号三要素认证</option><option value="3">人工审核认证</option></select>

</div>

<div class="form-group">

<label>真实姓名:</label><br>

<input type="text" class="form-control" name="certname" value="<?php echo $row['certname']?>">

</div>

<div class="form-group">

<label>身份证号:</label><br>

<input type="text" class="form-control" name="certno" value="<?php echo $row['certno']?>" maxlength="18">

</div>

<div class="form-group">

<label>公司名称:</label><br>

<input type="text" class="form-control" name="certcorpname" value="<?php echo $row['certcorpname']?>">

</div>

<div class="form-group">

<label>营业执照号码:</label><br>

<input type="text" class="form-control" name="certcorpno" value="<?php echo $row['certcorpno']?>" maxlength="30">

</div>

<h4><font color="blue">功能开关</font></h4>

<div class="form-group">

<label>手续费扣除模式:</label><br><select class="form-control" name="mode" default="<?php echo $row['mode']?>"><option value="0">余额扣费</option><option value="1">订单加费</option></select>

</div>

<div class="row">

	<div class="col-md-4 col-sm-12">

		<div class="form-group">

		<label>商户状态:</label><br><select class="form-control" name="status" default="<?php echo $row['status']?>"><option value="1">1_正常</option><option value="0">0_封禁</option><option value="2">2_未审核</option></select>

		</div>

	</div>

	<div class="col-md-4 col-sm-12">

		<div class="form-group">

		<label>支付权限:</label><br><select class="form-control" name="pay" default="<?php echo $row['pay']?>"><option value="1">1_开启</option><option value="0">0_关闭</option></select>

		</div>

	</div>

	<div class="col-md-4 col-sm-12">

		<div class="form-group">

		<label>结算权限:</label><br><select class="form-control" name="settle" default="<?php echo $row['settle']?>"><option value="1">1_开启</option><option value="0">0_关闭</option></select>

		</div>

	</div>

</div>

<h4><font color="blue">密码修改</font></h4>

<div class="form-group">

<label>重置登录密码:</label><br>

<input type="text" class="form-control" name="pwd" value="" placeholder="不重置密码请留空">

</div>

</div>

</div>

<input type="submit" class="btn btn-primary btn-block" value="确定修改"></form>

<br/><a href="./ulist.php">>>返回商户列表</a>

</div></div>

<script>

var items = $("select[default]");

for (i = 0; i < items.length; i++) {
	$(items[i]).val($(items[i]).attr("default")||0);
}
</script>
<?php }
elseif($my=='edit2')
{
$uid=intval($_GET['uid']);
$row=$DB->getRow("select * from pre_user where uid='$uid' limit 1");
if(!$row)showmsg('该商户不存在',4);
$group=\lib\Channel::getGroup($row['gid']);
$channelinfo = json_decode($row['channelinfo'], true);
?>
<div class="col-md-12 col-lg-10 center-block" style="float: none;">

<div class="panel panel-primary">

<div class="panel-heading"><h3 class="panel-title">修改商户信息 UID:<?php echo $uid?></h3></div>

<div class="panel-body">

<ul class="nav nav-tabs">

<li align="center"><a href="./uset.php?my=edit&uid=<?php echo $uid?>">基本信息</a></li>

<li align="center" class="active"><a href="#">自定义接口信息</a></li>

<?php if($group['subchannel_type']){?><li align="center"><a href="./uset.php?my=subchannel&uid=<?php echo $uid?>">自定义子通道</a></li><?php }?>
</ul>
<form onsubmit="return editUserChannelInfo(this, <?php echo $uid?>)" method="POST">
<?php
foreach(explode(',',$group['settings']) as $row){
	$arr = explode(':', $row);
	echo '<div class="form-group">

<label>'.$arr[1].':</label><br>

<input type="text" class="form-control" name="setting['.$arr[0].']" value="'.$channelinfo[$arr[0]].'" required>

</div>';
}
?>
<input type="submit" class="btn btn-primary btn-block" value="确定修改"></form>

<br/><a href="./ulist.php">>>返回商户列表</a>

</div></div>

<?php }

elseif($my=='subchannel')

{
$uid=intval($_GET['uid']);
$row=$DB->getRow("select * from pre_user where uid='$uid' limit 1");
if(!$row)showmsg('该商户不存在',4);
$group=\lib\Channel::getGroup($row['gid']);

$paytype = [];
$paytypes = [];
$type_select = '';
$rs = $DB->getAll("SELECT * FROM pre_type ORDER BY id ASC");
foreach($rs as $row){
	$paytype[$row['id']] = $row['showname'];
	$paytypes[$row['id']] = $row['name'];
	if(in_array($row['name'], $group['subchannel_type'])){
		$type_select .= '<option value="'.$row['id'].'">'.$row['showname'].'</option>';
	}
}
unset($rs);
$list = $DB->getAll("SELECT A.*,B.type,B.name channelname FROM pre_subchannel A LEFT JOIN pre_channel B ON A.channel=B.id WHERE uid='$uid' ORDER BY A.id ASC");
?>
<style>td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:300px;}</style>
<div class="modal" id="modal-store" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">

	<div class="modal-dialog">

		<div class="modal-content animated flipInX">

			<div class="modal-header">

				<button type="button" class="close" data-dismiss="modal"><span

							aria-hidden="true">&times;</span><span

							class="sr-only">Close</span></button>

				<h4 class="modal-title" id="modal-title">自定义子通道修改/添加</h4>

			</div>

			<div class="modal-body">

				<form class="form-horizontal" id="form-store">

					<input type="hidden" name="action" id="action"/>

					<input type="hidden" name="id" id="id"/>

					<input type="hidden" name="uid" value="<?php echo $uid?>"/>

					<div class="form-group">

						<label class="col-sm-2 control-label">支付方式</label>

						<div class="col-sm-10">

							<select name="type" id="type" class="form-control" onchange="changeType()">

								<option value="0">请选择支付方式</option><?php echo $type_select; ?>

							</select>

						</div>

					</div>

					<div class="form-group">

						<label class="col-sm-2 control-label">支付通道</label>

						<div class="col-sm-10">

							<select name="channel" id="channel" class="form-control">

							</select>

						</div>

					</div>

					<div class="form-group">

						<label class="col-sm-2 control-label no-padding-right">备注</label>

						<div class="col-sm-10">

							<input type="text" class="form-control" name="name" id="name" placeholder="仅显示使用,不要与其他备注重复">

						</div>

					</div>

				</form>

			</div>

			<div class="modal-footer">

				<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>

				<button type="button" class="btn btn-primary" id="store" onclick="save()">保存</button>

			</div>

		</div>

	</div>

</div>

<div class="col-md-12 col-lg-10 center-block" style="float: none;">

<div class="panel panel-primary">

<div class="panel-heading"><h3 class="panel-title">修改商户信息 UID:<?php echo $uid?></h3></div>

<div class="panel-body">

<ul class="nav nav-tabs">

<li align="center"><a href="./uset.php?my=edit&uid=<?php echo $uid?>">基本信息</a></li>

<?php if($group['settings']){?><li align="center"><a href="./uset.php?my=edit2&uid=<?php echo $uid?>">自定义接口信息</a></li><?php }?>
<li align="center" class="active"><a href="#">自定义子通道</a></li>

</ul>



<div class="panel panel-success">

   <div class="panel-heading"><h3 class="panel-title">当前商户共有 <b><?php echo count($list);?></b> 个子通道&nbsp;

     <span class="pull-right">

	   <a href="javascript:addframe()" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> 新增</a>

      </span>

   </h3></div>

      <div class="table-responsive">

        <table class="table table-striped">

          <thead><tr><th>ID</th><th>支付方式</th><th>支付通道</th><th>子通道备注</th><th>自定义支付参数</th><th>状态</th><th>操作</th></tr></thead>

          <tbody>

<?php

foreach($list as $res)

{
	if(empty($res['info'])) $res['info'] = '点击设置';
echo '<tr><td><b>'.$res['id'].'</b></td><td><img src="/assets/icon/'.$paytypes[$res['type']].'.ico" width="16" onerror="this.style.display=\'none\'"> '.$paytype[$res['type']].'</td><td>'.$res['channel'].'_'.$res['channelname'].'</td><td>'.$res['name'].'</td><td><a href="javascript:editInfo('.$res['id'].')">'.$res['info'].'</a></td><td>'.($res['status']==1?'<a class="btn btn-xs btn-success" onclick="setStatus('.$res['id'].',0)">已开启</a>':'<a class="btn btn-xs btn-warning" onclick="setStatus('.$res['id'].',1)">已关闭</a>').'</td><td><a class="btn btn-xs btn-info" onclick="editframe('.$res['id'].')">编辑</a>&nbsp;<a class="btn btn-xs btn-danger" onclick="delItem('.$res['id'].')">删除</a>&nbsp;<a href="./order.php?subchannel='.$res['id'].'" target="_blank" class="btn btn-xs btn-default">订单</a>&nbsp;<a onclick="testpay('.$res['id'].','.$res['channel'].')" class="btn btn-xs btn-default">测试</a></td></tr>';
}
?>
          </tbody>
        </table>
      </div>
	</div>
	
<a href="./ulist.php">>>返回商户列表</a>
</div></div>
<?php } ?>
    </div>
  </div>
<script src="<?php echo $cdnpublic?>layer/3.1.1/layer.js"></script>
<script>
function addUser(obj){
	var ii = layer.load(2, {shade:[0.1,'#fff']});
	$.ajax({
		type : 'POST',
		url : 'ajax_user.php?act=addUser',
		data : $(obj).serialize(),
		dataType : 'json',
		success : function(data) {
			layer.close(ii);
			if(data.code == 0){
				layer.alert('添加商户成功!商户ID:'+data.uid+'<br/>密钥:'+data.key, {
					icon: 1,
					closeBtn: false
				}, function(){
					window.location.href = './ulist.php';
				});
			}else{
				layer.alert(data.msg, {icon: 2})
			}
		},
		error:function(data){
			layer.close(ii);
			layer.msg('服务器错误');
		}
	});
	return false;
}
function editUser(obj, uid){
	var ii = layer.load(2, {shade:[0.1,'#fff']});
	$.ajax({
		type : 'POST',
		url : 'ajax_user.php?act=editUser&uid='+uid,
		data : $(obj).serialize(),
		dataType : 'json',
		success : function(data) {
			layer.close(ii);
			if(data.code == 0){
				layer.alert('修改商户信息成功!', {
					icon: 1,
					closeBtn: false
				});
			}else{
				layer.alert(data.msg, {icon: 2})
			}
		},
		error:function(data){
			layer.close(ii);
			layer.msg('服务器错误');
		}
	});
	return false;
}
function editUserChannelInfo(obj, uid){
	var ii = layer.load(2, {shade:[0.1,'#fff']});
	$.ajax({
		type : 'POST',
		url : 'ajax_user.php?act=editUserChannelInfo&uid='+uid,
		data : $(obj).serialize(),
		dataType : 'json',
		success : function(data) {
			layer.close(ii);
			if(data.code == 0){
				layer.alert('修改商户信息成功!', {
					icon: 1,
					closeBtn: false
				});
			}else{
				layer.alert(data.msg, {icon: 2})
			}
		},
		error:function(data){
			layer.close(ii);
			layer.msg('服务器错误');
		}
	});
	return false;
}

function changeType(channel){
	channel = channel || null
	var typeid = $("#type").val();
	if(typeid==0)return;
	$("#channel").empty();
	$.ajax({
		type : 'GET',
		url : 'ajax_user.php?act=getChannels&typeid='+typeid,
		dataType : 'json',
		success : function(data) {
			if(data.code == 0){
				$.each(data.data, function (i, res) {
					$("#channel").append('<option value="'+res.id+'">'+res.name+'</option>');
				})
				if(channel!=null)$("#channel").val(channel);
			}else{
				layer.msg(data.msg, {icon:2, time:1500})
			}
		},
		error:function(data){
			layer.msg('服务器错误');
		}
	});
}
function addframe(){
	$("#modal-store").modal('show');
	$("#modal-title").html("新增子通道");
	$("#action").val("add");
	$("#id").val('');
	$("#type").val(0);
	$("#channel").empty();
}
function editframe(id){
	var ii = layer.load(2, {shade:[0.1,'#fff']});
	$.ajax({
		type : 'GET',
		url : 'ajax_user.php?act=getSubChannel&id='+id,
		dataType : 'json',
		success : function(data) {
			layer.close(ii);
			if(data.code == 0){
				$("#modal-store").modal('show');
				$("#modal-title").html("修改子通道");
				$("#action").val("edit");
				$("#id").val(data.data.id);
				$("#name").val(data.data.name);
				$("#type").val(data.data.type);
				changeType(data.data.channel);
			}else{
				layer.alert(data.msg, {icon: 2})
			}
		},
		error:function(data){
			layer.msg('服务器错误');
			return false;
		}
	});
}
function save(){
	if($("#name").val()==''){
		layer.alert('请确保各项不能为空!');return false;
	}
	if($("#type").val()==0){
		layer.alert('请选择支付方式!');return false;
	}
	if($("#channel").val()==0 || $("#channel").val()==null){
		layer.alert('请选择支付通道!');return false;
	}
	var ii = layer.load(2, {shade:[0.1,'#fff']});
	$.ajax({
		type : 'POST',
		url : 'ajax_user.php?act=saveSubChannel',
		data : $("#form-store").serialize(),
		dataType : 'json',
		success : function(data) {
			layer.close(ii);
			if(data.code == 0){
				layer.alert(data.msg,{
					icon: 1,
					closeBtn: false
				}, function(){
				  window.location.reload()
				});
			}else{
				layer.alert(data.msg, {icon: 2})
			}
		},
		error:function(data){
			layer.msg('服务器错误');
		}
	});
}
function delItem(id) {
	var confirmobj = layer.confirm('你确实要删除此子通道吗?', {
	  btn: ['确定','取消'], icon:0
	}, function(){
	  $.ajax({
		type : 'GET',
		url : 'ajax_user.php?act=delSubChannel&id='+id,
		dataType : 'json',
		success : function(data) {
			if(data.code == 0){
				window.location.reload()
			}else{
				layer.alert(data.msg, {icon: 2});
			}
		},
		error:function(data){
			layer.msg('服务器错误');
			return false;
		}
	  });
	}, function(){
	  layer.close(confirmobj);
	});
}
function setStatus(id,status) {
	$.ajax({
		type : 'GET',
		url : 'ajax_user.php?act=setSubChannel&id='+id+'&status='+status,
		dataType : 'json',
		success : function(data) {
			if(data.code == 0){
				window.location.reload()
			}else{
				layer.msg(data.msg, {icon:2, time:1500});
			}
		},
		error:function(data){
			layer.msg('服务器错误');
			return false;
		}
	});
}
function editInfo(id){
	var ii = layer.load(2, {shade:[0.1,'#fff']});
	$.ajax({
		type : 'GET',
		url : 'ajax_user.php?act=subChannelInfo&id='+id,
		dataType : 'json',
		success : function(data) {
			layer.close(ii);
			if(data.code == 0){
				var area = [$(window).width() > 520 ? '520px' : '100%', ';max-height:100%'];
				layer.open({
				  type: 1,
				  area: area,
				  title: '自定义支付参数',
				  skin: 'layui-layer-rim',
				  content: data.data
				});
			}else{
				layer.alert(data.msg, {icon: 2})
			}
		},
		error:function(data){
			layer.msg('服务器错误');
			return false;
		}
	});
}
function saveInfo(id){
	var ii = layer.load(2, {shade:[0.1,'#fff']});
	$.ajax({
		type : 'POST',
		url : 'ajax_user.php?act=saveSubChannelInfo&id='+id,
		data : $("#form-info").serialize(),
		dataType : 'json',
		success : function(data) {
			layer.close(ii);
			if(data.code == 0){
				layer.alert(data.msg,{
					icon: 1,
					closeBtn: false
				}, function(){
				  window.location.reload()
				});
			}else{
				layer.alert(data.msg, {icon: 2})
			}
		},
		error:function(data){
			layer.msg('服务器错误');
			return false;
		}
	});
}
function testpay(subid, id) {
	var ii = layer.open({
		area: ['360px'],
		title: '测试支付',
		content: '<div class="form-group"><div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-shopping-cart"></span></span><input class="form-control" placeholder="订单名称" value="支付测试" name="test_name" type="text"></div></div><div class="form-group"><div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-yen"></span></span><input class="form-control" placeholder="订单金额" value="1" name="test_money" type="text"></div></div>',
		yes: function(){
			var name = $("input[name='test_name']").val();
			var money = $("input[name='test_money']").val();
			$.ajax({
				type : 'POST',
				url : 'ajax_pay.php?act=testpay',
				data : {channel:id, subchannel:subid, name:name, money:money},
				dataType : 'json',
				success : function(data) {
					if(data.code == 0){
						layer.close(ii);
						window.open(data.url);
					}else{
						layer.alert(data.msg, {icon:2});
					}
				},
				error:function(data){
					layer.msg('服务器错误');
					return false;
				}
			});
		}
	});
}
</script>