123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\controller;
- use app\BaseController;use think\App;use think\exception\HttpResponseException;use think\Response;
- class Base extends BaseController
- {
- protected $novalidate=[
- 'systemlast',
- 'login',
- 'stats',
- 'departstat',
- 'departEveryDay',
- 'departEveryMonth',
- 'companyEveryMonth',
- 'dzqrd',
- 'companyEvery',
- 'wechat_getinfo',
- 'wechat_getconfig',
- 'totalstat'
- ];
- public $supperAction=[
- 'payadd',#对账新建
- 'paysave',#对账编辑
- 'paydel',#对账删除
- 'invadd',#回票申请新建
- 'invAddBatchByImport',#回票申请批量
- 'invdel',#回票申请删除
- 'hpinvreturn', #回票申请退票
- 'stagereturn',#付款申请退款
- ];
- public $uid=0;
- public $uname='';
- public $roleid=0;
- public $level=0;
- public $post='';
- public function __construct(App $app) {
- parent::__construct($app);
- $this->post=$this->request->param();
- if(!in_array($this->request->pathinfo(),$this->novalidate)&&!in_array('*', $this->novalidate)){
- $this->validateToken($this->request->param());
- }
- }
-
- /**
- * @param string $message
- * @param int $code
- * @param null $data
- */
- public function error($message='',$code=1003,$data=null){
- $this->result($message,$data,$code);
- }
- /**
- * @param string $msg
- * @param null $data
- * @param int $code
- * @param string|null $type
- * @param array $header
- * @param array $options
- */
- private function result(string $msg, $data = null, int $code = 0, string $type = 'json', array $header = [], array
- $options = [])
- {
- $result = [
- 'code' => $code,
- 'message' => $msg,
- 'data' => $data,
- ];
- $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 success($message='',$data=null,$code=0){
- $this->result($message,$data,$code);
- }
- /**
- * @param $request 校验用户信息
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function validateToken($request){
- $token = $request['token']?? '';
- $companyNo = $request['relaComNo'] ?? '';
- if($token=='') $this->error('参数token不能为空',101);
- $effetc = VerifyTokens($token);
- if(!empty($effetc) && $effetc['code']!=0)$this->error($effetc['message'],$effetc['code']);
- $this->uid=$effetc['data']['id']??'';
- $this->uname=$effetc['data']['nickname']??'';
- $where=[];
- if($companyNo!=''){
- $where=['companyNo'=>$companyNo];
- }
- $userrole = \app\admin\model\UserRole::where(['uid'=>$this->uid,'is_del'=>0])->where($where)
- ->findOrEmpty();
- if($userrole->isEmpty()){
- $this->error("账户已禁用",101);
- }
- $this->roleid=$userrole->roleid;
- $role =\app\admin\model\Role::where(['id'=>$userrole->roleid])->findOrEmpty();
- if($role->status==0 || $userrole->status==0 ){
- $this->level=0;
- }else $this->level = $effetc['data']['level'];
-
- }
- //供应商公司存在操作账户,请用供应商账户操作
- public function NoAction(){
- $pathinfo =$this->request->pathinfo();
- $relaComNo =$this->request->param('relaComNo');
- if (in_array($this->level, [2, 3])) {
- if (in_array($pathinfo, $this->supperAction) && $this->level == 2) {
- if ($relaComNo == '') $this->error('关联公司不能为空');
- $companyinfo = UserHandle('/hqInfo', ['code' => $relaComNo]);
- if ($companyinfo['code'] != 0)$this->error($companyinfo['message'],$companyinfo['code']);
- if (!empty($companyinfo['data']) && $companyinfo['data']['relation_code'] != '') {
- $db= UserHandle('/userCompanyBasicList', ['companyNo' =>$companyinfo['data']['relation_code']]);
- if ($db['code'] != 0) $this->error($db['message'],$db['code']);
- if (!empty($db['data']) && $db['data']['count'] > 0) {
- $this->error("供应商公司存在操作账户,请用供应商账户操作");
- }
- }
- }
- }
- }
- }
|