Bank.php 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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\system\controller\passport;
  9. use app\common\model\SystemApis;
  10. use app\common\model\SystemMemberMiniapp;
  11. use app\common\model\SystemMemberBank;
  12. use app\common\model\SystemMemberBankBill;
  13. use app\common\model\SystemMemberBankRecharge;
  14. use app\common\facade\WechatPay;
  15. class Bank extends Common{
  16. public function initialize() {
  17. parent::initialize();
  18. if($this->user->parent_id){
  19. $this->error('无权限访问,只有创始人身份才允许使用。');
  20. }
  21. }
  22. /**
  23. * 我的应用
  24. * @access public
  25. */
  26. public function index(){
  27. $view['list'] = SystemMemberMiniapp::where(['member_id' => $this->user->id])->order('create_time desc')->paginate(10,false);
  28. $view['pathMaps'] = [['name'=>'财务管理','url'=>'javascript:;'],['name'=>'我的应用','url'=>'javascript:;']];
  29. return view()->assign($view);
  30. }
  31. /**
  32. * @return \think\response\View
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. * @throws \think\exception\DbException
  36. * 我的帐单
  37. */
  38. public function bill(){
  39. $view['bank'] = SystemMemberBank::where(['member_id' => $this->user->id])->find();
  40. $view['consume'] = SystemMemberBankBill::where(['member_id' => $this->user->id,'state' => 1])->sum('money');
  41. $view['list'] = SystemMemberBankBill::where(['member_id' => $this->user->id])->order('update_time desc')->paginate(20,false);
  42. $view['pathMaps'] = [['name'=>'财务管理','url'=>'javascript:;'],['name'=>'我的帐单','url'=>'javascript:;']];
  43. return view()->assign($view);
  44. }
  45. /**
  46. * 账户充值
  47. * @return \think\response\View
  48. */
  49. public function pay(){
  50. if(request()->isAjax()) {
  51. $param = [
  52. 'payType' => $this->request->param('payType/d',0),
  53. 'money' => $this->request->param('money/d',10),
  54. 'order_sn' => order_no(),
  55. ];
  56. $validate = $this->validate($param,'MemberBank.recharge');
  57. if(true !== $validate){
  58. return json(['code'=>0,'msg'=>$validate]);
  59. }
  60. $rel = SystemMemberBankRecharge::order(['money' => $param['money'],'member_id' => $this->user->id,'order_sn' => $param['order_sn']]);
  61. if ($rel) {
  62. switch ($param['payType']) {
  63. case 1:
  64. # 支付宝
  65. break;
  66. default:
  67. $config = SystemApis::Config('wepay');
  68. $order = [
  69. 'trade_type' => 'NATIVE',
  70. 'body' => '充值',
  71. 'out_trade_no' => $param['order_sn'],
  72. 'total_fee' => $param['money'] * 100,//分
  73. 'mch_id' => $config['mch_id'],
  74. 'appid' => $config['app_id'],
  75. 'notify_url' => url('system/event.rechargeNotify/wechat',[],'html',true)
  76. ];
  77. $result = WechatPay::doPay()->order->unify($order);
  78. if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
  79. return enjson(200,'操作成功',$result);
  80. }
  81. return enjson(0,$result['return_msg']);
  82. break;
  83. }
  84. }
  85. return enjson(0);
  86. }else{
  87. $view['pathMaps'] = [['name'=>'财务管理','url'=>'javascript:;'],['name'=>'账户充值','url'=>'javascript:;']];
  88. return view()->assign($view);
  89. }
  90. }
  91. }