GeoConfirmLogic.php 2.6 KB
<?php
/**
 * @remark :
 * @name   :GeoConfirmLogic.php
 * @author :lyh
 * @method :post
 * @time   :2025/10/25 11:36
 */

namespace App\Http\Logic\Aside\Geo;

use App\Enums\Common\Code;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Geo\GeoConfirm;
use App\Models\ProjectAssociation\ProjectAssociation;

/**
 * @remark :用户确认信息
 * @name   :GeoConfirmLogic
 * @author :lyh
 * @method :post
 * @time   :2025/10/25 11:37
 */
class GeoConfirmLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->param = $this->requestAll;
        $this->model = new GeoConfirm();
    }

    /**
     * @remark :保存数据->并推送微信群客户确认
     * @name   :saveConfirmContent
     * @author :lyh
     * @method :post
     * @time   :2025/10/25 11:41
     */
    public function saveConfirmContent($param)
    {
        try {
            $info = $this->model->read(['project_id' => $param['project_id'],'type' => $param['type']]);
            if($info === false){
                $id = $this->model->addReturnId($param);
            }else{
                $id = $info['id'];
                $this->model->edit($param,['id'=>$info['id']]);
            }
            $friend = ProjectAssociation::where(['project_id' => $param['project_id']])->first();
            if (empty($friend)){
                $this->fail('项目未绑定微信群, 推送消息失败!');
            }
            GeoConfirm::sendConfirmMessage($id, $friend->friend_id);
        } catch (\Exception $e) {
            $this->fail('操作失败, error:' . $e->getMessage());
        }
        return $this->success(['id'=>$id]);
    }

    /**
     * @remark :获取数据详情
     * @name   :getInfo
     * @author :lyh
     * @method :post
     * @time   :2025/10/30 09:13
     */
    public function getConfirmInfo()
    {
        $data = $this->model->read($this->param);
        if($data === false){
            return $this->success();
        }
        return $this->success($data);
    }

    /**
     * @remark :保存确认信息
     * @name   :saveConfirmInfo
     * @author :lyh
     * @method :post
     * @time   :2025/10/30 11:41
     */
    public function saveConfirmInfo()
    {
        $this->param['status'] = GeoConfirm::STATUS_FINISH;
        $info = $this->model->read(['project_id' => $this->param['project_id'],'type'=>$this->param['type']]);
        if($info === false){
            $id = $this->model->addReturnId($this->param);
        }else{
            $id  = $info['id'];
            $this->model->edit($this->param,['id'=>$info['id']]);
        }
        return $this->success(['id'=>$id]);
    }
}