|
@@ -230,6 +230,7 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function addArticle(array $data): array
|
|
|
{
|
|
|
+ var_dump($data, '----------12-----------1');
|
|
|
var_dump($data, '----------12-----------1');
|
|
|
unset($data['user_type']);
|
|
|
// unset($data['web_site_id']);
|
|
@@ -247,6 +248,16 @@ class NewsService implements NewsServiceInterface
|
|
|
unset($data['suvey_array']);
|
|
|
unset($data['website_id']);
|
|
|
|
|
|
+ if ($data['hits'] == '') {
|
|
|
+ $data['hits'] = 0;
|
|
|
+ }
|
|
|
+ if ($data['is_original'] == '') {
|
|
|
+ $data['is_original'] = 0;
|
|
|
+ }
|
|
|
+ if ($data['status'] == '') {
|
|
|
+ $data['status'] = 0;
|
|
|
+ }
|
|
|
+
|
|
|
$articleData = $data;
|
|
|
unset($articleData['content']);
|
|
|
$id = Article::insertGetId($articleData);
|
|
@@ -260,7 +271,8 @@ class NewsService implements NewsServiceInterface
|
|
|
if ($is_survey == 1) {
|
|
|
//生成年月日时分秒+8位随机数
|
|
|
$uuid = date('YmdHis') . rand(10000000, 99999999);
|
|
|
- $suveys_array = json_decode($suvey_array);
|
|
|
+ var_dump($suvey_array, 'suvey_array________');
|
|
|
+ $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
|
|
|
var_dump($suveys_array, '---------------------1');
|
|
|
var_dump($suvey_array, '---------------------2');
|
|
|
$suvey_data = [];
|
|
@@ -276,7 +288,7 @@ class NewsService implements NewsServiceInterface
|
|
|
'survey_name' => $survey_name,
|
|
|
'choice_name' => $value[1],
|
|
|
'is_other' => 1,
|
|
|
- 'orther_id' => 0,
|
|
|
+ 'other_id' => 0,
|
|
|
'results' => 0,
|
|
|
|
|
|
];
|
|
@@ -288,7 +300,7 @@ class NewsService implements NewsServiceInterface
|
|
|
'survey_name' => $survey_name,
|
|
|
'choice_name' => $value,
|
|
|
'is_other' => 0,
|
|
|
- 'orther_id' => 0,
|
|
|
+ 'other_id' => 0,
|
|
|
'results' => 0,
|
|
|
|
|
|
];
|
|
@@ -338,6 +350,7 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function updateArticle(array $data): array
|
|
|
{
|
|
|
+ var_dump($data, '----------12-----------1');
|
|
|
Db::beginTransaction();
|
|
|
unset($data['user_type']);
|
|
|
// unset($data['web_site_id']);
|
|
@@ -352,6 +365,15 @@ class NewsService implements NewsServiceInterface
|
|
|
unset($data['survey_name']);
|
|
|
unset($data['suvey_array']);
|
|
|
unset($data['website_id']);
|
|
|
+ if ($data['hits'] == '') {
|
|
|
+ $data['hits'] = 0;
|
|
|
+ }
|
|
|
+ if ($data['is_original'] == '') {
|
|
|
+ $data['is_original'] = 0;
|
|
|
+ }
|
|
|
+ if ($data['status'] == '') {
|
|
|
+ $data['status'] = 0;
|
|
|
+ }
|
|
|
|
|
|
$data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
|
|
|
$data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
|
|
@@ -370,49 +392,51 @@ class NewsService implements NewsServiceInterface
|
|
|
//处理投票
|
|
|
$id = $data['id'];
|
|
|
$surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
|
|
|
- var_dump($surveydata, 'suvey_array________delete');
|
|
|
+ var_dump($suvey_array, 'suvey_array________delete');
|
|
|
|
|
|
//处理投票
|
|
|
if ($is_survey == 1) {
|
|
|
//生成年月日时分秒+8位随机数
|
|
|
$uuid = date('YmdHis') . rand(10000000, 99999999);
|
|
|
- $suveys_array = json_decode($suvey_array);
|
|
|
+ $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
|
|
|
var_dump($suveys_array, '---------------------1');
|
|
|
var_dump($suvey_array, '---------------------2');
|
|
|
$suvey_data = [];
|
|
|
- foreach ($suveys_array as $key => $value) {
|
|
|
- if ($value == '') {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (is_array($value)) {
|
|
|
- $suvey_data[] = [
|
|
|
- 'sur_id' => $uuid,
|
|
|
- 'art_id' => $id,
|
|
|
- 'website_id' => $website_id ?? 2,
|
|
|
- 'survey_name' => $survey_name,
|
|
|
- 'choice_name' => $value[1],
|
|
|
- 'is_other' => 1,
|
|
|
- 'orther_id' => 0,
|
|
|
- 'results' => 0,
|
|
|
-
|
|
|
- ];
|
|
|
- } else {
|
|
|
- $suvey_data[] = [
|
|
|
- 'sur_id' => $uuid,
|
|
|
- 'art_id' => $id,
|
|
|
- 'website_id' => $website_id ?? 2,
|
|
|
- 'survey_name' => $survey_name,
|
|
|
- 'choice_name' => $value,
|
|
|
- 'is_other' => 0,
|
|
|
- 'orther_id' => 0,
|
|
|
- 'results' => 0,
|
|
|
+ if (is_array($suveys_array)) {
|
|
|
+ foreach ($suveys_array as $key => $value) {
|
|
|
+ if ($value == '') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (is_array($value)) {
|
|
|
+ $suvey_data[] = [
|
|
|
+ 'sur_id' => $uuid,
|
|
|
+ 'art_id' => $id,
|
|
|
+ 'website_id' => $website_id ?? 2,
|
|
|
+ 'survey_name' => $survey_name,
|
|
|
+ 'choice_name' => $value[1],
|
|
|
+ 'is_other' => 1,
|
|
|
+ 'other_id' => 0,
|
|
|
+ 'results' => 0,
|
|
|
+
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $suvey_data[] = [
|
|
|
+ 'sur_id' => $uuid,
|
|
|
+ 'art_id' => $id,
|
|
|
+ 'website_id' => $website_id ?? 2,
|
|
|
+ 'survey_name' => $survey_name,
|
|
|
+ 'choice_name' => $value,
|
|
|
+ 'is_other' => 0,
|
|
|
+ 'other_id' => 0,
|
|
|
+ 'results' => 0,
|
|
|
+
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if (empty($suvey_data)) {
|
|
|
+ throw new \Exception("投票数据为空");
|
|
|
+ }
|
|
|
|
|
|
- ];
|
|
|
- }
|
|
|
- if (empty($suvey_data)) {
|
|
|
- throw new \Exception("投票数据为空");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
$result = ArticleSurvey::insert($suvey_data);
|
|
|
if (!$result) {
|
|
@@ -422,13 +446,15 @@ class NewsService implements NewsServiceInterface
|
|
|
if (!$result) {
|
|
|
throw new \Exception("投票失败");
|
|
|
}
|
|
|
+ } else {
|
|
|
+ $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
|
|
|
}
|
|
|
Db::commit();
|
|
|
return Result::success([]);
|
|
|
} catch (\Throwable $ex) {
|
|
|
Db::rollBack();
|
|
|
var_dump($ex->getMessage());
|
|
|
- return Result::error("更新失败", 0);
|
|
|
+ return Result::error("更新失败1" . $ex->getMessage(), 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -454,12 +480,16 @@ class NewsService implements NewsServiceInterface
|
|
|
{
|
|
|
$where = [
|
|
|
'article.id' => $data['id'],
|
|
|
+ // 'article.status' => 1,
|
|
|
];
|
|
|
$result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
|
|
|
- $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
|
|
|
- $result['survey_array'] = $articleSurvey->toArray();
|
|
|
+ $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get()->all();
|
|
|
+ var_dump($articleSurvey, 'articleSurvey');
|
|
|
+ $info = $result;
|
|
|
+ var_dump($info, 'info');
|
|
|
+ // $info['survey_array'] = $articleSurvey == null ? [] : $info['survey_array'];
|
|
|
if ($result) {
|
|
|
- return Result::success($result->toArray());
|
|
|
+ return Result::success($info);
|
|
|
} else {
|
|
|
return Result::error("查询失败", 0);
|
|
|
}
|