Extension3059ModuleController.php
3.5 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
<?php
/**
* @remark :
* @name :Extension3059ModuleController.php
* @author :lyh
* @method :post
* @time :2024/12/25 9:44
*/
namespace App\Http\Controllers\Bside\ExtensionModule;
use App\Enums\Common\Code;
use App\Helper\PayStripeApi;
use App\Http\Controllers\Bside\BaseController;
use App\Models\ExtentModule\ExtensionModuleValue;
class Extension3059ModuleController extends BaseController
{
/**
* @remark :获取当前所有的商品列表
* @name :getProductLists
* @author :lyh
* @method :post
* @time :2024/12/25 9:37
*/
public function getProductLists(){
$this->param['module_id'] = $this->param['module_id'] ?? 2;//默认加载商品数据
$searchParam = [
'module_id'=>$this->param['module_id'],
];
$data = [];
$moduleValueModel = new ExtensionModuleValue();
$lists = $moduleValueModel->list($searchParam);
if(!empty($lists)){
foreach ($lists as $k => $v){
$data[$v['uuid']][$v['field_id']] = $v['value'];
$data[$v['uuid']]['created_at'] = $v['created_at'];
}
}
$resultData = [];
foreach ($data as $k => $v){
$v['uuid'] = $k;
$resultData[] = $v;
}
$this->response('success',Code::SUCCESS,$resultData);
}
/**
* @remark :编辑订单详情
* @name :editOrderDetail
* @author :lyh
* @method :post
* @time :2024/12/25 10:26
*/
public function saveOrderDetail(){
$this->request->validate([
'data'=>'required',
'amount'=>'required',
'currency'=>'required',
'payment_method_types'=>'required',
],[
'data.required' => '数据不能为空',
'amount.required' => '金额不能为空',
'currency.required' => '币种不能为空',
'payment_method_types.required' => '支付方式不能为空',
]);
$this->param['module_id'] = 1;//默认订单模块
$moduleValueModel = new ExtensionModuleValue();
$info = $moduleValueModel->where('module_id',$this->param['module_id'])->orderBy('uuid','desc')->first();
if(empty($info)){
$uuid = 1;
}else{
$info = $info->toArray();
$uuid = $info['uuid'] + 1;
}
$saveData = [];
try {
//生成订单id
$saveData[] =['uuid'=>$uuid,'module_id'=>$this->param['module_id'],'field_id'=>1,'value'=>md5(uniqid(mt_rand(), true))];
$data = $this->param['data'];
$moduleValueModel = new ExtensionModuleValue();
foreach ($data as $k => $v){
$saveData[] = [
'uuid'=>$uuid,
'module_id'=>$this->param['module_id'],
'field_id'=>$v['field_id'],
'value'=>$v['value']
];
}
$pay = new PayStripeApi();
$data = $pay->createPaymentIntent($this->param['amount'],$this->param['currency'],$this->param['payment_method_types']);
$saveData[] = ['uuid'=>$uuid,'module_id'=>$this->param['module_id'],'field_id'=>8,'value'=>$data['id'] ?? '未获取到支付意愿,请重新获取'];
$moduleValueModel->insertAll($saveData);
}catch (\Exception $e){
$this->fail('error,请联系管理员');
}
$this->response('success',Code::SUCCESS,['uuid'=>$uuid,'data'=>$data]);
}
}