|
|
@@ -0,0 +1,140 @@
|
|
|
+<?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);
|
|
|
+ }
|
|
|
+}
|