Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Письменов Дмитрий Иванович
/
yourroomads
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f607ecac
authored
May 18, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19461 Страница настройки целевых аккаунтов
1 parent
b335553d
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
13 deletions
app/Http/Controllers/CampaignVarsController.php
app/Http/Controllers/TokensController.php
app/Models/Campaigns.php
app/Models/Tokens.php
database/migrations/2021_05_17_141740_create_dictionary_campaigns_table.php
app/Http/Controllers/CampaignVarsController.php
View file @
f607eca
...
@@ -24,7 +24,7 @@ class CampaignVarsController extends Controller
...
@@ -24,7 +24,7 @@ class CampaignVarsController extends Controller
return
Redirect
::
back
();
return
Redirect
::
back
();
}
}
$campaign
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
get
()
->
first
()
->
campaigns
()
->
with
(
'vars'
)
->
find
(
$campaign_id
);
$campaign
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
get
()
->
first
()
->
campaigns
ForEnabled
()
->
with
(
'vars'
)
->
find
(
$campaign_id
);
if
(
!
$campaign
)
{
if
(
!
$campaign
)
{
return
Redirect
::
back
();
return
Redirect
::
back
();
...
...
app/Http/Controllers/TokensController.php
View file @
f607eca
...
@@ -8,6 +8,8 @@ use App\Models\Pivots\DictionaryCampaign;
...
@@ -8,6 +8,8 @@ use App\Models\Pivots\DictionaryCampaign;
use
App\Models\Tokens
;
use
App\Models\Tokens
;
use
App\Service\API\API
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Relations\HasMany
;
use
Illuminate\Support\Facades\Auth
;
use
Illuminate\Support\Facades\Auth
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Redirect
;
use
Illuminate\Support\Facades\Redirect
;
...
@@ -155,7 +157,7 @@ class TokensController extends Controller
...
@@ -155,7 +157,7 @@ class TokensController extends Controller
return
Redirect
::
back
();
return
Redirect
::
back
();
}
}
$token_main
=
Tokens
::
with
(
'campaigns'
)
->
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
$token_main
=
Tokens
::
with
(
'campaigns
ForEnabled
'
)
->
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token_main
)
{
if
(
!
$token_main
)
{
return
Redirect
::
back
();
return
Redirect
::
back
();
...
@@ -166,17 +168,14 @@ class TokensController extends Controller
...
@@ -166,17 +168,14 @@ class TokensController extends Controller
$token
->
cities
()
->
save
(
$city
);
$token
->
cities
()
->
save
(
$city
);
if
(
$token_main
->
campaigns
->
count
())
{
if
(
$token_main
->
campaigns
ForEnabled
->
count
())
{
$city
->
campaigns
()
->
syncWithoutDetaching
(
$city
->
campaigns
()
->
syncWithoutDetaching
(
$token_main
->
campaigns
->
keyBy
(
$token_main
->
campaigns
->
first
()
->
getKeyName
())
->
transform
(
function
(
Campaigns
$campaign
)
{
$token_main
->
campaigns
ForEnabled
->
keyBy
(
$token_main
->
campaignsForEnabled
->
first
()
->
getKeyName
())
->
transform
(
function
(
Campaigns
$campaign
)
{
return
DictionaryCampaign
::
copyPropertyInCampaign
(
$campaign
);
return
DictionaryCampaign
::
copyPropertyInCampaign
(
$campaign
);
})
->
all
()
})
->
all
()
);
);
}
}
$token_main
->
campaigns
->
each
(
function
(
Campaigns
$campaign
)
use
(
$city
)
{
});
DB
::
commit
();
DB
::
commit
();
return
Redirect
::
route
(
'token.edit'
,
$token
->
getKey
())
->
with
(
'success'
,
'City added.'
);
return
Redirect
::
route
(
'token.edit'
,
$token
->
getKey
())
->
with
(
'success'
,
'City added.'
);
...
...
app/Models/Campaigns.php
View file @
f607eca
...
@@ -42,13 +42,20 @@ class Campaigns extends Model
...
@@ -42,13 +42,20 @@ class Campaigns extends Model
{
{
parent
::
boot
();
parent
::
boot
();
static
::
created
(
function
(
Campaigns
$campaign_new
)
static
::
updated
(
function
(
Campaigns
$campaign
)
{
{
Dictionary
::
whereNotNull
(
'token_id'
)
->
each
(
function
(
Dictionary
$dictionary
)
use
(
$campaign_new
)
{
if
(
$campaign
->
enabled
!==
$campaign
->
getOriginal
(
'enabled'
))
{
$campaign_new
->
dictionaries
()
->
syncWithoutDetaching
([
if
(
$campaign
->
enabled
)
{
$dictionary
->
getKey
()
=>
DictionaryCampaign
::
copyPropertyInCampaign
(
$campaign_new
),
Dictionary
::
whereNotNull
(
'token_id'
)
->
each
(
function
(
Dictionary
$dictionary
)
use
(
$campaign
)
{
$campaign
->
dictionaries
()
->
syncWithoutDetaching
([
$dictionary
->
getKey
()
=>
DictionaryCampaign
::
copyPropertyInCampaign
(
$campaign
),
]);
]);
});
});
}
else
{
$campaign
->
dictionaries
()
->
detach
();
//$campaign->vars()->delete();
}
}
});
});
/*
/*
...
@@ -98,4 +105,14 @@ class Campaigns extends Model
...
@@ -98,4 +105,14 @@ class Campaigns extends Model
{
{
$query
->
where
(
'manage'
,
false
);
$query
->
where
(
'manage'
,
false
);
}
}
public
function
scopeForEnabled
(
$query
)
{
$query
->
where
(
'enabled'
,
true
);
}
public
function
scopeNotForEnabled
(
$query
)
{
$query
->
where
(
'enabled'
,
false
);
}
}
}
app/Models/Tokens.php
View file @
f607eca
...
@@ -39,6 +39,11 @@ class Tokens extends Model
...
@@ -39,6 +39,11 @@ class Tokens extends Model
->
orderBy
(
'updated_at'
,
'DESC'
);
->
orderBy
(
'updated_at'
,
'DESC'
);
}
}
public
function
campaignsForEnabled
()
{
return
$this
->
campaigns
()
->
forEnabled
();
}
public
function
cities
()
public
function
cities
()
{
{
return
$this
->
hasMany
(
Dictionary
::
class
,
'token_id'
,
'id'
)
return
$this
->
hasMany
(
Dictionary
::
class
,
'token_id'
,
'id'
)
...
...
database/migrations/2021_05_17_141740_create_dictionary_campaigns_table.php
View file @
f607eca
...
@@ -24,8 +24,10 @@ class CreateDictionaryCampaignsTable extends Migration
...
@@ -24,8 +24,10 @@ class CreateDictionaryCampaignsTable extends Migration
$table
->
timestamps
();
$table
->
timestamps
();
$table
->
foreign
(
'campaign_id'
)
->
references
(
'id'
)
->
on
(
'campaigns'
);
$table
->
foreign
(
'campaign_id'
)
->
references
(
'id'
)
->
on
(
'campaigns'
)
$table
->
foreign
(
'dictionary_id'
)
->
references
(
'id'
)
->
on
(
'dictionaries'
);
->
onDelete
(
"cascade"
);
$table
->
foreign
(
'dictionary_id'
)
->
references
(
'id'
)
->
on
(
'dictionaries'
)
->
onDelete
(
"cascade"
);
});
});
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment