作者 lyh

gx

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :Extension3059ModuleController.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/12/25 9:44
  8 + */
  9 +
  10 +namespace App\Http\Controllers\Bside\ExtensionModule;
  11 +
  12 +use App\Enums\Common\Code;
  13 +use App\Helper\PayStripeApi;
  14 +use App\Http\Controllers\Bside\BaseController;
  15 +use App\Models\ExtentModule\ExtensionModuleValue;
  16 +
  17 +class Extension3059ModuleController extends BaseController
  18 +{
  19 + /**
  20 + * @remark :获取当前所有的商品列表
  21 + * @name :getProductLists
  22 + * @author :lyh
  23 + * @method :post
  24 + * @time :2024/12/25 9:37
  25 + */
  26 + public function getProductLists(){
  27 + $this->param['module_id'] = $this->param['module_id'] ?? 2;//默认加载商品数据
  28 + $searchParam = [
  29 + 'module_id'=>$this->param['module_id'],
  30 + ];
  31 + $data = [];
  32 + $moduleValueModel = new ExtensionModuleValue();
  33 + $lists = $moduleValueModel->list($searchParam);
  34 + if(!empty($lists)){
  35 + foreach ($lists as $k => $v){
  36 + $data[$v['uuid']][$v['field_id']] = $v['value'];
  37 + $data[$v['uuid']]['created_at'] = $v['created_at'];
  38 + }
  39 + }
  40 + $resultData = [];
  41 + foreach ($data as $k => $v){
  42 + $v['uuid'] = $k;
  43 + $resultData[] = $v;
  44 + }
  45 + $this->response('success',Code::SUCCESS,$resultData);
  46 + }
  47 +
  48 +
  49 +
  50 + /**
  51 + * @remark :编辑订单详情
  52 + * @name :editOrderDetail
  53 + * @author :lyh
  54 + * @method :post
  55 + * @time :2024/12/25 10:26
  56 + */
  57 + public function saveOrderDetail(){
  58 + $this->request->validate([
  59 + 'data'=>'required',
  60 + 'amount'=>'required',
  61 + 'currency'=>'required',
  62 + 'payment_method_types'=>'required',
  63 + ],[
  64 + 'data.required' => '数据不能为空',
  65 + 'amount.required' => '金额不能为空',
  66 + 'currency.required' => '币种不能为空',
  67 + 'payment_method_types.required' => '支付方式不能为空',
  68 + ]);
  69 + $this->param['module_id'] = 1;//默认订单模块
  70 + $moduleValueModel = new ExtensionModuleValue();
  71 + $info = $moduleValueModel->where('module_id',$this->param['module_id'])->orderBy('uuid','desc')->first();
  72 + if(empty($info)){
  73 + $uuid = 1;
  74 + }else{
  75 + $info = $info->toArray();
  76 + $uuid = $info['uuid'] + 1;
  77 + }
  78 + $saveData = [];
  79 + try {
  80 + //生成订单id
  81 + $saveData[] =['uuid'=>$uuid,'module_id'=>$this->param['module_id'],'field_id'=>1,'value'=>md5(uniqid(mt_rand(), true))];
  82 + $data = $this->param['data'];
  83 + $moduleValueModel = new ExtensionModuleValue();
  84 + foreach ($data as $k => $v){
  85 + $saveData[] = [
  86 + 'uuid'=>$uuid,
  87 + 'module_id'=>$this->param['module_id'],
  88 + 'field_id'=>$v['field_id'],
  89 + 'value'=>$v['value']
  90 + ];
  91 + }
  92 + $pay = new PayStripeApi();
  93 + $data = $pay->createPaymentIntent($this->param['amount'],$this->param['currency'],$this->param['payment_method_types']);
  94 + $saveData[] = ['uuid'=>$uuid,'module_id'=>$this->param['module_id'],'field_id'=>8,'value'=>$data['id'] ?? '未获取到支付意愿,请重新获取'];
  95 + $moduleValueModel->insertAll($saveData);
  96 + }catch (\Exception $e){
  97 + $this->fail('error,请联系管理员');
  98 + }
  99 + $this->response('success',Code::SUCCESS,['uuid'=>$uuid,'data'=>$data]);
  100 + }
  101 +}
@@ -185,13 +185,7 @@ class ExtensionModuleController extends BaseController @@ -185,13 +185,7 @@ class ExtensionModuleController extends BaseController
185 foreach ($data as $k => $v){ 185 foreach ($data as $k => $v){
186 $info = $moduleValueModel->read(['uuid'=>$this->param['uuid'],'field_id'=>$v['field_id'],'module_id'=>$this->param['module_id']]); 186 $info = $moduleValueModel->read(['uuid'=>$this->param['uuid'],'field_id'=>$v['field_id'],'module_id'=>$this->param['module_id']]);
187 if($info === false){ 187 if($info === false){
188 - if($this->user['project_id'] == 2205 && $this->param['module_id'] == 1){  
189 - if($v['field_id'] == 12 && !empty($v['value'])){//下拉框数据  
190 - if($v['value'] != 'Ordered'){  
191 - $this->fail('请从第一个流程开始选择。');  
192 - }  
193 - }  
194 - } 188 + $this->edit2205ModuleValue($v);
195 $data = [ 189 $data = [
196 'uuid'=>$this->param['uuid'], 190 'uuid'=>$this->param['uuid'],
197 'module_id'=>$this->param['module_id'], 191 'module_id'=>$this->param['module_id'],
@@ -200,6 +194,22 @@ class ExtensionModuleController extends BaseController @@ -200,6 +194,22 @@ class ExtensionModuleController extends BaseController
200 ]; 194 ];
201 $moduleValueModel->addReturnId($data); 195 $moduleValueModel->addReturnId($data);
202 }else{ 196 }else{
  197 + $this->edit2205ModuleValue($v);
  198 + $moduleValueModel->edit(['value'=>$v['value'] ?? ''],['id'=>$info['id']]);
  199 + }
  200 + }
  201 + $this->response('success',Code::SUCCESS,['uuid'=>$this->param['uuid']]);
  202 + }
  203 +
  204 + /**
  205 + * @remark :2205项目单独处理
  206 + * @name :edit2205ModuleValue
  207 + * @author :lyh
  208 + * @method :post
  209 + * @time :2024/12/25 10:12
  210 + */
  211 + public function edit2205ModuleValue($v){
  212 + if(isset($this->param['id']) && !empty($this->param['id'])){
203 if($this->user['project_id'] == 2205 && $this->param['module_id'] == 1){ 213 if($this->user['project_id'] == 2205 && $this->param['module_id'] == 1){
204 if($v['field_id'] == 12 && (!empty($v['value']) && !empty($info['value']))){//下拉框数据 214 if($v['field_id'] == 12 && (!empty($v['value']) && !empty($info['value']))){//下拉框数据
205 $filedModel = new ExtensionModuleField(); 215 $filedModel = new ExtensionModuleField();
@@ -221,12 +231,16 @@ class ExtensionModuleController extends BaseController @@ -221,12 +231,16 @@ class ExtensionModuleController extends BaseController
221 } 231 }
222 } 232 }
223 } 233 }
224 - $moduleValueModel->edit(['value'=>$v['value'] ?? ''],['id'=>$info['id']]); 234 + }else{
  235 + if($this->user['project_id'] == 2205 && $this->param['module_id'] == 1){
  236 + if($v['field_id'] == 12 && !empty($v['value'])){//下拉框数据
  237 + if($v['value'] != 'Ordered'){
  238 + $this->fail('请从第一个流程开始选择。');
  239 + }
  240 + }
225 } 241 }
226 } 242 }
227 - $this->response('success',Code::SUCCESS,['uuid'=>$this->param['uuid']]);  
228 } 243 }
229 -  
230 244
231 /** 245 /**
232 * @remark :新增數據 246 * @remark :新增數據
@@ -252,13 +266,7 @@ class ExtensionModuleController extends BaseController @@ -252,13 +266,7 @@ class ExtensionModuleController extends BaseController
252 $data = $this->param['data']; 266 $data = $this->param['data'];
253 $moduleValueModel = new ExtensionModuleValue(); 267 $moduleValueModel = new ExtensionModuleValue();
254 foreach ($data as $k => $v){ 268 foreach ($data as $k => $v){
255 - if($this->user['project_id'] == 2205 && $this->param['module_id'] == 1){  
256 - if($v['field_id'] == 12 && !empty($v['value'])){//下拉框数据  
257 - if($v['value'] != 'Ordered'){  
258 - $this->fail('请重第一个流程开始选择');  
259 - }  
260 - }  
261 - } 269 + $this->edit2205ModuleValue($v);
262 $data = [ 270 $data = [
263 'uuid'=>$uuid, 271 'uuid'=>$uuid,
264 'module_id'=>$this->param['module_id'], 272 'module_id'=>$this->param['module_id'],
@@ -12,9 +12,11 @@ namespace App\Http\Controllers\Bside\PayStripe; @@ -12,9 +12,11 @@ namespace App\Http\Controllers\Bside\PayStripe;
12 use App\Enums\Common\Code; 12 use App\Enums\Common\Code;
13 use App\Helper\PayStripeApi; 13 use App\Helper\PayStripeApi;
14 use App\Http\Controllers\Bside\BaseController; 14 use App\Http\Controllers\Bside\BaseController;
  15 +use App\Models\ExtentModule\ExtensionModuleValue;
15 16
16 class PayStripeController extends BaseController 17 class PayStripeController extends BaseController
17 { 18 {
  19 +
18 /** 20 /**
19 * @remark :获取支付方式 21 * @remark :获取支付方式
20 * @name :getPayMethod 22 * @name :getPayMethod
@@ -36,10 +38,8 @@ class PayStripeController extends BaseController @@ -36,10 +38,8 @@ class PayStripeController extends BaseController
36 * @time :2024/12/24 14:56 38 * @time :2024/12/24 14:56
37 */ 39 */
38 public function createPaymentIntent(){ 40 public function createPaymentIntent(){
39 - $pay = new PayStripeApi();  
40 - $data = $pay->createPaymentIntent(100,'cny'); 41 +
  42 + //创建订单--记录当前的stripe_id
41 $this->response('success',Code::SUCCESS,$data); 43 $this->response('success',Code::SUCCESS,$data);
42 } 44 }
43 -  
44 -  
45 } 45 }
@@ -32,9 +32,9 @@ class ExtensionModuleFieldLogic extends BaseLogic @@ -32,9 +32,9 @@ class ExtensionModuleFieldLogic extends BaseLogic
32 public function saveModuleField(){ 32 public function saveModuleField(){
33 //先查看当前字段是否存在 33 //先查看当前字段是否存在
34 if(isset($this->param['id']) && !empty($this->param['id'])){ 34 if(isset($this->param['id']) && !empty($this->param['id'])){
35 - $info = $this->model->read(['field_name'=>$this->param['field_name'],'id'=>['!=',$this->param['id']]]); 35 + $info = $this->model->read(['field_name'=>$this->param['field_name'],'module_id'=>$this->param['module_id'],'id'=>['!=',$this->param['id']]]);
36 }else{ 36 }else{
37 - $info = $this->model->read(['field_name'=>$this->param['field_name']]); 37 + $info = $this->model->read(['field_name'=>$this->param['field_name'],'module_id'=>$this->param['module_id']]);
38 } 38 }
39 if($info !== false){ 39 if($info !== false){
40 $this->fail('当前字段名已存在'); 40 $this->fail('当前字段名已存在');
@@ -116,6 +116,24 @@ class Base extends Model @@ -116,6 +116,24 @@ class Base extends Model
116 } 116 }
117 117
118 /** 118 /**
  119 + * @remark :批量添加数据
  120 + * @name :addAllReturnId
  121 + * @author :lyh
  122 + * @method :post
  123 + * @time :2024/12/25 11:16
  124 + */
  125 + public function insertAll($data){
  126 + if(is_array($data)){
  127 + foreach ($data as $k => $sonData){
  128 + $sonData['created_at'] = date('Y-m-d H:i:s');
  129 + $sonData['updated_at'] = $sonData['created_at'];
  130 + $data[$k] = $sonData;
  131 + }
  132 + }
  133 + return $this->insert($data);
  134 + }
  135 +
  136 + /**
119 * @remark :统计数量 137 * @remark :统计数量
120 * @name :count 138 * @name :count
121 * @author :lyh 139 * @author :lyh