| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 | <?php
namespace App\Http\Services\Api;
use App\Models\SignupData;
use App\Models\TrackData;
use DB;
use GuzzleHttp\Client;
class SeminarSignUpService
{
    protected $signupDb;
    protected $trackDataDb;
    
    public function __construct()
    {
        $this->signupDb = new SignupData();
        $this->trackDataDb = new TrackData();
        
    }
    
    public function insertData(
        $firstName, $lastName, $companyName, $companyEmail, $backupEmail, $phoneNumber, $country, $trackNo, 
        $registeredSession, $lunchOptions, $typeOfIndustry, $typeOfJob, $jobTitle, $trackOfInterest, $areaOfInterest, $howToKnowAboutTheEvent, 
        $consentAcceptEmail, $consentPrivacyPolicy)
    {
        
        $this->signupDb
            ->insert([
                'firstName'     => $firstName,
                'lastName'      => $lastName,
                'companyName'   => $companyName,
                'companyEmail'  => $companyEmail,
                'backupEmail'   => $backupEmail,
                'phoneNumber'   => $phoneNumber,
                'country'       => $country,
                'trackNo'       => $trackNo,
                'registeredSession' => $registeredSession,
                'lunchOptions'      => $lunchOptions,
                'typeOfIndustry'    => $typeOfIndustry,
                'typeOfJob'     => $typeOfJob,
                'jobTitle'      => $jobTitle,
                'trackOfInterest'   => $trackOfInterest,
                'areaOfInterest'    => $areaOfInterest,
                'howToKnowAboutTheEvent'    => $howToKnowAboutTheEvent,
                'consentAcceptEmail'    => $consentAcceptEmail,
                'consentPrivacyPolicy'    => $consentPrivacyPolicy,
                'createDate'    => date("Y-m-d H:i:s"),
            ]);
        
    }
    
    public function overLimitOrNot($trackNo)
    {
        \Log::info($trackNo);
        $nowCount = $this->signupDb
            ->where('trackNo', '=', $trackNo)
            ->count();
        
        $limit = $this->trackDataDb
            ->select('trackLimit')
            ->where('trackNo', '=', $trackNo)
            ->first();
        
        if ($limit->trackLimit>$nowCount) {
            return true;
        } else {
            return false;
        }
    }
    
    public function getData()
    {
        $res = $this->trackDataDb
        ->select([
            '*'
        ])
        ->get();
        // 整理返回值並返回
        return $res;
    }
}
 |