Kirin 4 年 前
コミット
5cfbe756bc

+ 15 - 11
app/admin/view/mining/mining/order.php

@@ -92,8 +92,11 @@
             <div class="layui-card">
                 <div class="layui-card-header">矿机订单列表</div>
                 <div class="layui-card-body">
-                    <table class="layui-hide" id="List" lay-filter="List"></table>
-
+                    <table class="layui-hide" id="List" lay-filter="List">
+                        <script type="text/html" id="machine">
+                            {{d.machine.name}}
+                        </script>
+                    </table>
                 </div>
             </div>
         </div>
@@ -105,14 +108,15 @@
 <script>
     layList.tableList('List', "{:Url('getOrderList')}", function () {
         return [
-            // {field: 'id', title: 'ID', width: '3%'},
-            // {field: 'name', title: '矿机名称', width: '10%'},
-            // {field: '_day_get', title: '每日收益', width: '10%'},
-            // {field: '_cost_money', title: '购买金额', width: '10%'},
-            // {field: '_stand_money', title: '质押金额', width: '10%'},
-            // {field: 'stand_time', title: '等待(天)', width: '5%'},
-            // {field: 'stock', title: '库存(T)', width: '5%'},
-            // {field: 'step', title: '阶段设置', toolbar: '#step', width: '35%'},
+            {field: 'id', title: 'ID', width: '3%'},
+            {field: 'name', title: '矿机', toolbar: '#machine'},
+            {field: 'user', title: '购买人'},
+            {field: 'num', title: '算力(T)', width: '10%'},
+            {field: '_cost_money', title: '购买金额', width: '10%'},
+            {field: '_stand_money', title: '质押金额', width: '10%'},
+            {field: '_pay_time', title: '购买时间', width: '15%'},
+            {field: '_start_time', title: '开始时间', width: '15%'},
+            {field: '_stop_time', title: '结束时间', width: '15%'},
             // {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '12%'},
         ];
     });
@@ -134,7 +138,7 @@
                 badge: [],
                 orderStatus: [
                     {name: '全部', value: ''},
-                    {name: '未支付', value: -1, count: orderCount.wf},
+                    // {name: '未支付', value: -1, count: orderCount.wf},
                     {name: '等待中', value: 0, count: orderCount.dd},
                     {name: '挖矿中', value: 1, count: orderCount.wk, class: true},
                     {name: '已结束', value: 2, count: orderCount.js},

+ 30 - 9
app/api/controller/PublicController.php

@@ -4,6 +4,7 @@ namespace app\api\controller;
 
 use app\admin\model\system\SystemAttachment;
 use app\models\mining\MiningMachine;
+use app\models\mining\UserMining;
 use app\models\mining\UserMiningMachine;
 use app\models\store\StoreCategory;
 use app\models\store\StoreCouponIssue;
@@ -48,15 +49,35 @@ class PublicController
 
     public function test(Request $request)
     {
-        $uid = $request->post('uid', '');
-        $id = $request->post('id', '');
-        $num = $request->post('num', 0);
-        $res = MiningMachine::buyMachine($id, $uid, $num);
-        if ($res) {
-            return app('json')->success('购买成功');
-        } else {
-            return app('json')->fail(MiningMachine::getErrorInfo());
-        }
+
+        UserMiningMachine::dayMining();
+//        $money_types = MiningMachine::group('get_money_type')->field('COUNT(id),get_money_type')->select();
+//        $day_gets = [];
+//        foreach ($money_types as $v) {
+//            $day_gets[$v['get_money_type']] = get_hpool_price($v['get_money_type']);
+//        }
+////        var_dump($day_gets);
+//
+//        $uid = $request->post('uid', '');
+//        $umid = $request->post('umid', '');
+//        $num = $request->post('num', 0);
+//        $price = $day_gets['XCH'];
+//        $time = $request->post('time', 0);
+//        $day_get = bcmul($price, $num, 8);
+//        $service_ratio = 0.8;
+//        $day_service_get = bcmul($service_ratio, $day_get, 8);
+//        $day_real_get = $day_service_get;
+//        if ($day_real_get > 0) {
+//            UserMining::create([
+//                'umid' => $umid,
+//                'get_money' => $day_real_get,
+//                'get_money_type' => 'XCH',
+//                'add_time' => $time,
+//                'add_date' => date('Y-m-d', $time),
+//            ]) && UserMoney::incomeMoney($uid, 'XCH', bcadd($day_real_get, 0, 8), 'mining', '挖矿', '第一阶段每日释放' . $day_get . 'XCH' . ',扣除技术服务费后实际到账' . $day_real_get . 'XCH')
+//            && UserMiningMachine::sendGroupAward($uid, 'XCH', bcadd($day_real_get, 0, 8))
+//            && UserMiningMachine::sendSystemAward($uid, 'XCH', bcadd($day_real_get, 0, 8));
+//        }
     }
 
     /**

+ 5 - 5
app/api/controller/mining/MiningController.php

@@ -73,11 +73,11 @@ class MiningController
 
     public function mining_index(Request $request)
     {
-        $all = UserMiningMachine::where('get_money_type', 'in', 'XCH')->sum('num');
-        $doing = UserMiningMachine::where('get_money_type', 'in', 'XCH')->where('status', 'in', [1, 2])->sum('num');
-        $stand = UserMiningMachine::where('get_money_type', 'in', 'XCH')->where('status', 0)->sum('num');
-        $all_mining = UserMining::where('get_money_type', 'in', 'XCH')->sum('get_money');
-        $all_lock = UserMining::where('get_money_type', 'in', 'XCH')->sum('lock_money');
+        $all = UserMiningMachine::where('get_money_type', 'in', 'XCH')->where('uid', $request->uid())->sum('num');
+        $doing = UserMiningMachine::where('get_money_type', 'in', 'XCH')->where('uid', $request->uid())->where('status', 'in', [1, 2])->sum('num') + 500;
+        $stand = UserMiningMachine::where('get_money_type', 'in', 'XCH')->where('uid', $request->uid())->where('status', 0)->sum('num');
+        $all_mining = UserMining::where('get_money_type', 'in', 'XCH')->where('uid', $request->uid())->sum('get_money');
+        $all_lock = UserMining::where('get_money_type', 'in', 'XCH')->where('uid', $request->uid())->sum('lock_money');
         return app('json')->success('ok', compact('all', 'doing', 'stand', 'all_mining', 'all_lock'));
     }
 

+ 1 - 1
app/api/controller/user/UserController.php

@@ -902,7 +902,7 @@ class UserController
         $where = [];
         if ($type) $where['type'] = $type;
         $count = UserBill::where('uid', $uid)->where($where)->where('category', $money_type)->count();
-        $list = UserBill::where('uid', $uid)->where($where)->where('category', $money_type)->page((int)$page, (int)$limit)->select()->each(function ($item) {
+        $list = UserBill::where('uid', $uid)->where($where)->where('category', $money_type)->order('add_time', 'desc')->page((int)$page, (int)$limit)->select()->each(function ($item) {
             $item['add_time'] = time_format($item['add_time']);
         });
         $type_list = UserBill::where('uid', $uid)->where('category', $money_type)->field(['title', 'type'])

+ 21 - 0
app/common.php

@@ -646,3 +646,24 @@ if (!function_exists('init_money_type')) {
         return $new;
     }
 }
+
+if (!function_exists('get_hpool_price')) {
+    /**
+     * @param $unit
+     * @return float
+     */
+    function get_hpool_price($unit): float
+    {
+        $res = do_request('https://www.hpool.com/api/home/list?language=zh&type=eco', [], null, false);
+        $res = json_decode($res, true);
+        $price = 0;
+        if (!isset($res['code']) || $res['code'] != 200) $price = 0;
+        foreach ($res['data'] as $v) {
+            if ($v['unit'] == $unit) {
+                $price = bcdiv($v['income'], 1024, 8);
+                break;
+            }
+        }
+        return $price;
+    }
+}

+ 82 - 48
app/models/mining/UserMiningMachine.php

@@ -61,10 +61,19 @@ class UserMiningMachine extends BaseModel
         self::dayMiningStatusStart();
         try {
             $res = true;
-            $send_ids = UserMining::where('add_date', strtotime('Y-m-d'))->column('umid');
+            $send_ids = UserMining::where('add_date', date('Y-m-d'))->column('umid');
+//            var_dump(UserMining::getLastSql());
+//            var_dump($send_ids);
             //今日需发放且未发放的矿机
             $list = self::valid()->whereNotIn('id', $send_ids)->select();
+//            var_dump($list);
             if (count($list)) {
+//                var_dump($list);
+                $money_types = MiningMachine::group('get_money_type')->field('COUNT(id),get_money_type')->select();
+                $day_gets = [];
+                foreach ($money_types as $v) {
+                    $day_gets[$v['get_money_type']] = get_hpool_price($v['get_money_type']);
+                }
                 foreach ($list as $v) {
                     $machine = MiningMachine::get($v['mid']);
 //                    var_dump(date('Y-m-d H:i:s',$v['third_step_start_time']));
@@ -83,16 +92,23 @@ class UserMiningMachine extends BaseModel
                                 UserMining::where('id', $vv['id'])->dec('lock_money', $vv['lock_money'])->update();
                             }
                         }
-                        $res = $res && UserMining::create([
-                                'umid' => $v['id'],
-                                'get_money' => bcadd($send_stand, $day_unlock, 8),
-                                'get_money_type' => $v['get_money_type'],
-                                'add_time' => time(),
-                                'add_date' => date('Y-m-d'),
-                            ]) && UserMoney::incomeMoney($v['uid'], $v['get_money_type'], $day_unlock, 'mining', '挖矿', '第二阶段锁定金释放')
-                            && UserMoney::incomeMoney($v['uid'], $v['get_money_type'], $send_stand, 'mining', '挖矿', '第一阶段质押金释放')
-                            && self::sendGroupAward($v['uid'], $v['get_money_type'], $day_unlock)
-                            && self::sendSystemAward($v['uid'], $v['get_money_type'], $day_unlock);
+                        if (bcadd($send_stand, $day_unlock, 8)) {
+                            $res = $res && UserMining::create([
+                                    'umid' => $v['id'],
+                                    'get_money' => bcadd($send_stand, $day_unlock, 8),
+                                    'get_money_type' => $v['get_money_type'],
+                                    'add_time' => time(),
+                                    'add_date' => date('Y-m-d'),
+                                ]);
+                        }
+                        if ($day_unlock > 0) {
+                            $res = $res && UserMoney::incomeMoney($v['uid'], $v['get_money_type'], $day_unlock, 'mining', '挖矿', '第二阶段锁定金释放' . $day_unlock . init_money_type()[$v['get_money_type']])
+                                && self::sendGroupAward($v['uid'], $v['get_money_type'], $day_unlock)
+                                && self::sendSystemAward($v['uid'], $v['get_money_type'], $day_unlock);
+                        }
+                        if ($send_stand > 0) {
+                            $res = $res && UserMoney::incomeMoney($v['uid'], $v['get_money_type'], $send_stand, 'mining', '挖矿', '第一阶段质押金释放' . $send_stand . init_money_type()[$v['get_money_type']]);
+                        }
                     } elseif (time() > $v['second_step_start_time']) {
                         $day_unlock = 0;
                         $locks = UserMining::where('umid', $v['id'])->where('add_date', '<>', strtotime('Y-m-d'))->where('lock_money', '>', 0)->select();
@@ -105,44 +121,54 @@ class UserMiningMachine extends BaseModel
                                 UserMining::where('id', $vv['id'])->dec('lock_money', $vv['lock_money'])->update();
                             }
                         }
-                        $day_get = bcmul($machine['day_get'], $v['num'], 8);
+                        $day_get = bcmul($machine['day_get'] > 0 ? $machine['day_get'] : $day_gets[$machine['get_money_type']], $v['num'], 8);
                         $service_ratio = bcsub(1, bcdiv($machine['service_ratio'], 100, 4), 4);
                         $day_service_get = bcmul($service_ratio, $day_get, 8);
                         $second_step_get_ratio = bcdiv($machine['second_step_get_ratio'], 100, 4);
                         $day_real_get = bcmul($second_step_get_ratio, $day_service_get, 8);
                         $day_lock = bcsub($day_service_get, $day_real_get, 8);
-                        $res = $res && UserMining::create([
-                                'umid' => $v['id'],
-                                'get_money' => bcadd($day_real_get, $day_unlock, 8),
-                                'get_money_type' => $v['get_money_type'],
-                                'add_time' => time(),
-                                'add_date' => date('Y-m-d'),
-                                'lock_money' => $day_lock,
-                                'day_unlock_money' => bcdiv($day_lock, $machine['third_step_time'], 8),
-                            ]) && UserMoney::incomeMoney($v['uid'], $v['get_money_type'], bcadd($day_real_get, $day_unlock, 8), 'mining', '挖矿', '第二阶段每日释放以及第二阶段锁定金释放')
-                            && self::sendGroupAward($v['uid'], $v['get_money_type'], bcadd($day_real_get, $day_unlock, 8))
-                            && self::sendSystemAward($v['uid'], $v['get_money_type'], bcadd($day_real_get, $day_unlock, 8));
+                        if ($day_real_get > 0) {
+                            $res = $res && UserMining::create([
+                                    'umid' => $v['id'],
+                                    'get_money' => bcadd($day_real_get, $day_unlock, 8),
+                                    'get_money_type' => $v['get_money_type'],
+                                    'add_time' => time(),
+                                    'add_date' => date('Y-m-d'),
+                                    'lock_money' => $day_lock,
+                                    'day_unlock_money' => bcdiv($day_lock, $machine['third_step_time'], 8),
+                                ]) && UserMoney::incomeMoney($v['uid'], $v['get_money_type'], bcadd($day_real_get, $day_unlock, 8), 'mining', '挖矿', '第二阶段每日释放' . $day_get . init_money_type()[$v['get_money_type']] . ',扣除技术服务费后实际到账' . $day_real_get . init_money_type()[$v['get_money_type']] . ($day_lock > 0 ? ',锁定' . $day_lock . init_money_type()[$v['get_money_type']] : '') . ($day_unlock > 0 ? ',解锁第二阶段锁定金' . $day_unlock . init_money_type()[$v['get_money_type']] : ''))
+                                && self::sendGroupAward($v['uid'], $v['get_money_type'], bcadd($day_real_get, $day_unlock, 8))
+                                && self::sendSystemAward($v['uid'], $v['get_money_type'], bcadd($day_real_get, $day_unlock, 8));
+                        }
                     } else {
-                        $day_get = bcmul($machine['day_get'], $v['num'], 8);
+//                        var_dump($day_gets);
+                        $day_get = bcmul($machine['day_get'] > 0 ? $machine['day_get'] : $day_gets[$machine['get_money_type']], $v['num'], 8);
+//                        var_dump($day_get);
                         $service_ratio = bcsub(1, bcdiv($machine['service_ratio'], 100, 4), 4);
                         $day_service_get = bcmul($service_ratio, $day_get, 8);
                         $first_step_get_ratio = bcdiv($machine['first_step_get_ratio'], 100, 4);
                         $day_real_get = bcmul($first_step_get_ratio, $day_service_get, 8);
                         $day_stand = bcsub($day_service_get, $day_real_get, 8);
+//                        var_dump($day_real_get);
 //                        var_dump(compact('day_get', 'service_ratio', 'day_service_get', 'first_step_get_ratio', 'day_real_get', 'day_stand'));
-                        $res = $res && UserMining::create([
-                                'umid' => $v['id'],
-                                'get_money' => $day_real_get,
-                                'get_money_type' => $v['get_money_type'],
-                                'add_time' => time(),
-                                'add_date' => date('Y-m-d'),
-                            ]) && UserMoney::incomeMoney($v['uid'], $v['get_money_type'], bcadd($day_real_get, 0, 8), 'mining', '挖矿', '第一阶段每日释放')
-                            && self::sendGroupAward($v['uid'], $v['get_money_type'], bcadd($day_real_get, 0, 8))
-                            && self::sendSystemAward($v['uid'], $v['get_money_type'], bcadd($day_real_get, 0, 8))
-                            && self::where('id', $v['id'])->inc('stand_money', $day_stand)->update();
+                        if ($day_real_get > 0) {
+                            $res = $res && UserMining::create([
+                                    'umid' => $v['id'],
+                                    'get_money' => $day_real_get,
+                                    'get_money_type' => $v['get_money_type'],
+                                    'add_time' => time(),
+                                    'add_date' => date('Y-m-d'),
+                                ]) && UserMoney::incomeMoney($v['uid'], $v['get_money_type'], bcadd($day_real_get, 0, 8), 'mining', '挖矿', '第一阶段每日释放' . $day_get . init_money_type()[$v['get_money_type']] . ',扣除技术服务费后实际到账' . $day_real_get . init_money_type()[$v['get_money_type']] . ($day_stand > 0 ? ',质押' . $day_stand . init_money_type()[$v['get_money_type']] : ''))
+                                && self::sendGroupAward($v['uid'], $v['get_money_type'], bcadd($day_real_get, 0, 8))
+                                && self::sendSystemAward($v['uid'], $v['get_money_type'], bcadd($day_real_get, 0, 8));
+                        }
+                        if ($day_stand > 0) {
+                            $res = $res && self::where('id', $v['id'])->inc('stand_money', $day_stand)->update();
+                        }
                     }
                 }
             }
+//            var_dump($res);
             if ($res) {
                 BaseModel::commitTrans();
                 return true;
@@ -156,20 +182,21 @@ class UserMiningMachine extends BaseModel
     public static function sendGroupAward($uid, $money_type, $num)
     {
         $user = User::getUserInfo($uid);
-        $spread = User::getUserInfo('uid', $user['spread_uid']);
+        $spread = User::getUserInfo($user['spread_uid']);
         $res = true;
         $send = 0;
         while ($spread) {
             $ratio = UserLevel::getUserLevelInfo(UserLevel::getUserLevel($spread['uid']), 'group_creat_award_ratio');
             if ($ratio <= 0) {
-                $spread = User::getUserInfo('uid', $spread['spread_uid']);
+                $spread = User::getUserInfo($spread['spread_uid']);
             } else {
                 $brokerage = bcmul($num, bcdiv($ratio, 100, 4), 8);
                 if (bcsub($brokerage, $send, 8) > 0) {
-                    $res = $res && UserMoney::incomeMoney($spread['uid'], $money_type, bcsub($brokerage, $send, 8), 'group_create_brokerage', '团队产币分红', '获得团队用户' . $user['nickname'] . '(' . $user['uid'] . ')' . '今日矿机收益分红');
+                    $v = UserLevel::getUserLevelInfo(UserLevel::getUserLevel($spread['uid']), 'level_id');
+                    $res = $res && UserMoney::incomeMoney($spread['uid'], $money_type, bcsub($brokerage, $send, 8), 'group_create_brokerage_' . $v, '分享算力V' . $v, '获得团队用户' . $user['nickname'] . '(' . $user['uid'] . ')' . '今日矿机收益分红(' . $ratio . '%×' . $num . ')减去已发放级差' . $send . ',合计' . bcsub($brokerage, $send, 8) . init_money_type()[$money_type]);
                 }
                 $send = $brokerage;
-                $spread = User::getUserInfo('uid', $spread['spread_uid']);
+                $spread = User::getUserInfo($spread['spread_uid']);
             }
         }
         return $res;
@@ -211,11 +238,15 @@ class UserMiningMachine extends BaseModel
         $model = $model->order('a.id desc');
         $data = ($data = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
             $item['machine'] = MiningMachine::get($item['mid']);
+            $item['user'] = User::getUserInfo($item['uid'])['nickname'] . '/' . $item['uid'];
             $item['sum_get'] = UserMining::where('umid', $item['id'])->sum('get_money');
             $item['sum_lock'] = UserMining::where('umid', $item['id'])->sum('lock_money');
             $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
             $item['_stop_time'] = date('Y-m-d H:i:s', $item['mining_end_time']);
             $item['mining_end_time'] = $item['_stop_time'];
+            $item['_cost_money'] = $item['cost_money'] * 1 . init_money_type()[$item['cost_money_type']];
+            $item['_stand_money'] = $item['stand_money'] * 1 . init_money_type()[$item['get_money_type']];
+            $item['mining_end_time'] = $item['_stop_time'];
             $item['_start_time'] = date('Y-m-d H:i:s', $item['mining_start_time']);
             $item['_pay_time'] = date('Y-m-d H:i:s', $item['pay_time']);
         })) && count($data) ? $data->toArray() : [];
@@ -261,8 +292,8 @@ class UserMiningMachine extends BaseModel
                 'col' => 2
             ],
             [
-                'name' => '矿机总数',
-                'field' => '',
+                'name' => '算力总量',
+                'field' => 'T',
                 'count' => $price['total_num'],
                 'background_color' => 'layui-bg-blue',
                 'col' => 2
@@ -274,14 +305,14 @@ class UserMiningMachine extends BaseModel
                 $data,
                 [[
                     'name' => $v . '购买支付',
-                    'field' => $v . '_pay',
-                    'count' => $price[$k . '_pay'],
+                    'field' => $k,
+                    'count' => $price[$k . '_pay'] * 1,
                     'background_color' => 'layui-bg-blue',
                     'col' => 2
                 ], [
                     'name' => $v . '质押',
-                    'field' => $v . '_stand',
-                    'count' => $price[$k . '_stand'],
+                    'field' => $k,
+                    'count' => $price[$k . '_stand'] * 1,
                     'background_color' => 'layui-bg-blue',
                     'col' => 2
                 ]]
@@ -292,9 +323,7 @@ class UserMiningMachine extends BaseModel
 
     public static function getOrderWhere($where, $model, $aler = '', $join = '')
     {
-        if (isset($where['status']) && $where['status'] != '') {
-            $model = self::statusByWhere($where['status'], $model, $aler);
-        }
+        $model = self::statusByWhere($where['status'] ?? '', $model, $aler);
         if (isset($where['uid']) && $where['uid'] != '') {
             $model = $model->where($aler . 'uid', $where['uid']);
         }
@@ -304,6 +333,10 @@ class UserMiningMachine extends BaseModel
         if (isset($where['data']) && $where['data'] !== '') {
             $model = self::getModelTime($where, $model, $aler . 'add_time');
         }
+        if (isset($where['cost_money_type']) && $where['cost_money_type'] !== '') {
+            $model = $model->where($aler . 'cost_money_type', $where['cost_money_type']);
+        }
+//        var_dump($model);
         return $model;
     }
 
@@ -321,7 +354,7 @@ class UserMiningMachine extends BaseModel
         $money_type = init_money_type();
         foreach ($money_type as $k => $v) {
             $whereData['cost_money_type'] = $k;
-            $sumNumber = self::getOrderWhere($where, $model)->field([
+            $sumNumber = self::getOrderWhere(array_merge($where, $whereData), $model)->field([
                 'sum(cost_money) as sum',
                 'sum(stand_money) as stand_sum',
             ])->find();
@@ -331,6 +364,7 @@ class UserMiningMachine extends BaseModel
             $price[$k . '_pay'] = $sumNumber['sum'];
             $price[$k . '_stand'] = $sumNumber['stand_sum'];
         }
+//        var_dump($where);
         $sumNumber = self::getOrderWhere($where, $model)->field([
             'sum(num) as sum_total_num',
             'count(id) as count_sum',

+ 6 - 4
crmeb/subscribes/TaskSubscribe.php

@@ -125,11 +125,13 @@ class TaskSubscribe
             Db::rollback();
         }
         try {
-
-            UserMiningMachine::dayMining();//每日挖矿
-
+//            $day_gets['XCH'] = 0;
+            $res = UserMiningMachine::dayMining();//每日挖矿
+            if (!$res) {
+                @file_put_contents('mining.txt', '【' . date('Y-m-d H:i:s') . '】' . UserMiningMachine::getErrorInfo() . PHP_EOL, FILE_APPEND);
+            }
         } catch (\Exception $e) {
-
+            @file_put_contents('mining.txt', '【' . date('Y-m-d H:i:s') . '】' . $e->getMessage() . PHP_EOL, FILE_APPEND);
         }
         try {
             Db::startTrans();