| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\Config;
- use app\common\model\MongyIn;
- use app\common\model\Order AS OrderModel;
- use app\common\model\User 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::getAgentInfoByAgentId($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::getAgentInfoByAgentId($user['agent_id']);
- if(empty($recharge_info)){
- $this->error(__('无充值信息'));
- }
- $insert_data = [
- 'order_type' => $recharge_type,
- 'user_id' => $user['id'],
- 'amount' => $amount,
- 'status' => 0,
- '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['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 MongyIn())->save($insert_data);
- Db::commit();
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- $this->success('', $insert_data);
- }
- /**
- * 订单列表
- * @return void
- * @throws \think\exception\DbException
- */
- public function list()
- {
- $user = $this->auth->getUser();
- $paginator = OrderModel::where('user_id', $user['id'])
- ->field('order_no,amount,bonus,status,create_time')
- ->order('id DESC')
- ->paginate($this->pageSize);
- foreach ($paginator as $k => $v) {
- $paginator[$k]['status_name'] = (new OrderModel())->getStatusNames($v['status']);
- }
- $res_data = $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items());
- $res_data['bonus_sum'] = $user['bonus_sum'];
- $this->success('', $res_data);
- }
- /**
- * 获取订单
- * @return void
- * @throws \think\exception\DbException
- */
- public function get()
- {
- $user = $this->auth->getUser();
- $data['order_no'] = 'sn45784545';
- $data['title'] = '商品标题111';
- $data['amount'] = 4545;
- $data['bonus'] = $user['bonus_sum'];
- $this->success('', $data);
- }
- }
|