Userproduct.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. ->order('userProduct_buyTime desc')
  39. ->paginate(10);
  40. return $result;
  41. }
  42. public function findUserProduct($condition)
  43. {
  44. $result = $this
  45. ->where($condition)
  46. ->find();
  47. return $result;
  48. }
  49. public function updateUserProduct($condition, $data)
  50. {
  51. $result = $this
  52. ->where($condition)
  53. ->update($data);
  54. return $result;
  55. }
  56. }