ProductAssistSetDao.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\store\product;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\product\ProductAssistSet;
  14. use app\common\model\system\merchant\Merchant;
  15. use app\common\repositories\system\merchant\MerchantRepository;
  16. use think\Exception;
  17. class ProductAssistSetDao extends BaseDao
  18. {
  19. protected function getModel(): string
  20. {
  21. return ProductAssistSet::class;
  22. }
  23. public function incNum(int $type,int $id,int $inc = 1)
  24. {
  25. try{
  26. $query = $this->getModel()::where($this->getPk(),$id);
  27. if($type == 1) $query->inc('share_num',$inc)->update();
  28. if($type == 2) $query->inc('view_num',$inc)->update();
  29. }catch (Exception $exception){
  30. }
  31. }
  32. public function userCount()
  33. {
  34. $count = $this->getModel()::getDB()->count("*");
  35. $res = $this->getModel()::getDB()->order('create_time DESC')->with(['user' => function($query){
  36. $query->field('uid,avatar avatar_img');
  37. }])->limit(10)->group('uid')->select()->toArray();
  38. $list = [];
  39. foreach ($res as $item){
  40. if(isset($item['user']['avatar_img']) && $item['user']['avatar_img']){
  41. $list[] = $item['user'];
  42. }
  43. }
  44. return compact('count','list');
  45. }
  46. /**
  47. * TODO 更新状态
  48. * @param int $id
  49. * @author Qinii
  50. * @day 2020-11-25
  51. */
  52. public function changStatus(int $id)
  53. {
  54. $this->getModel()::getDB()->where($this->getPk(),$id)->update(['status' => 20]);
  55. }
  56. }