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_maturityTime'])
  20. ->where(['user_id' => $userId])
  21. ->select();
  22. $count = 0;
  23. foreach ($allData as $key => $value) {
  24. $remindDate = date("Y-m-d",strtotime(15 . " day"));
  25. if ($value->userProduct_maturityTime <= $remindDate) {
  26. $count++;
  27. }
  28. }
  29. return $count;
  30. }
  31. public function getUserProduct($condition)
  32. {
  33. $result = $this
  34. ->alias('a')
  35. ->join('product b', 'a.product_id = b.product_id')
  36. ->where($condition)
  37. ->order('userProduct_buyTime desc')
  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. }