hrjy há 2 anos atrás
pai
commit
d9459e6e6e

+ 11 - 0
app/admin/controller/user/User.php

@@ -322,6 +322,7 @@ class User extends AuthController
      */
     public function edit($uid)
     {
+
         if (!$uid) return $this->failed('数据不存在');
         $user = UserModel::get($uid);
         if (!$user) return Json::fail('数据不存在!');
@@ -331,6 +332,10 @@ class User extends AuthController
         $f[] = Form::text('phone', '手机号', $user->getData('phone'));
         $f[] = Form::date('birthday', '生日', $user->getData('birthday') ? date('Y-m-d', $user->getData('birthday')) : 0);
         $f[] = Form::input('card_id', '身份证号', $user->getData('card_id'));
+        $f[] = Form::input('flowing_water', '流水分红', $user->getData('flowing_water'));
+        $f[] = Form::input('city', '代理市', $user->getData('city'));
+        $f[] = Form::input('area', '代理区', $user->getData('area'));
+        $f[] = Form::input('flowing_water', '流水分红', $user->getData('flowing_water'));
         $f[] = Form::textarea('mark', '用户备注', $user->getData('mark'));
         $f[] = Form::radio('is_promoter', '推广员', $user->getData('is_promoter'))->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
         $f[] = Form::select('spread_uid', '推荐人', (string)$user->getData('spread_uid'))->options(array_merge([['value' => 0, 'label' => '无']], UserModel::where('uid', '<>', $uid)->field('uid as value,nickname as label')->select()->toArray()))->filterable(true);
@@ -355,6 +360,9 @@ class User extends AuthController
             ['integration', 0],
             ['status', 0],
             ['spread_uid', 0],
+            ['flowing_water', 0],
+            ['city', ''],
+            ['area', ''],
         ]);
         if (!$uid) return $this->failed('数据不存在');
         $user = UserModel::get($uid);
@@ -420,6 +428,9 @@ class User extends AuthController
         $edit['birthday'] = strtotime($data['birthday']);
         $edit['mark'] = $data['mark'];
         $edit['is_promoter'] = $data['is_promoter'];
+        $edit['flowing_water'] = $data['flowing_water'];
+        $edit['city'] = trim($data['city'],'');
+        $edit['area'] = trim($data['area'], '');
         if ($edit) $res3 = UserModel::edit($edit, $uid);
         else $res3 = true;
         if ($res1 && $res2 && $res3 && $res_sp) $res = true;

+ 4 - 0
app/admin/view/user/user/index.php

@@ -233,6 +233,9 @@
                         {{# } }}
                     </script>
+                    <script type="text/html" id="flowing_water">
+                        {{d.flowing_water}}%
+                    </script>
                     <script type="text/html" id="data_time">
                         <p>首次:{{d.add_time}}</p>
                         <p>最近:{{d.last_time}}</p>
@@ -338,6 +341,7 @@
             // {field: 'status', title: '状态',templet:"#checkboxstatus",width:'6%',align:'center'},
             {field: 'effective', title: '账户状态',templet:"#effective",align:'center'},
             {field: 'is_merchant', title: '商家状态',templet:"#is_merchant",align:'center'},
+            {field: 'flowing_water', title: '流水分红',align:'center',templet:"#flowing_water"},
             // {field: 'user_type', title: '用户类型',width:'6%',align:'center'},
             {field: 'operate', title: '操作', width: '10%', align: 'center', toolbar: '#barDemo'}
         ];

+ 19 - 0
app/common.php

@@ -647,5 +647,24 @@ if (!function_exists('do_request')) {
         }
     }
 
+    if (!function_exists('getParent')){
+        //查找所有上级
+        function getParent($uid){
+            //当前用户
+            static $arr=[];
+            //当前用户
+            $member = getDataFind('user',array('uid'=>$uid));
+            if ($member['spread_uid'] > 0){
+                $parent = getDataFind('user',array('uid'=>$member['spread_uid']));
+
+                $arr[]= $parent['uid'];
+
+                getParent($parent['uid']);
+            }
+            return $arr;
+
+        }
+    }
+
 
 }

+ 40 - 2
app/http/middleware/AllowOriginMiddleware.php

@@ -6,9 +6,11 @@ namespace app\http\middleware;
 
 use app\models\many\Many;
 use app\models\many\ManyOrder;
+use app\models\user\User;
 use app\Request;
 use crmeb\interfaces\MiddlewareInterface;
 use think\facade\Config;
+use think\facade\Db;
 use think\Response;
 
 /**
@@ -54,8 +56,44 @@ class AllowOriginMiddleware implements MiddlewareInterface
         } else {
             $response = $next($request)->header($header);
         }
-        Many::fail();
-        ManyOrder::suc_return();
+
+        try {
+            Db::startTrans();
+            User::agent();//区域代理发放
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
+
+        try {
+            Db::startTrans();
+            ManyOrder::push(); //团队奖励
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
+        try {
+            Db::startTrans();
+            ManyOrder::flowing_water(); //流水分红
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
+        try {
+            Db::startTrans();
+            Many::fail();//众筹失败
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
+        try {
+            Db::startTrans();
+            ManyOrder::suc_return(); // 众筹成功订单返还
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
+        ManyOrder::time(); //流水分红
 
         $request->filter(['htmlspecialchars', 'strip_tags', 'addslashes', 'trim']);
         return $response;

+ 7 - 0
app/models/many/Many.php

@@ -57,6 +57,13 @@ class Many extends BaseModel
     }
 
 
+    /**
+     * 众筹失败
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
     public static function fail()
     {
         $many = self::where('end_time', '<', time())->where('status', '=', 1)->select();//找到结束为完成的场次

+ 164 - 2
app/models/many/ManyOrder.php

@@ -6,6 +6,7 @@
 
 namespace app\models\many;
 
+use app\admin\model\system\SystemConfig;
 use app\models\user\User;
 use app\models\user\UserBill;
 use crmeb\services\PHPExcelService;
@@ -72,7 +73,7 @@ class ManyOrder extends BaseModel
         if ($order){
             foreach ($order as $item)
             {
-                if (strtotime($item['create_time'])+600 < time()){
+                if (strtotime($item['create_time'])+(86400*7) < time()){
                     $user = User::where('uid', $item['uid'])->find();//用户
                     $user1 = [];
                     $user2 = [];
@@ -96,7 +97,7 @@ class ManyOrder extends BaseModel
                         $user2['purple_integral'] += round($sy2 * 0.7, 2);
                         $user2['business_integral'] += round($sy2 * 0.3, 2);
                     }
-                    self::where('id', $item['id'])->update(['status' => 1]);
+                    self::where('id', $item['id'])->update(['status' => 1, 'return_time' => time()]);
                     $user->save();
                     UserBill::income('众筹成功奖励紫积分', $user['uid'], 'purple_integral', 'zccg', $purple_integral, $user['spread_uid'], $user['purple_integral'], '众筹成功返还紫积分');
                     UserBill::income('众筹成功奖励商家积分', $user['uid'], 'business_integral', 'zccg', $business_integral, $user['spread_uid'], $user['business_integral'], '众筹成功返还商家积分');
@@ -115,5 +116,166 @@ class ManyOrder extends BaseModel
         }
     }
 
+    /**
+     * 团队奖励
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function push()
+    {
+        if (!Push::where('add_time', strtotime('today'))->find()){
+            $user = User::select();
+            foreach ($user as $item)
+            {
+                $price = ManyOrder::whereBetweenTime('return_time', strtotime('yesterday'), strtotime('today'))->where('uid', $item['uid'])->sum('price');// 昨天众筹成功返还的金额流水
+                if ($item['spread_uid'] > 0 and $price > 0){
+                    $spread = getParent($item['uid']);// 找到所有上级
+                    $v1 = 0;
+                    $v2 = 0;
+                    $v3 = 0;
+                    $one = SystemConfig::getConfigValue('v1')/100; // v1比例
+                    $tow = SystemConfig::getConfigValue('v2')/100;// v2比例
+                    $three = SystemConfig::getConfigValue('v3')/100;// v3比例
+                    foreach ($spread as $value) {
+                        $details = User::where('uid', $value)->find();
+                        if ($details['level'] == 1){
+                            if ($v2 == 0 and $v3 == 0){
+                                // 没有发放v2和v3的奖励
+                                if ($v1 == 0) { // 没有发放v1的奖励
+                                    $jl = $price * $one;
+                                    $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                    $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                    $v1++;
+                                }elseif ($v1 == 1){// 发放v1奖励1次
+                                    $jl = ($price*$one)*0.05;//平级的百分之五
+                                    $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                    $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                    $v1++;
+                                }
+                            }
+                        }elseif ($details['level'] == 2){
+                            if ($v3 == 0){
+                                // 没有发放v3的奖励
+                                if ($v1 == 0 and $v2 == 0) { // 没有发放v1和v2的奖励的奖励
+                                    $jl = $price * $tow; // 拿到流水的百分之八
+                                    $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                    $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                    $v2++;
+                                }elseif($v1 == 0 and $v2 == 1) { // 没有发放v1和v2的奖励的奖励
+                                    $jl = ($price * $tow)*0.05; // 拿到流水的百分之八
+                                    $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                    $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                    $v2++;
+                                }elseif ($v1 > 0 and $v2 == 0){// 发放v1奖励,没有发放v2的奖励
+                                    $jl = $price * ($tow - $one); // 拿到流水减掉v1的百分之五
+                                    $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                    $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                    $v2++;
+                                }elseif ($v1 > 0 and $v2 == 1){// 发放v1奖励,发放v2的奖励一次
+                                    $jl = ($price * ($tow - $one))*0.05; // 拿到平级的百分之五
+                                    $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                    $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                    $v2++;
+                                }
+
+                            }
+
+                        }elseif ($details['level'] == 3){
+                            if ($v1 == 0 and $v2 == 0 and $v3 == 0) { // 没有发放v1和v2v3的奖励的奖励
+                                $jl = $price * $three; // 拿到流水的百分之11
+                                $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                $v3++;
+                            }elseif ($v1 == 0 and $v2 == 0 and $v3 == 1) {// 没有发放v1和v2的奖励的奖励
+                                $jl = ($price * $three) * 0.05; // 拿到平级的百分之五
+                                $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                $v3++;
+                            }elseif ($v1 > 0 and $v2 == 0 and $v3 == 0){// 发放v1奖励,没有发放v2v3的奖励
+                                $jl = $price * ($three - $one); // 拿到流水减掉v1的百分之五
+                                $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                $v3++;
+                            }elseif ($v1 > 0 and $v2 == 0 and $v3 == 1){// 发放v1奖励,没有发放v2v3的奖励
+                                $jl = ($price * ($three - $one)) * 0.05; // 拿到平级的百分之五
+                                $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                $v3++;
+                            }elseif ($v1 == 0 and $v2 > 0 and $v3 == 0){// 发放v1奖励,发放v2的奖励,没有发放v3的奖励
+                                $jl = ($price * ($three - $tow)); // 拿到平级的百分之五
+                                $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                $v3++;
+                            }elseif ($v1 == 0 and $v2 > 0 and $v3 == 1){// 发放v1奖励,发放v2的奖励,发放v3的奖励
+                                $jl = ($price * ($three - $tow)) * 0.05; // 拿到平级的百分之五
+                                $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                $v3++;
+                            }elseif ($v1 > 0 and $v2 > 0 and $v3 == 0){// 发放v1奖励,发放v2的奖励,发放v3的奖励
+                                $jl = ($price * ($three - $tow)); // 拿到平级的百分之五
+                                $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                $v3++;
+                            }elseif ($v1 > 0 and $v2 > 0 and $v3 == 1){// 发放v1奖励,发放v2的奖励,发放v3的奖励
+                                $jl = ($price * ($three - $tow)) * 0.05; // 拿到平级的百分之五
+                                $details['purple_integral'] = $jl * 0.7; // 百分之70的紫积分
+                                $details['business_integral'] = $jl * 0.3; // 百分之30的商家积分
+                                $v3++;
+                            }
+                        }
+                        if ($jl > 0){
+                            $details->save();
+                            UserBill::income('团队奖励紫积分', $details['uid'], 'purple_integral', 'team', $jl * 0.7, 0,$details['purple_integral'], 'v'.$details['level'].'团队奖励紫积分');
+                            UserBill::income('团队奖励商家积分', $details['uid'], 'business_integral', 'team', $jl * 0.3, 0,$details['business_integral'], 'v'.$details['level'].'团队奖励商家积分');
+                        }
+                        $jl = 0;
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 流水分红
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function flowing_water()
+    {
+        if (!Push::where('add_time', strtotime('today'))->find()) {
+            $user = User::where('flowing_water', '>', 0)->select();
+            if ($user) {
+                foreach ($user as $item) {
+                    $price = ManyOrder::whereBetweenTime('return_time', strtotime('yesterday'), strtotime('today'))->sum('price');// 昨天众筹成功返还的流水
+                    $details = User::where('uid', $item['uid'])->find();
+
+                    $details['purple_integral'] = ($price * ($details['flowing_water'] / 100)) * 0.7; // 百分之70的紫积分
+                    $details['business_integral'] = ($price * ($details['flowing_water'] / 100)) * 0.3; // 百分之30的商家积分
+                    $details->save();
+                    UserBill::income('分红流水奖励紫积分', $details['uid'], 'purple_integral', 'team', ($price * ($details['flowing_water'] / 100)) * 0.7, 0, $details['purple_integral'], '分红流水奖励紫积分');
+                    UserBill::income('分红流水奖励商家积分', $details['uid'], 'business_integral', 'team', ($price * ($details['flowing_water'] / 100)) * 0.3, 0, $details['business_integral'], '分红流水奖励商家积分');
+                }
+            }
+        }
+    }
+
+    /**
+     * 更新推送时间
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function time()
+    {
+        if (!Push::where('add_time', strtotime('today'))->find()) {
+            Push::create(['add_time' => strtotime('today')]); //存入数据库信息
+        }
+    }
+
 
 }

+ 36 - 0
app/models/many/Push.php

@@ -0,0 +1,36 @@
+<?php
+/**
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/11/11
+ */
+
+namespace app\models\many;
+
+use app\models\user\User;
+use app\models\user\UserBill;
+use crmeb\services\PHPExcelService;
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+
+/**
+ * Class StoreCategory
+ * @package app\admin\model\store
+ */
+class Push extends BaseModel
+{
+
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'push';
+
+    use ModelTrait;
+
+}

+ 34 - 0
app/models/user/User.php

@@ -3,6 +3,7 @@
 
 namespace app\models\user;
 
+use app\models\many\Push;
 use app\models\store\StoreOrder;
 use app\models\store\StoreProduct;
 use crmeb\services\SystemConfigService;
@@ -736,4 +737,37 @@ class User extends BaseModel
         }
         return $model->where('brokerage_price', '>', $brokerage_price)->count('uid');
     }
+
+    public static function agent()
+    {
+        if (!Push::where('add_time', strtotime('today'))->find()) {
+            $user = self::where('city', '<>', '')->select();
+            if ($user) {
+                foreach ($user as $item) {
+                    $address = $item['city'] . ' ' . $item['area'];
+                    $order_price = StoreOrder::where('user_address', 'like', '%' . $address . '%')->where('paid', 1)->whereBetweenTime('pay_time', strtotime('yesterday'), strtotime('today'))->sum('pay_price');//订单流水
+                    if ($order_price > 0) {
+                        $details = self::where('uid', $item['uid'])->find();
+                        if ($item['area'] == '') {//市代理
+                            $purple_integral = ($order_price * 0.005) * 0.7;
+                            $business_integral = ($order_price * 0.005) * 0.3;
+                            $details['purple_integral'] = ($order_price * 0.005) * 0.7;
+                            $details['business_integral'] = ($order_price * 0.005) * 0.3;
+                        } else {//区代理
+                            $purple_integral = ($order_price * 0.01) * 0.7;
+                            $business_integral = ($order_price * 0.01) * 0.3;
+                            $details['purple_integral'] = $purple_integral;
+                            $details['business_integral'] = $business_integral;
+                        }
+                        $details->save();
+                        UserBill::income('代理奖励紫积分', $details['uid'], 'purple_integral', 'team', $purple_integral, 0, $details['purple_integral'], $address . '代理奖励紫积分');
+                        UserBill::income('代理奖励商家积分', $details['uid'], 'business_integral', 'team', $business_integral, 0, $details['business_integral'], $address . '代理奖励商家积分');
+
+                    }
+                }
+            }
+        }
+    }
+
+
 }