You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

868 lines
29 KiB

  1. <?php
  2. /**
  3. * 全局通用方法集合
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm Util.php
  13. * Create By 2017/2/22 19:44 $
  14. */
  15. namespace common\util;
  16. use common\models\AdmUser;
  17. use common\models\FxUser;
  18. use common\models\LogUserOperation;
  19. use common\models\OrderMain;
  20. use common\models\ProdCategory;
  21. use common\models\ShUser;
  22. use yii\base\Exception;
  23. class Util
  24. {
  25. /**微信配置参数**/
  26. private static $weChatConfig = null;
  27. private static $siteConfig = null;
  28. private static $aliPayConfig = null;
  29. /**
  30. * Des:获取配置参数
  31. * Name: getSiteConfig
  32. * @return null
  33. * @author 倪宗锋
  34. */
  35. public static function getSiteConfig()
  36. {
  37. if (static::$siteConfig == null) {
  38. static::$siteConfig = \Yii::$app->params;
  39. }
  40. return static::$siteConfig;
  41. }
  42. /**
  43. * Des:配置参数部分设置 慎用
  44. * Name: setSiteConfig
  45. * @param $key
  46. * @param $val
  47. * @author 倪宗锋
  48. */
  49. public static function setSiteConfig($key, $val)
  50. {
  51. $setConfig = static::getSiteConfig();
  52. $setConfig[$key] = $val;
  53. static::$weChatConfig = null;
  54. static::$aliPayConfig = null;
  55. static::$siteConfig = $setConfig;
  56. }
  57. /**
  58. * Function Description:获取参数配置
  59. * Function Name: getAliPayConfig
  60. * @param $app_id string
  61. * @return array
  62. *
  63. * @author 倪宗�?
  64. */
  65. public static function getAliPayConfig($app_id = '')
  66. {
  67. if (self::$aliPayConfig == null) {
  68. $payConfig = require ROOT_PATH . '/common/config/aliConfig/payConfig.php';
  69. self::$aliPayConfig = $payConfig;
  70. }
  71. if (empty($app_id)) {
  72. $setConfig = static::getSiteConfig();
  73. $app_id = $setConfig['aliPay'];
  74. }
  75. return self::$aliPayConfig[$app_id];
  76. }
  77. /**
  78. * Function Description:返回成功Json数据到
  79. * Function Name: returnSu
  80. * @param string $msg 提示信息
  81. * @param string $url 跳转地址
  82. * @param string|array $data 需要传递的数据
  83. * @param string $code 错误码
  84. *
  85. * @return string
  86. *
  87. * @author 倪宗锋
  88. */
  89. public static function returnJsSu($msg = '', $data = '', $url = '', $code = '')
  90. {
  91. $return = array();
  92. $return['flag'] = true;
  93. $return['msg'] = $msg;
  94. $return['url'] = $url;
  95. $return['code'] = $code;
  96. $return['data'] = $data;
  97. return json_encode($return);
  98. }
  99. /**
  100. * Function Description:返回成功Json数据
  101. * Function Name: returnEr
  102. * @param string $msg 提示信息
  103. * @param string $url 跳转地址
  104. * @param string|array $data 需要传递的数据
  105. * @param string $code 错误码
  106. *
  107. * @return string
  108. *
  109. * @author 倪宗锋
  110. */
  111. public static function returnJsEr($msg = '', $data = '', $url = '', $code = '')
  112. {
  113. $return = array();
  114. $return['flag'] = false;
  115. $return['msg'] = $msg;
  116. $return['url'] = $url;
  117. $return['code'] = $code;
  118. $return['data'] = $data;
  119. return json_encode($return);
  120. }
  121. /**
  122. * Function Description:返回成功数组数据
  123. * Function Name: returnArrSu
  124. * @param string $msg 提示信息
  125. * @param string $url 跳转地址
  126. * @param string|array $data 需要传递的数据
  127. * @param string $code 错误码
  128. *
  129. * @return array
  130. *
  131. * @author 倪宗锋
  132. */
  133. public static function returnArrSu($msg = '', $data = '', $url = '', $code = '')
  134. {
  135. $return = array();
  136. $return['flag'] = true;
  137. $return['msg'] = $msg;
  138. $return['url'] = $url;
  139. $return['code'] = $code;
  140. $return['data'] = $data;
  141. return $return;
  142. }
  143. /**
  144. * Function Description:返回错误数组数据
  145. * Function Name: returnArrEr
  146. * @param string $msg 提示信息
  147. * @param string $url 跳转地址
  148. * @param string|array $data 需要传递的数据
  149. * @param string $code 错误码
  150. *
  151. * @return array
  152. *
  153. * @author 倪宗锋
  154. */
  155. public static function returnArrEr($msg = '', $data = '', $url = '', $code = '')
  156. {
  157. $return = array();
  158. $return['flag'] = false;
  159. $return['msg'] = $msg;
  160. $return['url'] = $url;
  161. $return['code'] = $code;
  162. $return['data'] = $data;
  163. return $return;
  164. }
  165. /**
  166. * Des:获取微信配置文件
  167. * Name: getWeChatConfig
  168. * @param $app_id string
  169. * @return array
  170. * @author 倪宗锋
  171. */
  172. public static function getWeChatConfig($app_id = '')
  173. {
  174. if (static::$weChatConfig == null) {
  175. $weChatConfigs = require ROOT_PATH . '/common/config/wechatConfig/payConfig.php';
  176. static::$weChatConfig = $weChatConfigs;
  177. }
  178. if (empty($app_id)) {
  179. $setConfig = static::getSiteConfig();
  180. $app_id = $setConfig['entryAuthWeChat'];
  181. }
  182. return static::$weChatConfig[$app_id];
  183. }
  184. /**
  185. * Function Description:校验字符串的正则
  186. * Function Name: checkPattern
  187. * @param $type string 已有正则的key
  188. * @param $str string 校验的字符串
  189. * @param string $Regex 校验规则 固若该值不为空 则使用该正则校验 $type失效
  190. *
  191. * @return bool
  192. *
  193. * @author 倪宗锋 2016-11-10
  194. */
  195. public static function checkPattern($type, $str, $Regex = '')
  196. {
  197. if ($Regex == '') {
  198. $pattern = require(ROOT_PATH . '/common/config/checkParams.php');
  199. if (empty($pattern[$type])) {//正则不存在 则验证失败
  200. return false;
  201. }
  202. $Regex = $pattern[$type];
  203. }
  204. if (is_array($str)) {
  205. foreach ($str as $val) {
  206. if (!preg_match($Regex, $val)) {
  207. return false;
  208. }
  209. }
  210. return true;
  211. } else {
  212. if (preg_match($Regex, $str)) {
  213. return true;
  214. } else {
  215. return false;
  216. }
  217. }
  218. }
  219. /**
  220. * Function Description:json转换为xml
  221. * Function Name: jsonToXml
  222. * @param $json
  223. *
  224. * @return bool|string
  225. *
  226. * @author 倪宗锋
  227. */
  228. public static function jsonToXml($json)
  229. {
  230. if (empty($json)) {
  231. return false;
  232. }
  233. $array = json_decode($json);
  234. $xml = '';
  235. $xml .= '<?xml version="1.0" encoding="UTF-8"?>' . self::arraysToXml(['response' => $array]);
  236. return $xml;
  237. }
  238. /**
  239. * Function Description:数组转换成xml
  240. * Function Name: arrayToXml
  241. * @param $array
  242. * @param $key
  243. * @return string
  244. *
  245. * @author 倪宗锋
  246. */
  247. public static function arraysToXml($array, $key = '')
  248. {
  249. $string = '';
  250. if (count($array) == 0) {
  251. return '';
  252. }
  253. foreach ($array as $k => $v) {
  254. if (is_array($v) && isset($v['0'])) {
  255. $string .= self::arraysToXml($v, $k);//是数组或者对像就的递归调用
  256. } else {
  257. if ($key != '') {
  258. $k = $key;
  259. }
  260. $string .= '<' . $k . '>';
  261. if (is_array($v) || is_object($v)) {//判断是否是数组,或者,对像
  262. $string .= self::arraysToXml($v);//是数组或者对像就的递归调用
  263. } elseif (is_numeric($v)) {
  264. $string .= $v;
  265. } elseif ($v != '') {
  266. $string .= '<![CDATA[' . $v . ']]>';
  267. } else {
  268. $string .= '';
  269. }
  270. $string .= '</' . $k . '>';
  271. }
  272. }
  273. return $string;
  274. }
  275. /**
  276. * Function Description:xml转换为json
  277. * Function Name: xml_to_json
  278. * @param $source
  279. *
  280. * @return string
  281. *
  282. * @author 倪宗锋
  283. */
  284. public static function xmlToJson($source)
  285. {
  286. if (is_file($source)) { //传的是文件,还是xml的string的判断
  287. $xml_array = simplexml_load_file($source);
  288. } else {
  289. $xml_array = simplexml_load_string(trim($source));
  290. }
  291. $json = json_encode($xml_array, true);
  292. return $json;
  293. }
  294. /**
  295. * Function Description:xml转换成数组
  296. * Function Name: xmlToArray
  297. * @param $source
  298. *
  299. * @return mixed
  300. *
  301. * @author 倪宗锋
  302. */
  303. public static function xmlToArray($source)
  304. {
  305. libxml_disable_entity_loader(true);
  306. $getResult = json_decode(json_encode(simplexml_load_string(trim($source), 'SimpleXMLElement', LIBXML_NOCDATA)), true);
  307. return $getResult;
  308. }
  309. /** Function Description:加密解密函数
  310. * Function Name: authCode
  311. * @param $string
  312. * @param string $operation
  313. * @param int $expiry
  314. * @return string|array
  315. * @author 倪宗锋
  316. */
  317. static function authCode($string, $operation = 'DECODE', $expiry = 0)
  318. {
  319. $key = 'udM5A8S50eg8veH15dd0m601de7073N8Bcn7d1I8Res7C7o7z274D6y342I4C7t7';
  320. $ckey_length = 4; // 随机密钥长度 取值 0-32;
  321. // 加入随机密钥,可以令密文无任何规律,即便是原文和密钥完全相同,加密结果也会每次不同,增大破解难度。
  322. // 取值越大,密文变动规律越大,密文变化 = 16 的 $ckey_length 次方
  323. // 当此值为 0 时,则不产生随机密钥
  324. $key = md5($key);
  325. $keya = md5(substr($key, 0, 16));
  326. $keyb = md5(substr($key, 16, 16));
  327. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
  328. $cryptkey = $keya . md5($keya . $keyc);
  329. $key_length = strlen($cryptkey);
  330. $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
  331. $string_length = strlen($string);
  332. $result = '';
  333. $box = range(0, 255);
  334. $rndkey = array();
  335. for ($i = 0; $i <= 255; $i++) {
  336. $rndkey[$i] = ord($cryptkey[$i % $key_length]);
  337. }
  338. for ($j = $i = 0; $i < 256; $i++) {
  339. $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  340. $tmp = $box[$i];
  341. $box[$i] = $box[$j];
  342. $box[$j] = $tmp;
  343. }
  344. for ($a = $j = $i = 0; $i < $string_length; $i++) {
  345. $a = ($a + 1) % 256;
  346. $j = ($j + $box[$a]) % 256;
  347. $tmp = $box[$a];
  348. $box[$a] = $box[$j];
  349. $box[$j] = $tmp;
  350. $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
  351. }
  352. if ($operation == 'DECODE') {
  353. if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
  354. return substr($result, 26);
  355. } else {
  356. return '';
  357. }
  358. } else {
  359. return $keyc . str_replace('=', '', base64_encode($result));
  360. }
  361. }
  362. /**
  363. * Des: 生成二维码
  364. * Name: addQRCode
  365. * @param $qCode string 生成的内容
  366. * @param $QRFile string 二维码图片路径
  367. * @param int $reType 1:返回成功或失败 2 返回图片数据流
  368. * @param bool|false $isCreate 生成的图片是否保留 当$reType=2才会有效
  369. * @param bool $logo 是否添加logo图
  370. * @param string $logoUrl logo图地址
  371. * @return array
  372. * @author 倪宗锋
  373. */
  374. public static function addQRCode($qCode, $QRFile, $reType = 1, $isCreate = false, $logo = false, $logoUrl = '')
  375. {
  376. include ROOT_PATH . '/common/util/phpqrcode/phpqrcode.php';
  377. $value = $qCode;//二维码内容
  378. $errorCorrectionLevel = 'H';//容错级别
  379. $matrixPointSize = 6;//生成图片大小
  380. //生成二维码图片
  381. \QRcode::png($value, $QRFile, $errorCorrectionLevel, $matrixPointSize, 2);
  382. $QR = imagecreatefromstring(file_get_contents($QRFile));
  383. if ($logo !== FALSE && $logoUrl != '') {
  384. $logoUrl = imagecreatefromstring(file_get_contents($logoUrl));
  385. $QR_width = imagesx($QR);//二维码图片宽度
  386. $logo_width = imagesx($logoUrl);//logo图片宽度
  387. $logo_height = imagesy($logoUrl);//logo图片高度
  388. $logo_qr_width = $QR_width / 5;
  389. $scale = $logo_width / $logo_qr_width;
  390. $logo_qr_height = $logo_height / $scale;
  391. $from_width = ($QR_width - $logo_qr_width) / 2;
  392. //重新组合图片并调整大小
  393. imagecopyresampled($QR, $logoUrl, $from_width, $from_width, 0, 0, $logo_qr_width,
  394. $logo_qr_height, $logo_width, $logo_height);
  395. }
  396. //只返回成功失败的话 则图片必须保存
  397. if ($reType == 1) {
  398. @ImagePng($QR, $QRFile);
  399. if (file_exists($QRFile)) {
  400. return Util::returnArrSu();
  401. }
  402. return Util::returnArrEr('图片生成失败!');
  403. } else {
  404. //输出图片
  405. Header("Content-type: image/png");
  406. ImagePng($QR);
  407. if ($isCreate == false) {//不保存图片则删除
  408. @unlink($QRFile);
  409. } else {//保存则需图片再生成一次
  410. @ImagePng($QR, $QRFile);
  411. }
  412. die;
  413. }
  414. }
  415. /**
  416. * Function Description:调用CS接口时的加密规则
  417. * Function Name: authCodeForCs
  418. * @param $request_time string
  419. * @return string
  420. *
  421. * @author 娄梦宁
  422. */
  423. public static function authCodeForCs($request_time)
  424. {
  425. $siteConfig = static::getSiteConfig();
  426. $user = $siteConfig['adm_user'];
  427. $user_key = $siteConfig['adm_user_key'];
  428. //加密规则为 request_time(linux时间戳)前三位作为种子,调用srand生成随机数 + user + user_key,进行MD5加密后,换成大写字母
  429. $auth_code = strtoupper(md5(substr($request_time, 0, 3) . "|" . $user . "|" . $user_key . "|" . substr($request_time, strlen($request_time) - 3, 3)));
  430. return $auth_code;
  431. }
  432. /**
  433. * Des:发送验证码
  434. * Name: sendMessage
  435. * @param $msg
  436. * @param $phones
  437. * @return array
  438. * @author 倪宗锋
  439. */
  440. public static function sendMessage($msg, $phones)
  441. {
  442. $phoneArr = explode(',', $phones);
  443. $siteConfig = static::getSiteConfig();
  444. foreach ($phoneArr as $phone) {
  445. $send_data = array();
  446. $send_data["account"] = "dh78301";
  447. $send_data["password"] = strtolower(md5("jGRk34B7"));
  448. $send_data["sign"] = "【{$siteConfig['msg_web_name']}】";
  449. $send_data["phones"] = $phone;
  450. $send_data["content"] = $msg;
  451. $url = 'http://www.dh3t.com/json/sms/Submit';
  452. $curlInterface = new CurlInterface($send_data, 1);
  453. $result = $curlInterface->execute($url, 'POST');
  454. if (!isset($result['result']) || $result['result'] != '0') {
  455. return Util::returnArrSu('验证码发送成功');
  456. }
  457. }
  458. return Util::returnArrSu('验证码发送成功');
  459. }
  460. /**
  461. * 检测是微信还是支付宝 1、微信 2、支付宝 3、其他
  462. * @return string
  463. */
  464. public static function checkWeChatOrAliPay()
  465. {
  466. $header = \Yii::$app->request->getHeaders();
  467. $user_agent = $header['user-agent'];
  468. //判断是不是微信
  469. if (preg_match('/MicroMessenger/i', $user_agent)) {
  470. return 1;
  471. }
  472. if (preg_match('/AlipayClient/i', $user_agent)) {
  473. return 2;
  474. }
  475. return 3;
  476. }
  477. /**
  478. * Des:发送信息到RTX
  479. * Name: sendMsgRTX
  480. * @param string $receiverList
  481. * @param $title
  482. * @param $msg
  483. * @author 倪宗锋
  484. */
  485. public static function sendMsgRTX($receiverList = 'nizf', $title, $msg)
  486. {
  487. $arr = array(
  488. 'agentid' => '1000004',
  489. 'title' => $title,
  490. 'msg' => substr($msg, 0, 1024),
  491. 'touser' => $receiverList
  492. );
  493. $curl = new CurlInterface($arr, 1);
  494. $curl->execute('http://cs1.zhizhuchuxing.com/hotel/hotel/send-msg', 'POST');
  495. }
  496. /**
  497. * Des: 获取地图两点间的距离
  498. * Name: getDistance
  499. * @param $params array
  500. * start_latitude double 纬度值
  501. * start_longitude double 经度值
  502. * end_latitude double 纬度值
  503. * end_longitude double 经度值
  504. * @return float
  505. * @author 倪宗锋
  506. */
  507. public static function getDistance($params)
  508. {
  509. $earthRadius = 6367000; //approximate radius of earth in meters
  510. $lat1 = ($params['start_latitude'] * pi()) / 180;
  511. $lng1 = ($params['start_longitude'] * pi()) / 180;
  512. $lat2 = ($params['end_latitude'] * pi()) / 180;
  513. $lng2 = ($params['end_longitude'] * pi()) / 180;
  514. $calcLongitude = $lng2 - $lng1;
  515. $calcLatitude = $lat2 - $lat1;
  516. $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
  517. $stepTwo = 2 * asin(min(1, sqrt($stepOne)));
  518. $calculatedDistance = $earthRadius * $stepTwo;
  519. return round($calculatedDistance);
  520. }
  521. /**
  522. * Des:发送cs请求
  523. * Name: sendCs
  524. * @param $send_data
  525. * @param $url
  526. * @param int $hostType
  527. * @param int $system
  528. * @return array
  529. * @author 倪宗锋
  530. */
  531. public static function sendCs($send_data, $url, $hostType = 1, $system = 2)
  532. {
  533. $siteConfig = Util::getSiteConfig();
  534. $siteConfig['adm_user_id'] = $siteConfig['adm_user_arr'][$system]['adm_user_id'];//重置配置
  535. $siteConfig['adm_source_id'] = $siteConfig['adm_user_arr'][$system]['adm_source_id'];//重置配置
  536. $time = time();
  537. $send_data['auth_code'] = Util::authCodeForCs($time);
  538. $send_data['user_key'] = $siteConfig['adm_user_key'];
  539. $send_data['user'] = $siteConfig['adm_user'];
  540. $send_data['request_time'] = $time;
  541. //用户标识
  542. $send_data['CreateUserID'] = $siteConfig['adm_user_id'];
  543. $send_data['user_id'] = $siteConfig['adm_user_id'];
  544. //渠道标识
  545. $send_data['org_id'] = $siteConfig['adm_source_id'];
  546. $send_data['DistribID'] = $siteConfig['adm_source_id'];
  547. $curlInterface = new CurlInterface($send_data, 4);
  548. if ($hostType == 1) {
  549. $host = $siteConfig['adm_host'];
  550. } else {
  551. $host = $siteConfig['adm_host1'];
  552. }
  553. $result = $curlInterface->execute($host . $url, 'POST');
  554. if (isset($result['code']) && $result['code'] == '0') {
  555. return Util::returnArrSu('', $result);
  556. } else {
  557. $msg = empty($result['info']) ? '系统繁忙,请稍后再试' : $result['info'];
  558. return Util::returnArrEr($msg, $result);
  559. }
  560. }
  561. /**
  562. * Des:Des:GCJ-02(火星,高德)坐标 转换成 BD-09(百度)坐标
  563. * Name: bd_encrypt
  564. * @param $gg_lon float 高德经度
  565. * @param $gg_lat float 高德纬度
  566. * @return mixed
  567. * @author 倪宗锋
  568. */
  569. static function bd_encrypt($gg_lon, $gg_lat)
  570. {
  571. $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  572. $x = $gg_lon;
  573. $y = $gg_lat;
  574. $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
  575. $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
  576. $data['bd_lon'] = $z * cos($theta) + 0.0065;
  577. $data['bd_lat'] = $z * sin($theta) + 0.006;
  578. return $data;
  579. }
  580. /**
  581. * Des:BD-09(百度) 坐标转换成 GCJ-02(火星,高德) 坐标
  582. * Name: bd_decrypt
  583. * @param $bd_lon float 百度经度
  584. * @param $bd_lat float 百度纬度
  585. * @return mixed
  586. * @author 倪宗锋
  587. */
  588. static function bd_decrypt($bd_lon, $bd_lat)
  589. {
  590. $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  591. $x = $bd_lon - 0.0065;
  592. $y = $bd_lat - 0.006;
  593. $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
  594. $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
  595. $data['gg_lon'] = $z * cos($theta);
  596. $data['gg_lat'] = $z * sin($theta);
  597. return $data;
  598. }
  599. /**
  600. * Des:获取出租车计价 公里数为直线距离上浮百分之二十
  601. * Name: getTaxiMoney
  602. * @param $distance
  603. * @return float|int
  604. * @author 倪宗锋
  605. */
  606. public static function getTaxiMoney($distance)
  607. {
  608. $distance = round($distance * 1.5);
  609. if ($distance <= 3) {
  610. $money = 14;
  611. } elseif ($distance > 3 && $distance < 10) {//小于10公里,
  612. $money = ($distance - 3) * 2.4 + 14;
  613. } else {
  614. $money = 7 * 2.4 + 14 + ($distance - 10) * 3.6;
  615. }
  616. return ceil($money);
  617. }
  618. /**
  619. * Des:添加操作日志
  620. * Name: addOperationLog
  621. * @param $title string 标题
  622. * @param $memo string 详细
  623. * @param string $uid 用户ID
  624. * @param string $u_type 用户 类型:1、管理员2、分销商、3、客户 4、cs系统用户
  625. * @param string $source_id 资源ID
  626. * @param string $source_type 资源类型 1、产品,2、订单
  627. * @return bool
  628. * @author 倪宗锋
  629. */
  630. public static function addOperationLog($title, $memo, $uid = '', $u_type = '', $source_id = '', $source_type = '')
  631. {
  632. try {
  633. $user_info = static::getUserName($uid, $u_type);
  634. $sourceInfo = static::getSourceInfo($source_id, $source_type);
  635. $logTab = new LogUserOperation();//日志记录表
  636. $result = $logTab->addNew($title, $memo, $user_info, $sourceInfo);
  637. return $result;
  638. } catch (Exception $e) {
  639. return false;
  640. }
  641. }
  642. /**
  643. * Des:获取用户 名称
  644. * Name: getUserName
  645. * @param $uid
  646. * @param $u_type
  647. * @return array
  648. * @author 倪宗锋
  649. */
  650. public static function getUserName($uid, $u_type)
  651. {
  652. if (empty($uid) || empty($u_type)) {
  653. return ['uid' => $uid, 'user_type' => $u_type, 'user_name' => '-', 'last_login' => ''];
  654. } elseif ($u_type == 1) {
  655. $userTab = new AdmUser();
  656. $userInfo = $userTab::findOne($uid);
  657. $user_name = $userInfo['u_name'];
  658. $last_login = $userInfo['last_login'];
  659. } elseif ($u_type == 2) {
  660. $userTab = new FxUser();
  661. $userInfo = $userTab::findOne($uid);
  662. $user_name = $userInfo['user_name'];
  663. $last_login = '';
  664. } elseif ($u_type == 3) {
  665. $userTab = new ShUser();
  666. $userInfo = $userTab::findOne($uid);
  667. $user_name = $userInfo['user_name'];
  668. $last_login = '';
  669. } elseif ($u_type == 4) {
  670. return ['uid' => $uid, 'user_type' => $u_type, 'user_name' => 'UID:' . $uid, 'last_login' => ''];
  671. } else {
  672. return ['uid' => $uid, 'user_type' => $u_type, 'user_name' => 'system', 'last_login' => ''];
  673. }
  674. return ['uid' => $uid, 'user_type' => $u_type, 'user_name' => $user_name, 'last_login' => $last_login];
  675. }
  676. /**
  677. * Des:获取资源详细
  678. * Name: getSourceInfo
  679. * @param $source_id
  680. * @param $source_type
  681. * @return array
  682. * @author 倪宗锋
  683. */
  684. public static function getSourceInfo($source_id, $source_type)
  685. {
  686. if (empty($source_id) || empty($source_type)) {
  687. return ['resources_id' => 0, 'resources_type' => 0, 'resources_name' => '-'];
  688. } elseif ($source_type == 1) {//1、产品表
  689. $tab = new ProdCategory();
  690. $info = $tab::findOne($source_id);
  691. $name = $info['pro_cate_name'];
  692. } elseif ($source_type == 2) {//订单表
  693. $tab = new OrderMain();
  694. $info = $tab::findOne($source_id);
  695. $name = $info['order_name'];
  696. } else {
  697. return ['resources_id' => 0, 'resources_type' => 0, 'resources_name' => 'system'];
  698. }
  699. return ['resources_id' => $source_id, 'resources_type' => $source_type, 'resources_name' => $name];
  700. }
  701. /**
  702. * Des:添加订单日志
  703. * Name: addOrderLog
  704. * @param $uid
  705. * @param $u_type int 0系统,1管理员,2分销商,3微信用户',
  706. * @param $order_id
  707. * @param $name
  708. * @param $log_type int 1、录入订单2、修改价格 3、支付、4自动取消、5、申请退款 ',
  709. * @author 倪宗锋
  710. */
  711. public static function addOrderLog($uid, $u_type, $order_id, $name, $log_type)
  712. {
  713. $time = time();
  714. $data = [];
  715. $data['time'] = $time;
  716. $data['uid'] = $uid;
  717. $data['u_type'] = $u_type;
  718. $data['order_id'] = $order_id;
  719. $data['name'] = $name;
  720. $data['log_type'] = $log_type;
  721. $param = [
  722. 'code' => Util::authCode(http_build_query($data), 'ENCODE'),
  723. 'time' => $time
  724. ];
  725. $curl = new CurlInterface($param, 4);
  726. $curl->setTimeOut(1);//一秒超时不管
  727. $siteConfig = Util::getSiteConfig();
  728. $url = '/zzcx/interfaces/fx/add-order-log';
  729. $curl->execute($siteConfig['host_name'] . $url, 'POST');
  730. }
  731. /**
  732. * Des:发送微信通知【异步】
  733. * Name: sendWxMsg
  734. * @param $data array type :1下单通知,2退款通知 3、佣金结算通知 4、出行车辆通知 5、取消订单通知
  735. * 6、酒店确认订单通知 7、酒店出行通知
  736. * money 金额,【type】为2 时需要传值
  737. * @author 倪宗锋
  738. */
  739. public static function sendWxMsg($data)
  740. {
  741. $time = time();
  742. $data['time'] = $time;
  743. $param = [
  744. 'code' => Util::authCode(http_build_query($data), 'ENCODE'),
  745. 'time' => $time
  746. ];
  747. $curl = new CurlInterface($param, 4);
  748. $curl->setTimeOut(1);//一秒超时
  749. $siteConfig = Util::getSiteConfig();
  750. $url = '/zzcx/interfaces/order/send-wx-msg';
  751. $curl->execute($siteConfig['host_name'] . $url, 'POST');
  752. }
  753. /**
  754. * 获取客户端IP地址
  755. * @return mixed
  756. */
  757. public static function getclientip()
  758. {
  759. static $realip = NULL;
  760. if ($realip !== NULL) {
  761. return $realip;
  762. }
  763. if (isset($_SERVER)) {
  764. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { //但如果客户端是使用代理服务器来访问,那取到的就是代理服务器的 IP 地址,而不是真正的客户端 IP 地址。要想透过代理服务器取得客户端的真实 IP 地址,就要使用 $_SERVER["HTTP_X_FORWARDED_FOR"] 来读取。
  765. $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
  766. /* 取X-Forwarded-For中第一个非unknown的有效IP字符串 */
  767. foreach ($arr AS $ip) {
  768. $ip = trim($ip);
  769. if ($ip != 'unknown') {
  770. $realip = $ip;
  771. break;
  772. }
  773. }
  774. } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {//HTTP_CLIENT_IP 是代理服务器发送的HTTP头。如果是"超级匿名代理",则返回none值。同样,REMOTE_ADDR也会被替换为这个代理服务器的IP。
  775. $realip = $_SERVER['HTTP_CLIENT_IP'];
  776. } else {
  777. if (isset($_SERVER['REMOTE_ADDR'])) { //正在浏览当前页面用户的 IP 地址
  778. $realip = $_SERVER['REMOTE_ADDR'];
  779. } else {
  780. $realip = '0.0.0.0';
  781. }
  782. }
  783. } else {
  784. //getenv环境变量的值
  785. if (getenv('HTTP_X_FORWARDED_FOR')) {//但如果客户端是使用代理服务器来访问,那取到的就是代理服务器的 IP 地址,而不是真正的客户端 IP 地址。要想透过代理服务器取得客户端的真实 IP 地址
  786. $realip = getenv('HTTP_X_FORWARDED_FOR');
  787. } elseif (getenv('HTTP_CLIENT_IP')) { //获取客户端IP
  788. $realip = getenv('HTTP_CLIENT_IP');
  789. } else {
  790. $realip = getenv('REMOTE_ADDR'); //正在浏览当前页面用户的 IP 地址
  791. }
  792. }
  793. preg_match("/[\d\.]{7,15}/", $realip, $onlineip);
  794. $realip = !empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0';
  795. return $realip;
  796. }
  797. /**
  798. * Des:获取浏览器机器类型
  799. * Name: get_device_type
  800. * @return string
  801. * @author 倪宗锋
  802. */
  803. public static function get_device_type()
  804. {
  805. //全部变成小写字母
  806. $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
  807. $type = 'other';
  808. //分别进行判断
  809. if (strpos($agent, 'iphone') || strpos($agent, 'ipad')) {
  810. $type = 'ios';
  811. }
  812. if (strpos($agent, 'android')) {
  813. $type = 'android';
  814. }
  815. return $type;
  816. }
  817. }