123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- 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'),'操作成功');
- }
- }
|