UserHelp.php 19.3 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 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
<?php


namespace app\admin\controller;

use phpDocumentor\Reflection\DocBlock\Tag\VarTagTest;
use think\AjaxPage;
use think\Page;
use app\admin\logic\GoodsLogic;
use think\db;


class UserHelp extends Base
{
    public function index()
    {
        $getp = I('p');
        if (empty($getp)) {
            $getp = 0;
        }
        $pagenum = 10;//每页显示多少条
        if ((int)I('pagenum/s') > 0) {
            $pagenum = I('pagenum/s');
        }
        $oldurl = U('Admin/UserHelp/index', array(
            "p" => $getp
        ));
        $this->assign('oldurl', urlencode($oldurl));
        $this->assign('pagenum', $pagenum);
        $this->assign('cur_page', $getp);
        return $this->fetch('', getAdmStoId());

    }

    public function ajaxindex()
    {


        $cur_page = 1;//当前页数
        if ((int)I('p/s') > 0) {
            $cur_page = I('p/s');
        }
        $pagenum = 10;//每页显示多少条
        if ((int)I('pagenum/s') > 0) {
            $pagenum = I('pagenum/s');
            $ylp_postdata["pageSize"] = $pagenum;
        }

        $begin = $this->begin;
        $end = $this->end;


        $getact_name = I('act_name') ? trim(I('act_name')) : ''; // 活动名称
         $status = I('status');//活动状态

        $where["a.store_id"] = getAdmStoId();

        if ($begin) {
            $where['a.begindate'] = array('egt', $begin);
        }
        if ($end) {
            $where['a.enddate'] = array('elt', $end);
        }


        if ($getact_name) {
            $where["a.act_name"] = array('like', '%' . $getact_name . '%');
        }

        $begin = $add_time_begin = I("add_time_begin");
        $end = $add_time_end = I("add_time_end");
        if ($add_time_begin) {
            $this->assign('start_time', $add_time_begin);
            $this->assign('end_time', $add_time_end);
            $this->assign('timegap', $add_time_begin . ' - ' . $add_time_end);
        }
        if ($begin) {
            $where['a.begindate'] = array('egt', strtotime($begin));
        }
        if ($end) {
            $where['a.enddate'] = array('elt', strtotime($end));
        }
        if ($status != "") {
            switch ($status) {
                case "0":
                    $where['a.isdel'] = 0;
                    $where['a.begindate'] = array('gt', time());
                    break;
                case "1":
                    $where['a.isdel'] = 0;
                    $where['a.begindate'] = array('elt', time());
                    $where['a.enddate'] = array('gt', time());
                    break;
                case "-1":
                    $where['a.isdel'] = 1;
                    break;
                default:
                    break;
            }
        }

        $count = M('marketing_help_form')->alias("a")->where($where)->count();
        $Page = new AjaxPage($count, $pagenum);
        $show = $Page->show();
        $list = M('marketing_help_form')->alias("a")
            ->where($where)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->field('a.*')
            ->order(array('sort_order', 'id' => 'desc'))
            ->select();


        $oldurl = U('Admin/Userholiday/ajaxindex', array(
            "pagenum" => $pagenum,
            "p" => $cur_page
        ));

        $this->assign('oldurl', urlencode($oldurl));
        $this->assign('page', $show);
        $this->assign('pager', $Page);
        $this->assign('pagenum', $pagenum);
        $this->assign('cur_page', $cur_page);
        $this->assign('list', $list);
        $this->assign('timegap', date('Y-m-d h:m:s', $this->begin) . ' - ' . date('Y-m-d h:m:s', $this->end));
        return $this->fetch('', getAdmStoId());


    }

    public function user_help_info()
    {
        $getadmstoid = getAdmStoId();
        //会员权益
        $grade_data['storeId'] = $getadmstoid;
        $init_data = getApiData_mini("api/weshop/users/grade/vip/init/get", $grade_data, $getadmstoid);
        $isBool = 0;
        if ($init_data) {
            $init_data = json_decode($init_data, true);
            if ($init_data['code'] === 0 && $init_data['data']) {
                try {
                    $isBool = $init_data['data']['isBool'];
                } catch (\Exception $e) {
                }
                $this->assign('isBool', $isBool);
                if ($isBool) {
                    //会员权益列表
                    $grade_list = getApiData_mini("/api/weshop/users/grade/vipgradeinfo/page", $grade_data, $getadmstoid);
                    if ($grade_list) {
                        $grade_list = json_decode($grade_list, true);
                        if ($grade_list['code'] == 0 && $grade_list['data']['pageData']) {
                            $this->assign('grade_list', $grade_list['data']['pageData']);
                        }
                    }
                }
            }
        }
        //plus会员
        $accdb = tpCache('shop_info.ERPId', $getadmstoid);
        $rs = getApiData_java_p("/api/erp/vip/mem/bership/list", $accdb, null, 1, 10, null, "GET");
        //要进行加密计算
        $arrlist = json_decode($rs, true)['data'];
        $this->assign('arrlist', $arrlist);

        //礼包数据
        $lblist = M('marketing_libao_form')->where(array('store_id' => $getadmstoid, 'is_act' => 1,'isdel'=>0,"isshow"=>1))->select();
        $this->assign('lblist', $lblist);
        //保存

        $m = db::query("select max(sort_order)odr from __PREFIX__marketing_help_form where store_id=" . $getadmstoid);
        $md = (int)$m[0]["odr"];
        $md++;
        $help['sort_order'] = $md;
        $help['begindate'] = time();
        $help['enddate'] = time() + 3600 * 24 * 30;
//        $help['exchange_begindate'] = time();
//        $help['exchange_enddate'] = time() + 3600 * 24 * 30;
        $getid = I('id/d', 0);
        $help['isuse'] = 1;

        //修改
        if ($getid) {
            $help = M('marketing_help_form')->where(array('store_id' => $getadmstoid, 'id' => $getid))->find();
            if (empty($help)) {
                $this->error("找不到相关信息");
            }
            //开始时间大于当前时间
            if ($help['begindate'] < time()) {
                $this->assign('is_stime', 1);
            }

            $help_list = M('marketing_help_list')->where(array('store_id' => $getadmstoid, 'help_id' => $help['id']))->select();
            $this->assign('help_list', $help_list);
            $this->assign('help', $help);
        }
        else
        {
            $fu = M("marketing_help_form")->where(array('store_id'=>$getadmstoid,'isdel'=>0))->field('begindate,enddate')->find();
            if ($fu) {
                $this->assign('quan_s_time', date('Y-m-d H:i:s', $fu['begindate']));
                $this->assign('quan_e_time', date('Y-m-d H:i:s', $fu['enddate']));
            }
        }
        $this->assign('help', $help);
        $this->initEditor(); // 编辑器
        return $this->fetch('', getAdmStoId());
    }

    /*  添加节日活动*/
    public function addindex()
    {
        $getadmstoid = getAdmStoId();
        if (IS_POST) {
            $datas = input('post.');
            $id = $datas['lbid'];
            $rr = M("admin")->where("admin_id", $getadmstoid)->find();
            $rw_data = $datas['data'];
            foreach ($rw_data as $keys => $vals) {
                if ($vals['giftbagid'] != null && $vals['giftbagid'] != '') {
                    $id_name = explode(',', $vals['giftbagid']);
                    foreach ($id_name as $ks => $vs) {
                        $rw_data[$keys]['giftbagid'] = $id_name[0];
                        $rw_data[$keys]['giftbagname'] = $id_name[1];

                    }
                }

            }

            //助力需关注和助力需注册会员
            $help_condition = "";
            if ($datas['help_condition1']) {
                $help_condition = "," . $datas['help_condition1'];
            }
            if ($datas['help_condition2']) {
                $help_condition .= "," . $datas['help_condition2'];
            }
            if ($help_condition) {
                $help_condition = $help_condition . ",";
            }

            //会员权益等级
            $grade_state = $datas['grade_state'];
            $grade_str = $datas['grade_str'];
            $str = "";
            if ($grade_state != null && $grade_state != null) {
                foreach ($grade_state as $k => $v) {
                    if ($v == $grade_state[$k]) {
                        $str .= $grade_state[$k] . ",";
                    }
                }
            }
            if ($str) {
                $str = "," . $str;
            }
            //plus会员
            $plus_state = $datas['plus_state'];
            $plus_str = $datas['plus_str'];
            $plus_list = "";
            if ($plus_state != null && $plus_state != "") {
                foreach ($plus_state as $k => $v) {
                    if ($v == $plus_state[$k]) {
                        $plus_list .= $plus_state[$k] . ",";
                    }
                }
            }
            $plus_list = "," . $plus_list;
            $data['act_name'] = $datas['act_name'];
            $data['isuse'] = $datas['isuse'];
            $data['store_id']=$getadmstoid;
            //排序
            $data['sort_order'] = $datas['sort_order'];
            //活动开始时间
            $data['begindate'] = strtotime($datas['begindate']);
            $data['enddate'] = strtotime($datas['enddate']);
            $data['imageurl'] = $datas['imageurl'];
            //兑换时间
//            $data['exchange_begindate'] = strtotime($datas['exchange_begindate']);
//            $data['exchange_enddate'] = strtotime($datas['exchange_enddate']);
            //会员参与类型
            $data['vip_act_type'] = $datas['vip_act_type'];
            //会员参与类型次数
            $data['vip_act_num'] = $datas['vip_act_num'];
            //助力需要关注
            $data['help_act_type'] = $datas['help_act_type'];
            //助力需要关注次数
            $data['help_act_num'] = $datas['help_act_num'];
            //助力需关注和助力需注册会员
            $data['help_condition'] = $help_condition;
            $data['grade'] = $str;
            //是否是plus会员
            $data['plus_list'] = $plus_list;
            $data['remark'] = $datas['remark'];

            //修改
            if ($id) {
                $helpinfo = M('marketing_help_form')->where(array('store_id' => $getadmstoid, 'id' => $id))->find();
                if (empty($helpinfo)) {
                    $this->error('操作失败,找不到相关数据!');
                    exit;
                }
                //修改
                $oldurl = I('oldurl/s');
                if ($oldurl) {
                    $oldurl = urldecode(urldecode($oldurl));
                }
                $this->assign('oldurl', $oldurl);
                unset($datas['lbid']);

                $data['edittime'] = time();
                $data['editip'] = getIP();
                $data['editman'] = $rr['ERPName'];

                $results = M('marketing_help_form')->where(array('store_id' => $getadmstoid, 'id' => $id))->save($data);
                if ($results) {
                    $help_list = $rw_data;
                    $is_msg = "";
                    foreach ($help_list as $k => $val) {
                        $val["store_id"] = $getadmstoid;
                        if ($val['id']) {
                            //这个是修改从表
                            $help_list = M('marketing_help_list')->where(array('store_id' => $getadmstoid, 'id' => $val['id']))->save($val);
                            if(empty($help_list)) $help_list=$val['id'];
                            $is_msg .= $help_list;
                        } else {
                            //这个保存道具
                            $val["help_id"] = $id;
                            $help_list = M('marketing_help_list')->insertGetId($val);
                            $is_msg .= $help_list;
                        }

                        //活动没有开始,就要修改redis
                        if($data['begindate']>time() && $help_list ){
                            $redis=get_redis_handle();
                            $name=get_redis_name($help_list,7,getAdmStoId());
                            del_redis($redis,$name);
                            for ($i = 0; $i < $val['gift_qty']; $i++) {
                                $redis->lPush($name, "m" . $i);
                            }
                        }
                    }
                    //判断是不是助力从表是否保存成功
                    if (strpos($is_msg, -1) !== false) {
                        $this->error('操作失败');
                        exit;
                    } else {
                        $this->success('操作成功', U('admin/UserHelp/index'));
                        exit;
                    }

                } else {
                    $this->error('修改失败');
                    exit;
                }


            } else {

                $data['addtime'] = time();
                $data['addip'] = getIP();
                $data['addman'] = $rr['ERPName'];
                $current_time = $data['addtime'];
                $results = M('marketing_help_form')->save($data);
                if ($results) {
                    /* 查询出刚刚保存的*/
                    $help_form = M("marketing_help_form")->where(array("store_id" => $getadmstoid, 'isdel' => 0, "addtime" => $current_time, "act_name" => $datas['act_name']))->select();
                    if ($help_form) {
                        $help_list = $rw_data;
                        $is_msg = "";
                        foreach ($help_list as $k => $val) {
                            $val["store_id"] = $getadmstoid;
                            $val["help_id"] = $help_form[0]["id"];

                            $help_list = M('marketing_help_list')->insertGetId($val);
                            $is_msg .= $help_list;
                            //活动没有开始,就要修改redis
                             $redis=get_redis_handle();
                             $name=get_redis_name($help_list,7,getAdmStoId());

                              for ($i = 0; $i < $val['gift_qty']; $i++) {
                                  $redis->lPush($name, "m" . $i);
                               }

                        }
                        //判断是不是助力从表是否保存成功
                        if (strpos($is_msg, -1) !== false) {
                            $this->error('操作失败');
                            exit;
                        } else {
                            $this->success('操作成功', U('admin/UserHelp/index'));
                            exit;
                        }
                    }

                } else {
                    $this->error('操作失败');
                    exit;
                }


            }


        }
    }

    //删除
    public function dellibao()
    {
        $id = $this->request->param('id');
        $getadmstoid = getAdmStoId();

        $lqnum = M('marketing_help_user')->where(array('store_id' => $getadmstoid, 'help_formid' => $id))->count();
        $is_del = "";
        if ($lqnum > 0) {
            $data["isdel"] = 1;
            $is_del = M('marketing_help_form')->where(array('store_id' => $getadmstoid, 'id' => $id))->save($data);
            $return_arr = array(
                'status' => 1,
                'msg' => '操作成功',
                'data' => array('url' => U('admin/UserHelp/index')),
            );
            $this->ajaxReturn($return_arr);
        }

        $is_del = M('marketing_help_form')->where(array('store_id' => $getadmstoid, 'id' => $id))->delete();
        $is_del_s = M('marketing_help_list')->where(array('store_id' => $getadmstoid, 'help_id' => $id))->delete();
        $return_arr = array(
            'status' => 1,
            'msg' => '操作成功',
            'data' => array('url' => U('admin/UserHelp/index')),
        );
        $this->ajaxReturn($return_arr);


    }

    //获取礼包数据
    public function get_gift_list()
    {
        $getadmstoid = getAdmStoId();
        $lblists = M('marketing_libao_form')->where(array('store_id' => $getadmstoid, 'is_act' => 1,'isdel'=>0,"isshow"=>1))->fetchSql(true)->select();
        //礼包数据
        $lblist = M('marketing_libao_form')->where(array('store_id' => $getadmstoid, 'is_act' => 1,'isdel'=>0,"isshow"=>1))->select();
        if ($lblist) {
            return json(["code" => 0, "msg" => $lblist]);
        } else {
            return json(["code" => -1, "msg" => '未找到礼包']);
        }

    }

    //删除任务奖励
    public function del_help_list()
    {

        $help_id = I('id/d',0);
        if (empty($help_id)) {
            return json(["code" => -1, "msg" => "操作失败,参数有数"]);
        }
        $getadmstoid=getAdmStoId();
        $help_listinfo = M('marketing_help_list')->where(array('store_id' => $getadmstoid, 'id' => $help_id))->find();
        if (empty($help_listinfo)) {
            return json(["code" => -1, "msg" => "操作失败,找不到相关数据"]);
        }
        $gethelp_id=$help_listinfo['help_id'];
        $helpinfo=M('marketing_help_form')->where(array('store_id'=>$getadmstoid,'id'=>$gethelp_id))->find();
        if (empty($helpinfo)) {
            return json(["code" => -1, "msg" => "操作失败,找不到相关数据"]);
        }
        if ($helpinfo['isdel']==1) {
            return json(["code" => -1, "msg" => "操作失败,活动已结束,无法删除"]);
        }
        if ($helpinfo['begindate']<time()) {
            return json(["code" => -1, "msg" => "操作失败,活动已开始,无法删除"]);
        }
        if ($helpinfo['enddate']>time()) {
            return json(["code" => -1, "msg" => "操作失败,活动已结束,无法删除"]);
        }
        $help_listdel=M('marketing_help_list')->where(array('store_id' => $getadmstoid, 'id' => $help_id))->delete();
        if (empty($help_listdel))
        {
            return json(["code" => -1, "msg" => "操作失败,无法删除"]);
        }
        return json(["code" => 0, "msg" => "操作成功"]);

    }

    private function initEditor()
    {
        $this->assign("URL_upload", U('admin/Ueditor/imageUp', array('savepath' => 'userhelp', 'savepath1' => strtolower(getERPId())))); // 图片上传目录
        $this->assign("URL_imageUp", U('admin/Ueditor/imageUp', array('savepath' => 'userhelp', 'savepath1' => strtolower(getERPId())))); //  不知道啥图片
        $this->assign("URL_fileUp", U('admin/Ueditor/fileUp', array('savepath' => 'userhelp', 'savepath1' => strtolower(getERPId())))); // 文件上传s
        $this->assign("URL_scrawlUp", U('admin/Ueditor/scrawlUp', array('savepath' => 'userhelp', 'savepath1' => strtolower(getERPId()))));  //  图片流
        $this->assign("URL_getRemoteImage", U('admin/Ueditor/getRemoteImage', array('savepath' => 'userhelp', 'savepath1' => strtolower(getERPId())))); // 远程图片管理
        $this->assign("URL_imageManager", U('admin/Ueditor/imageManager', array('savepath' => 'userhelp', 'savepath1' => strtolower(getERPId())))); // 图片管理
        $this->assign("URL_getMovie", U('admin/Ueditor/getMovie', array('savepath' => 'userhelp', 'savepath1' =>strtolower(getERPId())))); // 视频上传
        $this->assign("URL_Home", "");
    }
}