Acquisition.php 3.8 KB
<?php
/**
 * Created by PhpStorm.
 * User: ty01
 * Date: 2022/3/10
 * Time: 14:31
 */

namespace app\api\controller\v1;

use think\Db;

/**
 * 文章管理
 * Class Acquisition
 * @package app\api\controller\core
 */
class Acquisition extends Base
{

    /**
     * 文章采集入库
     */
    public function article()
    {
        $response = $this->request->param();

        $title = $response['title'];//文章标题
        $articlecontent = $response['content'];
        $url = $response['url'];
        $from = $response['source'];
        $cjtime = $response['tacq'];
        $fwtime = $response['DispatchTime'];
        $Sensitive = $response['Sensitive'];
        $group_id = $response['group_id'];
        $fakeid = $response['fakeid'];//公众号id

        $ss = [];
        $ids_string = "";
        if (!empty($Sensitive)) {
            foreach ($Sensitive as $kk=>$vv){
                if (!empty($vv)) {
                    $ids = Db::name("theme_keywords")->where("name", $vv)->column("id");
                    if (!empty($ids)) {
                        $ss = array_unique(array_merge($ss, $ids));
                    }
                }
            }
            if (!empty($ss)) {
                $ids_string = implode(",", $ss);
            }
            $Sensitive = implode(",", $Sensitive);
        }

        if (empty($title)) {
            $this->error("文章标题不能为空");
        }

        if (empty($articlecontent)) {
            $this->error("文章内容不能为空");
        }

        if (empty($from) || !in_array($from, ['微信', '网站', '论坛', '全部网页', '网络问政', '头条号', '广播电视', '搜狐号', '微博', '视频'])) {
            $this->error("文章来源渠道参数异常");
        }

        $admin_id = Db::name("auth_group_access")->where("group_id", $group_id)->value("uid");//获取角色组下第一层的某个管理id

        $data = [
            "title" => $title,
            "articlecontent" => $articlecontent,
            "url" => $url,
            "from" => $from,
            "cjtime" => $cjtime,
            "fwtime" => $fwtime,
            "createtime" => time(),
            "sensitive" => $Sensitive,
            "theme_keywords_ids"=>$ids_string,
            "admin_id" => $admin_id ? $admin_id : 1,
            "fakeid"=>$fakeid,
        ];

        $ac_id = Db::name("article_acquisition")->insertGetId($data);
        if ($ac_id) {
            $this->success("数据入库成功", $ac_id);
        } else {
            $this->error("数据入库失败");
        }

    }

    /**
     * 处理敏感词老数据(多个id用逗号隔开)
     */
    public function test()
    {
        $article = Db::name("article_acquisition")->order("id asc")->select();
        if (!empty($article)) {
            foreach ($article as $k => $v) {

                if (!empty($v['sensitive'])) {
                    $sensitive_array = explode(",", $v['sensitive']);
                    $ss = [];
                    foreach ($sensitive_array as $kk => $vv) {
                        if (!empty($vv)) {
                            $ids = Db::name("theme_keywords")->where("name", $vv)->column("id");
                            if (!empty($ids)) {
                                $ss = array_unique(array_merge($ss, $ids));
                            }
                        }
                    }
                    if (!empty($ss)) {
                        $ids_string = "";
                        $ids_string = implode(",", $ss);
                        Db::name("article_acquisition")->where("id", $v['id'])->update(["theme_keywords_ids" => $ids_string]);
                    }

                }

            }
        }

    }
}