| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- /**
- * @package merchant
- *
- * @author Qinii
- * @day 2020-07-30
- *
- *
- */
- namespace app\common\repositories\store;
- use app\common\dao\store\ExcelDao;
- use app\common\repositories\BaseRepository;
- use app\common\repositories\system\admin\AdminRepository;
- use app\common\repositories\system\merchant\MerchantAdminRepository;
- use crmeb\services\ExcelService;
- use think\facade\Db;
- use think\facade\Queue;
- use crmeb\jobs\SpreadsheetExcelJob;
- class ExcelRepository extends BaseRepository
- {
- /**
- * @var ExcelDao
- */
- protected $dao;
- /**
- * StoreAttrTemplateRepository constructor.
- * @param ExcelDao $dao
- */
- public function __construct(ExcelDao $dao)
- {
- $this->dao = $dao;
- }
- /**
- * TODO
- * @param array $where
- * @param int $admin_id
- * @param string $type
- * @author Qinii
- * @day 2020-07-30
- */
- public function create(array $where ,int $admin_id, string $type,int $merId)
- {
- //app()->make(ExcelService::class)->order($where,1);
- $excel = $this->dao->create([
- 'mer_id' => $merId,
- 'admin_id' => $admin_id,
- 'type' => $type
- ]);
- $data = ['where' => $where,'type' => $type,'excel_id' => $excel->excel_id];
- Queue::push(SpreadsheetExcelJob::class,$data);
- }
- /**
- * @param array $where
- * @param int $admin_id
- * @param string $type
- * @param int $merId
- * @return \app\common\dao\BaseDao|\think\Model
- * @author 史晨
- * @date 2026/3/10 14:48
- */
- public function createNoJob(array $where ,int $admin_id, string $type,int $merId)
- {
- return $this->dao->create([
- 'mer_id' => $merId,
- 'admin_id' => $admin_id,
- 'type' => $type
- ]);
- }
- /**
- * TODO
- * @param array $where
- * @param int $page
- * @param int $limit
- * @return array
- * @author Qinii
- * @day 2020-07-30
- */
- public function getList(array $where,int $page, int $limit)
- {
- $mer_make = app()->make(MerchantAdminRepository::class);
- $sys_make = app()->make(AdminRepository::class);
- $query = $this->dao->search($where);
- $count = $query->count();
- $list = $query->page($page,$limit)->hidden(['path'])->select()
- ->each(function($item) use ($mer_make,$sys_make){
- if($item['mer_id']){
- $admin = $mer_make->get($item['admin_id']);
- }else{
- $admin = $sys_make->get($item['admin_id']);
- }
- $real_name = $admin['real_name'];
- return $item['real_name'] = $real_name;
- });
- return compact('count','list');
- }
- /**
- * TODO 删除文件
- * @param int $id
- * @param string $path
- * @author Qinii
- * @day 2020-08-15
- */
- public function del(int $id,?string $path)
- {
- Db::transaction(function()use($id,$path){
- $this->dao->delete($id);
- if(!is_null($path)){
- $path = app()->getRootPath().'public'.$path;
- if(file_exists($path))unlink($path);
- }
- });
- }
- }
|