Commit 77e062bc by Phạm Văn Đoan

tạo task để lấy bài hát

parent 7900e8b5
<?php
namespace App\Console\Commands\Zing;
use Illuminate\Console\Command;
class ZingCrawlerTrackCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'zing:get-track';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Lấy thông tin bài hát từ ZingMp3';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
}
}
......@@ -3,6 +3,7 @@
namespace App\Console;
use App\Console\Commands\CrontjobCommand;
use App\Console\Commands\Zing\ZingCrawlerTrackCommand;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
......@@ -15,6 +16,8 @@ class Kernel extends ConsoleKernel
*/
protected $commands = [
CrontjobCommand::class,
ZingCrawlerTrackCommand::class,
];
/**
......
<?php
namespace App\Helpers;
class Constants
{
const TABLE_ARTISTS = 'artists';
const TABLE_FAILED_JOBS = 'failed_jobs';
const TABLE_JOBS = 'jobs';
const TABLE_MIGRATIONS = 'migrations';
const TABLE_NOTIFICATIONS = 'notifications';
const TABLE_OAUTH_ACCESS_TOKENS = 'oauth_access_tokens';
const TABLE_OAUTH_AUTH_CODES = 'oauth_auth_codes';
const TABLE_OAUTH_CLIENTS = 'oauth_clients';
const TABLE_OAUTH_PERSONAL_ACCESS_CLIENTS = 'oauth_personal_access_clients';
const TABLE_OAUTH_REFRESH_TOKENS = 'oauth_refresh_tokens';
const TABLE_PASSWORD_RESETS = 'password_resets';
const TABLE_PERMISSION_USER = 'permission_user';
const TABLE_PERMISSIONS = 'permissions';
const TABLE_ROLE_USER = 'role_user';
const TABLE_ROLES = 'roles';
const TABLE_TRACK_ARTIST = 'track_artist';
const TABLE_TRACK_USER = 'track_user';
const TABLE_TRACKS = 'tracks';
const TABLE_USER_LOGS = 'user_logs';
const TABLE_USERS = 'users';
const USER_STATUS_INACTIVE = 0;
const USER_STATUS_ACTIVE = 1;
const USER_STATUS_LOCKED = 2;
const USER_STATUS_LEFT = 3;
const DB_NO_CONNECTION = 2002;
const SYSTEM_ERROR = -500;
const ACCESS_DENIED = 403;
const KILL_MYSELF = 'KILL_MYSELF';
const SYSTEM_MAINTENANCE = 503;
const CODE_SUCCESS = 0;
const CODE_ERROR = 1;
const CODE_EMPTY = 2;
const MESSAGE_SUCCESS = 'success';
const MESSAGE_ERROR = 'error';
const MESSAGE_EMPTY = 'empty';
const BIRTHDAY_STATUS_NEW = 0;
const BIRTHDAY_STATUS_PROCESSING = 1;
const BIRTHDAY_STATUS_SUCCESS = 2;
const BIRTHDAY_STATUS_FAILED = 3;
const BIRTHDAY_STATUS_SUCCESS_AGAIN = 4;
const BIRTHDAY_STATUS_CANCEL = 5;
const BIRTHDAY_CHANNEL_CODE_SMS = 'SMS';
const BIRTHDAY_CHANNEL_CODE_EMAIL = 'EMAIL';
const BIRTHDAY_CHANNEL_CODE_EMAIL_SMS = 'EMAIL_SMS';
const CHANNEL_CODE_DEFAULT = 'EMAIL';
const EMAIL_CONTENT_DEFAULT = 'Hi! Thay mặt Công Đoàn Công ty DCV, tôi xin gửi lời chúc sinh nhật vui vẻ, thành công và hạnh phúc tới đồng chí. Chúc đồng chí luôn hoàn thành tốt nhiệm vụ!';
const SMS_CONTENT_DEFAULT = '(DCV - CONG DOAN) Thay mat Cong Doan Cong ty DCV, chuc Ban sinh nhat VUI VE.';
/* Cấu hình khoảng giá trị sinh mã bảo mật */
const VERIFICATION_CODE_MIN = 100000;
const VERIFICATION_CODE_MAX = 999999;
/* Cấu hình thời gian bắt đầu gửi chúc mừng sinh nhật */
const BIRTHDAY_START_SEND_HOUR = '09';
const BIRTHDAY_START_SEND_MINUTE = '00';
const BIRTHDAY_START_SEND_SECOND = '00';
const BIRTHDAY_EMAIL_TEMPLATE_FILENAME = 'mail_birthday.html';
const BIRTHDAY_EMAIL_TEMPLATE_FROM_PUBLIC = 'storage/templates/mail/';
const BIRTHDAY_EMAIL_TEMPLATE_FROM_STORAGE = 'app/public/templates/mail/';
/* Backend view path */
const BE_VIEW_PATH_DASHBOARD = 'pages.backend.dashboard.index';
/* Tên Tab ứng dụng extension PMS */
const BROWSER_TYPE_NOTIFICATION = 'NOTIFICATION';
const BROWSER_TYPE_PROJECT = 'PROJECT';
const BROWSER_TYPE_TASK = 'TASK';
const BROWSER_TYPE_COWORKER = 'COWORKER';
/* Tên Tab ứng dụng extension SmartJob */
const SMARTJOB_TYPE_JOBS = 'JOBS';
const SMARTJOB_TYPE_COMPANIES = 'COMPANIES';
const SMARTJOB_TYPE_BLOG = 'BLOG';
/* Tên Tab ứng dụng extension AHoaDon */
const AHOADON_TYPE_SEARCH = 'SEARCH';
const AHOADON_TYPE_PACKAGE = 'PACKAGE';
const AHOADON_TYPE_TEMPLATE = 'TEMPLATE';
const AHOADON_PRICE_INIT = 500000;
const AHOADON_VAT = 10;
const STORAGE_OPENWEATHERMAP_ICON = 'storage/weather/openweathermap';
const STORAGE_COURSE_ICON = 'storage/courses';
const STORAGE_IMG_TRACKS_DB = 'storage/tracks/images/';
const STORAGE_IMG_TRACKS = 'storage/app/public/tracks/images/';
const STORAGE_IMG_EMPTY_PNG = 'storage/app/public/empty-1x1-png.png';
const STORAGE_IMG_EMPTY_JPG = 'storage/app/public/empty-1x1-jpg.jpg';
const STORAGE_IMG_EMPTY_GIF = 'storage/app/public/empty-1x1-gif.gif';
const STORAGE_FILE_TRACKS_DB = 'storage/tracks/files/';
const STORAGE_FILE_TRACKS = 'storage/app/public/tracks/files/';
const STORAGE_COVER_ARTISTS_DB = 'storage/artists/covers/';
const STORAGE_COVER_ARTISTS = 'storage/app/public/artists/covers/';
const STORAGE_THUMBNAIL_ARTISTS_DB = 'storage/artists/thumbnails/';
const STORAGE_THUMBNAIL_ARTISTS = 'storage/app/public/artists/thumbnails/';
}
\ No newline at end of file
<?php
use App\Helpers\Constants;
use Illuminate\Support\Facades\Auth;
if (!function_exists('includeRouteFiles')) {
/**
* Loops through a folder and requires all PHP files
* Searches sub-directories as well.
*
* @param $folder
*/
function includeRouteFiles($folder)
{
try {
$rdi = new recursiveDirectoryIterator($folder);
$it = new recursiveIteratorIterator($rdi);
while ($it->valid()) {
if (!$it->isDot() && $it->isFile() && $it->isReadable() && $it->current()->getExtension() === 'php') {
require $it->key();
}
$it->next();
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
}
if (!function_exists('processCommonResponse')) {
/**
* @param $result
* @param null $data
* @return \Illuminate\Http\JsonResponse
*/
function processCommonResponse($result, $data = null)
{
return response()->json(array(
'code' => $result ? Constants::CODE_SUCCESS : Constants::CODE_ERROR,
'message' => $result ? Constants::MESSAGE_SUCCESS : Constants::MESSAGE_ERROR,
'data' => $data
));
}
}
if (!function_exists('generateFilenameUpload')) {
/**
* Get filename from file when upload
* @param $file
* @return string
*/
function generateFilenameUpload($file)
{
if (is_object($file) && is_file($file)) {
return 'user_' . Auth::id().'_upload_'.time().'.'.$file->getClientOriginalExtension();
}
return 'user_' . Auth::id().'_upload_'.time();
}
}
if (!function_exists('isAdmin')) {
/**
* check is admin
* @return true,false
*/
function isAdmin() {
$query = \App\User::where('id',Auth::Id());
$query->with([
'roles' => function($roleSql){
$roleSql->select( 'roles.id','roles.name');
}
]);
$result = $query->get()->first();
$role = array();
if(!empty($result) && count($result->roles) > 0){
foreach($result->roles as $val){
$role[] = $val->name;
}
}
if(in_array('administrator', $role) && Auth::check()){
return true;
}
return false;
}
}
/**
* The function check item and return value
*/
if (!function_exists('getArrayItem')) {
/**
* Get filename from file when upload
* @param $array
* @param $key
* @return string
*/
function getArrayItem($array, $key)
{
if(is_array($array) && isset($array[$key])) {
return $array[$key];
} else {
return null;
}
}
}
if (!function_exists('translateKeyWord')) {
/**
* Translate special key work
* @param $keyWord
* @return mixed
*/
function translateKeyWord($keyWord)
{
if (empty($keyWord)) {
return $keyWord;
} else {
return str_replace(['%'], ['\%'], $keyWord);
}
}
}
if (!function_exists('get_browser_name')) {
/**
* Get browser name from user agent
*
* @param $user_agent
* @return string
*/
function get_browser_name($user_agent)
{
if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
elseif (strpos($user_agent, 'Edge')) return 'edge';
elseif (strpos($user_agent, 'Chrome')) return 'chrome';
elseif (strpos($user_agent, 'Safari')) return 'safari';
elseif (strpos($user_agent, 'Firefox')) return 'firefox';
elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'ie';
return 'Other';
}
}
if (!function_exists('convertFileEncodingToUTF8')) {
/**
* Convert file (csv) encoding to uft-8
*
* @param $filePath
* @return mixed
*/
function convertFileEncodingToUTF8($filePath)
{
try{
if(\File::exists($filePath)){
$inputContent = file_get_contents($filePath);
$inputEncoding = mb_detect_encoding($inputContent, \App\Constants::SPECIFY_ENCODING_LIS);
if (strtoupper($inputEncoding) == 'JIS') {
$inputEncoding = 'SJIS';
}
if (! empty($inputEncoding)) {
if (strtoupper($inputEncoding) != \App\Constants::OUT_CHARSET) {
file_put_contents($filePath, iconv($inputEncoding, \App\Constants::OUT_CHARSET, $inputContent));
}
return true;
} else {
return false;
}
} else {
return false;
}
} catch (Exception $e){
error_log('import encoding: '.$e->getMessage());
return false;
}
}
}
if (!function_exists('checkArrayNull')) {
/**
* Check array null (all item null)
*
* @param array $array
* @return bool
*/
function checkArrayNull(array $array)
{
if (is_array($array) && count($array) > 0) {
$arrayNull = array_filter($array, 'is_null');
if (count($array) === count($arrayNull)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}
if (!function_exists('isJson')) {
/**
* Check JSON format is valid
*
* @param $string
* @return bool
*/
function isJson($string)
{
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
}
}
if (!function_exists('getCustomFieldForExport')) {
/**
* Get custom field for export csv
*
* @param $customFieldDataAll
* @param $receiverCustomField
* @return array
*/
function getCustomFieldForExport($customFieldDataAll, $receiverCustomField, $isSimpleArray=true)
{
if (is_array($customFieldDataAll) && count($customFieldDataAll) > 0) {
if (! empty($receiverCustomField)) {
$customFields = explode('||', $receiverCustomField);
} else {
return [];
}
if (count($customFields) > 1) {
unset($customFields[count($customFields)-1]);
}
$data = [];
foreach ($customFieldDataAll as $customValue) {
$init = null;
foreach ($customFields as $value) {
preg_match("/^\[(.*):=\](.*)$/", $value, $temp);
if (count($temp) == 3) {
unset($temp[0]);
}
if ($customValue['id'] == $temp[1]) {
$init = trim($temp[2]);
}
}
if (empty($init)) {
if ($isSimpleArray) {
$data[][$customValue['id']] = null;
} else {
$data[] = null;
}
} else {
if ($isSimpleArray) {
$data[][$customValue['id']] = $init;
} else {
$data[] = $init;
}
}
}
return $data;
}
return [];
}
}
if (!function_exists('getRoleList')) {
/**
* Get custom field for export csv
* Default call: getRoleList()
*
* @param $userId
* @param $isCurrentUser
* @param $isArray
*
* @return array
*/
function getRoleList($userId=null, $isCurrentUser=true, $isArray=false)
{
if ($isCurrentUser) {
$userId = \auth()->id();
}
$user = \App\Models\User::find($userId);
if ($user) {
$arr = collect($user->roles)->map(function ($item) {
return $item->name;
})->all();
return ($isArray) ? $arr : implode(",", $arr);
} else {
return ($isArray) ? [] : '';
}
}
}
if (!function_exists('getUserListInPartner')) {
/**
* Get custom field for export csv
* Default call: getUserListInPartner()
*
* @param $userId
* @param $isCurrentUser
* @param $isObject
*
* @return array
*/
function getUserListInPartner($userId=null, $isCurrentUser=true, $isObject=false)
{
if ($isCurrentUser) {
$userId = \auth()->id();
}
$user = \App\Models\User::find($userId);
if ($user) {
$users = User::select('id', 'partner_id', 'name', 'email')
->where('partner_id', $user->partner_id)
->get();
if ($isObject) {
return $users;
} else {
return collect($users)->map(function ($item) {
return $item->id;
})->all();
}
} else {
return [];
}
}
}
if (!function_exists('getBirthdayEmailTemplateFromFile')) {
/**
* Hàm lấy template từ file html gửi mail chúc mừng sinh nhật
*
*/
function getBirthdayEmailTemplateFromFile()
{
try {
$path_file = public_path(Constants::BIRTHDAY_EMAIL_TEMPLATE_FROM_PUBLIC . Constants::BIRTHDAY_EMAIL_TEMPLATE_FILENAME);
if (\File::exists($path_file)) {
$email_template_path = storage_path(Constants::BIRTHDAY_EMAIL_TEMPLATE_FROM_STORAGE . Constants::BIRTHDAY_EMAIL_TEMPLATE_FILENAME);
$email_template_file = fopen($email_template_path, 'r');
$email_template_data = fread($email_template_file, filesize($email_template_path));
fclose($email_template_file);
return $email_template_data;
}
return null;
} catch (Exception $e) {
return null;
}
}
}
if (!function_exists('sendRequest')) {
function sendRequest($url, $params = array(), $method = 'POST', $isJSON = true, $isAuthen = false, $timeOut = 60)
{
$request = \Ixudra\Curl\Facades\Curl::to($url)
->withOption('TIMEOUT', $timeOut)
->withOption('CONNECTTIMEOUT', 0)
->withOption('SSL_VERIFYPEER', 0)
->withContentType('application/json')
->withOption('FOLLOWLOCATION', true)
->returnResponseObject();
if ($isJSON) {
$request->withData(json_encode($params));
} else {
$request->withData($params);
}
if ($isAuthen) {
$request->withOption('USERPWD', 'admin:weppoHER4352GGErfg');
}
$response = '';
switch ($method) {
case 'GET':
$response = $request->get();
break;
case 'POST':
$response = $request->post();
break;
case 'PUT':
$response = $request->put();
break;
case 'PATCH':
$response = $request->patch();
break;
case 'DELETE':
$response = $request->delete();
break;
default:
break;
}
return $response->content;
}
}
if (!function_exists('dataResponse')) {
function dataResponse($code, $message, $data) {
return [
'code' => $code,
'message' => $message,
'data' => $data
];
}
}
if (!function_exists('checkTaxCode')) {
function checkTaxCode($taxcode) {
$vn_taxcode = '/^[0-9]{10}$|^[0-9]{10}-[0-9]{2}[1-9]{1}$/';
if (preg_match($vn_taxcode, $taxcode)) {
$prefix_input = substr($taxcode, 0, 3);
$array_prefix = config('validator.tax_code_by_province');
if (count($array_prefix) > 0 && in_array($prefix_input, $array_prefix)) {
$tax_code = substr($taxcode, 0, 10);
if (strlen($tax_code) == 10) {
$total = 31*$tax_code[0];
$total += 29*$tax_code[1];
$total += 23*$tax_code[2];
$total += 19*$tax_code[3];
$total += 17*$tax_code[4];
$total += 13*$tax_code[5];
$total += 7*$tax_code[6];
$total += 5*$tax_code[7];
$total += 3*$tax_code[8];
if ($tax_code[9] == (10 - ($total % 11))) {
return true;
}
return false;
}
return false;
}
return false;
}
}
}
if (!function_exists('getDom')) {
function getDom($link)
{
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
$dom = \Sunra\PhpSimple\HtmlDomParser::str_get_html($content);
return $dom;
}
}
if (!function_exists('getNotificationStatus')) {
function getNotificationStatus($name, $status) {
$badge = $name . ' ';
switch ($status) {
case 0:
$badge .= '<span class="badge badge-secondary" style="float: right">Chưa đọc</span>';
break;
case 1:
$badge .= '<span class="badge badge-primary" style="float: right">Đã đọc</span>';
break;
case 2:
$badge .= '<span class="badge badge-danger" style="float: right">Đã xóa</span>';
break;
default:
}
return $badge;
}
}
if (!function_exists('getProjectStatus')) {
function getProjectStatus($name, $status) {
$badge = $name . ' ';
switch ($status) {
case 0:
$badge .= '<span class="badge badge-secondary" style="float: right">Bản nháp</span>';
break;
case 1:
$badge .= '<span class="badge badge-info" style="float: right">Chờ duyệt</span>';
break;
case 2:
$badge .= '<span class="badge badge-primary" style="float: right">Đã duyệt</span>';
break;
case 3:
$badge .= '<span class="badge badge-warning" style="float: right">Đang thực hiện</span>';
break;
case 4:
$badge .= '<span class="badge badge-success" style="float: right">Hoàn thành</span>';
break;
case 5:
$badge .= '<span class="badge badge-danger" style="float: right">Tạm dừng</span>';
break;
default:
}
return $badge;
}
}
if (!function_exists('getTaskStatus')) {
function getTaskStatus($name, $status) {
$badge = $name . ' ';
switch ($status) {
case 0:
$badge .= '<span class="badge badge-secondary" style="float: right">Bản nháp</span>';
break;
case 1:
$badge .= '<span class="badge badge-info" style="float: right">Đã duyệt</span>';
break;
case 2:
$badge .= '<span class="badge badge-primary" style="float: right">Đã giao</span>';
break;
case 3:
$badge .= '<span class="badge badge-warning" style="float: right">Đang thực hiện</span>';
break;
case 4:
$badge .= '<span class="badge badge-success" style="float: right">Hoàn thành</span>';
break;
case 5:
$badge .= '<span class="badge badge-danger" style="float: right">Tạm dừng</span>';
break;
case 6:
$badge .= '<span class="badge badge-dark" style="float: right">Chuyển tiếp</span>';
break;
default:
}
return $badge;
}
}
if (!function_exists('getUserStatus')) {
function getUserStatus($name, $status) {
$badge = $name . ' ';
switch ($status) {
case 0:
$badge .= '<span class="badge badge-secondary" style="float: right">Chưa kích hoạt</span>';
break;
case 1:
$badge .= '<span class="badge badge-info" style="float: right">Đã kích hoạt</span>';
break;
case 2:
$badge .= '<span class="badge badge-warning" style="float: right">Tạm khóa</span>';
break;
case 3:
$badge .= '<span class="badge badge-danger" style="float: right">Đã nghỉ làm</span>';
break;
default:
}
return $badge;
}
}
if (!function_exists('validateMobile')) {
function validateMobile($mobile) {
if ($mobile == "" || $mobile == null) return false;
$start_pattern = "/";
$end_pattern = "/";
$viettel_pattern = $start_pattern;
$viettel_pattern .= "^8498\d{7}$|^0?98\d{7}$|^98\d{7}$";
$viettel_pattern .= "|^8497\d{7}$|^0?97\d{7}$|^97\d{7}$";
$viettel_pattern .= "|^8496\d{7}$|^0?96\d{7}$|^96\d{7}$";
$viettel_pattern .= "|^8432\d{7}$|^0?32\d{7}$|^32\d{7}$";
$viettel_pattern .= "|^8433\d{7}$|^0?33\d{7}$|^33\d{7}$";
$viettel_pattern .= "|^8434\d{7}$|^0?34\d{7}$|^34\d{7}$";
$viettel_pattern .= "|^8435\d{7}$|^0?35\d{7}$|^35\d{7}$";
$viettel_pattern .= "|^8436\d{7}$|^0?36\d{7}$|^36\d{7}$";
$viettel_pattern .= "|^8437\d{7}$|^0?37\d{7}$|^37\d{7}$";
$viettel_pattern .= "|^8438\d{7}$|^0?38\d{7}$|^38\d{7}$";
$viettel_pattern .= "|^8439\d{7}$|^0?39\d{7}$|^39\d{7}$";
$viettel_pattern .= "|^8486\d{7}$|^0?86\d{7}$|^86\d{7}$";
$vinaphone_pattern = $viettel_pattern;
$vinaphone_pattern .= "|^8491\d{7}$|^0?91\d{7}$|^91\d{7}$";
$vinaphone_pattern .= "|^8494\d{7}$|^0?94\d{7}$|^94\d{7}$";
$vinaphone_pattern .= "|^8481\d{7}$|^0?81\d{7}$|^81\d{7}$";
$vinaphone_pattern .= "|^8482\d{7}$|^0?82\d{7}$|^82\d{7}$";
$vinaphone_pattern .= "|^8483\d{7}$|^0?83\d{7}$|^83\d{7}$";
$vinaphone_pattern .= "|^8484\d{7}$|^0?84\d{7}$|^84\d{7}$";
$vinaphone_pattern .= "|^8485\d{7}$|^0?85\d{7}$|^85\d{7}$";
$vinaphone_pattern .= "|^8488\d{7}$|^0?88\d{7}$|^88\d{7}$";
$mobifone_pattern = $vinaphone_pattern;
$mobifone_pattern .= "|^8490\d{7}$|^0?90\d{7}$|^90\d{7}$";
$mobifone_pattern .= "|^8493\d{7}$|^0?93\d{7}$|^93\d{7}$";
$mobifone_pattern .= "|^8470\d{7}$|^0?70\d{7}$|^70\d{7}$";
$mobifone_pattern .= "|^8476\d{7}$|^0?76\d{7}$|^76\d{7}$";
$mobifone_pattern .= "|^8477\d{7}$|^0?77\d{7}$|^77\d{7}$";
$mobifone_pattern .= "|^8478\d{7}$|^0?78\d{7}$|^78\d{7}$";
$mobifone_pattern .= "|^8479\d{7}$|^0?79\d{7}$|^79\d{7}$";
$mobifone_pattern .= "|^8489\d{7}$|^0?89\d{7}$|^89\d{7}$";
$vietnamobile_pattern = $mobifone_pattern;
$vietnamobile_pattern .= "|^8492\d{7}$|^0?92\d{7}$|^92\d{7}$";
$vietnamobile_pattern .= "|^8456\d{7}$|^0?56\d{7}$|^56\d{7}$";
$vietnamobile_pattern .= "|^8458\d{7}$|^0?58\d{7}$|^58\d{7}$";
$vietnamobile_pattern .= $end_pattern;
// $landline_pattern = /^84203\d{8}$|^0?203\d{8}$|^203\d{8}$|^84204\d{8}$|^0?204\d{8}$|^204\d{8}$|^84205\d{8}$|^0?205\d{8}$|^205\d{8}$|^84206\d{8}$|^0?206\d{8}$|^206\d{8}$|^84207\d{8}$|^0?207\d{8}$|^207\d{8}$|^84208\d{8}$|^0?208\d{8}$|^208\d{8}$|^84209\d{8}$|^0?209\d{8}$|^209\d{8}$|^84210\d{8}$|^0?210\d{8}$|^210\d{8}$|^84211\d{8}$|^0?211\d{8}$|^211\d{8}$|^84212\d{8}$|^0?212\d{8}$|^212\d{8}$|^84213\d{8}$|^0?213\d{8}$|^213\d{8}$|^84214\d{8}$|^0?214\d{8}$|^214\d{8}$|^84215\d{8}$|^0?215\d{8}$|^215\d{8}$|^84216\d{8}$|^0?216\d{8}$|^216\d{8}$|^84218\d{8}$|^0?218\d{8}$|^218\d{8}$|^84219\d{8}$|^0?219\d{8}$|^219\d{8}$|^84220\d{8}$|^0?220\d{8}$|^220\d{8}$|^84221\d{8}$|^0?221\d{8}$|^221\d{8}$|^84222\d{8}$|^0?222\d{8}$|^222\d{8}$|^84225\d{8}$|^0?225\d{8}$|^225\d{8}$|^84226\d{8}$|^0?226\d{8}$|^226\d{8}$|^84227\d{8}$|^0?227\d{8}$|^227\d{8}$|^84228\d{8}$|^0?228\d{8}$|^228\d{8}$|^84229\d{8}$|^0?229\d{8}$|^229\d{8}$|^84232\d{8}$|^0?232\d{8}$|^232\d{8}$|^84233\d{8}$|^0?233\d{8}$|^233\d{8}$|^84234\d{8}$|^0?234\d{8}$|^234\d{8}$|^84235\d{8}$|^0?235\d{8}$|^235\d{8}$|^84236\d{8}$|^0?236\d{8}$|^236\d{8}$|^84237\d{8}$|^0?237\d{8}$|^237\d{8}$|^84238\d{8}$|^0?238\d{8}$|^238\d{8}$|^84239\d{8}$|^0?239\d{8}$|^239\d{8}$|^8424\d{8}$|^0?24\d{8}$|^24\d{8}$|^84251\d{8}$|^0?251\d{8}$|^251\d{8}$|^84252\d{8}$|^0?252\d{8}$|^252\d{8}$|^84254\d{8}$|^0?254\d{8}$|^254\d{8}$|^84255\d{8}$|^0?255\d{8}$|^255\d{8}$|^84256\d{8}$|^0?256\d{8}$|^256\d{8}$|^84257\d{8}$|^0?257\d{8}$|^257\d{8}$|^84258\d{8}$|^0?258\d{8}$|^258\d{8}$|^84259\d{8}$|^0?259\d{8}$|^259\d{8}$|^84260\d{8}$|^0?260\d{8}$|^260\d{8}$|^84261\d{8}$|^0?261\d{8}$|^261\d{8}$|^84262\d{8}$|^0?262\d{8}$|^262\d{8}$|^84263\d{8}$|^0?263\d{8}$|^263\d{8}$|^84269\d{8}$|^0?269\d{8}$|^269\d{8}$|^84270\d{8}$|^0?270\d{8}$|^270\d{8}$|^84271\d{8}$|^0?271\d{8}$|^271\d{8}$|^84272\d{8}$|^0?272\d{8}$|^272\d{8}$|^84273\d{8}$|^0?273\d{8}$|^273\d{8}$|^84274\d{8}$|^0?274\d{8}$|^274\d{8}$|^84275\d{8}$|^0?275\d{8}$|^275\d{8}$|^84276\d{8}$|^0?276\d{8}$|^276\d{8}$|^84277\d{8}$|^0?277\d{8}$|^277\d{8}$|^8428\d{8}$|^0?28\d{8}$|^28\d{8}$|^84290\d{8}$|^0?290\d{8}$|^290\d{8}$|^84291\d{8}$|^0?291\d{8}$|^291\d{8}$|^84292\d{8}$|^0?292\d{8}$|^292\d{8}$|^84293\d{8}$|^0?293\d{8}$|^293\d{8}$|^84294\d{8}$|^0?294\d{8}$|^294\d{8}$|^84296\d{8}$|^0?296\d{8}$|^296\d{8}$|^84297\d{8}$|^0?297\d{8}$|^297\d{8}$|^84299\d{8}$|^0?299\d{8}$|^299\d{8}$/;
if (preg_match($vietnamobile_pattern, $mobile)) {
return true;
} else{
return false;
}
}
}
if (!function_exists('formatMobile')) {
function formatMobile($mobile) {
$res_format = '';
if (validateMobile($mobile)) {
switch (strlen($mobile)) {
case 9:
$res_format = '84' . $mobile;
break;
case 10:
$res_format = '84' . substr($mobile, 1);
break;
case 11:
$res_format = $mobile;
default:
}
}
return $res_format;
}
}
if (!function_exists('curlZingMp3')) {
function curlZingMp3($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Authority: mp3.zing.vn';
$headers[] = 'Cache-Control: max-age=0';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3';
$headers[] = 'Accept-Encoding: gzip, deflate, br';
$headers[] = 'Accept-Language: vi-VN,vi;q=0.9,en-US;q=0.8,en;q=0.7,ja;q=0.6';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
return false;
}
curl_close ($ch);
return $result;
}
}
if (!function_exists('curlZingArtist')) {
function curlZingArtist($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Authority: zingmp3.vn';
$headers[] = 'Cache-Control: max-age=0';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3';
$headers[] = 'Accept-Encoding: gzip, deflate, br';
$headers[] = 'Accept-Language: vi-VN,vi;q=0.9,en-US;q=0.8,en;q=0.7,ja;q=0.6';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
return false;
}
curl_close ($ch);
return $result;
}
}
if (!function_exists('getUrlArtistByPage')) {
function getUrlArtistByPage($start=1, $count=100) {
$url = 'https://zingmp3.vn/api/artist/get-list?';
$url .= 'id=IWZ9Z08I';
$url .= '&type=genre';
$url .= '&sort=listen';
$url .= '&start=' . $start;
$url .= '&count=' . $count;
$url .= '&ctime=1584216597';
$url .= '&sig=e2b8e1e48ccd12f560959913a6901fc76c9b93e1cafecba2d3517d8ab57eeb44717aa41eca70338bcf8bc8c84def1c43367ef44c887589db4ed81a1e2c042303';
$url .= '&api_key=38e8643fb0dc04e8d65b99994d3dafff';
return $url;
}
}
if (!function_exists('read_money')) {
/**
* Hàm đọc số tiền trên hóa đơn thành chuỗi
* doanpv - 14/06/2019
*
* @param $money
* @param string $currency_type
*
* @return string
*/
function read_money($money, $currency_type='1')
{
switch (strtoupper($currency_type)) {
case '1': // VND
$unit_name = 'đồng';
$sub_unit_name = 'xu';
$money = round($money, 0);
break;
case '2': // USD
$unit_name = 'Đô la Mỹ';
$sub_unit_name = 'cent';
$money = round($money, 2);
break;
case '3': // EUR
$unit_name = 'Ơ Rô';
$sub_unit_name = 'cent';
$money = round($money, 2);
break;
default:
$unit_name = 'đồng';
$sub_unit_name = 'xu';
$money = round($money, 0);
}
if ($money == 0) {
return 'Không ' . $unit_name . '.';
} elseif ($money < 0) {
return './.';
}
$number = [
1 => 'một',
2 => 'hai',
3 => 'ba',
4 => 'bốn',
5 => 'năm',
6 => 'sáu',
7 => 'bảy',
8 => 'tám',
9 => 'chín',
];
if ($money <= 2147483647) {
$odd = intval(($money - intval($money))*100);
$even = intval(trim($money));
$even = str_repeat(' ', 15 - strlen($even)) . $even;
$thousands_of_billions = intval(substr($even, 0, 3));
$billions = intval(substr($even, 3, 3));
$millions = intval(substr($even, 6, 3));
$thousands = intval(substr($even, 9, 3));
$units = intval(substr($even, 12, 3));
} else {
$odd = floatval(($money - floatval($money))*100);
$even = floatval(trim($money));
$even = str_repeat(' ', 15 - strlen($even)) . $even;
$thousands_of_billions = floatval(substr($even, 0, 3));
$billions = floatval(substr($even, 3, 3));
$millions = floatval(substr($even, 6, 3));
$thousands = floatval(substr($even, 9, 3));
$units = floatval(substr($even, 12, 3));
}
if ($thousands_of_billions == 0 && $billions == 0 && $millions == 0 && $thousands == 0 && $units == 0) {
$result = 'Không ' . $unit_name . ' ';
$i = 5;
} else {
$result = '';
$i = 0;
}
while ($i <= 5) {
switch ($i) {
case 0:
$temp = $thousands_of_billions;
$name = 'nghìn tỷ'; break;
case 1:
$temp = $billions;
$name = 'tỷ'; break;
case 2:
$temp = $millions;
$name = 'triệu'; break;
case 3:
$temp = $thousands;
$name = 'nghìn'; break;
case 4:
$temp = $units;
$name = $unit_name; break;
case 5:
$temp = $odd;
$name = $sub_unit_name; break;
}
if ($temp != 0) {
$hundred = intval($temp/100);
$ten = intval(($temp - $hundred*100)/10);
$unit = intval(($temp - $hundred * 100) - $ten*10);
if (substr($result, strlen($result) - 3) == ' ') {
$result = substr($result, strlen($result) - 3);
}
$result .= ((strlen($result) == 0) ? '' : ', ') . (($hundred != 0) ? $number[$hundred] . ' trăm ' : '');
if ($ten == 0 && $hundred != 0 && $unit != 0) {
$result .= 'lẻ ';
} else {
if($ten != 0) {
$result .= (($ten != 0 && $ten != 1) ? $number[$ten] . ' mươi ' : 'mười ');
}
}
if ($ten != 0 && $unit == 5) {
$result .= 'lăm ' . $name . ' ';
} else {
if ($ten > 1 && $unit == 1) {
$result .= 'mốt ' . $name . ' ';
} else {
$result .= (($unit != 0) ? $number[$unit] . ' ' . $name : $name) . ' ';
}
}
} else {
$result .= (($i == 4) ? $unit_name . '': '');
}
$i = $i + 1;
}
if ($odd == 0 && $currency_type == '1') {
$result .= ((substr($result, strlen($result) - 3) == ' ') ? '' : ' ') . 'chẵn';
}
return ucfirst(str_replace(' ,', ',', $result)) . './.';
}
}
<?php
namespace App\Models;
use App\Helpers\Constants;
use Illuminate\Database\Eloquent\Model;
class Artist extends Model
{
protected $table = Constants::TABLE_ARTISTS;
/**
* Hàm lấy ds bài hát của 1 ca sĩ
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function tracks()
{
return $this->belongsToMany(
'App\Models\Track',
Constants::TABLE_TRACKS,
'artist_id',
'track_id'
);
}
}
<?php
namespace App\Models;
use App\Helpers\Constants;
use Illuminate\Database\Eloquent\Model;
class Track extends Model
{
protected $table = Constants::TABLE_TRACKS;
/**
* Hàm lấy ds nghệ sĩ biểu diễn 1 bài hát
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function artists()
{
return $this->belongsToMany(
'App\Models\Artist',
Constants::TABLE_ARTISTS,
'track_id',
'artist_id'
);
}
}
<?php
namespace App\Models;
use App\Helpers\Constants;
use Illuminate\Database\Eloquent\Model;
class TrackArtist extends Model
{
protected $table = Constants::TABLE_TRACK_ARTIST;
}
<?php
namespace App\Repositories;
use App\Models\Artist;
class ArtistRepository extends BaseRepository
{
public function __construct()
{
}
/**
* Lấy mảng ID do bên nguồn quản lý đã insert trong tracks
* @param string $src
* @return null
*/
public function getArtistSrcIdInserted($src='all')
{
$query = Artist::select(['id', 'source', 'id_zing', 'id_nct', 'id_keeng']);
if ($src != 'all') {
$query->where('source', $src);
switch ($src) {
case 'zing': return $query->pluck('id_zing')->toArray(); break;
case 'nct': return $query->pluck('id_nct')->toArray(); break;
case 'keeng': return $query->pluck('id_keeng')->toArray(); break;
}
return null;
}
return $query->get();
}
public function getArtistThumbnailEmpty()
{
$query = Artist::select(['id', 'thumbnail', 'source', 'id_zing', 'id_nct', 'id_keeng', 'src_thumbnail'])->whereNull('thumbnail');
return $query->get()->toArray();
}
public function getArtistCoverEmpty()
{
$query = Artist::select(['id', 'cover', 'source', 'id_zing', 'id_nct', 'id_keeng', 'src_cover'])->whereNull('cover');
return $query->get()->toArray();
}
}
\ No newline at end of file
<?php
namespace App\Repositories;
class BaseRepository
{
public function __construct()
{
}
}
\ No newline at end of file
<?php
namespace App\Repositories;
use App\Models\Crontjob;
class CrontjobRepository
{
protected $crontjob;
public function __construct(Crontjob $crontjob)
{
$this->crontjob = $crontjob;
}
public function listing()
{
}
public function store($params)
{
$crontjob = new Crontjob();
$crontjob->fill($params);
if ($crontjob->save()) {
return true;
} else {
return false;
}
}
}
\ No newline at end of file
<?php
namespace App\Repositories;
use App\Models\Track;
class TrackRepository extends BaseRepository
{
public function __construct()
{
}
/**
* Lấy mảng ID do bên nguồn quản lý đã insert trong tracks
* @param string $src
* @return null
*/
public function getTrackSrcIdInserted($src='all')
{
$query = Track::select(['id', 'source', 'id_zing', 'id_nct', 'id_keeng']);
if ($src != 'all') {
$query->where('source', $src);
switch ($src) {
case 'zing': return $query->pluck('id_zing')->toArray(); break;
case 'nct': return $query->pluck('id_nct')->toArray(); break;
case 'keeng': return $query->pluck('id_keeng')->toArray(); break;
}
return null;
}
return $query->get();
}
public function getTrackImageEmpty()
{
$query = Track::select(['id', 'image', 'source', 'id_zing', 'id_nct', 'id_keeng', 'thumbnail_medium'])->whereNull('image');
return $query->get()->toArray();
}
}
\ No newline at end of file
<?php
namespace App\Repositories;
use App\User;
class UserRepository extends BaseRepository
{
public function __construct()
{
}
public function getAllUser() {
return User::all();
}
}
\ No newline at end of file
......@@ -20,7 +20,10 @@
],
"psr-4": {
"App\\": "app/"
}
},
"files": [
"app/Helpers/Functions.php"
]
},
"autoload-dev": {
"psr-4": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment