CmsController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\index\controller;
  3. use app\index\service\HelperService;
  4. use app\index\service\TokenService;
  5. use \think\Controller;
  6. class CmsController extends Controller
  7. {
  8. public $post = [];
  9. public $allowCompany = [
  10. 'YAWY','YTMALL','GREENLNNHOTEL','VOWKIN','TMZJ','VWHEEL','JINRONGYUAN',
  11. 'CCHLK','MISAP','AYKJ','ALJL','YLBG','SMDD','GD','RHZB',"WPCW"
  12. ];
  13. public function _initialize()
  14. {
  15. HelperService::$_startExecTime = microtime(true);
  16. $params_list = ['token'=>'string','companyCode'=>'string'];
  17. $this->post = $this->request->post();
  18. //跳过验证的特殊办法
  19. if(isset($this->request->param()['leo_debug'])
  20. && $this->request->param()['leo_debug']== 'leo'){
  21. return true;
  22. }
  23. HelperService::diffParam($params_list,$this->post);
  24. $TokenService = new TokenService();
  25. $res = $TokenService->checkToken($this->post);
  26. if($res !== true){
  27. HelperService::returnJson($res);
  28. }else{
  29. unset($this->post['token']);
  30. }
  31. }
  32. protected function returnJson($data,$code=200,$msg='success'){
  33. HelperService::returnJson([
  34. 'code'=>$code,
  35. 'msg'=>$msg,
  36. 'data'=>$data
  37. ]);
  38. }
  39. protected function toArray($res){
  40. $data = [];
  41. if(!empty($res)){
  42. foreach($res as $k=>$v){
  43. $data[] = $res[$k]->toArray();
  44. }
  45. }
  46. return $data ;
  47. }
  48. /**
  49. * 生成订单号
  50. * @return string
  51. */
  52. protected function createOrderNum(){
  53. $key = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 4, 5);
  54. $key.=rand(100,999);
  55. usleep(1000);
  56. return $key;
  57. }
  58. }