ForceGuidePersonAccountService.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: z-yang
  5. * Date: 2019/7/2
  6. * Time: 14:47
  7. */
  8. namespace App\Modules\User\Services;
  9. use App\Modules\User\Models\ForceGuidePersonAccount;
  10. use Carbon\Carbon;
  11. class ForceGuidePersonAccountService
  12. {
  13. public static function isShow($uid,$bid,$cid)
  14. {
  15. $model = new ForceGuidePersonAccount();
  16. $result = $model->where('uid', $uid)
  17. ->where('day', date('Y-m-d'))
  18. ->where('bid',$bid)
  19. ->where('cid',$cid)
  20. ->select('bid', 'cid', 'created_at')
  21. ->first();
  22. if($result){
  23. return false;
  24. }
  25. $result = $model->where('uid', $uid)->where('day', date('Y-m-d'))->select('bid', 'cid', 'created_at')->get();
  26. if ($result->isEmpty()) {
  27. $yesterday = $model->where('uid', $uid)
  28. ->where('day', date('Y-m-d', time() - 86400))
  29. ->select('bid', 'cid', 'created_at')
  30. ->orderBy('id', 'desc')
  31. ->first();
  32. if (!$yesterday) {
  33. return true;
  34. }
  35. $now = Carbon::now()->timestamp;
  36. if ($now - $yesterday->created_at->timestamp <= 6 * 3600) {
  37. return false;
  38. }
  39. return true;
  40. }
  41. if ($result->count() >= 2) {
  42. return false;
  43. }
  44. return true;
  45. }
  46. public static function create($uid,$bid,$cid){
  47. $model = new ForceGuidePersonAccount();
  48. $day = date('Y-m-d');
  49. $result = $model->where('uid', $uid)
  50. ->where('day', date('Y-m-d'))
  51. ->where('bid',$bid)
  52. ->where('cid',$cid)
  53. ->select('bid', 'cid', 'created_at')
  54. ->first();
  55. if($result) return false;
  56. $model->create(compact('uid','day','bid','cid'));
  57. return true;
  58. }
  59. }