WechatQrcodeRecordDao.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\dao\wechat;
  3. use app\dao\BaseDao;
  4. use app\model\wechat\WechatQrcodeRecord;
  5. class WechatQrcodeRecordDao extends BaseDao
  6. {
  7. /**
  8. * @return string
  9. */
  10. protected function setModel(): string
  11. {
  12. return WechatQrcodeRecord::class;
  13. }
  14. /**
  15. * 获取列表
  16. * @param $where
  17. * @param int $page
  18. * @param int $limit
  19. * @param int $is_distinct
  20. * @return array
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\DbException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. */
  25. public function getList($where, $page = 0, $limit = 0, $is_distinct = 0)
  26. {
  27. return $this->search($where)->with(['user'])->when($page && $limit, function ($query) use ($page, $limit) {
  28. $query->page($page, $limit);
  29. })->when($is_distinct, function ($query) {
  30. $query->distinct(true)->field('uid');
  31. })->order('id desc')->select()->toArray();
  32. }
  33. /**
  34. * 扫码趋势
  35. * @param $qid
  36. * @param $time
  37. * @param $timeType
  38. * @param $field
  39. * @param $str
  40. * @param string $orderStatus
  41. * @return mixed
  42. */
  43. public function getRecordTrend($qid, $time, $timeType, $field, $str, $orderStatus = '')
  44. {
  45. return $this->getModel()->where(function ($query) use ($field, $orderStatus) {
  46. if ($orderStatus == 'yes') {
  47. $query->where('is_follow', 1);
  48. }
  49. })->where(function ($query) use ($time, $field) {
  50. if ($time[0] == $time[1]) {
  51. $query->whereDay($field, $time[0]);
  52. } else {
  53. $query->whereTime($field, 'between', $time);
  54. }
  55. })->where('qid', $qid)->field("FROM_UNIXTIME($field,'$timeType') as days,$str as num")->group('days')->select()->toArray();
  56. }
  57. }