Blame view

addons/antis/library/Ku.php 4.35 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  <?php

  

  namespace  addons\antis\library;

  

  use addons\antis\model\AdminConfig;

  use addons\antis\model\Contacts;

  use addons\antis\model\Customer;

  use addons\antis\model\KuCustomer;

  use think\Model;

  use fast\Http;

  

  /**

   *

   */

  class Ku extends Model

  {

  

      //客户增加

      public function addCustomer($params=null){

          $ku = AdminConfig::where(['type'=>AdminConfig::TYPE_KU])->column('field,value');

          if(isset($ku) && $ku && $params){

              if($ku['status'] == 1 && $ku['account'] && $ku['key']){

                  $info = KuCustomer::where(array('customer_id'=>$params['customer_id']))->find();

                  if($info){

                      return true;

                  }

                  $customer = Customer::where(array('id'=>$params['customer_id']))->find();

                  $url =$ku['url'].'api/kuerp/third/customers/joinCustomers';

                  $sign = md5('account='.$ku['account'].'&mobile='.$params['mobile'].'&name='.$customer['name'].'key='.$ku['key']);

                  $data = array(

                      'account'=>$ku['account'],

                      'sign'=>$sign,

                      'request_time'=>time(),

                      'name'=>$customer['name'],

                      'mobile'=>$params['mobile'],

                      'address'=>$customer['address'],

                      'note'=>$customer['remarks'],

                  );

                  $result = $this->http_post($url,$data);

                  $result = json_decode($result,true);

                  if($result['code'] == 1){

                      $ress = array(

                          'customer_id'=>$params['customer_id'],

                          'contacts_id'=>$params['contacts_id'],

                          'ku_id'=>$result['data']['id'],

                          'code'=>$result['data']['customer_code'],

                          'createtime'=>time()

                      );

                      KuCustomer::create($ress);

                  }

              }

          }

          return true;

      }

      //客户修改

      public function editCustomer($params=null){

  

          $ku = AdminConfig::where(['type'=>AdminConfig::TYPE_KU])->column('field,value');

          if(isset($ku) && $ku && $params){

              if($ku['status'] == 1 && $ku['account'] && $ku['key']){

                  $info = KuCustomer::where(array('customer_id'=>$params['id']))->find();

                  if(!$info){

                      return true;

                  }

                  $contacts = Contacts::where(array('id'=>$info['contacts_id']))->value('mobile');

                  $url =$ku['url'].'api/kuerp/third/customers/editCustomers';

                  $sign = md5('account='.$ku['account'].'&code='.$info['code'].'&mobile='.$contacts.'&name='.$params['name'].'key='.$ku['key']);

                  $data = array(

                      'account'=>$ku['account'],

                      'sign'=>$sign,

                      'request_time'=>time(),

                      'code'=>$info['code'],

                      'name'=>$params['name'],

                      'mobile'=>$contacts,

                      'address'=>$params['address'],

                  );

                  $result = $this->http_post($url,$data);

                  $result = json_decode($result,true);

              }

          }

          return true;

      }

      public function http_post($url,$param,$post_file=false){

          $oCurl = curl_init();

          if(stripos($url,"https://")!==FALSE){

              curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);

              curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);

              curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1

          }

          if (is_string($param) || $post_file) {

              $strPOST = $param;

          } else {

              $aPOST = array();

              foreach($param as $key=>$val){

                  $aPOST[] = $key."=".urlencode($val);

              }

              $strPOST =  join("&", $aPOST);

          }

          curl_setopt($oCurl, CURLOPT_URL, $url);

          curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );

          curl_setopt($oCurl, CURLOPT_POST,true);

          curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);

          $sContent = curl_exec($oCurl);

          $aStatus = curl_getinfo($oCurl);

          curl_close($oCurl);

          if(intval($aStatus["http_code"])==200){

              return $sContent;

          }else{

              return false;

          }

      }

  

  }