ProductAssistSetDao.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. 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 search(array $where)
  24. {
  25. $query = $this->getSearch($where)
  26. ->when(isset($where['date']) && $where['date'] !== '',function($query) use($where){
  27. getModelTime($query,$where['date']);
  28. })->where('is_del',0);
  29. return $query->order('create_time DESC');
  30. }
  31. public function incNum(int $type,int $id,int $inc = 1)
  32. {
  33. try{
  34. $query = $this->getModel()::where($this->getPk(),$id);
  35. if($type == 1) $query->inc('share_num',$inc)->update();
  36. if($type == 2) $query->inc('view_num',$inc)->update();
  37. }catch (Exception $exception){
  38. }
  39. }
  40. public function userCount()
  41. {
  42. $count = $this->getModel()::getDB()->count("*");
  43. $res = $this->getModel()::getDB()->order('create_time DESC')->with(['user' => function($query){
  44. $query->field('uid,avatar avatar_img');
  45. }])->limit(10)->group('uid')->select()->toArray();
  46. $list = [];
  47. foreach ($res as $item){
  48. if($item['user']['avatar_img']){
  49. $list[] = $item['user'];
  50. }
  51. }
  52. return compact('count','list');
  53. }
  54. /**
  55. * TODO 更新状态
  56. * @param int $id
  57. * @author Qinii
  58. * @day 2020-11-25
  59. */
  60. public function changStatus(int $id)
  61. {
  62. $this->getModel()::getDB()->where($this->getPk(),$id)->update(['status' => 20]);
  63. }
  64. }