WechatQrcodeRecordDao.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. declare (strict_types=1);
  12. namespace app\dao\wechat;
  13. use think\model;
  14. use app\dao\BaseDao;
  15. use app\model\wechat\WechatQrcodeRecord;
  16. /**
  17. *
  18. * Class UserWechatUserDao
  19. * @package app\dao\user
  20. */
  21. class WechatQrcodeRecordDao extends BaseDao
  22. {
  23. /**
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return WechatQrcodeRecord::class;
  29. }
  30. /**
  31. * 获取列表
  32. * @param $where
  33. * @param int $page
  34. * @param int $limit
  35. * @param int $is_distinct
  36. * @return array
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function getList($where, $page = 0, $limit = 0, $is_distinct = 0)
  42. {
  43. return $this->search($where)->with(['user'])->when($page && $limit, function ($query) use ($page, $limit) {
  44. $query->page($page, $limit);
  45. })->when($is_distinct, function ($query) {
  46. $query->distinct(true)->field('uid');
  47. })->order('id desc')->select()->toArray();
  48. }
  49. /**
  50. * 扫码趋势
  51. * @param $qid
  52. * @param $time
  53. * @param $timeType
  54. * @param $field
  55. * @param $str
  56. * @return mixed
  57. */
  58. public function getRecordTrend($qid, $time, $timeType, $field, $str, $orderStatus = '')
  59. {
  60. return $this->getModel()->where(function ($query) use ($field, $orderStatus) {
  61. if ($orderStatus == 'yes') {
  62. $query->where('is_follow', 1);
  63. }
  64. })->where(function ($query) use ($time, $field) {
  65. if ($time[0] == $time[1]) {
  66. $query->whereDay($field, $time[0]);
  67. } else {
  68. $query->whereTime($field, 'between', $time);
  69. }
  70. })->where('qid', $qid)->field("FROM_UNIXTIME($field,'$timeType') as days,$str as num")->group('days')->select()->toArray();
  71. }
  72. }