12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?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)
- {
- $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);
- }
- }
- 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());
- }
- }
- }
- }
|