审查视图

app/portal/controller/SalesmangoodsController.php 6.2 KB
anyv authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\WeChatBaseController;
use think\Db;
class SalesmangoodsController extends WeChatBaseController{

    /**
     * 业务员商品管理
     */
    public function salesman_goods(){
anyv authored
20 21
        $uid = cmf_get_current_user_id();
        $data_goods = Db::name('goods') -> where("uid =".$uid." and type =2") -> order("sort desc") -> select() -> toArray();
5  
anyv authored
22 23 24 25 26 27 28 29
        if(!empty($data_goods)){
            foreach ($data_goods as $key => $val){
                $price = explode('.',$val['price']);
                $data_goods[$key]['price0'] = $price[0];
                $data_goods[$key]['price1'] = $price[1];
            }
        }
        $this -> assign('data_goods',$data_goods);
anyv authored
30 31 32 33
        return $this -> fetch();

    }
6  
anyv authored
34 35 36 37 38
    /**
     * 业务员商品上移
     */
    public function goods_move_up(){
5  
anyv authored
39
        $uid = cmf_get_current_user_id();
6  
anyv authored
40
        $goods_id = $_POST['goods_id'];
5  
anyv authored
41
        $data_goods = Db::name('goods') -> where('id',$goods_id) -> find();
5  
anyv authored
42
        $data = Db::name('goods') -> where("uid =".$uid." and type =2") -> order("sort desc") -> select() -> toArray();
5  
anyv authored
43 44
        foreach ($data as $key => $val){
            if($val['sort'] == $data_goods['sort']){
5  
anyv authored
45
                $sort = $data[$key-1]['sort'];
5  
anyv authored
46
                $data[$key-1]['sort'] = $data[$key]['sort'];
5  
anyv authored
47
                Db::name('goods') -> where('id',$data[$key-1]['id']) -> update(['sort'=>$data[$key-1]['sort']]);
5  
anyv authored
48
                $data[$key]['sort'] = $sort;
5  
anyv authored
49
                Db::name('goods') -> where('id',$data[$key]['id']) -> update(['sort'=>$data[$key]['sort']]);
5  
anyv authored
50 51 52
            }
        }
        return true;
6  
anyv authored
53 54

    }
anyv authored
55
5  
anyv authored
56 57 58 59 60 61 62 63 64 65 66 67 68 69
    /**
     * 业务员商品删除
     */
    public function goods_del(){

        $id = $_POST['goods_id'];
        $data = Db::name('goods') -> delete($id);
        if($data){
            return true;
        }else{
            return false;
        }

    }
anyv authored
70
anyv authored
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    /**
     * 业务员商品费用查询
     */
    public function goods_cost(){

        $id = $_POST['goods_id'];
        $data = Db::name('goods') -> where('id',$id) -> find();
        return json_encode($data);

    }

    /**
     * 点击费用编辑
     */
    public function moneyedit(){

        $data = Db::name('goods') -> where('id',$_POST['goods_id']) -> update(['price'=>$_POST['price'],'money'=>$_POST['money']]);
        if($data){
            return true;
        }else{
            return false;
        }
anyv authored
93
anyv authored
94
    }
anyv authored
95
anyv authored
96 97 98 99 100
    /**
     * 添加业务员商品页
     */
    public function Salesman_goods_add(){
anyv authored
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
        if($this -> request -> isPost()){
            $data['show_img'] = $_POST['show_img'];
            $data['thumbnail'] = $_POST['thumbnail'];
            $data['book_name'] = $_POST['book_name'];
            $data['money'] = $_POST['money'];
            $data['price'] = $_POST['price'];
            $data['pricing'] = $_POST['pricing'];
            $data['instr'] = $_POST['instr'];
            $data['book_number'] = $_POST['book_number'];
            $data['paper'] = $_POST['paper'];
            $data['book_size'] = $_POST['book_size'];
            $data['binding'] = $_POST['binding'];
            $data['author'] = $_POST['author'];
            $data['press'] = $_POST['press'];
            $data['press_time'] = $_POST['press_time'];
            $data['suit'] = $_POST['suit'];
            $data['grade'] = $_POST['grade'];
anyv authored
118 119 120 121 122
            $det_img[0] = $_POST['img0'];
            $det_img[1] = $_POST['img1'];
            $det_img[2] = $_POST['img2'];
           /* $data['det_img'] = $_POST['img0'].','.$_POST['img1'].','.$_POST['img2'];*/
            $data['det_img'] = json_encode($det_img);
anyv authored
123 124 125 126 127 128 129 130 131 132 133 134 135
            $data['create_time'] = time();
            $data['type'] = 2;
            $data['uid'] = cmf_get_current_user_id();
            $goods_id = Db::name('goods') -> insertGetId($data);
            Db::name('goods') -> where("id=".$goods_id) -> update(['sort'=>$goods_id]);
            if($goods_id){
                return true;
            }else{
                return false;
            }
        }else{
            return $this -> fetch();
        }
anyv authored
136 137

    }
anyv authored
138
anyv authored
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
    /**
     * 点击编辑商品
     */
    public function Salesman_goods_edit(){

        if($this -> request -> isPost()){
            $data['show_img'] = $_POST['show_img'];
            $data['thumbnail'] = $_POST['thumbnail'];
            $data['book_name'] = $_POST['book_name'];
            $data['money'] = $_POST['money'];
            $data['price'] = $_POST['price'];
            $data['pricing'] = $_POST['pricing'];
            $data['instr'] = $_POST['instr'];
            $data['book_number'] = $_POST['book_number'];
            $data['paper'] = $_POST['paper'];
            $data['book_size'] = $_POST['book_size'];
            $data['binding'] = $_POST['binding'];
            $data['author'] = $_POST['author'];
            $data['press'] = $_POST['press'];
            $data['press_time'] = $_POST['press_time'];
            $data['suit'] = $_POST['suit'];
            $data['grade'] = $_POST['grade'];
            $data['det_img'] = $_POST['img0'].','.$_POST['img1'].','.$_POST['img2'];
            $data['id'] = $_POST['id'];
            $up_data = Db::name('goods') -> update($data);
            if($up_data){
               return true;
            }else{
                return false;
            }
        }else{
            $id = $this -> request -> param();
            $goods_data = Db::name('goods') -> where('id',$id['goods_id']) -> find();
            $goods_data['det_img'] = explode(',',$goods_data['det_img']);
            foreach ($goods_data['det_img'] as $key => $val){
                $goods_data['det_img'][$key] = cmf_get_image_url($goods_data['det_img'][$key]);
            }
            $this -> assign('goods_data',$goods_data);
            return $this -> fetch();
        }

    }
anyv authored
181 182 183 184 185 186 187 188 189 190 191 192 193












}