Cron.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php namespace Pay\Yspay;
  2. use Dever;
  3. class Cron
  4. {
  5. # 定时更新银联账户余额信息
  6. public function account_api()
  7. {
  8. # 获取有银联商户号的门店
  9. $where = array();
  10. $mid = Dever::input('mid');
  11. if ($mid) {
  12. $where['mid'] = $mid;
  13. }
  14. $merchant = Dever::db('pay/yspay_merchant')->select($where);
  15. if (!$merchant) {
  16. return 'error';
  17. }
  18. foreach ($merchant as $k => $v) {
  19. if ($v['mid']) {
  20. $config = Dever::db('pay/yspay')->one(array('account_id' => $v['account_id']));
  21. if ($config['type'] == 1) {
  22. $data = Dever::load('pay/yspay/account')->query($v['mid']);
  23. $update['where_id'] = $v['id'];
  24. $update['yue'] = $data;
  25. Dever::db('pay/yspay_merchant')->update($update);
  26. }
  27. }
  28. }
  29. return 'ok';
  30. }
  31. # 定时获取银联提现信息
  32. public function tixian_api()
  33. {
  34. $num = Dever::input('num', 1);
  35. $start = Dever::input('start', date('Ymd', strtotime('-'.$num.' day')));
  36. $end = Dever::input('end', date('Ymd'));
  37. # 获取有银联商户号的门店
  38. $where = array();
  39. $mid = Dever::input('mid');
  40. if ($mid) {
  41. $where['mid'] = $mid;
  42. }
  43. $test = Dever::input('test');
  44. $merchant = Dever::db('pay/yspay_merchant')->select($where);
  45. if (!$merchant) {
  46. return 'error';
  47. }
  48. foreach ($merchant as $k => $v) {
  49. if ($v['mid']) {
  50. $data = Dever::load('pay/yspay/account')->record($v['mid'], $start, $end);
  51. if ($data) {
  52. if ($test == 1) {
  53. print_r($data);die;
  54. }
  55. foreach ($data as $k1 => $v1) {
  56. $update = array();
  57. $update['merchant_id'] = $v['id'];
  58. $update['type'] = $v1['trxTypeDtl'];
  59. $update['tdate'] = Dever::maketime($v1['trxTime']);
  60. $update['mid'] = $v1['mchntNo'];
  61. $update['cardNo'] = $v1['cardNo'];
  62. $update['order_num'] = $v1['sysOrderId'];
  63. $update['status'] = $v1['status'];
  64. $update['clear'] = true;
  65. $info = Dever::db('pay/yspay_tixian')->one($update);
  66. $update['cash'] = $v1['transAmt'];
  67. if (!$info) {
  68. Dever::db('pay/yspay_tixian')->insert($update);
  69. } else {
  70. $update['where_id'] = $info['id'];
  71. Dever::db('pay/yspay_tixian')->update($update);
  72. }
  73. $total = Dever::db('pay/yspay_tixian')->getTotal(array('shop_id' => $v['id'], 'status' => 4));
  74. if ($total) {
  75. $account_data['tx_cash'] = $total['cash'];
  76. $account_data['where_id'] = $v['id'];
  77. Dever::db('pay/yspay_merchant')->update($account_data);
  78. }
  79. }
  80. }
  81. }
  82. }
  83. return 'ok';
  84. }
  85. }