|
@@ -8,9 +8,14 @@ use app\common\library\MobileConstant;
|
|
|
use app\common\service\MobileImport;
|
|
|
use app\common\service\MobilePriceLogService;
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
|
|
+use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Csv;
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
|
|
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
+use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
|
+use PhpOffice\PhpSpreadsheet\Style\Border;
|
|
|
+use PhpOffice\PhpSpreadsheet\Style\Fill;
|
|
|
use think\App;
|
|
|
use think\Db;
|
|
|
use think\Exception;
|
|
@@ -465,4 +470,137 @@ class Mobile extends Backend
|
|
|
public function status(){
|
|
|
return \app\common\model\Mobile::$status;
|
|
|
}
|
|
|
+
|
|
|
+ public function add()
|
|
|
+ {
|
|
|
+ if($this->request->isPost()) {
|
|
|
+ $data = input('row/a');
|
|
|
+ if (!empty($data['city'])) {
|
|
|
+ $data['city'] = explode('/', $data['city'])[1];
|
|
|
+ }
|
|
|
+ Db::startTrans();
|
|
|
+ $this->validate($data, \app\admin\validate\Mobile::class);
|
|
|
+ $data['type'] = 1;
|
|
|
+ $info = [];
|
|
|
+ if (isset($data['describe'])) {
|
|
|
+ $info['describe'] = $data['describe'];
|
|
|
+ unset($data['describe']);
|
|
|
+ }
|
|
|
+ $mobile = $this->model::create($data);
|
|
|
+ $mobile->info()->save($info);
|
|
|
+ Db::commit();
|
|
|
+ $this->success();
|
|
|
+ }else{
|
|
|
+ return view();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function export($ids){
|
|
|
+ $mobiles=$this->model->whereIn('id',$ids)->select();
|
|
|
+ $excel = new Spreadsheet();
|
|
|
+ $excel->getProperties()
|
|
|
+ ->setCreator("admin")
|
|
|
+ ->setLastModifiedBy("admin")
|
|
|
+ ->setTitle("导出号码")
|
|
|
+ ->setSubject("导出号码");
|
|
|
+ $excel->getDefaultStyle()->getFont()->setName('Microsoft Yahei');
|
|
|
+ $excel->getDefaultStyle()->getFont()->setSize(12);
|
|
|
+ $excel->getDefaultStyle()->applyFromArray(
|
|
|
+ array(
|
|
|
+ 'fill' => array(
|
|
|
+ 'type' => Fill::FILL_SOLID,
|
|
|
+ 'color' => array('rgb' => '000000')
|
|
|
+ ),
|
|
|
+ 'font' => array(
|
|
|
+ 'color' => array('rgb' => "000000"),
|
|
|
+ ),
|
|
|
+ 'alignment' => array(
|
|
|
+ 'vertical' => Alignment::VERTICAL_CENTER,
|
|
|
+ 'horizontal' => Alignment::HORIZONTAL_CENTER,
|
|
|
+ 'indent' => 1
|
|
|
+ ),
|
|
|
+ 'borders' => array(
|
|
|
+ 'allborders' => array('style' => Border::BORDER_THIN),
|
|
|
+ )
|
|
|
+ ));
|
|
|
+ $excel->getActiveSheet()->setCellValue('A1','ID');
|
|
|
+ $excel->getActiveSheet()->setCellValue('B1','手机号');
|
|
|
+ $excel->getActiveSheet()->setCellValue('C1','省份');
|
|
|
+ $excel->getActiveSheet()->setCellValue('D1','归属地');
|
|
|
+ $excel->getActiveSheet()->setCellValue('E1','运营商');
|
|
|
+ $excel->getActiveSheet()->setCellValue('F1','供应商');
|
|
|
+ $excel->getActiveSheet()->setCellValue('G1','卡品牌');
|
|
|
+ $excel->getActiveSheet()->setCellValue('H1','规律');
|
|
|
+ $excel->getActiveSheet()->setCellValue('I1','套餐信息');
|
|
|
+ $excel->getActiveSheet()->setCellValue('J1','原价');
|
|
|
+ $excel->getActiveSheet()->setCellValue('K1','底价');
|
|
|
+ $excel->getActiveSheet()->setCellValue('L1','售价');
|
|
|
+ $excel->getActiveSheet()->setCellValue('M1','秒杀价');
|
|
|
+ $excel->getActiveSheet()->setCellValue('N1','预存话费');
|
|
|
+ $excel->getActiveSheet()->setCellValue('O1','备注');
|
|
|
+ $excel->getActiveSheet()->setCellValue('P1','置顶');
|
|
|
+ $excel->getActiveSheet()->setCellValue('Q1','推荐');
|
|
|
+ $excel->getActiveSheet()->setCellValue('R1','号码状态');
|
|
|
+ $excel->getActiveSheet()->setCellValue('S1','更新时间');
|
|
|
+ $excel->getActiveSheet()->setCellValue('T1','上架时间');
|
|
|
+ $excel->getActiveSheet()->setCellValue('U1','排序');
|
|
|
+ $excel->getActiveSheet()->setCellValue('V1','预占通道');
|
|
|
+ $excel->getActiveSheet()->setCellValue('W1','预占用户ID');
|
|
|
+ $excel->getActiveSheet()->setCellValue('X1','上传用户');
|
|
|
+ $i=2;
|
|
|
+ foreach ($mobiles as $mobile){
|
|
|
+ $rules=[];
|
|
|
+ foreach (MobileConstant::getFilters() as $rule=>$field){
|
|
|
+ foreach (array_values($field) as $column){
|
|
|
+ if($mobile[$column]==1){
|
|
|
+ $rules[]=$rule;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $mobile['rules']=array_values(array_unique($rules));
|
|
|
+ $status=$mobile['is_activity']?'预占':\app\common\model\Mobile::$status[$mobile['status']];
|
|
|
+ $excel->getActiveSheet()->setCellValue('A'.$i,$mobile['id']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('B'.$i,$mobile['no']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('C'.$i,$mobile['province']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('D'.$i,$mobile['city']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('E'.$i,$mobile['network']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('F'.$i,$mobile['proxy']['nickname']??'');
|
|
|
+ $excel->getActiveSheet()->setCellValue('G'.$i,$mobile['brand']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('H'.$i,implode(',',$mobile['rules']));
|
|
|
+ $excel->getActiveSheet()->setCellValue('I'.$i,$mobile['info']['describe']??'');
|
|
|
+ $excel->getActiveSheet()->setCellValue('J'.$i,$mobile['amount_original']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('K'.$i,$mobile['amount_di']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('L'.$i,$mobile['amount_base']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('M'.$i,$mobile['amount_kill']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('N'.$i,$mobile['amount_charge']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('O'.$i,$mobile['remark']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('P'.$i,$mobile['top_time']?'是':'否');
|
|
|
+ $excel->getActiveSheet()->setCellValue('Q'.$i,$mobile['rec_time']?'是':'否');
|
|
|
+ $excel->getActiveSheet()->setCellValue('R'.$i,$status);
|
|
|
+ $excel->getActiveSheet()->setCellValue('S'.$i,date('Y-m-d H:i:s',$mobile['update_time']));
|
|
|
+ $excel->getActiveSheet()->setCellValue('T'.$i,date('Y-m-d H:i:s',$mobile['create_time']));
|
|
|
+ $excel->getActiveSheet()->setCellValue('U'.$i,$mobile['sort']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('V'.$i,$mobile['hold_chan']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('W'.$i,$mobile['hold_user']);
|
|
|
+ $excel->getActiveSheet()->setCellValue('X'.$i,$mobile['admin_id']);
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+ $excel->createSheet();
|
|
|
+ // Redirect output to a client’s web browser (Excel2007)
|
|
|
+ $title = date("YmdHis");
|
|
|
+ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
+ header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
|
|
|
+ header('Cache-Control: max-age=0');
|
|
|
+ // If you're serving to IE 9, then the following may be needed
|
|
|
+ header('Cache-Control: max-age=1');
|
|
|
+
|
|
|
+ // If you're serving to IE over SSL, then the following may be needed
|
|
|
+ header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
|
|
|
+ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
|
|
|
+ header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
|
|
+ header('Pragma: public'); // HTTP/1.0
|
|
|
+
|
|
|
+
|
|
|
+ $objWriter = IOFactory::createWriter($excel, 'Xlsx');
|
|
|
+ $objWriter->save('php://output');
|
|
|
+ }
|
|
|
}
|