|
@@ -72,6 +72,7 @@ use Hyperf\Context\ApplicationContext as ContextApplicationContext;
|
|
|
use Hyperf\Amqp\Producer;
|
|
|
|
|
|
use App\Amqp\Producer\MqProducer;
|
|
|
+use App\Model\Web;
|
|
|
|
|
|
#[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class NewsService implements NewsServiceInterface
|
|
@@ -1197,11 +1198,34 @@ class NewsService implements NewsServiceInterface
|
|
|
->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
|
|
|
->where('article.status', 1)
|
|
|
->where('website_category.website_id', $data['website_id'])
|
|
|
- ->select('article.id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
|
|
|
+ ->select('article.id', 'article.cat_arr_id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
|
|
|
->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
|
|
|
// ->orderBy('article.updated_at', 'desc')
|
|
|
->limit(5)
|
|
|
->get();
|
|
|
+ //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
|
|
|
+ foreach ($commendArticle as $k => $v) {
|
|
|
+ $cat_arr_id = json_decode($v->cat_arr_id, true);
|
|
|
+ if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
|
|
|
+ $cat_arr_id = array_unique($cat_arr_id);
|
|
|
+ // 从website_category取出alias_pinyin
|
|
|
+ $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
|
|
|
+ ->whereIn('category_id', $cat_arr_id)
|
|
|
+ ->pluck('alias_pinyin', 'category_id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ // 将cat_arr_id的json转成路径/隔开
|
|
|
+ $path_parts = [];
|
|
|
+ foreach ($cat_arr_id as $cat_id) {
|
|
|
+ if (isset($cat_arr[$cat_id])) {
|
|
|
+ $path_parts[] = $cat_arr[$cat_id];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $v->alias_pinyin = implode('/', $path_parts);
|
|
|
+ } else {
|
|
|
+ $v->alias_pinyin = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$result['category_id'] = $category['category_id'];
|