xiansin 2 年 前
コミット
73fce5da39

+ 7 - 0
mini/api/user/index.js

xqd xqd
@@ -58,6 +58,12 @@ export async function info() {
   )
 }
 
+export async function bind(id) {
+  return request.post(
+    `user/${id}/bind`
+  )
+}
+
 export function isLogin() {
   return !!getToken()
 }
@@ -65,6 +71,7 @@ export function isLogin() {
 export default {
   login,
   update,
+  bind,
   info,
   isLogin,
   episode,

+ 4 - 2
mini/setting.js

xqd
@@ -2,12 +2,14 @@
  * Created by JianJia.Zhou<jianjia.zhou> on 2022/3/18.
  */
 const IS_DEV = process.env.NODE_ENV === 'development'
+// const URL = 'https://zhangsiye.9026.com/'
+const URL = 'https://t3.9026.com/'
 
 module.exports = {
   // 版本
   VERSION: '0.0.1',
   // API 接口URL
-  BASE_URL: IS_DEV ? 'http://www.zsy.me/api' : 'https://zhangsiye.9026.com/api',
+  BASE_URL: IS_DEV ? 'http://www.zsy.me/api' : URL,
   // API 接口URL
-  IMAGE_URL: IS_DEV ? 'http://www.zsy.me/static/image' : 'https://zhangsiye.9026.com/static/image'
+  IMAGE_URL: IS_DEV ? 'http://www.zsy.me/static/image' : URL + '/static/image'
 }

+ 43 - 0
server/app/Http/Controllers/V1/PayNoticeController.php

xqd xqd xqd xqd
@@ -7,9 +7,12 @@ use App\Helper\ByteDance;
 use App\Helper\UniPlatform\Bytedance\Payment as BytedancePayment;
 use App\Helper\UniPlatform\Kuaishou\Payment as KuaishouPayment;
 use App\Models\Pay;
+use App\Models\ShareConfig;
+use App\Models\User;
 use App\Models\UserConsumeRecord;
 use App\Models\UserInfo;
 use App\Models\UserRechargeRecord;
+use App\Models\UserShare;
 use App\Models\UserVipRecord;
 use Carbon\Carbon;
 use Illuminate\Http\JsonResponse;
@@ -174,6 +177,9 @@ class PayNoticeController extends Controller
         $record->status = 1;
         $record->save();
 
+        // 分销
+        $this->share($record ,2);
+
         return [
             'id' => $record->combo_id,
             'title' => $record->combo->name,
@@ -204,6 +210,9 @@ class PayNoticeController extends Controller
         $record->status = 1;
         $record->save();
 
+        // 分销
+        $this->share($record,1);
+
         return [
             'id' => $record->combo_id,
             'title' => $record->combo->name,
@@ -212,5 +221,39 @@ class PayNoticeController extends Controller
         ];
 
     }
+
+
+    /**
+     * @param UserVipRecord | UserRechargeRecord $record
+     * @param $type
+     * @return void
+     */
+    private function share($record ,$type)
+    {
+        $user = User::find($record->user_id);
+        // 一级分销
+        if($user->parent_id){
+            $config = ShareConfig::first();
+            $pay = Pay::find($record->pay_id);
+            if($config->share_type == 1){ // 百分比
+                $income = $pay->order_fee * $config->share_number / 100;
+            }else{ // 固定
+                $income = $config->share_number;
+            }
+
+            $share = new UserShare();
+            $share->user_id = $user->parent_id;
+            $share->child_id = $user->id;
+            $share->order_type = $type;
+            $share->order_id = $record->pay_id;
+            $share->income = $income;
+            $share->save();
+
+
+            $user->income = $user->income + $income;
+            $user->total_income = $user->total_income + $income;
+            $user->save();
+        }
+    }
 }
 

+ 21 - 0
server/app/Http/Controllers/V1/UserController.php

xqd
@@ -88,6 +88,27 @@ class UserController extends Controller
         return $this->success($user);
     }
 
+    // 绑定上级
+    public function bind($id)
+    {
+        $user = \user();
+        $parent = User::find($id);
+        // 没有绑定上级 且上级存在其实分销商
+        if(!$user->parent_id && $parent && $parent->is_share){
+            $user->parent_id = $id;
+            $user->become_child_at = Carbon::now()->toDateTimeString();
+
+            // 之前不是分销商 自动成为分销商
+            if(!$user->is_share){
+                $user->become_share_at = Carbon::now()->toDateTimeString();
+                $user->is_share = 1;
+            }
+            $user->save();
+        }
+        $user = User::with(['info','parent'])->where('id', $user->id)->first();
+        return $this->success($user);
+    }
+
     public function update(Request $request)
     {
         try

+ 16 - 0
server/routes/api.php

xqd xqd
@@ -76,6 +76,7 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api)
             $api->post('feedback', 'UserController@feedback'); //问题反馈
             $api->get('info', 'UserController@info'); //用户信息
             $api->post('update', 'UserController@update'); //更新用户信息
+            $api->post('{id}/bind', 'UserController@bind'); //绑定上级
 
 
             $api->group(['namespace' => 'User'], function ($api){
@@ -174,6 +175,21 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api)
             $api->get('setting', 'ShareController@setting'); // 设置
         });
 
+        // 短剧
+        $api->group(['prefix' => 'episode'],function ($api){
+            /* @var Dingo\Api\Routing\Router $api*/
+            $api->get('recommend', 'EpisodeController@recommend'); // 推荐
+            $api->get('today/recommend', 'EpisodeController@todayRecommend'); // 今日推荐
+            $api->get('news', 'EpisodeController@news'); // 最新
+            $api->get('rank', 'EpisodeController@rank'); // 排行
+            $api->get('trace', 'EpisodeController@trace'); // 追剧
+            $api->get('list', 'EpisodeController@list'); // 列表
+            $api->get('search', 'EpisodeController@search'); // 搜索
+            $api->get('vip/free', 'EpisodeController@vipFree'); // banner
+            $api->get('{id}/detail', 'EpisodeController@detail'); // 详情
+            $api->get('/list/{listId}/buyNum', 'EpisodeController@listBuyNum'); // 详情
+        });
+
     });
 
     $api->get('pay/{pay_id}/query', 'PayController@query'); //字节跳动支付