| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\MoneyIn;
- use app\common\model\MoneyOut;
- use app\common\model\Users AS UserModel;
- use think\Db;
- use think\Exception;
- /**
- * 首页接口
- */
- class Money extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- /**
- * 充值信息
- * @return void
- * @throws \think\exception\DbException
- */
- public function recharge()
- {
- $user = $this->auth->getUser();
- $data['amount_list'] = [100,200,500,1000,5000,10000];//快捷输入额度
- $data['usdt'] = $data['bank'] = 1;
- $recharge_info = UserModel::getAgentRechargeInfoByAgentId($user['agent_id']);
- if(empty($recharge_info)){
- $this->error(__('无充值信息'));
- }
- if(empty($recharge_info['usdt'])){
- $data['usdt'] = 0;
- }
- if(empty($recharge_info['bank'])){
- $data['bank'] = 0;
- }
- $this->success('', $data);
- }
- /**
- * 创建充值订单
- * @return void
- */
- public function recharge_create()
- {
- $recharge_type = $this->request->post('type');
- $amount = $this->request->post('amount');
- if(!in_array($recharge_type, [1,2])){
- $this->error(__('参数有误'));
- }
- if(!($amount > 0)){
- $this->error(__('参数有误'));
- }
- $user = $this->auth->getUser();
- $recharge_info = UserModel::getAgentRechargeInfoByAgentId($user['agent_id']);
- if(empty($recharge_info)){
- $this->error(__('无充值信息'));
- }
- $insert_data = [
- 'order_type' => $recharge_type,
- 'user_id' => $user['id'],
- 'amount' => $amount,
- 'status' => MoneyIn::Default,
- 'user_type' => $user['user_type'],
- 'agent_id' => $recharge_info['agent_id']
- ];
- //USDT充值
- if($recharge_type == 1){
- if(empty($recharge_info['usdt'])){
- $this->error(__('参数有误'));
- }
- $insert_data['order_no'] = 'U' . time() . $user['id'];
- $insert_data['usdt_address'] = $recharge_info['usdt'];
- }else{
- if(empty($recharge_info['bank'])){
- $this->error(__('参数有误'));
- }
- $insert_data['order_no'] = 'B' . time() . $user['id'];
- $insert_data['bank_name'] = $recharge_info['bank']['bank_name'];
- $insert_data['bank_card'] = $recharge_info['bank']['bank_card'];
- $insert_data['account_name']= $recharge_info['bank']['account_name'];
- }
- //写入
- Db::startTrans();
- try {
- (new MoneyIn())->save($insert_data);
- Db::commit();
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- $this->success('', $insert_data);
- }
- /**
- * 上传图片
- * @return void
- * @throws \think\exception\DbException
- */
- public function recharge_upload()
- {
- $user = $this->auth->getUser();
- $order_no = $this->request->post('order_no');
- if (empty($order_no)) {
- $this->error(__('参数有误'));
- }
- $order_info = (new MoneyIn())
- ->where('user_id', $user['id'])
- ->where('order_no', $order_no)
- ->find();
- if (empty($order_no)) {
- $this->error(__('参数有误'));
- }
- $file_info = ali_oss_upload($this->request, 'recharge', $order_no);
- if($file_info['code'] == 0){
- $this->error($file_info['msg']);
- }
- $this->success('', $file_info['data']);
- }
- /**
- * 提交充值信息
- * @return void
- * @throws \think\exception\DbException
- */
- public function recharge_submit()
- {
- $user = $this->auth->getUser();
- $order_no = $this->request->post('order_no');
- if (empty($order_no)) {
- $this->error(__('参数有误'));
- }
- $order_info = (new MoneyIn())
- ->where('user_id', $user['id'])
- ->where('order_no', $order_no)
- ->find();
- if (empty($order_info)) {
- $this->error(__('参数有误'));
- }
- //上传图片
- $file_info = ali_oss_upload($this->request, 'recharge', $order_no);
- if($file_info['code'] == 0){
- $this->error($file_info['msg']);
- }
- $img_url = $file_info['data']['full_url'];
- if ($order_info['status'] != MoneyIn::Default) {
- if (empty($order_info['img_url'])) {
- (new MoneyIn())
- ->where('order_no', $order_no)
- ->update([
- 'img_url' => $img_url
- ]);
- }
- $this->success(__('提交成功'));
- }
- (new MoneyIn())
- ->where('order_no', $order_no)
- ->update([
- 'img_url' => $img_url,
- 'status' => MoneyIn::Pending,
- ]);
- $this->success(__('提交成功'));
- }
- /**
- * 提现
- * @return void
- */
- public function withdraw()
- {
- $user = $this->auth->getUser();
- $data['balance'] = $user['balance'];
- $data['money_out_sum'] = MoneyOut::where('user_id', $user['id'])->where('status', MoneyOut::Success)->sum('amount');
- $withdraw_info = UserModel::getAgentWithdrawInfoByAgentId($user['agent_id']);
- if(empty($withdraw_info)){
- $this->error(__('无提现信息'));
- }
- $data = array_merge($data, $withdraw_info);
- $this->success('', $data);
- }
- /**
- * 提交提现信息
- * @return void
- * @throws \think\exception\DbException
- */
- public function withdraw_submit()
- {
- $type = $this->request->post('type');
- $amount = $this->request->post('amount');
- if(!in_array($type, [1,2])){
- $this->error(__('参数有误'));
- }
- if(!($amount > 0)){
- $this->error(__('参数有误'));
- }
- $user = $this->auth->getUser();
- if($amount > $user['balance']){
- $this->error(__('余额不足'));
- }
- $withdraw_info = UserModel::getAgentWithdrawInfoByAgentId($user['agent_id']);
- if(empty($withdraw_info)){
- $this->error(__('无提现信息'));
- }
- $insert_data = [
- 'order_type' => $type,
- 'user_id' => $user['id'],
- 'amount' => $amount,
- 'status' => MoneyOut::Default,
- 'agent_id' => $withdraw_info['agent_id'],
- 'user_type' => $user['user_type'],
- ];
- //USDT充值
- if($type == 1){
- if(empty($withdraw_info['usdt'])){
- $this->error(__('参数有误'));
- }
- $usdt_address = $this->request->post('usdt');
- if(empty($usdt_address)){
- $this->error(__('参数有误'));
- }
- $insert_data['order_no'] = 'U' . time() . $user['id'];
- $insert_data['usdt_address'] = $usdt_address;
- }else{
- if(empty($withdraw_info['bank'])){
- $this->error(__('参数有误'));
- }
- $insert_data['bank_name'] = $this->request->post('bank_name');
- $insert_data['bank_card'] = $this->request->post('bank_card');
- $insert_data['account_name']= $this->request->post('account_name');
- if(empty($insert_data['bank_name']) || empty($insert_data['bank_card']) || empty($insert_data['account_name'])){
- $this->error(__('参数有误'));
- }
- $insert_data['order_no'] = 'B' . time() . $user['id'];
- }
- $fund_pwd = $this->request->post('fund_pwd');
- if(empty($fund_pwd)){
- $this->error(__('参数有误'));
- }
- if($user['fund_pwd'] != md5($fund_pwd)){
- $this->error(__('资金密码有误'));
- }
- //写入
- Db::startTrans();
- try {
- (new MoneyOut())->save($insert_data);
- Db::commit();
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- $this->success('');
- }
- /**
- * 充值提现列表
- * @return void
- * @throws \think\exception\DbException
- */
- public function money_list()
- {
- $type = $this->request->post('type');
- if(empty($type)){
- $type = 1;
- }
- if(!in_array($type, [1,2])){
- $this->error(__('参数有误'));
- }
- $user = $this->auth->getUser();
- $res_data = [];
- if($type == 1){
- //充值列表
- $info_list = MoneyIn::where('user_id', $user['id'])
- ->field('order_no,order_type,usdt_address,bank_name,bank_card,account_name,amount,status,create_time')
- ->order('id DESC')
- ->paginate($this->pageSize);
- foreach ($info_list as $k => $v) {
- $info_list[$k]['status_name'] = (new MoneyIn())->getStatusNames($v['status']);
- }
- $res_data = $this->buildResp($info_list->total(), $info_list->currentPage(), $info_list->items());
- }else{
- //提现列表
- $info_list = MoneyOut::where('user_id', $user['id'])
- ->field('order_no,order_type,amount,status,create_time')
- ->order('id DESC')
- ->paginate($this->pageSize);
- foreach ($info_list as $k => $v) {
- $info_list[$k]['status_name'] = (new MoneyOut())->getStatusNames($v['status']);
- }
- $res_data = $this->buildResp($info_list->total(), $info_list->currentPage(), $info_list->items());
- }
- $res_data['money_in_sum'] = MoneyIn::where('user_id', $user['id'])->where('status', MoneyIn::Success)->sum('amount');
- $res_data['money_out_sum'] = MoneyOut::where('user_id', $user['id'])->where('status', MoneyOut::Success)->sum('amount');
- $this->success('', $res_data);
- }
- }
|