12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Services;
- use App\Imports\WXPopulationInfoImport;
- use App\Models\WXPopulation;
- use App\Support\EmailQueue;
- use App\Support\Log;
- use Maatwebsite\Excel\Facades\Excel;
- class WXPopulationService
- {
- /**
- * 导入万象人群包到系统
- * */
- public static function importPopulationInfo($file)
- {
- if (!$file->isValid()) return 1010;
- $fileExt = $file->getClientOriginalExtension();
- if ($fileExt != 'xlsx') return 1011;
- try {
- // 导入数据
- $import = new WXPopulationInfoImport();
- Excel::import($import, $file);
- } catch (\Throwable $e) {
- EmailQueue::rPush('万象人群包导入失败', $e->getMessage(), ['xiaohua.hou@kuxuan-inc.com'], '聚星');
- Log::error('万象人群包导入失败', [
- 'msg' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ], 'ImportPopulationInfo');
- return 1015;
- }
- return 0;
- }
- /**
- * 万象人群包列表
- * */
- public static function populationLists($advertiserId, $orientationId, $orientationName, $page, $pageSize)
- {
- list($list, $total) = WXPopulation::getPopulationList($advertiserId, $orientationId, $orientationName, $page, $pageSize);
- return [$list, $total];
- }
- /**
- * 万象人群包启用/禁用
- * */
- public static function changeStatus($populationIds, $enable)
- {
- $populationIds = explode(',', $populationIds);
- $rst = WXPopulation::whereIn('id', $populationIds)->update(['enable'=> $enable]);
- return $rst ? 0 : 1016;
- }
- }
|