RatingLogic.php 2.4 KB
<?php
/**
 * @remark :
 * @name   :RatingLogic.php
 * @author :lyh
 * @method :post
 * @time   :2024/1/20 14:15
 */

namespace App\Http\Logic\Bside\Scoring;

use App\Http\Logic\Bside\BaseLogic;
use App\Models\Scoring\RatingQuestion;
use App\Models\Scoring\ScoringSystem;

class RatingLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->model = new RatingQuestion();
        $this->scoringModel = new ScoringSystem();
        $this->param = $this->requestAll;
    }

    /**
     * @remark :获取详情
     * @name   :getRatingRead
     * @author :lyh
     * @method :post
     * @time   :2024/1/20 14:27
     */
    public function getRatingRead(){
        $data = [
            'company'=>$this->project['company'],
            'mobile'=>$this->project['mobile'],
            'uptime'=>$this->project['uptime'],
            'domain'=>$this->user['domain'],
            'question'=>$this->model->list(['type'=>$this->param['type']]),
            'project_id'=>$this->user['project_id']
        ];
        return $this->success($data);
    }

    /**
     * @remark :提交统计
     * @name   :ratingSave
     * @author :lyh
     * @method :post
     * @time   :2024/1/20 14:46
     */
    public function ratingSave(){
        $param = [
            'data'=>json_encode($this->param['data']),
            'mobile'=>$this->param['mobile'],
            'project_id'=>$this->user['project_id'],
            'type'=>$this->param['type']
        ];
        $this->scoringModel->add($param);
        return $this->httpSore($this->param['data'],$this->project['post_id'],$this->param['type']);
    }

    /**
     * @remark :同步数据
     * @name   :httpSore
     * @author :lyh
     * @method :post
     * @time   :2024/1/24 15:04
     */
    public function httpSore($data,$postId,$fType){
        $fType = (int)($fType + 1);
        $token = md5('qqs'.$postId.$fType.date("Y-m-d"));
        //$ftype 2,3,4
        $str = '';
        foreach ($data as $k => $v){
            $str .= 'name_'.(int)($k+1).'='.($v['level'] ?? 5).'&';
        }
        $str = trim($str,'&');
        $url = "http://www.quanqiusou.cn/extend_api/api/service_score.php?postid=$postId&token=$token&ftype=$fType&$str";
        @file_put_contents(storage_path('logs/lyh_error.log'), var_export($url, true) . PHP_EOL, FILE_APPEND);
        return http_get($url,['charset=utf-8']);
    }
}