Commit bf56583b by 庄欣

样片,套系编辑时对精选的影响

parent 8883939f
<?php
/**
* Created by PhpStorm.
* User: zhuangxin
* Date: 16-9-20
* Time: 下午2:09
*/
namespace App\Choice\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class Choice extends Model
{
protected $table = "myp_choice";
const SETS = "sets";
const WORKS = "works";
const TYPE = [
self::SETS => '套系',
self::WORKS => '样片'
];
public static function isChoiceItem($id,$type = self::SETS)
{
$sql = "SELECT a.id,b.id as sid FROM %s a JOIN %s b ON b.choice_id = a.id WHERE a.type = '%s' AND b.src_id=%d";
$sql = sprintf($sql,"myp_choice","myp_choice_set",$type,$id);
return count(DB::select($sql)) > 0;
}
public static function UpdateStatus($id,$type = self::SETS,$status = 0)
{
$sql = "UPDATE %s a,%s b SET b.is_del = %d WHERE a.type = '%s' AND b.src_id=%d";
$sql = sprintf($sql,"myp_choice","myp_choice_set",$status,$type,$id);
return DB::update($sql);
}
}
\ No newline at end of file
......@@ -15,11 +15,13 @@ class EventServiceProvider extends ServiceProvider
*/
protected $listen = [
\App\Works\Events\WorksEditedEvent::class => [
\App\Works\Listeners\WorksSearcherListener::class
\App\Works\Listeners\WorksSearcherListener::class,
\App\Works\Listeners\PropChoice::class
],
\App\Sets\Events\SetsEditedEvent::class => [
\App\Sets\Listeners\SetsSearcherListener::class,
\App\Sets\Listeners\SetsEditedListener::class
\App\Sets\Listeners\SetsEditedListener::class,
\App\Sets\Listeners\PropChoice::class
],
\App\Article\Events\ArtAddEvent::class => [
\App\Article\Listeners\ArtListener::class
......
<?php
namespace App\Sets\Listeners;
use App\Choice\Model\Choice as ChoiceModel;
class PropChoice
{
public function handle($event)
{
/** @var \App\Sets\Model\Sets $model */
$model = $event->model;
if(!ChoiceModel::isChoiceItem($model->id,ChoiceModel::SETS)) {
return;
}
if ($model->exists === false || $model->is_del == 1 || $model->is_shelf == 1) {
ChoiceModel::UpdateStatus($model->id,ChoiceModel::SETS,1);
} else {
ChoiceModel::UpdateStatus($model->id,ChoiceModel::SETS,0);
}
}
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ namespace App\Test\Controller;
use App\Article\Model\Art;
use App\Choice\Model\Choice;
use App\Ident\Model\Ident;
use App\Ident\Validation\IdentValidator;
use App\Libraries\Upyun\UpyunClient;
......@@ -36,7 +37,7 @@ class TestController extends Controller
public function index()
{
$k = User::getUserInfo(14,["nickname"])->nickname;
var_dump($k);
$res = Choice::UpdateStatus(13,Choice::SETS,0);
var_dump($res);
}
}
\ No newline at end of file
<?php
namespace App\Works\Listeners;
use App\Choice\Model\Choice as ChoiceModel;
class PropChoice
{
public function handle($event)
{
/** @var \App\Works\Model\Works $model */
$model = $event->model;
if(!ChoiceModel::isChoiceItem($model->id,ChoiceModel::WORKS)) {
return;
}
if ($model->exists === false || $model->is_del == 1 || $model->is_hidden == 1) {
ChoiceModel::UpdateStatus($model->id,ChoiceModel::WORKS,1);
} else {
ChoiceModel::UpdateStatus($model->id,ChoiceModel::WORKS,0);
}
}
}
\ No newline at end of file
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