Bank.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 客户收益管理
  7. */
  8. namespace app\allwin\controller;
  9. use app\allwin\model\Bank as ModelBank;
  10. use app\allwin\model\BankBill;
  11. use app\allwin\model\BankCash;
  12. use app\allwin\model\AllwinStore;
  13. use think\facade\Request;
  14. use think\helper\Time;
  15. use app\common\model\SystemUserBank;
  16. use app\common\model\SystemUser;
  17. class Bank extends Common{
  18. public function initialize(){
  19. parent::initialize();
  20. $this->assign('pathMaps', [['name'=>'账号余额','url'=>url("bank/index")]]);
  21. }
  22. /**
  23. * 客户收益管理
  24. * @return void
  25. */
  26. public function index(int $types = 0){
  27. $condition = [];
  28. $condition[] = ['member_miniapp_id','=',$this->member_miniapp_id];
  29. $time = Request::param('time/d',0);
  30. if($time){
  31. switch ($time) {
  32. case 2:
  33. list($start, $end) = Time::yesterday();
  34. break;
  35. case 30:
  36. list($start, $end) = Time::month();
  37. break;
  38. case 60:
  39. list($start, $end) = Time::lastMonth();
  40. break;
  41. default:
  42. list($start, $end) = Time::today();
  43. break;
  44. }
  45. $condition[] = ['update_time','>=',$start];
  46. $condition[] = ['update_time','<=',$end];
  47. }
  48. $starttime = Request::param('starttime/s');
  49. $endtime = Request::param('endtime/s');
  50. if($starttime){
  51. $condition[] = ['update_time','>=',strtotime($starttime)];
  52. }
  53. if($endtime){
  54. $condition[] = ['update_time','<=',strtotime($endtime)];
  55. }
  56. $view['receipts'] = BankBill::where($condition)->where('money','>',0)->sum('money'); //收入
  57. $view['expenses'] = BankBill::where($condition)->where('money','<',0)->sum('money'); //支付
  58. $view['time'] = $time;
  59. $view['starttime'] = $starttime;
  60. $view['endtime'] = $endtime;
  61. //查询帐号
  62. switch ($types) {
  63. case 1:
  64. $order = 'income_money desc';
  65. break;
  66. case 2:
  67. $order = 'money desc';
  68. break;
  69. case 3:
  70. $order = 'lack_money desc';
  71. break;
  72. case 4:
  73. $order = 'shop_money desc';
  74. break;
  75. default:
  76. $order = 'update_time desc';
  77. break;
  78. }
  79. $keyword = trim(input('get.keyword','','htmlspecialchars'));
  80. $view['list'] = ModelBank::bank($this->member_miniapp_id,$keyword)->order($order)->paginate(20,false,['query'=>['types' => $types]]);
  81. $view['income'] = ModelBank::bank($this->member_miniapp_id,$keyword)->sum('income_money');
  82. $view['points'] = ModelBank::bank($this->member_miniapp_id,$keyword)->sum('shop_money');
  83. $view['money'] = ModelBank::bank($this->member_miniapp_id,$keyword)->sum('money');
  84. $view['keyword']= $keyword;
  85. $view['types'] = $types;
  86. return view()->assign($view);
  87. }
  88. /**
  89. * 客户收益记录
  90. * @return void
  91. */
  92. public function bill(int $uid){
  93. $this->path[] = ['name'=>'账单管理','url'=>'javascript:;'];
  94. $where['user_id'] = $uid;
  95. $view['list'] = BankBill::bill($where);
  96. $view['pathMaps'] = $this->path;
  97. return view()->assign($view);
  98. }
  99. /**
  100. * 客户提现
  101. */
  102. public function cash($types = 0){
  103. $keyword = trim(input('get.keyword','','htmlspecialchars'));
  104. $condition = [];
  105. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  106. if(!empty($keyword)){
  107. //$condition['system_user.phone_uid'] = $keyword;
  108. }
  109. switch ($types) {
  110. case 1:
  111. $state = -1;
  112. break;
  113. case 2:
  114. $state = 1;
  115. break;
  116. default:
  117. $state = 0;
  118. break;
  119. }
  120. $condition['state'] = $state;
  121. $view['list'] = BankCash::where($condition)->order('id desc')->paginate(20,false,['query' => ['types' => $types]]);
  122. $view['money'] = ModelBank::bank($this->member_miniapp_id,$keyword)->sum('money');
  123. $view['lack_money'] = ModelBank::bank($this->member_miniapp_id,$keyword)->sum('lack_money');
  124. $view['now_money'] = BankCash::where(['member_miniapp_id' =>$this->member_miniapp_id,'state' => 0])->sum('money');
  125. $view['realmoney'] = BankCash::where(['member_miniapp_id' =>$this->member_miniapp_id,'state' => 1])->sum('realmoney');
  126. $view['back_money'] = BankCash::where(['member_miniapp_id' =>$this->member_miniapp_id,'state' => -1])->sum('money');
  127. $view['keyword'] = $keyword;
  128. $view['types'] = $types;
  129. $view['pathMaps'] = [['name'=>' 提现管理','url' => url("bank/cash")]];
  130. return view()->assign($view);
  131. }
  132. /**
  133. * 客户审核
  134. */
  135. public function cashpass(int $id){
  136. if(request()->isAjax()){
  137. $data = [
  138. 'id' => input('post.id/d'),
  139. 'ispass' => input('post.ispass/d'),
  140. 'miniapp_id' => $this->member_miniapp_id,
  141. 'realmoney' => input('post.realmoney/f')
  142. ];
  143. $validate = $this->validate($data,'Bank.cash');
  144. if(true !== $validate){
  145. return json(['code'=>0,'msg'=>$validate]);
  146. }
  147. $result = ModelBank::isPass($data,$this->member_miniapp_id);
  148. return json($result);
  149. }else{
  150. $cash = BankCash::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id])->find();;
  151. if(empty($cash)){
  152. $this->error('未找到到申请提现内容');
  153. }
  154. $setting = model('AllwinConfig')->getConfig($this->member_miniapp_id);
  155. $is_manage = AllwinStore::manageStore($cash->user_id);
  156. if(empty($is_manage)){
  157. $realmoney = money($cash->money - $cash->money*($setting->cash_charges/1000));
  158. }else{
  159. $realmoney = $cash->money;
  160. }
  161. $view['cash'] = $cash;
  162. $view['realmoney'] = $realmoney;
  163. $view['bank'] = ModelBank::where(['user_id' => $cash->user_id])->find();
  164. $view['info'] = SystemUserBank::where(['user_id' => $cash->user_id])->find();
  165. $view['wechat'] = SystemUser::where(['id' => $cash->user_id])->field('id,miniapp_uid,phone_uid,official_uid')->find();
  166. $view['config'] = $setting ;
  167. return view()->assign($view);
  168. }
  169. }
  170. }