input('limit', 10); $page = $request->input('page', 1); $offset = ($page - 1) * 10; $date = $request->input('date'); $date= $date??Carbon::now()->format('Y-m'); $lists = UserRechargeRecord::filterUser() ->when($date,function ($query,$date){ /* @var Builder $query*/ return $query->where('created_at', 'like', "$date%"); }) ->where('status', 1) ->orderByDesc('id') ->limit($limit) ->offset($offset) ->get(); return $this->success($lists); } public function createOrder() { try { /* @var Setting $setting*/ $setting = Setting::first(); if($setting->is_review) { throw new \Exception('暂不支持,请联系管理员'); } \DB::beginTransaction(); $comboId = \request()->input('id'); $app = $this->getUniFactory(\user()->info->platform); $combo = RechargeCombo::find($comboId); // 避免重复创建订单 一个小时内有未支付的订单直接使用 $recharge = UserRechargeRecord::where('user_id', \user()->id) ->where('combo_id', $combo->id) ->where('status', 0) ->where('created_at','>=', Carbon::now()->subHour()->toDateTimeString()) ->first(); if($recharge){ $pay = Pay::find($recharge->pay_id); if(\user()->info->platform == 3){ $res = $app->payment()->jssdk->bridgeConfig($pay->prepay_id); $res = json_decode($res, true); }else{ $res = [ 'order_id' => $pay->prepay_id, 'order_token' => $pay->token, ]; } }else{ $res = app(Pay::class)->create($app, $combo->price, Pay::SOURCE_RECHARGE); $recharge = new UserRechargeRecord(); $recharge->user_id = \user()->id; $recharge->combo_id = $combo->id; $recharge->price = $combo->price; $recharge->gold = $combo->gold; $recharge->gift = $combo->gift; $recharge->pay_id = $res['pay_id']; $recharge->status = 0; $recharge->save(); if(\user()->info->platform == 3){ $pay = Pay::find($res['pay_id']); $res = $app->payment()->jssdk->bridgeConfig($pay->prepay_id); $res = json_decode($res, true); } } $res['pay_id'] = $recharge->pay_id; \DB::commit(); return $this->success($res); }catch (QueryException $e){ \DB::rollBack(); return $this->error('下单失败'); }catch (\Exception $e){ \DB::rollBack(); return $this->error($e->getMessage()); } } }