WithdrawController.php 4.2 KB

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