| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 | <?phpnamespace Act\Lib;use Dever;class Share{    # 获取某个用户在某个图文的分享回流数    public function getRefluxNum($uid, $id, $type)    {        $where['source_uid'] = $uid;        $where['type'] = $type;        $where['data_id'] = $id;        return Dever::db('act/share_reflux')->total($where);    }    # 提交分享    public function submit($uid, $id, $type)    {        $where['uid'] = $uid;        $where['data_id'] = $id;        $where['type'] = $type;        $info = Dever::db('act/share')->one($where);        if (!$info) {            $where['num'] = 1;            Dever::db('act/share')->insert($where);        } else {            $where['num'] = $info['num'] + 1;            $where['where_id'] = $info['id'];            Dever::db('act/share')->update($where);        }        Dever::score($uid, 'share_friend', '邀请好友');        return true;    }    # 回流    public function submit_reflux($source_uid, $uid, $id, $type)    {        $where['source_uid'] = $source_uid;        $where['uid'] = $uid;        if ($where['source_uid'] == $where['uid']) {            //return false;        }        $where['data_id'] = $id;        $where['type'] = $type;        $share = Dever::db('act/share')->one($where);        if ($share) {            $user = Dever::db('passport/user')->one($uid);            $where['user_type'] = 3;            //if ($user['temp'] == 2 || $user['bind'] == 1) {            if ($user) {                # 必须是已经绑定手机号或者授权用户才可以增加积分                # 新用户 增加邀请关系                if (Dever::project('invite')) {                    $parent = Dever::load('invite/api')->getParent($uid, $level = 1);                    if (!$parent) {                        # 新用户                        $where['user_type'] = 1;                        Dever::load('invite/api')->setRelation($uid, $source_uid);                    } else {                        # 老用户                        $where['user_type'] = 2;                                            }                }                if ($type <= 4) {                    $method = '';                    $name = Dever::config('base')->type[$type];                    if ($type == 1) {                        $method = 'article';                    }                    if ($type == 2) {                        $method = 'vod';                    }                    if ($type == 3) {                        $method = 'live';                    }                    if ($type == 4) {                        $method = 'journal';                    }                    # 增加积分                    if ($where['user_type'] == 1) {                        $score = 0;                        if ($type == 4) {                            $active = Dever::db('journal/active')->one(array('id' => $id));                            if ($active && $active['status'] == 1 && time() <= $active['end']) {                                $score = $active['invite_score'];                            }                        }                        Dever::score($source_uid, 'share_'.$method.'_new_reflux', '通过'.$name.'邀请到新用户', 'act/lib/score.submit?method=share&type='.$type.'&id=' . $id, $score);                        # 插入到邀请列表里                        Dever::load('act/lib/invite')->submit($source_uid, $uid, $id, $type);                        # 小刊订阅                        if ($type == 4) {                            if (isset($active) && $active) {                                $num = $active['invite_num'];                                $invite_num = Dever::load('act/lib/invite')->getTotal($source_uid, $id, $type);                                if ($invite_num >= $num) {                                    Dever::load('act/lib/subscribe')->submit($source_uid, $id, 3);                                }                            }                        }                                            } elseif ($where['user_type'] == 2) {                        Dever::score($source_uid, 'share_'.$method.'_reflux', '通过'.$name.'邀请到老用户');                    }                }            }            $where['share_id'] = $share['id'];            $info = Dever::db('act/share_reflux')->one($where);            if (!$info) {                Dever::db('act/share_reflux')->insert($where);                return true;            }        }        return false;    }}
 |