UserRechargeDao.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\common\dao\user;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\user\UserRecharge;
  5. use think\db\BaseQuery;
  6. /**
  7. * Class UserRechargeDao
  8. * @package app\common\dao\user
  9. * @author zfy
  10. * @day 2020/6/2
  11. */
  12. class UserRechargeDao extends BaseDao
  13. {
  14. /**
  15. * @return string
  16. * @author zfy
  17. * @day 2020/6/2
  18. */
  19. protected function getModel(): string
  20. {
  21. return UserRecharge::class;
  22. }
  23. public function createOrderId($uid)
  24. {
  25. $count = (int)UserRecharge::getDB()->where('uid', $uid)->where('create_time', '>=', date("Y-m-d"))->where('create_time', '<', date("Y-m-d", strtotime('+1 day')))->count();
  26. return 'wx' . date('YmdHis', time()) . ($uid . $count);
  27. }
  28. public function userRechargePrice($uid)
  29. {
  30. return UserRecharge::getDB()->where('uid', $uid)->where('paid', 1)->sum('price');
  31. }
  32. /**
  33. * @param array $where
  34. * @return BaseQuery
  35. * @author zfy
  36. * @day 2020/6/23
  37. */
  38. public function searchJoinQuery(array $where)
  39. {
  40. return UserRecharge::getDB()->alias('a')->join('User b', 'a.uid = b.uid')
  41. ->field('a.paid,a.order_id,a.recharge_id,b.nickname,b.avatar,a.price,a.give_price,a.recharge_type,a.pay_time')
  42. ->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  43. $query->whereLike('b.nickname|a.order_id', "%{$where['keyword']}%");
  44. })->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
  45. $query->whereLike('a.paid', $where['paid']);
  46. })->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  47. getModelTime($query, $where['date'], 'a.create_time');
  48. });
  49. }
  50. public function totalPayPrice()
  51. {
  52. return UserRecharge::getDB()->where('paid', 1)->sum('price');
  53. }
  54. public function totalRefundPrice()
  55. {
  56. return UserRecharge::getDB()->where('paid', 1)->sum('refund_price');
  57. }
  58. public function totalRoutinePrice()
  59. {
  60. return UserRecharge::getDB()->where('paid', 1)->where('recharge_type', 'routine')->sum('price');
  61. }
  62. public function totalWxPrice()
  63. {
  64. return UserRecharge::getDB()->where('paid', 1)->whereIn('recharge_type', ['h5', 'wechat'])->sum('price');
  65. }
  66. }