| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Modes\AccountLog;
- use App\Modes\BusinessGoal;
- use App\Modes\Config;
- use App\Modes\Proxy;
- use App\Modes\Slider;
- use App\Modes\User;
- use App\Modes\Order;
- use App\Rules\Phone;
- use Carbon\Carbon;
- use Encore\Admin\Form\Field\Date;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- class HomeController extends Controller
- {
- /**
- * 获取收益
- * @author lyh
- * @date 2019/3/27
- * @param $uid
- * @param $start_time
- * @param $end_timel
- * @return mixed
- * @description
- * * 'uv' => $resItem['uv'], // pv代理收益次数
- * 'earnings' => $resItem['earnings'],// 总收益
- * 'inviteNum' => $resItem['proxyNum'], // 下级代理数量
- * 'proxyNum' => $resItem['proxyNum'], // 代理数量
- * 'proxyMoney' => $resItem['proxyMoney'], // 代理收益
- * 'adverNum' => $resItem['adverNum'], // 广告数量
- * 'adverMoney' => $resItem['adverMoney'] // 广告收益
- */
- private static function getEarnings($uid, $start_time, $end_time)
- {
- if (\Cache::has('getEarnings' . $start_time)) {
- return \Cache::get('getEarnings' . $start_time);
- }
- $type = [10, 11, 12, 13, 20, 21, 22, 23];
- \DB::connection()->enableQueryLog();
- $ids = User::getAllInvite($uid, null, $end_time, false);
- $inviteNum = count($ids);
- $uv = AccountLog::getUv($ids, $type, $start_time, $end_time);
- $earnings = AccountLog::getEarngings($ids, $type, $start_time, $end_time);
- $proxyNum = AccountLog::getInviteUv($ids, [20, 21, 22, 23], $start_time, $end_time, $ids);
- $proxyMoney = AccountLog::getEarngings($ids, [20, 21, 22, 23], $start_time, $end_time);
- $adverNum = AccountLog::getInviteUv($ids, [10, 11, 12, 13], $start_time, $end_time, $ids);
- $adverMoney = AccountLog::getEarngings($ids, [10, 11, 12, 13], $start_time, $end_time);
- $res = [
- 'uv' => $uv,
- 'earnings' => $earnings,
- 'inviteNum' => $inviteNum,
- 'proxyNum' => $proxyNum,
- 'proxyMoney' => $proxyMoney,
- 'adverNum' => $adverNum,
- 'adverMoney' => $adverMoney,
- 'uid' => $ids
- ];
- if (strtotime($start_time) + 86400 * 31 < time()) {
- \Cache::put('getEarnings' . $start_time, $res, 3600);
- }
- return $res;
- }
- public function getSms(Request $request)
- {
- $validator = \Validator::make($param = $request->post(), [
- 'mobile' => [
- 'required',
- // 'string',
- 'regex:/^[1][3,4,5,6,7,8,9][0-9]{9}$/',
- new Phone()
- ],
- 'type' => 'required|between:1,10'
- ]);
- if ($validator->fails()) {
- return showJson(102, $validator->errors()->first());
- }
- //检测用户的mobile是否存在
- if(!empty($param['send_type'])&&$param['send_type']>0){
- $user = User::whereMobile($param['mobile'])->first();
- if(empty($user) && $param['send_type']==1)return showJson('102','用户不存在,请扫码注册后再登录');
- if(empty($user) && $param['send_type']==2)return showJson('102','手机号不存在,请重新输入');
- }
- // var_dump('6666666666');exit;
- $smsProvider = \App::make('sms');
- $sms = $smsProvider->getSms($param['mobile'], 0);
- if ($sms == false) {
- return showJson(102, '获取短信验证码失败');
- }
- return showJsonSucc('获取验证码成功,请注意查收', [
- // 'sms' => $sms,
- ]);
- }
- /**
- * 收益记录
- * @author lyh
- * @date 2019/3/26
- * @description
- * 代理收益次数
- * 总收益
- * 下级代理数量
- * N 个 带来代理佣金总额
- * N 个 带来广告佣金收益总额
- */
- public function statistics(Request $request)
- {
- $res = [];
- $year = $request->post('year', 0);
- if ($year < 2018 && $year > 2040) {
- return showJsonErr('请选择查询的年份');
- }
- $month = $request->post('month', '');
- $day = $request->post('day', '');
-
- if (!empty($day)) {
- $time = [
- 'date' => "{$year}-{$month}-{$day}",
- 'start_time' => Carbon::create($year, $month, $day)->startOfDay(),
- 'end_time' => Carbon::create($year, $month, $day)->endOfDay()
- ];
- //获取下级总人数
- $chidsarr=User::getAllChilds(\Auth::id(),$time['end_time']);
- $resItem=AccountLog::getShouYi($chidsarr,$time['start_time'],$time['end_time']);
- $resItem['month']=$time['date'];
- $res[]=$resItem;
- return showJsonSucc(1001, $res);
- }
- //月
- if (!empty($month)) {
- $time = [
- 'date' => "{$year}-{$month}",
- 'start_time' => Carbon::create($year, $month)->firstOfMonth(),
- 'end_time' => Carbon::create($year, $month)->endOfMonth()
- ];
- //获取下级总人数
- $chidsarr=User::getAllChilds(\Auth::id(),$time['end_time']);
- $resItem=AccountLog::getShouYi($chidsarr,$time['start_time'],$time['end_time']);
- $resItem['month']=$time['date'];
- $res[]=$resItem;
- return showJsonSucc(1001, $res);
- }
- //年
- $time = [];
- $monthcoun=intval(date('m'));
- $curyear=intval(date('Y'));
- if($year<$curyear)$monthcoun=12;
- for ($i = 1; $i <= $monthcoun; $i++) {
- $time[] = [
- 'date' => "{$year}-{$i}",
- 'start_time' => Carbon::create($year, $i)->firstOfMonth(),
- 'end_time' => Carbon::create($year, $i)->subMonth(-1)->firstOfMonth()->subSecond(1)
- ];
- }
- //年
- foreach ($time as $item) {
- //获取下级总人数
- //$item['end_time']=date('Y-m-d H:i:S');
- //$item['start_time']='2019-07-01';
- $chidsarr=User::getAllChilds(\Auth::id(),$item['end_time']);
- $resItem=AccountLog::getShouYi($chidsarr,$item['start_time'],$item['end_time']);
- $resItem['month']=Carbon::instance($item['start_time'])->month;
- $res[]=$resItem;
- }
- return showJsonSucc(1001, $res);
- }
- /**
- * 任务进度轴
- * @author lyh
- * @date 2019/3/26
- * @description
- * edit by wsl
- * 20190628
- *
- */
- public function progress()
- {
- $goal = BusinessGoal::whereUid(\Auth::id())->orderByDesc('id')->paginate(perPage());
- //根据用户等级找到相关配置
- $userinfo=User::whereId(\Auth::id())->first()->toArray();
- if($userinfo['level']==7){
- $levels=7;
- }else $levels=$userinfo['level']+1;
- $setting=Proxy::getSettingByAreaAndLevel($levels,$userinfo['province'],$userinfo['city'],$userinfo['district']);
-
- //计算当月达到的任务量
- $tasks=$this->getCurTask($userinfo['id']);
- $goal = BusinessGoal::whereUid(\Auth::id())->orderByDesc('id')->paginate(perPage());
- $month = [];
- if ($goal->currentPage() == 1) {
- $month = [
- 'time' => date('Y-m'),
- 'goal' => $setting['upgrade_business_month'],
- 'actual' => round($tasks['month'],3),
- ];
- }
- return showJsonSucc(1001, [
- 'goal' => $setting['upgrade_business_year'], // 当前年度目标业绩
- 'actual' => round($tasks['year'],3),
- 'currentMonth' => $month,
- 'month' => $goal
- ]);
- }
- public function slider(){
- $data = Slider::orderBy('sort','desc')->get();
- collect($data)->each(function ($item, $key) {
- $item->img = \Storage::disk('api')->url($item->img);
- // $item->img = $item->url;
- });
- return showJsonSucc(1001, $data);
- }
- //计算年和月的任务总量,addbywsl,20190628
- function getCurTask($uid){
- $childarr=User::where('invitor','=',$uid)->get(['id']);
- $childarr=$childarr->toArray();
- $arr=[];
- if(!empty($childarr)){
- foreach ($childarr as $ke=>$ve){
- $arr[]=$ve['id'];
- }
- }
- // dd($arr);
- $montstat=Order::getMonthOrYearStat($uid,$arr,'month');
- $yearstat=Order::getMonthOrYearStat($uid,$arr,'year');
- return ['month'=>$montstat,'year'=>$yearstat];
- }
- }
|