Keine Beschreibung

WXPopulationService.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Services;
  3. use App\Imports\WXPopulationInfoImport;
  4. use App\Models\WXPopulation;
  5. use App\Support\EmailQueue;
  6. use App\Support\Log;
  7. use Maatwebsite\Excel\Facades\Excel;
  8. class WXPopulationService
  9. {
  10. /**
  11. * 导入万象人群包到系统
  12. * */
  13. public static function importPopulationInfo($file)
  14. {
  15. if (!$file->isValid()) return 1010;
  16. $fileExt = $file->getClientOriginalExtension();
  17. if ($fileExt != 'xlsx') return 1011;
  18. try {
  19. // 导入数据
  20. $import = new WXPopulationInfoImport();
  21. Excel::import($import, $file);
  22. } catch (\Throwable $e) {
  23. EmailQueue::rPush('万象人群包导入失败', $e->getMessage(), ['xiaohua.hou@kuxuan-inc.com'], '聚星');
  24. Log::error('万象人群包导入失败', [
  25. 'msg' => $e->getMessage(),
  26. 'trace' => $e->getTraceAsString()
  27. ], 'ImportPopulationInfo');
  28. return 1015;
  29. }
  30. return 0;
  31. }
  32. /**
  33. * 万象人群包列表
  34. * */
  35. public static function populationLists($advertiserId, $orientationId, $orientationName, $page, $pageSize)
  36. {
  37. list($list, $total) = WXPopulation::getPopulationList($advertiserId, $orientationId, $orientationName, $page, $pageSize);
  38. return [$list, $total];
  39. }
  40. /**
  41. * 万象人群包启用/禁用
  42. * */
  43. public static function changeStatus($populationIds, $enable)
  44. {
  45. $populationIds = explode(',', $populationIds);
  46. $rst = WXPopulation::whereIn('id', $populationIds)->update(['enable'=> $enable]);
  47. return $rst ? 0 : 1016;
  48. }
  49. }