Browse Source
Merge branch 'develop' of ssh://8.134.10.79:222/Leadfyy.co/hainan into develop
develop
Merge branch 'develop' of ssh://8.134.10.79:222/Leadfyy.co/hainan into develop
develop
20 changed files with 259 additions and 80 deletions
-
34MySQL_change.sql
-
6app/Admin/Controllers/AgentController.php
-
3app/Admin/Controllers/MiniProgramDraftController.php
-
11app/Admin/Controllers/MiniProgramTemplateController.php
-
2app/Admin/Extensions/Grid/AuditAgent.php
-
2app/Admin/Extensions/Grid/AuditAgentProduct.php
-
2app/Admin/Extensions/Grid/AuditDemandProduct.php
-
2app/Admin/Extensions/Grid/AuditGuide.php
-
2app/Admin/Extensions/Grid/AuditProduct.php
-
56app/Admin/Extensions/Grid/PullTemplateList.php
-
89app/Admin/Extensions/Grid/UploadMiniProgram.php
-
2app/Admin/Repositories/MiniProgramDraft.php
-
2app/Admin/Repositories/MiniProgramList.php
-
60app/Admin/Repositories/MiniProgramTemplate.php
-
21app/Admin/Repositories/MiniProgramTemplateList.php
-
18app/AdminSettled/Controllers/AgentController.php
-
2app/AdminSupplier/Controllers/ProductController.php
-
11app/Models/MiniProgramTemplateList.php
-
11app/Models/MiniProgramUploadLog.php
-
3resources/lang/zh_CN/mini-program.php
@ -0,0 +1,56 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Extensions\Grid; |
||||
|
use App\Models\AdminSetting; |
||||
|
use App\Models\MiniProgramTemplateList; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use EasyWeChat\Factory; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
/** |
||||
|
* 上传(注册)小程序 |
||||
|
* Class UploadMiniProgram |
||||
|
* @package App\Admin\Extensions\Grid |
||||
|
*/ |
||||
|
class PullTemplateList extends RowAction |
||||
|
{ |
||||
|
protected $title = '更新列表'; |
||||
|
|
||||
|
protected function html() |
||||
|
{ |
||||
|
$this->appendHtmlAttribute('class', 'btn btn-primary'); |
||||
|
$this->defaultHtmlAttribute('href', 'javascript:;'); |
||||
|
|
||||
|
return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>"; |
||||
|
} |
||||
|
|
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
try { |
||||
|
$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']; |
||||
|
$list = $codeTemplate->list(); |
||||
|
|
||||
|
MiniProgramTemplateList::insertOrIgnore($list['template_list']); |
||||
|
//删除不存在的数据
|
||||
|
MiniProgramTemplateList::whereNotIn('template_id', array_column($list['template_list'], 'template_id'))->delete(); |
||||
|
|
||||
|
return $this->response()->success("操作成功")->refresh(); |
||||
|
} catch (\Exception $e) { |
||||
|
return $this->response()->error($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['此操作将数据与腾讯服务器数据同步,是否继续?', '']; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,89 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Extensions\Grid; |
||||
|
use App\Common\UserStatus; |
||||
|
use App\Models\AdminSetting; |
||||
|
use App\Models\Agent; |
||||
|
use App\Models\Category; |
||||
|
use App\Models\Channel; |
||||
|
use App\Models\Advertising; |
||||
|
use App\Models\MiniProgramTemplateList; |
||||
|
use App\Models\MiniProgramUploadLog; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
/** |
||||
|
* 上传(注册)小程序 |
||||
|
* Class UploadMiniProgram |
||||
|
* @package App\Admin\Extensions\Grid |
||||
|
*/ |
||||
|
class UploadMiniProgram extends RowAction |
||||
|
{ |
||||
|
protected $title = '上传小程序'; |
||||
|
|
||||
|
protected function html() |
||||
|
{ |
||||
|
$this->appendHtmlAttribute('class', 'btn btn-sm btn-primary'); |
||||
|
$this->defaultHtmlAttribute('href', 'javascript:;'); |
||||
|
|
||||
|
return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>"; |
||||
|
} |
||||
|
|
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$template = MiniProgramTemplateList::orderBy('template_id', 'desc')->first(); |
||||
|
if (MiniProgramUploadLog::query()->where(['agent_id' => $this->getKey(), 'template_id' => $template->template_id])->exists()) { |
||||
|
return $this->response()->error('该代理商已经上传过小程序,无需重复上传'); |
||||
|
} |
||||
|
|
||||
|
$agent = Agent::find($this->getKey()); |
||||
|
if (empty($agent->appid)) { |
||||
|
return $this->response()->error('该代理商未注册过小程序,请先注册'); |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
$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 = \EasyWeChat\Factory::openPlatform($config); |
||||
|
$refreshToken = $openPlatform->getAuthorizer($agent->appid)['authorization_info']['authorizer_refresh_token'] ?? null; |
||||
|
if (!$refreshToken) { |
||||
|
return $this->response()->error('获取refresh_token失败'); |
||||
|
} |
||||
|
$code = $openPlatform->miniProgram($agent->appid, $refreshToken)['code']; |
||||
|
|
||||
|
$templateId = $template->template_id; |
||||
|
$extJson = json_encode(['extAppid' => $agent->appid]); |
||||
|
$version = $template->user_version; |
||||
|
$description = $agent->company_name; |
||||
|
|
||||
|
$commit = $code->commit($templateId, $extJson, $version, $description); |
||||
|
// $qrcode = $code->getQrCode();
|
||||
|
|
||||
|
if (isset($commit['errcode'], $commit['errmsg']) && $commit['errcode'] == 0 && $commit['errmsg'] == 'ok') { |
||||
|
MiniProgramUploadLog::insert([ |
||||
|
'agent_id' => $agent->id, |
||||
|
'appid' => $agent->appid, |
||||
|
'template_id' => $templateId, |
||||
|
]); |
||||
|
return $this->response()->success("上传成功")->refresh(); |
||||
|
} else { |
||||
|
throw new \Exception(join(',', $commit)); |
||||
|
} |
||||
|
} catch (\Exception $e) { |
||||
|
return $this->response()->error($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定要上传小程序吗?', '']; |
||||
|
} |
||||
|
} |
||||
@ -1,60 +0,0 @@ |
|||||
<?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; |
|
||||
use Illuminate\Support\Facades\Cache; |
|
||||
|
|
||||
/** |
|
||||
* 小程序模板 |
|
||||
* Class MiniProgramDraft |
|
||||
* @package App\Admin\Repositories |
|
||||
*/ |
|
||||
class MiniProgramTemplate extends Repository |
|
||||
{ |
|
||||
protected $keyName = 'template_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'], |
|
||||
]; |
|
||||
|
|
||||
$cache_key = 'mini_program:template_list'; |
|
||||
if ($data['subjects'] = Cache::get($cache_key)) { |
|
||||
$data['total'] = count($data['subjects']); |
|
||||
} else { |
|
||||
$openPlatform = Factory::openPlatform($config); |
|
||||
$codeTemplate = $openPlatform['code_template']; |
|
||||
|
|
||||
if (empty($codeTemplate) || (!$list = $codeTemplate->list())) { |
|
||||
$data['total'] = 0; |
|
||||
$data['subjects'] = []; |
|
||||
} else { |
|
||||
$data['total'] = count($list['template_list']); |
|
||||
$data['subjects'] = $list['template_list'] ?? []; |
|
||||
Cache::put($cache_key, $list['template_list'], 120); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return $model->makePaginator( |
|
||||
$data['total'] ?? 0, // 传入总记录数
|
|
||||
$data['subjects'] ?? [] // 传入数据二维数组
|
|
||||
); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,21 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Repositories; |
||||
|
use App\Models\MiniProgramTemplateList as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
/** |
||||
|
* 小程序模板 |
||||
|
* Class MiniProgramDraft |
||||
|
* @package App\Admin\Repositories |
||||
|
*/ |
||||
|
class MiniProgramTemplateList extends EloquentRepository |
||||
|
{ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
|
||||
|
public function __construct() |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
$this->setKeyName('template_id'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Models; |
||||
|
|
||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
|
||||
|
class MiniProgramTemplateList extends Model |
||||
|
{ |
||||
|
use HasFactory; |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Models; |
||||
|
|
||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
|
||||
|
class MiniProgramUploadLog extends Model |
||||
|
{ |
||||
|
use HasFactory; |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue