Skip to content

Commit e0798bb

Browse files
committed
新增:演示数据内容修复
1 parent 24484a3 commit e0798bb

37 files changed

Lines changed: 1935 additions & 308 deletions

File tree

app/Console/Commands/DumpDemoDataCommand.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,26 @@ public function handle()
1414
'inserts' => $this->buildInsert(
1515
['config', ['key', 'value'], function ($item) {
1616
return in_array($item['key'], [
17+
1718
'siteName',
1819
'siteDescription',
1920
'siteKeywords',
2021
'siteLogo',
2122
'siteSlogan',
2223
'siteDomain',
23-
'systemCounter',
24-
'Blog_Avatar',
25-
'Blog_Slogan',
24+
2625
'Blog_Name',
26+
'Blog_Slogan',
27+
'Blog_Avatar',
28+
'Blog_ContactQQ',
29+
'Blog_ContactWeibo',
30+
'Blog_ContactWechat',
31+
2732
'Blog_AboutContent',
2833
]);
2934
}],
3035
'blog',
3136
'blog_category',
32-
'blog_message',
3337
'banner',
3438
'partner',
3539
'nav'

module/Vendor/LazyValue/LazyValueJob.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
use ModStart\Core\Util\SerializeUtil;
88
use Module\Vendor\Log\Logger;
99

10+
11+
/**
12+
* Class LazyValueJob
13+
* @package Module\Vendor\LazyValue
14+
* @deprecated delete at 2024-07-16
15+
*/
1016
class LazyValueJob extends BaseJob
1117
{
1218
private $key;

module/Vendor/LazyValue/LazyValueProcessor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Module\Vendor\LazyValue;
44

5+
/**
6+
* Interface LazyValueProcessor
7+
* @package Module\Vendor\LazyValue
8+
* @deprecated delete at 2024-07-16
9+
*/
510
interface LazyValueProcessor
611
{
712
function execute($param);

module/Vendor/LazyValue/LazyValueUtil.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
use ModStart\Core\Util\SerializeUtil;
99
use Module\Vendor\Util\CacheUtil;
1010

11+
/**
12+
* Class LazyValueUtil
13+
* @package Module\Vendor\LazyValue
14+
* @deprecated delete at 2024-07-16
15+
*/
1116
class LazyValueUtil
1217
{
1318
public static function hash($key, $callback)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
4+
namespace Module\Vendor\Lib\AdminApi;
5+
6+
7+
use ModStart\Core\Input\Response;
8+
use ModStart\Core\Util\CurlUtil;
9+
10+
class AdminApi
11+
{
12+
private $base;
13+
private $apiKey;
14+
15+
/**
16+
* @param $base string 基础URL
17+
* @param $apiKey string API Key
18+
* @return AdminApi
19+
*/
20+
public static function build($base = null, $apiKey = null)
21+
{
22+
if (null === $base) {
23+
$base = modstart_config('AdminApiRequest_Base', '');
24+
}
25+
if (null === $apiKey) {
26+
$apiKey = modstart_config('AdminApiRequest_ApiKey', '');
27+
}
28+
$ins = new static();
29+
$ins->base = $base;
30+
$ins->apiKey = $apiKey;
31+
return $ins;
32+
}
33+
34+
public function ping()
35+
{
36+
return $this->request('admin_api/ping', []);
37+
}
38+
39+
public function uploadImage($filename, $content)
40+
{
41+
return $this->request('admin_api/upload/image', [
42+
'filename' => $filename,
43+
'base64Content' => base64_encode($content),
44+
]);
45+
}
46+
47+
public function uploadImageTemp($filename, $content)
48+
{
49+
return $this->request('admin_api/upload/image_temp', [
50+
'filename' => $filename,
51+
'base64Content' => base64_encode($content),
52+
]);
53+
}
54+
55+
public function uploadFile($filename, $content)
56+
{
57+
return $this->request('admin_api/upload/file', [
58+
'filename' => $filename,
59+
'base64Content' => base64_encode($content),
60+
]);
61+
}
62+
63+
public function uploadFileTemp($filename, $content)
64+
{
65+
return $this->request('admin_api/upload/file_temp', [
66+
'filename' => $filename,
67+
'base64Content' => base64_encode($content),
68+
]);
69+
}
70+
71+
public function request($url, $data)
72+
{
73+
$url = rtrim($this->base, '/') . '/' . ltrim($url, '/');
74+
$ret = CurlUtil::request(
75+
$url,
76+
$data,
77+
[
78+
'method' => 'post',
79+
'header' => [
80+
'admin-api-key' => $this->apiKey
81+
]
82+
]
83+
);
84+
if (200 == $ret['code']) {
85+
$result = @json_decode($ret['body'], true);
86+
if (empty($result)) {
87+
return Response::generate(0, '接口返回数据格式错误', [
88+
'body' => $ret['body']
89+
]);
90+
}
91+
return Response::generateSuccessData($result);
92+
}
93+
return Response::generate(0, '接口请求失败', [
94+
'code' => $ret['code'],
95+
'body' => $ret['body']
96+
]);
97+
}
98+
}

module/Vendor/Migrate/2018_10_24_000000_create_lazy_value.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public function up()
1717
$table->increments('id');
1818
$table->timestamps();
1919

20-
$table->string('key', 50)->nullable()->comment('');
21-
$table->string('param', 100)->nullable()->comment('');
20+
$table->string('key', 50)->nullable()->comment('业务标识');
21+
$table->string('param', 100)->nullable()->comment('参数JSON');
2222
$table->integer('expire')->nullable()->comment('');
2323
$table->integer('lifeExpire')->nullable()->comment('');
2424
$table->integer('cacheSeconds')->nullable()->comment('');
@@ -40,4 +40,4 @@ public function down()
4040
{
4141

4242
}
43-
}
43+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
4+
namespace Module\Vendor\Provider\LazyValue;
5+
6+
7+
use ModStart\Core\Dao\ModelUtil;
8+
use ModStart\Core\Exception\BizException;
9+
use ModStart\Core\Util\SerializeUtil;
10+
use Module\Vendor\Model\LazyValue;
11+
12+
abstract class AbstractLazyValueBiz
13+
{
14+
abstract public function name();
15+
16+
abstract public function title();
17+
18+
abstract public function execute($param = []);
19+
20+
public function cacheSeconds()
21+
{
22+
return 1800;
23+
}
24+
25+
public function defaultValue()
26+
{
27+
return null;
28+
}
29+
30+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
4+
namespace Module\Vendor\Provider\LazyValue;
5+
6+
7+
use ModStart\Core\Dao\ModelUtil;
8+
use ModStart\Core\Exception\BizException;
9+
use ModStart\Core\Input\Response;
10+
use ModStart\Core\Util\SerializeUtil;
11+
use Module\Vendor\Model\LazyValue;
12+
use Module\Vendor\Provider\BizTrait;
13+
14+
/**
15+
* @method static AbstractLazyValueBiz[] listAll()
16+
* @method static AbstractLazyValueBiz getByName($name)
17+
*/
18+
class LazyValueBiz
19+
{
20+
use BizTrait;
21+
22+
public static function dispatch($biz, $param)
23+
{
24+
$job = new LazyValueJob();
25+
$job->key = $biz;
26+
$job->param = $param;
27+
$job->onQueue('LazyValue');
28+
app('Illuminate\Contracts\Bus\Dispatcher')->dispatch($job);
29+
}
30+
31+
public static function dispatchRefresh($biz, $param)
32+
{
33+
$job = new LazyValueJob();
34+
$job->key = $biz;
35+
$job->param = $param;
36+
$job->onQueue('LazyValueRefresh');
37+
app('Illuminate\Contracts\Bus\Dispatcher')->dispatch($job);
38+
}
39+
40+
public static function get($biz, $param = [], $expireLife = 86400)
41+
{
42+
$bizer = self::getByName($biz);
43+
BizException::throwsIfEmpty("BizNotFound", $bizer);
44+
$where = [
45+
'key' => $bizer->name(),
46+
'param' => SerializeUtil::jsonEncode($param)
47+
];
48+
$record = ModelUtil::get(LazyValue::class, $where);
49+
if (empty($record)) {
50+
ModelUtil::insert(LazyValue::class, array_merge([
51+
'expire' => time() + $bizer->cacheSeconds(),
52+
'lifeExpire' => time() + $expireLife,
53+
'cacheSeconds' => $bizer->cacheSeconds(),
54+
'value' => SerializeUtil::jsonEncode($bizer->defaultValue()),
55+
], $where));
56+
LazyValueBiz::dispatch($bizer->name(), $param);
57+
return [
58+
'status' => 'running',
59+
'value' => $bizer->defaultValue(),
60+
];
61+
}
62+
if ($record['expire'] < time()) {
63+
LazyValueBiz::dispatchRefresh($bizer->name(), $param);
64+
}
65+
$value = @json_decode($record['value'], true);
66+
if (empty($value)) {
67+
return [
68+
'status' => 'running',
69+
'value' => $bizer->defaultValue(),
70+
];
71+
}
72+
return [
73+
'status' => 'finish',
74+
'value' => $value,
75+
];
76+
}
77+
78+
private static function status(&$value)
79+
{
80+
foreach ($value as $v) {
81+
if (null === $v) {
82+
return 'running';
83+
}
84+
}
85+
return 'finish';
86+
}
87+
88+
public static function fetch($bizParamList = [])
89+
{
90+
$status = 'finish';
91+
$value = [];
92+
foreach ($bizParamList as $k => $v) {
93+
if (!isset($v['param'])) {
94+
$v['param'] = [];
95+
}
96+
$ret = LazyValueBiz::get($v['biz'], $v['param']);
97+
if ($ret['status'] == 'running') {
98+
$status = 'running';
99+
}
100+
$value[$k] = $ret;
101+
}
102+
return Response::generate(0, 'ok', [
103+
'status' => $status,
104+
'value' => $value,
105+
]);
106+
}
107+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
4+
namespace Module\Vendor\Provider\LazyValue;
5+
6+
7+
use Illuminate\Support\Facades\Log;
8+
use ModStart\Core\Dao\ModelUtil;
9+
use ModStart\Core\Input\Response;
10+
use ModStart\Core\Job\BaseJob;
11+
use ModStart\Core\Util\SerializeUtil;
12+
use Module\Vendor\Model\LazyValue;
13+
14+
class LazyValueJob extends BaseJob
15+
{
16+
public $key;
17+
public $param;
18+
19+
public function handle()
20+
{
21+
if (null === $this->param) {
22+
$this->param = [];
23+
}
24+
Log::info("Vendor.LazyValue - Start - {$this->key}." . SerializeUtil::jsonEncode($this->param));
25+
$bizer = LazyValueBiz::getByName($this->key);
26+
if (empty($bizer)) {
27+
Log::info("Vendor.LazyValue - Error.BizNotFound");
28+
return;
29+
}
30+
$ret = $bizer->execute($this->param);
31+
if (Response::isError($ret)) {
32+
Log::info("Vendor.LazyValue - Error.BizExecuteError - " . SerializeUtil::jsonEncode($ret));
33+
return;
34+
}
35+
$value = $ret['data'];
36+
Log::info("Vendor.LazyValue - Value - " . SerializeUtil::jsonEncode($value));
37+
$where = [
38+
'key' => $this->key,
39+
'param' => SerializeUtil::jsonEncode($this->param),
40+
];
41+
$first = ModelUtil::get(LazyValue::class, $where);
42+
if (empty($first)) {
43+
Log::info("Vendor.LazyValue - Error.RecordNotFound");
44+
return;
45+
}
46+
ModelUtil::update(LazyValue::class, $first['id'], [
47+
'expire' => time() + $bizer->cacheSeconds(),
48+
'value' => SerializeUtil::jsonEncode($value),
49+
]);
50+
Log::info("Vendor.LazyValue - End");
51+
}
52+
}

module/Vendor/Provider/SiteUrl/AbstractSiteUrlBiz.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ abstract public function urlBuildBatch($nextId, $param = []);
2929
// 'nextId'=>$batchRet['nextId'],
3030
// ];
3131
// }
32+
33+
public static function update($url, $title = '', $param = [])
34+
{
35+
SiteUrlProvider::updateBiz(static::NAME, $url, $title, $param);
36+
}
3237
}

0 commit comments

Comments
 (0)