ExcelRepository.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author Qinii
  6. * @day 2020-07-30
  7. *
  8. *
  9. */
  10. namespace app\common\repositories\store;
  11. use app\common\dao\store\ExcelDao;
  12. use app\common\repositories\BaseRepository;
  13. use app\common\repositories\system\admin\AdminRepository;
  14. use app\common\repositories\system\merchant\MerchantAdminRepository;
  15. use crmeb\services\ExcelService;
  16. use think\facade\Db;
  17. use think\facade\Queue;
  18. use crmeb\jobs\SpreadsheetExcelJob;
  19. class ExcelRepository extends BaseRepository
  20. {
  21. /**
  22. * @var ExcelDao
  23. */
  24. protected $dao;
  25. /**
  26. * StoreAttrTemplateRepository constructor.
  27. * @param ExcelDao $dao
  28. */
  29. public function __construct(ExcelDao $dao)
  30. {
  31. $this->dao = $dao;
  32. }
  33. /**
  34. * TODO
  35. * @param array $where
  36. * @param int $admin_id
  37. * @param string $type
  38. * @author Qinii
  39. * @day 2020-07-30
  40. */
  41. public function create(array $where ,int $admin_id, string $type,int $merId)
  42. {
  43. //app()->make(ExcelService::class)->order($where,1);
  44. $excel = $this->dao->create([
  45. 'mer_id' => $merId,
  46. 'admin_id' => $admin_id,
  47. 'type' => $type
  48. ]);
  49. $data = ['where' => $where,'type' => $type,'excel_id' => $excel->excel_id];
  50. Queue::push(SpreadsheetExcelJob::class,$data);
  51. }
  52. /**
  53. * TODO
  54. * @param array $where
  55. * @param int $page
  56. * @param int $limit
  57. * @return array
  58. * @author Qinii
  59. * @day 2020-07-30
  60. */
  61. public function getList(array $where,int $page, int $limit)
  62. {
  63. $mer_make = app()->make(MerchantAdminRepository::class);
  64. $sys_make = app()->make(AdminRepository::class);
  65. $query = $this->dao->search($where);
  66. $count = $query->count();
  67. $list = $query->page($page,$limit)->hidden(['path'])->select()
  68. ->each(function($item) use ($mer_make,$sys_make){
  69. if($item['mer_id']){
  70. $admin = $mer_make->get($item['admin_id']);
  71. }else{
  72. $admin = $sys_make->get($item['admin_id']);
  73. }
  74. $real_name = $admin['real_name'];
  75. return $item['real_name'] = $real_name;
  76. });
  77. return compact('count','list');
  78. }
  79. /**
  80. * TODO 删除文件
  81. * @param int $id
  82. * @param string $path
  83. * @author Qinii
  84. * @day 2020-08-15
  85. */
  86. public function del(int $id,?string $path)
  87. {
  88. Db::transaction(function()use($id,$path){
  89. $this->dao->delete($id);
  90. if(!is_null($path)){
  91. $path = app()->getRootPath().'public'.$path;
  92. if(file_exists($path))unlink($path);
  93. }
  94. });
  95. }
  96. }