// +---------------------------------------------------------------------- declare (strict_types = 1); namespace app\store\controller; use app\store\model\GiveOutCoupon as GiveOutCouponModel; use app\store\model\store\UserRole; use app\store\service\store\Role as StoreRoleService; use PhpOffice\PhpSpreadsheet\Reader\Xls; use think\cache\driver\Redis; use think\facade\Filesystem; /** * 申请分销员 * Class Setting * @package app\store\controller */ class GiveOutCoupon extends Controller { /** * 申请列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function list() { $cs = request()->get(); $m = new GiveOutCouponModel(); $list = $m->getList($cs); return $this->renderSuccess(compact('list')); } /** * 详情 * @param $id * @return array */ public function details($id) { $m = new GiveOutCouponModel(); $list = $m->detail($id); return $this->renderSuccess(compact('list')); } /** * 创建 * @return array */ public function create() { // 保存商城设置 $model = new GiveOutCouponModel(); $params = $this->postForm(); $params['create_admin_id'] =$this->store['user']['store_user_id']; if ($model->add($params )) { return $this->renderSuccess('操作成功'); } return $this->renderError($model->getError() ?: '操作失败'); } /** * 审核 * @return array */ public function audit(){ $params = request()->get(); $params['audit_user_id'] =$this->store['user']['store_user_id']; $params['audit_time'] = date('Y-m-d H:i:s'); $model = new GiveOutCouponModel(); if ($model->audit($params)) { return $this->renderSuccess('操作成功'); } return $this->renderError($model->getError() ?: '操作失败'); } /** * 上传文件 * @return array|false * @throws \PhpOffice\PhpSpreadsheet\Exception * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception */ public function uploadMobiles(){ // 获取表单上传文件 例如上传了001.jpg $file = request()->file('iFile'); // 上传到本地服务器 $savename = Filesystem::putFile( 'topic', $file); $fileName = runtime_root_path().'storage/'.$savename; if (!$fileName)return false; $reader = new Xls(); $excel = $reader->load($fileName); $sheet = $excel->getSheet(0); $sheetRows = $sheet->getHighestRow(); $mobiles = []; for ($i = 2; $i <= $sheetRows; $i++) { $mobiles[] = trim(strval($sheet->getCell('A' . $i)->getValue()??'')); } $keys = 'GIVEOUTCOUPONKEY'.time().rand(1000,9999); $rds = new Redis(config('cache.stores.redis')); $rds->set($keys,json_encode($mobiles),900);//写10000秒 if (file_exists($fileName)){ unlink($fileName); } return $this->renderSuccess(compact('keys'),'操作成功'); } }