Extension3059ModuleController.php
4.9 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
<?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\ExtensionModuleField;
use App\Models\ExtentModule\ExtensionModuleValue;
class Extension3059ModuleController extends BaseController
{
/**
* @remark :获取当前所有的商品列表
* @name :getProductLists
* @author :lyh
* @method :post
* @time :2024/12/25 9:37
*/
public function get3059Product(){
$this->param['module_id'] = $this->param['module_id'] ?? 2;//默认加载商品数据
$searchParam = [
'module_id'=>$this->param['module_id'],
];
$data = [];
$filedData = $this->getFiledList();
$moduleValueModel = new ExtensionModuleValue();
$lists = $moduleValueModel->list($searchParam);
if(!empty($lists)){
foreach ($lists as $k => $v){
$data[$v['uuid']][$filedData[$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 :getFiledList
* @author :lyh
* @method :post
* @time :2024/12/25 14:13
*/
public function getFiledList(){
$moduleFieldModel = new ExtensionModuleField();
$this->param['module_id'] = 2;//商品的所有字段
$filedList = $moduleFieldModel->list(['module_id'=>$this->param['module_id']],'sort',['id','field_name'],'desc');
$data = [];
if(!empty($filedList)){
foreach ($filedList as $k => $v){
$data[$v['id']] = $v['field_name'];
}
}
return $data;
}
/**
* @remark :编辑订单详情
* @name :editOrderDetail
* @author :lyh
* @method :post
* @time :2024/12/25 10:26
*/
public function save3059OrderDetail(){
$this->param = [
'amount'=>1000,
'currency'=>'cny',
'payment_method_types'=>'alipay',
'data'=>[
['field_id'=>2, 'value'=>'20241225114204'],
['field_id'=>3, 'value'=>date('Y-m-d H:i:s')],
['field_id'=>4, 'value'=>1000],
['field_id'=>5, 'value'=>'成都市武侯区二仙桥走成华大道'],
['field_id'=>9, 'value'=>'cny'],
['field_id'=>10, 'value'=>'alipay'],
['field_id'=>14, 'value'=>'二仙桥大爷'],
['field_id'=>14, 'value'=>'15687012587'],
]
];
// $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]);
}
}