Store.php
28.1 KB
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
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
<?php
namespace app\api\controller;
use addons\litestore\model\Litestoreorder;
use app\api\model\Deposit;
use app\api\model\DepositOrder;
use app\api\model\Industry;
use app\api\model\LitestoreBanner;
use app\api\model\LitestoreGoodsSpec;
use app\api\model\Report;
use app\api\model\StoreApply;
use app\api\model\StoreComment;
use app\api\model\StoreInform;
use app\api\model\StoreOrder;
use app\api\model\UserSearch;
use app\api\validate\StoreValidate;
use app\common\controller\Api;
use EasyWeChat\Foundation\Application;
use EasyWeChat\Payment\Order;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\Request;
/**
* 店铺接口
*/
class Store extends Api
{
protected $noNeedLogin = [];
protected $noNeedRight = ['*'];
protected $store_model;
protected $industry_model;
protected $deposit_model;
protected $deposit_order_model;
protected $favorite_model;
protected $comment_model;
protected $good_model;
protected $follow_model;
protected $user_id;
public function __construct(Request $request,\app\api\model\Store $store,Industry $industry,Deposit $deposit,DepositOrder $deposit_order)
{
parent::__construct($request);
$this->industry_model = $industry;
$this->deposit_model = $deposit;
$this->deposit_order_model = $deposit_order;
$this->store_model = $store;
$this->user_id = $this->auth->id;
}
/**
* 入驻协议
* @ApiWeigh (90)
*
* @ApiTitle (入驻协议)
* @ApiSummary (入驻协议)
* @ApiMethod (POST)
* @ApiRoute (/api/store/settled)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"settled": 入驻协议,
}
})
*/
public function settled()
{
if($this->request->isPost()){
$return = [
'settled' => config('site.settled')
];
$this->success('成功',$return);
}
}
/**
* 行业列表
* @ApiWeigh (80)
*
* @ApiTitle (行业列表)
* @ApiSummary (行业列表)
* @ApiMethod (POST)
* @ApiRoute (/api/store/industry)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="keyword", type="string", required=true, description="关键词")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"list": [
{
"id": 1,
"name": "行业名称",
"weigh": 0,
}
]
}
})
*/
public function industry()
{
if($this->request->isPost()){
$keyword = $this->request->param('keyword','');
$where = [
'where' => []
];
if($keyword) {
$where['where'] = ['name'=>['like','%'.$keyword.'%']];
}
$indus = $this->industry_model->selectOrFail($where,false,'*','weigh');
$return = [
'list' => $indus,
];
$this->success('请求成功',$return);
}
}
/**
* 店铺申请
* @ApiWeigh (55)
*
* @ApiTitle (店铺申请)
* @ApiSummary (店铺申请)
* @ApiMethod (POST)
* @ApiRoute (/api/store/store_add)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="store_name", type="string", required=true, description="店铺名称")
* @ApiParams (name="house_ids", type="string", sample="店铺1id,店铺2id", required=true, description="入驻社区")
* @ApiParams (name="industry_id", type="string", required=true, description="行业/关键词id")
* @ApiParams (name="name", type="string", required=true, description="联系人姓名")
* @ApiParams (name="mobile", type="string", required=true, description="联系人手机号")
* @ApiParams (name="license", type="string", required=true, description="营业执照")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function store_add()
{
$param = (new StoreValidate())->goCheck('store_add');
$where_s = ['user_id'=>$this->user_id];
$where = [
'where' => $where_s
];
$store = $this->store_model->findOrFail($where,false,'*','createtime');
if($store) {
if($store['status'] == 1) {
$param['id'] = $store['id'];
}
if($store['status'] == 2) {
$this->error('商家申请仍在审核中');
}
if($store['status'] == 3) {
$this->error('商家申请已通过');
}
}
$order_sn = $param['order_sn'] = get_order_sn();
$pay_data = [];
// if($this->auth->end_time > time()) {
// $param['status'] = 2;
// } else {
$param['status'] = 1;
// // 获取小程序配置
// $options = \config('miniprogram.basic');
// $app = new Application($options);
// $payment = $app->payment;
// // 获取支付参数
// $attributes = [
// 'body' => '发布招募合伙人',
// 'out_trade_no' => $order_sn,
// 'total_fee' => 1, // $param['money'] * 100
// 'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
// 'notify_url' => url('index/ajax/notify',[],true,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
// 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
// 'openid' => Db::name('third')->where('user_id',$this->auth->id)->value('openid'),
// ];
// $order = new Order($attributes);
// $order_result = $payment->pay($order);
// if($order_result['return_code'] == 'SUCCESS' && $order_result['result_code'] == 'SUCCESS') {
// $prepayId = $order_result->prepay_id;
// $pay_data = $payment->configForJSSDKPayment($prepayId);
// } else {
// $this->error($order_result['return_msg']);
// }
// }
Db::startTrans();
$result = false;
$result_invite = true;
try{
$param['user_id'] = $this->auth->id;
if(!empty($param['id'])) {
$result = $this->store_model->edit($param);
} else {
$result = $this->store_model->add($param);
}
$id = $this->store_model->id;
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if(!$result || !$result_invite) {
$this->error('申请提交失败');
}
$this->success('申请提交成功',['id'=>$id,'status'=>$param['status'],'pay_data'=>$pay_data]);
}
/**
* 开通社区提交
* @ApiWeigh (50)
*
* @ApiTitle (开通社区提交)
* @ApiSummary (开通社区提交)
* @ApiMethod (POST)
* @ApiRoute (/api/store/store_apply)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="store_name", type="string", required=true, description="店铺名称")
* @ApiParams (name="province", type="string", required=true, description="省")
* @ApiParams (name="city", type="string", required=true, description="市")
* @ApiParams (name="region", type="string", required=true, description="区")
* @ApiParams (name="name", type="string", required=true, description="联系人姓名")
* @ApiParams (name="mobile", type="string", required=true, description="联系人手机号")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function store_apply()
{
$param = (new StoreValidate())->goCheck('store_apply');
Db::startTrans();
$result = false;
try{
$param['user_id'] = $this->auth->id;
$model = new StoreApply();
$result = $model->add($param);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if(!$result) {
$this->error('提交失败');
}
$this->success('提交成功');
}
/**
* 举报建议提交
* @ApiWeigh (45)
*
* @ApiTitle (举报建议提交)
* @ApiSummary (举报建议提交)
* @ApiMethod (POST)
* @ApiRoute (/api/store/store_report)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="content", type="string", required=true, description="建议内容")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function store_report()
{
$param = (new StoreValidate())->goCheck('store_report');
Db::startTrans();
$result = false;
try{
$param['user_id'] = $this->auth->id;
$model = new Report();
$result = $model->add($param);
$id = $model->id;
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if(!$result) {
$this->error('提交失败');
}
$this->success('提交成功');
}
/**
* 商家首页
* @ApiWeigh (40)
*
* @ApiTitle (商家首页)
* @ApiSummary (商家首页)
* @ApiMethod (POST)
* @ApiRoute (/api/store/store)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"id": 1,
"store_name": "123",
"image_arr": [
"http://cloud.caiyunpan.brotop.cn/assets/img/qrcode.png",
"http://cloud.caiyunpan.brotop.cn/assets/img/qrcode.png"
]
}
})
*/
public function store()
{
$store = $this->get_store();
$return = [
'id' => $store['id'],
'store_name' => $store['store_name'],
'image_arr' => $store['image_arr'],
];
$this->success('成功',$return);
}
/**
* 店铺信息更新
* @ApiWeigh (35)
*
* @ApiTitle (店铺信息更新)
* @ApiSummary (店铺信息更新)
* @ApiMethod (POST)
* @ApiRoute (/api/store/store_edit)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="integer", required=true, description="店铺id")
* @ApiParams (name="store_icon", type="string", required=true, description="店铺图标")
* @ApiParams (name="store_name", type="string", required=true, description="店铺名称")
* @ApiParams (name="mobile", type="string", required=true, description="商家电话")
* @ApiParams (name="province", type="string", required=true, description="省")
* @ApiParams (name="city", type="string", required=true, description="市")
* @ApiParams (name="region", type="string", required=true, description="区")
* @ApiParams (name="images", type="string", required=true, description="宣传图/轮播图")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function store_edit()
{
$param = (new StoreValidate())->goCheck('store_edit');
$store = $this->get_store($param['id']);
Db::startTrans();
$result = false;
try{
$param['user_id'] = $this->auth->id;
$result = $this->store_model->edit($param);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if(!$result) {
$this->error('保存失败');
}
$this->success('保存成功');
}
/**
* 发布信息
* @ApiWeigh (30)
*
* @ApiTitle (发布信息)
* @ApiSummary (发布信息)
* @ApiMethod (POST)
* @ApiRoute (/api/store/store_inform_add)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="content", type="string", required=true, description="详细内容")
* @ApiParams (name="images", type="string", required=true, description="图片")
* @ApiParams (name="house_ids", type="string", required=true, description="推广社区")
* @ApiParams (name="type", type="integer", required=true, description="推广类型1=红包推送信息2=一般信息")
* @ApiParams (name="red_package", type="string", required=false, description="红包总金额")
* @ApiParams (name="number", type="string", required=false, description="红包数量")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function store_inform_add()
{
$param = (new StoreValidate())->goCheck('store_inform_add');
if($param['type'] == 1) {
$param = (new StoreValidate())->goCheck('red');
}
$store = $this->get_store();
if($param['type'] == 1) {
$param['score'] = bcadd(config('site.send_score'),$param['red_package'],2);
}
Db::startTrans();
$result = false;
try{
$param['user_id'] = $this->auth->id;
$param['house_ids'] = ','.$param['house_ids'].',';
$model = new StoreInform();
$result = $model->add($param);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if(!$result) {
$this->error('提交失败');
}
$this->success('提交成功');
}
/**
* 绑定新社区
* @ApiWeigh (25)
*
* @ApiTitle (绑定新社区)
* @ApiSummary (绑定新社区)
* @ApiMethod (POST)
* @ApiRoute (/api/store/store_new)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_ids", type="string", sample="店铺1id,店铺2id", required=true, description="绑定社区id")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function store_new()
{
$param = (new StoreValidate())->goCheck('store_new');
$store = $this->get_store();
$order_sn = $param['order_sn'] = get_order_sn();
$pay_data = [];
if($this->auth->end_time > time()) {
$param['status'] = 2;
} else {
$param['status'] = 1;
// 获取小程序配置
$options = \config('miniprogram.basic');
$app = new Application($options);
$payment = $app->payment;
// 获取支付参数
$attributes = [
'body' => '发布招募合伙人',
'out_trade_no' => $order_sn,
'total_fee' => 1, // $param['money'] * 100
'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
'notify_url' => url('index/ajax/notify',[],true,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
'openid' => Db::name('third')->where('user_id',$this->auth->id)->value('openid'),
];
$order = new Order($attributes);
$order_result = $payment->pay($order);
if($order_result['return_code'] == 'SUCCESS' && $order_result['result_code'] == 'SUCCESS') {
$prepayId = $order_result->prepay_id;
} else {
$this->error($order_result['return_msg']);
}
}
$model = new StoreOrder();
Db::startTrans();
$result = false;
$result_invite = true;
try{
$param['store_id'] = $store['id'];
$param['user_id'] = $this->auth->id;
$result = $model->add($param);
$id = $model->id;
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if(!$result || !$result_invite) {
$this->error('提交失败');
}
$this->success('提交成功',['id'=>$id,'status'=>$param['status'],'pay_data'=>$pay_data]);
}
/**
* 留言消息
* @ApiWeigh (24)
*
* @ApiTitle (留言消息)
* @ApiSummary (留言消息)
* @ApiMethod (POST)
* @ApiRoute (/api/store/comment_list)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="页数")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"list": [
{
"id": 1,
"name": "行业名称",
"weigh": 0,
}
]
}
})
*/
public function comment_list()
{
if($this->request->isPost()){
$param = (new StoreValidate())->goCheck('common');
$store = $this->get_store();
$page = $param['page'];
$where = [
'where' => ['store_id'=>$store['id']],
'with' => ['user_info']
];
$order = ['createtime'=>'DESC'];
$model = new StoreComment();
$comment = $model->pageSelect($page,$where,'*',$order,config('option.num'));
$list = $comment->items();
$return = [
'list' => $list,
'this_page' => $comment->currentPage(),
'total_page' => $comment->lastPage()
];
$this->success('请求成功',$return);
}
}
/**
* 留言消息详情
* @ApiWeigh (23)
*
* @ApiTitle (留言消息详情)
* @ApiSummary (留言消息详情)
* @ApiMethod (POST)
* @ApiRoute (/api/store/comment_detail)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="comment_id", type="integer", required=true, description="留言id")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"comment": [
{
"id": 1,
"name": "行业名称",
"weigh": 0,
}
]
}
})
*/
public function comment_detail()
{
if($this->request->isPost()){
$param = (new StoreValidate())->goCheck('comment_detail');
$store = $this->get_store();
$where = [
'where' => ['id'=>$param['comment_id']],
'with' => ['user_info']
];
$model = new StoreComment();
$comment = $model->findOrFail($where,'*');
$return = [
'comment' => $comment
];
$this->success('请求成功',$return);
}
}
/**
* 留言回复
* @ApiWeigh (22)
*
* @ApiTitle (留言回复)
* @ApiSummary (留言回复)
* @ApiMethod (POST)
* @ApiRoute (/api/store/comment_reply)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="comment_id", type="integer", required=true, description="留言id")
* @ApiParams (name="content", type="string", required=true, description="留言内容")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function comment_reply()
{
$param = (new StoreValidate())->goCheck('comment_reply');
Db::startTrans();
$result = false;
try{
$param['user_id'] = $this->auth->id;
$model = new StoreComment();
$result = $model->add($param);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if(!$result) {
$this->error('提交失败');
}
$this->success('提交成功');
}
/**
* 板币充值列表
* @ApiWeigh (20)
*
* @ApiTitle (板币充值列表)
* @ApiSummary (板币充值列表)
* @ApiMethod (POST)
* @ApiRoute (/api/store/deposit)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"list": [
{
"id": 1,
"money": "充值金额",
"score": "赠送板币",
"weigh": 1,
},
]
}
})
*/
public function deposit()
{
if($this->request->isPost()){
$where = [
'where' => []
];
$deposit = $this->deposit_model->selectOrFail($where,false,'*','weigh');
$return = [
'list' => $deposit,
];
$this->success('请求成功',$return);
}
}
/**
* 板币充值提交
* @ApiWeigh (15)
*
* @ApiTitle (板币充值提交)
* @ApiSummary (板币充值提交)
* @ApiMethod (POST)
* @ApiRoute (/api/store/deposit_order)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="deposit_id", type="integer", required=true, description="板币充值id")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function deposit_order()
{
$param = (new StoreValidate())->goCheck('deposit_order');
$store = $this->get_store();
$deposit = $this->deposit_model->findOrFail(['id'=>$param['depost_id']]);
$order_sn = $param['order_sn'] = get_order_sn();
$pay_data = [];
if($this->auth->end_time > time()) {
$param['status'] = 2;
} else {
$param['status'] = 1;
// 获取小程序配置
$options = \config('miniprogram.basic');
$app = new Application($options);
$payment = $app->payment;
// 获取支付参数
$attributes = [
'body' => '板币充值',
'out_trade_no' => $order_sn,
'total_fee' => 1, // $param['money'] * 100
'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
'notify_url' => url('index/ajax/notify',[],true,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
'openid' => Db::name('third')->where('user_id',$this->auth->id)->value('openid'),
];
$order = new Order($attributes);
$order_result = $payment->pay($order);
if($order_result['return_code'] == 'SUCCESS' && $order_result['result_code'] == 'SUCCESS') {
$prepayId = $order_result->prepay_id;
$pay_data = $payment->configForJSSDKPayment($prepayId); // 返回数组
} else {
$this->error($order_result['return_msg']);
}
}
$model = $this->deposit_order_model;
Db::startTrans();
$result = false;
$result_invite = true;
try{
$param['deposit_id'] = $store['id'];
$param['user_id'] = $this->auth->id;
$param['score'] = $deposit['score'];
$param['money'] = $deposit['money'];
$result = $model->add($param);
$id = $model->id;
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if(!$result || !$result_invite) {
$this->error('提交失败');
}
$this->success('提交成功',['id'=>$id,'status'=>$param['status'],'pay_data'=>$pay_data]);
}
/**
* 获取店铺信息
* @param string $id 店铺id
*/
private function get_store($id = null)
{
$where_s = ['user_id'=>$this->user_id];
if($id) {
$where_s['id'] = $id;
}
$where = [
'where' => $where_s,
'with' => ['user_info']
];
$store = $this->store_model->findOrFail($where,false);
if(!$store) {
$this->error('请先提交商家入驻申请');
}
if($store['status'] == 4) {
$this->error('请先提交商家入驻申请');
}
if($store['status'] == 1) {
$this->error('未提交入驻申请');
}
if($store['status'] == 2) {
$this->error('商家申请仍在审核中');
}
return $store;
}
}