Userproduct.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\user\model;
  3. use think\Model;
  4. /**
  5. * 用户管理
  6. */
  7. class Userproduct extends Model
  8. {
  9. public function getProductCount($userId)
  10. {
  11. $result = $this
  12. ->where(['user_id' => $userId])
  13. ->count();
  14. return $result;
  15. }
  16. public function getRenewProductCount($userId)
  17. {
  18. $allData = $this
  19. ->field(['userProduct_dayNumber', 'userProduct_buyTime'])
  20. ->where(['user_id' => $userId])
  21. ->select();
  22. $count = 0;
  23. foreach ($allData as $key => $value) {
  24. $numberDay = $value->userProduct_dayNumber - 15;
  25. $remindDate = date("Y-m-d",strtotime($numberDay . " day"));
  26. if ($value->userProduct_buyTime >= $remindDate) {
  27. $count++;
  28. }
  29. }
  30. return $count;
  31. }
  32. public function getUserProduct($condition)
  33. {
  34. $result = $this
  35. ->alias('a')
  36. ->join('product b', 'a.product_id = b.product_id')
  37. ->where($condition)
  38. ->paginate(10);
  39. return $result;
  40. }
  41. public function findUserProduct($condition)
  42. {
  43. $result = $this
  44. ->where($condition)
  45. ->find();
  46. return $result;
  47. }
  48. public function updateUserProduct($condition, $data)
  49. {
  50. $result = $this
  51. ->where($condition)
  52. ->update($data);
  53. return $result;
  54. }
  55. }