You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							56 lines
						
					
					
						
							1.4 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							56 lines
						
					
					
						
							1.4 KiB
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								namespace App\Admin\Repositories;
							 | 
						|
								use App\Models\AdminSetting;
							 | 
						|
								use Dcat\Admin\Grid;
							 | 
						|
								use Dcat\Admin\Repositories\Repository;
							 | 
						|
								use EasyWeChat\Factory;
							 | 
						|
								use GuzzleHttp\Exception\GuzzleException;
							 | 
						|
								use Illuminate\Pagination\LengthAwarePaginator;
							 | 
						|
								
							 | 
						|
								/**
							 | 
						|
								 * 小程序草稿箱
							 | 
						|
								 * Class MiniProgramDraft
							 | 
						|
								 * @package App\Admin\Repositories
							 | 
						|
								 */
							 | 
						|
								class MiniProgramDraft extends Repository
							 | 
						|
								{
							 | 
						|
									public function getPrimaryKeyColumn()
							 | 
						|
									{
							 | 
						|
										return 'draft_id';
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									/**
							 | 
						|
									 * 查询表格数据
							 | 
						|
									 *
							 | 
						|
									 * @param Grid\Model $model
							 | 
						|
									 * @return LengthAwarePaginator
							 | 
						|
									 * @throws GuzzleException
							 | 
						|
									 */
							 | 
						|
									public function get(Grid\Model $model): LengthAwarePaginator
							 | 
						|
									{
							 | 
						|
										$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']);
							 | 
						|
										$config = [
							 | 
						|
											'app_id'   => $setting['service_appid'],
							 | 
						|
											'secret'   => $setting['service_appsecret'],
							 | 
						|
											'token'    => $setting['service_token'],
							 | 
						|
											'aes_key'  => $setting['service_aeskey'],
							 | 
						|
										];
							 | 
						|
								
							 | 
						|
										$openPlatform = Factory::openPlatform($config);
							 | 
						|
										$codeTemplate = $openPlatform['code_template'];
							 | 
						|
								
							 | 
						|
										if (empty($codeTemplate) || (!$list = $codeTemplate->getDrafts())) {
							 | 
						|
											$data['total'] = 0;
							 | 
						|
											$data['subjects'] = [];
							 | 
						|
										} else {
							 | 
						|
											$data['total'] = count($list['draft_list']);
							 | 
						|
											$data['subjects'] = $list['draft_list'] ?? [];
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										return $model->makePaginator(
							 | 
						|
											$data['total'] ?? 0, // 传入总记录数
							 | 
						|
											$data['subjects'] ?? [] // 传入数据二维数组
							 | 
						|
										);
							 | 
						|
									}
							 | 
						|
								}
							 |