MerchantReconciliationDao.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\order;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\order\MerchantReconciliation as model;
  14. use app\common\repositories\system\admin\AdminRepository;
  15. use app\common\repositories\system\merchant\MerchantRepository;
  16. class MerchantReconciliationDao extends BaseDao
  17. {
  18. public function getModel(): string
  19. {
  20. return model::class;
  21. }
  22. public function search(array $where)
  23. {
  24. $query = ($this->getModel()::getDB())
  25. ->when(isset($where['mer_id']) && $where['mer_id'] != '' ,function($query)use($where){
  26. $query->where('mer_id',$where['mer_id']);
  27. })->when(isset($where['status']) && $where['status'] != '' ,function($query)use($where){
  28. $query->where('status',$where['status']);
  29. })->when(isset($where['is_accounts']) && $where['is_accounts'] != '' ,function($query)use($where){
  30. $query->where('is_accounts',$where['is_accounts']);
  31. })->when(isset($where['date']) && $where['date'] != '' ,function($query)use($where){
  32. getModelTime($query,$where['date']);
  33. })->when(isset($where['reconciliation_id']) && $where['reconciliation_id'] != '' ,function($query)use($where){
  34. $query->where('reconciliation_id',$where['reconciliation_id']);
  35. })
  36. ->when(isset($where['keyword']) && $where['keyword'] !== '',function($query)use($where){
  37. $make = app()->make(AdminRepository::class);
  38. $admin_id = $make->getSearch(['real_name' => $where['keyword']],null,false)->column('admin_id');
  39. $query->where(function($query) use($admin_id,$where){
  40. if(isset($where['mer_id'])){
  41. $query->where('admin_id','in',$admin_id);
  42. }else {
  43. $mer_make = app()->make(MerchantRepository::class);
  44. $mer_id = $mer_make->getSearch(['keyword' => $where['keyword']])->column('mer_id');
  45. $query->where('admin_id','in',$admin_id)->whereOr('mer_id','in',$mer_id);
  46. }
  47. });
  48. });
  49. return $query->order('create_time DESC,status DESC');
  50. }
  51. }