UserDivisionPropertyService.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: z-yang
  5. * Date: 2019/3/22
  6. * Time: 10:53
  7. */
  8. namespace App\Modules\User\Services;
  9. use App\Modules\User\Models\UserDivisionProperty;
  10. use DB;
  11. class userDivisionPropertyService
  12. {
  13. public static function getUserPropertyFromTable($uid){
  14. return UserDivisionProperty::where('uid',$uid)->where('is_enable',1)->select('property','created_at')->first();
  15. }
  16. public static function getUserPropertyFromStats($uid){
  17. $sql = "SELECT f.uid,f.subscribe_time,f.appid,(o.price) FROM force_subscribe_users f LEFT JOIN orders o on f.uid = o.uid and o.`status` = 'PAID'
  18. and o.created_at>=f.subscribe_time and o.created_at <= DATE_ADD(f.subscribe_time,INTERVAL 3 day) where f.is_subscribed = 1 and f.uid = %s ";
  19. $res = DB::select(sprintf($sql,$uid));
  20. if(!$res){
  21. return '';
  22. }
  23. $data = [];
  24. foreach ($res as $value){
  25. $data[] = ['subscribe_time'=>$value->subscribe_time,'appid'=>$value->appid,'price'=>$value->price];
  26. }
  27. if(!$data) return '';
  28. $collection = collect($data);
  29. $sort = $collection->groupBy('appid')->sortByDesc(function($item, $key){
  30. return $item[0]['subscribe_time'];
  31. });
  32. print_r($sort->all());
  33. }
  34. }