AiccWeChatController.php 2.1 KB
<?php

namespace App\Http\Controllers\Bside\Aicc;

use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Aside\Aicc\AiccWeChatLogic;
use Illuminate\Http\Request;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class AiccWeChatController extends BaseController
{
    private $aiccWeChatLogic;

    public function __construct(Request $request)
    {
        $this->aiccWeChatLogic = new AiccWeChatLogic();
        parent::__construct($request);
    }

    /**
     * V6与AICC数据关联
     * @return void
     * @throws BsideGlobalException
     */
    public function save()
    {
        $project_id = (int)request()->post('project_id', 0);
        if (empty($project_id)) {
            $this->fail('请选择项目!', Code::USER_PARAMS_ERROE);
        }
        $status     = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
        $wx_user_id = (int)request()->post('user_id', 0);
        if (empty($wx_user_id) && $status) {
            $this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE);
        }
        $wx_id = (int)request()->post('wx_id', 0);
        if (empty($wx_id) && $status) {
            $this->fail('请选择要绑定的AICC项目!', Code::USER_PARAMS_ERROE);
        }
        $wx_nickname  = request()->post('nickname', '');
        $wx_user_name = request()->post('user_name', '');
        $wx_image     = request()->post('image', '');
        $data         = compact('project_id', 'wx_id', 'wx_nickname', 'wx_user_id', 'wx_user_name', 'wx_image');
        $this->aiccWeChatLogic->saveData($data);
        $this->response('success');
    }

    /**
     * 数据推送到AICC
     * @return void
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function dataPush()
    {
        $page    = (int)request()->get('page', 1);
        $perPage = (int)request()->get('perPage', 15); # 分页页数
        $data    = $this->aiccWeChatLogic->AiccWeChatLists($page, $perPage);
        $this->response('success', Code::SUCCESS, $data);
    }
}