WithdrawController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace app\index\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Withdraw;
  5. use app\model\UuidRelation;
  6. use app\model\Agent;
  7. use app\model\Technical;
  8. use app\model\Tuanzhang;
  9. use app\model\Store;
  10. use app\model\Operatingcity;
  11. use app\model\Config;
  12. class WithdrawController extends Base
  13. {
  14. public function index()
  15. {
  16. $where['weid'] = weid();
  17. $where['uid'] = UID();
  18. $data = Withdraw::where($where)
  19. ->order('id desc')
  20. ->select()
  21. ->toArray();
  22. foreach ($data as &$vo) {
  23. if (!empty($vo['pay_time'])) {
  24. $vo['pay_time'] = time_format($vo['pay_time']);
  25. }
  26. }
  27. return $this->json(['data' => $data]);
  28. }
  29. public function calculate()
  30. {
  31. $message = '返回消息';
  32. $errno = 0;
  33. $amounts = input('post.amounts', '', 'serach_in');
  34. $mo = input('post.mo', '', 'serach_in');
  35. $Config = Config::getconfig($mo);
  36. if (empty($Config['cash_service_charge'])) {
  37. $data['poundage'] = 0;
  38. $data['poundage_rate'] = $Config['cash_service_charge'];
  39. $data['actual_amounts'] = $amounts;
  40. } else {
  41. $data['poundage'] = $amounts * percent_to_num($Config['cash_service_charge']);
  42. $data['poundage_rate'] = $Config['cash_service_charge'];
  43. $data['actual_amounts'] = $amounts - $data['poundage'];
  44. }
  45. return $this->json(['message' => $message, 'errno' => $errno, 'data' => $data]);
  46. }
  47. public function apply()
  48. {
  49. $message = '返回消息';
  50. $data = [];
  51. $uid = UID();
  52. $amounts = input('post.amounts', '', 'serach_in');
  53. $bid = input('post.bid', '', 'serach_in');
  54. $pay_from = input('get.from', '', 'serach_in');
  55. $mo = input('post.mo', '', 'serach_in');
  56. $uuid = UuidRelation::getuuid(UID(), $mo);
  57. $Config = Config::getconfig($mo);
  58. if ($mo == 'agent') {
  59. $moapply = Agent::where('uid', $uid)->find();
  60. $moapplyid = $moapply->id;
  61. $moapplyincome = $moapply->income;
  62. $model = new Agent;
  63. } elseif ($mo == 'technical') {
  64. $moapply = Technical::where('uuid', $uuid)->find();
  65. $moapplyid = $moapply->id;
  66. $moapplyincome = $moapply->income;
  67. $model = new Technical;
  68. }elseif ($mo == 'tuanzhang') {
  69. $moapply = Tuanzhang::where('uuid', $uuid)->find();
  70. $moapplyid = $moapply->id;
  71. $moapplyincome = $moapply->income;
  72. $model = new Tuanzhang;
  73. } elseif ($mo == 'store') {
  74. $moapply = Store::getInfobyuid(UID());
  75. $moapplyincome = $moapply['income'];
  76. $moapplyid = $moapply['id'];
  77. $model = new Store;
  78. } elseif ($mo == 'operatingcity') {
  79. $moapply = Operatingcity::where('uuid', $uuid)->find();
  80. $moapplyid = $moapply->id;
  81. $moapplyincome = $moapply->income;
  82. $model = new Operatingcity;
  83. }
  84. if ($moapplyincome >= $amounts) {
  85. $param['withdraw_sn'] = $this->build_no();
  86. $param['mo'] = $mo;
  87. $param['amounts'] = $amounts;
  88. $param['actual_amounts'] = $amounts;
  89. if (empty($Config['cash_service_charge'])) {
  90. $param['poundage'] = 0;
  91. } else {
  92. $param['poundage'] = $amounts * percent_to_num($Config['cash_service_charge']);
  93. $param['poundage_rate'] = $Config['cash_service_charge'];
  94. $param['actual_amounts'] = $amounts - $param['poundage'];
  95. }
  96. $param['status'] = 0;
  97. $param['uid'] = $uid;
  98. $param['bid'] = $bid;
  99. $param['pay_from'] = $pay_from;
  100. $param["weid"] = weid();
  101. $Withdraw = Withdraw::create($param);
  102. if ($Withdraw) {
  103. $model->where('id', $moapplyid)->dec('income', $amounts)->update();
  104. $errno = 0;
  105. $message = '您的提现申请己提交';
  106. } else {
  107. $errno = 1;
  108. $message = '申请提现失败,请联系管理员';
  109. }
  110. } else {
  111. $errno = 1;
  112. $message = '申请提现失败,提现金额不能大于帐户余额';
  113. }
  114. return $this->json(['message' => $message, 'errno' => $errno, 'data' => $data]);
  115. }
  116. //生成唯一编号
  117. function build_no()
  118. {
  119. return date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
  120. }
  121. }