| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- <?php
- namespace App\Modes;
- use Illuminate\Database\Eloquent\Model;
- /**
- * App\Modes\AccountLog
- *
- * @property int $id
- * @property int $uid 用户ID
- * @property int $source_uid 来源用户id
- * @property int $type 记录类型 0-未知 1-提现 2-转账点币-收入 3-转账点币-支出 4-提现 5-佣金 6-广告业绩 10-直推(广告代理费分佣) 11-间一(广告代理费分佣) 12-间二(广告代理费分佣)13-全局(广告代理费分佣) 20-直推(推广代理费分佣) 21-间一(推广代理费分佣) 22-间二(推广代理费分佣)23-全局(推广代理费分佣) 10? 对应订单类型
- * @property int $status 状态 0-未生效 1-成功 2-失效
- * @property int $money_type 1-点币 2-RMB
- * @property float $money 金额(收入为正,支出为负)
- * @property int $current_money 当前用户余额
- * @property string $remark 备注
- * @property \Illuminate\Support\Carbon $created_at
- * @property \Illuminate\Support\Carbon $updated_at
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog newModelQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog newQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog query()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereCreatedAt($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereCurrentMoney($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereId($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereMoney($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereMoneyType($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereRemark($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereSourceUid($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereStatus($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereType($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereUid($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\AccountLog whereUpdatedAt($value)
- * @mixin \Eloquent
- */
- class AccountLog extends Model
- {
- protected $table = 'account_log';
- //
- /**
- * 保存账号流水
- * @author lyh
- * @date 2019/3/25
- * @param int $type 记录类型 0-未知 1-提现 2-转账点币-收入 3-转账点币-支出 4-提现 5-佣金
- * @param int $money 金额
- * @param int $source_id 来源
- * @param int $money_type 类型 1-点币 2-RMB
- * @param int $status
- * @description
- */
- public static function saveData($type = 0, $money = 0, $source_id = 0, $money_type = 2, $status = 1, $remark = '')
- {
- AccountLog::insertGetId([
- 'uid' => \Auth::id(),
- 'source_uid' => $source_id,
- 'type' => $type,
- 'status' => $status,
- 'money_type' => $money_type,
- 'money' => $money,
- 'current_money' => self::getCurentMoney($type),
- 'remark' => $remark
- ]);
- }
- public static function saveDataByPost($uid,$type = 0, $money = 0,$current_money, $money_type = 2, $status = 1, $remark = '',$source_uid=0)
- {
- AccountLog::insert([
- 'uid' => $uid,
- 'source_uid' => $source_uid,
- 'type' => $type,
- 'status' => $status,
- 'money_type' => $money_type,
- 'money' => $money,
- 'current_money' => $current_money,
- 'remark' => $remark
- ]);
- }
- /*
- * 获取收益addby wsl
- * ids array 用户id
- *
- * */
- public static function getShouYi($ids,$starttime,$endtime){
- //$starttime='2019-06-01';
- //$endtime='2019-06-28 15:45:50';
- $list=AccountLog::whereIn('type',[5, 10, 11, 12, 13, 20, 21, 22, 23])->where('uid','=',\Auth::id())->whereIn('source_uid',$ids)->whereBetween('created_at',[$starttime,$endtime])->get();
- $count=0;
- $sum=0;
- $gguser=[];
- $dluser=[];
- $ggsum=0;
- $dlsum=0;
- if(!empty($list)){
- foreach($list as $key=>$value){
- $count++;
- $sum+=$value->money;
- if(strpos($value->remark,'广告')==true){
- if(!in_array($value->uid,$gguser)){
- $gguser[]=$value->uid;
- }
- $ggsum+=$value->money;
- }else{
- if(!in_array($value->uid,$dluser)){
- $dluser[]=$value->uid;
- }
- $dlsum+=$value->money;
- }
- }
- }
- $arr=[
- 'uv' => $count, // 代理收益次数
- 'earnings' => round($sum,3),// 总收益
- 'inviteNum' => count($ids), // 下级代理数量
- 'proxyNum' => count($dluser), // 代理数量
- 'proxyMoney' => round($dlsum,3), // 代理收益
- 'adverNum' => count($gguser), // 广告数量
- 'adverMoney' => round($ggsum,3), // 广告收益
- ];
- return $arr;
- }
- /**
- * 获取当前账号余额
- * @author lyh
- * @date 2019/3/25
- * @param int $type
- * @description
- */
- private static function getCurentMoney(int $type)
- {
- $user = User::find(\Auth::id());
- if ($type = 1) {
- return $user->coin;
- } else {
- return $user->balance;
- }
- }
- /**
- * 获取金额
- * @author lyh
- * @date 2019/3/25
- * @param $id
- * @param array $array
- * @return mixed
- * @description
- */
- public static function getSumMoney($id, array $array, $where = [])
- {
- $res = AccountLog::whereUid($id)
- ->whereStatus(1)
- ->whereIn('type', $array);
- if (!empty($where)) {
- $res->where($where);
- }
- return $res->sum('money');
- }
- /**
- * 统计次数
- * @author lyh
- * @date 2019/3/25
- * @param $id
- * @param array $array
- * @return mixed
- * @description
- */
- public static function getUv($id, array $array, $start_time, $end_time, $where = [])
- {
- $res = AccountLog::whereStatus(1)
- ->whereIn('uid', $id)
- ->whereIn('type', $array);
- if (!empty($where)) {
- $res->where($where);
- }
- if ($start_time != null && $end_time != null) {
- $res->whereBetween('created_at', [$start_time, $end_time]);
- }
- return $res->count('id');
- }
- /**
- * 业绩
- * @author lyh
- * @date 2019/3/26
- * @param int $id
- * @param array $type
- * @param string $start
- * @param string $end
- * @description
- */
- public static function getBusinessGoal(int $id, array $type, $start, $end)
- {
- return AccountLog::whereStatus(1)
- ->whereIn('uid', User::getAllInvite($id))
- ->whereBetween('created_at', [$start, $end])
- ->whereIn('type', $type)
- ->sum('money');
- }
- /**
- * 获取收益
- * @author lyh
- * @date 2019/3/27
- * @param array $id
- * @param array $type
- * @param $start_time
- * @param $end_time
- * @return int
- * @description
- */
- public static function getEarngings(array $id, array $type, $start_time, $end_time)
- {
- $res = AccountLog::whereStatus(1)
- ->whereIn('uid', $id)
- ->whereIn('type', $type);
- if (!empty($where)) {
- $res->where($where);
- }
- if ($start_time != null && $end_time != null) {
- $res->whereBetween('created_at', [$start_time, $end_time]);
- }
- return $res->sum('money');
- }
- /**
- * 获取带来收益用户数
- * @author lyh
- * @date 2019/3/27
- * @param array $ids
- * @param array $array
- * @param $start_time
- * @param $end_time
- * @param array $ids1
- * @return int
- * @description
- */
- public static function getInviteUv(array $ids, array $array, $start_time, $end_time, array $ids1)
- {
- $res = AccountLog::whereStatus(1)
- ->whereIn('uid', $ids)
- ->groupBy('uid')
- ->whereIn('type', $array);
- if (!empty($where)) {
- $res->where($where);
- }
- if ($start_time != null && $end_time != null) {
- $res->whereBetween('created_at', [$start_time, $end_time]);
- }
- return $res->count('uid');
- }
- /**
- * @author lyh
- * @date 2019/4/12
- * @param int $type
- * @description
- * 0-未知 1-提现 2-转账点币-收入 3-转账点币-支出 4-提现 5-佣金 6-广告业绩 7-升级交费 10-直推(广告代理费分佣) 11-间一(广告代理费分佣) 12-间二(广告代理费分佣)13-全局(广告代理费分佣) 20-直推(推广代理费分佣) 21-间一(推广代理费分佣) 22-间二(推广代理费分佣)23-全局(推广代理费分佣)30-点币转账-收入 31-点币转账-支出 32-点币购买 10? 对应订单类型
- */
- public static function getTypeMsg(int $type)
- {
- $msg = [
- 1 => '提现',
- 2 => '转账点币-收入',
- 3 => '转账点币-支出',
- 4 => '提现',
- 5 => '佣金',
- 6 => '广告业绩',
- 7 => '升级交费',
- 10 => '直推(广告代理费分佣)',
- 11 => '间一(广告代理费分佣)',
- 12 => '间二(广告代理费分佣)',
- 13 => '全局(广告代理费分佣)',
- 20 => '直推(推广代理费分佣)',
- 21 => '间一(推广代理费分佣)',
- 22 => '间二(推广代理费分佣)',
- 23 => '全局(推广代理费分佣)',
- 30 => '点币转账-收入',
- 31 => '点币转账-支出',
- 32 => '点币购买',
- 101 => '升级支付',
- 102 => '购买广告支付',
- 103 > '点币购买',
- ];
- if (in_array($type, $msg)) {
- return $msg[$type];
- }
- return '';
- }
- }
|