ExcelRepository.php 2.5 KB

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