common.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. <?php
  2. // 应用公共文件
  3. use think\facade\Config;
  4. use think\facade\Db;
  5. use think\facade\Filesystem;
  6. use think\helper\Str;
  7. // 应用公共文件
  8. function app_show($code=0,$message="",$data=[]){
  9. $result = ['code'=>$code,"message"=>$message,"data"=>$data];
  10. echo json_encode($result,JSON_UNESCAPED_UNICODE);
  11. die();
  12. }
  13. // 应用公共文件
  14. function error_show($code=0,$message=""){
  15. $result = ['code'=>$code,"message"=>$message];
  16. echo json_encode($result,JSON_UNESCAPED_UNICODE);
  17. die();
  18. }
  19. function GetUserInfo($token){
  20. $host = Config::get("app");
  21. $url = $host["api_host"]."/Api/userinfo";
  22. $data=[
  23. "token"=>$token
  24. ];
  25. $response=curl_request($url,$data);
  26. return json_decode($response,true);
  27. }
  28. //参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies
  29. function curl_request($url,$post=''){
  30. $curl = curl_init();
  31. curl_setopt($curl, CURLOPT_URL, $url);
  32. curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');
  33. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  34. curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
  35. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  36. if($post) {
  37. curl_setopt($curl, CURLOPT_POST, 1);
  38. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
  39. }
  40. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  41. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  42. $data = curl_exec($curl);
  43. if (curl_errno($curl)) {
  44. return curl_error($curl);
  45. }
  46. curl_close($curl);
  47. return $data;
  48. }
  49. /**手机号验证
  50. * @param $mobile
  51. * @return bool
  52. */
  53. function checkMobile($mobile){
  54. if (!is_numeric($mobile)) {
  55. return false;
  56. }
  57. return preg_match('#^1[3,4,5,6,7,8,9]{1}[\d]{9}$#', $mobile) ? true : false;
  58. }
  59. function checkTel($tel){
  60. if (!$tel) {
  61. return false;
  62. }
  63. return preg_match('/^(0[0-9]{2,3}\-)([0-9]{7,8})+(\-[0-9]{1,4})?$/', $tel) ? true : false;
  64. }
  65. /**邮箱验证
  66. * @param $email
  67. * @return bool
  68. */
  69. function checkEmail($email){
  70. if (!$email) {
  71. return false;
  72. }
  73. return preg_match('#[a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+)?\.[\w\-]+#is', $email) ? true : false;
  74. }
  75. /**
  76. * @param
  77. * @return int
  78. */
  79. function makeSalt(){
  80. $salt = rand(10000000,99999999);
  81. return $salt;
  82. }
  83. /**
  84. * @param $token
  85. * @return array
  86. * @throws \think\db\exception\DataNotFoundException
  87. * @throws \think\db\exception\DbException
  88. * @throws \think\db\exception\ModelNotFoundException
  89. * @throws \think\exception\DbException
  90. */
  91. function VerifyTokens($token){
  92. $host = Config::get("app");
  93. $url = $host["api_host"]."/Api/verify_token";
  94. $data=[
  95. "token"=>$token
  96. ];
  97. $response=curl_request($url,$data);
  98. return json_decode($response,true);
  99. }
  100. /**
  101. * @param $token
  102. * @param $condition
  103. * @return mixed
  104. */
  105. function GetUserlist($token,$condition){
  106. $host = Config::get("app");
  107. $url = $host["api_host"]."/Api/getuserlist";
  108. $condition['token']=$token;
  109. $response=curl_request($url,$condition);
  110. return json_decode($response,true);
  111. }
  112. /**
  113. * @param $token
  114. * @param $condition
  115. * @return mixed
  116. */
  117. function GetAccountall($token, $condition){
  118. $host = Config::get("app");
  119. $url = $host["api_host"]."/Api/userall";
  120. $condition['token']=$token;
  121. $response=curl_request($url,$condition);
  122. return json_decode($response,true);
  123. }
  124. function GetList($token,$condition){
  125. $host = Config::get("app");
  126. $url = $host["api_host"]."/Api/userlist";
  127. $condition['token']=$token;
  128. $response=curl_request($url,$condition);
  129. return json_decode($response,true);
  130. }
  131. /**
  132. * @param $token
  133. * @param $condition ['id'=>1]
  134. * @return mixed
  135. */
  136. function GetInfoById($token,$condition){
  137. $host = Config::get("app");
  138. $url = $host["api_host"]."/Api/userinfobyid";
  139. $condition['token']=$token;
  140. $response=curl_request($url,$condition);
  141. return json_decode($response,true);
  142. }
  143. function GetInfoNoToken($condition){
  144. $host = Config::get("app");
  145. $url = $host["api_host"]."/Api/uinfo";
  146. $response=curl_request($url,$condition);
  147. return json_decode($response,true);
  148. }
  149. function makeNo($str){
  150. $date=date("mdHis");
  151. $year = date("Y")-2000;
  152. $msec=rand(1000,9999);
  153. return $str.$year.$date.$msec;
  154. }
  155. function randomkeys($length) {
  156. $returnStr='';
  157. $pattern = '1234567890abcdefghijklmnopqrstuvwxyz';//ABCDEFGHIJKLOMNOPQRSTUVWXYZ
  158. for($i = 0; $i < $length; $i ++) {
  159. $returnStr .= $pattern[mt_rand ( 0, strlen($pattern)-1 )]; //生成php随机数
  160. }
  161. return $returnStr;
  162. }
  163. function tree(){
  164. }
  165. /**
  166. * @param $files
  167. * @return array
  168. */
  169. function UploadImg($files)
  170. {
  171. $savename = [];
  172. $files = !is_array($files) ? [$files] : $files;
  173. try {
  174. //验证
  175. validate(['imgFile' => ['fileSize' => 10240000, 'fileExt' => 'jpg,jpeg,png,bmp,gif', 'fileMime' => 'image/jpeg,image/png,image/gif']])->check(['imgFile' => $files]);
  176. foreach ($files as $file) {
  177. $url = Filesystem::disk('public')->putFile('topic/' . date("Ymd"), $file, function () use ($file) {
  178. return str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName() . "_" . date('YmdHis'));
  179. });
  180. $name = str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName());
  181. $temp = ["url" => $url, "name" => $name];
  182. $savename[] = $temp;
  183. }
  184. return $savename;
  185. } catch (\think\exception\ValidateException $e) {
  186. return $e->getMessage();
  187. }
  188. }
  189. /**
  190. * @param $files
  191. * @return array
  192. */
  193. function UploadFile($files)
  194. {
  195. $savename = [];
  196. $files = !is_array($files) ? [$files] : $files;
  197. try {
  198. //验证
  199. validate(['imgFile' => ['fileSize' => 10240000,'fileExt' => 'xlsx,xls,pdf,zip,rar,7z,doc,docx']])->check(['imgFile' =>
  200. $files]);
  201. foreach ($files as $file) {
  202. $url = Filesystem::disk('public')->putFile('files/' . date("Ymd"), $file, function () use ($file) {
  203. return str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName() . "_" . date('YmdHis'));
  204. });
  205. $name = str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName());
  206. $temp = ["url" => $url, "name" => $name];
  207. $savename[] = $temp;
  208. }
  209. return $savename;
  210. } catch (\think\exception\ValidateException $e) {
  211. return $e->getMessage();
  212. }
  213. }
  214. /**
  215. * @param $files
  216. * @return array
  217. */
  218. function UploadVideo($files)
  219. {
  220. $savename = [];
  221. $files = !is_array($files) ? [$files] : $files;
  222. try {
  223. //验证
  224. validate(['videoFile' => ['fileSize' => 10240000,'fileExt' => 'mp4,mp3,avi']])->check(['videoFile' => $files]);
  225. foreach ($files as $file) {
  226. $url = Filesystem::disk('public')->putFile('video/' . date("Ymd"), $file, function () use ($file) {
  227. return str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName() . "_" . date('YmdHis'));
  228. });
  229. $name = str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName());
  230. $temp = ["url" => $url, "name" => $name];
  231. $savename[] = $temp;
  232. }
  233. return $savename;
  234. } catch (\think\exception\ValidateException $e) {
  235. return $e->getMessage();
  236. }
  237. }
  238. /**
  239. * @param $token
  240. * @param $condition
  241. * @return mixed
  242. */
  243. function resetpwd($token,$condition){
  244. $host = Config::get("app");
  245. $url = $host["api_host"]."/Api/passset";
  246. $condition['token']=$token;
  247. $response=curl_request($url,$condition);
  248. return json_decode($response,true);
  249. }
  250. function resetpasswd($token,$condition){
  251. $host = Config::get("app");
  252. $url = $host["api_host"]."/Api/passsave";
  253. $condition['token']=$token;
  254. $response=curl_request($url,$condition);
  255. return json_decode($response,true);
  256. }
  257. /**
  258. * @param $token
  259. * @param $condition
  260. * @return mixed
  261. */
  262. function resetinfo($token,$condition){
  263. $host = Config::get("app");
  264. $url = $host["api_host"]."/Api/usersave";
  265. $condition['token']=$token;
  266. $response=curl_request($url,$condition);
  267. return json_decode($response,true);
  268. }
  269. /**
  270. * @param $token
  271. * @param $condition
  272. * @return mixed
  273. */
  274. function resetstatus($token,$condition){
  275. $host = Config::get("app");
  276. $url = $host["api_host"]."/Api/userstatus";
  277. $condition['token']=$token;
  278. $response=curl_request($url,$condition);
  279. return json_decode($response,true);
  280. }
  281. /**
  282. * @param $data
  283. * @throws \think\db\exception\DataNotFoundException
  284. * @throws \think\db\exception\DbException
  285. * @throws \think\db\exception\ModelNotFoundException
  286. */
  287. function crea($data,$vio=0)
  288. {
  289. $db = Db::name("company_item")->where(['pid'=>$data['id'],'is_del'=>0])->select()->toArray();
  290. if($vio==1){
  291. $d = Db::name("depart_user")->where(['itemid'=>$data['id'],'is_del'=>0])->select()->toArray();
  292. if(empty($d)){
  293. $data['item']=[];
  294. }else{
  295. $data['item']=$d;
  296. }
  297. }
  298. if(empty($db)){
  299. $data['child']=[];
  300. return $data;
  301. }
  302. //var_dump($db);
  303. foreach ($db as $p){
  304. $data['child'][]=crea($p,$vio);
  305. }
  306. return $data;
  307. }
  308. function GetPart($id,$data=[]){
  309. $db = Db::name("company_item")->where(['id'=>$id,'is_del'=>0])->find();
  310. if($db==false){
  311. return [];
  312. }
  313. $tem=[];
  314. $tem['id']=$db['id'];
  315. $tem['name']=$db['name'];
  316. array_unshift($data,$tem);
  317. if($db['pid']==0){
  318. // krsort($data);
  319. return $data;
  320. }else{
  321. return GetPart($db['pid'],$data);
  322. }
  323. }
  324. function stro($data){
  325. $db=Db::name('cat')->where(['pid'=>$data['id']])->select()->toArray();
  326. if(empty($db)){
  327. $data['child']=[];
  328. return $data;
  329. }
  330. foreach ($db as $item) {
  331. $data['child'][]=stro($item);
  332. }
  333. return $data;
  334. }
  335. function coco($data){
  336. $db=Db::name('exclusive')->where(['pid'=>$data['id']])->select()->toArray();
  337. if(empty($db)){
  338. $data['child']=[];
  339. return $data;
  340. }
  341. foreach ($db as $item) {
  342. $data['child'][]=coco($item);
  343. }
  344. return $data;
  345. }
  346. function mai($var,$data=[]){
  347. $str = Db::name('exclusive')->where(['id'=>$var])->find();
  348. if($str==false){
  349. return [];
  350. }
  351. $vmn =[];
  352. $vmn['id'] =$str['id'];
  353. $vmn['rname'] =$str['name'];
  354. array_unshift($data,$vmn);
  355. // $var['id']=made();
  356. if($str['pid']==0){
  357. // krsort($data);
  358. return $data;
  359. }else{
  360. return mai($str['pid'],$data);
  361. }
  362. }
  363. function made($var,$data=[]){
  364. $str = Db::name('cat')->where(['id'=>$var])->find();
  365. if($str==false){
  366. return [];
  367. }
  368. $vmn =[];
  369. $vmn['id'] =$str['id'];
  370. $vmn['name'] =$str['cat_name'];
  371. array_unshift($data,$vmn);
  372. // $var['id']=made();
  373. if($str['pid']==0){
  374. // krsort($data);
  375. return $data;
  376. }else{
  377. return made($str['pid'],$data);
  378. }
  379. }
  380. //获取有赞分类信息
  381. function made_youzan(int $yz_cat_id=0,$data=[]){
  382. $rs = get_yz_cat_info($yz_cat_id);
  383. if(empty($rs)) return [];
  384. $vmn =[];
  385. $vmn['yz_cat_id'] =$rs['id'];
  386. $vmn['yz_cat_name'] =$rs['yz_cat_name'];
  387. array_unshift($data,$vmn);
  388. if($rs['parent_cid']==0) return $data;
  389. else return made_youzan($rs['parent_cid'],$data);
  390. }
  391. //跨数据库获取有赞分类信息
  392. if(!function_exists('get_yz_cat_info')){
  393. function get_yz_cat_info(int $yz_cat_id=0){
  394. $key = 'yz_cat_item_'.(string)$yz_cat_id;
  395. $rs = \think\facade\Cache::get($key);
  396. if(!$rs){
  397. $rs = Db::connect('mysql_yz')
  398. ->table('yz_cat')
  399. ->field('id,yz_cat_name,parent_cid')
  400. ->where(['id'=>$yz_cat_id,'status'=>1])
  401. ->findOrEmpty();
  402. if($rs) \think\facade\Cache::set($key,$rs,36000);
  403. }
  404. return $rs;
  405. }
  406. }
  407. function catChild($var,&$data=[]){
  408. $str = Db::name('cat')->where(['id'=>$var])->find();
  409. if($str==false){
  410. return;
  411. }
  412. $data[]=$var;
  413. $lsit = Db::name("cat")->where(["pid"=>$var,"status"=>1,"is_del"=>0])->column("id");
  414. if(!empty($lsit)){
  415. foreach ($lsit as $value){
  416. catChild($value,$data);
  417. }
  418. }
  419. return $data;
  420. }
  421. function makeExcluse($var,$data=[]){
  422. $str = Db::name('exclusive')->where(['id'=>$var])->find();
  423. if($str==false){
  424. return [];
  425. }
  426. $vmn =[];
  427. $vmn['id'] =$str['id'];
  428. $vmn['name'] =$str['name'];
  429. array_unshift($data,$vmn);
  430. // $var['id']=made();
  431. if($str['pid']==0){
  432. // krsort($data);
  433. return $data;
  434. }else{
  435. return makeExcluse($str['pid'],$data);
  436. }
  437. }
  438. function sear($id){
  439. $item = Db::name('cat')->where(['id'=>$id])->field("search")->find();
  440. if($item==false){
  441. return false;
  442. }else{
  443. $temp = Db::name('cat')->where(['pid'=>$id,'is_del'=>0])->select();
  444. if ($temp==false){
  445. return false;
  446. }
  447. }
  448. foreach ($temp as $value){
  449. $value['search']=$item['search']."_".$value['cat_name'];
  450. $list = Db::name('cat')->save($value);
  451. sear($value['id']);
  452. }
  453. }
  454. function manger($list=[],$level=1){
  455. $var = Db::name('cat')->where(['pid'=>$list,'level'=>$level+1])->column("id");
  456. if(empty($var)){
  457. return $list;
  458. }
  459. $a=array_merge($list,$var);
  460. return manger($a,$level+1);
  461. }
  462. /**
  463. * @param $files
  464. * @param string $extend
  465. * @return array
  466. * @throws PHPExcel_Exception
  467. * @throws PHPExcel_Reader_Exception
  468. */
  469. function upload_excel($files,$extend="xls")
  470. {
  471. // 获取表单上传文件
  472. try {
  473. validate([
  474. 'file' => [
  475. // 限制文件大小(单位b),这里限制为4M
  476. //fileSize' => 4 * 1024 * 1024,
  477. 'fileExt' => 'xlsx,xls'
  478. ]
  479. ],
  480. [
  481. //'file.fileSize' => '文件太大',
  482. 'file.fileExt' => '不支持的文件',
  483. ]
  484. )->check(['file' => $files]);
  485. // $name = $files->getOriginalExtension();
  486. if ($extend == 'xlsx') {
  487. $objReader = PHPExcel_IOFactory::createReader('Excel2007');
  488. } else {
  489. $objReader = PHPExcel_IOFactory::createReader('Excel5');
  490. }
  491. $savename = Filesystem::disk('public')->putFile('topic/excel', $files);
  492. $import_path = root_path() . 'public/storage/' . $savename;
  493. $spreadsheet = $objReader->load($import_path);
  494. $sheet = $spreadsheet->getActiveSheet();
  495. $sheetData = $sheet->toArray();
  496. if (empty($sheetData) || !is_array($sheetData)) {
  497. return ['code' => 1003, "msg" => '数据不能为空'];
  498. }
  499. $list = [];
  500. foreach ($sheetData as $key => $value) {
  501. $list[] = $value;
  502. }
  503. return ['code' => 0, "msg" => '数据解析成功', 'data' => $list];
  504. } catch (think\exception\ValidateException $e) {
  505. // echo $e->getMessage();
  506. return ['code' => 1003, "msg" => $e->getMessage()];
  507. }
  508. }
  509. /**
  510. * @param string $fileName
  511. * @param array $headArr
  512. * @param array $data
  513. */
  514. function excelSave($fileName = '', $headArr = [], $data = [])
  515. {
  516. $objPHPExcel = new PHPExcel();
  517. $objPHPExcel->getProperties();
  518. $keyA = 0; // 设置表头
  519. foreach ($headArr as $v) {
  520. $colum = PHPExcel_Cell::stringFromColumnIndex($keyA);
  521. $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v);
  522. $keyA += 1;
  523. }
  524. $column = 2;
  525. $objActSheet = $objPHPExcel->getActiveSheet();
  526. foreach ($data as $key => $rows) { // 行写入
  527. $span = 0;
  528. foreach ($rows as $keyName => $value) { // 列写入
  529. //判断数据是否有数组,如果有数组,转换成字符串
  530. if(is_array($value)){
  531. $value = implode("、", $value);
  532. }
  533. $objActSheet->setCellValue(PHPExcel_Cell::stringFromColumnIndex($span) . $column, $value);
  534. $span++;
  535. }
  536. $column++;
  537. }
  538. // var_dump($objActSheet->getActiveCell());
  539. $file = $fileName. ".xls";
  540. //$fileName .= "_" . date("Y_m_d", Request()->instance()->time()) . ".xls";
  541. //$fileName = iconv("utf-8", "gb2312", $fileName); // 重命名表
  542. $dir =root_path() . 'public/storage/report/'.date("YmdHis")."/";
  543. if(!is_dir($dir)){
  544. mkdir($dir,0777,true);
  545. }
  546. PHPExcel_Settings::setCacheStorageMethod(PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized);
  547. $objPHPExcel->setActiveSheetIndex(0); // 设置活动单指数到第一个表,所以Excel打开这是第一个表
  548. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  549. $objWriter->save($dir . $file); // 文件通过浏览器下载
  550. $url = $dir . $file;
  551. if(!file_exists($url)){
  552. echo "文件生成失败";
  553. }
  554. $saveDir = root_path()."public/storage/zip/";
  555. if(!is_dir( $saveDir)){
  556. mkdir($saveDir,0777,true);
  557. }
  558. $datetime = date("Y-m-d H:i:s");
  559. $file_dir = $saveDir.$datetime.".zip";
  560. # 5.1 文件打包,提示:使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
  561. $zip = new \ZipArchive ();
  562. # 5.2 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip
  563. if ($zip->open($file_dir, \ZipArchive::OVERWRITE) !== true && $zip->open($file_dir, \ZipArchive::CREATE) !==
  564. true) echo '无法打开文件或者文件创建失败';
  565. # 5.3 批量写入压缩包
  566. $zip->addEmptyDir($fileName);
  567. // @$zip->addFile($v['file_path'], 'resume'.DIRECTORY_SEPARATOR.basename($headername));
  568. @$zip->addFile($url,$fileName.DIRECTORY_SEPARATOR.basename($url));
  569. # 5.4 关闭压缩包写入
  570. $zip->close();
  571. @deldir($dir);
  572. # 6. 检查文件是否存在,并输出文件
  573. if (! file_exists ( $file_dir )) echo '简历文件不存在';
  574. ob_clean();
  575. flush();
  576. header("Cache-Control: max-age=0");
  577. header("Content-Description: File Transfer");
  578. header('Content-disposition: attachment; filename=' . basename($file_dir)); # 处理文件名
  579. header("Content-Type: application/octet-stream"); # 流文件输出
  580. header("Content-Transfer-Encoding: binary"); # 告诉浏览器,这是二进制文件
  581. // header('Content-Length: ' . filesize($file_dir)); # 告诉浏览器,文件大小
  582. // readfile($file_dir); # 输出文件
  583. $res = read_big_file($file_dir);
  584. foreach ($res as $val) {
  585. echo $val;
  586. }
  587. @ unlink($file_dir);
  588. exit();
  589. }
  590. //读取大文件
  591. if (!function_exists('read_big_file')){
  592. function read_big_file(string $file=''){
  593. $handle = fopen($file, 'rb');
  594. while (feof($handle) === false) {
  595. yield fgets($handle);
  596. }
  597. fclose($handle);
  598. }
  599. }
  600. function deldir($path){
  601. //如果是目录则继续
  602. if(is_dir($path)){
  603. //扫描一个文件夹内的所有文件夹和文件并返回数组
  604. $p = scandir($path);
  605. //如果 $p 中有两个以上的元素则说明当前 $path 不为空
  606. if(count($p)>2){
  607. foreach($p as $val){
  608. //排除目录中的.和..
  609. if($val !="." && $val !=".."){
  610. //如果是目录则递归子目录,继续操作
  611. if(is_dir($path.$val)){
  612. //子目录中操作删除文件夹和文件
  613. deldir($path.$val.'/');
  614. }else{
  615. //如果是文件直接删除
  616. unlink($path.$val);
  617. }
  618. }
  619. }
  620. }
  621. }
  622. //删除目录
  623. return rmdir($path);
  624. }
  625. /**
  626. * @param string $AddrJson
  627. */
  628. function GetAddr($AddrJson=""){
  629. if($AddrJson==""){
  630. return '';
  631. }
  632. $adr = json_decode($AddrJson,true);
  633. if(!is_array($adr)){
  634. return '';
  635. }
  636. $addr='';
  637. if(isset($adr['provice_code'])&&$adr['provice_code']!=''){
  638. $provice = Db::name("province")->where(["province_code"=>$adr['provice_code']])->find();
  639. $addr.=isset($provice['name']) ? $provice['name']:"";
  640. }
  641. if(isset($adr['city_code'])&&$adr['city_code']!=''){
  642. $city = Db::name("city")->where(["city_code"=>$adr['city_code']])->find();
  643. $addr.=isset($city['name']) ? $city['name']:"";
  644. }
  645. if(isset($adr['area_code'])&&$adr['area_code']!=''){
  646. $area = Db::name("area")->where(["area_code"=>$adr['area_code']])->find();
  647. $addr.=isset($area['name']) ? $area['name']:"";
  648. }
  649. return $addr;
  650. }
  651. /**
  652. * POST 请求
  653. * @param string $url
  654. * @param array $param
  655. * @param boolean $post_file 是否文件上传
  656. * @return string content
  657. */
  658. function post($url,$data,$header=[])
  659. {
  660. //对空格进行转义
  661. $url = str_replace(' ','+',$url);
  662. $ch = curl_init();
  663. //设置选项,包括URL
  664. curl_setopt($ch, CURLOPT_URL, "$url");
  665. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  666. curl_setopt($ch, CURLOPT_HEADER, 0);
  667. curl_setopt($ch,CURLOPT_TIMEOUT,3); //定义超时3秒钟
  668. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  669. // POST数据
  670. // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  671. curl_setopt($ch, CURLOPT_POST, 1);
  672. // 把post的变量加上
  673. curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //所需传的数组用http_bulid_query()函数处理一下,就ok了
  674. curl_setopt($ch, CURLOPT_HEADER, true);
  675. //执行并获取url地址的内容
  676. $output = curl_exec($ch);
  677. $errorCode = curl_errno($ch);
  678. //释放curl句柄
  679. $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  680. // 根据头大小去获取头信息内容
  681. $header = substr($output, 0, $headerSize);
  682. curl_close($ch);
  683. if(0 !== $errorCode) {
  684. return false;
  685. }
  686. return $header;
  687. }
  688. function post2($url,$data,$header=[])
  689. {
  690. //对空格进行转义
  691. $url = str_replace(' ','+',$url);
  692. $ch = curl_init();
  693. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  694. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  695. //设置选项,包括URL
  696. curl_setopt($ch, CURLOPT_URL, "$url");
  697. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  698. curl_setopt($ch, CURLOPT_HEADER, 0);
  699. // POST数据
  700. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  701. curl_setopt($ch, CURLOPT_POST, 1);
  702. // 把post的变量加上
  703. curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //所需传的数组用http_bulid_query()函数处理一下,就ok了
  704. $output = curl_exec($ch);
  705. $errorCode = curl_errno($ch);
  706. curl_close($ch);
  707. if(0 !== $errorCode) {
  708. return false;
  709. }
  710. return $output;
  711. }
  712. function GoldPrice($data,$cost_rate=0){
  713. $gold = Db::name("gold_price1")->where(["type"=>$data["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  714. ->find();
  715. // $rate = $data['open_fee']/$data['num'] + $data['weight']* $gold["price"] + $data['cost_fee']/(1-$cost_rate) *
  716. // $data['weight']+$data['packing_fee']+$data["mark_fee"]+$data["cert_fee"]+$data['nake_fee'];
  717. $saleprice = ($data['demo_fee']/$data['num']+$data['delivery_fee']+$data['open_fee']/$data['num']+ $data['weight']*
  718. $gold["price"] + $data['cost_fee'] *$data['weight'] + $data['packing_fee']+ $data["mark_fee"]+ $data["cert_fee"]+$data['nake_fee']) / (1 - $cost_rate);
  719. return $saleprice;
  720. }
  721. function GoodPrice($data,$cost_rate=0){
  722. $rate = ($data['open_fee']/$data['num']+ $data['cost_fee']+$data['packing_fee']+$data["mark_fee"]+$data["cert_fee"]+$data['nake_fee'])/(1-$cost_rate
  723. );
  724. return $rate;
  725. }
  726. function checkRole($roleid,$menu){
  727. $roleinfo = Db::name("role_action")->where([['role_id',"=",$roleid],["status","=",1]])->find();
  728. if($roleinfo['private_data']!=""){
  729. $private = explode(",",$roleinfo['private_data']);
  730. if(in_array($menu,$private)){
  731. return true;
  732. }
  733. }
  734. return false;
  735. }
  736. /**
  737. * 根据地址解析省市区
  738. * @param 详细地址,类似于'北京市顺义区xxx路xxx号'
  739. */
  740. if (!function_exists('get_address')) {
  741. function get_address(string $address = '')
  742. {
  743. preg_match('/(.*?(省|自治区|北京市|天津市|上海市|重庆市|澳门特别行政区|香港特别行政区))/', $address, $matches);
  744. if (count($matches) > 1) {
  745. $province = $matches[count($matches) - 2];
  746. $address = preg_replace('/(.*?(省|自治区|北京市|天津市|上海市|重庆市|澳门特别行政区|香港特别行政区))/', '', $address, 1);
  747. }
  748. preg_match('/(.*?(市|自治州|地区|区划|县))/', $address, $matches);
  749. if (count($matches) > 1) {
  750. $city = $matches[count($matches) - 2];
  751. $address = str_replace($city, '', $address);
  752. }
  753. preg_match('/(.*?(区|县|镇|乡|街道))/', $address, $matches);
  754. if (count($matches) > 1) {
  755. $area = $matches[count($matches) - 2];
  756. $address = str_replace($area, '', $address);
  757. }
  758. return [
  759. 'province' => isset($province) ? $province : '',
  760. 'city' => isset($city) ? $city : '',
  761. 'district' => isset($area) ? $area : '',
  762. "address" => $address
  763. ];
  764. }
  765. }
  766. /**
  767. * 批量生成多个文件excel,生成压缩包
  768. */
  769. if (!function_exists('excelSaveBatch')) {
  770. function excelSaveBatch(array $datas = [])
  771. {
  772. $urls = [];
  773. $dir = root_path() . 'public/storage/report/' . date("YmdHis") . "/";
  774. if (!is_dir($dir)) {
  775. mkdir($dir, 0777, true);
  776. }
  777. foreach ($datas as $item) {
  778. $objPHPExcel = new PHPExcel();
  779. $objPHPExcel->getProperties();
  780. $keyA = 0; // 设置表头
  781. foreach ($item['head'] as $v) {
  782. $colum = PHPExcel_Cell::stringFromColumnIndex($keyA);
  783. $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v);
  784. $keyA += 1;
  785. }
  786. $column = 2;
  787. $objActSheet = $objPHPExcel->getActiveSheet();
  788. foreach ($item['list'] as $key => $rows) { // 行写入
  789. $span = 0;
  790. foreach ($rows as $keyName => $value) { // 列写入
  791. //判断数据是否有数组,如果有数组,转换成字符串
  792. if (is_array($value)) {
  793. $value = implode("、", $value);
  794. }
  795. $objActSheet->setCellValue(PHPExcel_Cell::stringFromColumnIndex($span) . $column, $value);
  796. $span++;
  797. }
  798. $column++;
  799. }
  800. // var_dump($objActSheet->getActiveCell());
  801. $file = $item['filename'] . ".xls";
  802. //$fileName .= "_" . date("Y_m_d", Request()->instance()->time()) . ".xls";
  803. //$fileName = iconv("utf-8", "gb2312", $fileName); // 重命名表
  804. $objPHPExcel->setActiveSheetIndex(0); // 设置活动单指数到第一个表,所以Excel打开这是第一个表
  805. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  806. $objWriter->save($dir . $file); // 文件通过浏览器下载
  807. $url = $dir . $file;
  808. if (!file_exists($url)) {
  809. echo "文件生成失败";
  810. } else {
  811. $urls[] = $url;
  812. }
  813. }
  814. $saveDir = root_path() . "public/storage/zip/";
  815. if (!is_dir($saveDir)) {
  816. mkdir($saveDir, 0777, true);
  817. }
  818. $datetime = date("YmdHis");
  819. $file_dir = $saveDir . $datetime . ".zip";
  820. # 5.1 文件打包,提示:使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
  821. $zip = new \ZipArchive ();
  822. # 5.2 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip
  823. if ($zip->open($file_dir, \ZipArchive::OVERWRITE) !== true && $zip->open($file_dir, \ZipArchive::CREATE) !== true) echo '无法打开文件或者文件创建失败';
  824. # 5.3 批量写入压缩包
  825. // $zip->addEmptyDir($fileName);//往zip压缩包写入空目录
  826. foreach ($urls as $fileName) {
  827. // @$zip->addFile($fileName);
  828. @$zip->addFile($fileName, DIRECTORY_SEPARATOR.basename($fileName));
  829. }
  830. // @$zip->addFile($v['file_path'], 'resume'.DIRECTORY_SEPARATOR.basename($headername));
  831. # 5.4 关闭压缩包写入
  832. $zip->close();
  833. @deldir($dir);//删除已生成的文件及目录
  834. //6. 检查文件是否存在,并输出文件
  835. if (!file_exists($file_dir)) echo '压缩包文件不存在';
  836. ob_clean();
  837. flush();
  838. header("Cache-Control: max-age=0");
  839. header("Content-Description: File Transfer");
  840. header('Content-disposition: attachment; filename=' . basename($file_dir)); # 处理文件名
  841. header("Content-Type: application/octet-stream"); # 流文件输出
  842. header("Content-Transfer-Encoding: binary"); # 告诉浏览器,这是二进制文件
  843. // header('Content-Length: ' . filesize($file_dir)); # 告诉浏览器,文件大小
  844. // readfile($file_dir);//输出文件
  845. $res = read_big_file($file_dir);
  846. foreach ($res as $val) {
  847. echo $val;
  848. }
  849. @unlink($file_dir);
  850. exit();
  851. }
  852. }
  853. /**
  854. * 批量生成多个文件excel,生成压缩包,保存到本地,返回文件链接
  855. * datas 生成器
  856. * header array 头部字段
  857. * filename string 文件名
  858. */
  859. if (!function_exists('excelSaveFile')) {
  860. function excelSaveFile($datas, string $filename = '')
  861. {
  862. // $urls = [];
  863. $dir = root_path() . 'public/storage/report/' . date("YmdHis") . "/";
  864. if (!is_dir($dir)) mkdir($dir, 0777, true);
  865. // foreach ($datas as $item) {
  866. PHPExcel_Settings::setCacheStorageMethod();
  867. PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;//单元格缓存为MemoryGZip
  868. $objPHPExcel = new PHPExcel();
  869. $keyA = 0; // 设置表头
  870. $column = 2;
  871. $objActSheet = $objPHPExcel->getActiveSheet();
  872. foreach ($datas as $key => $rows) { // 行写入
  873. //第一行取key作表头
  874. if($key==0){
  875. $objPHPExcel->getProperties();
  876. foreach ($rows as $k=>$v) {
  877. $colum = PHPExcel_Cell::stringFromColumnIndex($keyA);
  878. $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $k);
  879. $keyA += 1;
  880. }
  881. }
  882. //写入列
  883. $span = 0;
  884. foreach ($rows as $keyName => $value) {
  885. //判断数据是否有数组,如果有数组,转换成字符串
  886. if (is_array($value)) $value = implode("、", $value);
  887. $objActSheet->setCellValue(PHPExcel_Cell::stringFromColumnIndex($span) . $column, $value);
  888. $span++;
  889. }
  890. $column++;
  891. }
  892. $file = $filename . ".xls";
  893. $objPHPExcel->setActiveSheetIndex(0);
  894. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  895. $objWriter->save($dir . $file); // 文件通过浏览器下载
  896. $url = $dir . $file;
  897. if (!file_exists($url)) throw new Exception('文件生成失败');
  898. $saveDir = root_path() . "public/storage/zip/" . date('Ymd') . '/';
  899. if (!is_dir($saveDir)) mkdir($saveDir, 0777, true);
  900. $file_dir = $saveDir . $filename . ".zip";
  901. # 5.1 文件打包,提示:使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
  902. $zip = new \ZipArchive ();
  903. # 5.2 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip
  904. if ($zip->open($file_dir, \ZipArchive::OVERWRITE) !== true && $zip->open($file_dir, \ZipArchive::CREATE) !== true) echo '无法打开文件或者文件创建失败';
  905. # 5.3 批量写入压缩包
  906. // $zip->addEmptyDir($fileName);//往zip压缩包写入空目录
  907. // foreach ($urls as $fileName) {
  908. @$zip->addFile($url, DIRECTORY_SEPARATOR . basename($url));
  909. // }
  910. // @$zip->addFile($v['file_path'], 'resume'.DIRECTORY_SEPARATOR.basename($headername));
  911. # 5.4 关闭压缩包写入
  912. $zip->close();
  913. @deldir($dir);//删除已生成的文件及目录
  914. //6. 检查文件是否存在,并输出文件
  915. if (!file_exists($file_dir)) throw new Exception('压缩包文件不存在');
  916. // return $file_dir;
  917. return str_replace(root_path() . "public/", '', $file_dir);
  918. }
  919. }
  920. //通过快递网的api获取物流信息
  921. if (!function_exists('get_logistics_information')) {
  922. function get_logistics_information(string $post_code = '', string $phone = '')
  923. {
  924. if ($post_code == '') throw new Exception('快递单号不能为空');
  925. $signer = new \app\admin\common\HuaweiSigner();
  926. //设置相关参数
  927. $signer->Key = '1b4cfe41d72d4fbdb6778a5e0193c4b5';
  928. $signer->Secret = '0fd04c5d5287424eb0d25f8f620aeb78';
  929. $req = new \app\admin\common\HuaweiRequest('GET', 'http://kuaidi.apistore.huaweicloud.com/kuaidiinfo?nu=' . $post_code . '&phone=' . $phone);
  930. $req->headers = array(
  931. 'content-type' => 'application/json',
  932. 'x-stage' => 'RELEASE',
  933. );
  934. $req->body = '';//如果是post/put请求的话,要往请求体中添加内容
  935. $curl = $signer->Sign($req);
  936. $response = curl_exec($curl);
  937. $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  938. $curl_error = curl_error($curl);
  939. curl_close($curl);
  940. if ($status == 200) return json_decode($response, true);
  941. else throw new Exception('请求失败:' . $curl_error);
  942. }
  943. }
  944. //获取三级架构
  945. if (!function_exists('get_top_customer_org')) {
  946. function get_top_customer_org($var, $data = [])
  947. {
  948. $str = Db::name('customer_org1')
  949. ->field('id,name,pid,level')
  950. ->where(['id' => $var])
  951. ->find();
  952. if ($str == false) {
  953. return [];
  954. }
  955. $vmn = [];
  956. $vmn['id'] = $str['id'];
  957. $vmn['name'] = $str['name'];
  958. $vmn['level'] = $str['level'];
  959. array_unshift($data, $vmn);
  960. // $var['id']=made();
  961. if ($str['pid'] == 0) {
  962. // krsort($data);
  963. return $data;
  964. } else {
  965. return get_top_customer_org($str['pid'], $data);
  966. }
  967. }
  968. }
  969. //根据某个关键字匹配所有子级部门及用户
  970. /**
  971. * $company_name string 部门名称
  972. * $off bool 是否查询离职人员,默认不查询
  973. */
  974. if (!function_exists('get_company_item_user_by_name')) {
  975. function get_company_item_user_by_name(string $company_name = '', bool $off = false)
  976. {
  977. $data = [];
  978. //查询符合条件的部门id
  979. $company_ids = Db::name("company_item")
  980. ->field('id,level')
  981. ->where(['is_del' => 0])
  982. ->whereLike('name', '%' . $company_name . '%')
  983. ->select()
  984. ->toArray();
  985. if (!empty($company_ids)) {
  986. $level_temp = $company_ids[0]['level'] + 1;
  987. $company_ids = array_column($company_ids, 'id');
  988. for ($level = $level_temp; $level > 0; $level++) {
  989. if (!empty($company_ids)) {
  990. //根据部门id找人
  991. $uids = Db::name('depart_user')
  992. ->where(['is_del' => 0])
  993. ->order('uid')
  994. ->whereIn('itemid', $company_ids);
  995. if (!$off) $uids->where('status', 1);
  996. $uids = $uids->column('uid');
  997. $data = array_unique(array_merge($data, $uids));
  998. $company_ids = Db::name("company_item")
  999. ->where(['is_del' => 0, 'level' => $level])
  1000. ->whereIn('pid', $company_ids)
  1001. ->column('id');
  1002. } else break;
  1003. }
  1004. }
  1005. return $data;
  1006. }
  1007. }
  1008. //获取某个用户所属部门名称
  1009. //$uid int 用户id
  1010. //$cache bool 是否启用缓存,(默认启用,不启用的话直接从数据库查)
  1011. //$get_tops bool 是否获取多级部门,例如 万宇恒通/采购部/仓储物流,默认不获取
  1012. if (!function_exists('get_company_name_by_uid')) {
  1013. function get_company_name_by_uid(int $uid = 0, bool $cache = true, bool $get_tops = false)
  1014. {
  1015. $rs = '';
  1016. $key = 'get_company_name_by_uid_' . $uid.'_'.$get_tops;
  1017. if ($cache) $rs = \think\facade\Cache::get($key);
  1018. if (empty($rs)) {
  1019. $itemid = Db::name('depart_user')->where(['is_del' => 0, 'uid' => $uid])->value('itemid', 0);
  1020. if ($get_tops) $rs = implode('/', array_column(GetPart($itemid), 'name'));
  1021. else $rs = Db::name('company_item')->where(['is_del' => 0, 'id' => $itemid])->value('name');
  1022. \think\facade\Cache::set($key, $rs, 3600);
  1023. }
  1024. return $rs;
  1025. }
  1026. }
  1027. //返回json格式的响应信息,方便中间件记录,目前在abutmenu应用中有用到
  1028. if (!function_exists('json_show')) {
  1029. function json_show(int $code = 0, string $message = '请求成功', array $data = [])
  1030. {
  1031. return json(['code' => $code, 'message' => $message, 'data' => $data]);
  1032. }
  1033. }
  1034. //获取加密后的密码密文
  1035. /**
  1036. * @param $password string 密码明文
  1037. * @param $salt string 盐值(不传的话随机生成一个)
  1038. */
  1039. if (!function_exists('get_encryption_password')) {
  1040. function get_encryption_password(string $password = '',string $salt=''):array
  1041. {
  1042. if($salt=='') $salt = Str::random(mt_rand(10, 30), -1);
  1043. return [
  1044. 'password' => md5($salt . $password . $salt . $salt),
  1045. 'salt' => $salt
  1046. ];
  1047. }
  1048. }
  1049. //检查供应商是否有开通账号
  1050. if (!function_exists('checkHasAccountBySupplierNos')) {
  1051. function checkHasAccountBySupplierNos(array $supplierNo = []): array
  1052. {
  1053. return \app\abutment\model\SupplierRelationUser::where('is_del', \app\abutment\model\SupplierUser::$is_del_normal)
  1054. ->whereIn('supplierNo', $supplierNo)
  1055. ->where('status', \app\abutment\model\SupplierUser::$status_normal)
  1056. ->column('uid','supplierNo');
  1057. }
  1058. }
  1059. //获取当前操作人(待办列表)
  1060. if (!function_exists('get_handle_user_list')) {
  1061. function get_handle_user_list(int $action_process_id = 0, int $holder_id = 0, string $api_url = '')
  1062. {
  1063. //筛选符合流程权限的角色id集合
  1064. $roleids = Db::name('role_process')
  1065. ->where('is_del', 0)
  1066. ->where('role_id', '<>', 1)//排除超级管理员
  1067. ->whereFindInSet('action_data', $action_process_id)
  1068. ->field('role_id')
  1069. ->buildSql();
  1070. //根据角色id筛选用户id
  1071. $data = Db::name('user_role')
  1072. ->where(['is_del' => 0, 'status' => 1])
  1073. ->where('roleid IN ' . $roleids)
  1074. ->column('uid', []);
  1075. //根据菜单筛选符合条件的共享数据
  1076. //当前请求的接口地址
  1077. if ($api_url == '') $api_url = app('http')->getName() . '/' . request()->pathinfo();
  1078. $menu_id = Db::name('admin_menu')
  1079. ->where(['is_del' => 0, 'menu_api' => $api_url])
  1080. ->value('id', 0);
  1081. if ($menu_id) {
  1082. //共享规则
  1083. $share = Db::name('role_share')
  1084. ->field('id,to_user,to_group')
  1085. ->where([
  1086. 'share_user' => $holder_id,
  1087. 'is_del' => 0,
  1088. 'status' => 1,
  1089. ])
  1090. ->whereFindInSet('action_collect', $menu_id)
  1091. ->cursor();
  1092. foreach ($share as $s) {
  1093. if ($s['to_user']) $data[] = [$s['to_user']];
  1094. elseif ($s['to_group']) {
  1095. $group_user = Db::name('role_group')
  1096. ->where([
  1097. 'id' => $s['to_group'],
  1098. 'is_del' => 0,
  1099. 'status' => 1,
  1100. ])->value('group_user');
  1101. $data = array_merge($data, explode(',', $group_user));
  1102. }
  1103. }
  1104. }
  1105. sort($data);
  1106. $data = array_unique($data);
  1107. return $data;
  1108. }
  1109. }