SalesmangoodsController.php 3.4 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(){
        $param = $this->request->param();
        $where = [
            'type' => 2,
        ];
        if(!empty($param['start_time']) && !empty($param['end_time'])){
            $start_time = strtotime($param['start_time']);
            $end_time = strtotime($param['end_time']);
            $where['a.create_time'] = [['>=',$start_time],['<=',$end_time]];
        }
        if(!empty($param['keyword'])){
            $keyword = trim($param['keyword']);
            $where['a.book_name'] = ['like',"%$keyword%"];
        }
        $data = Db::name('goods')->alias('a')
            ->field('a.*,b.user_nickname')
            ->join('user b',"a.uid=b.id",'LEFT')
            ->where($where)
            ->order('a.create_time','DESC')
            ->paginate(12);
        $data->appends($param);
        $this->assign('start_time',!empty($param['start_time']) ? $param['start_time'] : '');
        $this->assign('end_time',!empty($param['end_time']) ? $param['end_time'] : '');
        $this->assign('keyword',!empty($param['keyword']) ? trim($param['keyword']) : '');
        $this -> assign('data',$data);
        return $this -> fetch();

    }

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

        if($this -> request -> isPost()){
            if($_POST['money'] > $_POST['price']){
                $this -> error('佣金不能大于售价');
            }

            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_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();
        }

    }

    /**
     * 业务员商品列删除
     */
    public function salesman_del(){

        $data = Db::name('goods') -> delete($_POST['id']);
        //删除浏览记录
        Db::name('browsing_history') -> where('goods_id',$_POST['id']) -> delete();
        //删除收藏
        Db::name('collect') -> where('goods_id',$_POST['id']) -> delete();
        //删除购物车
        Db::name('shopping_cart') -> where('goods_id',$_POST['id']) -> delete();
        if($data){
           return true;
        }else{
            return false;
        }

    }















}