| 
									
										
										
										
											2022-10-08 17:31:39 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace app\controller\manager; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use app\controller\BaseController; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Style\Alignment; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Style\Border; | 
					
						
							|  |  |  | use think\response\Redirect; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * 控制器基础类 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class Base extends BaseController | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // excel 导出格式配置
 | 
					
						
							|  |  |  |     protected $excelStyle = [ | 
					
						
							|  |  |  |         'font'      => [ | 
					
						
							|  |  |  |             'name' => '宋体', | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         'alignment' => [ | 
					
						
							|  |  |  |             'horizontal' => Alignment::HORIZONTAL_CENTER,  // 水平居中
 | 
					
						
							|  |  |  |             'vertical'   => Alignment::VERTICAL_CENTER,  // 垂直居中
 | 
					
						
							|  |  |  |             'wrapText'   => true, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         'borders'   => [ | 
					
						
							|  |  |  |             'allBorders' => [ | 
					
						
							|  |  |  |                 'borderStyle' => Border::BORDER_THIN, | 
					
						
							|  |  |  |                 'color'       => ['rgb' => 'eeeeee'], | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected $defaultSetting = [ | 
					
						
							|  |  |  |         'cell_width' => 30, | 
					
						
							|  |  |  |         'font_size'  => 12 | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected $data = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected function initialize() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->middleware     = [ | 
					
						
							|  |  |  |             //'csrf',
 | 
					
						
							|  |  |  |             'auth' => [ | 
					
						
							|  |  |  |                 'except' => ['manager.login/index'] | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         $auth                 = session('auth'); | 
					
						
							|  |  |  |         $this->data['member'] = $auth; | 
					
						
							|  |  |  |         if (session('?__token__')) { | 
					
						
							|  |  |  |             $this->data['_token'] = session('__token__'); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $this->data['_token'] = $this->request->buildToken(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $this->data['groupId'] = $auth['groupId'] ?? 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //变量赋值到模板
 | 
					
						
							|  |  |  |     protected function view() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return view()->assign($this->data); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param  string  $msg | 
					
						
							|  |  |  |      * @param  string|null  $url | 
					
						
							|  |  |  |      * @param  string  $data | 
					
						
							|  |  |  |      * @param  int  $wait | 
					
						
							|  |  |  |      * @return Redirect | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function error($msg = '', string $url = null, $data = '', int $wait = 3): Redirect | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (is_null($url)) { | 
					
						
							|  |  |  |             $url = $this->request->isAjax() ? '' : 'javascript:history.back(-1);'; | 
					
						
							|  |  |  |         } elseif ($url) { | 
					
						
							|  |  |  |             $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : $this->app->route->buildUrl($url); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $result = [ | 
					
						
							|  |  |  |             'code' => 0, | 
					
						
							|  |  |  |             'msg'  => $msg, | 
					
						
							|  |  |  |             'data' => $data, | 
					
						
							|  |  |  |             'url'  => $url, | 
					
						
							|  |  |  |             'wait' => $wait, | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->redirect(url('manager.error/jump', $result)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-10-11 18:20:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // 根据活动
 | 
					
						
							|  |  |  |     protected function getImgSize($categoryId) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-12 17:53:40 +08:00
										 |  |  |         $category      = \app\model\Category::field('id,img_width,img_height,img_width_mobile,img_height_mobile,width,height,width_mobile,height_mobile')->find($categoryId); | 
					
						
							|  |  |  |         $pcImgSize     = '';//PC组图
 | 
					
						
							|  |  |  |         $mobileImgSize = '';//手机组图
 | 
					
						
							|  |  |  |         //PC封面图
 | 
					
						
							|  |  |  |         $coverSize = $category['img_width'].'*'.$category['img_height'].'px'; | 
					
						
							|  |  |  |         //手机封面图
 | 
					
						
							|  |  |  |         $mobileCoverSize = $category['img_width_mobile'].'*'.$category['img_height_mobile'].'px'; | 
					
						
							| 
									
										
										
										
											2022-10-11 18:20:04 +08:00
										 |  |  |         switch ($categoryId) { | 
					
						
							|  |  |  |             // 品牌活动
 | 
					
						
							|  |  |  |             case 39: | 
					
						
							|  |  |  |                 $pcImgSize       = '1360*680px'; | 
					
						
							|  |  |  |                 $mobileImgSize   = '365*185px'; | 
					
						
							|  |  |  |                 $coverSize       = '340*225px'; | 
					
						
							|  |  |  |                 $mobileCoverSize = '185*120px'; | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2022-10-12 17:53:40 +08:00
										 |  |  |             case 9: | 
					
						
							|  |  |  |             case 10: | 
					
						
							|  |  |  |             case 23: | 
					
						
							|  |  |  |             case 24: | 
					
						
							|  |  |  |             case 25: | 
					
						
							|  |  |  |                 $pcImgSize     = '1360*680px'; | 
					
						
							|  |  |  |                 $mobileImgSize = '365*185px'; | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2022-10-11 18:20:04 +08:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->data['pcImgSize']       = $pcImgSize; | 
					
						
							|  |  |  |         $this->data['mobileImgSize']   = $mobileImgSize; | 
					
						
							| 
									
										
										
										
											2022-10-12 17:53:40 +08:00
										 |  |  |         $this->data['coverSize']       = $coverSize ?? ''; | 
					
						
							|  |  |  |         $this->data['mobileCoverSize'] = $mobileCoverSize ?? ''; | 
					
						
							| 
									
										
										
										
											2022-10-11 18:20:04 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-10-08 17:31:39 +08:00
										 |  |  | } |