123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- declare (strict_types = 1);
- namespace app\report\controller;
- use app\BaseController;
- use app\model\AccountItem;use think\App;
- use think\facade\Cache;use think\Response;
- use think\exception\HttpResponseException;
- class Base extends BaseController
- {
- protected $responseType = 'json';
- public function __construct(App $app) {parent::__construct($app);}
-
- public function result(string $msg, $data = null, int $code = 0, string $type = null, array $header = [], array $options = [])
- {
- $result = [
- 'code' => $code,
- 'msg' => $msg,
- 'data' => $data,
- ];
- // 如果未设置类型则自动判断
- $type = $type ?: $this->responseType;
- $code = 200;
- if (isset($header['statuscode'])) {
- $code = $header['statuscode'];
- unset($header['statuscode']);
- }
- $response = Response::create($result, $type, $code)->header($header)->options($options);
- throw new HttpResponseException($response);
- }
-
- /**
- * @param string $message
- * @param int $code
- * @param null $data
- */
- public function error($message='',$code=1004,$data=null){
- $this->result($message,$data,$code);
- }
- /**
- * @param string $message
- * @param int $code
- * @param null $data
- */
- public function success($message='',$data=null,$code=0){
- $this->result($message,$data,$code);
- }
- public function GetDepartId($derpar_id){
- $uid=Cache::get("Report::depart_".$derpar_id);
- if($uid==false){
- $uid = (new AccountItem())->GetUidByDepartId($derpar_id);
- Cache::set('Report::depart_'.$derpar_id,$uid,new \DateTime(date("Y-m-d 23:59:59")));
- }
-
- return $uid;
- }
- }
|