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.
 
 
 
 
 
 

699 lines
22 KiB

  1. <?php
  2. namespace backend\common;
  3. use Yii;
  4. use yii\base\Model;
  5. use yii\db\Exception;
  6. use common\components\zHttp;
  7. /**
  8. * Created by PhpStorm.
  9. * User: wangxj
  10. * Date: 2017/4/12
  11. * Time: 16:21
  12. */
  13. class Utils
  14. {
  15. /**
  16. * User:Steven
  17. *
  18. * Desc:发生soap请求
  19. * @param $request_fun
  20. * @param $param
  21. * @param $url
  22. * @return Exception | string
  23. */
  24. public function soapRequest($request_fun, $param, $url)
  25. {
  26. ini_set("soap.wsdl_cache_enabled", "0");
  27. $soap = new SoapClient($url, array(array('soap_version' => SOAP_1_2, 'trace' => true, 'exceptions' => true)));
  28. try {
  29. $response = $soap->{$request_fun}(['requestXml' => $param]);
  30. return $response;
  31. } catch (Exception $sf) {
  32. return $sf;
  33. /*print ($soap->__getLastRequest());
  34. print ($soap->__getLastResponse());*/
  35. }
  36. }
  37. /**
  38. * User:Steven
  39. *
  40. * Desc:发送post请求(xml)
  41. * @param $url
  42. * @param $xmlData
  43. * @return mixed
  44. */
  45. public function xml_post_request($url, $xmlData)
  46. {
  47. $header[] = "Content-type: text/xml"; //定义content-type为xml,注意是数组
  48. $ch = curl_init($url);
  49. curl_setopt($ch, CURLOPT_URL, $url);
  50. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  51. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  52. curl_setopt($ch, CURLOPT_POST, 1);
  53. curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData);
  54. $response = curl_exec($ch);
  55. if (curl_errno($ch)) {
  56. print curl_error($ch);
  57. }
  58. curl_close($ch);
  59. return $response;
  60. }
  61. public function execute($request, $session = null)
  62. {
  63. $this->data = $this->format == 'json' ? json_encode($request) : $this->xml_encode($request);
  64. $this->Url = 'http://' . str_replace(array('http://', 'https://'), '', $this->Url);
  65. $postUrl = $this->Url . "?method={$this->requestMethod}&data=" . urlencode($this->data);
  66. return $this->request_by_curl($postUrl);
  67. }
  68. /**
  69. * User:Steven
  70. *
  71. * Desc:编辑符合携程需要的XML格式
  72. * @param $data array 请求体
  73. * @param $RequestTypeName string 请求方法名称
  74. * @return string
  75. */
  76. public static function xml_encode($data, $RequestTypeName)
  77. {
  78. $params = Yii::$app->params['ctrip']['soap'];
  79. $timeStamp = date("Y-m-d H:i:s", time());
  80. $xml = "<Request>";
  81. $xml .= "<HeaderInfo UserID=\"" . $params['UserID'] . "\" RequestorId=\"" . $params['RequestorId'] .
  82. "\" AsyncRequest=\"" . $params['AsyncRequest'] . "\" TimeStamp=\"$timeStamp\"><Authentication UserName=\"" .
  83. $params['UserName'] . "\" Password=\"" . $params['Password'] . "\" /><RequestType Name=\"$RequestTypeName\" Version=\"" . $params['Version'] . "\" /></HeaderInfo>";
  84. $xml .= self::data_to_xml($data);
  85. $xml .= "</Request>";
  86. return $xml;
  87. }
  88. /**
  89. * User:Steven
  90. *
  91. * Desc:编辑符合携程需要的XML格式
  92. * @param $data array 请求体
  93. * @param $RequestTypeName string 请求方法名称
  94. * @return string
  95. */
  96. public static function xml_encode_remain($data, $RequestTypeName)
  97. {
  98. $params = Yii::$app->params['ctrip']['soap'];
  99. $timeStamp = date("Y-m-d H:i:s", time());
  100. $xml = "<![CDATA[<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  101. $xml .= "<q1:Request xmlns:q1=\"http://soa.ctrip.com/hotel/vendor/RoomQuantity/v1\">";
  102. $xml .= "<q1:HeaderInfo UserID=\"" . $params['UserID'] . "\" RequestorId=\"" . $params['RequestorId'] .
  103. "\" AsyncRequest=\"" . $params['AsyncRequest'] . "\" TimeStamp=\"$timeStamp\"><q1:Authentication UserName=\"" .
  104. $params['UserNameRemain'] . "\" Password=\"" . $params['PasswordRemain'] . "\" /><q1:RequestType Name=\"$RequestTypeName\" Version=\"" . $params['VersionRemain'] . "\" /></q1:HeaderInfo>";
  105. $xml .= self::data_to_xml_ns($data, 'q1:');
  106. $xml .= "</q1:Request>]]>";
  107. return $xml;
  108. }
  109. /**
  110. * User: wangxj
  111. *
  112. * 格式化返回的soap字符串
  113. *
  114. * @param $str
  115. */
  116. public static function formatResult($str)
  117. {
  118. $result = "<RequestResponse><RequestResult>{$str}</RequestResult></RequestResponse>";
  119. return $result;
  120. }
  121. /**
  122. * User:Steven
  123. *
  124. * Desc:将xml转换为数组
  125. * @param $xml
  126. * @return mixed
  127. */
  128. public static function xml_to_array($xml)
  129. {
  130. $ob = simplexml_load_string($xml);
  131. $json = json_encode($ob);
  132. $array = json_decode($json, true);
  133. return $array;
  134. }
  135. /**
  136. * User:Steven
  137. *
  138. * Desc:将数组转化成xml
  139. * @param $data
  140. * @return string
  141. */
  142. public static function data_to_xml($data)
  143. {
  144. if (is_object($data)) {
  145. $data = get_object_vars($data);
  146. }
  147. $xml = '';
  148. foreach ($data as $key => $val) {
  149. if (is_null($val) || $val === '') {
  150. // $xml .= "<$key/>\n";
  151. $xml .= "<$key>$val</$key>";
  152. } else {
  153. if (!is_numeric($key)) {
  154. $xml .= "<$key>";
  155. }
  156. $xml .= (is_array($val) || is_object($val)) ? self::data_to_xml($val) : $val;
  157. if (!is_numeric($key)) {
  158. $xml .= "</$key>";
  159. }
  160. }
  161. }
  162. return $xml;
  163. }
  164. /**
  165. * User:Steven
  166. * Desc:拼接带有命名空间的XML
  167. * @param $data
  168. * @param $namespace
  169. * @return string
  170. */
  171. public static function data_to_xml_ns($data, $namespace)
  172. {
  173. if (is_object($data)) {
  174. $data = get_object_vars($data);
  175. }
  176. $xml = '';
  177. foreach ($data as $key => $val) {
  178. if (is_null($val) || $val === '') {
  179. // $xml .= "<$namespace$key/>\n";
  180. $xml .= "<$namespace$key>$val</$namespace$key>";
  181. } else {
  182. if (!is_numeric($key)) {
  183. $xml .= "<$namespace$key>";
  184. }
  185. $xml .= (is_array($val) || is_object($val)) ? self::data_to_xml_ns($val, $namespace) : $val;
  186. if (!is_numeric($key)) {
  187. $xml .= "</$namespace$key>";
  188. }
  189. }
  190. }
  191. return $xml;
  192. }
  193. /**
  194. * User:Steven
  195. * Desc:格式化时间字符串 (适用于Ctrip)
  196. * @param $dataTime
  197. * @param $type 1: 去掉T 2:拼接T
  198. */
  199. public static function formatDataTime($dataTime, $type)
  200. {
  201. if ($type == 1) {
  202. $dateTime_arr = explode('T', $dataTime);
  203. $DataTime = $dateTime_arr[0] . ' ' . $dateTime_arr[1];
  204. } else {
  205. $DataTime = date('Y-m-d\TH:i:s', strtotime($dataTime));
  206. }
  207. return $DataTime;
  208. }
  209. /**
  210. * User: wangxj
  211. *
  212. * 获取错误信息到字符串
  213. *
  214. * @param $model Model
  215. * @return string
  216. */
  217. public static function getModelError($model)
  218. {
  219. $tmp = $model->getErrors();
  220. if (!empty($tmp)) {
  221. $str = '';
  222. foreach ($tmp as $item) {
  223. if (is_array($item)) {
  224. foreach ($item as $value) {
  225. $str .= $value . ' ';
  226. }
  227. } else {
  228. $str .= $item;
  229. }
  230. }
  231. return trim($str);
  232. } else {
  233. return '';
  234. }
  235. }
  236. /**
  237. * User: wangxj
  238. *
  239. * 把时间转换为
  240. *
  241. * @param $time
  242. * @param $type string 不需要返回 23988
  243. */
  244. public static function timeHour($time, $type = '')
  245. {
  246. if ($time != '-1' && $time != '-2' || $type == '') {
  247. $data = explode(',', $time);
  248. if (count($data) > 1) {
  249. $tmp = explode(':', $data[1]);
  250. return (int)($data[0]) * 24 + (24 - (int)($tmp[0]));
  251. } else {
  252. $tmp = explode(':', $data[0]);
  253. return (24 - (int)($tmp[0]));
  254. }
  255. } else {
  256. return '23988';
  257. }
  258. }
  259. /**
  260. * User:Stevem
  261. *
  262. * 求两个日期之间相差的天数
  263. * (针对1970年1月1日之后,求之前可以采用泰勒公式)
  264. * @param string $day1
  265. * @param string $day2
  266. * @return number
  267. */
  268. static function diffBetweenTwoDays($day1, $day2)
  269. {
  270. $second1 = strtotime($day1);
  271. $second2 = strtotime($day2);
  272. if ($second1 < $second2) {
  273. $tmp = $second2;
  274. $second2 = $second1;
  275. $second1 = $tmp;
  276. }
  277. return ($second1 - $second2) / 86400;
  278. }
  279. /**
  280. * User:Steven
  281. * Desc:计算两个日期范围内的所有日期 ,不包括期限的结束日期
  282. * @param $strDateFrom
  283. * @param $strDateTo
  284. * @return array
  285. */
  286. static function createDateRangeArray($strDateFrom, $strDateTo)
  287. {
  288. $aryRange = array();
  289. $iDateFrom = mktime(1, 0, 0, substr($strDateFrom, 5, 2), substr($strDateFrom, 8, 2), substr($strDateFrom, 0, 4));
  290. $iDateTo = mktime(1, 0, 0, substr($strDateTo, 5, 2), substr($strDateTo, 8, 2), substr($strDateTo, 0, 4));
  291. if ($iDateTo >= $iDateFrom) {
  292. array_push($aryRange, date('Y-m-d', $iDateFrom)); // first entry
  293. while ($iDateFrom + 86400 < $iDateTo) {
  294. $iDateFrom += 86400; // add 24 hours
  295. array_push($aryRange, date('Y-m-d', $iDateFrom));
  296. }
  297. }
  298. return $aryRange;
  299. }
  300. /**
  301. * User:Steven
  302. *
  303. * 想RTX发送推送消息
  304. * 使用企业微信 zOfficeWechat::sendMsg($arr)
  305. *
  306. * $title 通知标题
  307. * $msg 通知内容
  308. */
  309. static function sendMessageToRTX($title, $msg, $user = 'shifp,wangxj,yuw')
  310. {
  311. //生产环境才发送RTX
  312. if (Yii::$app->params['sendRTX']) {
  313. $cuntomer_list = $user;
  314. $arr = array(
  315. 'title' => $title . '【' . date('Y-m-d H:i:s', time()) . '】' . '[' . microtime() . ']',
  316. 'receiver' => $cuntomer_list,
  317. 'msg' => substr($msg, 0, 1024),
  318. );
  319. self::httpsPost('http://180.168.4.58:8012/SendNotify.cgi', $arr);
  320. }
  321. }
  322. /**
  323. * User:Steven
  324. * Desc:
  325. * @param $url
  326. * @param array $param
  327. * @return mixed
  328. * @throws Exception
  329. */
  330. static function httpsPost($url, $param = array())
  331. {
  332. $ch = curl_init(); // 初始化一个 cURL 对象
  333. curl_setopt($ch, CURLOPT_URL, $url); // 设置需要抓取的URL
  334. curl_setopt($ch, CURLOPT_HEADER, 0); // // 设置header
  335. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
  336. // 如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
  337. curl_setopt($ch, CURLOPT_POST, 1);
  338. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param)); // 传递一个作为HTTP “POST”操作的所有数据的字符串。//http_build_query:生成 URL-encode 之后的请求字符串
  339. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  340. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  341. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  342. 'Content-type:application/x-www-form-urlencoded;charset=utf-8'
  343. ));
  344. $rtn = curl_exec($ch); // 运行cURL,请求网页
  345. if ($errno = curl_errno($ch)) {
  346. throw new Exception ('Curl Error(' . $errno . '):' . curl_error($ch));
  347. }
  348. curl_close($ch); // 关闭URL请求
  349. return $rtn; // 返回获取的数据
  350. }
  351. /**
  352. * User:Steven
  353. * Desc:GET 请求
  354. * @param $url
  355. * @return mixed
  356. */
  357. static function http_get($url)
  358. {
  359. $oCurl = curl_init();
  360. if (stripos($url, "https://") !== FALSE) {
  361. curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
  362. curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
  363. curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
  364. }
  365. curl_setopt($oCurl, CURLOPT_URL, $url);
  366. curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
  367. curl_setopt($oCurl, CURLOPT_VERBOSE, 1);
  368. curl_setopt($oCurl, CURLOPT_HEADER, 1);
  369. // $sContent = curl_exec($oCurl);
  370. // $aStatus = curl_getinfo($oCurl);
  371. $sContent = self::execCURL($oCurl);
  372. curl_close($oCurl);
  373. return $sContent;
  374. }
  375. /**
  376. * User:Steven
  377. * POST 请求(新)
  378. * @param string $url
  379. * @param array $param
  380. * @param boolean $post_file 是否文件上传
  381. * @return string content
  382. */
  383. static function http_post($url, $param, $post_file = false)
  384. {
  385. $oCurl = curl_init();
  386. if (stripos($url, "https://") !== FALSE) {
  387. curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
  388. curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
  389. curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
  390. }
  391. if (PHP_VERSION_ID >= 50500 && class_exists('\CURLFile')) {
  392. $is_curlFile = true;
  393. } else {
  394. $is_curlFile = false;
  395. if (defined('CURLOPT_SAFE_UPLOAD')) {
  396. curl_setopt($oCurl, CURLOPT_SAFE_UPLOAD, false);
  397. }
  398. }
  399. if ($post_file) {
  400. if ($is_curlFile) {
  401. foreach ($param as $key => $val) {
  402. if (isset($val["tmp_name"])) {
  403. $param[$key] = new \CURLFile(realpath($val["tmp_name"]), $val["type"], $val["name"]);
  404. } else if (substr($val, 0, 1) == '@') {
  405. $param[$key] = new \CURLFile(realpath(substr($val, 1)));
  406. }
  407. }
  408. }
  409. $strPOST = $param;
  410. } else {
  411. $strPOST = urldecode(json_encode($param));
  412. }
  413. curl_setopt($oCurl, CURLOPT_URL, $url);
  414. curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
  415. curl_setopt($oCurl, CURLOPT_POST, true);
  416. curl_setopt($oCurl, CURLOPT_POSTFIELDS, $strPOST);
  417. curl_setopt($oCurl, CURLOPT_VERBOSE, 1);
  418. curl_setopt($oCurl, CURLOPT_HEADER, 1);
  419. // $sContent = curl_exec($oCurl);
  420. // $aStatus = curl_getinfo($oCurl);
  421. $sContent = self::execCURL($oCurl);
  422. curl_close($oCurl);
  423. return $sContent;
  424. }
  425. /**
  426. * User:Steven
  427. * Desc:执行CURL请求,并封装返回对象
  428. * @param $ch
  429. * @return array
  430. */
  431. static function execCURL($ch)
  432. {
  433. $response = curl_exec($ch);
  434. $error = curl_error($ch);
  435. $result = array('header' => '',
  436. 'content' => '',
  437. 'curl_error' => '',
  438. 'http_code' => '',
  439. 'last_url' => '');
  440. if ($error != "") {
  441. $result['curl_error'] = $error;
  442. return $result;
  443. }
  444. $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  445. $result['header'] = str_replace(array("\r\n", "\r", "\n"), "<br/>", substr($response, 0, $header_size));
  446. $result['content'] = substr($response, $header_size);
  447. $result['http_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  448. $result['last_url'] = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
  449. $result["base_resp"] = array();
  450. $result["base_resp"]["ret"] = $result['http_code'] == 200 ? 0 : $result['http_code'];
  451. $result["base_resp"]["err_msg"] = $result['http_code'] == 200 ? "ok" : $result["curl_error"];
  452. return $result;
  453. }
  454. /**
  455. * User: wangxj
  456. *
  457. * 保存日志
  458. *
  459. * @param $action
  460. * @param $string
  461. */
  462. static function writeLog($action, $string)
  463. {
  464. $string = date('Y-m-d H:i:s') . " $action " . PHP_EOL . $string . PHP_EOL;
  465. if (!file_exists(__DIR__ . '/../runtime/logs/soap/receive')) {
  466. mkdir(__DIR__ . '/../runtime/logs/soap/receive', 0777, true);
  467. }
  468. file_put_contents(__DIR__ . '/../runtime/logs/soap/receive/' . date('Y-m-d') . '.log', $string, FILE_APPEND);
  469. }
  470. /**
  471. * 根据时间戳,返回后七天的时间戳
  472. * @param $time
  473. * @return array
  474. */
  475. static function getWeekTime($time)
  476. {
  477. $times[] = strtotime('+0 days', $time);
  478. $times[] = strtotime('+1 days', $time);
  479. $times[] = strtotime('+2 days', $time);
  480. $times[] = strtotime('+3 days', $time);
  481. $times[] = strtotime('+4 days', $time);
  482. $times[] = strtotime('+5 days', $time);
  483. $times[] = strtotime('+6 days', $time);
  484. $times[] = strtotime('+7 days', $time);
  485. $times[] = strtotime('+8 days', $time);
  486. $times[] = strtotime('+9 days', $time);
  487. $times[] = strtotime('+10 days', $time);
  488. $times[] = strtotime('+11 days', $time);
  489. $times[] = strtotime('+12 days', $time);
  490. $times[] = strtotime('+13 days', $time);
  491. return $times;
  492. }
  493. /**
  494. * User:Steven
  495. * Desc:获取日期label
  496. * @param $number
  497. * @param string $tag
  498. * @return string
  499. */
  500. static function getWeekLabel($number, $tag = '周')
  501. {
  502. $week = ['日', '一', '二', '三', '四', '五', '六'];
  503. return isset($week[$number]) ? $tag . $week[$number] : '';
  504. }
  505. /**
  506. * 获取日期区间的所有日期
  507. *
  508. * @param $start_date string 2017-07-01
  509. * @param $end_date string 2017-07-31
  510. * @param $type bool 是否包含结束日期
  511. *
  512. * @author wangxj
  513. */
  514. static function getRangeDate($start_date, $end_date, $type=false){
  515. $start = new \DateTime($start_date);
  516. $end = new \DateTime($end_date);
  517. $interval = new \DateInterval('P1D'); // 1 day interval
  518. $period = new \DatePeriod($start, $interval, $end);
  519. $result = [];
  520. foreach ($period as $day) {
  521. // Do stuff with each $day...
  522. /* @var $day /DatePeriod */
  523. $result[] = $day->format('Y-m-d');
  524. }
  525. if($type=== true){
  526. $result[] = $end_date;
  527. }
  528. return $result;
  529. }
  530. /**
  531. * Function Description:发送邮件
  532. * Function Name: send_mail
  533. * @param $user
  534. * @param $pwd
  535. * @param $toemail
  536. * @param $title
  537. * @param $content
  538. *
  539. * @return mixed
  540. *
  541. * @author 冒炎
  542. */
  543. static function send_mail($user, $pwd, $toemail, $title, $content)
  544. {
  545. $currentDir = dirname(__FILE__);
  546. include_once $currentDir .'/Smtp.class.php';
  547. //******************** 配置信息 ********************************
  548. $smtpserver = "smtp.exmail.qq.com";//SMTP服务器
  549. $smtpserverport = 25;//SMTP服务器端口
  550. $smtpusermail = $user;//SMTP服务器的用户邮箱
  551. $smtpemailto = $toemail;//发送给谁
  552. $smtpuser = $user;//SMTP服务器的用户帐号,注:部分邮箱只需@前面的用户名
  553. $smtppass = $pwd;//SMTP服务器的用户密码
  554. $mailtitle = $title;//邮件主题
  555. $mailcontent = "<h1>" . $content . "</h1>";//邮件内容
  556. $mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件
  557. //************************ 配置信息 ****************************
  558. set_time_limit(0);
  559. $smtp = new \Smtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
  560. $smtp->debug = false;//是否显示发送的调试信息
  561. $state = $smtp->sendmail($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);
  562. if ($state == "") {
  563. $data['code'] = '1';
  564. $data['info'] = '邮件发送失败,请联系管理员';
  565. } else {
  566. $data['code'] = '0';
  567. $data['info'] = '邮件发送成功';
  568. }
  569. return $data;
  570. }
  571. /**
  572. * User:Steven
  573. * Desc:计算早餐级别
  574. * @param $breakfast
  575. * @return int
  576. */
  577. static function calBreakfastLevel($breakfast)
  578. {
  579. switch ($breakfast) {
  580. case 0:
  581. $breakfast_desc = '无早';
  582. break;
  583. case 1:
  584. $breakfast_desc ='单早';
  585. break;
  586. case 2:
  587. $breakfast_desc = '双早';
  588. break;
  589. case 3:
  590. $breakfast_desc = '三早';
  591. break;
  592. case 4:
  593. $breakfast_desc = '四早';
  594. break;
  595. case 5:
  596. $breakfast_desc = '五早';
  597. break;
  598. case 6:
  599. $breakfast_desc = '六早';
  600. break;
  601. case 7:
  602. $breakfast_desc = '七早';
  603. break;
  604. case 8:
  605. $breakfast_desc ='八早';
  606. break;
  607. case 9:
  608. $breakfast_desc = '九早';
  609. break;
  610. case 10:
  611. $breakfast_desc = '十早';
  612. break;
  613. default:
  614. $breakfast_desc = '多早';
  615. break;
  616. }
  617. return $breakfast_desc;
  618. }
  619. /**
  620. * Notes:过滤所选日期中符合星期的日期
  621. * User: Steven
  622. * Date: 2018/2/2
  623. * Time: 14:33
  624. * @param $strDateFrom
  625. * @param $strDateTo
  626. * @param $week_arr
  627. * @return array
  628. */
  629. static function createDateByWeek($strDateFrom, $strDateTo, $week_arr)
  630. {
  631. $aryRange = array();
  632. $iDateFrom = mktime(1, 0, 0, substr($strDateFrom, 5, 2), substr($strDateFrom, 8, 2), substr($strDateFrom, 0, 4));
  633. $iDateTo = mktime(1, 0, 0, substr($strDateTo, 5, 2), substr($strDateTo, 8, 2), substr($strDateTo, 0, 4));
  634. if ($iDateTo >= $iDateFrom) {
  635. if (in_array(date("w", $iDateFrom), $week_arr)) {
  636. array_push($aryRange, date('Y-m-d', $iDateFrom));//first entry
  637. }
  638. while ($iDateFrom < $iDateTo) {
  639. $iDateFrom += 86400;//add 24 hours
  640. $number_wk = date("w", $iDateFrom);
  641. if (in_array($number_wk, $week_arr)) {
  642. array_push($aryRange, date('Y-m-d', $iDateFrom));
  643. }
  644. }
  645. }
  646. return $aryRange;
  647. }
  648. }
  649. ?>