审查视图

app/admin/controller/SalesmanController.php 13.0 KB
anyv authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php
namespace app\admin\controller;

use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use function GuzzleHttp\Psr7\str;
use think\Db;
class SalesmanController extends AdminBaseController{

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

        if($this -> request -> isPost()){
            $where = [
anyv authored
17
                'a.status' => 2
anyv authored
18 19 20 21 22 23 24 25 26 27
            ];
            if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
                $start_time = strtotime($_POST['start_time']);
                $end_time = strtotime($_POST['end_time']);
                $where['audit_time'] = [['>=',$start_time],['<=',$end_time]];
            }
            if(!empty($_POST['keyword'])){
                $keyword = $_POST['keyword'];
                $where['b.phone'] = $keyword;
            }
anyv authored
28
            $data = Db::name('my_user') -> alias('a') -> field("a.uid,a.id,a.balance,a.audit_time,a.is_pro,b.phone") -> join('sale_audit b','a.uid = b.uid','LEFT') -> where($where) -> group('a.id') -> paginate(12);
anyv authored
29
        }else{
anyv authored
30 31
            $data = Db::name('my_user') -> alias('a') -> field("a.uid,a.id,a.balance,a.audit_time,a.is_pro,b.phone") -> join('sale_audit b','a.uid = b.uid','LEFT') -> where('a.status',2) -> group('a.id') -> paginate(12);
anyv authored
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
        }

        $data_arr = $data -> toArray();
   /*     array(1) {
            [0] => array(5) {
                ["uid"] => int(1)
                ["balance"] => string(6) "100.00"
                ["audit_time"] => int(1558509018)
                ["is_pro"] => int(1)
                ["phone"] => string(11) "18602699971"
  }
}*/
        $data_money = Db::name('money_ratio') -> find();
        foreach ($data_arr['data'] as $key => $val){
            $data_user = Db::name('user') -> where('id',$val['uid']) -> find();
            $data_arr['data'][$key]['name'] = $data_user['user_nickname'];
            $data_arr['data'][$key]['money'] = $data_money['platform_ratio'];
        }
        $this -> assign('data_arr',$data_arr['data']);
        $this -> assign('data',$data);
        return $this -> fetch();

    }

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

        if($this -> request -> isPost()){
            $data['id'] = $_POST['id'];
            $data['name'] = $_POST['name'];
            $data['phone'] = $_POST['phone'];
            $data['id_number'] = $_POST['id_number'];
            $res = Db::name('sale_audit') -> update($data);
            if($res){
                $this -> success('保存成功',url('Salesman/salesman_edit',array('uid' =>$_POST['uid'] )));
            }else{
                $this -> error('保存失败!');
            }
        }else{
            $uid = $this -> request -> param();
            $data = Db::name('sale_audit') -> where('uid',$uid['uid']) -> find();
            $this -> assign('data',$data);
            return $this -> fetch();
        }

    }

    /**
     * 业务员商品管理列表
     */
    public function salesman_goods_list(){

        if($this -> request -> isPost()){
            $where = [
                'uid' => ['=',$_POST['uid']]
            ];
            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') -> order('sort desc') -> where($where) -> select() -> toArray();
            $this -> assign('good_uid',$_POST['uid']);
            $data_num = Db::name('goods') -> order('sort desc') -> where('uid',$_POST['uid']) -> select() -> toArray();
            for($i=0;$i<count($data_num);$i++){
                $data_num[$i]['wei_sort'] = $i;
            }
            /**
             * 获取假的排序顺序
             */
            for($i=0;$i<count($data_num);$i++){
                for($j=0;$j<count($data);$j++){
                    if($data[$j]['id'] == $data_num[$i]['id']){
                        $data[$j]['wei_sort'] = $data_num[$i]['wei_sort'];
                    }
                }
            }
            $this -> assign('data_num',$data_num);
            $this -> assign('data',$data);
            return $this -> fetch();
        }else{
            $uid = $this -> request -> param();
            $this -> assign('good_uid',$uid['uid']);
            $data = Db::name('goods') -> order('sort desc') -> where('uid',$uid['uid']) -> select() -> toArray();
            for($i=0;$i<count($data);$i++){
                $data[$i]['wei_sort'] = $i;
            }
            $data_num = $data;
            $this -> assign('data_num',$data_num);
            $this -> assign('data',$data);
            return $this -> fetch();
        }

    }

    /**
     * 业务员商品添加
     */
    public function salesman_goods_add(){

        if($this -> request -> isPost()){
           $goods_data = Db::name('goods') -> where('uid',$_POST['uid']) -> select() -> toArray();
            if(count($goods_data) >= 8){
                $this -> error('添加失败');
            }else{
                if(!empty($_POST['det_img'])){
                    $_POST['det_img'] = json_encode($_POST['det_img']);
                    $_POST['det_name'] = json_encode($_POST['det_name']);
                }
                $_POST['create_time'] = time();
                $data = Db::name('goods') -> insertGetId($_POST);
                Db::name('goods') -> where('id',$data) -> update(['sort'=>$data]);
                if($data){
                    $this -> success('添加成功',url('Salesman/salesman_goods_list',array('uid'=>$_POST['uid'])));
                }else{
                    $this -> error('添加失败');
                }
            }
        }else{
            $uid = $this -> request -> param();
            $this -> assign('good_uid',$uid['uid']);
            return $this -> fetch();
        }

    }

    /**
     * 业务员商品管理列表排序替换
     */
    public function salesman_change(){

        $start_id = $_POST['start_id'];
        $start_sort = $_POST['start_sort'];
        $end_id = $_POST['end_id'];
        $end_sort = $_POST['end_sort'];
        Db::name('goods') -> where('id',$start_id) -> update(['sort'=>$end_sort]);
        Db::name('goods') -> where('id',$end_id) -> update(['sort'=>$start_sort]);
        return true;

    }

    /**
     * 业务员商品管理列表编辑
     */
    public function salesman_goods_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('Salesman/salesman_goods_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];
                }
            }
            $this -> assign('data',$data);
            return $this -> fetch();
        }

    }

    /**
     * 业务员商品列表下架
     */
    public function salesman_goods_soldout(){

        $id = $_POST['id'];
        $data = Db::name('goods') -> where('id',$id) -> update(['is_out'=>0]);
        if($data){
            return true;
        }else{
            return false;
        }

    }

    /**
     * 业务员商品列表上架
     */
    public function salesman_goods_putaway(){

        $id = $_POST['id'];
        $data = Db::name('goods') -> where('id',$id) -> update(['is_out'=>1]);
        if($data){
            return true;
        }else{
            return false;
        }

    }

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

        $id = $_POST['id'];
        $data = Db::name('goods') -> delete($id);
5  
anyv authored
249
        Db::name('shopping_cart') -> where("goods_id",$id) -> delete();
anyv authored
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
        if($data){
            return true;
        }else{
            return false;
        }

    }

    /**
     * 业务员列表取消推广
     */
    public function salesman_list_no_pro(){

        $id = $_POST['id'];
        $data = Db::name('my_user') -> where('id',$id) -> update(['is_pro'=>0]);
        if($data){
           return true;
        }else{
            return false;
        }

    }

    /**
     * 业务员列表恢复推广
     */
    public function salesman_list_yes_pro(){

        $id = $_POST['id'];
        $data = Db::name('my_user') -> where('id',$id) -> update(['is_pro'=>1]);
        if($data){
            return true;
        }else{
            return false;
        }

    }

    /**
     * 下线老师列表
     */
    public function teacher_list(){

        if($this -> request -> isPost()){
            $where = [
                'status' => 3,
                'pid' => $_POST['salesman_id']
            ];
            if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
                $start_time = strtotime($_POST['start_time']);
                $end_time = strtotime($_POST['end_time']);
                $where['a.create_time'] = [['>=',$start_time],['<=',$end_time]];
            }
            if(!empty($_POST['keyword'])){
                $keyword = $_POST['keyword'];
                $where['user_nickname'] = ['like',"%$keyword%"];
            }
            $this -> assign('salesman_id',$_POST['salesman_id']);
            $data = Db::name('my_user') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b','a.uid = b.id','left') -> where($where) -> paginate(12);
            $data_arr = $data -> toArray();
        }else{
            $id = $this -> request -> param();
            $this -> assign('salesman_id',$id['id']);
            $data = Db::name('my_user') -> where("status = 3 and pid =".$id['id']) -> paginate(12);
            $data_arr = $data -> toArray();
            foreach($data_arr['data'] as $key => $val){
                $data_nick = Db::name('user') -> where('id',$data[$key]['uid']) -> find();
                $data_arr['data'][$key]['user_nickname'] = $data_nick['user_nickname'];
            }
        }
anyv authored
321 322 323 324 325 326 327 328
        foreach ($data_arr['data'] as $key => $val){
            $money_income = Db::name('money_income') -> where('uid',$val['uid']) -> select();
            $m_money = 0;
            foreach ($money_income as $key1 => $val1){
                $m_money += $val1['money'];
            }
            $data_arr['data'][$key]['money'] = $m_money;
        }
anyv authored
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
        $this -> assign('data',$data);
        $this -> assign('data_arr',$data_arr['data']);
        return $this -> fetch();

    }

    /**
     * 下线学生列表
     */
    public function student_list(){

        if($this -> request -> isPost()){
            $teacher_id = $_POST['teacher_id'];
            $salesman_id = $_POST['salesman_id'];
            $where = [
                'a.status' => 4,
                'a.pid' => $teacher_id
            ];
            if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
                $start_time = strtotime($_POST['start_time']);
                $end_time = strtotime($_POST['end_time']);
                $where['a.create_time'] = [['>=',$start_time],['<=',$end_time]];
            }
            if(!empty($_POST['keyword'])){
                $keyword = $_POST['keyword'];
                $where['b.user_nickname'] = ['like',"%$keyword%"];
            }
            $data = Db::name('my_user') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b','a.uid = b.id','left') -> where($where) -> paginate(12);
        }else{
            $id = $this -> request -> param();
            $teacher_id = $id['teacher_id'];
            $salesman_id = $id['salesman_id'];
            $data = Db::name('my_user') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b','a.uid = b.id','left') -> where("a.status = 4 and a.pid =".$teacher_id) -> paginate(12);
        }
anyv authored
363
anyv authored
364 365 366 367 368 369 370
        $this -> assign('salesman_id',$salesman_id);
        $this -> assign('teacher_id',$teacher_id);
        $this -> assign('data',$data);
        return $this -> fetch();

    }
anyv authored
371 372 373 374 375 376 377 378 379 380 381
    /**
     * 业务员余额明细表
     */
    public function salesman_money(){

        $uid = $this -> request -> param();
        $data = Db::name('money_income') -> where('uid',$uid['uid']) -> select();
        $this -> assign('data',$data);
        return $this -> fetch();

    }
anyv authored
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411





























}