blue2(); // 卡片内容宽度 $this->contentWidth(11, 1); // 标题 $this->title('合约交易'); // 设置下拉选项 $coin_options = OptionBetCoin::query()->where('is_bet', 1)->orderBy('sort', 'desc')->orderBy('coin_id', 'asc')->pluck('coin_name', 'coin_id')->toArray(); $this->dropdown($coin_options); // 设置图表颜色 $this->chartColors([ $dark35, $dark35, $dark35, $dark35, $dark35, $color->success(), ]); $this->request('POST', $this->getRequestUrl(), ['user_id' => request()->input('key')]); // 设置API请求地址 携带参数 // $this->handle(request()); } /** * 处理请求 * * @param Request $request * * @return mixed|void */ public function handle(Request $request) { $user_id = $request->get('user_id', null); $builder1 = ContractEntrust::query() ->where('user_id', $user_id) // ->whereNotIn('status', [0, 1]) ->get(['fee', 'profit', 'created_at']); $builder2 = $builder1 ->where('created_at', '>=', Carbon::today()->toDayDateTimeString()) ->where('created_at', '<', Carbon::today()->addDay()->toDateTimeString()); $value1 = $builder1->count(); //下单量 $value2 = $builder1->sum('profit'); //用户盈亏 $value3 = $builder1->sum('fee'); //总手续费 $value4 = $builder2->count(); //下单量 $value5 = $builder2->sum('profit'); //用户盈亏 $value6 = $builder2->sum('fee'); //总手续费 // 卡片内容 $this->withContent($user_id, $value1, $value2, $value3, $value4, $value5, $value6); // // 图表数据 // for ($i = 6; $i >= 0; $i--) { // $chart_data[] = $builder1 // ->where('created_at', '>=', Carbon::today()->subDays($i)) // ->where('created_at', '<', Carbon::today()->subDays($i - 1)) // ->count(); // } // $this->withChart([ // [ // 'name' => 'Bet amount', // 'data' => $chart_data // ], // ]); } /** * 设置图表数据. * * @param array $data * * @return $this */ public function withChart(array $data) { return $this->chart([ 'series' => $data, ]); } /** * 设置卡片内容. * * @param int $referrer * @param string $value1 * @param string $value2 * @param string $value3 * @param string $value4 * @param string $value5 * @param string $value6 * * @return $this */ public function withContent($user_id, string $value1, string $value2, string $value3, string $value4, string $value5, string $value6) { // 根据选项显示 $label = strtolower( $this->dropdown[request()->option] ?? 'last 7 days' ); $minHeight = '183px'; $admin_url = admin_url(); return $this->content( <<