123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- // 应用公共文件
- use think\facade\Db;
- if(!function_exists("json_show")){
- function json_show(int $code = 0, string $message = '请求成功', array $data = [])
- {
- return json(['code' => $code, 'message' => $message, 'data' => $data]);
- }
- }
- /**手机号验证
- * @param $mobile
- * @return bool
- */
- if(!function_exists("checkMobile")){
- function checkMobile($mobile){
- if (!is_numeric($mobile)) {
- return false;
- }
- return preg_match('#^1[3,4,5,6,7,8,9]{1}[\d]{9}$#', $mobile) ? true : false;
- }
- }
- /**邮箱验证
- * @param $email
- * @return bool
- */
- if(!function_exists("checkEmail")){
- function checkEmail($email){
- if (!$email) {
- return false;
- }
- return preg_match('#[a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+)?\.[\w\-]+#is', $email) ? true : false;
- }
- }
- /**
- * @param
- * @return int
- */
- if(!function_exists("makeSalt")){
- function makeSalt(){
- $salt = rand(10000000,99999999);
- return $salt;
- }
- }
- /**
- * @param $account
- * @param float|int $expire
- * @return string
- */
- if(!function_exists("makeToken")){
- function makeToken($account){
- return sha1($account['username'].$account['mobile'].time());
- }
- }
- if(!function_exists("checkToken")){
- /**
- * @param $token
- * @param int $expire
- * @return array|bool|float|int|mixed|\stdClass|string|null
- * @throws \Psr\SimpleCache\InvalidArgumentException
- */
- function checkToken($token,$expire=0){
- $getToken = think\facade\Cache::store("redis")->get("user:info:{$token}");
- if($getToken!=false){
- $cache=think\facade\Cache::store("redis")->set("user:info:{$token}",$getToken,$expire);
- if($cache!=false) return $getToken;
- }
- return false;
- }
- }
- //获取部门的层级名称
- if (!function_exists('get_part')) {
- function get_part(int $item_id = 0,array $data=[])
- {
- $db = Db::name("company_item")
- ->field('id,name,pid')
- ->where(['id' => $item_id, 'is_del' => 0])
- ->findOrEmpty();
- if (empty($db)) return [];
- // $tem=[];
- // $tem['id']=$db['id'];
- // $tem['name']=$db['name'];
- array_unshift($data, $db);
- if ($db['pid'] == 0) return $data;
- else return get_part($db['pid'], $data);
- }
- }
- //获取组织架构的层级列表
- //@param $data 顶级列表的数据集合
- //@param $vio 是否展示部门下的账号
- if (!function_exists('crea')) {
- function crea($data, $vio = 0)
- {
- $db = Db::name("company_item")
- ->field(true)
- ->where(['pid' => $data['id'], 'is_del' => 0])
- ->select()
- ->toArray();
- if ($vio == 1) {
- $d = Db::name("sys_account_item")
- ->alias('a')
- ->field('a.account_id,b.username,c.nickname,c.mobile,b.status')
- ->leftJoin('account b','b.id=a.account_id AND b.is_del=0')
- ->leftJoin('user c','c.account_id=a.account_id')
- ->where(['itemid' => $data['id'], 'is_del' => 0])
- ->select()
- ->toArray();
- $data['item'] = $d;
- }
- if (empty($db)) {
- $data['child'] = [];
- return $data;
- }
- //var_dump($db);
- foreach ($db as $p) {
- $data['child'][] = crea($p, $vio);
- }
- return $data;
- }
- }
- //生成随机字符串
- if (function_exists('makeNo') == false) {
- function makeNo(string $str = '')
- {
- $date = date("ymdHis");
- // $year = date("Y")-2000;
- $msec = rand(1000, 9999);
- return $str . $date . $msec;
- }
- }
- //获取三级架构
- if (!function_exists('get_top_customer_org')) {
- function get_top_customer_org($var, $data = [])
- {
- $str = Db::name('customer_org1')
- ->field('id,name,pid,level')
- ->where(['id' => $var])
- ->findOrEmpty();
- if (empty($str)) return [];
- $vmn = [];
- $vmn['id'] = $str['id'];
- $vmn['name'] = $str['name'];
- $vmn['level'] = $str['level'];
- array_unshift($data, $vmn);
- // $var['id']=made();
- if ($str['pid'] == 0) return $data;
- else return get_top_customer_org($str['pid'], $data);
- }
- }
|