ProductGroupBuyingDao.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\ProductGroupBuying;
  14. class ProductGroupBuyingDao extends BaseDao
  15. {
  16. public function getModel(): string
  17. {
  18. return ProductGroupBuying::class;
  19. }
  20. public function search($where)
  21. {
  22. $query = ProductGroupBuying::getDb()->alias('B')->join('StoreProductGroup G','B.product_group_id = G.product_group_id');
  23. $query
  24. ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function($query)use($where){
  25. $query->where('B.mer_id',$where['mer_id']);
  26. })
  27. ->when(isset($where['date']) && $where['date'] , function($query)use($where){
  28. getModelTime($query,$where['date'],'B.create_time');
  29. })
  30. ->when(isset($where['status']) && $where['status'] !== '', function($query)use($where){
  31. $query->where('B.status',$where['status']);
  32. })
  33. ->when(isset($where['user_name']) && $where['user_name'] !== '', function($query)use($where){
  34. $query->join('StoreProductGroupUser U','U.group_buying_id = B.group_buying_id')->where('is_initiator',1)
  35. ->whereLike('uid|nickname',"%{$where['user_name']}%");
  36. })
  37. ->when(isset($where['keyword']) && $where['keyword'] !== '' , function($query)use($where){
  38. $query->join('StoreProduct P','G.product_id = P.product_id')
  39. ->whereLike('B.group_buying_id|P.product_id|store_name',"%{$where['keyword']}%");
  40. })
  41. ->when(isset($where['is_trader']) && $where['is_trader'] !== '', function($query)use($where){
  42. $query->join('Merchant M','M.mer_id = B.mer_id')->where('is_trader',$where['is_trader']);
  43. })
  44. ;
  45. return $query;
  46. }
  47. }