BasicController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\IncomExpenses;
  4. use App\Models\Infos;
  5. use App\Models\Message;
  6. use App\Models\Order;
  7. use App\Models\OrderGoods;
  8. use App\Models\Picture;
  9. use App\Models\Question;
  10. use App\Models\System;
  11. use App\Models\User;
  12. use App\Models\UserW;
  13. use App\Models\Version;
  14. use App\Models\VideoInfo;
  15. use App\Models\WechatNotice;
  16. use Carbon\Carbon;
  17. use Illuminate\Http\Request;
  18. use Illuminate\Support\Facades\Auth;
  19. use Illuminate\Support\Facades\DB;
  20. use App\Models\Article;
  21. use App\Models\ArticleLike;
  22. use Illuminate\Support\Facades\Log;
  23. class BasicController extends Controller{
  24. /**公告**/
  25. public function GetNoticeList(Request $request){
  26. $page_index=$request->input('page_index');
  27. $page_size=$request->input('page_size');
  28. $re=WechatNotice::query();
  29. $count=$re->count();
  30. $re=$re->orderByDesc('is_top')->orderByDesc('created_at')
  31. ->select('title','time','id','cover','description','is_top')
  32. ->take($page_size)
  33. ->skip(($page_index-1)*$page_size)
  34. ->get();
  35. return $this->success_list($re,'',$count);
  36. }
  37. public function WeChatNotice(Request $request){
  38. $id=$request->input('id');
  39. $text=WechatNotice::find($id);
  40. return $this->success($text);
  41. }
  42. public function question(Request $request){
  43. $user=Auth::user();
  44. $question=new Question();
  45. $question->user_id=$user->id;
  46. $question->contents=$request->feedback;
  47. $question->status=0;
  48. $question->save();
  49. return $this->success();
  50. }
  51. /*----消息通知----*/
  52. public function message(){
  53. $id=Auth::user()->id;
  54. // $system=Message::where('type',1)->where('status',0)->get();
  55. $system_data=[];
  56. // foreach ($system as $k=>$v){
  57. // $system_data[$k]['title']=$v->title;
  58. // $system_data[$k]['id']=$v->id;
  59. // $system_data[$k]['time']=strtotime($v->created_at)*1000;
  60. // $system_data[$k]['message']=$v->data;
  61. // $system_data[$k]['url']=$v->url==null?'':$v->url;
  62. // }
  63. $myorder=Message::where('type',2)->where('status',0)->where('user_id',$id)->get();
  64. $myorder_data=[];
  65. foreach ($myorder as $k=>$v){
  66. $myorder_data[$k]['order_num']=$v->order_num;
  67. $myorder_data[$k]['id']=$v->id;
  68. $myorder_data[$k]['status']=$v->order_status;
  69. $myorder_data[$k]['time']=strtotime($v->created_at)*1000;
  70. $myorder_data[$k]['goodList']=json_decode($v->data);
  71. // Log::error('{----消息-----}'.json_decode($v->data));
  72. }
  73. $downOrder=Message::where('type',3)->where('agent_status',0)->where('agent_id',$id)->get();
  74. $downOrder_data=[];
  75. foreach ($downOrder as $k=>$v){
  76. $downOrder_data[$k]['order_num']=$v->order_num;
  77. $downOrder_data[$k]['id']=$v->id;
  78. $downOrder_data[$k]['price']=$v->price;
  79. $downOrder_data[$k]['time']=strtotime($v->created_at)*1000;
  80. $downOrder_data[$k]['phone']=$v->mobile;
  81. $downOrder_data[$k]['nickname']=$v->nickname;
  82. }
  83. return $this->success(['system'=>$system_data,'myOrder'=>$myorder_data,'downOrder'=>$downOrder_data]);
  84. }
  85. /*--处理数据-*/
  86. public function data($data,$type){
  87. $total=$data->toArray();
  88. $da=[];
  89. foreach ($data as $k=>$v){
  90. if ($v->type==0){
  91. $da[$k]['title']=$v->title;
  92. $da[$k]['message']=$v->data;
  93. $da[$k]['time']=$v->title;
  94. $da[$k]['title']=$v->title;
  95. }
  96. }
  97. }
  98. /*移出消息*/
  99. public function message_read(Request $request){
  100. $id=Auth::user()->id;
  101. if ($request->type==1){
  102. Message::where('user_id',$id)->update(["status"=>1]);
  103. }else if ($request->type==2){
  104. Message::where('user_id',$id)->update(["status"=>1]);
  105. } else{
  106. $id='agent_id';
  107. $type='agent_status';
  108. Message::where('agent_id',$id)->update(["$type"=>1]);
  109. }
  110. return $this->success([]);
  111. }
  112. public function charts(Request $request){
  113. // $dates = Carbon::now()->addDay('-1')->startOfDay()->format('Y-m-d H:i:s');
  114. $user=Auth::user();
  115. $day=$request->day;
  116. $data=[];
  117. $date=[];
  118. for ($i=$day-1;$i>=0;$i--){
  119. $par='-'.$i;
  120. $start=Carbon::now()->addDay($par)->startOfDay()->format('Y-m-d H:i:s');
  121. $end=Carbon::now()->addDay($par)->endOfDay()->format('Y-m-d H:i:s');
  122. $date[].= Carbon::now()->addDay($par)->format('m/d');
  123. if ($request->type==0){
  124. $re=Order::where('user_id',$user->id)->where('turn_is',0)->whereBetween('created_at',[$start,$end])->get();
  125. $num=0;
  126. foreach ($re as $k=>$v){
  127. $nums=OrderGoods::where('order_id',$v->id)->sum('num');
  128. $num=$num+$nums;
  129. }
  130. $data[].=$num;
  131. }elseif($request ->type==1){
  132. $num=User::where('agent_id',$user->id)->where('status',0)->where('cert_status',6)->whereBetween('created_at',[$start,$end])->count();
  133. $data[].=$num;
  134. }elseif ($request->type==2){
  135. $money=IncomExpenses::where('user_id',$user->id)->whereBetween('created_at',[$start,$end])->sum('totalprice');
  136. $data[].=$money;
  137. }
  138. }
  139. $s['date']=$date;
  140. $s['data']=$data;
  141. return $this->success($s);
  142. }
  143. /*-----首页-------*/
  144. public function index(){
  145. $picture=Picture::where('status',0)->where('classify',1)->get();
  146. $news=Infos::where('disabled',0)->get();
  147. $data=Article::where('label','=','1')->where('status',1)->orderByDesc('created_at')->first();
  148. $re=[];
  149. if ($data){
  150. $re['id']=$data->id;
  151. $re['title']=$data->title;
  152. $re['type']=$data->type;
  153. $re['off']=1;
  154. $re['avatar'] = 'https://api.jiuweiyun.cn/public/uploads/images/topics/916.jpg';
  155. $re['summary']=$data->summary;
  156. $re['author']=$data->author;
  157. $re['contents']=$data->contents;
  158. $re['created_at']=strtotime($data->created_at)*1000;
  159. $re['like_num']=$data->like;
  160. // $re['imgurl']=json_encode($data->imgurl);
  161. $re['imgurl']=[$data->imgurl];
  162. $re['like']=(ArticleLike::where('uid',Auth::user()->id)->where('article_id',$data->id)->value('like'))==1?true:false;
  163. $re['collection']=(ArticleLike::where('uid',Auth::user()->id)->where('article_id',$data->id)->value('collection'))==1?true:false;
  164. }
  165. $s=['swiper'=>$picture,'news'=>$news,'article'=>$re];
  166. return $this->success($s);
  167. }
  168. public function version(){
  169. $data=Version::where('status',0)->first();
  170. $re['version']=$data->version;
  171. $re['message']=$data->message;
  172. $re['url']=$data->url;
  173. return $this->success($re);
  174. }
  175. public function system(){
  176. $data=System::get();
  177. foreach ($data as $k=>$v){
  178. $re[$v->keys]=$v->values;
  179. }
  180. return $re;
  181. }
  182. public function wechat_data(Request $request){
  183. $data=$request->all();
  184. Log::error('{----------}'.json_encode($data));
  185. return $data['echostr'];
  186. }
  187. public function token(Request $request){
  188. if ($request->client_id=='daweiboshi'){
  189. if ($request->secret=='fb1a8b61130a'){
  190. $user=User::find(1);
  191. $token=Auth::guard()->fromUser($user);
  192. return $this->success(['token'=>$token]);
  193. }
  194. }
  195. return $this->error(400);
  196. }
  197. public function wechat(Request $request){
  198. $user=Auth::user();
  199. // Log::error('{---weixin-----}'.$user->mobile);
  200. // Log::error('{---weixin-----}'.time());
  201. // $url='http://api.app.cliu.cc/api/gzh/'.urlencode($user->nickname).'/'.urlencode($user->mobile).'/'.urlencode($user->recom_code);
  202. // $url='http://api.app.cliu.cc/api/gzh/'.urlencode($user->nickname).'/'.urlencode($user->mobile).'/'.urlencode($user->recom_code).'/'.time();
  203. // $url='http://api.woaidakele.cn/api/gzh?id='.$user->id;
  204. $url='http://api.app.cliu.cc/api/gzh?id='.$user->id;
  205. $app=app('wechat.official_account');
  206. $app->jssdk->setUrl($url);
  207. $arr=$app->jssdk->buildConfig(array('updateAppMessageShareData', 'updateTimelineShareData'), false);
  208. Log::error($arr);
  209. return $arr;
  210. }
  211. public function wechats(Request $request){
  212. $app=app('wechat.official_account');
  213. $url='http://api.app.cliu.cc/api/gzhtest';
  214. $app->jssdk->setUrl($url);
  215. $arr=$app->jssdk->buildConfig(array('scanQRCode'), true);
  216. Log::error($arr);
  217. return $arr;
  218. }
  219. public function return_code(){
  220. $app=app('wechat.official_account');
  221. $arr=$app->jssdk->buildConfig(array('updateAppMessageShareData', 'updateTimelineShareData'), true);
  222. // Log::error($arr);
  223. return $arr;
  224. }
  225. public function get_user_re(Request $request){
  226. $user=User::find($request->id);
  227. $area_code=null;
  228. if($request->has('user_id')){
  229. $customer=UserW::find($request->user_id);
  230. if($customer){
  231. $customer_mobile=$customer->phone;
  232. $area_code=$customer->area_code;
  233. }else{
  234. $customer_mobile=null;
  235. }
  236. }else{
  237. $customer_mobile=null;
  238. }
  239. if ($user){
  240. if ($user->deleted_at){
  241. return $this->error(500214,'','该代理已被删除');
  242. }
  243. }
  244. $status=false;
  245. // if (Carbon::now()>'2022-03-18 09:00:00'){
  246. // $status=true;
  247. // }
  248. if(empty($area_code)){
  249. $area_code='+86';
  250. }
  251. $arr=['nickname'=>$user->nickname,
  252. 'recom_code'=>$user->recom_code,
  253. 'mobile'=>$user->mobile,
  254. 'system_status'=>$status,
  255. 'customer_mobile'=>$customer_mobile,
  256. 'area_code'=>$area_code];
  257. // return $this->success(['nickname'=>$user->nickname,'recom_code'=>$user->recom_code,'mobile'=>$user->mobile,'system_status'=>$status]);
  258. return $this->success($arr);
  259. }
  260. public function GetVRLink(){
  261. return $this->success([
  262. 'vr_link'=>System::where('keys','vr_glory_link')->value('values'),
  263. 'appraise_service_url'=>System::where('keys','appraise_service_url')->value('values'),
  264. ]);
  265. }
  266. public function GetVideoList(){
  267. return $this->success(VideoInfo::where('status',0)->where('type',0)->orderBy('sort')->orderBy('id')->get());
  268. }
  269. }