Core.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php namespace Pay\Lib;
  2. use Dever;
  3. class Core
  4. {
  5. /**
  6. * 更新订单状态
  7. */
  8. public function updateOrder($order_id, $cash, $desc = '')
  9. {
  10. $db = Dever::db('pay/order');
  11. $info = $db->one(array('order_id' => $order_id, 'status' => 1));
  12. if ($info) {
  13. $param['where_id'] = $info['id'];
  14. $param['status'] = 2;
  15. $msg = '支付成功';
  16. if ($desc) {
  17. $param['status'] = 3;
  18. $param['status_desc'] = $desc;
  19. $msg = '支付失败||' . $desc;
  20. }
  21. $this->log($msg, $info);
  22. $db->update($param);
  23. }
  24. }
  25. /**
  26. * 更新订单的支付信息
  27. */
  28. protected function updateOrderParam($order_id, $data)
  29. {
  30. $db = Dever::db('pay/order');
  31. $info = $db->one(array('order_id' => $order_id, 'status' => 1));
  32. if ($info) {
  33. $param['where_id'] = $info['id'];
  34. $param['param'] = Dever::array_encode($data);
  35. $db->update($param);
  36. }
  37. }
  38. /**
  39. * 创建订单
  40. */
  41. protected function createOrder($uid, $username, $account_id, $product_id, $name, $cash, $type)
  42. {
  43. $db = Dever::db('pay/order');
  44. $order_id = Dever::order();
  45. $info = $db->one(array('order_id' => $order_id));
  46. if ($info) {
  47. return $this->createOrder();
  48. } else {
  49. $add['status'] = 1;
  50. $add['uid'] = $uid;
  51. $add['username'] = $username;
  52. $add['account_id'] = $account_id;
  53. $add['name'] = $name;
  54. $add['cash'] = $cash;
  55. $add['type'] = $type;
  56. $add['order_id'] = $order_id;
  57. $add['product_id'] = $product_id;
  58. $add['id'] = $db->insert($add);
  59. $msg = '发起支付';
  60. $this->log($msg, $add);
  61. }
  62. return $order_id;
  63. }
  64. /**
  65. * 获取回调url
  66. */
  67. protected function url($type, $account_id)
  68. {
  69. //$project = Dever::project('pay');
  70. //return $project['url'] . 'daemon/notify/'.$type.'.php';
  71. return Dever::url('api.notify?account_id=' . $account_id, 'pay');
  72. }
  73. /**
  74. * 写日志
  75. */
  76. protected function log($msg, $data = array())
  77. {
  78. if ($data) {
  79. $data = Dever::json_encode($data);
  80. $msg .= '||' . $data;
  81. /*
  82. $insert = $data;
  83. $insert['cdate'] = time();
  84. Dever::db('pay/order_log')->insert($insert);
  85. */
  86. }
  87. Dever::log($msg, 'pay');
  88. }
  89. }