common.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. // 应用公共文件
  3. use think\facade\Db;
  4. if(!function_exists("json_show")){
  5. function json_show(int $code = 0, string $message = '请求成功', array $data = [])
  6. {
  7. return json(['code' => $code, 'message' => $message, 'data' => $data]);
  8. }
  9. }
  10. /**手机号验证
  11. * @param $mobile
  12. * @return bool
  13. */
  14. if(!function_exists("checkMobile")){
  15. function checkMobile($mobile){
  16. if (!is_numeric($mobile)) {
  17. return false;
  18. }
  19. return preg_match('#^1[3,4,5,6,7,8,9]{1}[\d]{9}$#', $mobile) ? true : false;
  20. }
  21. }
  22. /**邮箱验证
  23. * @param $email
  24. * @return bool
  25. */
  26. if(!function_exists("checkEmail")){
  27. function checkEmail($email){
  28. if (!$email) {
  29. return false;
  30. }
  31. return preg_match('#[a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+)?\.[\w\-]+#is', $email) ? true : false;
  32. }
  33. }
  34. /**
  35. * @param
  36. * @return int
  37. */
  38. if(!function_exists("makeSalt")){
  39. function makeSalt(){
  40. $salt = rand(10000000,99999999);
  41. return $salt;
  42. }
  43. }
  44. /**
  45. * @param $account
  46. * @param float|int $expire
  47. * @return string
  48. */
  49. if(!function_exists("makeToken")){
  50. function makeToken($account){
  51. return sha1($account['username'].$account['mobile'].time());
  52. }
  53. }
  54. if(!function_exists("checkToken")){
  55. /**
  56. * @param $token
  57. * @param int $expire
  58. * @return array|bool|float|int|mixed|\stdClass|string|null
  59. * @throws \Psr\SimpleCache\InvalidArgumentException
  60. */
  61. function checkToken($token,$expire=0){
  62. $getToken = think\facade\Cache::store("redis")->get("user:info:{$token}");
  63. if($getToken!=false){
  64. $cache=think\facade\Cache::store("redis")->set("user:info:{$token}",$getToken,$expire);
  65. if($cache!=false) return $getToken;
  66. }
  67. return false;
  68. }
  69. }
  70. if(!function_exists('GetPart')){
  71. function GetPart(int $item_id=0){
  72. return '';
  73. }
  74. }
  75. //获取组织架构的层级列表
  76. //@param $data 顶级列表的数据集合
  77. //@param $vio 是否展示部门下的账号
  78. if (!function_exists('crea')) {
  79. function crea($data, $vio = 0)
  80. {
  81. $db = Db::name("company_item")
  82. ->field(true)
  83. ->where(['pid' => $data['id'], 'is_del' => 0])
  84. ->select()
  85. ->toArray();
  86. if ($vio == 1) {
  87. $d = Db::name("sys_account_item")
  88. ->alias('a')
  89. ->field('a.account_id,b.username,c.nickname,c.mobile,b.status')
  90. ->leftJoin('account b','b.id=a.account_id AND b.is_del=0')
  91. ->leftJoin('user c','c.account_id=a.account_id')
  92. ->where(['itemid' => $data['id'], 'is_del' => 0])
  93. ->select()
  94. ->toArray();
  95. $data['item'] = $d;
  96. }
  97. if (empty($db)) {
  98. $data['child'] = [];
  99. return $data;
  100. }
  101. //var_dump($db);
  102. foreach ($db as $p) {
  103. $data['child'][] = crea($p, $vio);
  104. }
  105. return $data;
  106. }
  107. }