|
@@ -5,6 +5,9 @@ |
|
@@ -5,6 +5,9 @@ |
5
|
use Symfony\Component\VarExporter\VarExporter;
|
5
|
use Symfony\Component\VarExporter\VarExporter;
|
6
|
use think\exception\HttpResponseException;
|
6
|
use think\exception\HttpResponseException;
|
7
|
use think\Response;
|
7
|
use think\Response;
|
|
|
8
|
+use think\Db;
|
|
|
9
|
+
|
|
|
10
|
+error_reporting(E_ERROR | E_WARNING | E_PARSE);
|
8
|
|
11
|
|
9
|
if (!function_exists('__')) {
|
12
|
if (!function_exists('__')) {
|
10
|
|
13
|
|
|
@@ -512,3 +515,1752 @@ EOT; |
|
@@ -512,3 +515,1752 @@ EOT; |
512
|
return $icon;
|
515
|
return $icon;
|
513
|
}
|
516
|
}
|
514
|
}
|
517
|
}
|
|
|
518
|
+
|
|
|
519
|
+
|
|
|
520
|
+if (!function_exists('array_callback')) {
|
|
|
521
|
+ /**
|
|
|
522
|
+ * 20190729 kevin
|
|
|
523
|
+ * 规范数据返回函数
|
|
|
524
|
+ * @param unknown $state
|
|
|
525
|
+ * @param unknown $msg
|
|
|
526
|
+ * @param unknown $data
|
|
|
527
|
+ * @return multitype:unknown
|
|
|
528
|
+ */
|
|
|
529
|
+ function array_callback($state = true, $msg = '', $data = array())
|
|
|
530
|
+ {
|
|
|
531
|
+ return array('state' => $state, 'msg' => $msg, 'data' => $data);
|
|
|
532
|
+ }
|
|
|
533
|
+}
|
|
|
534
|
+
|
|
|
535
|
+if (!function_exists('send_post')) {
|
|
|
536
|
+//请求函数
|
|
|
537
|
+ function send_post($url, $post_data = [], $method = 'POST')
|
|
|
538
|
+ {
|
|
|
539
|
+ $postdata = http_build_query($post_data);
|
|
|
540
|
+ $options = array(
|
|
|
541
|
+ 'http' => array(
|
|
|
542
|
+ 'method' => $method, //or GET
|
|
|
543
|
+ 'header' => 'Content-type:application/x-www-form-urlencoded',
|
|
|
544
|
+ 'content' => $postdata,
|
|
|
545
|
+ 'timeout' => 15 * 60 // 超时时间(单位:s)
|
|
|
546
|
+ )
|
|
|
547
|
+ );
|
|
|
548
|
+ $context = stream_context_create($options);
|
|
|
549
|
+ $result = file_get_contents($url, false, $context);
|
|
|
550
|
+ return $result;
|
|
|
551
|
+ }
|
|
|
552
|
+}
|
|
|
553
|
+
|
|
|
554
|
+if (!function_exists('corp_admin_id')) {
|
|
|
555
|
+ /**
|
|
|
556
|
+ * 获取企业所属admin_id
|
|
|
557
|
+ */
|
|
|
558
|
+ function corp_admin_id($corp_id = null)
|
|
|
559
|
+ {
|
|
|
560
|
+ $admin_id = 1;
|
|
|
561
|
+ if (!empty($corp_id)) {
|
|
|
562
|
+ $admin_id = \think\Db::name("corp")->where("id", $corp_id)->value("admin_id");
|
|
|
563
|
+ }
|
|
|
564
|
+ $admin_id = $admin_id > 0 ? $admin_id : 1;
|
|
|
565
|
+ return $admin_id;
|
|
|
566
|
+ }
|
|
|
567
|
+}
|
|
|
568
|
+
|
|
|
569
|
+if (!function_exists('group_id_exchange_admin_id')) {
|
|
|
570
|
+ /**
|
|
|
571
|
+ * 根据角色组获取某个管理员id
|
|
|
572
|
+ */
|
|
|
573
|
+ function group_id_exchange_admin_id($group_id = null)
|
|
|
574
|
+ {
|
|
|
575
|
+ $admin_id = 1;
|
|
|
576
|
+ if (!empty($group_id)) {
|
|
|
577
|
+ $admin_id = \think\Db::name("auth_group_access")->where("group_id", $group_id)->value("uid");
|
|
|
578
|
+ }
|
|
|
579
|
+ $admin_id = $admin_id > 0 ? $admin_id : 1;
|
|
|
580
|
+ return $admin_id;
|
|
|
581
|
+ }
|
|
|
582
|
+}
|
|
|
583
|
+
|
|
|
584
|
+if (!function_exists('get_groupinfo_by_admin_id')) {
|
|
|
585
|
+ /**
|
|
|
586
|
+ * 根据admin_id获取角色组信息
|
|
|
587
|
+ */
|
|
|
588
|
+ function get_groupinfo_by_admin_id($admin_id = null)
|
|
|
589
|
+ {
|
|
|
590
|
+ $group_info = [
|
|
|
591
|
+ "id" => null,
|
|
|
592
|
+ "name" => ""
|
|
|
593
|
+ ];
|
|
|
594
|
+ if (!empty($admin_id)) {
|
|
|
595
|
+ $group_info = \think\Db::name("auth_group_access")->alias("a")
|
|
|
596
|
+ ->join("auth_group g", "g.id=a.group_id")
|
|
|
597
|
+ ->field("g.id,g.name")
|
|
|
598
|
+ ->where("a.uid", $admin_id)->find();
|
|
|
599
|
+ }
|
|
|
600
|
+ return $group_info;
|
|
|
601
|
+
|
|
|
602
|
+ }
|
|
|
603
|
+}
|
|
|
604
|
+
|
|
|
605
|
+if (!function_exists('verify_corp_admin_id')) {
|
|
|
606
|
+ /**
|
|
|
607
|
+ * 验证是否绑定过角色组(常规管理员)
|
|
|
608
|
+ */
|
|
|
609
|
+ function verify_corp_admin_id($corp_id = null)
|
|
|
610
|
+ {
|
|
|
611
|
+ $check = false;
|
|
|
612
|
+ if (!empty($corp_id)) {
|
|
|
613
|
+ $admin_id = \think\Db::name("corp")->where("id", $corp_id)->value("admin_id");
|
|
|
614
|
+ if ($admin_id > 1) {
|
|
|
615
|
+ //绑定过其他管理员
|
|
|
616
|
+ $exsit = \think\Db::name("admin")->where("id", $admin_id)->find();
|
|
|
617
|
+ if ($exsit) {
|
|
|
618
|
+ $check = true;
|
|
|
619
|
+ }
|
|
|
620
|
+ }
|
|
|
621
|
+ }
|
|
|
622
|
+ return $check;
|
|
|
623
|
+ }
|
|
|
624
|
+}
|
|
|
625
|
+
|
|
|
626
|
+if (!function_exists('insert_openid_info')) {
|
|
|
627
|
+ /**
|
|
|
628
|
+ * 将授权用户信息保存起来
|
|
|
629
|
+ */
|
|
|
630
|
+ function insert_openid_info($data)
|
|
|
631
|
+ {
|
|
|
632
|
+ $data['upt_time'] = time();
|
|
|
633
|
+ $res = \think\Db::name("openid_info")->where("openid", $data['openid'])->find();
|
|
|
634
|
+// file_put_contents("ccc.txt", date("Y-m-d H:i:s") . json_encode($data) . PHP_EOL, FILE_APPEND);
|
|
|
635
|
+ if (!empty($res)) {
|
|
|
636
|
+ \think\Db::name("openid_info")->where("openid", $data['openid'])->update($data);
|
|
|
637
|
+ } else {
|
|
|
638
|
+ \think\Db::name("openid_info")->insertGetId($data);
|
|
|
639
|
+ }
|
|
|
640
|
+ return true;
|
|
|
641
|
+ }
|
|
|
642
|
+}
|
|
|
643
|
+
|
|
|
644
|
+if (!function_exists('http_request')) {
|
|
|
645
|
+// curl请求
|
|
|
646
|
+ function http_request($url, $timeout = 30, $header = array())
|
|
|
647
|
+ {
|
|
|
648
|
+ if (!function_exists('curl_init')) {
|
|
|
649
|
+ throw new Exception('server not install curl');
|
|
|
650
|
+ }
|
|
|
651
|
+ $ch = curl_init();
|
|
|
652
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
653
|
+ curl_setopt($ch, CURLOPT_HEADER, true);
|
|
|
654
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
655
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
|
656
|
+ if (!empty($header)) {
|
|
|
657
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
|
658
|
+ }
|
|
|
659
|
+ $data = curl_exec($ch);
|
|
|
660
|
+ list($header, $data) = explode("\r\n\r\n", $data);
|
|
|
661
|
+ $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
662
|
+ if ($http_code == 301 || $http_code == 302) {
|
|
|
663
|
+ $matches = array();
|
|
|
664
|
+ preg_match('/Location:(.*?)\n/', $header, $matches);
|
|
|
665
|
+ $url = trim(array_pop($matches));
|
|
|
666
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
667
|
+ curl_setopt($ch, CURLOPT_HEADER, false);
|
|
|
668
|
+ $data = curl_exec($ch);
|
|
|
669
|
+ }
|
|
|
670
|
+
|
|
|
671
|
+ if ($data == false) {
|
|
|
672
|
+ curl_close($ch);
|
|
|
673
|
+ }
|
|
|
674
|
+ @curl_close($ch);
|
|
|
675
|
+
|
|
|
676
|
+ return $data;
|
|
|
677
|
+ }
|
|
|
678
|
+}
|
|
|
679
|
+//加密解密函数
|
|
|
680
|
+if (!function_exists('tyssl_decode')) {
|
|
|
681
|
+ /**
|
|
|
682
|
+ * 解密函数
|
|
|
683
|
+ * @param string $secretdata
|
|
|
684
|
+ * @return string
|
|
|
685
|
+ */
|
|
|
686
|
+ function tyssl_decode($secretdata)
|
|
|
687
|
+ {
|
|
|
688
|
+ $cryptkey = hash('sha256', 'e09dor37csce2', true);
|
|
|
689
|
+ $password = "h78c4ea56z0sgw9e";
|
|
|
690
|
+ return openssl_decrypt($secretdata, 'aes-256-cbc', $cryptkey, false, $password);
|
|
|
691
|
+ }
|
|
|
692
|
+}
|
|
|
693
|
+if (!function_exists('tyssl_encode')) {
|
|
|
694
|
+ /**
|
|
|
695
|
+ * 加密函数
|
|
|
696
|
+ * @param string $secretdata
|
|
|
697
|
+ * @return string
|
|
|
698
|
+ */
|
|
|
699
|
+ function tyssl_encode($secretdata)
|
|
|
700
|
+ {
|
|
|
701
|
+ $cryptkey = hash('sha256', 'e09dor37csce2', true);
|
|
|
702
|
+ $password = "h78c4ea56z0sgw9e";
|
|
|
703
|
+ return openssl_encrypt($secretdata, 'aes-256-cbc', $cryptkey, false, $password);
|
|
|
704
|
+ }
|
|
|
705
|
+}
|
|
|
706
|
+
|
|
|
707
|
+if (!function_exists('grid_level_pid_zero')) {
|
|
|
708
|
+ /**
|
|
|
709
|
+ * 无限级分类 获取顶级分类ID
|
|
|
710
|
+ */
|
|
|
711
|
+ function grid_level_pid_zero($id)
|
|
|
712
|
+ {
|
|
|
713
|
+ $arr = \think\Db::name("grid_level")->order("pid asc,id asc")->column("id,pid");
|
|
|
714
|
+ while ($arr[$id]) {
|
|
|
715
|
+ $id = $arr[$id];
|
|
|
716
|
+ }
|
|
|
717
|
+ return $id;
|
|
|
718
|
+ }
|
|
|
719
|
+}
|
|
|
720
|
+
|
|
|
721
|
+if (!function_exists('uuid')) {
|
|
|
722
|
+ function uuid($num = 32)
|
|
|
723
|
+ {
|
|
|
724
|
+ if ($num == 16) {
|
|
|
725
|
+ return strtoupper(substr(md5(uniqid(mt_rand(), 1)), 10, 16));
|
|
|
726
|
+ }
|
|
|
727
|
+ if (function_exists('com_create_guid')) {
|
|
|
728
|
+ return com_create_guid();
|
|
|
729
|
+ } else {
|
|
|
730
|
+ mt_srand(( double )microtime() * 10000); //optional for php 4.2.0 and up.随便数播种,4.2.0以后不需要了。
|
|
|
731
|
+ $charid = strtoupper(md5(uniqid(rand(), true))); //根据当前时间(微秒计)生成唯一id.
|
|
|
732
|
+ $uuid = substr($charid, 0, 8) . substr($charid, 8, 4) . substr($charid, 12, 4) . substr($charid, 16, 4) . substr($charid, 20, 12);
|
|
|
733
|
+ return $uuid;
|
|
|
734
|
+ }
|
|
|
735
|
+ }
|
|
|
736
|
+}
|
|
|
737
|
+
|
|
|
738
|
+if (!function_exists('suiji_num')) {
|
|
|
739
|
+ /**
|
|
|
740
|
+ * 生成一个16位随机数(可以自定义前缀)
|
|
|
741
|
+ */
|
|
|
742
|
+ function suiji_num($before)
|
|
|
743
|
+ {
|
|
|
744
|
+ return $before . substr(uuid(16), 0, 16 - strlen($before));
|
|
|
745
|
+ }
|
|
|
746
|
+}
|
|
|
747
|
+
|
|
|
748
|
+if (!function_exists('grid_level_has_child')) {
|
|
|
749
|
+ /**
|
|
|
750
|
+ * 查看当前网格层级是否还有子层级
|
|
|
751
|
+ */
|
|
|
752
|
+ function grid_level_has_child($grid_leve_id)
|
|
|
753
|
+ {
|
|
|
754
|
+ $count = \think\Db::name("grid_level")->where("pid", $grid_leve_id)->count();
|
|
|
755
|
+ if ($count) {
|
|
|
756
|
+ return true;
|
|
|
757
|
+ }
|
|
|
758
|
+ return false;
|
|
|
759
|
+ }
|
|
|
760
|
+}
|
|
|
761
|
+
|
|
|
762
|
+if (!function_exists('grid_level_bottom_id')) {
|
|
|
763
|
+ /**
|
|
|
764
|
+ * 查看城市/农村的最底层分类id
|
|
|
765
|
+ */
|
|
|
766
|
+ function grid_level_bottom_id($id)
|
|
|
767
|
+ {
|
|
|
768
|
+ $sid = \think\Db::name("grid_level")->where("pid", $id)->order("weigh desc,id desc")->value("id");
|
|
|
769
|
+ if (!empty($sid)) {
|
|
|
770
|
+ $id = grid_level_bottom_id($sid);
|
|
|
771
|
+ }
|
|
|
772
|
+ return $id;
|
|
|
773
|
+ }
|
|
|
774
|
+}
|
|
|
775
|
+
|
|
|
776
|
+if (!function_exists('grid_level_bottom_id_list')) {
|
|
|
777
|
+ /**
|
|
|
778
|
+ * 查看城市和农村的最底层id返回数组
|
|
|
779
|
+ */
|
|
|
780
|
+ function grid_level_bottom_id_list()
|
|
|
781
|
+ {
|
|
|
782
|
+ $arr = [];
|
|
|
783
|
+ $c_id = grid_level_bottom_id(1);//1城市
|
|
|
784
|
+ $n_id = grid_level_bottom_id(2);//2农村
|
|
|
785
|
+ if ($c_id) {
|
|
|
786
|
+ $arr[] = $c_id;
|
|
|
787
|
+ }
|
|
|
788
|
+ if ($n_id) {
|
|
|
789
|
+ $arr[] = $n_id;
|
|
|
790
|
+ }
|
|
|
791
|
+ return $arr;
|
|
|
792
|
+ }
|
|
|
793
|
+}
|
|
|
794
|
+
|
|
|
795
|
+if (!function_exists('grid_level_last_two_id_list')) {
|
|
|
796
|
+ /**
|
|
|
797
|
+ * 查看城市和农村的最底层id返回数组
|
|
|
798
|
+ */
|
|
|
799
|
+ function grid_level_last_two_id_list()
|
|
|
800
|
+ {
|
|
|
801
|
+ $arr = [];
|
|
|
802
|
+ $c_id = grid_level_bottom_id(1);//1城市
|
|
|
803
|
+ $n_id = grid_level_bottom_id(2);//2农村
|
|
|
804
|
+ if ($c_id) {
|
|
|
805
|
+ $arr[] = $c_id;
|
|
|
806
|
+ }
|
|
|
807
|
+ if ($n_id) {
|
|
|
808
|
+ $arr[] = $n_id;
|
|
|
809
|
+ }
|
|
|
810
|
+ $arr2 = [];
|
|
|
811
|
+ if (!empty($arr)) {
|
|
|
812
|
+ foreach ($arr as $k => $v) {
|
|
|
813
|
+ $arr2[] = $v;
|
|
|
814
|
+ $pid = \think\Db::name("grid_level")->where("id", $v)->value("pid");
|
|
|
815
|
+ if ($pid) {
|
|
|
816
|
+ $arr2[] = $pid;
|
|
|
817
|
+ }
|
|
|
818
|
+ }
|
|
|
819
|
+ }
|
|
|
820
|
+ return $arr2;
|
|
|
821
|
+ }
|
|
|
822
|
+}
|
|
|
823
|
+
|
|
|
824
|
+if (!function_exists('get_groupchat_ids_by_grid_infomation_id')) {
|
|
|
825
|
+ /**
|
|
|
826
|
+ * 查询某个网格及其子网格的客户群ids的一维数组
|
|
|
827
|
+ */
|
|
|
828
|
+ function get_groupchat_ids_by_grid_infomation_id($grid_infomation_id)
|
|
|
829
|
+ {
|
|
|
830
|
+ $data = [];
|
|
|
831
|
+ $where = [];
|
|
|
832
|
+ if (!empty($grid_infomation_id)) {
|
|
|
833
|
+ if ($grid_infomation_id == -1) {
|
|
|
834
|
+ //返回全部客户群
|
|
|
835
|
+ } else {
|
|
|
836
|
+ //获取下级所有子网格ID
|
|
|
837
|
+ $tree = \fast\Tree::instance();
|
|
|
838
|
+ $gridInfomationModel = new \app\admin\model\GridInfomation();
|
|
|
839
|
+ $tree->init(collection($gridInfomationModel->order('pid asc,id asc')->select())->toArray(), 'pid');
|
|
|
840
|
+ $grid_ids = $tree->getChildrenIds($grid_infomation_id, true);
|
|
|
841
|
+ if (!empty($grid_ids)) {
|
|
|
842
|
+ //查询网格点对应客户群ids
|
|
|
843
|
+ if (!empty($grid_ids)) {
|
|
|
844
|
+ $where["id"] = ["IN", $grid_ids];
|
|
|
845
|
+ }
|
|
|
846
|
+ }
|
|
|
847
|
+ }
|
|
|
848
|
+ $gird_infomation_list = \think\Db::name("grid_infomation")->where($where)->field("corp_groupchat_ids,corp_user_ids")->select();
|
|
|
849
|
+ if (!empty($gird_infomation_list)) {
|
|
|
850
|
+ foreach ($gird_infomation_list as $k => $v) {
|
|
|
851
|
+ if (!empty($v['corp_groupchat_ids'])) {
|
|
|
852
|
+ $corp_groupchat_ids_arr = explode(",", $v['corp_groupchat_ids']);
|
|
|
853
|
+ $data = array_merge($data, $corp_groupchat_ids_arr);
|
|
|
854
|
+ }
|
|
|
855
|
+ }
|
|
|
856
|
+ }
|
|
|
857
|
+ }
|
|
|
858
|
+ if (!empty($data)) {
|
|
|
859
|
+ //过滤掉相同客户群id
|
|
|
860
|
+ $data = array_unique($data);
|
|
|
861
|
+ }
|
|
|
862
|
+ return $data;
|
|
|
863
|
+ }
|
|
|
864
|
+}
|
|
|
865
|
+if (!function_exists('get_all_next_grid_infomation_ids')) {
|
|
|
866
|
+ /***
|
|
|
867
|
+ * 获得下级所有网格点id
|
|
|
868
|
+ */
|
|
|
869
|
+ function get_all_next_grid_infomation_ids($grid_infomation_id)
|
|
|
870
|
+ {
|
|
|
871
|
+ $grid_infomation = \think\Db::name("grid_infomation")->where("id", $grid_infomation_id)->find();
|
|
|
872
|
+ if (!empty($grid_infomation)) {
|
|
|
873
|
+ //获取下级所有子网格ID
|
|
|
874
|
+ $tree = \fast\Tree::instance();
|
|
|
875
|
+ $gridInfomationModel = new \app\admin\model\GridInfomation();
|
|
|
876
|
+ $tree->init(collection($gridInfomationModel->order('pid asc,id asc')->select())->toArray(), 'pid');
|
|
|
877
|
+ //$grid_ids包含网格所有等级的网格ids
|
|
|
878
|
+ $grid_ids = $tree->getChildrenIds($grid_infomation_id, true);
|
|
|
879
|
+ //获得网格点ids ,house_building_ids绑定了楼栋的
|
|
|
880
|
+ $where['id'] = ['in', $grid_ids];
|
|
|
881
|
+ $where['house_building_ids'] = ['>', '0'];
|
|
|
882
|
+ $list = \think\Db::name("grid_infomation")
|
|
|
883
|
+ ->where($where)
|
|
|
884
|
+ ->column('id');
|
|
|
885
|
+ return $list;
|
|
|
886
|
+ }
|
|
|
887
|
+ }
|
|
|
888
|
+}
|
|
|
889
|
+if (!function_exists('grid_infomation_relation')) {
|
|
|
890
|
+ /**
|
|
|
891
|
+ * 获取1.本网格、2.同级网格、3.本网格以及下级所有网格、4.同级网格以及下级所有网格 (多个用,隔开)
|
|
|
892
|
+ */
|
|
|
893
|
+ function grid_infomation_relation($grid_infomation_id, $type = 1)
|
|
|
894
|
+ {
|
|
|
895
|
+ // 新版本根据网格点找人(user_grid) 2022.05.27 kevin更新
|
|
|
896
|
+ $ids = "";
|
|
|
897
|
+ $where = [];
|
|
|
898
|
+ if ($type == 1) {
|
|
|
899
|
+ //本网格
|
|
|
900
|
+ $where["a.id"] = ["=", $grid_infomation_id];
|
|
|
901
|
+// $where["a.corp_groupchat_ids"] = ["neq", ""];//客户群不能为空
|
|
|
902
|
+ $id_arr = \think\Db::name("grid_infomation")
|
|
|
903
|
+ ->alias("a")
|
|
|
904
|
+ ->join("user_grid b", "a.id=b.grid_id")
|
|
|
905
|
+ ->where($where)
|
|
|
906
|
+ ->group("a.id")
|
|
|
907
|
+ ->column("a.id");
|
|
|
908
|
+ if (!empty($id_arr)) {
|
|
|
909
|
+ $ids = implode($id_arr, ",");
|
|
|
910
|
+ }
|
|
|
911
|
+ } elseif ($type == 2) {
|
|
|
912
|
+ //同级网格
|
|
|
913
|
+ $grid_infomation = \think\Db::name("grid_infomation")->where("id", $grid_infomation_id)->find();
|
|
|
914
|
+ if (!empty($grid_infomation)) {
|
|
|
915
|
+ $where["a.pid"] = ["=", $grid_infomation['pid']];
|
|
|
916
|
+ $where["a.corp_id"] = ["=", $grid_infomation['corp_id']];
|
|
|
917
|
+ $where["a.grid_level_id"] = ["=", $grid_infomation['grid_level_id']];
|
|
|
918
|
+// $where["a.corp_groupchat_ids"] = ["neq", ""];//客户群不能为空
|
|
|
919
|
+ $id_arr = \think\Db::name("grid_infomation")
|
|
|
920
|
+ ->alias("a")
|
|
|
921
|
+ ->join("user_grid b", "a.id=b.grid_id")
|
|
|
922
|
+ ->where($where)
|
|
|
923
|
+ ->group("a.id")
|
|
|
924
|
+ ->column("a.id");
|
|
|
925
|
+ if (!empty($id_arr)) {
|
|
|
926
|
+ $ids = implode($id_arr, ",");
|
|
|
927
|
+ }
|
|
|
928
|
+ }
|
|
|
929
|
+ } elseif ($type == 3) {
|
|
|
930
|
+ //本网格以及下级所有网格
|
|
|
931
|
+ $grid_infomation = \think\Db::name("grid_infomation")->where("id", $grid_infomation_id)->find();
|
|
|
932
|
+ if (!empty($grid_infomation)) {
|
|
|
933
|
+ //获取下级所有子网格ID
|
|
|
934
|
+ $tree = \fast\Tree::instance();
|
|
|
935
|
+ $gridInfomationModel = new \app\admin\model\GridInfomation();
|
|
|
936
|
+ $tree->init(collection($gridInfomationModel->order('pid asc,id asc')->select())->toArray(), 'pid');
|
|
|
937
|
+ $grid_ids = $tree->getChildrenIds($grid_infomation_id, true);
|
|
|
938
|
+ if (!empty($grid_ids)) {
|
|
|
939
|
+ $where["a.id"] = ["in", $grid_ids];
|
|
|
940
|
+// $where["a.corp_groupchat_ids"] = ["neq", ""];//客户群不能为空
|
|
|
941
|
+ $id_arr = \think\Db::name("grid_infomation")
|
|
|
942
|
+ ->alias("a")
|
|
|
943
|
+ ->join("user_grid b", "a.id=b.grid_id")
|
|
|
944
|
+ ->where($where)
|
|
|
945
|
+ ->group("a.id")
|
|
|
946
|
+ ->column("a.id");
|
|
|
947
|
+ if (!empty($id_arr)) {
|
|
|
948
|
+ $ids = implode($id_arr, ",");
|
|
|
949
|
+ }
|
|
|
950
|
+ }
|
|
|
951
|
+ }
|
|
|
952
|
+ } elseif ($type == 4) {
|
|
|
953
|
+ //同级网格以及下级所有网格
|
|
|
954
|
+ $grid_infomation = \think\Db::name("grid_infomation")->where("id", $grid_infomation_id)->find();
|
|
|
955
|
+ if (!empty($grid_infomation)) {
|
|
|
956
|
+ //第一步:先找到同级网格id
|
|
|
957
|
+ $where["pid"] = ["=", $grid_infomation['pid']];
|
|
|
958
|
+ $where["corp_id"] = ["=", $grid_infomation['corp_id']];
|
|
|
959
|
+ $where["grid_level_id"] = ["=", $grid_infomation['grid_level_id']];
|
|
|
960
|
+ $id_arr = \think\Db::name("grid_infomation")->where($where)->column("id");
|
|
|
961
|
+ if (!empty($id_arr)) {
|
|
|
962
|
+ $tree = \fast\Tree::instance();
|
|
|
963
|
+ $gridInfomationModel = new \app\admin\model\GridInfomation();
|
|
|
964
|
+ $tree->init(collection($gridInfomationModel->order('pid asc,id asc')->select())->toArray(), 'pid');
|
|
|
965
|
+ $grid_ids_arr = [];
|
|
|
966
|
+ foreach ($id_arr as $k => $v) {
|
|
|
967
|
+ $grid_ids = $tree->getChildrenIds($v, true);
|
|
|
968
|
+ $grid_ids_arr = array_merge($grid_ids_arr, $grid_ids);
|
|
|
969
|
+ $grid_ids_arr = array_unique($grid_ids_arr);
|
|
|
970
|
+ }
|
|
|
971
|
+ if (!empty($grid_ids_arr)) {
|
|
|
972
|
+ $where2 = [];
|
|
|
973
|
+ $where2["a.id"] = ["in", $grid_ids_arr];
|
|
|
974
|
+// $where2["corp_groupchat_ids"] = ["neq", ""];//客户群不能为空
|
|
|
975
|
+ $id_arr = \think\Db::name("grid_infomation")
|
|
|
976
|
+ ->alias("a")
|
|
|
977
|
+ ->join("user_grid b", "a.id=b.grid_id")
|
|
|
978
|
+ ->where($where2)
|
|
|
979
|
+ ->group("a.id")
|
|
|
980
|
+ ->column("a.id");
|
|
|
981
|
+ if (!empty($id_arr)) {
|
|
|
982
|
+ $ids = implode($id_arr, ",");
|
|
|
983
|
+ }
|
|
|
984
|
+ }
|
|
|
985
|
+ }
|
|
|
986
|
+ }
|
|
|
987
|
+ }
|
|
|
988
|
+ return $ids;
|
|
|
989
|
+
|
|
|
990
|
+ // // 老版本根据客户群找人
|
|
|
991
|
+// $ids = "";
|
|
|
992
|
+// $where = [];
|
|
|
993
|
+// if ($type == 1) {
|
|
|
994
|
+// //本网格
|
|
|
995
|
+// $where["id"] = ["=", $grid_infomation_id];
|
|
|
996
|
+// $where["corp_groupchat_ids"] = ["neq", ""];//客户群不能为空
|
|
|
997
|
+// $id_arr = \think\Db::name("grid_infomation")->where($where)->column("id");
|
|
|
998
|
+// if (!empty($id_arr)) {
|
|
|
999
|
+// $ids = implode($id_arr, ",");
|
|
|
1000
|
+// }
|
|
|
1001
|
+// } elseif ($type == 2) {
|
|
|
1002
|
+// //同级网格
|
|
|
1003
|
+// $grid_infomation = \think\Db::name("grid_infomation")->where("id", $grid_infomation_id)->find();
|
|
|
1004
|
+// if (!empty($grid_infomation)) {
|
|
|
1005
|
+// $where["pid"] = ["=", $grid_infomation['pid']];
|
|
|
1006
|
+// $where["corp_id"] = ["=", $grid_infomation['corp_id']];
|
|
|
1007
|
+// $where["grid_level_id"] = ["=", $grid_infomation['grid_level_id']];
|
|
|
1008
|
+// $where["corp_groupchat_ids"] = ["neq", ""];//客户群不能为空
|
|
|
1009
|
+// $id_arr = \think\Db::name("grid_infomation")->where($where)->column("id");
|
|
|
1010
|
+// if (!empty($id_arr)) {
|
|
|
1011
|
+// $ids = implode($id_arr, ",");
|
|
|
1012
|
+// }
|
|
|
1013
|
+// }
|
|
|
1014
|
+// } elseif ($type == 3) {
|
|
|
1015
|
+// //本网格以及下级所有网格
|
|
|
1016
|
+// $grid_infomation = \think\Db::name("grid_infomation")->where("id", $grid_infomation_id)->find();
|
|
|
1017
|
+// if (!empty($grid_infomation)) {
|
|
|
1018
|
+// //获取下级所有子网格ID
|
|
|
1019
|
+// $tree = \fast\Tree::instance();
|
|
|
1020
|
+// $gridInfomationModel = new \app\admin\model\GridInfomation();
|
|
|
1021
|
+// $tree->init(collection($gridInfomationModel->order('pid asc,id asc')->select())->toArray(), 'pid');
|
|
|
1022
|
+// $grid_ids = $tree->getChildrenIds($grid_infomation_id, true);
|
|
|
1023
|
+// if (!empty($grid_ids)) {
|
|
|
1024
|
+// $where["id"] = ["in", $grid_ids];
|
|
|
1025
|
+// $where["corp_groupchat_ids"] = ["neq", ""];//客户群不能为空
|
|
|
1026
|
+// $id_arr = \think\Db::name("grid_infomation")->where($where)->column("id");
|
|
|
1027
|
+// if (!empty($id_arr)) {
|
|
|
1028
|
+// $ids = implode($id_arr, ",");
|
|
|
1029
|
+// }
|
|
|
1030
|
+// }
|
|
|
1031
|
+// }
|
|
|
1032
|
+// } elseif ($type == 4) {
|
|
|
1033
|
+// //同级网格以及下级所有网格
|
|
|
1034
|
+// $grid_infomation = \think\Db::name("grid_infomation")->where("id", $grid_infomation_id)->find();
|
|
|
1035
|
+// if (!empty($grid_infomation)) {
|
|
|
1036
|
+// //第一步:先找到同级网格id
|
|
|
1037
|
+// $where["pid"] = ["=", $grid_infomation['pid']];
|
|
|
1038
|
+// $where["corp_id"] = ["=", $grid_infomation['corp_id']];
|
|
|
1039
|
+// $where["grid_level_id"] = ["=", $grid_infomation['grid_level_id']];
|
|
|
1040
|
+// $id_arr = \think\Db::name("grid_infomation")->where($where)->column("id");
|
|
|
1041
|
+// if (!empty($id_arr)) {
|
|
|
1042
|
+// $tree = \fast\Tree::instance();
|
|
|
1043
|
+// $gridInfomationModel = new \app\admin\model\GridInfomation();
|
|
|
1044
|
+// $tree->init(collection($gridInfomationModel->order('pid asc,id asc')->select())->toArray(), 'pid');
|
|
|
1045
|
+// $grid_ids_arr = [];
|
|
|
1046
|
+// foreach ($id_arr as $k => $v) {
|
|
|
1047
|
+// $grid_ids = $tree->getChildrenIds($v, true);
|
|
|
1048
|
+// $grid_ids_arr = array_merge($grid_ids_arr, $grid_ids);
|
|
|
1049
|
+// $grid_ids_arr = array_unique($grid_ids_arr);
|
|
|
1050
|
+// }
|
|
|
1051
|
+// if (!empty($grid_ids_arr)) {
|
|
|
1052
|
+// $where2 = [];
|
|
|
1053
|
+// $where2["id"] = ["in", $grid_ids_arr];
|
|
|
1054
|
+// $where2["corp_groupchat_ids"] = ["neq", ""];//客户群不能为空
|
|
|
1055
|
+// $id_arr = \think\Db::name("grid_infomation")->where($where2)->column("id");
|
|
|
1056
|
+// if (!empty($id_arr)) {
|
|
|
1057
|
+// $ids = implode($id_arr, ",");
|
|
|
1058
|
+// }
|
|
|
1059
|
+// }
|
|
|
1060
|
+// }
|
|
|
1061
|
+// }
|
|
|
1062
|
+// }
|
|
|
1063
|
+// return $ids;
|
|
|
1064
|
+ }
|
|
|
1065
|
+}
|
|
|
1066
|
+if (!function_exists('user_day_count')) {
|
|
|
1067
|
+ /***
|
|
|
1068
|
+ * 根据网格id更新当日网格中群众总数
|
|
|
1069
|
+ * type =1 添加人员 type=2 删除人员
|
|
|
1070
|
+ */
|
|
|
1071
|
+ function user_day_count($grid_id, $type = 1)
|
|
|
1072
|
+ {
|
|
|
1073
|
+ $nowday = date('Ymd', time());
|
|
|
1074
|
+ //网格点信息
|
|
|
1075
|
+ $info = \think\Db::name('grid_infomation')
|
|
|
1076
|
+ ->where(['id' => $grid_id])
|
|
|
1077
|
+ ->find();
|
|
|
1078
|
+ //判断今日数据是否存在
|
|
|
1079
|
+ $kcs = \think\Db::name('user_user_ctall')
|
|
|
1080
|
+ ->where(['nowday' => $nowday, 'grid_id' => $grid_id])
|
|
|
1081
|
+ ->find();
|
|
|
1082
|
+ if ($type == 1) {
|
|
|
1083
|
+ //添加人员
|
|
|
1084
|
+ if (empty($kcs)) {
|
|
|
1085
|
+ //保存数据
|
|
|
1086
|
+ $gduall['admin_id'] = corp_admin_id($info['corp_id']);
|
|
|
1087
|
+ $gduall['grid_id'] = $grid_id;
|
|
|
1088
|
+ $gduall['nowday'] = $nowday;
|
|
|
1089
|
+ $gduall['nums'] = 1;
|
|
|
1090
|
+ $gduall['createtime'] = time();
|
|
|
1091
|
+ $rs = \think\Db::name('user_user_ctall')->insertGetId($gduall);
|
|
|
1092
|
+ } else {
|
|
|
1093
|
+ //更新总数
|
|
|
1094
|
+ $gdupd['nums'] = $kcs['nums'] + 1;
|
|
|
1095
|
+ $gdupd['updatetime'] = time();
|
|
|
1096
|
+ $rs = \think\Db::name('user_user_ctall')
|
|
|
1097
|
+ ->where(['grid_id' => $grid_id, 'nowday' => $nowday])
|
|
|
1098
|
+ ->update($gdupd);
|
|
|
1099
|
+ }
|
|
|
1100
|
+ }
|
|
|
1101
|
+ if ($type == 2 && !empty($kcs)) {
|
|
|
1102
|
+ //删除人员更新数据
|
|
|
1103
|
+ //更新总数
|
|
|
1104
|
+ $userAll = $kcs['nums'] - 1;
|
|
|
1105
|
+ $gdupd['nums'] = $userAll > 0 ? $userAll : 0;
|
|
|
1106
|
+ $gdupd['updatetime'] = time();
|
|
|
1107
|
+ $rs = \think\Db::name('user_user_ctall')
|
|
|
1108
|
+ ->where(['grid_id' => $grid_id, 'nowday' => $nowday])
|
|
|
1109
|
+ ->update($gdupd);
|
|
|
1110
|
+ }
|
|
|
1111
|
+ }
|
|
|
1112
|
+}
|
|
|
1113
|
+if (!function_exists('sub_str')) {
|
|
|
1114
|
+ /**
|
|
|
1115
|
+ * 字符串截取
|
|
|
1116
|
+ *
|
|
|
1117
|
+ */
|
|
|
1118
|
+ function sub_str($str, $length = 0, $append = true)
|
|
|
1119
|
+ {
|
|
|
1120
|
+ $str = trim($str);
|
|
|
1121
|
+ $strlength = strlen($str);
|
|
|
1122
|
+
|
|
|
1123
|
+ if ($length == 0 || $length >= $strlength) {
|
|
|
1124
|
+ return $str; //截取长度等于0或大于等于本字符串的长度,返回字符串本身
|
|
|
1125
|
+ } elseif ($length < 0) //如果截取长度为负数
|
|
|
1126
|
+ {
|
|
|
1127
|
+ $length = $strlength + $length;//那么截取长度就等于字符串长度减去截取长度
|
|
|
1128
|
+ if ($length < 0) {
|
|
|
1129
|
+ $length = $strlength;//如果截取长度的绝对值大于字符串本身长度,则截取长度取字符串本身的长度
|
|
|
1130
|
+ }
|
|
|
1131
|
+ }
|
|
|
1132
|
+
|
|
|
1133
|
+ if (function_exists('mb_substr')) {
|
|
|
1134
|
+ $newstr = mb_substr($str, 0, $length, "utf-8");
|
|
|
1135
|
+ } elseif (function_exists('iconv_substr')) {
|
|
|
1136
|
+ $newstr = iconv_substr($str, 0, $length, "utf-8");
|
|
|
1137
|
+ } else {
|
|
|
1138
|
+ //$newstr = trim_right(substr($str, 0, $length));
|
|
|
1139
|
+ $newstr = substr($str, 0, $length);
|
|
|
1140
|
+ }
|
|
|
1141
|
+
|
|
|
1142
|
+ if ($append && $str != $newstr) {
|
|
|
1143
|
+ $newstr .= '...';
|
|
|
1144
|
+ }
|
|
|
1145
|
+
|
|
|
1146
|
+ return $newstr;
|
|
|
1147
|
+ }
|
|
|
1148
|
+}
|
|
|
1149
|
+
|
|
|
1150
|
+if (!function_exists('beingPushed')) {
|
|
|
1151
|
+ /**
|
|
|
1152
|
+ * 小程序模板推送选择类型
|
|
|
1153
|
+ * @param $type @模板类型
|
|
|
1154
|
+ * @param $openid @接收人ID
|
|
|
1155
|
+ * @param $page @跳转页面
|
|
|
1156
|
+ * @param $temp @具体提醒参数
|
|
|
1157
|
+ * @throws \think\Exception
|
|
|
1158
|
+ * @throws \think\exception\PDOException
|
|
|
1159
|
+ */
|
|
|
1160
|
+ function beingPushed($type, $openid, $page, $temp)
|
|
|
1161
|
+ {
|
|
|
1162
|
+ $data = [];
|
|
|
1163
|
+ $data['touser'] = $openid;
|
|
|
1164
|
+ //$data['page'] = $page;
|
|
|
1165
|
+ //模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
|
|
|
1166
|
+ switch ($type) {
|
|
|
1167
|
+ case 1:
|
|
|
1168
|
+ //待审批事项提醒(新版本的长期订阅)
|
|
|
1169
|
+ $data['template_id'] = "ws6bz6-WyHHA-upU2oRzc_C5toDUexe9ZicQ-ITtImA";
|
|
|
1170
|
+ $data['data'] = [
|
|
|
1171
|
+ "thing10" => [
|
|
|
1172
|
+ 'value' =>1,//审核状态(待处理)
|
|
|
1173
|
+ ],
|
|
|
1174
|
+ "thing12" => [
|
|
|
1175
|
+ 'value' => 2,//申请人(测试黄超)
|
|
|
1176
|
+ ],
|
|
|
1177
|
+
|
|
|
1178
|
+ "thing8" => [
|
|
|
1179
|
+ 'value' => 3,//原因(入州报备审核)
|
|
|
1180
|
+ ]
|
|
|
1181
|
+ ];
|
|
|
1182
|
+ break;
|
|
|
1183
|
+ case 2:
|
|
|
1184
|
+ //审核结果通知(新版本的长期订阅)
|
|
|
1185
|
+ $data['template_id'] = "Qt2xqfH8uQyTm1A0ReNxeybtAydAhfhi4HinnyB5f0s";
|
|
|
1186
|
+ $data['data'] = [
|
|
|
1187
|
+ "thing1" => [
|
|
|
1188
|
+ 'value' => $temp['value1'],//提醒内容(已审核)
|
|
|
1189
|
+ ],
|
|
|
1190
|
+// "name1" => [
|
|
|
1191
|
+// 'value' => $temp['value2'],//审核人
|
|
|
1192
|
+// ],
|
|
|
1193
|
+ "thing4" => [
|
|
|
1194
|
+ 'value' => $temp['value3'],//提示说明
|
|
|
1195
|
+ ]
|
|
|
1196
|
+ ];
|
|
|
1197
|
+ break;
|
|
|
1198
|
+ case 3:
|
|
|
1199
|
+ //待审批事项提醒(老版本的一次性订阅)
|
|
|
1200
|
+ $data['template_id'] = "vVOonN76AFjxgz77iG-hcWrH6HJ-vPGKyIyAK0VzPIk";
|
|
|
1201
|
+ $data['data'] = [
|
|
|
1202
|
+ "thing1" => [
|
|
|
1203
|
+ 'value' => $temp['value1'],//待办事项
|
|
|
1204
|
+ ],
|
|
|
1205
|
+ "thing4" => [
|
|
|
1206
|
+ 'value' => $temp['value2'],//流程状态
|
|
|
1207
|
+ ],
|
|
|
1208
|
+ "thing2" => [
|
|
|
1209
|
+ 'value' => $temp['value3'],//申请人
|
|
|
1210
|
+ ],
|
|
|
1211
|
+ "time3" => [
|
|
|
1212
|
+ 'value' => $temp['value4'],//申请时间
|
|
|
1213
|
+ ],
|
|
|
1214
|
+ "thing5" => [
|
|
|
1215
|
+ 'value' => $temp['value5'],//备注描述
|
|
|
1216
|
+ ]
|
|
|
1217
|
+ ];
|
|
|
1218
|
+ break;
|
|
|
1219
|
+ case 4:
|
|
|
1220
|
+ //审核结果通知(老版本的一次性订阅)
|
|
|
1221
|
+ $data['template_id'] = "yJRK0DZFuEPqaWwyS0DegT0r2p5be0bm2eE59oroGME";
|
|
|
1222
|
+ $data['data'] = [
|
|
|
1223
|
+ "phrase2" => [
|
|
|
1224
|
+ 'value' => $temp['value1'],//审核结果
|
|
|
1225
|
+ ],
|
|
|
1226
|
+ "name1" => [
|
|
|
1227
|
+ 'value' => $temp['value2'],//审核人
|
|
|
1228
|
+ ],
|
|
|
1229
|
+ "date4" => [
|
|
|
1230
|
+ 'value' => $temp['value3'],//审批时间
|
|
|
1231
|
+ ]
|
|
|
1232
|
+ ];
|
|
|
1233
|
+ break;
|
|
|
1234
|
+ case 5:
|
|
|
1235
|
+
|
|
|
1236
|
+ //预约结果通知
|
|
|
1237
|
+ $data['template_id'] = "WO4COOXP_-_mWCO8ck6FABISehjMiPrJrtLNOVHImVY";
|
|
|
1238
|
+ $data['data'] = [
|
|
|
1239
|
+ "thing1" => [
|
|
|
1240
|
+ 'value' => $temp['value1'],//消费代金券
|
|
|
1241
|
+ ],
|
|
|
1242
|
+ "phrase4" => [
|
|
|
1243
|
+ 'value' =>$temp['value2'],//券状态
|
|
|
1244
|
+ ],
|
|
|
1245
|
+ "time5" => [
|
|
|
1246
|
+ 'value' => $temp['value3'],//有效期
|
|
|
1247
|
+ ],
|
|
|
1248
|
+ "character_string7" => [
|
|
|
1249
|
+ 'value' => $temp['value4'],//优惠券号
|
|
|
1250
|
+
|
|
|
1251
|
+ ]
|
|
|
1252
|
+ ];
|
|
|
1253
|
+ break;
|
|
|
1254
|
+
|
|
|
1255
|
+ }
|
|
|
1256
|
+
|
|
|
1257
|
+ return sendSubscribeMessage($data);
|
|
|
1258
|
+ }
|
|
|
1259
|
+}
|
|
|
1260
|
+
|
|
|
1261
|
+if (!function_exists('sendSubscribeMessage')) {
|
|
|
1262
|
+ /**
|
|
|
1263
|
+ * 小程序订阅消息推送
|
|
|
1264
|
+ * @param $data
|
|
|
1265
|
+ * @throws \think\Exception
|
|
|
1266
|
+ * @throws \think\exception\PDOException
|
|
|
1267
|
+ */
|
|
|
1268
|
+ function sendSubscribeMessage($data)
|
|
|
1269
|
+ {
|
|
|
1270
|
+ //access_token
|
|
|
1271
|
+ $access_token = getAccessToken();
|
|
|
1272
|
+
|
|
|
1273
|
+ //请求url
|
|
|
1274
|
+ $url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=' . $access_token;
|
|
|
1275
|
+
|
|
|
1276
|
+ //file_put_contents('notify.txt',$data.PHP_EOL,FILE_APPEND);
|
|
|
1277
|
+ //跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
|
|
1278
|
+ $data['miniprogram_state'] = 'formal';
|
|
|
1279
|
+
|
|
|
1280
|
+ return curlPost($url, json_encode($data));
|
|
|
1281
|
+ }
|
|
|
1282
|
+}
|
|
|
1283
|
+
|
|
|
1284
|
+if (!function_exists('getAccessToken')) {
|
|
|
1285
|
+ /**
|
|
|
1286
|
+ * 获取access_token
|
|
|
1287
|
+ * @return mixed
|
|
|
1288
|
+ * @throws \think\Exception
|
|
|
1289
|
+ * @throws \think\exception\PDOException
|
|
|
1290
|
+ */
|
|
|
1291
|
+ function getAccessToken()
|
|
|
1292
|
+ {
|
|
|
1293
|
+ $wx_xcx_token = \think\Db::name("wechat_token")->where("type", "wx_xcx")->find();
|
|
|
1294
|
+ if (empty($wx_xcx_token) || empty($wx_xcx_token['access_token']) || $wx_xcx_token['over_time'] <= time()) {
|
|
|
1295
|
+ //微信小程序失效
|
|
|
1296
|
+ //当前时间戳
|
|
|
1297
|
+ $now_time = strtotime(date('Y-m-d H:i:s', time()));
|
|
|
1298
|
+
|
|
|
1299
|
+ //获取新的access_token
|
|
|
1300
|
+ $appid = "wx1c3cc5b4e2006be2";
|
|
|
1301
|
+ $secret = "643f1b6fdba08a773a7761a1a194a1ad";
|
|
|
1302
|
+ $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret;
|
|
|
1303
|
+ $res = json_decode(file_get_contents($url), true);
|
|
|
1304
|
+ print_r($res);return $res;
|
|
|
1305
|
+
|
|
|
1306
|
+ $access_token = $res['access_token'];
|
|
|
1307
|
+ if (!empty($access_token)) {
|
|
|
1308
|
+ $time = time();
|
|
|
1309
|
+ $update_data = [
|
|
|
1310
|
+ "access_token" => $access_token,
|
|
|
1311
|
+ "over_time" => $time + 7200,
|
|
|
1312
|
+ "type" => "wx_xcx",
|
|
|
1313
|
+ "updatetime" => $time
|
|
|
1314
|
+ ];
|
|
|
1315
|
+ if (!empty($wx_xcx_token)) {
|
|
|
1316
|
+ //更新
|
|
|
1317
|
+ \think\Db::name("wechat_token")->where("id", $wx_xcx_token['id'])->update($update_data);
|
|
|
1318
|
+ } else {
|
|
|
1319
|
+ //新增
|
|
|
1320
|
+ \think\Db::name("wechat_token")->insertGetId($update_data);
|
|
|
1321
|
+ }
|
|
|
1322
|
+ }
|
|
|
1323
|
+ } else {
|
|
|
1324
|
+ $access_token = $wx_xcx_token['access_token'];
|
|
|
1325
|
+ }
|
|
|
1326
|
+ return $access_token;
|
|
|
1327
|
+ }
|
|
|
1328
|
+}
|
|
|
1329
|
+
|
|
|
1330
|
+if (!function_exists('curlPost')) {
|
|
|
1331
|
+ /**
|
|
|
1332
|
+ * 发送post请求
|
|
|
1333
|
+ */
|
|
|
1334
|
+ function curlPost($url, $data)
|
|
|
1335
|
+ {
|
|
|
1336
|
+ $ch = curl_init();
|
|
|
1337
|
+ $params[CURLOPT_URL] = $url; //请求url地址
|
|
|
1338
|
+ $params[CURLOPT_HEADER] = FALSE; //是否返回响应头信息
|
|
|
1339
|
+ $params[CURLOPT_SSL_VERIFYPEER] = false;
|
|
|
1340
|
+ $params[CURLOPT_SSL_VERIFYHOST] = false;
|
|
|
1341
|
+ $params[CURLOPT_RETURNTRANSFER] = true; //是否将结果返回
|
|
|
1342
|
+ $params[CURLOPT_POST] = true;
|
|
|
1343
|
+ $params[CURLOPT_POSTFIELDS] = $data;
|
|
|
1344
|
+ curl_setopt_array($ch, $params); //传入curl参数
|
|
|
1345
|
+ $content = curl_exec($ch); //执行
|
|
|
1346
|
+// file_put_contents('notify.txt', $content . date('Y-m-d H:i:s', time()) . PHP_EOL, FILE_APPEND);
|
|
|
1347
|
+ curl_close($ch); //关闭连接
|
|
|
1348
|
+ return $content;
|
|
|
1349
|
+ }
|
|
|
1350
|
+}
|
|
|
1351
|
+
|
|
|
1352
|
+if (!function_exists('get_groupchat_member_list_by_groupchat_ids')) {
|
|
|
1353
|
+ /**
|
|
|
1354
|
+ * 根据客户群id找到外部联系人群成员unionid一维数组
|
|
|
1355
|
+ */
|
|
|
1356
|
+ function get_groupchat_member_list_by_groupchat_ids($ids)
|
|
|
1357
|
+ {
|
|
|
1358
|
+ $return_data = [];
|
|
|
1359
|
+ if (!empty($ids)) {
|
|
|
1360
|
+ $where = [];
|
|
|
1361
|
+ $where["g.id"] = ["in", $ids];
|
|
|
1362
|
+ $where["m.type"] = ["=", "2"];//成员类型 1企业成员 2外部联系人
|
|
|
1363
|
+ $where['m.unionid'] = ["neq", ""];//unionid不能为空
|
|
|
1364
|
+
|
|
|
1365
|
+ $return_data = \think\Db::name("corp_groupchat")->alias("g")
|
|
|
1366
|
+ ->join("corp_groupchat_member m", "m.corp_groupchat_id=g.id")
|
|
|
1367
|
+ ->where($where)
|
|
|
1368
|
+ ->group("m.unionid")
|
|
|
1369
|
+ ->column("unionid");
|
|
|
1370
|
+ }
|
|
|
1371
|
+
|
|
|
1372
|
+ return $return_data;
|
|
|
1373
|
+ }
|
|
|
1374
|
+}
|
|
|
1375
|
+
|
|
|
1376
|
+if (!function_exists('has_bind_grid_infomation_user_ids')) {
|
|
|
1377
|
+ /**
|
|
|
1378
|
+ * 查询哪些人员已经绑定过网格点了
|
|
|
1379
|
+ */
|
|
|
1380
|
+ function has_bind_grid_infomation_user_ids()
|
|
|
1381
|
+ {
|
|
|
1382
|
+ $return_data = [];
|
|
|
1383
|
+
|
|
|
1384
|
+ //网格管理员
|
|
|
1385
|
+ $where = [];
|
|
|
1386
|
+ $where["corp_user_mng_ids"] = ["neq", ""];
|
|
|
1387
|
+ $user_mng_ids = \think\Db::name("grid_infomation")->where($where)->where("corp_user_mng_ids", 'not null')->group("corp_user_mng_ids")->column("corp_user_mng_ids");
|
|
|
1388
|
+ if (!empty($user_mng_ids)) {
|
|
|
1389
|
+ foreach ($user_mng_ids as $k => $v) {
|
|
|
1390
|
+ //由于网格点可能有多个网格管理员,这里需要implode,然后去重后返回
|
|
|
1391
|
+ if (!empty($v)) {
|
|
|
1392
|
+ $id_arr = explode(",", $v);
|
|
|
1393
|
+ $return_data = array_merge($return_data, $id_arr);
|
|
|
1394
|
+ }
|
|
|
1395
|
+ }
|
|
|
1396
|
+ if (!empty($return_data)) {
|
|
|
1397
|
+ $return_data = array_unique($return_data);
|
|
|
1398
|
+ }
|
|
|
1399
|
+ }
|
|
|
1400
|
+
|
|
|
1401
|
+ //网格长
|
|
|
1402
|
+ $where2 = [];
|
|
|
1403
|
+ $where2["corp_user_ids"] = ["neq", ""];
|
|
|
1404
|
+ $user_ids = \think\Db::name("grid_infomation")->where($where2)->where("corp_user_ids", 'not null')->group("corp_user_ids")->column("corp_user_ids");
|
|
|
1405
|
+
|
|
|
1406
|
+ $return_data = array_merge($return_data, $user_ids);
|
|
|
1407
|
+
|
|
|
1408
|
+ $return_data = array_unique($return_data);
|
|
|
1409
|
+
|
|
|
1410
|
+
|
|
|
1411
|
+// $where = [];
|
|
|
1412
|
+// $where["corp_user_ids"] = ["neq", ""];
|
|
|
1413
|
+// $user_ids = \think\Db::name("grid_infomation")->where($where)->where("corp_user_ids", 'not null')->group("corp_user_ids")->column("corp_user_ids");
|
|
|
1414
|
+// if (!empty($user_ids)) {
|
|
|
1415
|
+// foreach ($user_ids as $k => $v) {
|
|
|
1416
|
+// //由于网格点可能有多个网格管理员,这里需要implode,然后去重后返回
|
|
|
1417
|
+// if (!empty($v)) {
|
|
|
1418
|
+// $id_arr = explode(",", $v);
|
|
|
1419
|
+// $return_data = array_merge($return_data, $id_arr);
|
|
|
1420
|
+// }
|
|
|
1421
|
+// }
|
|
|
1422
|
+// if (!empty($return_data)) {
|
|
|
1423
|
+// $return_data = array_unique($return_data);
|
|
|
1424
|
+// }
|
|
|
1425
|
+// }
|
|
|
1426
|
+ return $return_data;
|
|
|
1427
|
+ }
|
|
|
1428
|
+}
|
|
|
1429
|
+
|
|
|
1430
|
+if (!function_exists('has_bind_grid_infomation_groupchat_ids')) {
|
|
|
1431
|
+ /**
|
|
|
1432
|
+ * 查询哪些客户群已经绑定过网格点了
|
|
|
1433
|
+ */
|
|
|
1434
|
+ function has_bind_grid_infomation_groupchat_ids()
|
|
|
1435
|
+ {
|
|
|
1436
|
+ $return_data = [];
|
|
|
1437
|
+
|
|
|
1438
|
+ //楼栋
|
|
|
1439
|
+ $where = [];
|
|
|
1440
|
+ $where["corp_groupchat_ids"] = ["neq", ""];
|
|
|
1441
|
+ $corp_groupchat_ids = \think\Db::name("grid_infomation")->where($where)->where("corp_groupchat_ids", 'not null')->group("corp_groupchat_ids")->column("corp_groupchat_ids");
|
|
|
1442
|
+ if (!empty($corp_groupchat_ids)) {
|
|
|
1443
|
+ foreach ($corp_groupchat_ids as $k => $v) {
|
|
|
1444
|
+ //由于网格点可能有多个客户群,这里需要implode,然后去重后返回
|
|
|
1445
|
+ if (!empty($v)) {
|
|
|
1446
|
+ $id_arr = explode(",", $v);
|
|
|
1447
|
+ $return_data = array_merge($return_data, $id_arr);
|
|
|
1448
|
+ }
|
|
|
1449
|
+ }
|
|
|
1450
|
+ if (!empty($return_data)) {
|
|
|
1451
|
+ $return_data = array_unique($return_data);
|
|
|
1452
|
+ }
|
|
|
1453
|
+ }
|
|
|
1454
|
+ return $return_data;
|
|
|
1455
|
+ }
|
|
|
1456
|
+}
|
|
|
1457
|
+
|
|
|
1458
|
+if (!function_exists('has_bind_grid_infomation_building_ids')) {
|
|
|
1459
|
+ /**
|
|
|
1460
|
+ * 查询哪些楼栋已经绑定过网格点了
|
|
|
1461
|
+ */
|
|
|
1462
|
+ function has_bind_grid_infomation_building_ids()
|
|
|
1463
|
+ {
|
|
|
1464
|
+ $return_data = [];
|
|
|
1465
|
+
|
|
|
1466
|
+ //楼栋
|
|
|
1467
|
+ $where = [];
|
|
|
1468
|
+ $where["house_building_ids"] = ["neq", ""];
|
|
|
1469
|
+ $house_building_ids = \think\Db::name("grid_infomation")->where($where)->where("house_building_ids", 'not null')->group("house_building_ids")->column("house_building_ids");
|
|
|
1470
|
+ if (!empty($house_building_ids)) {
|
|
|
1471
|
+ foreach ($house_building_ids as $k => $v) {
|
|
|
1472
|
+ //由于网格点可能有多个楼栋,这里需要implode,然后去重后返回
|
|
|
1473
|
+ if (!empty($v)) {
|
|
|
1474
|
+ $id_arr = explode(",", $v);
|
|
|
1475
|
+ $return_data = array_merge($return_data, $id_arr);
|
|
|
1476
|
+ }
|
|
|
1477
|
+ }
|
|
|
1478
|
+ if (!empty($return_data)) {
|
|
|
1479
|
+ $return_data = array_unique($return_data);
|
|
|
1480
|
+ }
|
|
|
1481
|
+ }
|
|
|
1482
|
+ return $return_data;
|
|
|
1483
|
+ }
|
|
|
1484
|
+}
|
|
|
1485
|
+
|
|
|
1486
|
+if (!function_exists('getLatelyTime')) {
|
|
|
1487
|
+ /**
|
|
|
1488
|
+ * 获取最近一周,一个月,一年
|
|
|
1489
|
+ * */
|
|
|
1490
|
+ function getLatelyTime($type = '')
|
|
|
1491
|
+ {
|
|
|
1492
|
+ $now = time();
|
|
|
1493
|
+ $result = [];
|
|
|
1494
|
+
|
|
|
1495
|
+ if ($type == 'week5') {
|
|
|
1496
|
+ //最近一周
|
|
|
1497
|
+ for ($i = 0; $i < 5; $i++) {
|
|
|
1498
|
+ $result[] = date('Y-m-d ', strtotime('-' . $i . ' day', $now));
|
|
|
1499
|
+ }
|
|
|
1500
|
+ } elseif ($type == 'week') {
|
|
|
1501
|
+ //最近一周
|
|
|
1502
|
+ for ($i = 0; $i < 7; $i++) {
|
|
|
1503
|
+ $result[] = date('Ymd', strtotime('-' . $i . ' day', $now));
|
|
|
1504
|
+ }
|
|
|
1505
|
+ } elseif ($type == 'month') {
|
|
|
1506
|
+ //最近一个月
|
|
|
1507
|
+ for ($i = 0; $i < 30; $i++) {
|
|
|
1508
|
+ $result[] = date('Y-m-d', strtotime('-' . $i . ' day', $now));
|
|
|
1509
|
+ }
|
|
|
1510
|
+ } elseif ($type == 'year') {
|
|
|
1511
|
+ //最近一年
|
|
|
1512
|
+ for ($i = 0; $i < 12; $i++) {
|
|
|
1513
|
+ $result[] = date('Y-m', strtotime('-' . $i . ' month', $now));
|
|
|
1514
|
+ }
|
|
|
1515
|
+ }
|
|
|
1516
|
+ return $result;
|
|
|
1517
|
+ }
|
|
|
1518
|
+}
|
|
|
1519
|
+
|
|
|
1520
|
+if (!function_exists('grid_name_relation_by_id')) {
|
|
|
1521
|
+ /**
|
|
|
1522
|
+ * 根据某个网格点id返回所有上级的id(不含本身)
|
|
|
1523
|
+ */
|
|
|
1524
|
+ function grid_name_relation_by_id($id, $arr = [])
|
|
|
1525
|
+ {
|
|
|
1526
|
+
|
|
|
1527
|
+ $pid = \think\Db::name("grid_infomation")->where("id", $id)->value("pid");
|
|
|
1528
|
+ if ($pid > 0) {
|
|
|
1529
|
+ $arr = array_merge($arr, [$pid]);
|
|
|
1530
|
+ }
|
|
|
1531
|
+ return $pid > 0 ? grid_name_relation_by_id($pid, $arr) : $arr;
|
|
|
1532
|
+ }
|
|
|
1533
|
+}
|
|
|
1534
|
+
|
|
|
1535
|
+if (!function_exists('grid_name_relation_names')) {
|
|
|
1536
|
+ /**
|
|
|
1537
|
+ * 根据某个网格点id返回所有上级的名称 用"$str"拼接(不含本身)
|
|
|
1538
|
+ */
|
|
|
1539
|
+ function grid_name_relation_names($id, $str = "/")
|
|
|
1540
|
+ {
|
|
|
1541
|
+ $pid_arr = grid_name_relation_by_id($id);
|
|
|
1542
|
+ $grid_name_str = "";
|
|
|
1543
|
+ $pid_arr = array_reverse($pid_arr);//数组倒序
|
|
|
1544
|
+ if (!empty($pid_arr)) {
|
|
|
1545
|
+ $w1 = [];
|
|
|
1546
|
+ $w1["id"] = ["IN", $pid_arr];
|
|
|
1547
|
+ $grid_name_arr = \think\Db::name("grid_infomation")->where($w1)->order("grid_level_id asc")->column("name");
|
|
|
1548
|
+ $grid_name_str = implode($grid_name_arr, $str);
|
|
|
1549
|
+ }
|
|
|
1550
|
+ return $grid_name_str;
|
|
|
1551
|
+
|
|
|
1552
|
+ }
|
|
|
1553
|
+}
|
|
|
1554
|
+
|
|
|
1555
|
+if (!function_exists('building_relation_names')) {
|
|
|
1556
|
+ /**
|
|
|
1557
|
+ * 根据某个楼栋id返回所有上级的名称 用"$str"拼接(不含本身)
|
|
|
1558
|
+ */
|
|
|
1559
|
+ function building_relation_names($id, $str = "/")
|
|
|
1560
|
+ {
|
|
|
1561
|
+ $grid_name_str = "";
|
|
|
1562
|
+ $house_building = \think\Db::name("house_building")->where("id", $id)->find();
|
|
|
1563
|
+ $house_community = \think\Db::name("house_community")->where("id", $house_building['house_community_id'])->find();
|
|
|
1564
|
+ $grid_name_str = $house_community['community_name'] . $str . $house_building['building_name'];
|
|
|
1565
|
+ return $grid_name_str;
|
|
|
1566
|
+
|
|
|
1567
|
+ }
|
|
|
1568
|
+}
|
|
|
1569
|
+
|
|
|
1570
|
+if (!function_exists('create_unit_to_chinese')) {
|
|
|
1571
|
+ /**
|
|
|
1572
|
+ * 批量创建单元转换中文拼接
|
|
|
1573
|
+ * $start_num 起始单元
|
|
|
1574
|
+ * $end_num 结束单元
|
|
|
1575
|
+ */
|
|
|
1576
|
+ function create_unit_to_chinese($start_num, $end_num)
|
|
|
1577
|
+ {
|
|
|
1578
|
+ $arr = [];
|
|
|
1579
|
+ for ($i = $start_num; $i <= $end_num; $i++) {
|
|
|
1580
|
+ $arr[] = $i . "单元";
|
|
|
1581
|
+ }
|
|
|
1582
|
+ return $arr;
|
|
|
1583
|
+ }
|
|
|
1584
|
+
|
|
|
1585
|
+}
|
|
|
1586
|
+
|
|
|
1587
|
+if (!function_exists('create_floor_to_chinese')) {
|
|
|
1588
|
+ /**
|
|
|
1589
|
+ * 批量创建楼层转换中文拼接
|
|
|
1590
|
+ * $start_num 起始楼层号
|
|
|
1591
|
+ * $end_num 结束楼层号
|
|
|
1592
|
+ */
|
|
|
1593
|
+ function create_floor_to_chinese($start_num, $end_num)
|
|
|
1594
|
+ {
|
|
|
1595
|
+ $arr = [];
|
|
|
1596
|
+ for ($i = $start_num; $i <= $end_num; $i++) {
|
|
|
1597
|
+ $arr[] = $i;
|
|
|
1598
|
+ }
|
|
|
1599
|
+ return $arr;
|
|
|
1600
|
+ }
|
|
|
1601
|
+
|
|
|
1602
|
+}
|
|
|
1603
|
+
|
|
|
1604
|
+if (!function_exists('create_room_to_chinese')) {
|
|
|
1605
|
+ /**
|
|
|
1606
|
+ * 批量创建房号转换中文拼接
|
|
|
1607
|
+ * $start_num 起始房号
|
|
|
1608
|
+ * $end_num 结束房号
|
|
|
1609
|
+ */
|
|
|
1610
|
+ function create_room_to_chinese($start_num, $end_num)
|
|
|
1611
|
+ {
|
|
|
1612
|
+ $arr = [];
|
|
|
1613
|
+ for ($i = $start_num; $i <= $end_num; $i++) {
|
|
|
1614
|
+ $arr[] = str_pad($i, 2, "0", STR_PAD_LEFT);//两位数 左边补0
|
|
|
1615
|
+ }
|
|
|
1616
|
+ return $arr;
|
|
|
1617
|
+ }
|
|
|
1618
|
+
|
|
|
1619
|
+}
|
|
|
1620
|
+
|
|
|
1621
|
+if (!function_exists('show_online_message_by_grid_id_arr')) {
|
|
|
1622
|
+ /**
|
|
|
1623
|
+ * 根据可查看的网格点数组去找进行中的敲门通知ids 一维数组
|
|
|
1624
|
+ * $grid_ids 网格id一维数组
|
|
|
1625
|
+ */
|
|
|
1626
|
+ function show_online_message_by_grid_id_arr($grid_ids)
|
|
|
1627
|
+ {
|
|
|
1628
|
+ $arr = [];
|
|
|
1629
|
+ if (!empty($grid_ids)) {
|
|
|
1630
|
+ $now_date = date("Y-m-d");
|
|
|
1631
|
+ foreach ($grid_ids as $k => $v) {
|
|
|
1632
|
+ $wh = [];
|
|
|
1633
|
+ $wh["type"] = ["=", 3];//只显示网上敲门的数据
|
|
|
1634
|
+ $wh["status"] = ["=", "1"];
|
|
|
1635
|
+ $list = \think\Db::name("message")
|
|
|
1636
|
+ ->where($wh)
|
|
|
1637
|
+ ->where('FIND_IN_SET(:id,grid_infomation_ids)', ['id' => $v])
|
|
|
1638
|
+ ->field("id,start_time,end_time")
|
|
|
1639
|
+ ->group("id")
|
|
|
1640
|
+ ->select();
|
|
|
1641
|
+ if (!empty($list)) {
|
|
|
1642
|
+ foreach ($list as $lk => $lv) {
|
|
|
1643
|
+ if (!empty($lv['start_time'])) {
|
|
|
1644
|
+ if (strtotime($lv['start_time']) > strtotime($now_date)) {
|
|
|
1645
|
+ unset($list[$lk]);
|
|
|
1646
|
+ continue;//跳出本层循环
|
|
|
1647
|
+ }
|
|
|
1648
|
+ }
|
|
|
1649
|
+ if (!empty($lv['end_time'])) {
|
|
|
1650
|
+ if (strtotime($lv['end_time']) < strtotime($now_date)) {
|
|
|
1651
|
+ unset($list[$lk]);
|
|
|
1652
|
+ continue;//跳出本层循环
|
|
|
1653
|
+ }
|
|
|
1654
|
+ }
|
|
|
1655
|
+
|
|
|
1656
|
+ }
|
|
|
1657
|
+ $ids_arr = array_column($list, "id");
|
|
|
1658
|
+ $arr = array_merge($arr, $ids_arr);
|
|
|
1659
|
+ }
|
|
|
1660
|
+
|
|
|
1661
|
+ }
|
|
|
1662
|
+ }
|
|
|
1663
|
+ $arr = array_unique($arr);
|
|
|
1664
|
+
|
|
|
1665
|
+ return $arr;
|
|
|
1666
|
+ }
|
|
|
1667
|
+}
|
|
|
1668
|
+
|
|
|
1669
|
+if (!function_exists('show_outdate_online_message_by_grid_id_arr')) {
|
|
|
1670
|
+ /**
|
|
|
1671
|
+ * 根据可查看的网格点数组去找已过期的敲门通知ids 一维数组
|
|
|
1672
|
+ * $grid_ids 网格id一维数组
|
|
|
1673
|
+ */
|
|
|
1674
|
+ function show_outdate_online_message_by_grid_id_arr($grid_ids)
|
|
|
1675
|
+ {
|
|
|
1676
|
+ $arr = [];
|
|
|
1677
|
+ if (!empty($grid_ids)) {
|
|
|
1678
|
+ $now_date = date("Y-m-d");
|
|
|
1679
|
+ foreach ($grid_ids as $k => $v) {
|
|
|
1680
|
+ $wh = [];
|
|
|
1681
|
+ $wh["type"] = ["=", 3];//只显示网上敲门的数据
|
|
|
1682
|
+ $wh["status"] = ["=", "1"];
|
|
|
1683
|
+ $list = \think\Db::name("message")
|
|
|
1684
|
+ ->where($wh)
|
|
|
1685
|
+ ->where('FIND_IN_SET(:id,grid_infomation_ids)', ['id' => $v])
|
|
|
1686
|
+ ->field("id,start_time,end_time")
|
|
|
1687
|
+ ->group("id")
|
|
|
1688
|
+ ->select();
|
|
|
1689
|
+ if (!empty($list)) {
|
|
|
1690
|
+ foreach ($list as $lk => $lv) {
|
|
|
1691
|
+ if (!empty($lv['end_time'])) {
|
|
|
1692
|
+ if (strtotime($lv['end_time']) < strtotime($now_date)) {
|
|
|
1693
|
+ $arr = array_merge($arr, [$lv['id']]);
|
|
|
1694
|
+ }
|
|
|
1695
|
+ }
|
|
|
1696
|
+ }
|
|
|
1697
|
+ }
|
|
|
1698
|
+
|
|
|
1699
|
+ }
|
|
|
1700
|
+ }
|
|
|
1701
|
+ $arr = array_unique($arr);
|
|
|
1702
|
+ return $arr;
|
|
|
1703
|
+ }
|
|
|
1704
|
+}
|
|
|
1705
|
+
|
|
|
1706
|
+if (!function_exists('judge_bind_wx_xcx')) {
|
|
|
1707
|
+ /**
|
|
|
1708
|
+ * 判断是否绑定了小程序
|
|
|
1709
|
+ * true已绑定 false未绑定
|
|
|
1710
|
+ */
|
|
|
1711
|
+ function judge_bind_wx_xcx($unionid)
|
|
|
1712
|
+ {
|
|
|
1713
|
+ $flag = 0;
|
|
|
1714
|
+ if (!empty($unionid)) {
|
|
|
1715
|
+ //若授权小程序过小程序那么wx_xcx_openid肯定是有值的
|
|
|
1716
|
+ $wx_xcx_openid = Db::name("user")->where("unionid", $unionid)->value("wx_xcx_openid");
|
|
|
1717
|
+ if (!empty($wx_xcx_openid)) {
|
|
|
1718
|
+ $flag = 1;
|
|
|
1719
|
+ }
|
|
|
1720
|
+ }
|
|
|
1721
|
+ return $flag;
|
|
|
1722
|
+ }
|
|
|
1723
|
+}
|
|
|
1724
|
+
|
|
|
1725
|
+if (!function_exists('judge_bind_wgz_relation')) {
|
|
|
1726
|
+ /**
|
|
|
1727
|
+ * 判断是否与网格的网格长加了好友的
|
|
|
1728
|
+ * true已加好友 false未加好友
|
|
|
1729
|
+ */
|
|
|
1730
|
+ function judge_bind_wgz_relation($unionid, $grid_id)
|
|
|
1731
|
+ {
|
|
|
1732
|
+ $flag = 0;
|
|
|
1733
|
+ if (!empty($unionid) && !empty($grid_id)) {
|
|
|
1734
|
+ $grid_infomation = Db::name("grid_infomation")->where("id", $grid_id)->find();
|
|
|
1735
|
+ if (!empty($grid_infomation['corp_user_ids'])) {
|
|
|
1736
|
+ //网格长信息
|
|
|
1737
|
+ $corp_user = Db::name("corp_user")->where("id", $grid_infomation['corp_user_ids'])->field("corp_id,userid")->find();
|
|
|
1738
|
+ //找到外部联系人的userid
|
|
|
1739
|
+ $userid = Db::name("corp_groupchat_member")->where("unionid", $unionid)->value("userid");
|
|
|
1740
|
+ if (!empty($userid)) {
|
|
|
1741
|
+ //先查询外部联系人详细信息【follow_user中包含已加的内部成员列表】
|
|
|
1742
|
+ $externalcontact_Api = new \app\api\controller\wework\Externalcontact();
|
|
|
1743
|
+ $rr = $externalcontact_Api->externalcontactInfo($corp_user['corp_id'], $userid, "");
|
|
|
1744
|
+ //判断下网格长的userid是否在客户的资料详情的客户好友中
|
|
|
1745
|
+ if ($rr['state'] == true) {
|
|
|
1746
|
+ $follow_user = $rr['data']['follow_user'];
|
|
|
1747
|
+ if (!empty($follow_user)) {
|
|
|
1748
|
+ //找到了外部联系人加过的企业内部员工列表
|
|
|
1749
|
+ $userid_arr = array_column($follow_user, "userid");
|
|
|
1750
|
+ if (in_array($corp_user['userid'], $userid_arr)) {
|
|
|
1751
|
+ $flag = 1;
|
|
|
1752
|
+ }
|
|
|
1753
|
+ }
|
|
|
1754
|
+ }
|
|
|
1755
|
+ }
|
|
|
1756
|
+ }
|
|
|
1757
|
+ }
|
|
|
1758
|
+ return $flag;
|
|
|
1759
|
+ }
|
|
|
1760
|
+}
|
|
|
1761
|
+
|
|
|
1762
|
+if (!function_exists('judge_bind_groupchat_relation')) {
|
|
|
1763
|
+ /**
|
|
|
1764
|
+ * 判断是否加入过网格的客户群
|
|
|
1765
|
+ * true已加客户群 false未加客户群
|
|
|
1766
|
+ */
|
|
|
1767
|
+ function judge_bind_groupchat_relation($unionid, $grid_id)
|
|
|
1768
|
+ {
|
|
|
1769
|
+ $flag = 0;
|
|
|
1770
|
+ if (!empty($unionid) && !empty($grid_id)) {
|
|
|
1771
|
+ $grid_infomation = Db::name("grid_infomation")->where("id", $grid_id)->find();
|
|
|
1772
|
+ //客户群id
|
|
|
1773
|
+ if (!empty($grid_infomation['corp_groupchat_ids'])) {
|
|
|
1774
|
+ $w = [];
|
|
|
1775
|
+ $w["corp_groupchat_id"] = ["in", $grid_infomation['corp_groupchat_ids']];
|
|
|
1776
|
+ $w['type'] = ["=", "2"];//外部联系人
|
|
|
1777
|
+ $w['unionid'] = ["=", $unionid];
|
|
|
1778
|
+ $count = Db::name("corp_groupchat_member")->where($w)->count();
|
|
|
1779
|
+ if ($count > 0) {
|
|
|
1780
|
+ $flag = 1;
|
|
|
1781
|
+ }
|
|
|
1782
|
+ }
|
|
|
1783
|
+ }
|
|
|
1784
|
+ return $flag;
|
|
|
1785
|
+ }
|
|
|
1786
|
+}
|
|
|
1787
|
+
|
|
|
1788
|
+if (!function_exists('user_id_get_admin_id')) {
|
|
|
1789
|
+ /**
|
|
|
1790
|
+ * 根据用户id获取归属admin_id
|
|
|
1791
|
+ */
|
|
|
1792
|
+ function user_id_get_admin_id($id)
|
|
|
1793
|
+ {
|
|
|
1794
|
+ $admin_id = 1;
|
|
|
1795
|
+ if (!empty($id)) {
|
|
|
1796
|
+ $ad_id = Db::name("user")->alias("a")
|
|
|
1797
|
+ ->join("user_grid b", "a.unionid=b.unionid")
|
|
|
1798
|
+ ->where("a.id", $id)
|
|
|
1799
|
+ ->value("b.admin_id");
|
|
|
1800
|
+ if (!empty($ad_id)) {
|
|
|
1801
|
+ $admin_id = $ad_id;
|
|
|
1802
|
+ }
|
|
|
1803
|
+ }
|
|
|
1804
|
+ return $admin_id;
|
|
|
1805
|
+ }
|
|
|
1806
|
+}
|
|
|
1807
|
+
|
|
|
1808
|
+if (!function_exists('str_add_xing')) {
|
|
|
1809
|
+ /**
|
|
|
1810
|
+ * 字符串中间加“*”号
|
|
|
1811
|
+ * @param $str
|
|
|
1812
|
+ * @return string
|
|
|
1813
|
+ */
|
|
|
1814
|
+ function str_add_xing($str)
|
|
|
1815
|
+ {
|
|
|
1816
|
+ //判断是否包含中文字符
|
|
|
1817
|
+ if (preg_match("/[\x{4e00}-\x{9fa5}]+/u", $str)) {
|
|
|
1818
|
+ //按照中文字符计算长度
|
|
|
1819
|
+ $len = mb_strlen($str, 'UTF-8');
|
|
|
1820
|
+ //echo '中文';
|
|
|
1821
|
+ if ($len >= 3) {
|
|
|
1822
|
+ //三个字符或三个字符以上掐头取尾,中间用*代替
|
|
|
1823
|
+ $str = mb_substr($str, 0, 1, 'UTF-8') . '*' . mb_substr($str, -1, 1, 'UTF-8');
|
|
|
1824
|
+ } elseif ($len == 2) {
|
|
|
1825
|
+ //两个字符
|
|
|
1826
|
+ $str = mb_substr($str, 0, 1, 'UTF-8') . '*';
|
|
|
1827
|
+ }
|
|
|
1828
|
+ } else {
|
|
|
1829
|
+ //按照英文字串计算长度
|
|
|
1830
|
+ $len = strlen($str);
|
|
|
1831
|
+ //echo 'English';
|
|
|
1832
|
+ if ($len >= 3) {
|
|
|
1833
|
+ //三个字符或三个字符以上掐头取尾,中间用*代替
|
|
|
1834
|
+ $str = substr($str, 0, 1) . '*' . substr($str, -1);
|
|
|
1835
|
+ } elseif ($len == 2) {
|
|
|
1836
|
+ //两个字符
|
|
|
1837
|
+ $str = substr($str, 0, 1) . '*';
|
|
|
1838
|
+ }
|
|
|
1839
|
+ }
|
|
|
1840
|
+ return $str;
|
|
|
1841
|
+ }
|
|
|
1842
|
+
|
|
|
1843
|
+}
|
|
|
1844
|
+
|
|
|
1845
|
+if (!function_exists('mobile_hide')) {
|
|
|
1846
|
+ /**
|
|
|
1847
|
+ * 手机号中间星号代替
|
|
|
1848
|
+ */
|
|
|
1849
|
+ function mobile_hide($mobile)
|
|
|
1850
|
+ {
|
|
|
1851
|
+ if (strlen($mobile) == 11) {
|
|
|
1852
|
+ $mobile = substr_replace($mobile, "****", 3, 4);
|
|
|
1853
|
+ }
|
|
|
1854
|
+ return $mobile;
|
|
|
1855
|
+ }
|
|
|
1856
|
+}
|
|
|
1857
|
+
|
|
|
1858
|
+if (!function_exists('idcard_hide')) {
|
|
|
1859
|
+ /**
|
|
|
1860
|
+ * 身份证中间星号代替
|
|
|
1861
|
+ */
|
|
|
1862
|
+ function idcard_hide($idcard)
|
|
|
1863
|
+ {
|
|
|
1864
|
+ if (strlen($idcard) == 15) {
|
|
|
1865
|
+ $idcard = substr_replace($idcard, "****", 8, 4);
|
|
|
1866
|
+ } elseif (strlen($idcard) == 18) {
|
|
|
1867
|
+ $idcard = substr_replace($idcard, "********", 6, 8);
|
|
|
1868
|
+ }
|
|
|
1869
|
+ return $idcard;
|
|
|
1870
|
+ }
|
|
|
1871
|
+}
|
|
|
1872
|
+
|
|
|
1873
|
+if (!function_exists('get_root_url')) {
|
|
|
1874
|
+ /**
|
|
|
1875
|
+ * 获取网站的根Url
|
|
|
1876
|
+ * @return string
|
|
|
1877
|
+ */
|
|
|
1878
|
+ function get_root_url()
|
|
|
1879
|
+ {
|
|
|
1880
|
+ $request = request();
|
|
|
1881
|
+ $base = $request->root();
|
|
|
1882
|
+ $root = strpos($base, '.') ? ltrim(dirname($base), DS) : $base;
|
|
|
1883
|
+ if ('' != $root) {
|
|
|
1884
|
+ $root = '/' . ltrim($root, '/');
|
|
|
1885
|
+ }
|
|
|
1886
|
+
|
|
|
1887
|
+ return ($request->isSsl() ? 'https' : 'http') . '://' . $request->host() . "{$root}";
|
|
|
1888
|
+ }
|
|
|
1889
|
+}
|
|
|
1890
|
+
|
|
|
1891
|
+if (!function_exists('del_place_qrcode')) {
|
|
|
1892
|
+ /**
|
|
|
1893
|
+ * 删除场所二维码文件(地址存在的是带域名的全路径 )
|
|
|
1894
|
+ * @param [type] $pic [description]
|
|
|
1895
|
+ * @return [type] [description]
|
|
|
1896
|
+ */
|
|
|
1897
|
+ function del_place_qrcode($pic)
|
|
|
1898
|
+ {
|
|
|
1899
|
+ $pic_path_arr = parse_url($pic);//parse_url函数将URL转换为关联数组
|
|
|
1900
|
+ $real_pic_path = $pic_path_arr['path'];
|
|
|
1901
|
+ $path = __FILE__;
|
|
|
1902
|
+ $paths = substr($path, 0, strpos($path, 'application'));
|
|
|
1903
|
+ $pic1 = $paths . "public" . $real_pic_path;
|
|
|
1904
|
+
|
|
|
1905
|
+ if (file_exists($pic1)) {
|
|
|
1906
|
+
|
|
|
1907
|
+ @unlink($pic1);
|
|
|
1908
|
+
|
|
|
1909
|
+ return true;
|
|
|
1910
|
+ }
|
|
|
1911
|
+ return false;
|
|
|
1912
|
+ }
|
|
|
1913
|
+}
|
|
|
1914
|
+
|
|
|
1915
|
+
|
|
|
1916
|
+if (!function_exists('is_idcard')) {
|
|
|
1917
|
+ /**
|
|
|
1918
|
+ * 验证身份证
|
|
|
1919
|
+ * @param $id
|
|
|
1920
|
+ * @return bool
|
|
|
1921
|
+ * 公民身份证号码按照 GB11643—1999《公民身份证号码》国家标准编制,由18位数字组成。18位数字按照一定规则进行编写的:
|
|
|
1922
|
+ * 前1-6位:行政区划代码,即归属地
|
|
|
1923
|
+ * 第7-14位:出生年月日
|
|
|
1924
|
+ * 第15-17位:顺序码,表示在同一地址码所标识的区域范围内,对同年、同月、同日出生的人编定的顺序号
|
|
|
1925
|
+ * 第17位:顺序码之一,代表性别,奇数表示男性,偶数表示女性
|
|
|
1926
|
+ * 第18位:校验码,用于校验身份证号码是否合法。校检码可以是0~9的数字,有时也用x表示。
|
|
|
1927
|
+ * 例如: ·510525197902217660
|
|
|
1928
|
+ * 510525 四川省 泸州市 古蔺县
|
|
|
1929
|
+ * 19790221 1979年02月21日出生
|
|
|
1930
|
+ * 76 顺序码
|
|
|
1931
|
+ * 6 顺序码,男
|
|
|
1932
|
+ * 0 验证码
|
|
|
1933
|
+ */
|
|
|
1934
|
+ function is_idcard($id)
|
|
|
1935
|
+ {
|
|
|
1936
|
+ $id = strtoupper($id);
|
|
|
1937
|
+ $regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";
|
|
|
1938
|
+ $arr_split = array();
|
|
|
1939
|
+ if (!preg_match($regx, $id)) {
|
|
|
1940
|
+ return false;
|
|
|
1941
|
+ }
|
|
|
1942
|
+ if (15 == strlen($id)) //检查15位
|
|
|
1943
|
+ {
|
|
|
1944
|
+ $regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";
|
|
|
1945
|
+
|
|
|
1946
|
+ @preg_match($regx, $id, $arr_split);
|
|
|
1947
|
+ //检查生日日期是否正确
|
|
|
1948
|
+ $dtm_birth = "19" . $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];
|
|
|
1949
|
+ if (!strtotime($dtm_birth)) {
|
|
|
1950
|
+ return false;
|
|
|
1951
|
+ } else {
|
|
|
1952
|
+ return true;
|
|
|
1953
|
+ }
|
|
|
1954
|
+ } else //检查18位
|
|
|
1955
|
+ {
|
|
|
1956
|
+ $regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
|
|
|
1957
|
+ @preg_match($regx, $id, $arr_split);
|
|
|
1958
|
+ $dtm_birth = $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];
|
|
|
1959
|
+ if (!strtotime($dtm_birth)) //检查生日日期是否正确
|
|
|
1960
|
+ {
|
|
|
1961
|
+ return false;
|
|
|
1962
|
+ } else {
|
|
|
1963
|
+ //检验18位身份证的校验码是否正确。
|
|
|
1964
|
+ //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
|
|
|
1965
|
+ $arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
|
|
|
1966
|
+ $arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
|
|
|
1967
|
+ $sign = 0;
|
|
|
1968
|
+ for ($i = 0; $i < 17; $i++) {
|
|
|
1969
|
+ $b = (int)$id{$i};
|
|
|
1970
|
+ $w = $arr_int[$i];
|
|
|
1971
|
+ $sign += $b * $w;
|
|
|
1972
|
+ }
|
|
|
1973
|
+ $n = $sign % 11;
|
|
|
1974
|
+ $val_num = $arr_ch[$n];
|
|
|
1975
|
+ if ($val_num != substr($id, 17, 1)) {
|
|
|
1976
|
+ return false;
|
|
|
1977
|
+ } else {
|
|
|
1978
|
+ return true;
|
|
|
1979
|
+ }
|
|
|
1980
|
+ }
|
|
|
1981
|
+ }
|
|
|
1982
|
+
|
|
|
1983
|
+ }
|
|
|
1984
|
+}
|
|
|
1985
|
+
|
|
|
1986
|
+if (!function_exists('area_code_get_groupid_and_adminid')) {
|
|
|
1987
|
+ /**
|
|
|
1988
|
+ * 根据行政区域编码获取角色组和管理员id
|
|
|
1989
|
+ */
|
|
|
1990
|
+ function area_code_get_groupid_and_adminid($area_code = null)
|
|
|
1991
|
+ {
|
|
|
1992
|
+ $group_id = 1;
|
|
|
1993
|
+ $admin_id = 1;
|
|
|
1994
|
+ if (!empty($area_code)) {
|
|
|
1995
|
+ $group_id = Db::name("auth_group")->where("mng_area_code", $area_code)->value("id");
|
|
|
1996
|
+ if ($group_id > 0) {
|
|
|
1997
|
+ $admin_id = Db::name("auth_group_access")->where("group_id", $group_id)->value("uid");
|
|
|
1998
|
+ }
|
|
|
1999
|
+ }
|
|
|
2000
|
+
|
|
|
2001
|
+ $group_id = $group_id > 0 ? $group_id : 1;
|
|
|
2002
|
+ $admin_id = $admin_id > 0 ? $admin_id : 1;
|
|
|
2003
|
+
|
|
|
2004
|
+ return ["group_id" => $group_id, "admin_id" => $admin_id];
|
|
|
2005
|
+ }
|
|
|
2006
|
+}
|
|
|
2007
|
+
|
|
|
2008
|
+if (!function_exists('full_image')) {
|
|
|
2009
|
+ /**
|
|
|
2010
|
+ * 获取图片全地址
|
|
|
2011
|
+ */
|
|
|
2012
|
+ function full_image($img)
|
|
|
2013
|
+ {
|
|
|
2014
|
+
|
|
|
2015
|
+ //七牛云插件(标识:qiniu)
|
|
|
2016
|
+ $qiniu_config = get_addon_config("qiniu");
|
|
|
2017
|
+
|
|
|
2018
|
+ if (!empty($img)) {
|
|
|
2019
|
+ //判断是不是数组
|
|
|
2020
|
+ if (is_array($img)) {
|
|
|
2021
|
+ foreach ($img as $k => $v) {
|
|
|
2022
|
+ if (!empty($v)) {
|
|
|
2023
|
+ if ('http' != substr($v, 0, 4)) {
|
|
|
2024
|
+ $img[$k] = $qiniu_config['cdnurl'] . $v;
|
|
|
2025
|
+ }
|
|
|
2026
|
+ }
|
|
|
2027
|
+ }
|
|
|
2028
|
+ } else {
|
|
|
2029
|
+ //判断是不是http开头的(若是就是就代表是本地上传。不是就是七牛上传的=>"/uploads")
|
|
|
2030
|
+ if ('http' != substr($img, 0, 4)) {
|
|
|
2031
|
+ $img = $qiniu_config['cdnurl'] . $img;
|
|
|
2032
|
+ }
|
|
|
2033
|
+ }
|
|
|
2034
|
+ }
|
|
|
2035
|
+ return $img;
|
|
|
2036
|
+ }
|
|
|
2037
|
+}
|
|
|
2038
|
+
|
|
|
2039
|
+if (!function_exists('get_tree_list')) {
|
|
|
2040
|
+ /**
|
|
|
2041
|
+ * 父子级树状结构 传入的参数为二维数组 parent是父级id
|
|
|
2042
|
+ */
|
|
|
2043
|
+ function get_tree_list($list)
|
|
|
2044
|
+ {
|
|
|
2045
|
+ //将每条数据中的id值作为其下标
|
|
|
2046
|
+ $temp = [];
|
|
|
2047
|
+ foreach ($list as $v) {
|
|
|
2048
|
+ $v['children'] = [];
|
|
|
2049
|
+ $temp[$v['id']] = $v;
|
|
|
2050
|
+ }
|
|
|
2051
|
+ //获取分类树
|
|
|
2052
|
+ foreach ($temp as $k => $v) {
|
|
|
2053
|
+ $temp[$v['parent']]['children'][] = &$temp[$v['id']];
|
|
|
2054
|
+ }
|
|
|
2055
|
+ return isset($temp[0]['children']) ? $temp[0]['children'] : [];
|
|
|
2056
|
+ }
|
|
|
2057
|
+}
|
|
|
2058
|
+
|
|
|
2059
|
+if (!function_exists('monthlater')) {
|
|
|
2060
|
+ /**
|
|
|
2061
|
+ * @return array获取近12个月(月份从远到近)
|
|
|
2062
|
+ */
|
|
|
2063
|
+ function monthlater()
|
|
|
2064
|
+ {
|
|
|
2065
|
+ $str = array();
|
|
|
2066
|
+ for ($i = 0; $i <= 11; $i++) {
|
|
|
2067
|
+ $str[] = date("Y-m", strtotime(date('Y-m-01') . " -$i months"));
|
|
|
2068
|
+ }
|
|
|
2069
|
+ return array_reverse($str);
|
|
|
2070
|
+ }
|
|
|
2071
|
+}
|
|
|
2072
|
+
|
|
|
2073
|
+if (!function_exists('apply_bind_admin_id')) {
|
|
|
2074
|
+ /**
|
|
|
2075
|
+ * 绑定管理员信息
|
|
|
2076
|
+ */
|
|
|
2077
|
+ function apply_bind_admin_id($cun_code)
|
|
|
2078
|
+ {
|
|
|
2079
|
+ $admin_id = 4;
|
|
|
2080
|
+ if ($cun_code) {
|
|
|
2081
|
+ $admin_id = Db::name("hc_area_code")->where("code", $cun_code)->value("admin_id");
|
|
|
2082
|
+ }
|
|
|
2083
|
+ return $admin_id;
|
|
|
2084
|
+ }
|
|
|
2085
|
+}
|
|
|
2086
|
+
|
|
|
2087
|
+if (!function_exists('area_code_relation_names')) {
|
|
|
2088
|
+ /**
|
|
|
2089
|
+ * 根据某个区域code返回所有上级的名称 用"$str"拼接(不含本身)
|
|
|
2090
|
+ */
|
|
|
2091
|
+ function area_code_relation_names($code, $str = "/")
|
|
|
2092
|
+ {
|
|
|
2093
|
+ $pid_arr = area_name_relation_by_id($code);
|
|
|
2094
|
+ $grid_name_str = "";
|
|
|
2095
|
+ $pid_arr = array_reverse($pid_arr);//数组倒序
|
|
|
2096
|
+ if (!empty($pid_arr)) {
|
|
|
2097
|
+ $w1 = [];
|
|
|
2098
|
+ $w1["code"] = ["IN", $pid_arr];
|
|
|
2099
|
+ $grid_name_arr = Db::name("hc_area_code")->where($w1)->order("level asc")->column("name");
|
|
|
2100
|
+ $grid_name_str = implode($grid_name_arr, $str);
|
|
|
2101
|
+ }
|
|
|
2102
|
+ return $grid_name_str;
|
|
|
2103
|
+
|
|
|
2104
|
+ }
|
|
|
2105
|
+}
|
|
|
2106
|
+
|
|
|
2107
|
+if (!function_exists('area_name_relation_by_id')) {
|
|
|
2108
|
+ /**
|
|
|
2109
|
+ * 根据某个区域code返回所有上级的id(不含本身)
|
|
|
2110
|
+ */
|
|
|
2111
|
+ function area_name_relation_by_id($code, $arr = [])
|
|
|
2112
|
+ {
|
|
|
2113
|
+
|
|
|
2114
|
+ $pcode = Db::name("hc_area_code")->where("code", $code)->value("pcode");
|
|
|
2115
|
+ if ($pcode > 0) {
|
|
|
2116
|
+ $arr = array_merge($arr, [$pcode]);
|
|
|
2117
|
+ }
|
|
|
2118
|
+ return $pcode > 0 ? area_name_relation_by_id($pcode, $arr) : $arr;
|
|
|
2119
|
+ }
|
|
|
2120
|
+}
|
|
|
2121
|
+
|
|
|
2122
|
+if (!function_exists('get_child_ids')) {
|
|
|
2123
|
+ /**
|
|
|
2124
|
+ * @Description: 获取当前分类下所有子类ID(包含自己)
|
|
|
2125
|
+ * @pid:父类ID
|
|
|
2126
|
+ */
|
|
|
2127
|
+ function get_child_ids($pid)
|
|
|
2128
|
+ {
|
|
|
2129
|
+ return get_ids($pid, '', 'code');
|
|
|
2130
|
+ }
|
|
|
2131
|
+}
|
|
|
2132
|
+
|
|
|
2133
|
+if (!function_exists('get_ids')) {
|
|
|
2134
|
+ /**
|
|
|
2135
|
+ * @Description: 获取类下所有父/子类ID
|
|
|
2136
|
+ * @pid:多个父/子类ID集以,分隔
|
|
|
2137
|
+ * @childids:找到的子/父分类列表
|
|
|
2138
|
+ * @find_column:where查找的字段[id|pid:default]
|
|
|
2139
|
+ */
|
|
|
2140
|
+ function get_ids($pid, $childids, $find_column = 'code')
|
|
|
2141
|
+ {
|
|
|
2142
|
+ if (!$pid || $pid <= 0 || strlen($pid) <= 0 || !in_array($find_column, array('code', 'pcode'))) return 0;
|
|
|
2143
|
+ if (!$childids || strlen($childids) <= 0) $childids = $pid;
|
|
|
2144
|
+ $column = ($find_column == 'code' ? "pcode" : "code");//id跟pid为互斥
|
|
|
2145
|
+ $ids = Db::name("hc_area_code")->where("$column in ($pid)")->column("$find_column");
|
|
|
2146
|
+ $ids = implode(",", $ids);
|
|
|
2147
|
+
|
|
|
2148
|
+ //未找到,返回已经找到的
|
|
|
2149
|
+ if ($ids <= 0) return $childids;
|
|
|
2150
|
+ //添加到集合中
|
|
|
2151
|
+ $childids .= ',' . $ids;
|
|
|
2152
|
+ //递归查找
|
|
|
2153
|
+ return get_ids($ids, $childids, $find_column);
|
|
|
2154
|
+ }
|
|
|
2155
|
+}
|
|
|
2156
|
+
|
|
|
2157
|
+/**
|
|
|
2158
|
+ * 发送curl请求获得数据
|
|
|
2159
|
+ * @param $url string
|
|
|
2160
|
+ * @param return array|mixed
|
|
|
2161
|
+ */
|
|
|
2162
|
+function https_request($url)
|
|
|
2163
|
+{
|
|
|
2164
|
+ $curl = curl_init();
|
|
|
2165
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
2166
|
+ curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
2167
|
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
2168
|
+ $AjaxReturn = curl_exec($curl);
|
|
|
2169
|
+ //获取转换为数组
|
|
|
2170
|
+ $data = json_decode($AjaxReturn, true);
|
|
|
2171
|
+ curl_close($curl);
|
|
|
2172
|
+ return $data;
|
|
|
2173
|
+}
|
|
|
2174
|
+
|
|
|
2175
|
+function mb_substr_replace($string, $replacement, $start, $length = null, $encoding = null)
|
|
|
2176
|
+{
|
|
|
2177
|
+ if (extension_loaded('mbstring') === true) {
|
|
|
2178
|
+ $string_length = (is_null($encoding) === true) ? mb_strlen($string) : mb_strlen($string, $encoding);
|
|
|
2179
|
+
|
|
|
2180
|
+ if ($start < 0) {
|
|
|
2181
|
+ $start = max(0, $string_length + $start);
|
|
|
2182
|
+ } else if ($start > $string_length) {
|
|
|
2183
|
+ $start = $string_length;
|
|
|
2184
|
+ }
|
|
|
2185
|
+
|
|
|
2186
|
+ if ($length < 0) {
|
|
|
2187
|
+ $length = max(0, $string_length - $start + $length);
|
|
|
2188
|
+ } else if ((is_null($length) === true) || ($length > $string_length)) {
|
|
|
2189
|
+ $length = $string_length;
|
|
|
2190
|
+ }
|
|
|
2191
|
+
|
|
|
2192
|
+ if (($start + $length) > $string_length) {
|
|
|
2193
|
+ $length = $string_length - $start;
|
|
|
2194
|
+ }
|
|
|
2195
|
+
|
|
|
2196
|
+ if (is_null($encoding) === true) {
|
|
|
2197
|
+ return mb_substr($string, 0, $start) . $replacement . mb_substr($string, $start + $length, $string_length - $start - $length);
|
|
|
2198
|
+ }
|
|
|
2199
|
+
|
|
|
2200
|
+ return mb_substr($string, 0, $start, $encoding) . $replacement . mb_substr($string, $start + $length, $string_length - $start - $length, $encoding);
|
|
|
2201
|
+ }
|
|
|
2202
|
+
|
|
|
2203
|
+ return (is_null($length) === true) ? substr_replace($string, $replacement, $start) : substr_replace($string, $replacement, $start, $length);
|
|
|
2204
|
+}
|
|
|
2205
|
+
|
|
|
2206
|
+function send_post($url, $post_data, $method = 'POST')
|
|
|
2207
|
+{
|
|
|
2208
|
+ $postdata = http_build_query($post_data);
|
|
|
2209
|
+ $options = array(
|
|
|
2210
|
+ 'http' => array(
|
|
|
2211
|
+ 'method' => $method, //or GET
|
|
|
2212
|
+ 'header' => 'Content-type:application/x-www-form-urlencoded',
|
|
|
2213
|
+ 'content' => $postdata,
|
|
|
2214
|
+ 'timeout' => 15 * 60 // 超时时间(单位:s)
|
|
|
2215
|
+ )
|
|
|
2216
|
+ );
|
|
|
2217
|
+ $context = stream_context_create($options);
|
|
|
2218
|
+ $result = file_get_contents($url, false, $context);
|
|
|
2219
|
+
|
|
|
2220
|
+ return $result;
|
|
|
2221
|
+}
|
|
|
2222
|
+
|
|
|
2223
|
+function api_notice_increment($url, $data = '', $method = 'GET')
|
|
|
2224
|
+{
|
|
|
2225
|
+ $curl = curl_init();
|
|
|
2226
|
+ $header = array("application/x-www-form-urlencoded; charset=utf-8");
|
|
|
2227
|
+ curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
2228
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
|
|
2229
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
|
|
|
2230
|
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
|
|
2231
|
+ curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
|
|
|
2232
|
+ curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
|
|
|
2233
|
+ curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
|
|
|
2234
|
+ if ($method == 'POST') {
|
|
|
2235
|
+ curl_setopt($curl, CURLOPT_POST, 1);
|
|
|
2236
|
+ if ($data != '') {
|
|
|
2237
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
|
2238
|
+ }
|
|
|
2239
|
+ }
|
|
|
2240
|
+ curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
|
|
2241
|
+ curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
|
2242
|
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
2243
|
+ $result = curl_exec($curl);
|
|
|
2244
|
+ curl_close($curl);
|
|
|
2245
|
+ return $result;
|
|
|
2246
|
+}
|
|
|
2247
|
+
|
|
|
2248
|
+/**
|
|
|
2249
|
+ *求两个已知经纬度之间的距离,单位为千米
|
|
|
2250
|
+ * @param lng1,lng2 经度
|
|
|
2251
|
+ * @param lat1,lat2 纬度
|
|
|
2252
|
+ * @return float 距离,单位千米
|
|
|
2253
|
+ **/
|
|
|
2254
|
+//根据经纬度计算距离
|
|
|
2255
|
+function distance($lng1, $lat1, $lng2, $lat2)
|
|
|
2256
|
+{
|
|
|
2257
|
+ //将角度转为弧度
|
|
|
2258
|
+ $radLat1 = deg2rad($lat1);
|
|
|
2259
|
+ $radLat2 = deg2rad($lat2);
|
|
|
2260
|
+ $radLng1 = deg2rad($lng1);
|
|
|
2261
|
+ $radLng2 = deg2rad($lng2);
|
|
|
2262
|
+ $a = $radLat1 - $radLat2;//两纬度之差,纬度<90
|
|
|
2263
|
+ $b = $radLng1 - $radLng2;//两经度之差纬度<180
|
|
|
2264
|
+ $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137;
|
|
|
2265
|
+ return $s;
|
|
|
2266
|
+} |