PlatCat.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\listener;
  4. use app\admin\model\Cat;
  5. use app\admin\model\Platform;
  6. class PlatCat
  7. {
  8. /**
  9. * 事件监听处理
  10. *
  11. * @return mixed
  12. */
  13. public function handle($event)
  14. {
  15. $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();
  16. if($info->isEmpty())return;
  17. $plat = Platform::where(['platform_type' => 1, 'is_del' => 0])->field("id")->select();
  18. if(!$plat->isEmpty()){
  19. $data = [];
  20. foreach ($info as $item){
  21. $temp= array_map(function($v)use($item){
  22. $item['platform_id'] = $v['id'];
  23. return $item;
  24. },$plat);
  25. $data = array_merge($data,$temp);
  26. }
  27. $this->save($data);
  28. }
  29. }
  30. protected function save($data){
  31. if(!empty($data)){
  32. $model = new \app\admin\model\CatPlat();
  33. try{
  34. $model->saveAll($data);
  35. }catch(\Exception $e){
  36. throw new \Exception($e->getMessage());
  37. }
  38. }
  39. }
  40. }