Ver código fonte

add: 增加开奖结果的 jsonp 接口,供官网查询结果

joe 4 anos atrás
pai
commit
ad81451f1e

+ 27 - 0
app/api/controller/PublicController.php

@@ -2,6 +2,7 @@
 
 namespace app\api\controller;
 
+use app\models\system\SystemAwardHistory;
 use app\admin\model\system\SystemAttachment;
 use app\models\store\StoreCategory;
 use app\models\store\StoreCouponIssue;
@@ -327,4 +328,30 @@ class PublicController
         return app('json')->successful($data);
     }
 
+    /**
+     * 返回给官网或第三方应用
+     * 
+     * 支持 jsonp
+     * 
+     */
+    public function get_activities_result()
+    {
+        $data = UtilService::getMore([
+            ['callback', ''],
+            ['begin', ts_of_day() - SECONDS_OF_ONEDAY],
+            ['end', 0],
+            ['activity', []],
+            ['page', 0],
+            ['limit', 0],
+        ]);
+        // $arr = json_encode([
+        //     'a' => 3,
+        //     'b' => 4,
+        // ]);
+        $callback = $data['callback'];
+        $res = SystemAwardHistory::getList($data['activity'], 
+            $data['begin'], $data['end'], $data['page'], $data['limit']);
+        $res = json_encode($res);
+        echo "$callback($res)";
+    }
 }

+ 2 - 0
app/common.php

@@ -34,6 +34,8 @@ define('SHIPPING_SELF_COLLECT', 2);
 define('DISTRIBUTE_SPECIFIED', 1);  // 指定分銷
 define('DISTRIBUTE_EVERYONE', 2);   // 人人分銷
 
+// 
+define('SECONDS_OF_ONEDAY', 86400);
 
 /**
  * 获取所有 幸运2021 活动及其子活动 ID 列表

+ 43 - 0
app/models/system/SystemAwardHistory.php

@@ -7,4 +7,47 @@ use crmeb\basic\BaseModel;
 class SystemAwardHistory extends BaseModel {
 
     use ModelTrait;
+
+    public static function InsertNew($activity, $result, $order_num, $winner_num, $total_paid, $diff_paid, $profit, $rate)
+    {
+        self::create([
+            'activity' => $activity,
+            'result' => $result,
+            'ts' => time(),
+            'order_num' => $order_num,
+            'winner_num' => $winner_num,
+            'total_paid' => $total_paid,
+            'diff_paid' => $diff_paid,
+            'profit' => $profit,
+            'rate' => $rate,
+        ]);
+    }
+
+    /**
+     * 获取开奖结果
+     * 
+     * @return array
+     */
+    public static function getList($activity, $startTime, $stopTime, $page, $limit)
+    {
+        $model = new self();
+        $model = $model::where('1=1');
+        if ($activity) {
+            $model = $model->where('activity', 'in', $activity);
+        }
+        if ($startTime) {
+            $model = $model->where('ts', '>=', $startTime);
+        }
+
+        if ($stopTime) {
+            $model = $model->where('ts', '<=', $stopTime);
+        }
+
+        if ($page && $limit) {
+            $model = $model->page(intval($page), intval($limit));
+        }
+
+        $model = $model->field('FROM_UNIXTIME(ts, "%Y-%m-%d %H:%i:%s") as ts, activity, result')->order('ts desc');
+        return $model->select()->toArray();
+    }
 }

+ 1 - 1
crmeb/traits/ModelTrait.php

@@ -93,7 +93,7 @@ trait ModelTrait
      * @param null $eachFn 处理结果函数
      * @param array $params 分页参数
      * @param int $limit 分页数
-     * @return array
+     * @return object
      */
     public static function page($model = null, $eachFn = null, $params = [], $limit = 20)
     {

+ 5 - 0
route/api/route.php

@@ -32,6 +32,11 @@ Route::post('register/reset', 'AuthController/reset')->name('registerReset')
  */
 Route::get('boards', 'board.UserBoardController/boards')->name('board'); // 排行榜榜单
 
+/**
+ * 开奖结果 api,支持 jsonp
+ */
+Route::get('activities', 'PublicController/get_activities_result')->name('activities'); // 排行榜榜单
+
 // 模拟推送 (不需要登录)
 Route::get('notifications', 'AuthController/notifications')->name('notifications'); // 获取通知