SalesmangoodsController.php 2.6 KB
<?php
namespace app\admin\controller;

use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;

class SalesmangoodsController extends AdminBaseController{

    /**
     *业务员商品列表
     */
    public function salesman_list(){

        if($this -> request -> isPost()){
            $where = [
                'type' => 2,
            ];
            if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
                $start_time = strtotime($_POST['start_time']);
                $end_time = strtotime($_POST['end_time']);
                $where['create_time'] = [['>=',$start_time],['<=',$end_time]];
            }
            if(!empty($_POST['keyword'])){
                $keyword = $_POST['keyword'];
                $where['book_name'] = ['like',"%$keyword%"];
            }
            $data = Db::name('goods') -> group('book_name') -> where($where) -> paginate(12);
            $this -> assign('data',$data);
            return $this -> fetch();
        }else{
            $data = Db::name('goods') -> group('book_name') -> where('type',2) -> paginate(12);
            $this -> assign('data',$data);
            return $this -> fetch();
        }

    }

    /**
     * 业务员商品编辑查看
     */
    public function salesman_edit(){

        if($this -> request -> isPost()){
            if(!empty($_POST['det_img'])){
                $_POST['det_img'] = json_encode($_POST['det_img']);
                $_POST['det_name'] = json_encode($_POST['det_name']);
            }
            $data = Db::name('goods') -> update($_POST);
            if($data){
                $this -> success('保存成功',url('Salesmangoods/salesman_edit',array('id'=>$_POST['id'])));
            }else{
                $this -> error('保存失败');
            }
        }else{
            $id = $this -> request -> param();
            $data = Db::name('goods') -> where('id',$id['id']) -> find();
            if(!empty($data['det_img'])){
                $data['det_img'] = json_decode($data['det_img'],true);
                /*$data['det_img'] = explode(',',$data['det_img']);*/
                $data['det_name'] = json_decode($data['det_name'],true);
                foreach ($data['det_img'] as $key => $val){
                    $data['more'][$key]['url'] = $data['det_img'][$key];
                    $data['more'][$key]['name'] = $data['det_name'][$key];
                }
            }
            $data_gradeall = Db::name('gradeall ') -> select();
            $this -> assign('data_gradeall',$data_gradeall);
            $this -> assign('data',$data);
            return $this -> fetch();
        }

    }
















}