| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 | <?php
namespace App\Http\Services\Web;
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(
        $trackNo, $firstName, $lastName, $companyName, $companyEmail, $backupEmail, $phoneNumber, $country, 
        $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)
    {
        $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;
    }
}
 |