招标
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

122 lines
4.1 KiB

<?php
/**
* Member.php
* User: ChenLong
* DateTime: 2020-12-21 09:45:12
*/
namespace app\admin\controller;
use \app\common\controller\Admin;
use app\common\ResponseJson;
use sdModule\common\helper\Excel;
use sdModule\common\Sc;
use sdModule\layui\defaultForm\Form;
use think\facade\App;
use think\facade\Db;
/**
* Class Member
* @package app\admin\controller\Member
* @author chenlong <vip_chenlong@163.com>
*/
class Member extends Admin
{
/**
* 列表数据接口
* @return mixed|string|\think\Collection|\think\response\Json
* @throws \app\common\SdException
*/
public function listData()
{
return $this
->setField('i.id,i.username,i.mobile,ifnull(i.avatar,"") avatar,i.email,i.company,i.position,i.status,i.status status_edit,i.create_time,i.is_tender')
->listsRequest();
}
public function beforeWrite(&$data)
{
$data['password'] = SC::password()->encryption('123456');
}
/**
* @return \think\response\Json
* @author Deng
* @date 2020-12-23 11:06
* 修改登录状态
*/
public function changeStatus(){
$status = $this->request->post('type');
$id = $this->request->post('id');
$res = \app\common\model\Member::where('id',$id)->update(['status'=>$status]);
return $res ? ResponseJson::success($res) : ResponseJson::fail('失败');
}
/**
* @return \think\response\Json
* @author Deng
* @date 2020-12-23 11:06
* 修改投标状态
*/
public function changeTenderStatus(){
$status = $this->request->post('type');
$id = $this->request->post('id');
$res = \app\common\model\Member::where('id',$id)->update(['is_tender'=>$status]);
return $res ? ResponseJson::success($res) : ResponseJson::fail('失败');
}
/**
* @return \think\response\Json
* @author Deng
* @date 2020-12-23 13:37
* 重置密码
*/
public function resetPassword(){
$getData = $this->request->get();
$password = Sc::password()->encryption('123456');
$res = \app\common\model\Member::where('id',$getData['id'])->update(['password'=>$password]);
return $res ? ResponseJson::success([],'密码重置成功') : ResponseJson::fail('密码重置失败');
}
/**
* @return array|\think\response\Json|\think\response\View
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
* @throws \ReflectionException
* @throws \app\common\SdException
* @author Deng
* @date 2021-01-18 11:05
* 导入会员
*/
public function importForm(){
if(request()->isPost()){
$getPost = request()->post();
if(!$getPost['file']) return ResponseJson::fail('资源不存在');
$resource = Db::name('resource')->where('id',$getPost['file'])->findOrEmpty();
if(!$resource) return ResponseJson::fail('资源不存在');
$path = App::getRootPath().'/upload/'.$resource['path'];
$excel = new Excel($path,'read');
$data = $excel->getActiveData();
if ($data) {
$addData = [];
foreach ($data as $index => $item) {
if ($index>=1){
$addData[] = [
'mobile' => $item[0],
'username' => $item[1],
'email' => $item[2],
'company' => $item[3],
'position' => $item[4],
'password' => SC::password()->encryption('123456'),
'create_time' => date('Y-m-d H:i:s'),
'update_time' => date('Y-m-d H:i:s')
];
}
}
$result = \app\common\model\Member::insertAll($addData);
return $result ? ResponseJson::success('','导入成功') : ResponseJson::fail('导入失败');
}
}
return $this->fetch('common/save_page',['form'=>Form::create($this->getPage()->importForm())->complete()]);
}
}