PlatCat.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. if($event['info']=='cat'){
  16. $this->cat();
  17. }
  18. if($event['info']=='plat'){
  19. $this->plat();
  20. }
  21. }
  22. public function cat(){
  23. $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();
  24. if($info->isEmpty())return;
  25. $plat = Platform::where(['platform_type' => 1, 'is_del' => 0])->field('id')->select();
  26. if(!$plat->isEmpty()){
  27. $data = [];
  28. foreach ($info as $item){
  29. $temp= array_map(function($v)use($item){
  30. $item['platform_id'] = $v['id'];
  31. return $item;
  32. },$plat);
  33. $data = array_merge($data,$temp);
  34. }
  35. $this->save($data);
  36. }
  37. }
  38. /**
  39. * 批量保存
  40. * @param $data
  41. */
  42. protected function save($data){
  43. if(!empty($data)){
  44. $model = new \app\admin\model\CatPlat();
  45. try{
  46. $model->saveAll($data);
  47. }catch(\Exception $e){
  48. throw new \Exception($e->getMessage());
  49. }
  50. }
  51. }
  52. }