Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.96 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * @package Pulsa Online w38s.com
  5. * @version 3.7.3
  6. * @author Samsul Bahri (0818118061 / achunk17@gmail.com)
  7. * @link http://w38s.com
  8. * @link http://facebook.com/achunks
  9. * @license http://w38s.com/lisensi
  10. * @copyright 2015 - 2017
  11. */
  12.  
  13. defined('BASEPATH') or exit('No direct script access allowed');
  14.  
  15. class Mtrx extends CI_Model
  16. {
  17. protected $auto_refund = true;
  18. protected $cek_saldo = true;
  19.  
  20. protected $adm_notifaction_config;
  21. protected $telebot_config;
  22. protected $apk_config;
  23.  
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28.  
  29. public function get_pending_trx($gateway = array())
  30. {
  31. $servers = array();
  32. foreach ($this->get_servers($gateway, 'sv_id') as $srv) {
  33. $servers[] = $srv->sv_id;
  34. }
  35. if (!$servers)
  36. return array();
  37.  
  38. $this->db->select('transaksi.*, voucher.vo_kode_fisik, voucher.vo_kode_trx, server.*, ' .
  39. 'users.us_username, users.us_name, users.us_email, users.us_phone, users.us_balance, ' .
  40. 'users.us_data, users.us_telegram_id');
  41. $this->db->from('transaksi');
  42.  
  43. $this->db->join('server', 'server.sv_id = transaksi.sv_id', 'LEFT');
  44. $this->db->join('voucher', 'voucher.vo_id = transaksi.vo_id', 'LEFT');
  45. $this->db->join('users', 'users.us_id = transaksi.us_id', 'LEFT');
  46.  
  47. $this->db->where_in('transaksi.sv_id', $servers);
  48. $this->db->where('transaksi.tr_status_pembayaran', 'sukses');
  49. $this->db->where('transaksi.tr_status', 'pending');
  50.  
  51. $this->db->order_by('transaksi.tr_id', 'ASC');
  52. $query_results = $this->db->get()->result();
  53.  
  54. $us_last_trx = array();
  55. $results = array();
  56.  
  57. foreach ($query_results as $res) {
  58. if ($res->us_id) {
  59. if (!isset($us_last_trx[$res->us_id]))
  60. $us_last_trx[$res->us_id] = 0;
  61. if (($res->tr_tanggal - $us_last_trx[$res->us_id]) <= 5 && strpos($res->tr_opsi, '"order_via":"Pembelian Massal"') === false) {
  62. $this->db->where('tr_id', $res->tr_id);
  63. $this->db->set('tr_status', 'manual');
  64. $this->db->update('transaksi');
  65.  
  66. $this->db->where('us_id', $res->us_id);
  67. // Jika user adalah administrator maka akun tidak diblokir
  68. $this->db->where('us_rights !=', '10');
  69. $this->db->set('us_block', '1');
  70. $this->db->update('users');
  71.  
  72. $this->db->insert('notifikasi', array(
  73. 'us_id' => '0',
  74. 'nf_admin' => '1',
  75. 'nf_judul' => 'Transaksi Mencurigakan',
  76. 'nf_teks' => $res->us_name .
  77. ' melakukan transaksi mencurigakan dan akun telah diblokir secara otomatis.',
  78. 'nf_link' => 'admin/transaksi?status_pengisian=manual',
  79. 'nf_tanggal' => time(),
  80. ));
  81. } else {
  82. $us_last_trx[$res->us_id] = $res->tr_tanggal;
  83. $results[] = $res;
  84. }
  85. } else {
  86. $results[] = $res;
  87. }
  88. }
  89.  
  90. return $results;
  91. }
  92.  
  93. public function get_trx_in_process($gateway = array(), $start_time = null)
  94. {
  95. $servers = array();
  96. foreach ($this->get_servers($gateway, 'sv_id') as $srv) {
  97. $servers[] = $srv->sv_id;
  98. }
  99. if (!$servers)
  100. return array();
  101.  
  102. $this->db->select('transaksi.*, voucher.vo_kode_fisik, voucher.vo_kode_trx, server.*, ' .
  103. 'users.us_username, users.us_name, users.us_email, users.us_phone, users.us_balance, ' .
  104. 'users.us_data, users.us_telegram_id');
  105. $this->db->from('transaksi');
  106.  
  107. $this->db->join('server', 'server.sv_id = transaksi.sv_id', 'LEFT');
  108. $this->db->join('voucher', 'voucher.vo_id = transaksi.vo_id', 'LEFT');
  109. $this->db->join('users', 'users.us_id = transaksi.us_id', 'LEFT');
  110.  
  111. $this->db->where_in('transaksi.sv_id', $servers);
  112. $this->db->where('transaksi.tr_status_pembayaran', 'sukses');
  113. $this->db->group_start();
  114. $this->db->where('transaksi.tr_status', '-');
  115. $this->db->or_where('transaksi.tr_status', 'dalam_proses');
  116. $this->db->group_end();
  117. if ($start_time)
  118. $this->db->where('transaksi.tr_tanggal >', $start_time);
  119.  
  120. $this->db->order_by('transaksi.tr_id', 'ASC');
  121.  
  122. return $this->db->get()->result();
  123. }
  124.  
  125. public function trx_voucher_fisik($trx)
  126. {
  127. $kode_vouchers = json_decode($this->system->decrypt_data($trx->vo_kode_fisik), true);
  128. $sn = $kode_vouchers[0];
  129. unset($kode_vouchers[0]);
  130.  
  131. $this->db->where('vo_id', $trx->vo_id);
  132. if (count($kode_vouchers)) {
  133. $this->db->set('vo_kode_fisik', $this->system->encrypt_data(json_encode(array_values
  134. ($kode_vouchers))));
  135. } else {
  136. $this->db->set('vo_kode_fisik', '');
  137. }
  138. $this->db->update('voucher');
  139.  
  140. $opsi = $trx->tr_opsi ? json_decode($trx->tr_opsi, true) : array();
  141. $opsi['sn'] = $sn;
  142.  
  143. $this->db->where('tr_id', $trx->tr_id);
  144. $this->db->set('tr_opsi', json_encode($opsi));
  145. $this->db->update('transaksi');
  146. $message = "Trx #" . $trx->tr_id . " " . ($trx->vo_kode_trx ? $trx->vo_kode_trx :
  147. $trx->vo_kode) . "." . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx->tr_no_hp) .
  148. " SUKSES. Voucher Fisik: " . $sn;
  149. $this->set_sukses($trx, $message, $sn);
  150. }
  151.  
  152. public function sms_remind_trx()
  153. {
  154. if (!property_exists($this->system->perm, 'sms_reminder'))
  155. return;
  156.  
  157. if (!$this->system->perm->sms_reminder)
  158. return;
  159.  
  160. $this->db->select('transaksi.*, voucher.vo_kode_fisik, voucher.vo_kode_trx, server.*, ' .
  161. 'users.us_username, users.us_name, users.us_email, users.us_phone, users.us_balance, ' .
  162. 'users.us_data, users.us_telegram_id');
  163. $this->db->from('transaksi');
  164. $this->db->join('server', 'server.sv_id = transaksi.sv_id', 'LEFT');
  165. $this->db->join('voucher', 'voucher.vo_id = transaksi.vo_id', 'LEFT');
  166. $this->db->join('users', 'users.us_id = transaksi.us_id', 'LEFT');
  167. $this->db->where('transaksi.tr_tanggal < ', time() - ($this->system->perm->
  168. sms_reminder * 60));
  169. $this->db->where('transaksi.tr_tanggal > ', time() - (3600 * $this->system->set['jam_pembayaran']));
  170. $this->db->where('transaksi.tr_status_pembayaran', 'pending');
  171. $this->db->not_like('transaksi.tr_opsi', '"sms_reminder"');
  172. $query = $this->db->get();
  173. if (!$query->num_rows())
  174. return;
  175.  
  176. foreach ($query->result() as $trx) {
  177. $opsi = ($trx->tr_opsi ? json_decode($trx->tr_opsi, true) : array());
  178. $opsi['sms_reminder'] = format_tanggal(time());
  179. $this->db->where('tr_id', $trx->tr_id);
  180. $this->db->set('tr_opsi', json_encode($opsi));
  181. $this->db->update('transaksi');
  182. $pesan = "Trx #" . $trx->tr_id . " " . ($trx->vo_kode_trx ? $trx->vo_kode_trx :
  183. $trx->vo_kode) . "." . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx->tr_no_hp) .
  184. " " . @format_uang2($trx->tr_harga) . " belum dibayar.\r\n" . parse_url(site_url
  185. (), PHP_URL_HOST);
  186. send_sms($trx->us_id ? $trx->us_phone : $trx->tr_no_hp, $pesan);
  187. }
  188. }
  189.  
  190. public function get_servers($gateway = array(), $select = '*')
  191. {
  192. $this->db->select($select);
  193. $this->db->where_in('sv_gateway', $gateway);
  194. $query = $this->db->get('server');
  195. return $query->result();
  196. }
  197.  
  198. public function set_sukses($trx, $reply_message, $sn = null)
  199. {
  200. if ($this->cek_saldo) {
  201. $saldo = $this->get_saldo($reply_message);
  202. if ($saldo) {
  203. $this->db->where('sv_id', $trx->sv_id);
  204. $this->db->set('sv_saldo', $saldo);
  205. $this->db->update('server');
  206. }
  207. }
  208.  
  209. $income = $this->get_income($trx->us_id ? $trx->tr_harga2 : $trx->tr_harga, $reply_message);
  210.  
  211. $opsi = $trx->tr_opsi ? json_decode($trx->tr_opsi, true) : array();
  212.  
  213. if (is_null($sn)) {
  214. $sn = $this->get_sn($trx->sv_regex_sn, $reply_message);
  215. }
  216. if ($sn) {
  217. $opsi['sn'] = $sn;
  218. }
  219.  
  220. $string = $this->db->where('in_trx_id', $trx->tr_id)->get('sms_masuk')->row()->in_message;
  221. preg_match_all('/(ref)(:|=)(.*?)($)/', $string, $matches);
  222. foreach($matches[3] as $refno) {echo $value;};
  223.  
  224. $opsi['server_message'] = $reply_message;
  225.  
  226. $this->db->where('tr_id', $trx->tr_id);
  227. $this->db->set('tr_status', 'sukses');
  228. $this->db->set('tr_income', $income);
  229. $this->db->set('tr_opsi', json_encode($opsi));
  230. $this->db->update('transaksi');
  231.  
  232. $consumer_message ="Yth.Bosku $trx->us_username, Trx #".$trx->tr_id . " " . ($trx->vo_kode_trx ? $trx->
  233. vo_kode_trx : $trx->vo_kode) . "." . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx->
  234. tr_no_hp) . " SUKSES.";
  235. if ($sn) {
  236. $consumer_message .= "\r\nSN: " . $sn . "/" . $refno;
  237. }
  238. $consumer_message .="\r\nSaldo Rp".format_uang($trx->us_balance + $trx->tr_harga2)." - Rp".format_uang($trx->tr_harga2)." = Rp".format_uang($trx->us_balance)." @".format_tanggal($trx->tr_tanggal)."\r\n" ;
  239.  
  240. if (in_array($trx->op_produk, $this->system->perm->sms_order)) {
  241. $this->send_sms($trx->tr_no_hp, "Terima Kasih sudah isi ulang di RamsaPulsa.com ".$trx->op_nama." ".$trx->vo_nominal."\r\nStatus SUKSES. SN/Voucher/Token: ".$sn);
  242. }
  243.  
  244. if ($trx->us_id) {
  245. $this->db->insert('notifikasi', array(
  246. 'us_id' => $trx->us_id,
  247. 'nf_judul' => 'Status Order #' . $trx->tr_id,
  248. 'nf_teks' => $consumer_message,
  249. 'nf_link' => 'akun/riwayat-transaksi/view/' . $trx->tr_id,
  250. 'nf_feedback' => '1',
  251. 'nf_tanggal' => time(),
  252. ));
  253. if (isset($opsi['telegram_chat_id'])) {
  254. $this->send_telegram_message($opsi['telegram_chat_id'], $consumer_message);
  255. } elseif (isset($opsi['smstrx'])) {
  256. $this->send_sms($opsi['smstrx'], $consumer_message);
  257. } elseif (isset($opsi['jabbertrx'])) {
  258. $this->send_jabber($opsi['jabbertrx'], $consumer_message);
  259. } elseif (isset($opsi['order_via']) && $opsi['order_via'] == 'API') {
  260. $user_data = json_decode($trx->us_data, true);
  261. if (isset($user_data['api']) && isset($user_data['api']['reg_id'])) {
  262. $this->send_android_push($user_data['api']['reg_id'], $trx->tr_id, $consumer_message);
  263. }
  264. }
  265. if ($this->system->perm->email_order == 'yes') {
  266. $this->send_email($trx->us_email, 'Status Order #' . $trx->tr_id, $consumer_message .
  267. "\r\n\r\n" . site_url('akun/riwayat-transaksi/view/' . $trx->tr_id));
  268. }
  269. }
  270.  
  271. // Notifikasi admin
  272. if (!$this->adm_notifaction_config)
  273. $this->adm_notifaction_config = json_decode($this->system->get_set('trx_notifikasi'));
  274.  
  275. $this->db->insert('notifikasi', array(
  276. 'us_id' => '0',
  277. 'nf_admin' => '1',
  278. 'nf_judul' => $trx->sv_nama,
  279. 'nf_teks' => $reply_message,
  280. 'nf_link' => 'admin/transaksi/view/' . $trx->tr_id,
  281. 'nf_feedback' => '1',
  282. 'nf_tanggal' => time(),
  283. ));
  284. if ($this->adm_notifaction_config->sms) {
  285. $this->send_sms($this->adm_notifaction_config->sms, $reply_message);
  286. }
  287. if ($this->adm_notifaction_config->email) {
  288. $this->send_email($this->adm_notifaction_config->email, $trx->sv_nama, $reply_message .
  289. "\r\n\r\n" . site_url('admin/transaksi/view/' . $trx->tr_id));
  290. }
  291.  
  292. }
  293.  
  294. public function set_gagal($trx, $reply_message)
  295. {
  296. if ($this->cek_saldo) {
  297. $saldo = $this->get_saldo($reply_message);
  298. if ($saldo) {
  299. $this->db->where('sv_id', $trx->sv_id);
  300. $this->db->set('sv_saldo', $saldo);
  301. $this->db->update('server');
  302. }
  303. }
  304.  
  305. $opsi = $trx->tr_opsi ? json_decode($trx->tr_opsi, true) : array();
  306.  
  307. $string = $this->db->where('in_trx_id', $trx->tr_id)->get('sms_masuk')->row()->in_message;
  308. preg_match_all('/(GAGAL|gagal|Gagal)(.|. )(.*?)\./', $string, $matches);
  309. foreach($matches[3] as $value) {echo $value;};
  310.  
  311. $this->db->where('tr_id', $trx->tr_id);
  312. if ($trx->us_id && $this->auto_refund && $trx->sv_gateway != 'sms') {
  313. $this->db->set('tr_status_pembayaran', 'refund');
  314. }
  315. $this->db->set('tr_status', 'gagal');
  316. //$this->db->set('tr_opsi', json_encode($opsi));
  317. $this->db->update('transaksi');
  318.  
  319. $consumer_message = "Yth. Bosku $trx->us_username, Trx#" . $trx->tr_id . " " .($trx->op_nama)." ". ($trx->vo_nominal) . " ke " . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx->
  320. tr_no_hp) . " GAGAL. " .$value. "." . "\r\nSisa Saldo : Rp".format_uang($trx->us_balance + $trx->tr_harga2)." @".format_tanggal($trx->tr_tanggal);
  321.  
  322. if (in_array($trx->op_produk, $this->system->perm->sms_order) && !isset($opsi['jabbertrx']) &&
  323. !isset($opsi['smstrx']) && !isset($opsi['telegram_chat_id'])) {
  324. $this->send_sms($trx->tr_no_hp, "Yth My Bos. Isi ulang ".$trx->op_nama." ".$trx->vo_nominal."\r\nGAGAL.".$value."\r\nSilakan Hubungi Kami Di WA/SMS 08114552832 RamsaPulsa.com");
  325. }
  326.  
  327. if ($trx->us_id) {
  328. if ($this->auto_refund && $trx->sv_gateway != 'sms') {
  329. $note = 'Refund Pembayaran / Trx #' . $trx->tr_id;
  330. $this->db->where('us_id', $trx->us_id);
  331. $this->db->where('info', $note);
  332. if (!$this->db->count_all_results('balance_history')) {
  333. $this->db->query("UPDATE users SET us_balance = us_balance + $trx->tr_harga2 WHERE us_id = '$trx->us_id'");
  334. insert_balance_history(array(
  335. $trx->us_id,
  336. '0',
  337. $trx->tr_harga2,
  338. ($trx->us_balance + $trx->tr_harga2),
  339. $note,
  340. time(),
  341. ));
  342. }
  343. }
  344. $this->db->insert('notifikasi', array(
  345. 'us_id' => $trx->us_id,
  346. 'nf_judul' => 'Status Order #' . $trx->tr_id,
  347. 'nf_teks' => $consumer_message,
  348. 'nf_link' => 'akun/riwayat-transaksi/view/' . $trx->tr_id,
  349. 'nf_feedback' => '1',
  350. 'nf_tanggal' => time(),
  351. ));
  352. if (isset($opsi['telegram_chat_id'])) {
  353. $this->send_telegram_message($opsi['telegram_chat_id'], $consumer_message);
  354. } elseif (isset($opsi['smstrx'])) {
  355. $this->send_sms($opsi['smstrx'], $consumer_message);
  356. } elseif (isset($opsi['jabbertrx'])) {
  357. $this->send_jabber($opsi['jabbertrx'], $consumer_message);
  358. } elseif (isset($opsi['order_via']) && $opsi['order_via'] == 'API') {
  359. $user_data = json_decode($trx->us_data, true);
  360. if (isset($user_data['api']) && isset($user_data['api']['reg_id'])) {
  361. $this->send_android_push($user_data['api']['reg_id'], $trx->tr_id, $consumer_message);
  362. }
  363. }
  364. if ($this->system->perm->email_order == 'yes') {
  365. $this->send_email($trx->us_email, 'Status Order #' . $trx->tr_id, $consumer_message .
  366. "\r\n\r\n" . site_url('akun/riwayat-transaksi/view/' . $trx->tr_id));
  367. }
  368. }
  369.  
  370. // Notifikasi admin
  371. if (!$this->adm_notifaction_config)
  372. $this->adm_notifaction_config = json_decode($this->system->get_set('trx_notifikasi'));
  373.  
  374. $this->db->insert('notifikasi', array(
  375. 'us_id' => '0',
  376. 'nf_admin' => '1',
  377. 'nf_judul' => $trx->sv_nama,
  378. 'nf_teks' => $reply_message,
  379. 'nf_link' => 'admin/transaksi/view/' . $trx->tr_id,
  380. 'nf_feedback' => '1',
  381. 'nf_tanggal' => time(),
  382. ));
  383.  
  384. if ($this->adm_notifaction_config->sms) {
  385. $this->send_sms($this->adm_notifaction_config->sms, $reply_message);
  386. }
  387. if ($this->adm_notifaction_config->email) {
  388. $this->send_email($this->adm_notifaction_config->email, $trx->sv_nama, $reply_message);
  389. }
  390. }
  391.  
  392. public function cek_status($pesan, $regex_sukses, $regex_gagal)
  393. {
  394. $status = null;
  395. if ($regex_sukses) {
  396. $arr = explode('|', $regex_sukses);
  397. foreach ($arr as $ar) {
  398. if ($ar) {
  399. $arr1 = explode(',', $ar);
  400. $finds = count($arr1);
  401. foreach ($arr1 as $ar1) {
  402. if ($ar1) {
  403. if (stripos($pesan, $ar1) !== false) {
  404. $finds -= 1;
  405. }
  406. }
  407. }
  408. if ($finds == 0) {
  409. return 'sukses';
  410. }
  411. }
  412. }
  413. }
  414. if ($regex_gagal) {
  415. $arr = explode('|', $regex_gagal);
  416. foreach ($arr as $ar) {
  417. if ($ar) {
  418. $arr1 = explode(',', $ar);
  419. $finds = count($arr1);
  420. foreach ($arr1 as $ar1) {
  421. if ($ar1) {
  422. if (stripos($pesan, $ar1) !== false) {
  423. $finds -= 1;
  424. }
  425. }
  426.  
  427. }
  428. if ($finds == 0) {
  429. return 'gagal';
  430. }
  431. }
  432. }
  433. }
  434. return null;
  435. }
  436.  
  437. public function set_proses($trx)
  438. {
  439. $this->db->where('tr_id', $trx->tr_id);
  440. $this->db->set('tr_status', '-');
  441. $this->db->update('transaksi');
  442. }
  443.  
  444. public function get_sn($regex, $message)
  445. {
  446. $message = str_replace("\n", " ", $message);
  447. if (!$regex)
  448. return '';
  449. preg_match($regex, $message, $matches);
  450. $sn = '';
  451. if (isset($matches['sn'])) {
  452. $sn = trim($matches['sn']);
  453.  
  454. if (strpos($sn, 'Bisa diorderkan kembali') !== false) {
  455. $xsn = explode('Bisa diorderkan kembali', $sn);
  456. $sn = trim($xsn[0]);
  457. } elseif (strpos($sn, 'Harga:') !== false) {
  458. $xsn = explode('Harga:', $sn);
  459. $sn = trim($xsn[0]);
  460. } elseif (strpos($sn, 'Tgl:') !== false) {
  461. $xsn = explode('Tgl:', $sn);
  462. $sn = trim($xsn[0]);
  463. } elseif (strpos($sn, 'Hrg') !== false) {
  464. $xsn = explode('Hrg', $sn);
  465. $sn = trim($xsn[0]);
  466. }
  467.  
  468. $sn = (substr($sn, -1) == '.' ? substr($sn, 0, -1) : $sn);
  469. }
  470. return $sn;
  471. }
  472.  
  473. public function get_income($harga_jual, $message)
  474. {
  475. $message = str_replace("\n", " ", $message);
  476. $regex = array(
  477. '/([0-9\.\,]{4,16})( - |-)(?P<harga>[a-zA-Z0-9\.\,\:]{4,32})( =|=)/',
  478. '/(Hrg|Harga)(=| = |:| : | Rp\.| )(?P<harga>[0-9\.\,]{4,32})/i',
  479. );
  480. for ($i = 0; $i < count($regex); $i++) {
  481. preg_match($regex[$i], $message, $matches);
  482. if (isset($matches['harga'])) {
  483. $harga_beli = (int)preg_replace('/\D/', '', $matches['harga']);
  484. if ($harga_beli < $harga_jual) {
  485. return $harga_jual - $harga_beli;
  486. }
  487. }
  488. }
  489. return 0;
  490. }
  491.  
  492. public function get_saldo($message)
  493. {
  494. $message = str_replace("\n", " ", $message);
  495. $regex = array(
  496. '/([0-9\.\,]{4,16})( - |-)([a-zA-Z0-9\.\,\:]{4,32})( = |=)(?P<saldo>[a-zA-Z0-9\.\,\:]{4,32})/',
  497. '/(?P<saldo>[0-9\.,]+), masih proses/i',
  498. '/(Sal|Saldo)(=| = |:| : | )(?P<saldo>[a-zA-Z0-9\.\,\:]{4,32})/i');
  499. for ($i = 0; $i < count($regex); $i++) {
  500. preg_match($regex[$i], $message, $matches);
  501. if (isset($matches['saldo'])) {
  502. return (int)preg_replace('/\D/', '', $matches['saldo']);
  503. }
  504. }
  505. return 0;
  506. }
  507.  
  508. public function get_format_trx($trx)
  509. {
  510. $format = json_decode($trx->sv_format_trx, true);
  511. $format_trx = $format[$trx->op_produk];
  512. $format_dobel = $trx->op_produk . '_dobel';
  513. $total = 0;
  514. if (isset($format[$format_dobel])) {
  515. $total = $this->count_success_trx($trx);
  516. if ($total >= 1)
  517. $format_trx = $format[$format_dobel];
  518. }
  519. $replaces = array(
  520. '{ID}' => $trx->tr_id,
  521. '{KODE}' => $trx->vo_kode,
  522. '{NO_HP}' => $trx->tr_no_hp,
  523. '{NUM}' => ($total + 1),
  524. '{ID_PLGN}' => $trx->tr_id_plgn,
  525. '{PIN}' => $this->system->decrypt_data($trx->sv_pin),
  526. );
  527. $pesan = str_ireplace(array_keys($replaces), array_values($replaces), $format_trx);
  528. return $pesan;
  529. }
  530.  
  531. public function count_success_trx($trx)
  532. {
  533. $this->db->select('tr_id');
  534. $this->db->where('sv_id', $trx->sv_id);
  535. $this->db->where('vo_id', $trx->vo_id);
  536. if ($trx->tr_id_plgn)
  537. $this->db->where('tr_id_plgn', $trx->tr_id_plgn);
  538. else
  539. $this->db->where('tr_no_hp', $trx->tr_no_hp);
  540. $this->db->where('tr_status_pembayaran', 'sukses');
  541. $this->db->where('tr_status', 'sukses');
  542. $this->db->where('tr_tanggal >', strtotime(date('Y/m/d 00:00:00')));
  543. $this->db->where('tr_tanggal <', strtotime(date('Y/m/d 23:59:59')));
  544. return $this->db->count_all_results('transaksi');
  545. }
  546.  
  547. public function send_sms($phone, $message)
  548. {
  549. $this->db->insert('sms_keluar', array(
  550. 'out_to' => $phone,
  551. 'out_message' => $message,
  552. 'out_submit_date' => time(),
  553. ));
  554. }
  555.  
  556. protected function send_jabber($receiver, $message)
  557. {
  558. $this->load->model('sms_model');
  559. $jabber_api = json_decode($this->system->get_set('jabber_api'), true);
  560. if ($jabber_api['server_url'] && $jabber_api['username'] && $jabber_api['password']) {
  561. if ($this->sms_model->send_mass_jabber(array($receiver), $message, $jabber_api)) {
  562. return true;
  563. } else {
  564. return false;
  565. }
  566. } else {
  567. $this->sms_model->send_mass_jabber(array($receiver), $message, $jabber_api);
  568. return true;
  569. }
  570. }
  571.  
  572. public function send_email($to, $subject, $message)
  573. {
  574. $this->load->library('email');
  575. $this->email->from($this->system->get_set('site_email'), $this->system->set['site_name']);
  576. $this->email->to($to);
  577. $this->email->subject($subject);
  578. $this->email->message($message . "\r\n\r\n" . $this->system->set['site_name'] .
  579. "\r\n" . site_url());
  580. @$this->email->send();
  581. }
  582.  
  583. public function send_telegram_message($telegram_id, $message)
  584. {
  585. if (!$this->telebot_config)
  586. $this->telebot_config = json_decode($this->system->get_set('telegram_bot'));
  587.  
  588. if (!$this->telebot_config->token)
  589. return;
  590.  
  591. $ch = curl_init();
  592. curl_setopt($ch, CURLOPT_URL, 'https://api.telegram.org/bot' . $this->
  593. telebot_config->token . '/sendMessage');
  594. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  595. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  596. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  597. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
  598. curl_setopt($ch, CURLOPT_POST, true);
  599. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
  600. 'chat_id' => $telegram_id,
  601. 'text' => $message,
  602. 'disable_web_page_preview' => true,
  603. )));
  604. $req = curl_exec($ch);
  605. curl_close($ch);
  606.  
  607. return $req;
  608. }
  609.  
  610. public function send_android_push($reg_id, $trx_id, $body)
  611. {
  612. if (!$this->apk_config)
  613. $this->apk_config = @json_decode($this->system->get_set('aplikasi_android'));
  614.  
  615. $ch = curl_init();
  616. curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
  617. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  618. 'Authorization: key=' . $this->apk_config->fcm_server_key,
  619. 'Content-Type: application/json',
  620. ));
  621. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  622. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  623. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  624. curl_setopt($ch, CURLOPT_POST, true);
  625. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
  626. 'to' => $reg_id,
  627. 'notification' => array(
  628. 'title' => 'Status Order ' . $trx_id,
  629. 'body' => $body,
  630. 'sound' => 'mySound',
  631. 'click_action' => 'DETAIL_TRANSAKSI',
  632. ),
  633. 'data' => array('trxID' => $trx_id),
  634. )));
  635. $req = curl_exec($ch);
  636. curl_close($ch);
  637.  
  638. return $req;
  639. }
  640. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement