MerchantReconciliationDao.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\common\dao\store\order;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\store\order\MerchantReconciliation as model;
  5. use app\common\repositories\system\admin\AdminRepository;
  6. use app\common\repositories\system\merchant\MerchantRepository;
  7. class MerchantReconciliationDao extends BaseDao
  8. {
  9. public function getModel(): string
  10. {
  11. return model::class;
  12. }
  13. public function search(array $where)
  14. {
  15. $query = ($this->getModel()::getDB())
  16. ->when(isset($where['mer_id']) && $where['mer_id'] != '' ,function($query)use($where){
  17. $query->where('mer_id',$where['mer_id']);
  18. })->when(isset($where['status']) && $where['status'] != '' ,function($query)use($where){
  19. $query->where('status',$where['status']);
  20. })->when(isset($where['is_accounts']) && $where['is_accounts'] != '' ,function($query)use($where){
  21. $query->where('is_accounts',$where['is_accounts']);
  22. })->when(isset($where['date']) && $where['date'] != '' ,function($query)use($where){
  23. getModelTime($query,$where['date']);
  24. })->when(isset($where['reconciliation_id']) && $where['reconciliation_id'] != '' ,function($query)use($where){
  25. $query->where('reconciliation_id',$where['reconciliation_id']);
  26. })
  27. ->when(isset($where['keyword']) && $where['keyword'] !== '',function($query)use($where){
  28. $make = app()->make(AdminRepository::class);
  29. $admin_id = $make->getSearch(['real_name' => $where['keyword']],null,false)->column('admin_id');
  30. $query->where(function($query) use($admin_id,$where){
  31. if(isset($where['mer_id'])){
  32. $query->where('admin_id','in',$admin_id);
  33. }else {
  34. $mer_make = app()->make(MerchantRepository::class);
  35. $mer_id = $mer_make->getSearch(['keyword' => $where['keyword']])->column('mer_id');
  36. $query->where('admin_id','in',$admin_id)->whereOr('mer_id','in',$mer_id);
  37. }
  38. });
  39. });
  40. return $query->order('create_time DESC,status DESC');
  41. }
  42. }