UserRechargeDao.php 2.4 KB

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