FyySqlServerService.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BoxDetail;
  4. use App\Model\Orders;
  5. use App\Model\SaleOrdersProduct;
  6. use Illuminate\Support\Facades\Config;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Log;
  9. use Illuminate\Support\Facades\Redis;
  10. class FyySqlServerService extends Service
  11. {
  12. public $db = null;
  13. public $error = null;
  14. public $host = "";
  15. public $port = 0;
  16. public $database = "";
  17. public $url = "";
  18. public function __construct()
  19. {
  20. $fyy_array = Redis::get('fyy_sql_server');
  21. if(empty($fyy_array)) {
  22. $this->error = 'SQLSERVER设置不存在!';
  23. return;
  24. }
  25. $fyy_array = json_decode($fyy_array,true);
  26. $this->host = $fyy_array['sqlserver_host'] ?? '';
  27. $this->port = $fyy_array['sqlserver_port'] ?? 0;
  28. $this->database = $fyy_array['sqlserver_database'] ?? '';
  29. $this->url = empty($this->host)?: "http://" . $this->host . ":12365/U8Sys/U8API";
  30. if(! $this->db){
  31. $config = [
  32. 'driver' => 'sqlsrv',
  33. 'host' => $fyy_array['sqlserver_host'] ?? '',
  34. 'port' => $fyy_array['sqlserver_port'] ?? '',
  35. 'database' => $fyy_array['sqlserver_database'] ?? '',
  36. 'username' => env('SQLSRV_USERNAME'),
  37. 'password' => env('SQLSRV_PASSWORD'),
  38. ];
  39. // 进行数据库连接
  40. Config::set('database.connections.sqlsrvs', $config);
  41. try {
  42. $pdo = DB::connection('sqlsrvs')->getPdo();
  43. if ($pdo instanceof \PDO) {
  44. // 连接成功的逻辑代码
  45. $this->db = DB::connection('sqlsrvs');
  46. } else {
  47. $this->error = '连接失败!';
  48. return;
  49. }
  50. } catch (\Throwable $e) {
  51. $this->error = $e->getMessage();
  52. }
  53. }
  54. }
  55. private function fakeData(){
  56. $return = [
  57. [
  58. 'out_order_no' => '001',
  59. 'out_order_no_time' => 1685928995,
  60. 'customer_no' => '201603012',
  61. 'customer_name' => '巴大胡',
  62. 'table_header_mark' => '表头备注',
  63. 'product_no' => '产品编码001',
  64. 'product_title' => '产品名称001',
  65. 'product_size' => '产品规格30c',
  66. 'product_unit' => '产品单位米',
  67. 'order_quantity' => 100,
  68. 'product_quantity_on_hand' => 50,
  69. 'technology_material' => '工艺材质',
  70. 'technology_name' => '工艺名称:同命',
  71. 'wood_name' => '木皮名称:梭梭树皮',
  72. 'process_mark' => '加工备注',
  73. 'table_body_mark' => '表体备注',
  74. 'out_crt_man' => '外部人员一',
  75. 'out_checker_man' => '外部人员二',
  76. 'out_checker_time' => 1685928995,
  77. ],
  78. [
  79. 'out_order_no' => '001',
  80. 'out_order_no_time' => 1685928995,
  81. 'customer_no' => '201603012',
  82. 'customer_name' => '巴大胡',
  83. 'table_header_mark' => '表头备注',
  84. 'product_no' => '产品编码002',
  85. 'product_title' => '产品名称002',
  86. 'product_size' => '产品规格30d',
  87. 'product_unit' => '产品单位米',
  88. 'order_quantity' => 100,
  89. 'product_quantity_on_hand' => 50,
  90. 'technology_material' => '工艺材质',
  91. 'technology_name' => '工艺名称:同命',
  92. 'wood_name' => '木皮名称:梭梭树皮',
  93. 'process_mark' => '加工备注',
  94. 'table_body_mark' => '表体备注',
  95. 'out_crt_man' => '外部人员一',
  96. 'out_checker_man' => '外部人员二',
  97. 'out_checker_time' => 1685928995,
  98. ],
  99. [
  100. 'out_order_no' => '002',
  101. 'out_order_no_time' => 1685928995,
  102. 'customer_no' => '201603012',
  103. 'customer_name' => '巴大胡',
  104. 'table_header_mark' => '表头备注',
  105. 'product_no' => '产品编码002',
  106. 'product_title' => '产品名称002',
  107. 'product_size' => '产品规格30d',
  108. 'product_unit' => '产品单位米',
  109. 'order_quantity' => 100,
  110. 'product_quantity_on_hand' => 50,
  111. 'technology_material' => '工艺材质',
  112. 'technology_name' => '工艺名称:同命',
  113. 'wood_name' => '木皮名称:梭梭树皮',
  114. 'process_mark' => '加工备注',
  115. 'table_body_mark' => '表体备注',
  116. 'out_crt_man' => '外部人员一',
  117. 'out_checker_man' => '外部人员二',
  118. 'out_checker_time' => 1685928995,
  119. ],
  120. ];
  121. return $return;
  122. }
  123. public function is_same_month($timestamp1,$timestamp2){
  124. date_default_timezone_set("PRC");
  125. // 格式化时间戳为年份和月份
  126. $year1 = date('Y', $timestamp1);
  127. $month1 = date('m', $timestamp1);
  128. $year2 = date('Y', $timestamp2);
  129. $month2 = date('m', $timestamp2);
  130. if ($year1 === $year2 && $month1 === $month2) {
  131. return true;
  132. } else {
  133. return false;
  134. }
  135. }
  136. //获取数据(点击引入)
  137. public function getDataFromSqlServer($data){
  138. if(! empty($this->error)) return [false,$this->error,''];
  139. if(empty($data['out_order_no_time'][0]) || empty($data['out_order_no_time'][1])) return [false,'制单日期不能为空!',''];
  140. $bool = $this->is_same_month($data['out_order_no_time'][0],$data['out_order_no_time'][1]);
  141. if(! $bool) return [false,'制单日期必须同月!',''];
  142. //查询产品主表副表数据
  143. date_default_timezone_set("PRC");
  144. $start = date('Y-m-d H:i:s.000',$data['out_order_no_time'][0]);
  145. $end = date('Y-m-d H:i:s.000',$data['out_order_no_time'][1]);
  146. $model = $this->db->table('SO_SOMain as a')
  147. ->leftJoin('SO_SODetails as b','b.cSOCode','a.cSOCode')
  148. ->whereBetween('a.dDate',[$start, $end])
  149. ->whereNotNull('a.cVerifier')
  150. ->select('a.cSOCode as out_order_no','a.dDate as out_order_no_time','a.cCusCode as customer_no','a.cCusName as customer_name','a.cMemo as table_header_mark','a.cMaker as out_crt_man','a.cVerifier as out_checker_man','a.dverifydate as out_checker_time','b.cInvCode as product_no','b.iQuantity as order_quantity','b.cDefine28 as technology_material','b.cFree1 as technology_name','b.cFree2 as wood_name','b.cDefine30 as process_mark','b.cMemo as table_body_mark','b.iTaxUnitPrice as price');
  151. if(! empty($data['out_order_no'])) $model->where('a.cSOCode', 'LIKE', '%'.$data['out_order_no'].'%');
  152. if(! empty($data['customer_no'])) $model->where('a.cCusCode', 'LIKE', '%'.$data['customer_no'].'%');
  153. if(! empty($data['customer_name'])) $model->where('a.cCusName', 'LIKE', '%'.$data['customer_name'].'%');
  154. if(! empty($data['table_header_mark'])) $model->where('a.cMemo', 'LIKE', '%'.$data['table_header_mark'].'%');
  155. if(! empty($data['out_crt_man'])) $model->where('a.cMaker', 'LIKE', '%'.$data['out_crt_man'].'%');
  156. if(! empty($data['out_checker_man'])) $model->where('a.cVerifier', 'LIKE', '%'.$data['out_checker_man'].'%');
  157. if(! empty($data['out_checker_time'][0]) && ! empty($data['out_checker_time'][1])) {
  158. $start1 = date('Y-m-d H:i:s.000',$data['out_checker_time'][0]);
  159. $end1 = date('Y-m-d H:i:s.000',$data['out_checker_time'][1]);
  160. $model->whereBetween('a.dverifydate',[$start1, $end1]);
  161. }
  162. $result = $model->get()->toArray();
  163. if(empty($result)) return [false,'暂无数据,更新结束!',''];
  164. list($status,$msg) = $this->orderRule($result);
  165. if(empty($msg)) return [false,'暂无数据,更新结束!',''];
  166. $result = $msg;
  167. //查询附带的一些信息(比较少)
  168. $product_no = array_column($result,'product_no');
  169. $messageOne = $this->db->table('Inventory as a')
  170. ->join('ComputationUnit as b',function($join){
  171. $join->on('a.cGroupCode','=','b.cGroupCode')
  172. ->on('a.cComUnitCode','=','b.cComUnitCode');
  173. }, null,null,'left')
  174. ->whereIn('a.cInvCode',$product_no)
  175. ->select('a.cInvCode as product_no','a.cInvName as product_title','a.cInvStd as product_size','b.cComUnitName as product_unit')
  176. ->get()->toArray();
  177. $messageMap = array_column($messageOne,null,'product_no');
  178. //现存量查询开始 ---组织查询条件
  179. $args = '';
  180. foreach ($result as $value){
  181. $product = $value->product_no;
  182. $technology_name = $value->technology_name ?? '';
  183. $wood_name = $value->wood_name ?? '';
  184. $args .= "(a.cInvCode = '{$product}' and a.cFree1 = '{$technology_name}' and a.cFree2 = '{$wood_name}') OR ";
  185. }
  186. $args = rtrim($args,'OR ');
  187. $messageTwo = $this->db->table('CurrentStock as a')
  188. ->leftJoin('Warehouse as b','b.cWhCode','a.cWhCode')
  189. ->whereRaw("($args)")
  190. ->where('a.iQuantity','>',0)
  191. ->select('a.iQuantity as product_quantity_on_hand','a.cInvCode as product_no','a.cFree1 as technology_name','a.cFree2 as wood_name','b.cWhName as warehouse_name')
  192. ->get()->toArray();
  193. if(! empty($messageTwo)){
  194. foreach ($messageTwo as $key => $value){
  195. $messageTwo[$key] = (array)$value;
  196. }
  197. }
  198. //现存量查询结束
  199. foreach ($result as $key => $value){
  200. $result[$key]->technology_material = $value->technology_material ?? '';
  201. $result[$key]->technology_name = $value->technology_name ?? '';
  202. $result[$key]->wood_name = $value->wood_name ?? '';
  203. $result[$key]->process_mark = $value->process_mark ?? '';
  204. $result[$key]->table_body_mark = $value->table_body_mark ?? '';
  205. $result[$key]->table_header_mark = $value->table_header_mark ?? '';
  206. $keys = $value->product_no . $value->technology_name . $value->wood_name;
  207. $result[$key]->out_order_no_time = $value->out_order_no_time ? strtotime($value->out_order_no_time) : 0;
  208. $result[$key]->out_checker_time = $value->out_checker_time ? strtotime($value->out_checker_time) : 0;
  209. $result[$key]->product_title = $messageMap[$value->product_no]->product_title ?? '';
  210. $result[$key]->product_size = $messageMap[$value->product_no]->product_size ?? '';
  211. $result[$key]->product_unit = $messageMap[$value->product_no]->product_unit ?? '';
  212. $result[$key] = (array)$value;
  213. }
  214. return [true,$result,$messageTwo];
  215. }
  216. public function orderRule($data){
  217. $result = Orders::where('del_time',0)
  218. ->whereIn('out_order_no',array_column($data,'out_order_no'))
  219. ->select('out_order_no')
  220. ->get()->toArray();
  221. $out_order_no = array_column($result,'out_order_no');
  222. if(! empty($out_order_no)) {
  223. foreach ($data as $key => $value){
  224. if(in_array($value->out_order_no,$out_order_no)){
  225. unset($data[$key]);
  226. }
  227. }
  228. }
  229. return [true,$data];
  230. }
  231. //获取数据(刷新现存量)
  232. public function getDataFromSqlServerForOnHand($data){
  233. if(! empty($this->error)) return [false,$this->error,''];
  234. if(empty($data['id'])) return [false,'数据不能为空!',''];
  235. $product = SaleOrdersProduct::whereIn('id',$data['id'])
  236. ->select('product_no','technology_name','wood_name')
  237. ->get()->toArray();
  238. //现存量查询开始 ---组织查询条件
  239. $args = '';
  240. foreach ($product as $value){
  241. $args .= "(a.cInvCode = '{$value['product_no']}' and a.cFree1 = '{$value['technology_name']}' and a.cFree2 = '{$value['wood_name']}') OR ";
  242. }
  243. $args = rtrim($args,'OR ');
  244. $message = $this->db->table('CurrentStock as a')
  245. ->leftJoin('Warehouse as b','b.cWhCode','a.cWhCode')
  246. ->whereRaw("($args)")
  247. ->where('a.iQuantity','>',0)
  248. ->select('a.iQuantity as product_quantity_on_hand','a.cInvCode as product_no','a.cFree1 as technology_name','a.cFree2 as wood_name','b.cWhName as warehouse_name')
  249. ->get()->toArray();
  250. if(! empty($message)){
  251. foreach ($message as $key => $value){
  252. $message[$key] = (array)$value;
  253. }
  254. }
  255. //现存量查询结束
  256. return [true,$message,$product];
  257. }
  258. //产成品入库单保存接口以及审核
  259. public function U8Rdrecord10Save($data,$bredvouch = 0){
  260. if(! empty($this->error)) return [false,$this->error];
  261. date_default_timezone_set("PRC");
  262. list($bool,$msg) = $this->createOrderNumberAboutSCRK();
  263. if(! $bool) return [false,$msg];
  264. if($bredvouch){
  265. $cmemo = '来源:福羊羊完工操作撤回';
  266. }else{
  267. $cmemo = '来源:福羊羊完工操作 派工单号:'. $data['dispatch_no'];
  268. }
  269. //数据
  270. $bodys[] = [
  271. "cinvcode" => $data["product_no"],
  272. "cposition" => "",
  273. "cbatch" => "",
  274. "iquantity" => $data["quantity"],
  275. "inum" => $data["quantity"],
  276. "iunitcost" => $data["price"] * 0.95,
  277. "iprice" => $data["price"] * 0.95 * $data['quantity'],
  278. "iinvexchrate" => "1.00",
  279. "impoids" => "",
  280. "cmocode" => "",
  281. "imoseq" => "",
  282. "cbmemo" => "",
  283. "cfree1" => "",
  284. "cfree2" => "",
  285. ];
  286. $post = [
  287. "password"=>"cloud@123456",
  288. "entity"=>"U8Rdrecord10Save",
  289. "login"=>[
  290. "sAccID"=> "(default)@001",
  291. "sDate"=> date("Y-m-d"),
  292. "sServer"=> '127.0.0.1',
  293. "sUserID"=> "董晓磊",
  294. "sSerial"=> "",
  295. "sPassword"=> ""
  296. ],
  297. "data"=>[
  298. "ccode"=>'',
  299. "ddate"=>date("Y-m-d"),
  300. "cmaker"=>"董晓磊",
  301. "dnmaketime"=> date("Y-m-d"),
  302. "IsExamine"=>true,
  303. "bredvouch"=> $bredvouch,
  304. "cwhcode"=>"02",
  305. "cdepcode"=>"06",
  306. "crdcode"=>"102", //生产入库
  307. "cmemo"=> $cmemo,
  308. "cdefine10" => $data['customer_name'], //客户名称
  309. "bodys"=>$bodys
  310. ]
  311. ];
  312. $return = $this->post_helper($this->url,json_encode($post), ['Content-Type:application/json']);
  313. return [$return['flag'], $return['msg']];
  314. }
  315. //销售出库单保存接口给以及审核
  316. public function U8Rdrecord32Save($data,$bredvouch = 0){
  317. if(! empty($this->error)) return [false,$this->error];
  318. date_default_timezone_set("PRC");
  319. //获取包装单内数据
  320. $box = $this->getBoxData($data);
  321. if(empty($box)) return [false,'包装单不能为空!'];
  322. //获取发货单的数据
  323. $return = $this->getDataFromDispatchList(array_column($box,'cSOCode'));
  324. if(empty($return)) return [false,'没有找到发货单!'];
  325. //组织发货单的数据
  326. $map = [];
  327. foreach ($return as $value){
  328. $map[$value['cSOCode']][] = $value;
  329. }
  330. $detail = [];
  331. foreach ($box as $value){
  332. if(! isset($map[$value['cSOCode']])) {
  333. return [false,'包装单内销售订单号:' . $value['cSOCode'] .'没有找到发货单!'];
  334. }
  335. $is_flag = 0;
  336. foreach ($map[$value['cSOCode']] as $m){
  337. if($value['cinvcode'] == $m['cinvcode'] && $value['cfree1'] == $m['cfree1'] && $value['cfree2'] == $m['cfree2']) {
  338. $is_flag = 1;
  339. $m['iquantity'] = $value['iquantity'];
  340. $detail[$m['cSOCode']][] = $m;
  341. }
  342. }
  343. if(! $is_flag) return [false,'包装单内销售订单号:' . $value['cSOCode'] .'产品:' . $value['cinvcode'] . $value['cfree1'] . $value['cfree2'] . '在发货单中不存在!'];
  344. }
  345. foreach ($detail as $value){
  346. $main_tmp = $value[0];
  347. foreach ($value as $val){
  348. $bodys_tmp[] = [
  349. "idlsid"=>$val['idlsid'],
  350. "cdlcode"=>"",
  351. "dlrowno"=>"",
  352. "cbdlcode"=>"",
  353. "cinvcode"=>$val['cinvcode'],
  354. "cposition"=>$val['cposition'],
  355. "cbatch"=>$val['cbatch'],
  356. "iquantity"=>$val['iquantity'],
  357. "inum"=>$val['iquantity'],
  358. "iinvexchrate"=>$value['iinvexchrate'],
  359. "iunitcost"=>"",
  360. "iprice"=>"",
  361. "cbmemo"=>"",
  362. ];
  363. }
  364. $post_tmp = [
  365. "password"=>"cloud@123456",
  366. "entity"=>"U8Rdrecord32Save",
  367. "login"=>[
  368. "sAccID"=> "(default)@001",
  369. "sDate"=> date("Y-m-d"),
  370. "sServer"=> '127.0.0.1',
  371. "sUserID"=> "董晓磊",
  372. "sSerial"=> "",
  373. "sPassword"=> ""
  374. ],
  375. "data"=>[
  376. "ccode"=>'',
  377. "ddate"=>date("Y-m-d"),
  378. "cmaker"=>"董晓磊",
  379. "dnmaketime"=> date("Y-m-d"),
  380. "IsExamine"=>true,
  381. "bredvouch"=> $bredvouch,
  382. "cwhcode"=>"02",
  383. "cdepcode"=>"06",
  384. "crdcode"=>"102",
  385. "cmemo"=> '',
  386. "cdefine10" => $main_tmp['customer_name'], //客户名称
  387. "bodys"=>$bodys_tmp
  388. ]
  389. ];
  390. $return = $this->post_helper($this->url,json_encode($post_tmp), ['Content-Type:application/json']);
  391. if(! $return['flag']) return [false,$return['msg']];
  392. }
  393. return [true,''];
  394. }
  395. public function getBoxData($data){
  396. $boxData = BoxDetail::from('box_detail as a')
  397. ->leftJoin('sale_orders_product as b','b.id','a.top_id')
  398. ->where('a.del_time',0)
  399. ->where('a.order_no',$data['order_number']) //包装单号
  400. ->select('a.num as iquantity','b.product_no as cinvcode','b.technology_name as cfree1','b.wood_name as cfree2','b.out_order_no as cSOCode');
  401. return $boxData;
  402. }
  403. public function getDataFromDispatchList($order_number){
  404. $message = $this->db->table('DispatchList as a')
  405. ->leftJoin('DispatchLists as b','b.DLID','a.DLID')
  406. ->whereIn('a.cSOcode',$order_number)
  407. // ->whereColumn('b.iQuantity', '>', 'b.fOutQuantity')
  408. ->select('a.cDefine10 as customer_name','a.cSOCode','b.iDLsID as idlsid','b.cInvCode as cinvcode','b.cFree1 as cfree1','b.cFree2 as cfree2','b.cPosition as cposition','b.cBatch as cbatch','b.iQuantity as iquantity','b.iNum as inum','b.iInvExchRate as iinvexchrate','b.fOutQuantity as out_quantity')
  409. ->get()->toArray();
  410. if(! empty($message)){
  411. foreach ($message as $key => $value){
  412. // $message[$key]->iquantity = $value->iquantity - $value->out_quantity;
  413. $message[$key] = (array)$value;
  414. }
  415. }
  416. return $message;
  417. }
  418. //产成品入库单单据号
  419. public function createOrderNumberAboutSCRK(){
  420. date_default_timezone_set("PRC");
  421. $current_month = date('m'); // 获取当前月份
  422. $date1 = date('y') . $current_month ; // 格式 "2307"
  423. $date2 = date('Y') . $current_month; // 格式 "202307"
  424. $record = $this->db->table('VoucherHistory')
  425. ->where('CardNumber','0411')
  426. ->whereRaw("(cSeed = '{$date1}' or cSeed = '{$date2}')")
  427. ->select('cNumber')
  428. ->first();
  429. $record = (array)$record;
  430. if(empty($record)) return [false,'未找到产成品入库当月流水号信息!'];
  431. $tmp = $record['cNumber'] + 1;
  432. if(strlen($tmp) > 4) return [false,'产成品入库当月流水号超过四位数!'];
  433. $number = str_pad($tmp,4,'0',STR_PAD_LEFT);
  434. $number = $tmp . $number;
  435. $ccode = "SCRK" . $date2 . $number;
  436. return [true,$ccode];
  437. }
  438. //销售出库单单据号
  439. public function createOrderNumberAboutXC(){
  440. date_default_timezone_set("PRC");
  441. $current_month = date('m'); // 获取当前月份
  442. $date1 = date('y') . $current_month ; // 格式 "2307"
  443. $date2 = date('Y') . $current_month; // 格式 "202307"
  444. $record = $this->db->table('VoucherHistory')
  445. ->where('CardNumber','0303')
  446. ->whereRaw("(cSeed = '{$date1}' or cSeed = '{$date2}')")
  447. ->select('cNumber')
  448. ->first();
  449. $record = (array)$record;
  450. if(empty($record)) return [false,'未找到销售出库单当月流水号信息!'];
  451. $tmp = $record['cNumber'] + 1;
  452. if(strlen($tmp) > 4) return [false,'销售出库单当月流水号超过四位数!'];
  453. $number = str_pad($tmp,4,'0',STR_PAD_LEFT);
  454. $number = $tmp . $number;
  455. $ccode = "XC" . $date2 . $number;
  456. return [true,$ccode];
  457. }
  458. public function post_helper($url, $data,$header = [],$timeout = 60){
  459. $ch = curl_init();
  460. curl_setopt($ch, CURLOPT_URL, $url);
  461. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  462. curl_setopt($ch, CURLOPT_ENCODING, '');
  463. curl_setopt($ch, CURLOPT_POST, 1);
  464. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  465. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  466. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  467. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  468. if(!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  469. $r = curl_exec($ch);
  470. curl_close($ch);
  471. return json_decode($r, true);
  472. }
  473. }