UserRechargeDao.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\user;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\user\UserRecharge;
  14. use think\db\BaseQuery;
  15. /**
  16. * Class UserRechargeDao
  17. * @package app\common\dao\user
  18. * @author xaboy
  19. * @day 2020/6/2
  20. */
  21. class UserRechargeDao extends BaseDao
  22. {
  23. /**
  24. * @return string
  25. * @author xaboy
  26. * @day 2020/6/2
  27. */
  28. protected function getModel(): string
  29. {
  30. return UserRecharge::class;
  31. }
  32. public function createOrderId($uid)
  33. {
  34. $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();
  35. return 'wx' . date('YmdHis', time()) . ($uid . $count);
  36. }
  37. public function userRechargePrice($uid)
  38. {
  39. return UserRecharge::getDB()->where('uid', $uid)->where('paid', 1)->sum('price');
  40. }
  41. /**
  42. * @param array $where
  43. * @return BaseQuery
  44. * @author xaboy
  45. * @day 2020/6/23
  46. */
  47. public function searchJoinQuery(array $where)
  48. {
  49. return UserRecharge::getDB()->alias('a')->join('User b', 'a.uid = b.uid')
  50. ->field('a.paid,a.order_id,a.recharge_id,b.nickname,b.avatar,a.price,a.give_price,a.recharge_type,a.pay_time')
  51. ->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  52. $query->whereLike('b.nickname|a.order_id', "%{$where['keyword']}%");
  53. })->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
  54. $query->whereLike('a.paid', $where['paid']);
  55. })->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  56. getModelTime($query, $where['date'], 'a.create_time');
  57. });
  58. }
  59. public function totalPayPrice()
  60. {
  61. return UserRecharge::getDB()->where('paid', 1)->sum('price');
  62. }
  63. public function totalRefundPrice()
  64. {
  65. return UserRecharge::getDB()->where('paid', 1)->sum('refund_price');
  66. }
  67. public function totalRoutinePrice()
  68. {
  69. return UserRecharge::getDB()->where('paid', 1)->where('recharge_type', 'routine')->sum('price');
  70. }
  71. public function totalWxPrice()
  72. {
  73. return UserRecharge::getDB()->where('paid', 1)->whereIn('recharge_type', ['h5', 'wechat'])->sum('price');
  74. }
  75. }