123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\listener;
- use app\admin\model\Cat;
- use app\admin\model\Platform;
- class PlatCat
- {
- /**
- * 事件监听处理
- *
- * @return mixed
- */
- public function handle($event)
- {
- if($event['info']=='cat'){
- $this->cat();
- }
- if($event['info']=='plat'){
- $this->plat();
- }
- }
- public function cat(){
- $info = Cat::where(['id'=>$event['data']['id']??[]])->field('id cat_id,fund_code,status,is_del,creater apply_name,createrid apply_id,addtime,updatetime')->select();
- if($info->isEmpty())return;
- $plat = Platform::where(['platform_type' => 1, 'is_del' => 0])->field('id')->select();
- if(!$plat->isEmpty()){
- $data = [];
- foreach ($info as $item){
- $temp= array_map(function($v)use($item){
- $item['platform_id'] = $v['id'];
- return $item;
- },$plat);
- $data = array_merge($data,$temp);
- }
- $this->save($data);
- }
- }
- /**
- * 批量保存
- * @param $data
- */
- protected function save($data){
- if(!empty($data)){
- $model = new \app\admin\model\CatPlat();
- try{
- $model->saveAll($data);
- }catch(\Exception $e){
- throw new \Exception($e->getMessage());
- }
- }
- }
- }
|