ExcelRepository.php 3.3 KB

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