|
|
@@ -3,6 +3,9 @@ declare (strict_types = 1);
|
|
|
namespace App\Controller;
|
|
|
|
|
|
use App\JsonRpc\PublicRpcServiceInterface;
|
|
|
+use App\Model\Couplet;
|
|
|
+use App\Model\HistoryToday;
|
|
|
+use App\Model\Riddle;
|
|
|
use App\Tools\CommonService;
|
|
|
use App\Tools\PublicData;
|
|
|
use App\Tools\Result;
|
|
|
@@ -1266,5 +1269,95 @@ class PublicController extends AbstractController
|
|
|
$result = $this->publicServiceClient->getCalendar($data);
|
|
|
return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加历史上的今天
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function addHistoryToday()
|
|
|
+ {
|
|
|
+ $result = PublicData::getHistoryToday();
|
|
|
+ if($result['code']!=200){
|
|
|
+ return Result::error($result['msg']);
|
|
|
+ }
|
|
|
+ $dataList = $result['data']??[];
|
|
|
+ if($dataList){
|
|
|
+ foreach ($dataList as $value){
|
|
|
+ preg_match('/^(-?\d+)年(\d+)月(\d+)日$/', $value['year'], $matches);
|
|
|
+ if (isset($matches[1], $matches[2], $matches[3])) {
|
|
|
+ $year = $matches[1];
|
|
|
+ $month = str_pad($matches[2], 2, '0', STR_PAD_LEFT); // 补零至两位
|
|
|
+ $day = str_pad($matches[3], 2, '0', STR_PAD_LEFT); // 补零至两位
|
|
|
+ $formattedDate = "{$year}-{$month}-{$day}";
|
|
|
+// echo $formattedDate; // 输出:-1184-04-24
|
|
|
+ } else {
|
|
|
+ return Result::error($result['msg']);
|
|
|
+ }
|
|
|
+ $value['year'] = $formattedDate;
|
|
|
+ HistoryToday::updateOrInsert(
|
|
|
+ ['title' => $value['title']],
|
|
|
+ ['title' => $value['title']??'','year' => $value['year']]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result::success($result['data']);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 添加对联
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function addCouplet()
|
|
|
+ {
|
|
|
+ $requireData = $this->request->all();
|
|
|
+// $validator = $this->validationFactory->make(
|
|
|
+// $requireData,
|
|
|
+// [
|
|
|
+// 'type' => 'required',
|
|
|
+// ],
|
|
|
+// [
|
|
|
+// 'type.required' => 'type不能为空',
|
|
|
+// ]
|
|
|
+// );
|
|
|
+// if ($validator->fails()) {
|
|
|
+// $errorMessage = $validator->errors()->first();
|
|
|
+// return Result::error($errorMessage);
|
|
|
+// }
|
|
|
+ $result = PublicData::getCouplet($requireData['type']??"");
|
|
|
+ if($result['code']!=200){
|
|
|
+ return Result::error($result['msg']);
|
|
|
+ }
|
|
|
+ $dataList = $result['result']['list']??[];
|
|
|
+ if($dataList){
|
|
|
+ foreach ($dataList as $value){
|
|
|
+ Couplet::updateOrInsert(
|
|
|
+ ['first' => $value['shanglian']],
|
|
|
+ ['center' => $value['hengpi']??'','first' => $value['shanglian'],'second'=>$value['xialian'],'type'=>$value['fenlei']??'']
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result::success($result['result']['list']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加对联
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function addRiddle()
|
|
|
+ {
|
|
|
+ for ($i = 0; $i < 5; $i++) {
|
|
|
+ $result = PublicData::addRiddle();
|
|
|
+ if($result['code']!=1){
|
|
|
+ return Result::error("没资源了");
|
|
|
+ }
|
|
|
+ var_dump($result);
|
|
|
+ Riddle::updateOrInsert(
|
|
|
+ ['riddle_title' => $result['mt']],
|
|
|
+ ['riddle_title' => $result['mt']??'','riddle_bottom' => $result['md']??'','type' => $result['lx']??'','prompt' => $result['ts']??'']
|
|
|
+ );
|
|
|
+ $i++;
|
|
|
+ sleep(2);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
}
|
|
|
|