123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?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]);
- }
- }
- 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;
- }
- }
- if(!function_exists("checkEmail")){
- function checkEmail($email){
- if (!$email) {
- return false;
- }
- return preg_match('#[a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+)?\.[\w\-]+#is', $email) ? true : false;
- }
- }
- if(!function_exists("makeSalt")){
- function makeSalt(){
- $salt = rand(10000000,99999999);
- return $salt;
- }
- }
- if(!function_exists("makeToken")){
- function makeToken($account){
- return sha1($account['username'].$account['mobile'].time());
- }
- }
- if(!function_exists("checkToken")){
-
- 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('GetPart')){
- function GetPart(int $item_id=0){
- return '';
- }
- }
- 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;
- }
-
- foreach ($db as $p) {
- $data['child'][] = crea($p, $vio);
- }
- return $data;
- }
- }
|