WechatQrcodeRecordDao.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\wechat;
  12. use app\dao\BaseDao;
  13. use app\model\wechat\WechatQrcodeRecord;
  14. class WechatQrcodeRecordDao extends BaseDao
  15. {
  16. /**
  17. * @return string
  18. */
  19. protected function setModel(): string
  20. {
  21. return WechatQrcodeRecord::class;
  22. }
  23. /**
  24. * 获取列表
  25. * @param $where
  26. * @param int $page
  27. * @param int $limit
  28. * @param int $is_distinct
  29. * @return array
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function getList($where, $page = 0, $limit = 0, $is_distinct = 0)
  35. {
  36. return $this->search($where)->with(['user'])->when($page && $limit, function ($query) use ($page, $limit) {
  37. $query->page($page, $limit);
  38. })->when($is_distinct, function ($query) {
  39. $query->distinct(true)->field('uid');
  40. })->order('id desc')->select()->toArray();
  41. }
  42. /**
  43. * 扫码趋势
  44. * @param $qid
  45. * @param $time
  46. * @param $timeType
  47. * @param $field
  48. * @param $str
  49. * @param string $orderStatus
  50. * @return mixed
  51. */
  52. public function getRecordTrend($qid, $time, $timeType, $field, $str, $orderStatus = '')
  53. {
  54. return $this->getModel()->where(function ($query) use ($field, $orderStatus) {
  55. if ($orderStatus == 'yes') {
  56. $query->where('is_follow', 1);
  57. }
  58. })->where(function ($query) use ($time, $field) {
  59. if ($time[0] == $time[1]) {
  60. $query->whereDay($field, $time[0]);
  61. } else {
  62. $query->whereTime($field, 'between', $time);
  63. }
  64. })->where('qid', $qid)->field("FROM_UNIXTIME($field,'$timeType') as days,$str as num")->group('days')->select()->toArray();
  65. }
  66. }