VM暫存
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

128 řádky
3.7KB

  1. <?php
  2. /*
  3. file: Txdata_model.php 交易資訊系統
  4. */
  5. class Txdata_model extends CI_Model
  6. {
  7. var $mcache;
  8. var $mqtt;
  9. function __construct()
  10. {
  11. parent::__construct();
  12. $this->load->database();
  13. $this->now_str = date('Y-m-d H:i:s');
  14. }
  15. public function init($vars)
  16. {
  17. $this->mcache = $vars['mcache'];
  18. $this->mqtt = $vars['mqtt'];
  19. }
  20. // 取得所有場站有效費率
  21. public function get_all_valid_price_plan($station_no)
  22. {
  23. $result = $this->db->select('tx_price_plan_id as txid, tx_type, station_no, remarks, price_plan, start_time, valid_time, create_time')
  24. ->from('tx_price_plan')
  25. ->where(array(
  26. 'start_time <= ' => $this->now_str,
  27. 'valid_time > ' => $this->now_str,
  28. 'station_no' => $station_no
  29. ))
  30. ->get()
  31. ->result_array();
  32. return $result;
  33. }
  34. // 取得場站費率設定
  35. // http://203.75.167.89/txdata.html/get_price_plan/12112/0
  36. public function get_price_plan($station_no, $tx_type)
  37. {
  38. $result = $this->db->select('price_plan')
  39. ->from('tx_price_plan')
  40. ->where(array(
  41. 'start_time <= ' => $this->now_str,
  42. 'valid_time > ' => $this->now_str,
  43. 'station_no' => $station_no,
  44. 'tx_type' => $tx_type
  45. ))
  46. ->get()
  47. ->result_array();
  48. return $result;
  49. }
  50. // 取得特殊日期設定
  51. // http://203.75.167.89/txdata.html/get_date_plan/12345678/23456789
  52. public function get_date_plan($inTime, $balanceTime)
  53. {
  54. $inDateTimestamp = strtotime(date("Y-m-d", $inTime));
  55. $balanceDateTimestamp = strtotime(date("Y-m-d", $balanceTime));
  56. $result = $this->db->select('p_type, p_date')
  57. ->from('tx_date_plan')
  58. ->where("p_date BETWEEN FROM_UNIXTIME({$inDateTimestamp}) AND FROM_UNIXTIME({$balanceDateTimestamp})")
  59. //->where("p_date BETWEEN '{$inDate}' AND '{$outDate}'")
  60. ->get()
  61. ->result_array();
  62. return $result;
  63. }
  64. // 同步場站費率
  65. public function sync_price_plan()
  66. {
  67. try{
  68. $param = array('station_no' => STATION_NO);
  69. // 查另一台主機
  70. $ch = curl_init();
  71. curl_setopt($ch, CURLOPT_URL, 'http://61.219.172.11:60123/admins.html/price_plan_query');
  72. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  73. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  74. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  75. curl_setopt($ch, CURLOPT_POST, TRUE);
  76. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,5);
  77. curl_setopt($ch, CURLOPT_TIMEOUT, 5); //timeout in seconds
  78. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));
  79. $data = curl_exec($ch);
  80. curl_close($ch);
  81. }catch (Exception $e){
  82. trigger_error('error msg:'.$e->getMessage());
  83. }
  84. $decode_result = json_decode($data, true);
  85. if (sizeof($decode_result) <= 0) return "empty";
  86. $this->db->trans_start();
  87. foreach ($decode_result as $key => $value)
  88. {
  89. $station_no = $value["station_no"];
  90. $tx_price_plan_id = $value["txid"];
  91. $tx_type = $value["tx_type"];
  92. $price_plan_data = array
  93. (
  94. 'station_no' => $station_no,
  95. 'tx_type' => $tx_type,
  96. 'remarks' => $value['remarks'],
  97. 'price_plan' => $value['price_plan'],
  98. 'start_time' => $value['start_time'],
  99. 'valid_time' => $value['valid_time']
  100. );
  101. // 刪除
  102. $this->db->delete('tx_price_plan', array('station_no' => $station_no, 'tx_type' => $tx_type));
  103. // 新增
  104. $this->db->insert('tx_price_plan', $price_plan_data);
  105. }
  106. $this->db->trans_complete();
  107. return "ok";
  108. }
  109. }