WechatQrcodeDao.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\dao\wechat;
  3. use app\dao\BaseDao;
  4. use app\model\wechat\WechatQrcode;
  5. class WechatQrcodeDao extends BaseDao
  6. {
  7. /**
  8. * @return string
  9. */
  10. protected function setModel(): string
  11. {
  12. return WechatQrcode::class;
  13. }
  14. /**
  15. * 获取列表
  16. * @param $where
  17. * @param $page
  18. * @param $limit
  19. * @return array
  20. * @throws \think\db\exception\DataNotFoundException
  21. * @throws \think\db\exception\DbException
  22. * @throws \think\db\exception\ModelNotFoundException
  23. */
  24. public function getList($where, $page = 0, $limit = 0)
  25. {
  26. return $this->search($where)->with(['user', 'record' => function ($query) {
  27. $query->where('is_follow', 1)->whereDay('add_time', 'yesterday')->field('qid,count(distinct uid) as number')->bind(['y_follow' => 'number']);
  28. }])->when($page && $limit, function ($query) use ($page, $limit) {
  29. $query->page($page, $limit);
  30. })->order('id desc')->select()->toArray();
  31. }
  32. /**
  33. * 更新次数
  34. * @param $id
  35. * @param $isFollow
  36. */
  37. public function upFollowAndScan($id, $isFollow)
  38. {
  39. $this->getModel()->where('id', $id)->inc('scan')->when($isFollow, function ($query) {
  40. $query->inc('follow');
  41. })->update();
  42. }
  43. }