InquiryInfoLogic.php 8.2 KB
<?php

namespace App\Http\Logic\Aside\Optimize;

use App\Http\Logic\Aside\BaseLogic;
use App\Models\Inquiry\InquiryCount;
use App\Models\Inquiry\InquiryInfo;
use App\Models\Inquiry\InquiryIP;
use App\Models\Inquiry\InquiryType;
use App\Models\Project\Keywords;
use App\Models\Project\Project;
use Illuminate\Support\Facades\DB;

/**
 * @remark :询盘中心
 * @class  :InquiryInfoLogic.php
 * @author :lyh
 * @time   :2023/7/11 15:20
 */
class InquiryInfoLogic extends BaseLogic
{

    public function __construct()
    {
        parent::__construct();
        $this->param = $this->requestAll;
        $this->model = new InquiryInfo();
    }

    /**
     * @remark :获取列表
     * @name   :getInquiryLists
     * @author :lyh
     * @method :post
     * @time   :2023/7/11 15:25
     */
    public function getInquiryLists($map,$page,$row,$order = 'id',$filed = ['*']){
        $lists = $this->model->lists($map,$page,$row,$order,$filed);
        return $this->success($lists);
    }


    /**
     * @remark :自定义添加特殊询盘信息
     * @name   :inquirySave
     * @author :lyh
     * @method :post
     * @time   :2023/7/12 9:22
     */
    public function inquirySave(){
        if($this->param['delay'] != $this->model::STATUS_ZERO){
            $this->param['status'] = $this->model::STATUS_FOUR;//延时转发
            $this->param['send_time'] = date('Y-m-d H:i:s',time() + $this->param['delay'] * 60 * 60);//实际转发时间
        }
        $this->param['created_at'] = date('Y-m-d H:i:s');
        $this->param['updated_at'] = $this->param['created_at'];
        $xp_id = $this->model->insertGetId($this->param);
        if(!$xp_id){
            $this->fail('error');
        }
        //延时时间为0时,询盘转发
        if($this->param['delay'] == $this->model::STATUS_ZERO){
            $this->forwardTime($xp_id);
        }
        return $this->success();
    }


    /**
     * @remark :删除
     * @name   :inquiryInfoDel
     * @author :lyh
     * @method :post
     * @time   :2023/7/12 14:15
     */
    public function inquiryInfoDel(){
        DB::beginTransaction();
        try {
            $this->model->del(['id'=>$this->param['id']]);
            DB::commit();
        }catch (\Exception $e){
            DB::rollBack();
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @remark :转发详情
     * @name   :inquiryForwardInfo
     * @author :lyh
     * @method :post
     * @time   :2023/7/12 17:43
     */
    public function inquiryForwardInfo(){
        $info = $this->model->read(['id'=>$this->param['id']]);
        if($info === false){
            $this->fail('error');
        }
        return $this->success($info);
    }

    /**
     * @remark :导入保存数据
     * @name   :ImportInquiryInfoSave
     * @author :lyh
     * @method :post
     * @time   :2023/7/13 10:59
     */
    public function ImportInquiryInfoSave($row){
        $this->param = [
            'name'=>$row[0],
            'email'=>$row[1],
            'phone'=>$row[2],
            'ip'=>$row[3],
            'ip_area'=>$row[4],
            'message'=>$row[5],
            'type'=>$row[6],
            'forward_url'=>$row[7],
            'delay'=>$row[8],
        ];
        $this->inquirySave();
        return $this->success();
    }

    /**
     * @remark :根据国家获取随机ip
     * @name   :getSearchIp
     * @author :lyh
     * @method :post
     * @time   :2023/7/13 11:43
     */
    public function getSearchIp(){
        $inquiryIpModel = new InquiryIP();
        $info = $inquiryIpModel->where($this->param)->inRandomOrder()->first();
        return $this->success($info);
    }

    /**
     * @remark :根据时间转发
     * @name   :forwardTime
     * @author :lyh
     * @method :post
     * @time   :2023/7/13 17:39
     */
    public function forwardTime($xp_id){
        //获取数据详情
        $param = $this->model->read(['id'=>$xp_id]);
        $data = $param;
        $arr_url = explode(',',$param['forward_url']);
        foreach ($arr_url as $v){
            $data['url'] = $v;
            $this->inquiryForward($data);
        }
        //更新数据库,修改状态为已转发
        $this->param['status'] = 3;
        $this->param['user_id'] = $this->manager['id'];
        $this->param['user_name'] = $this->manager['name'];
        $this->param['send_time'] = date('Y-m-d H:i:s');
        $rs = $this->model->edit($this->param,['id'=>$xp_id]);
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @remark :询盘转发
     * @name   :inquiryForward
     * @author :lyh
     * @method :post
     * @time   :2023/7/13 14:39
     */
    public function inquiryForward($post_data){
        $url = 'https://form.globalso.com/api/external-interface/add/fa043f9cbec6b38f';
        $post_data_new = [];
        $post_data_new['refer'] = $post_data['url'];
        $post_data_new['name'] = $post_data['name'];
        $post_data_new['email'] = $post_data['email'];
        $post_data_new['phone'] = $post_data['phone'];
        $post_data_new['ip'] = $post_data['ip'];
        $post_data_new['message'] = $post_data['message'];
        $post_data_new['submit_time'] = date('Y-m-d H:i:s',time()+20);
        $token = md5($post_data_new['refer'].$post_data_new['name'].$post_data_new['ip'].date("Y-m-d",time()));
        $post_data_new['token'] = $token;
        $header = array(
            'CLIENT-IP: '.$post_data['ip'],
            'X-FORWARDED-FOR: '.$post_data['ip']
        );
        return http_post($url,$post_data_new,$header);
    }

    /**
     * @remark :更新询盘状态
     * @name   :inquiryEdit
     * @author :lyh
     * @method :post
     * @time   :2023/7/14 15:19
     */
    public function inquiryEdit(){
        $info = $this->model->read(['id'=>$this->param['id']]);
        if($info !== 0){
            $this->fail('当前状态下不允许修改状态');
        }
        $this->param['user_id'] = $this->manager['id'];
        $this->param['user_name'] = $this->manager['name'];
        $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @remark :获取30天统计
     * @name   :getNewThirtyCount
     * @author :lyh
     * @method :post
     * @time   :2023/7/14 16:00
     */
    public function getNewCount(){
        $inquiryCountModel = new InquiryCount();
        $lists = $inquiryCountModel->lists(['type'=>$this->param['type']],1,90);
        $data = $lists['list'];
        return $this->success($data);
    }

    /**
     * @remark :根据关键字获取域名
     * @name   :getKeywordUrl
     * @author :lyh
     * @method :post
     * @time   :2023/7/17 9:09
     */
    public function getKeywordUrl($map){
        $projectModel = new Project();
        $lists = $projectModel->leftJoin('gl_project_deploy_optimize', 'gl_project_deploy_optimize.project_id', '=', 'gl_project.id')
            ->leftJoin('gl_project_keyword', 'gl_project_keyword.project_id', '=', 'gl_project.id')
            ->where('gl_project_keyword.main_keyword','like','%'.$map['keyword'].'%')
            ->orWhere('gl_project_keyword.customer_keywords','like','%'.$map['keyword'].'%')
            ->select($this->selectParam())->get();
        if(!empty($lists)){
            $lists = $lists->toArray();
        }
        return $this->success($lists);
    }

    public function selectParam(){
        $select = [
            'gl_project.title AS title',
            'gl_project_deploy_optimize.domain AS domain',
        ];
        return $select;
    }
    /**
     * @remark :获取类型
     * @name   :getType
     * @author :lyh
     * @method :post
     * @time   :2023/8/1 9:16
     */
    public function getType(){
        $typeModel = new InquiryType();
        $list = $typeModel->list(['status'=>0]);
        return $this->success($list);
    }

    /**
     * @remark :获取内部统计
     * @name   :getManagerCount
     * @author :lyh
     * @method :post
     * @time   :2023/8/18 9:32
     */
    public function getManagerCount(){
        $list = $this->model->groupBy('user_name')->select("user_name",DB::raw('COUNT(*) as count'))->get()->toArray();
        return $this->success($list);
    }
}