Withdraw.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace app\api\controller\service;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Exception;
  6. use think\Loader;
  7. /**
  8. * 首页接口
  9. */
  10. class Withdraw extends Api
  11. {
  12. protected $noNeedLogin = [''];
  13. protected $noNeedRight = ['*'];
  14. public function apply()
  15. {
  16. $uid = $this->auth->id;
  17. $userInfo = \app\api\model\service\UserInfo::getUserMoney($uid);
  18. if (!$this->request->isPost()) {
  19. $this->error('请求方式异常');
  20. }
  21. $post = input('post.','','trim,strip_tags,htmlspecialchars,xss_clean');
  22. if(isset($post['types']) && $post['types'] == 'withdraw')
  23. {
  24. $post['user_id'] = $uid;
  25. $post['num'] = sprintf("%.2f",$post['num']);
  26. $validate = Loader::validate('service.Withdraw');
  27. if(!$validate->scene('add')->check($post)){
  28. $this->error($validate->getError());
  29. }
  30. Db::startTrans();
  31. try{
  32. \app\api\model\service\Withdraw::apply($post);
  33. Db::commit();
  34. } catch (Exception $e) {
  35. Db::rollback();
  36. $this->error('提现申请失败',$e->getMessage());
  37. }
  38. $this->success('提现申请已提交');
  39. }
  40. $this->success('信息返回成功',$userInfo);
  41. }
  42. public function getList()
  43. {
  44. if (!$this->request->isPost()) {
  45. $this->error('请求方式异常');
  46. }
  47. $uid = $this->auth->id;
  48. $post = input('post.','');
  49. $post['user_id'] = $uid;
  50. $list = \app\api\model\service\Withdraw::getList($post);
  51. $this->success('列表信息返回成功',$list);
  52. }
  53. public function moneyInfo()
  54. {
  55. if (!$this->request->isPost()) {
  56. $this->error('请求方式异常');
  57. }
  58. $uid = $this->auth->id;
  59. $data['money'] = \app\api\model\service\UserInfo::where(['user_id'=>$uid])->field('id,money,shop_money,shop_user_money')->find();
  60. $type = input('type/d',0);
  61. $page = input('page/d',1);
  62. if($type == 0)
  63. {
  64. $list = \app\api\model\service\UserMoneyLog::where(['user_id'=>$uid])->order('id desc')->page($page)->limit(10)->select();
  65. }elseif($type == 1){
  66. $list = \app\api\model\service\ShopMoneyLog::where(['user_id'=>$uid])->order('id desc')->page($page)->limit(10)->select();
  67. }elseif($type == 2){
  68. $list = \app\api\model\service\ShopUserMoneyLog::where(['user_id'=>$uid])->order('id desc')->page($page)->limit(10)->select();
  69. }
  70. $data['list'] = $list;
  71. $this->success('信息返回成功',$data);
  72. }
  73. public function getWithdrawDay()
  74. {
  75. if (!$this->request->isPost()) {
  76. $this->error('请求方式异常');
  77. }
  78. $uid = $this->auth->id;
  79. $type = input('type/d','');
  80. if($type == 0){
  81. $config = \app\api\model\service\ProjectConfig::where(['state'=>1])->field('withdrawtype,day')->find();
  82. }else{
  83. $shopId = \app\api\model\service\Skill::where(['user_id'=>$uid])->value('shop_id');
  84. $config = \app\api\model\service\Shop::where(['id'=>$shopId])->field('withdrawtype,day')->find();
  85. }
  86. $this->success('信息返回成功',$config);
  87. }
  88. public function shopWithdrawList()
  89. {
  90. if (!$this->request->isPost()) {
  91. $this->error('请求方式异常');
  92. }
  93. $uid = $this->auth->id;
  94. $shopId = \app\api\model\service\Shop::where(['user_id'=>$uid])->value('id');
  95. $post = input('post.','','trim,strip_tags');
  96. $post['shop_id'] = $shopId;
  97. $post['type'] = 1;
  98. $list = \app\api\model\service\Withdraw::getList($post);
  99. foreach ($list as $key=>$value)
  100. {
  101. $list[$key]['skill'] = \app\api\model\service\Skill::where(['user_id'=>$value['user_id']])->field('id,name,image')->find();
  102. $list[$key]['shop_money'] = \app\api\model\service\UserInfo::where('user_id',$value['user_id'])->value('shop_money');
  103. }
  104. $this->success('信息返回成功',$list);
  105. }
  106. public function shopCheckWithdraw()
  107. {
  108. if (!$this->request->isPost()) {
  109. $this->error('请求方式异常');
  110. }
  111. $uid = $this->auth->id;
  112. $shopId = \app\api\model\service\Shop::where(['user_id'=>$uid])->value('id');
  113. $post = input('post.','','trim,strip_tags');
  114. $info = \app\api\model\service\Withdraw::where(['id'=>$post['id'],'shop_id'=>$shopId])->find();
  115. !$info && $this->error('当前订单无法审核');
  116. Db::startTrans();
  117. try{
  118. $withdraw = new \app\api\model\service\Withdraw();
  119. $withdraw->allowField('note,state,images')->save($post,['id'=>$post['id']]);
  120. if($post['state'] == -1)
  121. {
  122. \app\api\model\service\UserInfo::shopMoney(+$info['num'],$info['user_id'],'审核拒绝余额退回');
  123. }
  124. Db::commit();
  125. } catch (Exception $e) {
  126. Db::rollback();
  127. $this->error('提现申请失败',$e->getMessage());
  128. }
  129. $this->success('提现订单已处理');
  130. }
  131. }