File: /www/wwwroot/bb.cwoyt.com/Application/Admin/Controller/ProductController.class.php
<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 赛脑 <2233759493@qq.com> <http://www.sn.com>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use User\Api\UserApi as UserApi;
use COM\Page;
/**
* 产品控制器
* @author 赛脑 <2233759493@qq.com>
*/
class ProductController extends AdminController
{
public $infoadmin = array();
public function __construct()
{
parent::__construct();
$perid = M('member')->where('uid = ' . UID)->getField('perid');
$infoadmin = M('permissions')->where('perid = ' . $perid)->field('product,list')->find();
if ($infoadmin['product']) {
$infoadmin['product'] = explode(',', $infoadmin['product']);
}
if ($infoadmin['list']) {
$infoadmin['list'] = explode(',', $infoadmin['list']);
}
if (!$infoadmin['product']) {
$this->error('参数错误!');
}
$this->infoadmin = $infoadmin;
$nav_type = 'product';
$nav_type_li = 'pro';
$this->assign('nav_type', $nav_type);
$this->assign('nav_type_li', $nav_type_li);
}
/*
*手机版产品列表选择
*/
public function orderpro()
{
if (UID != 1) {
$infoadmin = $this->peradmin;
if ($infoadmin['list']) {
$where['proid'] = array('in', $infoadmin['list']);
$list = M('product')->where($where)->order('sort asc,proid desc')->select();
}
if (!in_array("pro", $infoadmin['product'])) {
$this->error('参数错误!');
}
} else {
$list = M('product')->where($where)->order('sort asc,proid desc')->select();
}
$this->assign('list', $list);
$this->display();
}
/**
* 产品列表
* @author 赛脑 <2233759493@qq.com>
*/
public function index()
{
if (I('get.cid') != 'no' && I('get.cid') != '') {
$where['cid'] = array('eq', I('get.cid'));
}
if (I('get.title') != 'no' && I('get.title') != '') {
$where['title'] = array('like', '%' . I('get.title') . '%');
}
if (UID != 1) {
$infoadmin = $this->peradmin;
if ($infoadmin['list']) {
$where['proid'] = array('in', $infoadmin['list']);
$count = M('product')->where($where)->count();
$page = new Page($count, 50);
$list = M('product')->where($where)->order('sort asc,proid desc')->limit($page->firstRow . ',' . $page->listRows)->select();
$pages = $page->show();
}
if (!in_array("pro", $infoadmin['product'])) {
$this->error('参数错误!');
}
} else {
$count = M('product')->where($where)->count();
$page = new Page($count, 50);
$list = M('product')->where($where)->order('sort asc,proid desc')->limit($page->firstRow . ',' . $page->listRows)->select();
$pages = $page->show();
}
$style = require './Application/Admin/Conf/style.php';
$temp = M('template')->field('tid,name')->select();
foreach ($list as $k => $v) {
$list[$k]['style'] = $style[$v['style']];
$list[$k]['temp'] = M('template')->where('tid=' . $v['template'])->getField('name');
$list[$k]['class'] = M('class')->where('cid=' . $v['cid'])->getField('title');
}
$class = M('class')->select();
$c_title = M('class')->where('cid = ' . I('get.cid'))->getField('title');
$value = M('config')->where('id = 88')->getField('value');
$language = M('config')->where('id = 97')->getField('value');
$cookie = M('config')->where('id = 105')->getField('value');
$this->assign('cookie', $cookie);
$this->assign('class', $class);
$this->assign('c_title', $c_title);
$this->assign('cid', I('get.cid'));
$this->assign('title', I('get.title'));
$this->assign('language', $language);
$this->assign('count', $count);
$this->assign('_list', $list);
$this->assign('_page', $pages);
$this->assign('value', $value);
$this->meta_title = '产品管理';
$this->display();
}
public function audit()
{
if (IS_POST) {
$data = array(
'id' => I('post.id'),
'title' => I('post.title'),
'content' => I('post.content'),
'status' => I('post.status'),
);
if ($data['status'] == 'on') {
$data['status'] = 0;
} else {
$data['status'] = 1;
}
if (M('audit')->where('id = ' . $data['id'])->find()) {
M('audit')->save($data);
} else {
M('audit')->add($data);
}
$this->success('操作成功!');
} else {
$proid = I('get.proid');
$type = I('get.type');
$audit = M('audit')->where('id = ' . $proid)->find();
$info = M('product')->where('proid = ' . $proid)->field('template')->find();
$info['temp'] = M('template')->where('tid = ' . $info['template'])->field('pro_title,size_title,color_title')->find();
$this->assign('audit', $audit);
$this->assign('type', $type);
$this->assign('info', $info);
$this->meta_title = '产品管理';
$this->display();
}
}
public function sorts()
{
if (IS_POST) {
foreach (I('post.sort') as $k => $v) {
M('product')->where('proid = ' . $k)->save(array('sort' => $v));
}
}
$this->success('操作成功!', U('index'));
}
/*
*产品添加
*/
public function add()
{
if (IS_POST) {
$images = implode(',', I('post.images'));
$starttime = I('post.starttime') ? strtotime(I('post.starttime')) : '';
$endtime = I('post.endtime') ? strtotime(I('post.endtime')) : '';
$data = array(
'title' => I('post.title'),
'cid' => I('post.cid'),
'parameter' => I('post.parameter'),
'description' => I('post.description'),
'price_addition' => I('post.price_addition'),
'song' => I('post.song'),
'num_status' => I('post.num_status'),
'starttime' => $starttime,
'endtime' => $endtime,
'thumb' => I('post.thumb'),
'foot_thumb' => I('post.foot_thumb'),
'images' => $images,
'review_status' => I('post.review_status'),
'review_num' => I('post.review_num'),
'review' => I('post.review'),
'oldprice' => I('post.oldprice'),
'price' => I('post.price'),
'discount' => I('post.discount'),
'currency' => I('post.currency'),
'number' => I('post.number'),
'time_status' => I('post.time_status'),
'status' => I('post.status'),
'time_type' => I('post.time_type'),
'time_sum' => I('post.time_sum'),
'template' => I('post.template'),
'style' => I('post.style'),
'good' => I('post.good'),
'copyright' => I('post.copyright'),
'cichun' => I('post.cichun'),
'yanse' => I('post.yanse'),
'addtime' => time()
);
if ($data['status'] == 'on') {
$data['status'] = 1;
} else {
$data['status'] = 2;
}
if ($data['time_status'] == 'on') {
$data['time_status'] = 0;
} else {
$data['time_status'] = 1;
}
if ($data['num_status'] == 'on') {
$data['num_status'] = 0;
} else {
$data['num_status'] = 1;
}
if ($data['review_status'] == 'on') {
$data['review_status'] = 0;
} else {
$data['review_status'] = 1;
}
if ($data['good'] == 'on') {
$data['good'] = 1;
} else {
$data['good'] = 2;
}
if ($data['time_type'] == 2) {
$data['endtime'] = time();
}
action_log('pro_add', 'member', UID, UID);
$proid = M('product')->add($data);
$data1 =array(
'proid' => $proid,
'content' => I('post.content'),
// 'cichun' => I('post.cichun'),
// 'yanse' => I('post.yanse'),
);
$proid1 = M('product_data')->add($data1);
if (I('post.tc_title') != '' && I('post.tc_price') != '' && I('post.tc_number') != '' && I('post.tc_thumb') != '') {
$chandu = count($_POST['tc_title']); //总长度
for ($i = 0; $i < $chandu; $i++) {
$User = M("product_norms"); // 实例化User对象
$data['title'] = $_POST['tc_title'][$i];
$data['number'] = $_POST['tc_number'][$i];
$data['price'] = $_POST['tc_price'][$i];
$data['thumb'] = $_POST['tc_thumb'][$i];
$data['type'] = 1;
$data['proid'] = $proid;
$id = $User->add($data);
}
}
if (I('post.sx1_title') != '' && I('post.sx1_tc_thumb') != '') {
$chandu = count($_POST['sx1_title']);
for ($i = 0; $i < $chandu; $i++) {
$User = M("product_norms"); // 实例化User对象
$data['title'] = $_POST['sx1_title'][$i];
$data['thumb'] = $_POST['sx1_tc_thumb'][$i];
$data['type'] = 2;
$data['proid'] = $proid;
$data['shuxi'] = $_POST['shuxi2'];
$User->add($data);
}
}
if (I('post.sx2_title') != '' && I('post.sx2_tc_thumb') != '') {
$chandu = count($_POST['sx2_title']);
for ($i = 0; $i < $chandu; $i++) {
$User = M("product_norms"); // 实例化User对象
$data['title'] = $_POST['sx2_title'][$i];
$data['thumb'] = $_POST['sx2_tc_thumb'][$i];
$data['type'] = 3;
$data['proid'] = $proid;
$data['shuxi'] = $_POST['shuxi3'];
$User->add($data);
}
}
$this->success('操作成功!', U('index'));
} else {
$temp = M('template')->field('tid,name')->select();
$s = date('Y-m-d H:i', time());
$e = date('Y-m-d H:i', time());
if (UID != 1) {
$infoadmin = $this->peradmin;
if (!in_array("pro_add", $infoadmin['product'])) {
$this->error('参数错误!');
}
}
$style = require './Application/Admin/Conf/style.php';
$class = M('class')->order('sort asc')->select();
$this->assign('s', $s);
$this->assign('e', $e);
$this->assign('style', $style);
$this->assign('class', $class);
$this->meta_title = '产品管理';
$this->assign('temp', $temp);
$this->display();
}
//新加开始
// if (IS_POST) {
// $datatc = array(
// 'proid' => I('post.cid'),
// 'title' => trim(I('post.tc_title')),
// 'thumb' => I('post.tc_thumb'),
// 'type' => I('post.tc_type'),
// 'number' => trim(I('post.tc_number', 0)),
// 'price' => trim(I('post.tc_price', 0)),
// 'total_number' => trim(I('post.total_number', 0)),
// );
// echo $datatc['title'];
// echo $datatc['price'];
// M('product_norms')->add($datatc);
// $this->success('数据添加成功!');
// if ($data_sx1['title'] != '') {
// $data_sx1 = array(
// 'proid' => I('post.cid'),
// 'title' => trim(I('post.sx1_title')),
// 'thumb' => I('post.sx1_thumb'),
// 'type' => I('post.sx1_type'),
// );
// M('product_norms')->add($datatc_sx1);
// $this->success('数据添加成功!');
// }
// if ($data_sx2['title'] != '') {
// $data_sx2 = array(
// 'proid' => I('post.cid'),
// 'title' => trim(I('post.sx2_title')),
// 'thumb' => I('post.sx2_thumb'),
// 'type' => I('post.sx2_type'),
// );
// M('product_norms')->add($datatc_sx2);
// $this->success('数据添加成功!');
// }
// }
//新加结束
}
/*
*产品修改
*/
public function update()
{
if (IS_POST) {
$images = implode(',', I('post.images'));
$starttime = I('post.starttime') ? strtotime(I('post.starttime')) : '';
$endtime = I('post.endtime') ? strtotime(I('post.endtime')) : '';
$data = array(
'proid' => I('post.proid'),
'cid' => I('post.cid'),
'parameter' => I('post.parameter'),
'description' => I('post.description'),
'price_addition' => I('post.price_addition'),
'title' => I('post.title'),
'song' => I('post.song'),
'num_status' => I('post.num_status'),
'starttime' => $starttime,
'endtime' => $endtime,
'thumb' => I('post.thumb'),
'foot_thumb' => I('post.foot_thumb'),
'images' => $images,
'review_status' => I('post.review_status'),
'review_num' => I('post.review_num'),
'review' => I('post.review'),
'oldprice' => I('post.oldprice'),
'price' => I('post.price'),
'discount' => I('post.discount'),
'currency' => I('post.currency'),
'number' => I('post.number'),
'time_status' => I('post.time_status'),
'status' => I('post.status'),
'time_type' => I('post.time_type'),
'time_sum' => I('post.time_sum'),
'template' => I('post.template'),
'style' => I('post.style'),
'good' => I('post.good'),
'copyright' => I('post.copyright'),
'cichun' => I('post.cichun'),
'yanse' => I('post.yanse'),
'addtime' => time()
);
if ($data['status'] == 'on') {
$data['status'] = 1;
} else {
$data['status'] = 2;
}
if ($data['time_status'] == 'on') {
$data['time_status'] = 0;
} else {
$data['time_status'] = 1;
}
if ($data['num_status'] == 'on') {
$data['num_status'] = 0;
} else {
$data['num_status'] = 1;
}
if ($data['review_status'] == 'on') {
$data['review_status'] = 0;
} else {
$data['review_status'] = 1;
}
if ($data['good'] == 'on') {
$data['good'] = 1;
} else {
$data['good'] = 2;
}
if ($data['time_type'] == 2) {
$data['endtime'] = time();
}
action_log('pro_update', 'member', UID, UID);
M('product')->save($data);
M('product_data')->where('proid = ' . $data['proid'])->save(array('content' => I('post.content')));
$proid1 = I('post.proid');
M('product_norms')->where('proid='.$proid1)->delete();
if (I('post.tc_title') != '' && I('post.tc_price') != '' && I('post.tc_number') != '' && I('post.tc_thumb') != '' && I('post.total_number') != '') {
$chandu = count($_POST['tc_title']); //总长度
for ($i = 0; $i < $chandu; $i++) {
$User = M("product_norms"); // 实例化User对象
$data['title'] = $_POST['tc_title'][$i];
$data['number'] = $_POST['tc_number'][$i];
$data['price'] = $_POST['tc_price'][$i];
$data['thumb'] = $_POST['tc_thumb'][$i];
$data['total_number'] = $_POST['total_number'][$i];
$data['type'] = 1;
$data['proid'] = $proid1;
$User->add($data);
}
}
if (I('post.sx1_title') != '' && I('post.sx1_tc_thumb') != '') {
$chandu = count($_POST['sx1_title']);
for ($i = 0; $i < $chandu; $i++) {
$User = M("product_norms"); // 实例化User对象
$data['title'] = $_POST['sx1_title'][$i];
$data['thumb'] = $_POST['sx1_tc_thumb'][$i];
$data['type'] = 2;
$data['proid'] = $proid1;
$User->add($data);
}
}
if (I('post.sx2_title') != '' && I('post.sx2_tc_thumb') != '') {
$chandu = count($_POST['sx2_title']);
for ($i = 0; $i < $chandu; $i++) {
$User = M("product_norms"); // 实例化User对象
$data['title'] = $_POST['sx2_title'][$i];
$data['thumb'] = $_POST['sx2_tc_thumb'][$i];
$data['type'] = 3;
$data['proid'] = $proid1;
$User->add($data);
}
}
$this->success('操作成功!', U('index'));
} else {
$proid = I('get.proid');
$norms_type1 = M('product_norms')->where('type=1 AND proid = ' . $proid)->select();
$norms_type2 = M('product_norms')->where('type=2 AND proid = ' . $proid)->select();
$norms_type3 = M('product_norms')->where('type=3 AND proid = ' . $proid)->select();
// echo M('product')->_sql();
// var_dump($norms);die;
$info = M('product')->where('proid = ' . $proid)->find();
$info['content'] = M('product_data')->where('proid = ' . $info['proid'])->getField('content');
$s = date('Y-m-d H:i:s', $info['starttime']);
$e = date('Y-m-d H:i:s', $info['endtime']);
$temp = M('template')->field('tid,name,size_title,color_title')->select();
$info['temp'] = M('template')->where('tid = ' . $info['template'])->field('pro_title,size_title,color_title')->find();
if (UID != 1) {
$infoadmin = $this->peradmin;
if (!in_array("pro_update", $infoadmin['product'])) {
$this->error('参数错误!');
}
if (!in_array($proid, $infoadmin['list'])) {
$this->error('参数错误!');
}
}
$style = require './Application/Admin/Conf/style.php';
$class = M('class')->order('sort asc')->select();
//P($info);
// var_dump($norms);die;
// $norms_data = array();
// var_dump($norms_data);die;
$this->assign('info', $info);
$this->assign('norms_type1', $norms_type1);
$this->assign('norms_type2', $norms_type2);
$this->assign('norms_type3', $norms_type3);
$this->assign('style', $style);
$this->assign('class', $class);
$this->assign('s', $s);
$this->assign('e', $e);;
$this->assign('temp', $temp);
$this->meta_title = '产品管理';
$this->display();
}
}
/*
*删除产品
*/
public function del()
{
$proid = I('get.proid');
if (UID != 1) {
$infoadmin = $this->peradmin;
if (!in_array("pro_del", $infoadmin['product'])) {
$this->error('参数错误!');
}
if (!in_array($proid, $infoadmin['list'])) {
$this->error('参数错误!');
}
}
action_log('pro_del', 'member', UID, UID);
M('product')->where('proid = ' . $proid)->delete();
M('product_data')->where('proid = ' . $proid)->delete();
M('product_norms')->where('proid = ' . $proid)->delete();
M('audit')->where('proid = ' . $proid)->delete();
M('statistical')->where('proid = ' . $proid)->delete();
$this->success('删除成功!', U('index'));
}
/*
*批量删除产品
*/
public function del_arr()
{
foreach (I('post.proid') as $k => $v) {
if (UID != 1) {
$infoadmin = $this->peradmin;
if (!in_array($v, $infoadmin['list'])) {
$this->error('参数错误!');
}
}
M('product')->where('proid = ' . $v)->delete();
M('product_data')->where('proid = ' . $v)->delete();
M('product_norms')->where('proid = ' . $v)->delete();
M('audit')->where('proid = ' . $v)->delete();
M('statistical')->where('proid = ' . $v)->delete();
}
action_log('pro_del', 'member', UID, UID);
$this->success('删除成功!', U('index'));
}
public function gz()
{
$list = M('gzname')->select();
$proid = I('get.proid');
$type = I('get.type');
if (UID != 1) {
$infoadmin = $this->peradmin;
if (!in_array($proid, $infoadmin['list'])) {
$this->error('参数错误!');
}
}
$template = M('product')->where('proid = ' . $proid)->getField('template');
$info['temp'] = M('template')->where('tid = ' . $template)->field('pro_title,size_title,color_title')->find();
$value = M('config')->where('id = 88')->getField('value');
$this->assign('type', $type);
$this->assign('_list', $list);
$this->assign('proid', $proid);
$this->assign('info', $info);
$this->assign('value', $value);
$this->meta_title = '投放平台 ';
if (is_mobile()) {
$this->display('m-index');
} else {
$this->display();
}
}
public function htmlvalue()
{
$t = I('get.t', '0');
M('config')->where('id = 88')->save(array('value' => $t));
action_log('htmlvalue', 'member', UID, UID);
$this->success('操作成功!', U('index'));
}
public function language()
{
$t = I('get.t', '0');
M('config')->where('id = 97')->save(array('value' => $t));
$this->success('操作成功!', U('index'));
}
public function cookie()
{
$t = I('get.t', '0');
M('config')->where('id = 105')->save(array('value' => $t));
$this->success('操作成功!', U('index'));
}
}