ExcelRepository.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\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. //app()->make(ExcelService::class)->$type($where,$excel->excel_id);
  51. Queue::push(SpreadsheetExcelJob::class,$data);
  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($item['mer_id']){
  71. $admin = $mer_make->get($item['admin_id']);
  72. }else{
  73. $admin = $sys_make->get($item['admin_id']);
  74. }
  75. return $item['admin_id'] = $admin['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. }