فهرست منبع

feat: 成为分销商条件

xiansin 2 سال پیش
والد
کامیت
5267f9ce9a

+ 20 - 2
mini/pages/index/index.vue

xqd xqd xqd
@@ -52,6 +52,7 @@ import TabBar from '../../components/TabBar/index'
 import NavBar from '../../components/NavBar/index'
 import Recent from './components/Recent'
 import CheckLogin from '../../components/CheckLogin/index'
+import { mapState } from 'vuex'
 export default {
   components: { CheckLogin, Recent, NavBar, TabBar, EpisodeBox, SwiperBox },
   data() {
@@ -63,16 +64,24 @@ export default {
         3: 'news',
         4: 'rank'
       },
-      homeColumn: []
+      homeColumn: [],
+      parent_id: 0
     }
   },
   computed: {
     isLogin() {
       return this.$api.user.isLogin()
-    }
+    },
+    ...mapState({
+      userInfo: seate => seate.user.info
+    })
   },
   onLoad(options) {
     this.isLogin && this.getHomeColumn()
+    this.parent_id = typeof options.user_id !== 'undefined' ? options.user_id : 0
+    if (this.parent_id && !this.userInfo.parent_id) {
+      this.bindParent()
+    }
   },
   methods: {
     handleSearch() {
@@ -94,7 +103,16 @@ export default {
           obj.type = this.homeColumnType[obj.type]
         })
       })
+    },
+    bindParent() {
+      this.$api.user.bind(this.parent_id).then(res => {
+        console.log('-->bind success')
+        this.$store.dispatch('user/info', res.data)
+      })
     }
+  },
+  onShareAppMessage() {
+    return this.$util.shareMessage(this.userInfo)
   }
 }
 </script>

+ 3 - 3
mini/setting.js

xqd
@@ -2,14 +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/'
+// 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' : URL,
+  BASE_URL: IS_DEV ? 'http://www.zsy.me/api' : URL + '/api',
   // API 接口URL
   IMAGE_URL: IS_DEV ? 'http://www.zsy.me/static/image' : URL + '/static/image'
 }

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

xqd xqd xqd
@@ -52,6 +52,8 @@ class PayNoticeController extends Controller
                     $factory->pushOrder($payInfo->user->open_id, $payId, $goods ,'已支付');
                 }
                 \DB::commit();
+                // 成为分销商
+                (new User())->beComeShare($pay->user_id);
             } catch (\Exception $e) {
                 \DB::rollBack();
                 \Log::error('抖音支付回调错误==>'.$e->getMessage());
@@ -93,6 +95,8 @@ class PayNoticeController extends Controller
                 }
 
                 \DB::commit();
+                // 成为分销商
+                (new User())->beComeShare($pay->user_id);
             } catch (\Exception $e) {
                 \DB::rollBack();
                 \Log::error('快手支付回调错误==>'.$e->getMessage());
@@ -139,6 +143,8 @@ class PayNoticeController extends Controller
                 }
 
                 \DB::commit();
+                // 成为分销商
+                (new User())->beComeShare($pay->user_id);
             } catch (\Exception $e) {
                 \DB::rollBack();
                 \Log::error('微信支付回调错误==>'.$e->getMessage());

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

xqd
@@ -85,6 +85,8 @@ class UserController extends Controller
 
         $user = User::with(['info','parent'])->where('id', $user->id)->first();
 
+        (new User())->beComeShare($user->id);
+
         return $this->success($user);
     }
 

+ 34 - 0
server/app/Models/User.php

xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Models;
 
+use Carbon\Carbon;
 use Dcat\Admin\Traits\HasDateTimeFormatter;
 use Illuminate\Database\Eloquent\SoftDeletes;
 use Illuminate\Foundation\Auth\User as Authenticatable;
@@ -170,4 +171,37 @@ class User extends Authenticatable implements JWTSubject
     {
         return $this->hasMany(UserVipRecord::class,'user_id','id');
     }
+
+    public function beComeShare($id)
+    {
+        $user = self::find($id);
+        if(!$user->is_share){
+            $config = ShareConfig::first();
+            $isBecome = false;
+            if($config->become_type == 1) {// 无条件
+                $isBecome = true;
+            }else if($config->become_type == 2){ // 成为对应的会员
+                $vipRecords = UserVipRecord::where('combo_id' , $config->become_vip_id)
+                    ->where('user_id', $user->id)
+                    ->where('status', 1)
+                    ->count();
+                if($vipRecords){
+                    $isBecome = true;
+                }
+            }else{ // 充值一定金币
+                $RechargeGold = UserRechargeRecord::where('user_id', $user->id)
+                    ->where('status', 1)
+                    ->sum('gold');
+                if($RechargeGold >= $config->become_gold){
+                    $isBecome = true;
+                }
+            }
+
+            if($isBecome){
+                $user->is_share = 1;
+                $user->become_share_at = Carbon::now()->toDateTimeString();
+                $user->save();
+            }
+        }
+    }
 }