Forráskód Böngészése

updating: server-side

joe 4 éve
szülő
commit
ddbd9c0051

+ 16 - 2
app/admin/controller/Test.php

@@ -4,7 +4,10 @@ namespace app\admin\controller;
 
 
 use crmeb\services\async\LuckyCalc;
+use crmeb\services\async\ClearanceCalc;
 use crmeb\utils\Redis;
+use think\facade\Log;
+use app\api\controller\board\UserBoardController;
 
 class Test
 {
@@ -15,9 +18,20 @@ class Test
         var_dump($redis->get(['CRMEB','TESD']));
     }
 
+    protected function test_board() {
+        Log::warning("board updated.");
+        $ctl = new UserBoardController();
+        $ctl->cache_board();
+    }
+
+    protected function test_calc() {
+        $activities = [new ClearanceCalc(), new LuckyCalc()];
+        foreach($activities as $activity) {
+            $activity->calc();
+        }
+    }
+
     public function test()
     {
-        $calcer = new LuckyCalc;
-        $calcer->calc();
     }
 }

+ 73 - 1
app/api/controller/coin/UserCoinController.php

@@ -12,7 +12,79 @@ use think\facade\Config;
 
 class UserCoinController {
     public function status(Request $request) {
-        
+        // 是否开启挖矿
+        $symbol = Config::get('app.mining_symbo');
+        //
+        $icon = Cache::get($symbol);
+        if (!$icon) {
+            $icon = DictCoin::where('symbol', $symbol)->value('icon');
+            Cache::set($symbol, $icon);
+        }
+        //
+        $defStatus = [
+            'progress'=> 0,
+            'symbol'=>$symbol,
+            'icon'=>$icon,
+            'price'=> 0.00,
+            'total'=> 0,
+            'step' => 0,
+        ];
+
+        if (!$symbol) {
+            Log::warning('mining disabled: $symbol');
+            return app('json')->successful($defStatus);
+        }
+
+        $uid = $request->uid();
+        $mymining = UserHash::mining_get($uid) ?? $defStatus;
+        if ($mymining['progress'] > 0) {
+            $mining = $this->calcMining($uid, $mymining);
+            UserHash::mining_set($uid, $mining);
+        }
+    }
+
+    /**
+     * 根据上次挖矿状态, 和过去的时长, 计算当前的状态
+     * @param $p
+     * @return mixed
+     */
+    protected function calcMining($uid, $p) {
+        if ($p['progress'] <= 0) {
+            return $p;
+        }
+        if (!isset($p['ts'])) {
+            return $p;
+        }
+        $now = time();
+        $secs_passed = $now - $p['ts'];
+        $secs_unit = Config::get('app.mining_sec_unit');
+        $reward_unit = Config::get('app.mining_num_per_unit');
+        $hours = Config::get('app.mining_time');
+        if (count($hours) != 2 || $hours[0] > $hours[1]) {
+            Log::warning('app.mining_time config error.');
+            return $p;
+        }
+        $hour = random_int($hours[0], $hours[1]);
+        $secs = $hour * 60 * 60;
+        //
+        if ($secs_passed >= $secs) { // 挖矿结束
+            $p['progress'] = 0;
+
+            // 本次个数
+            $count = floatval(bcmul(bcdiv($secs, $secs_unit, 8), $reward_unit, 8));
+            // save to database
+            if (!UserCoinTransfer::addMining($uid, $p['order_id'], $p['symbol'], $count)) {
+                Log::error("user<$uid> save transfer failed, amount<$count>");
+            }
+
+            $p['total'] += $count;
+            return $p;
+        }
+
+        $count = floatval(bcmul(bcdiv($secs_passed, $secs_unit, 8), $reward_unit, 8));
+        $p['progress'] = $count;
+
+        return $p;
     }
 
     /**

+ 2 - 2
app/api/controller/store/StoreProductController.php

@@ -179,11 +179,11 @@ class StoreProductController
             }
         } else $data['replyChance'] = 0;
         $data['mer_id'] = $storeInfo['mer_id'];
-        $data['system_store'] = ($res = SystemStore::getStoreDispose()) ? $res : [];
+        $data['system_store'] = []; // ($res = SystemStore::getStoreDispose()) ? $res : [];
         $data['good_list'] = StoreProduct::getGoodList(18, 'image,store_name,price,id,ot_price');
         $data['mapKey'] = sys_config('tengxun_map_key');
         $data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;//门店自提是否开启
-        $data['activity'] = StoreProduct::activity($data['storeInfo']['id'], false);
+        $data['activity'] = []; // StoreProduct::activity($data['storeInfo']['id'], false);
         return app('json')->successful($data);
     }
 

+ 5 - 2
app/api/controller/user/UserController.php

@@ -94,7 +94,7 @@ class UserController
         $user['couponCount'] = 0; //StoreCouponUser::getUserValidCouponCount($user['uid']);
         $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
         $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
-//        $user['notice'] = UserNotice::getNotice($user['uid']);
+        $user['notice'] = UserNotice::getNotice($user['uid']);
 //        $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
         $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值
         $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费
@@ -161,7 +161,10 @@ class UserController
         } else if (!$user['phone']) {
             $user['switchUserInfo'][] = $request->user();
         }
-
+        $coins = UserCoin::alias('uc')
+            ->join('dict_coin dc', 'uc.symbol=dc.symbol')->field('uc.symbol, dc.icon, uc.addr, uc.balance as total')
+            ->where('uid', $user['uid'])->select();
+        $user['coins'] = $coins ? $coins->toArray() : [];
         return app('json')->successful($user);
     }
 

+ 3 - 68
app/api/controller/user/UserNotificationController.php

@@ -32,73 +32,8 @@ class UserNotificationController {
         // 未读消息
         $unread = UserHash::unread_get($uid);
 
-        // 是否开启挖矿
-        $symbol = Config::get('app.mining_symbo');
-        $icon = Cache::get($symbol);
-        if (!$icon) {
-            $icon = DictCoin::where('symbol', $symbol)->value('icon');
-            Cache::set($symbol, $icon);
-        }
-
-        $defStatus = [
-            'progress'=> 0,
-            'symbol'=>$symbol,
-            'icon'=>$icon,
-            'total'=> 0,
-            'ts' => time(),
-        ];
-        if ($symbol) {
-            $mymining = UserHash::mining_get($uid) ?? $defStatus;
-            if ($mymining['progress'] > 0) {
-                $mining = $this->calcMining($uid, $mymining);
-                UserHash::mining_set($uid, $mining);
-            }
-        }
-
-        return app('json')->successful(compact('unread', 'mining', 'carousel'));
-    }
-
-    /**
-     * 根据上次挖矿状态, 和过去的时长, 计算当前的状态
-     * @param $p
-     * @return mixed
-     */
-    protected function calcMining($uid, $p) {
-        if ($p['progress'] <= 0) {
-            return $p;
-        }
-        if (!isset($p['ts'])) {
-            return $p;
-        }
-        $now = time();
-        $secs_passed = $now - $p['ts'];
-        $secs_unit = Config::get('app.mining_sec_unit');
-        $reward_unit = Config::get('app.mining_num_per_unit');
-        $hours = Config::get('app.mining_time');
-        if (count($hours) != 2 || $hours[0] > $hours[1]) {
-            Log::warning('app.mining_time config error.');
-            return $p;
-        }
-        $hour = random_int($hours[0], $hours[1]);
-        $secs = $hour * 60 * 60;
-        //
-        if ($secs_passed >= $secs) { // 挖矿结束
-            $p['progress'] = 0;
-
-            // 本次个数
-            $count = floatval(bcmul(bcdiv($secs, $secs_unit, 8), $reward_unit, 8));
-            // save to database
-            if (!UserCoinTransfer::addMining($uid, $p['order_id'], $p['symbol'], $count)) {
-                Log::error("user<$uid> save transfer failed, amount<$count>");
-            }
-
-            $p['total'] += $count;
-            return $p;
-        }
-
-        $count = floatval(bcmul(bcdiv($secs_passed, $secs_unit, 8), $reward_unit, 8));
-        $p['progress'] = $count;
-
-        return $p;
+        return app('json')->successful([
+            'unread': intval($unread),
+        ]));
     }
 }

+ 4 - 3
app/models/board/UserBoard.php

@@ -4,6 +4,7 @@ namespace app\models\board;
 use crmeb\traits\ModelTrait;
 use crmeb\basic\BaseModel;
 use think\facade\Db;
+use think\facade\Env;
 
 class UserBoard extends BaseModel {
     protected $pk = 'id';
@@ -28,12 +29,12 @@ class UserBoard extends BaseModel {
         $tcart_info = $prefix . 'store_order_cart_info';
         $torder = $prefix . 'store_order';
         $sql = sprintf("
-            select u.uid, u.avatar, u.nickname, u.level, sum(reparation) as value 
+            select distinct u.uid, u.avatar, u.nickname, u.level, sum(reparation) as value 
             from %s tsoci inner join %s tso on tsoci.oid=tso.id inner join %s u on tso.uid = u.uid 
-            where activity is not null and tso.pay_time > %d 
+            where activity is not null and tso.pay_time > %d and reparation > 0
             group by oid 
             order by value desc, u.uid asc limit %d
-        ", $tcart_info, $torder, $tuser, $start, 30)
+        ", $tcart_info, $torder, $tuser, $start, 30);
         return Db::query($sql);
     }
 }

+ 2 - 3
app/models/user/UserNotice.php

@@ -81,10 +81,9 @@ class UserNotice extends BaseModel
         $tnotice = $prefix . 'user_notice';
         $tnotice_see = $prefix . 'user_notice_see';
         $sql = sprintf("
-            select n.id, n.icon, n.`user` as `from`, n.title as subject, n.content as `body`, n.add_time as ts, n.`type`, count(s.id) as `read`
-            from %s n right join %s s on n.uid = s.uid 
+            select n.id, n.icon, n.`user` as `from`, n.title as subject, n.content as `body`, n.add_time as ts, n.`type`, s.id as `read`
+            from %s n left join %s s on n.id = s.nid 
             where n.uid in (%d, 0) and n.del_time=0
-            group by s.id 
             order by n.add_time desc limit %d,%d
         ", $tnotice, $tnotice_see, $uid, ($page-1)*$limit, $limit);
         $data = Db::query($sql);

+ 3 - 3
config/activity.php

@@ -4,7 +4,7 @@ return [
     // 根分类ID
     'root_cate_id' => 10,
     // 是否开启挖矿活动
-    'mining_enabled' => true,
+    'mining_enabled' => false,
     'mining_display_name' => '黑洞星球',
     'mining_display_pic' => 'http://x.png',
     // 挖矿活动ID
@@ -13,11 +13,11 @@ return [
     // 免单活动ID
     'free_cate_id' => 3,
     // 清仓活动ID
-    'clearance_cate_id' => 1,
+    'clearance_cate_id' => 2,
     // 清仓开奖时间表
     'clearrance_daily_opens' => [],
     // 幸运活动 ID
-    'lucky_cate_id' => 2,
+    'lucky_cate_id' => 1,
     // 幸运活动开奖时间表
     'lucky_daily_opens' => [],
 ];

+ 1 - 1
config/app.php

@@ -60,5 +60,5 @@ return [
     'mining_num_per_unit' => 0.01,
 
     // 排行榜 banner 750 x 142
-    'leader_board_banner' => 'http://b.png',
+    'leader_board_banner' => 'http://twongstatic.shotshock.shop/banner_bargin.jpg',
 ];

+ 5 - 4
crmeb/subscribes/TimerSubscribe.php

@@ -92,13 +92,14 @@ class TimerSubscribe
         $tm = localtime(time(), true);
 
         // 缓存排行榜
-        if ($tm['tm_min'] % 5 == 0) {
+        Log::warning("onTimer_60()" . $tm['tm_hour'] . ':' . $tm['tm_min']);
+        if (intval($tm['tm_min']) % 5 == 0) {
+            Log::warning("board updated.");
             $ctl = new UserBoardController();
             $ctl->cache_board();
-            Log::warning("board updated.");
         }
 
-        if ($tm['tm_min'] == 0) {
+        if (intval($tm['tm_min']) == 0) {
             // 整点做活动
             $activities = [new ClearanceCalc(), new LuckyCalc()];
             foreach($activities as $activity) {
@@ -106,7 +107,7 @@ class TimerSubscribe
             }
             Log::warning('onTimer_60() activities calculated.');
             // 每日 24
-            if ($tm['tm_hour'] == 0) {
+            if (intval($tm['tm_hour']) == 0) {
                 SystemLog::deleteLog();
                 Log::warning('onTimer_60() remove outdated admin logs');
             }

+ 3 - 3
public/install/crmeb.sql

@@ -7826,7 +7826,7 @@ CREATE TABLE `eb_dict_coin` (
     `symbol` varchar(8) NOT NULL COMMENT '币英文名',
     `name` varchar(32) NOT NULL DEFAULT '' COMMENT '中文名',
     `icon` varchar(255) NOT NULL COMMENT '图标',
-    `price` decimal(12,8) NOT NULL DEFAULT 0.00000000 COMMENT '价格(rmb)',
+    `price` decimal(20,8) NOT NULL DEFAULT 0.00000000 COMMENT '价格(rmb)',
     `min_withdrawal` decimal(16,8) unsigned NOT NULL DEFAULT 0.00000000 COMMENT '最低提币数',
     PRIMARY KEY (`symbol`) USING BTREE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='币字典表';
@@ -7871,7 +7871,7 @@ CREATE TABLE `eb_user_coin` (
     `uid` int(10) unsigned NOT NULL,
     `symbol` varchar(8) NOT NULL,
     `addr` varchar(1024) NOT NULL DEFAULT '' COMMENT '提币地址',
-    `balance` decimal(12,8) NOT NULL DEFAULT 0.00000000 COMMENT '余额',
+    `balance` decimal(20,8) NOT NULL DEFAULT 0.00000000 COMMENT '余额',
     PRIMARY KEY (`id`) USING BTREE,
     UNIQUE KEY `uid_symbol` (`uid`,`symbol`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户币表';
@@ -7886,7 +7886,7 @@ CREATE TABLE `eb_user_coin_transfer` (
     `symbol` varchar(8) NOT NULL COMMENT '币',
     `from` varchar(1024) NOT NULL DEFAULT '' COMMENT '转账方地址 空为系统地址',
     `to` varchar(1024) NOT NULL DEFAULT '' COMMENT '转账接收地址',
-    `amount` decimal(12,8) NOT NULL COMMENT '转账金额',
+    `amount` decimal(20,8) NOT NULL COMMENT '转账金额',
     `ts` int(11) unsigned NOT NULL COMMENT '时间戳',
     `out` tinyint(2) NOT NULL DEFAULT 0 COMMENT '转账方向 0 收入 1 转出',
     `status` tinyint(2) unsigned NOT NULL DEFAULT 0 COMMENT '状态 0:正常 1:待处理',

+ 1 - 1
route/api/route.php

@@ -163,7 +163,7 @@ Route::group(function () {
     //首页获取未支付订单
     Route::get('order/nopay', 'order.StoreOrderController/get_noPay')->name('getNoPay');//获取未支付订单
     // 模拟推送 (需要登录)
-    Route::get('user/notifications', 'user.UserNotificationController/snapshot')->name('userNotifications');
+    //Route::get('user/notifications', 'user.UserNotificationController/snapshot')->name('userNotifications');
 
     /**
      * 消息类 api, 需要权限, 暂时为测试