738 lines
32 KiB
PHP
Executable File
738 lines
32 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use think\Lang;
|
|
use think\Loader;
|
|
use think\Config;
|
|
use think\Db;
|
|
|
|
class Job extends BaseController {
|
|
|
|
public function index() {
|
|
$this->redirect('/admin/job/lists');
|
|
}
|
|
|
|
public function lists() {
|
|
$where = null;
|
|
$order = ['stat' => 'asc', 'sort' => 'asc', 'publish_time' => 'desc'];
|
|
$field = ['id', 'department', 'job_name', 'count', 'job_address', 'experience_requirement', 'education', 'sort', 'publish_time', 'end_time', 'stat'];
|
|
|
|
$dataObject = model('job')->getJobLists($where, $order, $field, 12);
|
|
// tiaoshi($dataObject);die;
|
|
$value = [
|
|
'page' => $dataObject->render(),
|
|
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
|
|
];
|
|
// tiaoshi($dataObject->items());die;
|
|
$this->assign($value);
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function add() {
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function edit($id = 0) {
|
|
$id = intval($id);
|
|
// tiaoshi($id);die;
|
|
if ($id > 0) {
|
|
$job = model('job')->find($id);
|
|
if (!$job && !is_array($job)) {
|
|
return $this->error('数据有误,请检查后再操作');
|
|
}
|
|
$value['job'] = $job;
|
|
} else {
|
|
return $this->error('数据有误,请检查后再操作');
|
|
}
|
|
// dump($job);die;
|
|
$this->assign($value);
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function qiyong()
|
|
{
|
|
$id = $this->request->param('id');
|
|
if ($id < 0)
|
|
{
|
|
return $this->json(-1, 'id错误');
|
|
}
|
|
|
|
$result = model('job')->where(['id' => $id])->update(['stat' => 0]);
|
|
if (!$result)
|
|
{
|
|
return $this->json(-2, '修改失败');
|
|
}
|
|
|
|
return $this->json(200, 'ok');
|
|
}
|
|
|
|
public function delete($id = 0) {
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$result = model('job')->where(['id' => $id])->update(['stat' => 1]);
|
|
// echo \think\Db::table('job')->getLastSql();die;
|
|
// tiaoshi($result);die;
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/job/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function create() {
|
|
if ($this->request->isPost()) {
|
|
$data = $this->request->post();
|
|
if (empty($data) || !is_array($data)) {
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
$validaterule = [
|
|
'department' => 'require',
|
|
'job_name' => 'require',
|
|
'count' => 'require',
|
|
'experience_requirement' => 'require',
|
|
'education' => 'require',
|
|
'job_address' => 'require',
|
|
'salary' => 'require',
|
|
'workfare' => 'require',
|
|
'job_responsibility' => 'require',
|
|
'job_requirement' => 'require',
|
|
'publish_time' => 'require',
|
|
'end_time' => 'require',
|
|
];
|
|
$validatemsg = [
|
|
'job_name.require' => '岗位名称不能为空',
|
|
'department.require' => '部门不能为空',
|
|
'count.require' => '招聘人数不能为空',
|
|
'experience_requirement.require' => '经验要求不能为空',
|
|
'education.require' => '学历要求不能为空',
|
|
'job_address.require' => '工作地址不能为空',
|
|
'salary.require' => '薪资待遇不能为空',
|
|
'workfare.require' => '福利不能为空',
|
|
'job_responsibility.require' => '岗位职责不能为空',
|
|
'job_requirement.require' => '岗位要求不能为空',
|
|
// 'cid.between' => '所属上级值无效',
|
|
];
|
|
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
|
if (true !== $valid_result) {
|
|
return $this->error($valid_result);
|
|
}
|
|
$sort = intval($data['sort']);
|
|
|
|
$insert_data = [
|
|
'department' => $data['department'],
|
|
'job_name' => $data['job_name'],
|
|
'count' => $data['count'],
|
|
'experience_requirement' => $data['experience_requirement'],
|
|
'education' => $data['education'],
|
|
'job_address' => $data['job_address'],
|
|
'salary' => $data['salary'],
|
|
'workfare' => $data['workfare'],
|
|
'sort' => $sort,
|
|
'publish_time' => date('Y-m-d', strtotime($data['publish_time'])),
|
|
'end_time' => date('Y-m-d', strtotime($data['end_time'])),
|
|
'job_responsibility' => $data['job_responsibility'],
|
|
'job_requirement' => $data['job_requirement'],
|
|
'stat' => 0,
|
|
'create_time' => date('Y-m-d H:i:s', time()),
|
|
];
|
|
|
|
$result = model('job')->insertRow($insert_data);
|
|
if (empty($result)) {
|
|
$this->error('新增失败');
|
|
}
|
|
$this->success('新增成功', url('/admin/job/lists'));
|
|
}
|
|
}
|
|
|
|
public function update() {
|
|
$data = $this->request->post();
|
|
if (empty($data) || !is_array($data) || !$data['id']) {
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
$validaterule = [
|
|
'department' => 'require',
|
|
'job_name' => 'require',
|
|
'count' => 'require',
|
|
'experience_requirement' => 'require',
|
|
'education' => 'require',
|
|
'job_address' => 'require',
|
|
'salary' => 'require',
|
|
'workfare' => 'require',
|
|
'job_responsibility' => 'require',
|
|
'job_requirement' => 'require',
|
|
'publish_time' => 'require',
|
|
'end_time' => 'require',
|
|
];
|
|
$validatemsg = [
|
|
'job_name.require' => '岗位名称不能为空',
|
|
'department.require' => '部门不能为空',
|
|
'count.require' => '招聘人数不能为空',
|
|
'experience_requirement.require' => '经验要求不能为空',
|
|
'education.require' => '学历要求不能为空',
|
|
'job_address.require' => '工作地址不能为空',
|
|
'salary.require' => '薪资待遇不能为空',
|
|
'workfare.require' => '福利不能为空',
|
|
'job_responsibility.require' => '岗位职责不能为空',
|
|
'job_requirement.require' => '岗位要求不能为空',
|
|
// 'cid.between' => '所属上级值无效',
|
|
];
|
|
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
|
if (true !== $valid_result) {
|
|
return $this->error($valid_result);
|
|
}
|
|
$sort = intval($data['sort']);
|
|
|
|
$update_data = [
|
|
'department' => $data['department'],
|
|
'job_name' => $data['job_name'],
|
|
'count' => $data['count'],
|
|
'experience_requirement' => $data['experience_requirement'],
|
|
'education' => $data['education'],
|
|
'job_address' => $data['job_address'],
|
|
'salary' => $data['salary'],
|
|
'workfare' => $data['workfare'],
|
|
'sort' => $sort,
|
|
'publish_time' => date('Y-m-d', strtotime($data['publish_time'])),
|
|
'end_time' => date('Y-m-d', strtotime($data['end_time'])),
|
|
'job_responsibility' => $data['job_responsibility'],
|
|
'job_requirement' => $data['job_requirement'],
|
|
'stat' => 0,
|
|
// 'create_time' => date('Y-m-d H:i:s', time()),
|
|
];
|
|
|
|
$result = model('job')->where(['id' => $data['id']])->update($update_data);
|
|
if (empty($result)) {
|
|
$this->error('更新失败');
|
|
}
|
|
$this->success('更新成功', url('/admin/job/lists'));
|
|
}
|
|
|
|
|
|
|
|
public function content() {
|
|
$aid = $this->request->param('id', 0);
|
|
$aid = intval($aid);
|
|
if ($aid > 0) {
|
|
$addproduct = Loader::model('ProductAddition')->getRow(['aid' => $aid], ['id', 'aid', 'content']);
|
|
if (empty($addproduct)) {
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
$value = [
|
|
'addproduct' => $addproduct,
|
|
];
|
|
$this->assign($value);
|
|
$this->view->engine(['type' => 'php', 'view_suffix' => 'html']);
|
|
return $this->fetch();
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function modallists() {
|
|
$inputid = $this->request->param('inputid', '', 'urldecode');
|
|
$titleid = $this->request->param('titleid', '', 'urldecode');
|
|
$callback = $this->request->param('callback', '', 'urldecode');
|
|
$filter_name = $this->request->param('filter_name', '', 'urldecode');
|
|
$arg_where = array('stat' => 0);
|
|
$arg_order = array('sort' => 'asc', 'id' => 'desc');
|
|
$arg_field = array('id', 'name', 'item_number', 'tags', 'list_bk_img',);
|
|
if (!empty($filter_name)) {
|
|
$arg_where['brand_id'] = ['like', '%' . trim($filter_name) . '%'];
|
|
//$arg_where['brand_id'] = ['like', '%' . trim($filter_name) . '%'];
|
|
}
|
|
Config::set('url_common_param', true);
|
|
Config::set('paginate.query', array_filter(['inputid' => $inputid, 'titleid' => $titleid, 'callback' => $callback, 'filter_name' => $filter_name])); //分页参数
|
|
$dataObject = city(session('cit'),'Product')->getPageList($arg_where, $arg_order, $arg_field, 12, false);
|
|
$value = [
|
|
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
|
|
'page' => $dataObject->render(),
|
|
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
|
|
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
|
|
'total' => $dataObject->total(),
|
|
'inputid' => $inputid,
|
|
'titleid' => $titleid,
|
|
'callback' => $callback,
|
|
'filter_name' => $filter_name,
|
|
];
|
|
$this->assign($value);
|
|
Config::set('default_ajax_return', 'html');
|
|
$this->view->engine(['type' => 'php', 'view_suffix' => 'html']);
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function updatesort() {
|
|
$id = $this->request->param('id', 0);
|
|
$sort = $this->request->param('sort', 0);
|
|
$sort = intval($sort);
|
|
$id = intval($id);
|
|
if ($id > 0 && $sort <= 9999) {
|
|
$model = model('job')->updateRow(['id' => $id, 'sort' => $sort]);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function toggleisnew() {
|
|
$id = $this->request->param('id', 0);
|
|
$flag = $this->request->param('flag', 0);
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$model = city(session('cit'),'Product')->updateRow(['id' => $id, 'isnew' => $flag]);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function toggleishot() {
|
|
$id = $this->request->param('id', 0);
|
|
$flag = $this->request->param('flag', 0);
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$model = city(session('cit'),'Product')->updateRow(['id' => $id, 'ishot' => $flag]);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function togglerecommend() {
|
|
$id = $this->request->param('id', 0);
|
|
$flag = $this->request->param('flag', 0);
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$model = city(session('cit'),'Product')->updateRow(['id' => $id, 'recommend' => $flag]);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function toggleonsale() {
|
|
$id = $this->request->get('id', 0);
|
|
$flag = $this->request->get('flag', 0);
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$result = city(session('cit'),'Product')->updateRow(['id' => $id, 'is_onsale' => $flag]);
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function copy($id = 0) {
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$product = city(session('cit'),'Product')->getRow($id);
|
|
if (empty($product)) {
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
$value['product'] = $product;
|
|
} else {
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
$value['addproduct'] = Loader::model('ProductAddition')->getRow(['aid' => $id]);
|
|
$cid = isset($product['cid']) ? $product['cid'] : 0;
|
|
$arg_where = array('pid' => 0, 'stat' => 0);
|
|
$arg_order = array('sort' => 'asc', 'id' => 'asc');
|
|
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
|
|
$categoryOptions = city(session('cit'),'ProductCategory')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
|
|
$arg_where = array('stat' => 0);
|
|
$arg_order = array('id' => 'asc');
|
|
$arg_field = array('id', 'name');
|
|
$brandOption = Loader::model('Brand')->getOption($product['brand_id'], $arg_where, $arg_order, $arg_field, 100);
|
|
$typeOption = Loader::model('AttributeType')->getOption($product['type_id'], $arg_where, $arg_order, $arg_field, 100);
|
|
$supplierOption = Loader::model('Supplier')->getOption($product['supplier_id'], $arg_where, $arg_order, $arg_field, 100);
|
|
$value['supplierOption'] = $supplierOption;
|
|
$value['typeOption'] = $typeOption;
|
|
$value['brandOption'] = $brandOption;
|
|
$value['categoryOptions'] = $categoryOptions;
|
|
$value['cid'] = $cid;
|
|
$this->assign($value);
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function movecategory() {
|
|
$cid = $this->request->post('cid', 0);
|
|
$ids = $this->request->post('ids');
|
|
$cid = intval($cid);
|
|
if ($this->request->isPost() && $cid && $ids) {
|
|
$result = city(session('cit'),'Product')->updateRows(['cid' => $cid], ['id' => ['in', $ids]]);
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function recommends() {
|
|
$ids = $this->request->post('ids');
|
|
if ($this->request->isPost() && $ids) {
|
|
$result = city(session('cit'),'Product')->updateRows(['recommend' => 1], ['id' => ['in', $ids]]);
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
|
|
|
|
public function recycle() {
|
|
$skeyword = $this->request->get('skeyword', '', 'urldecode');
|
|
$arg_where = ['a.stat' => -1, 'a.siteid' => $this->siteid];
|
|
$arg_order = ['a.id' => 'desc'];
|
|
$arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
|
|
if (!empty($skeyword)) {
|
|
$skeyword = trim($skeyword);
|
|
$arg_where['a.name|a.description'] = ['like', '%' . $skeyword . '%'];
|
|
$search['skeyword'] = $skeyword;
|
|
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
|
|
} else {
|
|
$search['skeyword'] = '';
|
|
}
|
|
$dataObject = city(session('cit'),'Product')->getRecycleLists($arg_where, $arg_order, $arg_field, 12);
|
|
$argc_where = array('pid' => 0, 'stat' => 0);
|
|
$argc_order = array('sort' => 'asc', 'id' => 'asc');
|
|
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
|
|
$categoryOptions = city(session('cit'),'ProductCategory')->getCategoryOptions(0, $argc_where, $argc_order, $argc_field, 100);
|
|
$value = [
|
|
'categoryOptions' => $categoryOptions,
|
|
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
|
|
'page' => $dataObject->render(),
|
|
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
|
|
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
|
|
'search' => $search,
|
|
];
|
|
$this->assign($value);
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function recovery($id = 0) {
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$model = city(session('cit'),'Product')->updateRow(['id' => $id, 'stat' => 0]);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function recoverys() {
|
|
$ids = $this->request->post('ids');
|
|
if ($this->request->isPost() && $ids) {
|
|
$result = city(session('cit'),'Product')->updateRows(['stat' => 0], ['id' => ['in', $ids]]);
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
|
|
public function destroy($id = 0) {
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$result = city(session('cit'),'Product')->destroyRow($id);
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
public function destroys() {
|
|
$ids = $this->request->post('ids');
|
|
if ($this->request->isPost() && $ids) {
|
|
$result = city(session('cit'),'Product')->destroyRows($ids);
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/product/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
public function cont(){
|
|
$data = $_POST;
|
|
$id = $data['product'];
|
|
$arg_order = ['a.id' => 'desc'];
|
|
$arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
|
|
|
|
foreach ($id as $where ){
|
|
$where = ['a.id'=>$where,
|
|
'a.stat'=>0
|
|
];
|
|
$result = city(session('cit'),'product')->getProductLists($where,$arg_order,$arg_field,12);
|
|
}
|
|
|
|
dump($result);die;
|
|
$this->assign($result);
|
|
return $this->fetch('product/add');
|
|
}
|
|
public function productreated(){
|
|
$inputid = $this->request->param('inputid', '', 'urldecode');
|
|
$titleid = $this->request->param('titleid', '', 'urldecode');
|
|
$callback = $this->request->param('callback', '', 'urldecode');
|
|
$filter_name = $this->request->param('filter_name', '', 'urldecode');
|
|
$arg_where = array('stat' => 0);
|
|
$arg_order = array('sort' => 'asc', 'id' => 'desc');
|
|
$arg_field = array('id', 'name', 'item_number', 'tags', 'picture',);
|
|
if (!empty($filter_name)) {
|
|
$arg_where['name'] = ['like', '%' . trim($filter_name) . '%'];
|
|
}
|
|
Config::set('url_common_param', true);
|
|
Config::set('paginate.query', array_filter(['inputid' => $inputid, 'titleid' => $titleid, 'callback' => $callback, 'filter_name' => $filter_name])); //分页参数
|
|
$dataObject = city(session('cit'),'Product')->getPageList($arg_where, $arg_order, $arg_field, 12, false);
|
|
$value = [
|
|
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
|
|
'page' => $dataObject->render(),
|
|
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
|
|
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
|
|
'total' => $dataObject->total(),
|
|
'inputid' => $inputid,
|
|
'titleid' => $titleid,
|
|
'callback' => $callback,
|
|
'filter_name' => $filter_name,
|
|
];
|
|
$this->assign($value);
|
|
Config::set('default_ajax_return', 'html');
|
|
$this->view->engine(['type' => 'php', 'view_suffix' => 'html']);
|
|
return $this->fetch();
|
|
}
|
|
public function chickbrandid($id){
|
|
$where = ['brand_id'=>$id];
|
|
$product = city(session('cit'),'Product')->where($where)->find();
|
|
if($product){
|
|
echo '产品型号已经存在,无需重新添加';
|
|
}
|
|
exit;
|
|
}
|
|
|
|
public function export() {
|
|
$arg_where = ['a.stat' => 0, 'a.siteid' => $this->siteid];
|
|
$data = $this->request->param();
|
|
|
|
if (isset($data['name']) && $data['name']) {
|
|
$arg_where['a.name'] = ['like', '%' . $data['name'] . '%'];
|
|
$search['name'] = $data['name'];
|
|
} else {
|
|
$search['name'] = '';
|
|
}
|
|
if (isset($data['cid']) && $data['cid']) {
|
|
$childIDArray = city(session('cit'),'product_category')->getChildIDArray($data['cid']);
|
|
$arg_where['a.cid'] = count($childIDArray) == 1 ? $data['cid'] : ['in', $childIDArray];
|
|
$search['cid'] = $data['cid'];
|
|
} else {
|
|
$search['cid'] = 0;
|
|
}
|
|
if (isset($data['tags']) && $data['tags']) {
|
|
$arg_where['a.tags'] = ['like', '%' . $data['tags'] . '%'];
|
|
$search['tags'] = $data['tags'];
|
|
} else {
|
|
$search['tags'] = '';
|
|
}
|
|
|
|
$search['timebegin'] = isset($data['timebegin']) ? strtotime($data['timebegin']) : 0;
|
|
$search['timeend'] = isset($data['timeend']) ? strtotime($data['timeend']) : 0;
|
|
if ($search['timeend'] - $search['timebegin'] > 0) {
|
|
$arg_where['a.createtime'] = ['between', [$search['timebegin'], $search['timeend']]];
|
|
} else {
|
|
if ($search['timebegin'] > 0 && empty($search['timeend'])) {
|
|
$arg_where['a.createtime'] = ['gt', $search['timebegin']];
|
|
}
|
|
}
|
|
|
|
if (!empty($data['field'])) {
|
|
$fields = $data['field'];
|
|
} else {
|
|
$fields = array('id' => 'ID', 'brand_id' => '产品型号', 'url' => '产品链接', 'cid' => '所属分类', 'name' => '产品名称', 'shortname' => '副标题', 'recommend' => '是否推荐', 'ishot' => '是否热门', 'multi_color' => '是否有多颜色', 'list_bk_img' => '是否有一级列表图' , 'is_list2' => '是否有二级列表图', 'url_tm' => '天猫链接', 'url_jd' => '京东链接', 'seo_title' => 'SEO标题', 'seo_keyword' => 'SEO关键词', 'seo_description' => 'SEO描述', 'product_view' => '产品参数', 'related_product' => '关联产品', 'driver' => '是否有驱动', 'is_comment' => '是否有评论', 'createtime' => '发布时间');
|
|
}
|
|
|
|
$argc_where = array('pid' => 0, 'stat' => 0);
|
|
$argc_order = array('sort' => 'asc', 'id' => 'asc');
|
|
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
|
|
$categoryOptions = city(session('cit'),'product_category')->getCategoryOptions($search['cid'], $argc_where, $argc_order, $argc_field, 100);
|
|
|
|
if (empty($data['submit'])) {
|
|
$value = ['categoryOptions' => $categoryOptions, 'fields' => $fields];
|
|
$this->assign($value);
|
|
return $this->fetch();
|
|
}
|
|
|
|
$arg_order = ['c.sort' => 'asc', 'c.id' => 'asc'];
|
|
$arg_field = array_map(function($value) {return 'a.' . $value;}, array_keys($fields));
|
|
$arg_field['c.id'] = 'categoryid';
|
|
$arg_field['c.name'] = 'categoryname';
|
|
$arg_field['c.pid'] = 'pid';
|
|
|
|
set_time_limit(36000);
|
|
ini_set('memory_limit', '512M');
|
|
$total = city(session('cit'),'product')->getExportSearchProductLists($arg_where, $arg_order, null, true);
|
|
$page_size = 1000;
|
|
$totalpage = ceil($total / $page_size);
|
|
$sheet_size = 5 * $page_size;
|
|
|
|
$cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');
|
|
Loader::import('phpexcel.Classes.PHPExcel', EXTEND_PATH);
|
|
Loader::import('phpexcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory');
|
|
$objPHPExcel = new \PHPExcel();
|
|
// Set document properties
|
|
$objPHPExcel->getProperties()->setCreator("Call of Duty")
|
|
->setLastModifiedBy("Call of Duty")
|
|
->setTitle("Office 2007 XLSX Cod Document")
|
|
->setSubject("Office 2007 XLSX Cod Document")
|
|
->setDescription("Cod document for Office 2007 XLSX, generated using PHP classes.")
|
|
->setKeywords("office 2007 openxml php")
|
|
->setCategory("Cod result file");
|
|
$page = 0;
|
|
$sheet = 0;
|
|
do {
|
|
$start_index = $page * $page_size;
|
|
$arg_order = ['a.cid' => 'asc', 'a.id' => 'asc'];
|
|
$datainfo = city(session('cit'),'product')->getExportSearchProductLists($arg_where, $arg_order, [$start_index, $page_size], false, $arg_field);
|
|
|
|
if (!empty($datainfo)) {
|
|
if (($start_index % $sheet_size) == 0) {
|
|
if ($sheet) {
|
|
$objPHPExcel->createSheet();
|
|
}
|
|
$sheet++;
|
|
$i = 0;
|
|
foreach ($fields as $key => $value) {
|
|
$objPHPExcel->setActiveSheetIndex($sheet - 1)->setCellValue($cellName[$i] . '1', $value);
|
|
$i++;
|
|
}
|
|
$objPHPExcel->getActiveSheet()->setTitle('sheet' . $sheet);
|
|
$index = 1;
|
|
}
|
|
|
|
foreach ($datainfo as $value) {
|
|
if (isset($value['cid'])) {
|
|
$value->data('cid', $value['categoryname']);
|
|
}
|
|
if (isset($value['list_bk_img']) && $value['list_bk_img'] != '') {
|
|
$value->data('list_bk_img', 1);
|
|
} else {
|
|
$value->data('list_bk_img', 0);
|
|
}
|
|
if (isset($value['createtime'])) {
|
|
$value->data('createtime', date('Y-m-d H:i:s', $value['createtime']));
|
|
}
|
|
if (isset($value['related_product'])) {
|
|
$value->data('related_product', $value['related_product']);
|
|
}
|
|
if (isset($value['product_view'])) {
|
|
$value->data('product_view', json_encode(unserialize($value['product_view']), JSON_UNESCAPED_UNICODE));
|
|
}
|
|
if (isset($value['driver'])) {
|
|
$value->data('driver', $value['driver']);
|
|
}
|
|
$index++;
|
|
$i = 0;
|
|
foreach ($fields as $key => $field) {
|
|
if ($key == 'picture') {
|
|
$image = '.' . $this->request->root() . $value['picture'];
|
|
if (@fopen($image, 'r')) {
|
|
$objDrawing = new \PHPExcel_Worksheet_Drawing();
|
|
$objDrawing->setPath($image);
|
|
$objDrawing->setHeight(50);
|
|
$objDrawing->setWidth(50);
|
|
$objDrawing->setCoordinates($cellName[$i] . $index);
|
|
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
|
|
}
|
|
} else {
|
|
$objPHPExcel->setActiveSheetIndex($sheet - 1)->setCellValue($cellName[$i] . $index, $value[$key]);
|
|
}
|
|
$i++;
|
|
}
|
|
}
|
|
usleep(10000);
|
|
}
|
|
$page++;
|
|
if ($page > 650) {
|
|
break;
|
|
}
|
|
} while ($page < $totalpage);
|
|
$objPHPExcel->setActiveSheetIndex(0);
|
|
// Redirect output to a client's web browser (Excel2007)
|
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
header('Content-Disposition: attachment;filename="' . date('YmdHis') . '.xlsx"');
|
|
header('Cache-Control: max-age=0');
|
|
// If you're serving to IE 9, then the following may be needed
|
|
header('Cache-Control: max-age=1');
|
|
// If you're serving to IE over SSL, then the following may be needed
|
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
|
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
|
|
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
|
header('Pragma: public'); // HTTP/1.0
|
|
|
|
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
|
|
$objWriter->save('php://output');
|
|
exit;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|