Advertisement
Guest User

mtrx.php

a guest
Apr 22nd, 2019
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.00 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * @package Pulsa Online w38s.com
  5. * @version 3.8.0
  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 = false;
  18. protected $cek_saldo = false;
  19. protected $us_sms_notif = true;
  20.  
  21. protected $adm_notifaction_config;
  22. protected $telebot_config;
  23. protected $apk_config;
  24.  
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29.  
  30. public function get_pending_trx($gateway = array())
  31. {
  32. // notif pending start
  33. $sql = "Select transaksi.*, voucher.vo_kode_fisik, voucher.vo_kode_trx, server.*,users.us_username, users.us_name, users.us_email, users.us_phone, users.us_balance,users.us_data, users.us_telegram_id
  34. from transaksi left join server on server.sv_id = transaksi.sv_id left join voucher on voucher.vo_id =transaksi.vo_id left join users on users.us_id =transaksi.us_id
  35. left join mutasi on mutasi.trx_id = transaksi.tr_id
  36. where transaksi.tr_status_pembayaran = 'sukses'
  37. and transaksi.tr_status in ('dalam_proses','-')
  38. and FROM_UNIXTIME((case when transaksi.tr_pembayaran='balance' then transaksi.tr_tanggal else mutasi.tanggal end)) < (now() - (3 * 60)) and not (transaksi.tr_opsi like '%sms_pending%');";
  39.  
  40. $query = $this->db->query($sql)->result();
  41. foreach ($query as $trx) {
  42.  
  43. $opsi = ($trx->tr_opsi ? json_decode($trx->tr_opsi, true) : array());
  44. $opsi['sms_pending'] = format_tanggal(time());
  45. $this->db->where('tr_id', $trx->tr_id);
  46. $this->db->set('tr_opsi', json_encode($opsi));
  47. $this->db->update('transaksi');
  48.  
  49. $pesan = "Trx " . ($trx->vo_kode_trx ? $trx->vo_kode_trx : $trx->vo_kode) . "." . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx->tr_no_hp) . " masih dalam proses. Mohon di tunggu Juragan jangan mengembalikan uang kepelanggan sampe status Transaksi dinyatakan GAGAL/SUKSES.";
  50. $pesan2 = "Trx " . ($trx->vo_kode_trx ? $trx->vo_kode_trx : $trx->vo_kode) . "." . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx->tr_no_hp) . " Wah Pending nih yuk kita kawal bersama.";
  51. //notif user/buyer
  52. if ($trx->us_id) {
  53. if ($trx->us_telegram_id) {
  54. $this->send_telegram_message($trx->us_telegram_id,$pesan);
  55. } else {
  56. $this->send_sms($trx->us_phone, $pesan);
  57. }
  58. } else {
  59. $this->send_sms($trx->tr_no_hp, $pesan);
  60. }
  61. //notif admin
  62. $pesan = str_replace("Mohon ditunggu","Mohon dikawal",$pesan);
  63. $this->send_telegram_message("#idtelegram",$pesan2 . " " . site_url('admin/transaksi/view/' . $trx->tr_id));
  64. }
  65. //notif pending end
  66. $servers = array();
  67. foreach ($this->get_servers($gateway, 'sv_id') as $srv) {
  68. $servers[] = $srv->sv_id;
  69. }
  70. if (!$servers)
  71. return array();
  72.  
  73. $this->db->select('transaksi.*, voucher.*, server.*, users.us_username, users.us_name, users.us_email, users.us_phone, users.us_balance, users.us_data, users.us_telegram_id');
  74. $this->db->from('transaksi');
  75.  
  76. $this->db->join('server', 'server.sv_id = transaksi.sv_id', 'LEFT');
  77. $this->db->join('voucher', 'voucher.vo_id = transaksi.vo_id', 'LEFT');
  78. $this->db->join('users', 'users.us_id = transaksi.us_id', 'LEFT');
  79.  
  80. $this->db->where_in('transaksi.sv_id', $servers);
  81. $this->db->where('transaksi.tr_status_pembayaran', 'sukses');
  82. $this->db->where('transaksi.tr_status', 'pending');
  83.  
  84. $this->db->order_by('transaksi.tr_id', 'ASC');
  85. $query_results = $this->db->get()->result();
  86.  
  87. $us_last_trx = array();
  88. $results = array();
  89.  
  90. foreach ($query_results as $res) {
  91. if ($res->us_id) {
  92. if (!isset($us_last_trx[$res->us_id]))
  93. $us_last_trx[$res->us_id] = 0;
  94. if (($res->tr_tanggal - $us_last_trx[$res->us_id]) <= 5 && strpos($res->tr_opsi, '"order_via":"Pembelian Massal"') === false && strpos($res->tr_opsi, '"jabbertrx":') === false) {
  95. $this->db->where('tr_id', $res->tr_id);
  96. $this->db->set('tr_status', 'manual');
  97. $this->db->update('transaksi');
  98.  
  99. $this->db->where('us_id', $res->us_id);
  100. // Jika user adalah administrator maka akun tidak diblokir
  101. $this->db->where('us_rights !=', '10');
  102. $this->db->set('us_block', '1');
  103. $this->db->update('users');
  104.  
  105. $this->db->insert('notifikasi', array(
  106. 'us_id' => '0',
  107. 'nf_admin' => '1',
  108. 'nf_judul' => 'Transaksi Mencurigakan',
  109. 'nf_teks' => $res->us_name .
  110. ' melakukan transaksi mencurigakan dan akun telah diblokir secara otomatis.',
  111. 'nf_link' => 'admin/transaksi?status_pengisian=manual',
  112. 'nf_tanggal' => time(),
  113. ));
  114. } else {
  115. $us_last_trx[$res->us_id] = $res->tr_tanggal;
  116. $results[] = $res;
  117. }
  118. } else {
  119. $results[] = $res;
  120. }
  121. }
  122.  
  123. return $results;
  124. }
  125.  
  126. public function get_trx_in_process($gateway = array(), $start_time = null)
  127. {
  128. $servers = array();
  129. foreach ($this->get_servers($gateway, 'sv_id') as $srv) {
  130. $servers[] = $srv->sv_id;
  131. }
  132. if (!$servers)
  133. return array();
  134.  
  135. $this->db->select('transaksi.*, voucher.*, server.*, users.us_username, users.us_name, users.us_email, users.us_phone, users.us_balance, users.us_data, users.us_telegram_id');
  136. $this->db->from('transaksi');
  137.  
  138. $this->db->join('server', 'server.sv_id = transaksi.sv_id', 'LEFT');
  139. $this->db->join('voucher', 'voucher.vo_id = transaksi.vo_id', 'LEFT');
  140. $this->db->join('users', 'users.us_id = transaksi.us_id', 'LEFT');
  141.  
  142. $this->db->where_in('transaksi.sv_id', $servers);
  143. $this->db->where('transaksi.tr_status_pembayaran', 'sukses');
  144. $this->db->group_start();
  145. $this->db->where('transaksi.tr_status', '-');
  146. $this->db->or_where('transaksi.tr_status', 'dalam_proses');
  147. $this->db->group_end();
  148. if ($start_time)
  149. $this->db->where('transaksi.tr_tanggal >', $start_time);
  150.  
  151. $this->db->order_by('transaksi.tr_id', 'ASC');
  152.  
  153. return $this->db->get()->result();
  154. }
  155.  
  156. public function trx_voucher_fisik($trx)
  157. {
  158. $kode_vouchers = json_decode($this->system->decrypt_data($trx->vo_kode_fisik), true);
  159. $sn = $kode_vouchers[0];
  160. unset($kode_vouchers[0]);
  161.  
  162. $this->db->where('vo_id', $trx->vo_id);
  163. if (count($kode_vouchers)) {
  164. $this->db->set('vo_kode_fisik', $this->system->encrypt_data(json_encode(array_values
  165. ($kode_vouchers))));
  166. } else {
  167. $this->db->set('vo_kode_fisik', '');
  168. }
  169. $this->db->update('voucher');
  170.  
  171. $opsi = $trx->tr_opsi ? json_decode($trx->tr_opsi, true) : array();
  172. $opsi['sn'] = $sn;
  173.  
  174. $this->db->where('tr_id', $trx->tr_id);
  175. $this->db->set('tr_opsi', json_encode($opsi));
  176. $this->db->update('transaksi');
  177. $message = "Trx #" . $trx->tr_id . " " . ($trx->vo_kode_trx ? $trx->vo_kode_trx :
  178. $trx->vo_kode) . "." . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx->tr_no_hp) .
  179. " SUKSES. Voucher Fisik: " . $sn;
  180. $this->set_sukses($trx, $message, $sn);
  181. }
  182.  
  183. public function sms_remind_trx()
  184. {
  185. if (!property_exists($this->system->perm, 'sms_reminder'))
  186. return;
  187.  
  188. if (!$this->system->perm->sms_reminder)
  189. return;
  190.  
  191. $this->db->select('transaksi.*, voucher.vo_kode_fisik, voucher.vo_kode_trx, server.*, ' .
  192. 'users.us_username, users.us_name, users.us_email, users.us_phone, users.us_balance, ' .
  193. 'users.us_data, users.us_telegram_id');
  194. $this->db->from('transaksi');
  195. $this->db->join('server', 'server.sv_id = transaksi.sv_id', 'LEFT');
  196. $this->db->join('voucher', 'voucher.vo_id = transaksi.vo_id', 'LEFT');
  197. $this->db->join('users', 'users.us_id = transaksi.us_id', 'LEFT');
  198. $this->db->where('transaksi.tr_tanggal < ', time() - ($this->system->perm->
  199. sms_reminder * 60));
  200. $this->db->where('transaksi.tr_tanggal > ', time() - (3600 * $this->system->set['jam_pembayaran']));
  201. $this->db->where('transaksi.tr_status_pembayaran', 'pending');
  202. $this->db->not_like('transaksi.tr_opsi', '"sms_reminder"');
  203. $query = $this->db->get();
  204. if (!$query->num_rows())
  205. return;
  206.  
  207. foreach ($query->result() as $trx) {
  208. $opsi = ($trx->tr_opsi ? json_decode($trx->tr_opsi, true) : array());
  209. $opsi['sms_reminder'] = format_tanggal(time());
  210. $this->db->where('tr_id', $trx->tr_id);
  211. $this->db->set('tr_opsi', json_encode($opsi));
  212. $this->db->update('transaksi');
  213. $pesan = "Trx #" . $trx->tr_id . " " . ($trx->vo_kode_trx ? $trx->vo_kode_trx :
  214. $trx->vo_kode) . "." . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx->tr_no_hp) .
  215. " " . @format_uang2($trx->tr_harga) . " belum dibayar.\r\n" . parse_url(site_url
  216. (), PHP_URL_HOST);
  217. send_sms($trx->us_id ? $trx->us_phone : $trx->tr_no_hp, $pesan);
  218. }
  219. }
  220.  
  221. public function get_servers($gateway = array(), $select = '*')
  222. {
  223. $this->db->select($select);
  224. $this->db->where_in('sv_gateway', $gateway);
  225. $query = $this->db->get('server');
  226. return $query->result();
  227. }
  228.  
  229. public function set_sukses($trx, $reply_message, $sn = null)
  230. {
  231. if ($this->cek_saldo) {
  232. $saldo = $this->get_saldo($reply_message);
  233. if ($saldo) {
  234. $this->db->where('sv_id', $trx->sv_id);
  235. $this->db->set('sv_saldo', $saldo);
  236. $this->db->update('server');
  237. }
  238. }
  239.  
  240. $income = $this->get_income($trx, $reply_message);
  241.  
  242. $opsi = $trx->tr_opsi ? json_decode($trx->tr_opsi, true) : array();
  243.  
  244. if (is_null($sn)) {
  245. $sn = $this->get_sn($trx->sv_regex_sn, $reply_message);
  246. }
  247. if ($sn) {
  248. $opsi['sn'] = $sn;
  249. }
  250.  
  251. $opsi['server_message'] = $reply_message;
  252.  
  253. $this->db->where('tr_id', $trx->tr_id);
  254. $this->db->set('tr_status', 'sukses');
  255. $this->db->set('tr_income', $income);
  256. $this->db->set('tr_opsi', json_encode($opsi));
  257. $this->db->update('transaksi');
  258.  
  259. $consumer_message = "Yth. " . $trx->us_name . " 'My Boss' " . ($trx->vo_kode_trx ? $trx->
  260. vo_kode_trx : $trx->vo_kode) . " ke " . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx->
  261. tr_no_hp) . " DONE. Harga: " . format_uang($trx->tr_harga2);
  262. if ($sn) {
  263. $consumer_message .= " SN: " . $sn;
  264. }
  265. $consumer_message .= ". Saldo " . format_uang($trx->us_balance) . " @" . format_tanggal($trx->tr_tanggal).". Terimakasih atas pembelian Anda.";
  266.  
  267. // Telegram notifikasi
  268. $telegram_consumer = "Pembelian " . ($trx->vo_kode_trx ? $trx->
  269. vo_kode_trx : $trx->vo_kode) . " ke " . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx->
  270. tr_no_hp) . " BERHASIL HORE. Hrg: " . format_uang($trx->tr_harga2);
  271. if ($sn) {
  272. $telegram_consumer .= " SN: " . $sn;
  273. }
  274. $telegram_consumer .= ". Saldo " . format_uang($trx->us_balance + $trx->tr_harga2) . " - " . format_uang($trx->tr_harga2) . " = " . format_uang($trx->us_balance) . " @" . format_tanggal($trx->tr_tanggal)."\r\n\r\nHarap berhati-hati terhadap penelpon yang mengatas-namakan Telegram yang meminta kode verifikasi login akun Telegram.";
  275.  
  276.  
  277. // Jabber notifikasi
  278. $jabber_consumer = "Yth. " . $trx->us_name . ", Isi " . ($trx->vo_kode_trx ? $trx->
  279. vo_kode_trx : $trx->vo_kode) . "." . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx->
  280. tr_no_hp) . " Hrg: " . format_uang($trx->tr_harga2) . " SUKSES.";
  281. if ($sn) {
  282. $jabber_consumer .= "\r\nSN: " . $sn;
  283. }
  284. $jabber_consumer .= ". Saldo " . format_uang($trx->us_balance + $trx->tr_harga2) . " - " . format_uang($trx->tr_harga2) . " = " . format_uang($trx->us_balance) . " @" . format_tanggal($trx->tr_tanggal).". Terimakasih atas pembelian Anda.";
  285.  
  286. // Mail notifikasi
  287. $mail_consumer = "Topup " . $trx->vo_nominal . " ke " . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx->
  288. tr_no_hp) . " Hrg: " . format_uang($trx->tr_harga2) . " SUKSES.";
  289. if ($sn) {
  290. $mail_consumer .= "\r\nSN: " . $sn;
  291. }
  292. $mail_consumer .= ". Saldo Anda " . format_uang($trx->us_balance) . " @" . format_tanggal($trx->tr_tanggal).". Terimakasih atas pembelian Anda.";
  293.  
  294. // Sms notifikasi ke pembeli
  295. $sms_end_user = "Terimakasih telah membeli Produk " . $trx->vo_nominal ." di Outlet ". $trx->us_name;
  296. if ($sn) {
  297. $sms_end_user .= ". SN: " . $sn;
  298. }
  299. $sms_end_user .= " @" . format_tanggal($trx->tr_tanggal) . " Mau Jualan Pulsa? Daftar aja disini Gratiss!";
  300.  
  301. if (in_array($trx->op_produk, $this->system->perm->sms_order)) {
  302. $this->send_sms($trx->tr_no_hp, $sms_end_user);
  303. }
  304.  
  305. if ($trx->us_id) {
  306. $this->db->insert('notifikasi', array(
  307. 'us_id' => $trx->us_id,
  308. 'nf_judul' => 'Status Order #' . $trx->tr_id,
  309. 'nf_teks' => $consumer_message,
  310. 'nf_link' => 'akun/riwayat-transaksi/view/' . $trx->tr_id,
  311. 'nf_feedback' => '1',
  312. 'nf_tanggal' => time(),
  313. ));
  314. if (isset($opsi['telegram_chat_id'])) {
  315. $this->send_telegram_message($opsi['telegram_chat_id'], $telegram_consumer);
  316. } elseif(isset($opsi['telegram_chat_id2'])){
  317. $this->send_telegram_message2($opsi['telegram_chat_id2'], $telegram_consumer);
  318. }elseif (isset($opsi['smstrx'])) {
  319. $this->send_sms($opsi['smstrx'], $consumer_message);
  320. } elseif (isset($opsi['jabbertrx'])) {
  321. $this->send_jabber($opsi['jabbertrx'], $jabber_consumer);
  322. } elseif (isset($opsi['order_via']) && $opsi['order_via'] == 'API') {
  323. $user_data = json_decode($trx->us_data, true);
  324. if (isset($user_data['api']) && isset($user_data['api']['reg_id'])) {
  325. $this->send_android_push($user_data['api']['reg_id'], $trx->tr_id, $consumer_message);
  326. }
  327. }
  328. elseif (isset($opsi['order_via']) && $opsi['order_via'] == 'WhatsApp') {
  329. //Tambahan transaksi via WA
  330. $this->load->helper('ht');
  331. notif_wa($trx->tr_id,$wa_consumer);
  332. }
  333. if ($this->system->perm->email_order == 'yes') {
  334. $this->send_email($trx->us_email, 'Status Order #' . $trx->tr_id, $mail_consumer .
  335. "\r\n\r\nSelengkapnya Klik " . site_url('akun/riwayat-transaksi/view/' . $trx->tr_id));
  336. }
  337. }
  338.  
  339. // Notifikasi admin
  340. if (!$this->adm_notifaction_config)
  341. $this->adm_notifaction_config = json_decode($this->system->get_set('trx_notifikasi'));
  342.  
  343. $this->db->insert('notifikasi', array(
  344. 'us_id' => '0',
  345. 'nf_admin' => '1',
  346. 'nf_judul' => $trx->sv_nama,
  347. 'nf_teks' => $reply_message,
  348. 'nf_link' => 'admin/transaksi/view/' . $trx->tr_id,
  349. 'nf_feedback' => '1',
  350. 'nf_tanggal' => time(),
  351. ));
  352. if ($this->adm_notifaction_config->sms) {
  353. $this->send_sms($this->adm_notifaction_config->sms, $reply_message);
  354. }
  355. if ($this->adm_notifaction_config->email) {
  356. $this->send_email($this->adm_notifaction_config->email, $trx->sv_nama, $reply_message .
  357. "\r\n\r\n" . site_url('admin/transaksi/view/' . $trx->tr_id));
  358. }
  359.  
  360. //notif saldo start
  361. $saldo = $this->get_saldo($reply_message);
  362. if ($saldo >0 && $saldo<500000) {
  363. $infosaldo = 'Sisa deposit serpul ['.$trx->sv_nama.'] : '.@format_uang2($saldo).",segera topup!";
  364. $infosaldo .= "\r\n"."Saldo tersedia di :";
  365. $sql = "Select * from payments where status ='on';";
  366. $query = $this->db->query($sql)->result();
  367. foreach ($query as $pay) {
  368. $infosaldo .= "\r\n- ".$pay->nama." : ".@format_uang2($pay->saldo);
  369. }
  370. $this->send_telegram_message("#idtelegram",$infosaldo);
  371. $this->send_email('#email','sisa saldo '.$trx->sv_nama.': '.@format_uang2($saldo),$infosaldo);
  372. }
  373. //notif saldo end
  374.  
  375. }
  376.  
  377. public function set_gagal($trx, $reply_message)
  378. {
  379. if ($this->cek_saldo) {
  380. $saldo = $this->get_saldo($reply_message);
  381. if ($saldo) {
  382. $this->db->where('sv_id', $trx->sv_id);
  383. $this->db->set('sv_saldo', $saldo);
  384. $this->db->update('server');
  385. }
  386. }
  387.  
  388. $opsi = $trx->tr_opsi ? json_decode($trx->tr_opsi, true) : array();
  389.  
  390. if (is_null($gg)) {
  391. $gg = $this->get_gg('/(GAGAL)(\. )(?P<gg>(.*?))(Sal\.|Sal |Sal:|Sal=|Saldo|Trx|Hrg|Refund)/i', $reply_message);
  392. }
  393. if ($gg) {
  394. $opsi['gg'] = $gg;
  395. }
  396.  
  397. $this->db->where('tr_id', $trx->tr_id);
  398. if ($trx->us_id && $this->auto_refund && $trx->sv_gateway != 'sms') {
  399. $this->db->set('tr_status_pembayaran', 'refund');
  400. }
  401. $this->db->set('tr_status', 'gagal');
  402. $this->db->set('tr_opsi', json_encode($opsi));
  403. $this->db->update('transaksi');
  404.  
  405. $consumer_message = "Trx " . ($trx->vo_kode_trx ? $trx-> vo_kode_trx : $trx->vo_kode) . "." . ($trx->tr_id_plgn ? $trx->tr_id_plgn : $trx-> tr_no_hp) . " GAGAL. " .$gg. ". Refund: " . format_uang($trx->tr_harga2) . ", Saldo Tetap: " . format_uang($trx->us_balance + $trx->tr_harga2) . " @" . format_tanggal($trx->tr_tanggal) . "\r\nhttp:" . parse_url(site_url(), PHP_URL_HOST);
  406.  
  407. if (in_array($trx->op_produk, $this->system->perm->sms_order) && !isset($opsi['jabbertrx']) &&
  408. !isset($opsi['smstrx']) && !isset($opsi['telegram_chat_id'])) {
  409. $this->send_sms($trx->us_phone, $consumer_message);
  410. }
  411.  
  412. if ($trx->us_id) {
  413. if ($this->auto_refund && $trx->sv_gateway != 'sms') {
  414. $note = 'Refund Pembayaran / Trx #' . $trx->tr_id;
  415. $this->db->where('us_id', $trx->us_id);
  416. $this->db->where('info', $note);
  417. if (!$this->db->count_all_results('balance_history')) {
  418. $this->db->query("UPDATE users SET us_balance = us_balance + $trx->tr_harga2 WHERE us_id = '$trx->us_id'");
  419. insert_balance_history(array(
  420. $trx->us_id,
  421. '0',
  422. $trx->tr_harga2,
  423. ($trx->us_balance + $trx->tr_harga2),
  424. $note,
  425. time(),
  426. ));
  427. }
  428. }
  429. $this->db->insert('notifikasi', array(
  430. 'us_id' => $trx->us_id,
  431. 'nf_judul' => 'Status Order #' . $trx->tr_id,
  432. 'nf_teks' => $consumer_message,
  433. 'nf_link' => 'akun/riwayat-transaksi/view/' . $trx->tr_id,
  434. 'nf_feedback' => '1',
  435. 'nf_tanggal' => time(),
  436. ));
  437. if (isset($opsi['telegram_chat_id'])) {
  438. $this->send_telegram_message($opsi['telegram_chat_id'], $consumer_message);
  439. }elseif(isset($opsi['telegram_chat_id2'])){
  440. $this->send_telegram_message2($opsi['telegram_chat_id2'], $consumer_message);
  441. } elseif (isset($opsi['smstrx'])) {
  442. $this->send_sms($opsi['smstrx'], $consumer_message);
  443. } elseif (isset($opsi['jabbertrx'])) {
  444. $this->send_jabber($opsi['jabbertrx'], $consumer_message);
  445. } elseif (isset($opsi['order_via']) && $opsi['order_via'] == 'API') {
  446. $user_data = json_decode($trx->us_data, true);
  447. if (isset($user_data['api']) && isset($user_data['api']['reg_id'])) {
  448. $this->send_android_push($user_data['api']['reg_id'], $trx->tr_id, $consumer_message);
  449. }
  450. }
  451. elseif (isset($opsi['order_via']) && $opsi['order_via'] == 'WhatsApp') {
  452. //Tambahan transaksi via WA
  453. $this->load->helper('ht');
  454. notif_wa($trx->tr_id,$consumer_message);
  455. }
  456. if ($this->system->perm->email_order == 'yes') {
  457. $this->send_email($trx->us_email, 'Status Order #' . $trx->tr_id, $consumer_message .
  458. "\r\n\r\n" . site_url('akun/riwayat-transaksi/view/' . $trx->tr_id));
  459. }
  460. }
  461.  
  462. // Notifikasi admin
  463. if (!$this->adm_notifaction_config)
  464. $this->adm_notifaction_config = json_decode($this->system->get_set('trx_notifikasi'));
  465.  
  466. $this->db->insert('notifikasi', array(
  467. 'us_id' => '0',
  468. 'nf_admin' => '1',
  469. 'nf_judul' => $trx->sv_nama,
  470. 'nf_teks' => $reply_message,
  471. 'nf_link' => 'admin/transaksi/view/' . $trx->tr_id,
  472. 'nf_feedback' => '1',
  473. 'nf_tanggal' => time(),
  474. ));
  475.  
  476. if ($this->adm_notifaction_config->sms) {
  477. $this->send_sms($this->adm_notifaction_config->sms, $reply_message);
  478. }
  479. if ($this->adm_notifaction_config->email) {
  480. $this->send_email($this->adm_notifaction_config->email, $trx->sv_nama, $reply_message);
  481. }
  482. }
  483.  
  484. public function cek_status($pesan, $regex_sukses, $regex_gagal)
  485. {
  486. $status = null;
  487. if ($regex_sukses) {
  488. $arr = explode('|', $regex_sukses);
  489. foreach ($arr as $ar) {
  490. if ($ar) {
  491. $arr1 = explode(',', $ar);
  492. $finds = count($arr1);
  493. foreach ($arr1 as $ar1) {
  494. if ($ar1) {
  495. if (stripos($pesan, $ar1) !== false) {
  496. $finds -= 1;
  497. }
  498. }
  499. }
  500. if ($finds == 0) {
  501. return 'sukses';
  502. }
  503. }
  504. }
  505. }
  506. if ($regex_gagal) {
  507. $arr = explode('|', $regex_gagal);
  508. foreach ($arr as $ar) {
  509. if ($ar) {
  510. $arr1 = explode(',', $ar);
  511. $finds = count($arr1);
  512. foreach ($arr1 as $ar1) {
  513. if ($ar1) {
  514. if (stripos($pesan, $ar1) !== false) {
  515. $finds -= 1;
  516. }
  517. }
  518.  
  519. }
  520. if ($finds == 0) {
  521. return 'gagal';
  522. }
  523. }
  524. }
  525. }
  526. return null;
  527. }
  528.  
  529. public function set_proses($trx)
  530. {
  531. $this->db->where('tr_id', $trx->tr_id);
  532. $this->db->set('tr_status', '-');
  533. $this->db->update('transaksi');
  534. }
  535.  
  536. public function get_sn($regex, $message)
  537. {
  538. $message = str_replace("\n", " ", $message);
  539. if (!$regex)
  540. return '';
  541. preg_match($regex, $message, $matches);
  542. $sn = '';
  543. if (isset($matches['sn'])) {
  544. $sn = trim($matches['sn']);
  545.  
  546. if (strpos($sn, 'Bisa diorderkan kembali') !== false) {
  547. $xsn = explode('Bisa diorderkan kembali', $sn);
  548. $sn = trim($xsn[0]);
  549. } elseif (strpos($sn, 'Harga:') !== false) {
  550. $xsn = explode('Harga:', $sn);
  551. $sn = trim($xsn[0]);
  552. } elseif (strpos($sn, 'Tgl:') !== false) {
  553. $xsn = explode('Tgl:', $sn);
  554. $sn = trim($xsn[0]);
  555. } elseif (strpos($sn, 'Hrg') !== false) {
  556. $xsn = explode('Hrg', $sn);
  557. $sn = trim($xsn[0]);
  558. }
  559.  
  560. $sn = (substr($sn, -1) == '.' ? substr($sn, 0, -1) : $sn);
  561. }
  562. return $sn;
  563. }
  564.  
  565. public function get_gg($regex, $message)
  566. {
  567. $message = str_replace("\n", " ", $message);
  568. if (!$regex)
  569. return '';
  570. preg_match($regex, $message, $matches);
  571. $gg = '';
  572. if (isset($matches['gg'])) {
  573. $gg = trim($matches['gg']);
  574. $gg = (substr($gg, -1) == '.' ? substr($gg, 0, -1) : $gg);
  575. }
  576. return $gg;
  577. }
  578.  
  579. public function get_income($trx, $message)
  580. {
  581. $harga_beli = 0;
  582. $harga_jual = $trx->us_id ? $trx->tr_harga2 : $trx->tr_harga;
  583. $income = 0;
  584. $regex = array(
  585. '/([0-9\.\,]{4,16})( - |-)(?P<harga>[a-zA-Z0-9\.\,\:]{4,32})( =|=)/s',
  586. '/(Hrg|Harga)(=| = |:| : | Rp\.| )(?P<harga>[0-9\.\,]{4,32})/is',
  587. );
  588. for ($i = 0; $i < count($regex); $i++) {
  589. preg_match($regex[$i], $message, $matches);
  590. if (isset($matches['harga'])) {
  591. $harga_beli = (int)preg_replace('/\D/', '', $matches['harga']);
  592. $income = $harga_jual - $harga_beli;
  593. }
  594. }
  595. if (!$harga_beli && $trx->vo_harga_beli)
  596. $harga_beli = $trx->vo_harga_beli;
  597.  
  598. if ($harga_beli != $trx->vo_harga_beli) {
  599. $harga_umum = $harga_beli + ($trx->vo_harga - $harga_beli);
  600.  
  601. if ($trx->vo_harga_reseller)
  602. $harga_reseller = $harga_umum - ($trx->vo_harga - $trx->vo_harga_reseller);
  603. else
  604. $harga_reseller = $harga_umum;
  605.  
  606. if ($harga_reseller < $harga_beli)
  607. $harga_reseller = $harga_umum;
  608.  
  609. $this->db->where('vo_id', $trx->vo_id);
  610. $this->db->set('vo_harga_beli', $harga_beli);
  611. $this->db->set('vo_harga', $harga_umum);
  612. $this->db->set('vo_harga_reseller', $harga_reseller);
  613. $this->db->update('voucher');
  614. }
  615. if ($income == 0 && $harga_beli != 0)
  616. $income = $harga_jual - $harga_beli;
  617. return $income;
  618. }
  619.  
  620. public function get_saldo($message)
  621. {
  622. $message = str_replace("\n", " ", $message);
  623. $regex = array(
  624. '/([0-9\.\,]{4,16})( - |-)([a-zA-Z0-9\.\,\:]{4,32})( = |=)(?P<saldo>[a-zA-Z0-9\.\,\:]{4,32})/',
  625. '/(?P<saldo>[0-9\.,]+), masih proses/i',
  626. '/(Sal|Saldo)(=| = |:| : | )(?P<saldo>[a-zA-Z0-9\.\,\:]{4,32})/i');
  627. for ($i = 0; $i < count($regex); $i++) {
  628. preg_match($regex[$i], $message, $matches);
  629. if (isset($matches['saldo'])) {
  630. return (int)preg_replace('/\D/', '', $matches['saldo']);
  631. }
  632. }
  633. return 0;
  634. }
  635.  
  636. public function get_format_trx($trx)
  637. {
  638. $format = json_decode($trx->sv_format_trx, true);
  639. $format_trx = $format[$trx->op_produk];
  640. $format_dobel = $trx->op_produk . '_dobel';
  641. $total = 0;
  642. if (isset($format[$format_dobel])) {
  643. $total = $this->count_success_trx($trx);
  644. if ($total >= 1)
  645. $format_trx = $format[$format_dobel];
  646. }
  647. $replaces = array(
  648. '{ID}' => $trx->tr_id,
  649. '{KODE}' => $trx->vo_kode,
  650. '{NO_HP}' => $trx->tr_no_hp,
  651. '{NUM}' => ($total + 1),
  652. '{ID_PLGN}' => $trx->tr_id_plgn,
  653. '{PIN}' => $this->system->decrypt_data($trx->sv_pin),
  654. );
  655. $pesan = str_ireplace(array_keys($replaces), array_values($replaces), $format_trx);
  656. return $pesan;
  657. }
  658.  
  659. public function count_success_trx($trx)
  660. {
  661. $this->db->select('tr_id');
  662. $this->db->where('sv_id', $trx->sv_id);
  663. $this->db->where('vo_id', $trx->vo_id);
  664. if ($trx->tr_id_plgn)
  665. $this->db->where('tr_id_plgn', $trx->tr_id_plgn);
  666. else
  667. $this->db->where('tr_no_hp', $trx->tr_no_hp);
  668. $this->db->where('tr_status_pembayaran', 'sukses');
  669. $this->db->where('tr_status', 'sukses');
  670. $this->db->where('tr_tanggal >', strtotime(date('Y/m/d 00:00:00')));
  671. $this->db->where('tr_tanggal <', strtotime(date('Y/m/d 23:59:59')));
  672. return $this->db->count_all_results('transaksi');
  673. }
  674.  
  675. public function send_sms($phone, $message)
  676. {
  677. $this->db->insert('sms_keluar', array(
  678. 'out_to' => $phone,
  679. 'out_message' => $message,
  680. 'out_submit_date' => time(),
  681. ));
  682. }
  683.  
  684. protected function send_jabber($receiver, $message)
  685. {
  686. $this->load->model('sms_model');
  687. $jabber_api = json_decode($this->system->get_set('jabber_api'), true);
  688. if ($jabber_api['server_url'] && $jabber_api['username'] && $jabber_api['password']) {
  689. if ($this->sms_model->send_mass_jabber(array($receiver), $message, $jabber_api)) {
  690. return true;
  691. } else {
  692. return false;
  693. }
  694. } else {
  695. $this->sms_model->send_mass_jabber(array($receiver), $message, $jabber_api);
  696. return true;
  697. }
  698. }
  699.  
  700. public function send_email($to, $subject, $message)
  701. {
  702. $this->load->library('email');
  703. $this->email->from($this->system->get_set('site_email'), $this->system->set['site_name']);
  704. $this->email->to($to);
  705. $this->email->subject($subject);
  706. $this->email->message($message . "\r\n\r\n" . $this->system->set['site_name'] .
  707. "\r\n" . site_url());
  708. @$this->email->send();
  709. }
  710.  
  711. public function send_telegram_message2($telegram_id, $message)
  712. {
  713. if (!$this->telebot_config)
  714. $this->telebot_config = json_decode($this->system->get_set('modul_telegram'));
  715.  
  716. if (!$this->telebot_config->token)
  717. return;
  718.  
  719. $ch = curl_init();
  720. curl_setopt($ch, CURLOPT_URL, 'https://api.telegram.org/bot' . $this->
  721. telebot_config->token . '/sendMessage');
  722. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  723. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  724. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  725. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
  726. curl_setopt($ch, CURLOPT_POST, true);
  727. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
  728. 'chat_id' => $telegram_id,
  729. 'text' => $message,
  730. 'disable_web_page_preview' => true,
  731. )));
  732. $req = curl_exec($ch);
  733. curl_close($ch);
  734.  
  735. return $req;
  736. }
  737.  
  738. public function send_telegram_message($telegram_id, $message)
  739. {
  740. if (!$this->telebot_config)
  741. $this->telebot_config = json_decode($this->system->get_set('telegram_bot'));
  742.  
  743. if (!$this->telebot_config->token)
  744. return;
  745.  
  746. $ch = curl_init();
  747. curl_setopt($ch, CURLOPT_URL, 'https://api.telegram.org/bot' . $this->
  748. telebot_config->token . '/sendMessage');
  749. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  750. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  751. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  752. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
  753. curl_setopt($ch, CURLOPT_POST, true);
  754. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
  755. 'chat_id' => $telegram_id,
  756. 'text' => $message,
  757. 'disable_web_page_preview' => true,
  758. )));
  759. $req = curl_exec($ch);
  760. curl_close($ch);
  761.  
  762. return $req;
  763. }
  764.  
  765. public function send_android_push($reg_id, $trx_id, $body)
  766. {
  767. if (!$this->apk_config)
  768. $this->apk_config = @json_decode($this->system->get_set('aplikasi_android'));
  769.  
  770. $ch = curl_init();
  771. curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
  772. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  773. 'Authorization: key=' . $this->apk_config->fcm_server_key,
  774. 'Content-Type: application/json',
  775. ));
  776. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  777. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  778. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  779. curl_setopt($ch, CURLOPT_POST, true);
  780. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
  781. 'to' => $reg_id,
  782. 'notification' => array(
  783. 'title' => 'Status Order ' . $trx_id,
  784. 'body' => $body,
  785. 'sound' => 'mySound',
  786. 'click_action' => 'DETAIL_TRANSAKSI',
  787. ),
  788. 'data' => array('trxID' => $trx_id),
  789. )));
  790. $req = curl_exec($ch);
  791. curl_close($ch);
  792.  
  793. return $req;
  794. }
  795. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement