| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <?php
- namespace App\Modes;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Model;
- /**
- * App\Modes\Upgrade
- *
- * @property int $id
- * @property int|null $uid 会员ID
- * @property int $order_id 订单id
- * @property int $user_level 等级(user_level.id)
- * @property int $apply_level 申请等级(user_level.id)
- * @property float $money 费用
- * @property int $status 状态 1-未支付 2-待审核 3-完成 4-支付失败 5-审核拒绝 9-失效
- * @property string|null $remark 备注
- * @property \Illuminate\Support\Carbon $created_at
- * @property \Illuminate\Support\Carbon $updated_at
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade newModelQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade newQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade query()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereApplyLevel($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereCreatedAt($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereId($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereMoney($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereOrderId($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereRemark($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereStatus($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereUid($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereUpdatedAt($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereUserLevel($value)
- * @mixin \Eloquent
- * @property int $province 申请代理省份(area.id)
- * @property int $city 申请代理市(area.id)
- * @property int $district 申请代理区(area.id)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereCity($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereDistrict($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereProvince($value)
- * @property int $upgrade_way 升级方式 1-交费 2-月任务量达标 3-年任务量达标 4-推荐量达标
- * @property-read \App\Modes\User $User
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Upgrade whereUpgradeWay($value)
- */
- class Upgrade extends Model
- {
- protected $table = 'upgrade';
- /**
- * 获取代理费
- * @author lyh
- * @date 2019/3/25
- * @param int $applyLevel 申请等级
- * @param int int $id 当前用户
- * @description
- * 该处算法:
- * 第一优先为高级别代理费-用户当前级别代理费(即便用户为非交费升级)
- */
- public static function getCost($applyLevel, User $user)
- {
- // 获取高级别代理费
- $applyConfig = Proxy::getConfig($user->id, $user->province, $user->city, $user->district, $applyLevel);
- // 获取当前级别代理费
- $currentConfig = Proxy::getConfig($user->id, $user->province, $user->city, $user->district);
- return round($applyConfig->upgrade_money - $currentConfig->upgrade_money, 2);
- }
- /**
- * 支付确认升级处理
- * @author lyh
- * @date 2019/3/25
- * @param $out_trade_no
- * @description
- * 支付确认之后审核
- */
- public static function updateByPay($out_trade_no)
- {
- $order = Order::whereOrderNo($out_trade_no)->first();
- $upgrade = Upgrade::whereOrderId($order->id)->first();
- $updateRes = Upgrade::whereOrderId($order->id)->update(['status' => 2]);
- if (empty($updateRes)) {
- ErrorLog::saveMsg("订单[{$order->id}]确认支付保存失败");
- }
- $userUpData = ['level' => $upgrade->apply_level];
- // if ($upgrade->apply_level == 6 || $upgrade->apply_level == 7) {
- // User::whereId($order->uid)->update($userUpData);
- // }
- }
- /**
- * 判断是否达到升级条件
- * @author lyh
- * @date 2019/3/25
- * @param int $id
- * @description
- * 业务累积/任务-万
- *B 一月0.4/,2/年
- *C 一月1/年5
- *D 一月2/年10
- *E 一月10/年50
- *F 一月30/年100
- *G 一月50/年200
- *业务累积:统计自身以及两层下级(直推+间一+间二)的合计代理费业绩以及广告业务业绩总额达到升级额度。
- */
- public static function condition(int $id)
- {
- $resData = [];
- $user = User::find($id);
-
- $is = true;
- // 查看是否达到 B 级要求
- if ($user->level < 2) {
- $resData[] = [
- 'level' => 2,
- 'required' => $is = self::requierdLevel(2, $id) ? true : false
- ];
- }
- // 查看是否达到 C 级要求 并且已经满足下一级的升级要求
- if ($user->level < 3 && $is == true) {
- $resData[] = [
- 'level' => 3,
- 'required' => $is = self::requierdLevel(3, $id) ? true : false
- ];
- }
- // 查看是否达到 D 级要求
- if ($user->level < 4 && $is == true) {
- $resData[] = [
- 'level' => 4,
- 'required' => $is = self::requierdLevel(4, $id) ? true : false
- ];
- }
- // 查看是否达到 E 级要求
- if ($user->level < 5 && $is == true) {
- $resData[] = [
- 'level' => 5,
- 'required' => $is = self::requierdLevel(5, $id) ? true : false
- ];
- }
- // 查看是否达到 F 级要求
- if ($user->level < 6 && $is == true) {
- $resData[] = [
- 'level' => 6,
- 'required' => $is = self::requierdLevel(6, $id) ? true : false
- ];
- }
- // 查看是否达到 G 级要求
- if ($user->level < 7 && $is == true) {
- $resData[] = [
- 'level' => 7,
- 'required' => $is = self::requierdLevel(7, $id) ? true : false
- ];
- }
- return $resData;
- }
- /**
- * 查询是否升级达到要求
- * @author lyh
- * @date 2019/3/25
- * @param int $level 申请等级
- * @description
- * 业务累积/任务-万
- *B 一月0.4/,2/年
- *C 一月1/年5
- *D 一月2/年10
- *E 一月10/年50
- *F 一月30/年100
- *G 一月50/年200
- *业务累积:升级任务量:直推投放广告交费+自己投放广告交费+自己所交代理费+自己点币充值费
- */
- public static function requierdLevel(int $level, $uid)
- {
- $config = Proxy::getConfig($uid, null, null, null, $level);
-
- if (empty($config)) {
- return false;
- }
- // 自身以及两层下级id
- $ids = User::getAllInvite($uid);
- // 判断月业务累计是否达到要求
- //获取本月开始时间和结束时间
- $monthStart = Carbon::now()->firstOfMonth();
- $monthEnd = Carbon::now()->subMonth(-1)->firstOfMonth();
-
- $monthData = User::get_business_goal($uid,$monthStart,$monthEnd);
-
- // if ($monthData > $config->upgrade_business_month && $config->upgrade_business_month > 0 ) {
- // return 2;
- // }
- if ($monthData > $config->upgrade_business_month ) {
- return 2;
- }
- // 判断年业务累计是否达到要求
- $yearStart = Carbon::now()->firstOfYear();
- $yearEnd = Carbon::now()->subYear(-1)->firstOfYear();
- $yearData = User::get_business_goal($uid,$yearStart,$yearEnd);
- // if ($yearData > $config->upgrade_business_year && $config->upgrade_business_year > 0) {
- // return 3;
- // }
- if ($yearData > $config->upgrade_business_year) {
- return 3;
- }
- //靠推荐量升级
- $user = User::find($uid);
-
- $inviteNum = User::whereInvitor($uid)->count('id');
- if (!empty(intval($config->upgrade_invite)) && $inviteNum >= $config->upgrade_invite) {
-
- return 4;
- }
-
- return false;
- }
- /**
- * h
- * @author lyh
- * @date 2019/4/3
- * @param $where
- * @param $field
- * @param $userField
- * @description
- */
- public static function getList($where, $field = [], $userField = [])
- {
- $userField = array_merge(['id', 'mobile', 'nick_name', 'real_name'], $userField);
- $field = array_merge(['id', 'uid', 'order_id', 'money', 'status', 'created_at'], $field);
- $upgrade = Upgrade::where($where);
- if (\Auth::user()->is_super == 3) {
- $upgrade = $upgrade->whereIn('uid', getIds());
- }
- $upgrade = $upgrade->select($field)
- ->with(['User' => function ($query) use ($userField) {
- $query->select($userField);
- }])
- ->paginate(perPage());
- return $upgrade;
- }
- public function User()
- {
- return $this->hasOne('App\Modes\User', 'id', 'uid');
- }
- /**
- *添加升级记录
- *@author wsl
- * @date 2019-09-10
- * @type 1-区域代理升级
- * @remark 描述
- * @uid 用户id
- */
- public static function addUpgradeLog($type,$remark,$uid){
- $data=[
- 'type' =>$type,
- 'remark' =>$remark,
- 'uid' =>$uid
- ];
- $r=\DB::table('upgrade_log')->insert($data);
- return $r;
- }
- }
|