Seller.php 17.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 249 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 321 322 323 324 325 326 327 328 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 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 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
<?php
namespace app\admin\controller;
use think\Db;
use think\facade\Request;
class Seller extends Common
{
    /********************************打印机管理*******************************/
    /**
     * 商家list
     */
    public function sellerList(){
        if(Request::isAjax()){
            $data = Request::except('file');
            $key= input('post.key') ? input('post.key') : "";
            $channel = @$key['channel'] ? @$key['channel'] : 1;
            $limit = '&x='.$data["page"].'&y='.$data["limit"].'&keywords='.@$key['id'].'&channel='.$channel;

            //获取运营人员列表
            $list= file_get_contents(ON_LINE.'App.Seller.GetSellerList'.$limit);
            $array = json_decode($list,TRUE);
            foreach ($array['data'][0]['data'] as $key => $value) {
                $array['data'][0]['data'][$key]['cdate'] = date("Y-m-d H:i:s",$value['cdate']);
                if($value['status']==1)
                    $array['data'][0]['data'][$key]['statusVal'] = "启用";
                else
                    $array['data'][0]['data'][$key]['statusVal'] = "停用";

                $c_name = array();
                $t_name = array();
                //2019-03-05 增加菜系配置、商家类型配置
                if(is_array($value['cuisine'])){
                    foreach ($value['cuisine'] as $k => $v) {
                        $c_name[] = $v['name'];
                    }
                }
                if(is_array($value['type'])){
                    foreach ($value['type'] as $k => $v) {
                        $t_name[] = $v['type_name'];
                    }
                }
                if(!empty($c_name))
                    $array['data'][0]['data'][$key]['cuisine'] = implode(',', $c_name);
                if(!empty($t_name))
                    $array['data'][0]['data'][$key]['type'] = implode(',', $t_name);
            }
            return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$array['data'][0]['data'],'count'=>$array['data'][0]['total'],'rel'=>1];
        }
        $this->assign ( 'title','商户基本信息维护');
        return $this->fetch();
    }

    /**
     * 停用商家
     */
    public function configStop(){
        if(Request::isAjax()){
            $data = Request::except('file');
            $data['status'] = $data['status'] ? 0 : 1;
            $list= file_get_contents(ON_LINE.'App.Seller.SetStopBySeller&sellerid='.$data['sellerid'].'&status='.$data['status']);
            $array = json_decode($list,TRUE);
            if($array['ret']==200){
                $result['code'] = 1;
                $result['msg'] = 'SUCCESS!';
            }else{
                $result['code'] = 0;
                $result['msg'] = '请求错误!';
            }
            return $result;
        }
        return view();
    }

    /**
     * 从商家维度统计:订单、短信等情况
     */
    public function getStatistics(){
        if(Request::isAjax()){
            $data = Request::except('file');
            $key= input('post.key') ? input('post.key') : ""; 

            $sid = $data['sid'] ? implode(',', $data['sid']) : '';
            $sellername = $data['key'] ? $data['key'] : '';

            $time = $data['time'] ? explode(' - ', $data['time']) : '';

            $stime = $time ? strtotime(date($time[0],time())) : '';
            $etime = $time ? strtotime(date($time[1],time())) : '';

            $data['time_type'] = $data['time_type'] ? $data['time_type'] : 1;
            $data['channel'] = $data['channel'] ? $data['channel'] : 1;

            $parame = '&page='.$data["page"].'&size='.$data["limit"].'&sellername='.@$sellername.'&stime='.@$stime.'&etime='.@$etime.'&channel='.@$data['channel'].'&sid='.$sid.'&time_type='.@$data['time_type'];
            //获取运营人员列表
            $list= file_get_contents(ON_LINE.'App.Report.GetReserveData'.$parame);
            
            $array = json_decode($list,TRUE);
            $new_array = array();
            foreach ($array['data'] as $key => $value) {
                if(is_array($value)){
                    $new_array[$key]['id'] = $value['id'];
                    $new_array[$key]['sellername'] = $value['sellername'];
                    $new_array[$key]['contacts_total'] = $value['contacts_total'];
                    $new_array[$key]['inviting'] = $value['inviting'];
                    $new_array[$key]['reserve_count'] = $value['appReserveCount'] .'/'. $value['AndroidReserveCount'];
                    $new_array[$key]['reserve_count_sort'] = $value['appReserveCount'] + $value['AndroidReserveCount'];
                    $new_array[$key]['sms_send_count'] = $value['appSmsCount'] .'/'. $value['AndroidSmsCount'];
                    $new_array[$key]['sms_send_count_sort'] = $value['appSmsCount'] + $value['AndroidSmsCount'];
                    $new_array[$key]['table_room_total'] = $value['table_total'] .'/'. $value['room_total'];
                    $new_array[$key]['address_component'] = $value['address_component']['province'] && $value['address_component']['city'] ? $value['address_component']['province'] .'-'. $value['address_component']['city'] : '无法获取地区,请检查经纬度是否正确!';
                }
            }
            return $result = [
                'code'=>0,'msg'=>'获取成功!',
                'data'=>$new_array,
                'count'=>$array['data']['total'],
                'countReserve'=>$array['data']['appReserveCount']+$array['data']['AndroidReserveCount'],
                'countSms'=>$array['data']['appSmsCount']+$array['data']['AndroidSmsCount'],
                'inviteeCount'=>$array['data']['inviteeCount'],
                'appReserveCount'=>$array['data']['appReserveCount'],
                'AndroidReserveCount'=>$array['data']['AndroidReserveCount'],
                'appSmsCount'=>$array['data']['appSmsCount'],
                'AndroidSmsCount'=>$array['data']['AndroidSmsCount'],
                'Contacts'=>$array['data']['Contacts'],
                'rel'=>1
            ];
        }
        $this->assign ( 'title','预定订单统计');
        return $this->fetch();
    }

    /**
     * 从设备(电话机)维度统计:订单、短信等情况
     */
    public function getEquipment(){
        if(Request::isAjax()){
            $data = Request::except('file');
            $key= input('post.key') ? input('post.key') : ""; 

            $sid = $data['sid'] ? implode(',', $data['sid']) : '';
            $sellername = $data['key'] ? $data['key'] : '';

            $time = $data['time'] ? explode(' - ', $data['time']) : '';

            $stime = $time ? strtotime(date($time[0],time())) : '';
            $etime = $time ? strtotime(date($time[1],time())) : '';

            $data['time_type'] = $data['time_type'] ? $data['time_type'] : 1;
            $data['channel'] = $data['channel'] ? $data['channel'] : 1;

            $parame = '&page='.$data["page"].'&size='.$data["limit"].'&sellername='.@$sellername.'&stime='.@$stime.'&etime='.@$etime.'&channel='.@$data['channel'].'&sid='.$sid.'&time_type='.@$data['time_type'];
            //获取运营人员列表
            $list= file_get_contents(ON_LINE.'App.Report.GetReserveDataBydev'.$parame);
            $array = json_decode($list,TRUE);
            return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$array['data']['list'],'count'=>$array['data']['total'],'rel'=>1];
        }
        $this->assign ( 'title','设备维度统计预定订单');
        return $this->fetch();
    }

    /**
     * 商家菜系、类型配置
     */
    public function sellerconfig(){
        $data = Request::except('file');
        if(Request::isAjax()){
            $cuisine = !empty($data['cuisine']) ? implode(',', array_keys($data['cuisine'])) : '';
            $type = !empty($data['type']) ? implode(',', array_keys($data['type'])) : '';
            $mode = !empty($data['mode']) ? implode(',', array_keys($data['mode'])) : '';
            $sms_code = !empty($data['sms_code']) ? $data['sms_code'] : '';

            if($sms_code)
                $res_sms_code= file_get_contents(ON_LINE.'App.SendSMS.SetSellerSmsTemplate&sid='.$data['sellerid'].'&sms_id='.$sms_code);

            if($cuisine)
                $res_cuisine= file_get_contents(ON_LINE.'App.Seller.SetSellerCuisine&sellerid='.$data['sellerid'].'&cid='.$cuisine);
            //$res_cuisine = json_decode($res_cuisine,TRUE);
            if($type)
                $res_type= file_get_contents(ON_LINE.'App.Seller.SetSellerType&sellerid='.$data['sellerid'].'&typeid='.$type);
            //$res_type = json_decode($res_type,TRUE);
            
            if($mode)
                $res_mode= file_get_contents(ON_LINE.'App.Seller.setSellerMode&sellerid='.$data['sellerid'].'&modeid='.$mode);
            //$res_mode = json_decode($res_mode,TRUE);
            
            $result['code'] = 1;
            $result['msg'] = "配置成功!";
            return $result;
        }
        
        //获取商家已有菜系
        $cuisine_list= file_get_contents(ON_LINE.'App.Seller.getSellerCuisine&sellerid='.$data['id']);
        $cuisine_list = json_decode($cuisine_list,TRUE);
        //获取所有菜系
        $list= file_get_contents(ON_LINE.'App.Reserve.GetCustomerConfig');
        $array = json_decode($list,TRUE);
        //组装数据
        foreach ($cuisine_list['data'] as $key => $value) {
            foreach ($array['data']['cate'] as $k => $v) {
                if($value['cid']==$v['id']){
                    $array['data']['cate'][$k]['checked'] = 1;
                }
            }
        }
        $this->assign('list',$array['data']['cate']);//获取所有菜系

        //获取商家已有来源
        $type_list= file_get_contents(ON_LINE.'App.Seller.GetSellerType&sellerid='.$data['id']);
        $type_list = json_decode($type_list,TRUE);
        //获取来源
        $channel = array(array('id'=>1,'name'=>'合作'),array('id'=>2,'name'=>'推广'),array('id'=>3,'name'=>'测试'));
        //组装数据
        foreach ($type_list['data'] as $key => $value) {
            foreach ($channel as $k => $v) {
                if($value['type_id']==$v['id']){
                    $channel[$k]['checked'] = 1;
                }
            }
        }
        $this->assign('channel',$channel);//获取所有来源

        //获取商家已有地图显示方式
        $mode_list= file_get_contents(ON_LINE.'App.Seller.getSellerMode&sellerid='.$data['id']);
        $mode_list = json_decode($mode_list,TRUE);

        //获取所有地图显示方式
        $mode= array(array('id'=>1,'name'=>'地图上大图标'),array('id'=>2,'name'=>'地图上文字'));
        //组装数据
        foreach ($mode_list['data'] as $key => $value) {
            foreach ($mode as $k => $v) {
                if($value['sm_id']==$v['id']){
                    $mode[$k]['checked'] = 1;
                }
            }
        }
        $this->assign('mode',$mode);//获取所有菜系

        //获取商家已选短信模板
        $template = file_get_contents(ON_LINE.'App.Reserve.SellerInfo&seller_id='.$data['id']);
        $template = json_decode($template,TRUE);
        //获取商家已有地图显示方式
        $template_list = file_get_contents(ON_LINE.'App.SendSMS.GetSmsTemplate');
        $template_list = json_decode($template_list,TRUE);
        //组装数据
        foreach ($template_list['data'] as $key => $value) {
            if($value['template_code']==$template['data']['setting']['template_code']){
                $template_list['data'][$key]['checked'] = 1;
            }
        }
        $this->assign('template_list',$template_list['data']);//获取短信模板列表

        //商户信息
        $this->assign ('data',$data);  
        $this->assign ( 'title','商户信息配置' );
        return $this->fetch();
    }

    /**
     * 停用商家
     */
    public function setsellerconfig(){
        if(Request::isAjax()){
            $data = Request::except('file');
            $data['status'] = $data['status'] ? 0 : 1;
            $list= file_get_contents(ON_LINE.'App.Seller.SetSellerConfigByPC&sid='.$data['sellerid'].'&field='.$data['field'].'&value='.$data['value']);
            $array = json_decode($list,TRUE);
            if($array['ret']==200){
                $result['code'] = 1;
                $result['msg'] = 'SUCCESS!';
            }else{
                $result['code'] = 0;
                $result['msg'] = '请求错误!';
            }
            return $result;
        }
        return view();
    }

    /**
     * 停用商家
     */
    public function sellerdetail(){
        //print_r(Request::except('file'));die;
        $data = Request::except('file');
        //获取运营人员列表
        $list= file_get_contents(ON_LINE.'App.Seller.GetSellerById&sellerid='.$data['sid']);
        $array = json_decode($list,TRUE);
        if($array['data']['data']){
            $array['data']['data']['daily'] = json_decode($array['data']['data']['daily'],TRUE);
            $array['data']['data']['daily_time'] = json_decode($array['data']['data']['daily_time'],TRUE);
            $array['data']['data']['cdate'] = date("Y年m月d日 H时i分s秒",$array['data']['data']['cdate']);
        }
        //获取短信流水
        $sms= file_get_contents(ON_LINE.'App.SendSMS.GetSellerSmsFlowing&sid='.$data['sid']);
        $sms_data = json_decode($sms,TRUE);
        $sms_data_list = $sms_data['data'] ? $sms_data['data'] : array();
        $this->assign ( 'smslist',$sms_data_list);
        $this->assign ( 'data',$array['data']['data']);
        $this->assign ( 'title','商家详情页面');
        return $this->fetch();
    }

    //商家列表 用于配置商家活动
    public function seller_activity_list(){
        if(Request::isAjax()){
            $data = Request::except('file');
            $key= input('post.key') ? input('post.key') : "";
            $channel = @$key['channel'] ? @$key['channel'] : 1;
            $limit = '&x='.$data["page"].'&y='.$data["limit"].'&keywords='.@$key['id'].'&channel='.$channel;

            //获取运营人员列表
            $list= file_get_contents(ON_LINE.'App.Seller.GetSellerListByActivity'.$limit);
            $array = json_decode($list,TRUE);
            foreach($array['data'][0]['data'] as $key=>$value){
                if(!empty($value['activity'])){
                    foreach ($value['activity'] as $k => $v) {
                        $str[] = $v['id'].'、'.$v['title'];
                    }
                    $array['data'][0]['data'][$key]['activity'] = implode('<br/>', $str);
                    //$array['data'][0]['data'][$key]['activity'] = implode('<br/>', array_column($value['activity'], 'title'));
                }
            }
            return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$array['data'][0]['data'],'count'=>$array['data'][0]['total'],'rel'=>1];
        }
        $this->assign ( 'title','商家活动配置');
        return $this->fetch();
    }

    /**
     * 商家活动列表页
     */
    public function seller_activity(){
        $data = Request::except('file');
        //获取商家现有活动
        $seller_activity= file_get_contents(ON_LINE.'App.Seller.GetSellerActivity&sid='.$data['id']);
        $seller_activity = json_decode($seller_activity,TRUE);
        //活动列表
        $this->assign('sid',$data['id']);
        $this->assign ( 'seller_activity',$seller_activity['data']);
        $this->assign ( 'title','商家活动配置页面');
        return $this->fetch();
    }

    //添加活动
    public function add_activity(){
        $data = Request::except('file');
        if(Request::isAjax()){
            switch ($data['type']) {
                case '1':
                    $data['title'] = '满'.$data['max_num'].'立减'.$data['min_num'];
                    break;
                case '2':
                    $data['title'] = '满赠';
                    break;
                case '3':
                    $data['title'] = '满'.$data['max_num'].'立享'.$data['min_num'].'折';
                    break;
                case '4':
                    $data['title'] = $data['max_num'].'元代金券';
                    break;
                case '5':
                    $data['title'] = '会员价';
                    break;
                default:
                    # code...
                    break;
            }
            //字段空值过滤

            //添加活动
            $res= file_get_contents(ON_LINE.'App.Seller.SetActivity&str='.serialize($data));
            $res = json_decode($res,TRUE);
            if($data['aid']){
                if($res['data']){
                    $result = ['code'=>1,'msg'=>'修改成功!','rel'=>1];
                }else{
                    $result = ['code'=>0,'msg'=>'修改失败!','rel'=>1];
                } 
            }else{
                if($res['data']){
                    $result = ['code'=>1,'msg'=>'添加成功!','rel'=>1];
                }else{
                    $result = ['code'=>0,'msg'=>'添加失败!','rel'=>1];
                } 
            }
            return $result;
        }
        if($data['id']){
            //修改---需要获取对应的数据
            $activity= file_get_contents(ON_LINE.'App.Seller.GetSellerActivityById&id='.$data['id']);
            $activity = json_decode($activity,TRUE);
            $this->assign ('data',$activity['data']);
            $this->assign ( 'title','修改活动');
        }
        $this->assign ( 'hid',$data['sid']);
        $this->assign ( 'title','添加活动');
        return $this->fetch();
    }

    //删除活动
    public function del_activity(){
        $data = Request::except('file');
        $res= file_get_contents(ON_LINE.'App.Seller.DelSellerActivity&sid='.$data['sid'].'&aid='.$data['aid']);
        $res = json_decode($res,TRUE);
        $this->redirect('Seller/seller_activity', ['id' => $data['sid']]);
        //return $this->fetch('seller_activity',['id' => $data['sid']]);
    }
}