Przeglądaj źródła

增加订单及会员接口

Jason 1 rok temu
rodzic
commit
88137431f1

+ 6 - 5
application/api/controller/Index.php

@@ -20,11 +20,12 @@ class Index extends Api
     {
         $user = $this->auth->getUser();
         $data = [];
-        $data['notice'] = '滚动显示的公告信息';
-        $data['banner_list'] = ['https://dapp-static.oss-cn-shenzhen.aliyuncs.com/jue-jin-lu/3.pnggS02ouwrJfiF65979ec74db73','https://dapp-static.oss-cn-shenzhen.aliyuncs.com/jue-jin-lu/intro.pngkSx1GTBiuFzY65979f0cd34e1'];
-        $data['balance'] = $user['balance'];
-        $data['bonus_sum'] = $user['bonus_sum'];
-        $data['icon_list'] = [
+        $data['notice']         = '滚动显示的公告信息';
+        $data['banner_list']    = ['https://dapp-static.oss-cn-shenzhen.aliyuncs.com/jue-jin-lu/3.pnggS02ouwrJfiF65979ec74db73','https://dapp-static.oss-cn-shenzhen.aliyuncs.com/jue-jin-lu/intro.pngkSx1GTBiuFzY65979f0cd34e1'];
+        $data['balance']        = $user['balance'];
+        $data['bonus_sum']      = $user['bonus_sum'];
+        $data['service_link']   = $user['service_link'];
+        $data['icon_list']      = [
             'https://www.estyzl38.com/static/img/binance.ebc27893.png',
             'https://www.estyzl38.com/static/img/ibank.11f8808d.png',
             'https://www.estyzl38.com/static/img/gate.ef718121.png',

+ 79 - 0
application/api/controller/Order.php

@@ -0,0 +1,79 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use app\common\model\Config;
+use app\common\model\Order AS OrderModel;
+
+/**
+ * 首页接口
+ */
+class Order extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 订单列表
+     * @return void
+     * @throws \think\exception\DbException
+     */
+    public function base()
+    {
+        $user = $this->auth->getUser();
+
+        $data['banner_list']    = 'https://dapp-static.oss-cn-shenzhen.aliyuncs.com/jue-jin-lu/3.pnggS02ouwrJfiF65979ec74db73';
+
+        $data['day_tasks_num']  = (new Config())->getValue('day_tasks_num');//每日任务数
+        $data['task_income']    = (new Config())->getValue('task_income');//单次任务收益
+
+        $data['task_num']       = $user['task_num'];//今日已做任务
+        $data['balance']        = $user['balance'];
+        $data['bonus_sum']      = $user['bonus_sum'];
+        $data['bonus_today']    = (new OrderModel())
+                                    ->where('user_id', $user['id'])
+                                    ->where('status', OrderModel::STATUSFINISH)
+                                    ->whereTime('create_time', '>=', strtotime('today'))
+                                    ->sum('bonus');
+
+        $this->success('', $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);
+    }
+}

+ 13 - 1
application/api/controller/User.php

@@ -5,6 +5,7 @@ namespace app\api\controller;
 use app\common\controller\Api;
 use app\common\library\Ems;
 use app\common\library\Sms;
+use app\common\model\Order as OrderModel;
 use fast\Random;
 use think\Config;
 use think\Validate;
@@ -31,7 +32,18 @@ class User extends Api
      */
     public function index()
     {
-        $this->success('', ['welcome' => $this->auth->nickname]);
+        $user = $this->auth->getUser();
+        $data['code']        = $user['code'];//今日已做任务
+        $data['mobile']      = $user['mobile'];
+        $data['balance']     = $user['balance'];
+        $data['avatar']      = $user['avatar'];
+        $data['bonus_sum']   = $user['bonus_sum'];
+        $data['order_num']   = (new OrderModel())
+                                ->where('user_id', $user['id'])
+                                ->where('status', OrderModel::STATUSFINISH)
+                                ->count();
+
+        $this->success('', $data);
     }
 
     /**

+ 2 - 98
application/api/lang/zh-cn.php

@@ -1,103 +1,7 @@
 <?php
 
 return [
-    'Keep login'                                     => '保持会话',
-    'Username'                                       => '用户名',
-    'User id'                                        => '会员ID',
-    'Nickname'                                       => '昵称',
-    'Password'                                       => '密码',
-    'Sign up'                                        => '注 册',
-    'Sign in'                                        => '登 录',
-    'Sign out'                                       => '退 出',
-    'Guest'                                          => '游客',
-    'Welcome'                                        => '%s,你好!',
-    'Add'                                            => '添加',
-    'Edit'                                           => '编辑',
-    'Delete'                                         => '删除',
-    'Move'                                           => '移动',
-    'Name'                                           => '名称',
-    'Status'                                         => '状态',
-    'Weigh'                                          => '权重',
-    'Operate'                                        => '操作',
-    'Warning'                                        => '温馨提示',
-    'Default'                                        => '默认',
-    'Article'                                        => '文章',
-    'Page'                                           => '单页',
-    'OK'                                             => '确定',
-    'Cancel'                                         => '取消',
-    'Loading'                                        => '加载中',
-    'More'                                           => '更多',
-    'Normal'                                         => '正常',
-    'Hidden'                                         => '隐藏',
-    'Submit'                                         => '提交',
-    'Reset'                                          => '重置',
-    'Execute'                                        => '执行',
-    'Close'                                          => '关闭',
-    'Search'                                         => '搜索',
-    'Refresh'                                        => '刷新',
-    'First'                                          => '首页',
-    'Previous'                                       => '上一页',
-    'Next'                                           => '下一页',
-    'Last'                                           => '末页',
-    'None'                                           => '无',
-    'Home'                                           => '主页',
-    'Online'                                         => '在线',
-    'Logout'                                         => '退出',
-    'Profile'                                        => '个人资料',
-    'Index'                                          => '首页',
-    'Hot'                                            => '热门',
-    'Recommend'                                      => '推荐',
-    'Dashboard'                                      => '控制台',
-    'Code'                                           => '编号',
-    'Message'                                        => '内容',
-    'Line'                                           => '行号',
-    'File'                                           => '文件',
-    'Menu'                                           => '菜单',
-    'Type'                                           => '类型',
-    'Title'                                          => '标题',
-    'Content'                                        => '内容',
-    'Append'                                         => '追加',
-    'Memo'                                           => '备注',
-    'Parent'                                         => '父级',
-    'Params'                                         => '参数',
-    'Permission'                                     => '权限',
-    'Advance search'                                 => '高级搜索',
-    'Check all'                                      => '选中全部',
-    'Expand all'                                     => '展开全部',
-    'Begin time'                                     => '开始时间',
-    'End time'                                       => '结束时间',
-    'Create time'                                    => '创建时间',
-    'Flag'                                           => '标志',
-    'Please login first'                             => '请登录后操作',
-    'Uploaded successful'                            => '上传成功',
-    'You can upload up to %d file%s'                 => '你最多还可以上传%d个文件',
-    'You can choose up to %d file%s'                 => '你最多还可以选择%d个文件',
-    'Chunk file write error'                         => '分片写入失败',
-    'Chunk file info error'                          => '分片文件错误',
-    'Chunk file merge error'                         => '分片合并错误',
-    'Chunk file disabled'                            => '未开启分片上传功能',
-    'Cancel upload'                                  => '取消上传',
-    'Upload canceled'                                => '上传已取消',
-    'No file upload or server upload limit exceeded' => '未上传文件或超出服务器上传限制',
-    'Uploaded file format is limited'                => '上传文件格式受限制',
-    'Uploaded file is not a valid image'             => '上传文件不是有效的图片文件',
-    'Are you sure you want to cancel this upload?'   => '确定取消上传?',
-    'Remove file'                                    => '移除文件',
-    'You can only upload a maximum of %s files'      => '你最多允许上传 %s 个文件',
-    'You can\'t upload files of this type'           => '不允许上传的文件类型',
-    'Server responded with %s code'                  => '服务端响应(Code:%s)',
-    'File is too big (%sMiB), Max filesize: %sMiB'   => '当前上传(%sM),最大允许上传文件大小:%sM',
-    'Redirect now'                                   => '立即跳转',
-    'Operation completed'                            => '操作成功!',
-    'Operation failed'                               => '操作失败!',
-    'Unknown data format'                            => '未知的数据格式!',
-    'Network error'                                  => '网络错误!',
-    'Advanced search'                                => '高级搜索',
-    'Invalid parameters'                             => '未知参数',
-    'No results were found'                          => '记录未找到',
-    'Parameter %s can not be empty'                  => '参数%s不能为空',
-    'You have no permission'                         => '你没有权限访问',
-    'An unexpected error occurred'                   => '发生了一个意外错误,程序猿正在紧急处理中',
-    'This page will be re-directed in %s seconds'    => '页面将在 %s 秒后自动跳转',
     '请求成功'                                         => '请求成功zh-cn',
+    '全部状态'                                         => '全部',
+    '未定义'                                           => '未定义',
 ];

+ 8 - 0
application/api/lang/zh-cn/order.php

@@ -0,0 +1,8 @@
+<?php
+
+return [
+    '待支付'                  => '待支付',
+    '完成'                    => '完成',
+    '冻结'                    => '冻结',
+    '取消'                    => '取消',
+];

+ 21 - 0
application/common/controller/Api.php

@@ -9,6 +9,7 @@ use think\exception\ValidateException;
 use think\Hook;
 use think\Lang;
 use think\Loader;
+use think\Paginator;
 use think\Request;
 use think\Response;
 use think\Route;
@@ -64,6 +65,12 @@ class Api
      */
     protected $responseType = 'json';
 
+    /**
+     * 每页条数
+     * @var int
+     */
+    protected $pageSize = 10;
+
     /**
      * 构造方法
      * @access public
@@ -327,4 +334,18 @@ class Api
         //刷新Token
         $this->request->token();
     }
+
+    /**
+     * 构造分页的相应
+     * @param Paginator $paginator
+     * @return array
+     */
+    protected function buildResp(int $total, int $currentPage, array $rows): array
+    {
+        return [
+            'total'        => $total,
+            'current_page' => $currentPage,
+            'rows'         => $rows,
+        ];
+    }
 }

+ 4 - 0
application/common/lang/zh-cn.php

@@ -0,0 +1,4 @@
+<?php
+
+return [
+];

+ 5 - 0
application/common/lang/zh-cn/order.php

@@ -0,0 +1,5 @@
+<?php
+
+return [
+    '待支付'                    => '待支付zh-cn',
+];

+ 15 - 0
application/common/model/Config.php

@@ -224,4 +224,19 @@ class Config extends Model
         return true;
     }
 
+    /**
+     * 读取配置项内容
+     * @param $name //键名
+     * @return mixed|null
+     */
+    public function getValue($name)
+    {
+        $parameter = $this->where('name', $name)->find();
+        if (is_null($parameter)) {
+            return null;
+        } else {
+            return $parameter['value'];
+        }
+
+    }
 }

+ 21 - 8
application/common/model/Order.php

@@ -7,11 +7,6 @@ use think\Model;
 
 class Order extends Model
 {
-
-    
-
-    
-
     // 表名
     protected $name = 'order';
     
@@ -36,6 +31,26 @@ class Order extends Model
     const STATUSFREEZE = 2;
     const STATUSCANCEL = 3;
 
+    /*
+     * 订单状态
+     * 0未支付 1完成 2冻结 3取消
+     */
+    public function getStatusNames($type = -1){
+        $status_names = [
+            '-1'                    => __('全部状态'),
+            self::STATUSUNPAID      => __('待支付'),
+            self::STATUSFINISH      => __('完成'),
+            self::STATUSFREEZE      => __('冻结'),
+            self::STATUSCANCEL      => __('取消'),
+        ];
+        if($type == -1){
+            return $status_names;
+        }
+        if(isset($status_names[$type])){
+            return $status_names[$type];
+        }
+        return __('未定义');
+    }
 
     //users
     public function users()
@@ -46,7 +61,7 @@ class Order extends Model
     //操作列表
     public function getstatusList()
     {
-        return [1 => __('Finish'), 2 => __('Freeze'), 3 => __('Cancel')];
+        return [self::STATUSFINISH => __('Finish'), 2 => __('Freeze'), 3 => __('Cancel')];
     }
 
 
@@ -72,6 +87,4 @@ class Order extends Model
     {
         return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
     }
-
-
 }