ProductAssistSetDao.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\common\dao\store\product;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\store\product\ProductAssistSet;
  5. use app\common\model\system\merchant\Merchant;
  6. use app\common\repositories\system\merchant\MerchantRepository;
  7. use think\Exception;
  8. class ProductAssistSetDao extends BaseDao
  9. {
  10. protected function getModel(): string
  11. {
  12. return ProductAssistSet::class;
  13. }
  14. public function incNum(int $type,int $id,int $inc = 1)
  15. {
  16. try{
  17. $query = $this->getModel()::where($this->getPk(),$id);
  18. if($type == 1) $query->inc('share_num',$inc)->update();
  19. if($type == 2) $query->inc('view_num',$inc)->update();
  20. }catch (Exception $exception){
  21. }
  22. }
  23. public function userCount()
  24. {
  25. $count = $this->getModel()::getDB()->count("*");
  26. $res = $this->getModel()::getDB()->order('create_time DESC')->with(['user' => function($query){
  27. $query->field('uid,avatar avatar_img');
  28. }])->limit(10)->group('uid')->select()->toArray();
  29. $list = [];
  30. foreach ($res as $item){
  31. if($item['user']['avatar_img']){
  32. $list[] = $item['user'];
  33. }
  34. }
  35. return compact('count','list');
  36. }
  37. /**
  38. * TODO 更新状态
  39. * @param int $id
  40. * @author Qinii
  41. * @day 2020-11-25
  42. */
  43. public function changStatus(int $id)
  44. {
  45. $this->getModel()::getDB()->where($this->getPk(),$id)->update(['status' => 20]);
  46. }
  47. }