Tixian.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Pay\Yspay;
  3. use Dever;
  4. class Tixian
  5. {
  6. private $num = 1000;
  7. #生成订单号
  8. public function getOrderId()
  9. {
  10. $where['order_num'] = Dever::order('TX');
  11. $where['clear'] = true;
  12. $state = Dever::db('pay/yspay_tixian_log')->one($where);
  13. if (!$state) {
  14. return $where['order_num'];
  15. } else {
  16. return $this->getOrderId();
  17. }
  18. }
  19. public function insert($id, $name, $data)
  20. {
  21. $merchant_id = Dever::param('merchant_id',$data);
  22. $cash = Dever::param('cash',$data);
  23. $desc = Dever::param('desc',$data);
  24. $account = Dever::db('shop/yspay_merchant')->one($merchant_id);
  25. if (!$account) {
  26. Dever::alert('账户不存在');
  27. }
  28. if ($cash <= 0) {
  29. Dever::alert('提现金额不能小于0');
  30. }
  31. $cash = $cash * $this->num;
  32. if ($cash > $account['yue']) {
  33. Dever::alert('账户余额不足');
  34. }
  35. }
  36. public function update($id, $name, $data)
  37. {
  38. $merchant_id = Dever::param('merchant_id',$data);
  39. $cash = Dever::param('cash',$data);
  40. $desc = Dever::param('desc',$data);
  41. $account = Dever::db('shop/yspay_merchant')->one($merchant_id);
  42. if (!$account) {
  43. Dever::alert('账户不存在');
  44. }
  45. if ($cash <= 0) {
  46. Dever::alert('提现金额不能小于0');
  47. }
  48. $cash = $cash * $this->num;
  49. if ($cash > $account['yue']) {
  50. Dever::alert('账户余额不足');
  51. }
  52. $order_num = $this->getOrderId();
  53. $account['desc'] = $desc;
  54. $account['mtype'] = 2;
  55. Dever::load('pay/yspay/account')->action($account['mid'], $order_num, -1, 2, $cash, $account);
  56. }
  57. }