WechatQrcodeDao.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\WechatQrcode;
  16. /**
  17. *
  18. * Class UserWechatUserDao
  19. * @package app\dao\user
  20. */
  21. class WechatQrcodeDao extends BaseDao
  22. {
  23. /**
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return WechatQrcode::class;
  29. }
  30. /**
  31. * 获取列表
  32. * @param $where
  33. * @param $page
  34. * @param $limit
  35. * @return array
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public function getList($where, $page = 0, $limit = 0)
  41. {
  42. return $this->search($where)->with(['user', 'record' => function ($query) {
  43. $query->where('is_follow', 1)->whereDay('add_time', 'yesterday')->field('qid,count(distinct uid) as number')->bind(['y_follow' => 'number']);
  44. }])->when($page && $limit, function ($query) use ($page, $limit) {
  45. $query->page($page, $limit);
  46. })->order('id desc')->select()->toArray();
  47. }
  48. /**
  49. * 更新次数
  50. * @param $id
  51. * @param $isFollow
  52. */
  53. public function upFollowAndScan($id, $isFollow)
  54. {
  55. $this->getModel()->where('id', $id)->inc('scan')->when($isFollow, function ($query) {
  56. $query->inc('follow');
  57. })->update();
  58. }
  59. }