123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\IncomExpenses;
- use App\Models\Infos;
- use App\Models\Message;
- use App\Models\Order;
- use App\Models\OrderGoods;
- use App\Models\Picture;
- use App\Models\Question;
- use App\Models\System;
- use App\Models\User;
- use App\Models\UserW;
- use App\Models\Version;
- use App\Models\VideoInfo;
- use App\Models\WechatNotice;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\DB;
- use App\Models\Article;
- use App\Models\ArticleLike;
- use Illuminate\Support\Facades\Log;
- class BasicController extends Controller{
- /**公告**/
- public function GetNoticeList(Request $request){
- $page_index=$request->input('page_index');
- $page_size=$request->input('page_size');
- $re=WechatNotice::query();
- $count=$re->count();
- $re=$re->orderByDesc('is_top')->orderByDesc('created_at')
- ->select('title','time','id','cover','description','is_top')
- ->take($page_size)
- ->skip(($page_index-1)*$page_size)
- ->get();
- return $this->success_list($re,'',$count);
- }
- public function WeChatNotice(Request $request){
- $id=$request->input('id');
- $text=WechatNotice::find($id);
- return $this->success($text);
- }
- public function question(Request $request){
- $user=Auth::user();
- $question=new Question();
- $question->user_id=$user->id;
- $question->contents=$request->feedback;
- $question->status=0;
- $question->save();
- return $this->success();
- }
- /*----消息通知----*/
- public function message(){
- $id=Auth::user()->id;
- // $system=Message::where('type',1)->where('status',0)->get();
- $system_data=[];
- // foreach ($system as $k=>$v){
- // $system_data[$k]['title']=$v->title;
- // $system_data[$k]['id']=$v->id;
- // $system_data[$k]['time']=strtotime($v->created_at)*1000;
- // $system_data[$k]['message']=$v->data;
- // $system_data[$k]['url']=$v->url==null?'':$v->url;
- // }
- $myorder=Message::where('type',2)->where('status',0)->where('user_id',$id)->get();
- $myorder_data=[];
- foreach ($myorder as $k=>$v){
- $myorder_data[$k]['order_num']=$v->order_num;
- $myorder_data[$k]['id']=$v->id;
- $myorder_data[$k]['status']=$v->order_status;
- $myorder_data[$k]['time']=strtotime($v->created_at)*1000;
- $myorder_data[$k]['goodList']=json_decode($v->data);
- // Log::error('{----消息-----}'.json_decode($v->data));
- }
- $downOrder=Message::where('type',3)->where('agent_status',0)->where('agent_id',$id)->get();
- $downOrder_data=[];
- foreach ($downOrder as $k=>$v){
- $downOrder_data[$k]['order_num']=$v->order_num;
- $downOrder_data[$k]['id']=$v->id;
- $downOrder_data[$k]['price']=$v->price;
- $downOrder_data[$k]['time']=strtotime($v->created_at)*1000;
- $downOrder_data[$k]['phone']=$v->mobile;
- $downOrder_data[$k]['nickname']=$v->nickname;
- }
- return $this->success(['system'=>$system_data,'myOrder'=>$myorder_data,'downOrder'=>$downOrder_data]);
- }
- /*--处理数据-*/
- public function data($data,$type){
- $total=$data->toArray();
- $da=[];
- foreach ($data as $k=>$v){
- if ($v->type==0){
- $da[$k]['title']=$v->title;
- $da[$k]['message']=$v->data;
- $da[$k]['time']=$v->title;
- $da[$k]['title']=$v->title;
- }
- }
- }
- /*移出消息*/
- public function message_read(Request $request){
- $id=Auth::user()->id;
- if ($request->type==1){
- Message::where('user_id',$id)->update(["status"=>1]);
- }else if ($request->type==2){
- Message::where('user_id',$id)->update(["status"=>1]);
- } else{
- $id='agent_id';
- $type='agent_status';
- Message::where('agent_id',$id)->update(["$type"=>1]);
- }
- return $this->success([]);
- }
- public function charts(Request $request){
- // $dates = Carbon::now()->addDay('-1')->startOfDay()->format('Y-m-d H:i:s');
- $user=Auth::user();
- $day=$request->day;
- $data=[];
- $date=[];
- for ($i=$day-1;$i>=0;$i--){
- $par='-'.$i;
- $start=Carbon::now()->addDay($par)->startOfDay()->format('Y-m-d H:i:s');
- $end=Carbon::now()->addDay($par)->endOfDay()->format('Y-m-d H:i:s');
- $date[].= Carbon::now()->addDay($par)->format('m/d');
- if ($request->type==0){
- $re=Order::where('user_id',$user->id)->where('turn_is',0)->whereBetween('created_at',[$start,$end])->get();
- $num=0;
- foreach ($re as $k=>$v){
- $nums=OrderGoods::where('order_id',$v->id)->sum('num');
- $num=$num+$nums;
- }
- $data[].=$num;
- }elseif($request ->type==1){
- $num=User::where('agent_id',$user->id)->where('status',0)->where('cert_status',6)->whereBetween('created_at',[$start,$end])->count();
- $data[].=$num;
- }elseif ($request->type==2){
- $money=IncomExpenses::where('user_id',$user->id)->whereBetween('created_at',[$start,$end])->sum('totalprice');
- $data[].=$money;
- }
- }
- $s['date']=$date;
- $s['data']=$data;
- return $this->success($s);
- }
- /*-----首页-------*/
- public function index(){
- $picture=Picture::where('status',0)->where('classify',1)->get();
- $news=Infos::where('disabled',0)->get();
- $data=Article::where('label','=','1')->where('status',1)->orderByDesc('created_at')->first();
- $re=[];
- if ($data){
- $re['id']=$data->id;
- $re['title']=$data->title;
- $re['type']=$data->type;
- $re['off']=1;
- $re['avatar'] = 'https://api.jiuweiyun.cn/public/uploads/images/topics/916.jpg';
- $re['summary']=$data->summary;
- $re['author']=$data->author;
- $re['contents']=$data->contents;
- $re['created_at']=strtotime($data->created_at)*1000;
- $re['like_num']=$data->like;
- // $re['imgurl']=json_encode($data->imgurl);
- $re['imgurl']=[$data->imgurl];
- $re['like']=(ArticleLike::where('uid',Auth::user()->id)->where('article_id',$data->id)->value('like'))==1?true:false;
- $re['collection']=(ArticleLike::where('uid',Auth::user()->id)->where('article_id',$data->id)->value('collection'))==1?true:false;
- }
- $s=['swiper'=>$picture,'news'=>$news,'article'=>$re];
- return $this->success($s);
- }
- public function version(){
- $data=Version::where('status',0)->first();
- $re['version']=$data->version;
- $re['message']=$data->message;
- $re['url']=$data->url;
- return $this->success($re);
- }
- public function system(){
- $data=System::get();
- foreach ($data as $k=>$v){
- $re[$v->keys]=$v->values;
- }
- return $re;
- }
- public function wechat_data(Request $request){
- $data=$request->all();
- Log::error('{----------}'.json_encode($data));
- return $data['echostr'];
- }
- public function token(Request $request){
- if ($request->client_id=='daweiboshi'){
- if ($request->secret=='fb1a8b61130a'){
- $user=User::find(1);
- $token=Auth::guard()->fromUser($user);
- return $this->success(['token'=>$token]);
- }
- }
- return $this->error(400);
- }
- public function wechat(Request $request){
- $user=Auth::user();
- // Log::error('{---weixin-----}'.$user->mobile);
- // Log::error('{---weixin-----}'.time());
- // $url='http://api.app.cliu.cc/api/gzh/'.urlencode($user->nickname).'/'.urlencode($user->mobile).'/'.urlencode($user->recom_code);
- // $url='http://api.app.cliu.cc/api/gzh/'.urlencode($user->nickname).'/'.urlencode($user->mobile).'/'.urlencode($user->recom_code).'/'.time();
- // $url='http://api.woaidakele.cn/api/gzh?id='.$user->id;
- $url='http://api.app.cliu.cc/api/gzh?id='.$user->id;
- $app=app('wechat.official_account');
- $app->jssdk->setUrl($url);
- $arr=$app->jssdk->buildConfig(array('updateAppMessageShareData', 'updateTimelineShareData'), false);
- Log::error($arr);
- return $arr;
- }
- public function wechats(Request $request){
- $app=app('wechat.official_account');
- $url='http://api.app.cliu.cc/api/gzhtest';
- $app->jssdk->setUrl($url);
- $arr=$app->jssdk->buildConfig(array('scanQRCode'), true);
- Log::error($arr);
- return $arr;
- }
- public function return_code(){
- $app=app('wechat.official_account');
- $arr=$app->jssdk->buildConfig(array('updateAppMessageShareData', 'updateTimelineShareData'), true);
- // Log::error($arr);
- return $arr;
- }
- public function get_user_re(Request $request){
- $user=User::find($request->id);
- $area_code=null;
- if($request->has('user_id')){
- $customer=UserW::find($request->user_id);
- if($customer){
- $customer_mobile=$customer->phone;
- $area_code=$customer->area_code;
- }else{
- $customer_mobile=null;
- }
- }else{
- $customer_mobile=null;
- }
- if ($user){
- if ($user->deleted_at){
- return $this->error(500214,'','该代理已被删除');
- }
- }
- $status=false;
- // if (Carbon::now()>'2022-03-18 09:00:00'){
- // $status=true;
- // }
- if(empty($area_code)){
- $area_code='+86';
- }
- $arr=['nickname'=>$user->nickname,
- 'recom_code'=>$user->recom_code,
- 'mobile'=>$user->mobile,
- 'system_status'=>$status,
- 'customer_mobile'=>$customer_mobile,
- 'area_code'=>$area_code];
- // return $this->success(['nickname'=>$user->nickname,'recom_code'=>$user->recom_code,'mobile'=>$user->mobile,'system_status'=>$status]);
- return $this->success($arr);
- }
- public function GetVRLink(){
- return $this->success([
- 'vr_link'=>System::where('keys','vr_glory_link')->value('values'),
- 'appraise_service_url'=>System::where('keys','appraise_service_url')->value('values'),
- ]);
- }
- public function GetVideoList(){
- return $this->success(VideoInfo::where('status',0)->where('type',0)->orderBy('sort')->orderBy('id')->get());
- }
- }
|