login_white = '';// $this->check_status = array();//用户状态校验 $this->check_mobile = array();//需要手机号 $this->check_headimg = array();//授权微信信息 $this->majia_white = array('get');//超级管理员披上马甲可操作权限 $this->load->model('app/material/Material_template_model', 'mdTemplate'); $this->load->model('app/material/Material_biz_model', 'mdMaterialBiz'); $this->load->model('auto/auto_brand_model', 'mdAutoBrand'); $this->load->model("biz/biz_model", 'mdBiz'); $this->biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); $this->app_id == 1 && $this->app_id = 2;//获取狸车宝数据 } /** * Notes:推广素材_tab * Created on: 2021/10/13 11:42 * Created by: dengbw * @return array */ protected function get_tabs() { $distribute = intval($this->input_param('distribute')); $list = array(); $res = []; if ($distribute == 1) {//分销 $res = $this->mdAutoBrand->select(array('status' => 1, 'id<>' => 3), "id desc", 0, 0, 'id,name'); } else { $res = $this->mdAutoBrand->select(['id' => 1], "id desc", 0, 0, 'id,name');//临时只显示东风品牌 1.19 //临时隐藏 // if ($this->biz_id) {//查找门店授权品牌 // $re_b = $this->mdBiz->get(array('id' => $this->biz_id, 'status' => 1)); // if ($re_b['jsondata']) { // $jsondata = json_decode($re_b['jsondata'], true); // if ($jsondata['auto_brands']) { // $brand_ids = implode($jsondata['auto_brands'], ','); // !$brand_ids && $brand_ids = $jsondata['auto_brands']; // $res = $this->mdAutoBrand->select(array("id in ({$brand_ids})" => null, 'status' => 1, 'id<>' => 3), "id desc", 0, 0, 'id,name'); // } // } // } } //根据品牌做分类 if ($res) { foreach ($res as $key => $value) { $brand_id = $value['id'] . ','; $where = array('app_id' => $this->app_id, 'type in(4,1)' => null, "brand_ids like '%{$brand_id}%'" => null, 'status' => 1); $total = $this->mdTemplate->count($where); if ($total > 0) { $value['total'] = $total; $list[] = $value; } } if ($list) { $timeKey = array_column($list, 'total'); //取出数组中total的一列,返回一维数组 array_multisort($timeKey, SORT_DESC, $list);//排序,根据$total 排序 } } $distribute == 1 && $list[] = ['id' => '3', 'name' => '狸车'];//全品牌蓄客 $distribute == 1临时加分销判断 1.19 $this->data['title'] = '推广素材'; $this->data['list'] = $list; $this->data['list_type'] = [['id' => 4, 'name' => '图片'], ['id' => 1, 'name' => '视频']]; return $this->data; } /** * Notes:获取品牌素材_lists * Created on: 2021/10/18 11:51 * Created by: dengbw * @return array * @throws Hd_exception */ protected function get_lists() { $page = $this->input_param('page'); $size = $this->input_param('size'); $brand_id = intval($this->input_param('id')); $type = intval($this->input_param('type')); $distribute = intval($this->input_param('distribute')); !$type && $type = 4; $lists = array(); $total = 0; if ($brand_id) { !$page && $page = 1; !$size && $size = 8; $brand_id = $brand_id . ','; $where = array('app_id' => $this->app_id, 'type' => $type, "brand_ids like '%{$brand_id}%'" => null, 'status' => 1); $total = $this->mdTemplate->count($where); $fileds = 'id,title,cover,json_data'; $res = $this->mdTemplate->select($where, "id desc", $page, $size, $fileds); foreach ($res as $key2 => $value2) { $setValue = array(); $setValue['id'] = intval($value2['id']); $setValue['title'] = $value2['title']; $setValue['cover'] = $value2['cover'] ? build_qiniu_image_url($value2['cover']) : ''; $moments = $tag = ''; if ($value2['json_data']) { $json_data = json_decode($value2['json_data'], true); $json_data['moments'] && $moments = $json_data['moments']; $json_data['tag_id'] && $tag = $this->mdTemplate->tagAry()[$json_data['tag_id']]; } $setValue['moments'] = $moments; if ($distribute == 1) { $setValue['tag'] = $tag; } else { $if_add = 0; if ($this->biz_id) { $re_biz = $this->mdMaterialBiz->get(array('app_id' => $this->app_id, 't_id' => $value2['id'], 'biz_id' => $this->biz_id)); $re_biz && $if_add = 1; } $setValue['if_add'] = $if_add; } $lists[] = $setValue; } } $this->data['show'] = 'image'; $this->data['list'] = $lists; $this->data['total'] = $total; return $this->data; } /** * Notes:获取分类素材_lists * Created on: 2021/10/11 11:47 * Created by: dengbw * @return array * @throws Exception */ protected function get_type_lists() { $page = $this->input_param('page'); $size = $this->input_param('size'); $type = intval($this->input_param('type')); !$page && $page = 1; !$size && $size = 10; !$type && $type = 1; $brand_ids = array(); if ($this->biz_id) {//查找门店授权品牌 $re_b = $this->mdBiz->get(array('id' => $this->biz_id, 'status' => 1)); if ($re_b['jsondata']) { $jsondata = json_decode($re_b['jsondata'], true); $jsondata['auto_brands'] && $brand_ids = $jsondata['auto_brands']; } } $lists = array(); $total = 0; $show = 'image'; if ($brand_ids) { $where = array('app_id' => $this->app_id, 'type' => $type, 'status' => 1); if ($type == 3) { $show = 'text'; $res = $this->mdTemplate->select($where, "id desc", 1, 1, 'json_data'); if ($res[0]['json_data']) { $json_data = json_decode($res[0]['json_data'], true); $total = count($json_data['lists']); foreach ($json_data['lists'] as $key2 => $value2) { if ($value2['brands']) { $brands = $value2['brands'] . ','; foreach ($brand_ids as $key3 => $value3) { if (strstr($brands, $value3 . ',')) { $lists[] = array('content' => $value2['content']); break; } } } } } } else { $or_str = ''; foreach ($brand_ids as $key3 => $value3) { $brand_id = $value3 . ','; $or_str = $or_str ? $or_str . " OR brand_ids like '%{$brand_id}%'" : "brand_ids like '%{$brand_id}%'"; } $where[' (' . $or_str . ') '] = null; $total = $this->mdTemplate->count($where); $fileds = 'id,title,cover,json_data'; $res = $this->mdTemplate->select($where, "id desc", $page, $size, $fileds); foreach ($res as $key2 => $value2) { $setValue = array(); $moments = ''; $re_biz = $this->mdMaterialBiz->get(array('app_id' => $this->app_id, 't_id' => $value2['id'], 'biz_id' => $this->biz_id)); $setValue['id'] = intval($value2['id']); $setValue['title'] = $value2['title']; $setValue['cover'] = $value2['cover'] ? build_qiniu_image_url($value2['cover']) : ''; $setValue['if_add'] = $re_biz ? 1 : 0; if ($value2['json_data']) { $json_data = json_decode($value2['json_data'], true); $json_data['moments'] && $moments = $json_data['moments']; } $setValue['moments'] = $moments; $lists[] = $setValue; } } } $this->data['show'] = $show; $this->data['list'] = $lists; $this->data['total'] = $total; return $this->data; } /** * Notes:生成专题 * Created on: 2021/10/11 16:14 * Created by: dengbw * @throws Hd_exception */ protected function put_topic() { $t_id = intval($this->input_param('t_id')); if (!$t_id || !$this->biz_id) { throw new Hd_exception('参数错误', API_CODE_FAIL); } $where = array('app_id' => $this->app_id, 't_id' => $t_id, 'biz_id' => $this->biz_id); $re = $this->mdMaterialBiz->get($where); if ($re) { throw new Hd_exception('该专题已经生成过了~', API_CODE_FAIL); } $where['c_time'] = time(); $id = $this->mdMaterialBiz->add($where); if ($id) { throw new Exception('专题生成成功', API_CODE_SUCCESS); } else { throw new Exception('专题生成失败', API_CODE_FAIL); } } /** * Notes:店铺海报 * Created on: 2021/11/18 14:27 * Created by: dengbw * @return array * @throws Hd_exception */ protected function get_biz() { if (!$this->biz_id) { throw new Hd_exception('参数错误', API_CODE_FAIL); } $re = $this->mdBiz->get(array('id' => $this->biz_id, 'status' => 1)); if (!$re) { throw new Hd_exception('门店不存在!', API_CODE_FAIL); } $jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : []; $posters = $jsondata['posters'] ? build_qiniu_image_url($jsondata['posters']) : ''; $this->data['posters'] = $posters; $this->data['biz_name'] = $re['biz_name']; $this->data['address'] = $re['address']; return $this->data; } /** * Notes:店铺海报模版 * Created on: 2021/11/18 10:36 * Created by: dengbw */ protected function get_biz_posters() { $url = 'https://qs.haodian.cn/wechat_app/lichebao/distribute'; $lists = [ ['title' => '店铺常规模板', 'cover' => $url . '/md-0.jpg', 'type' => 0, 'tpHeight' => 10, 'ftHeight' => 350, 'marginLR' => 10, 'posterBg' => '', 'posterFt' => $url . '/posterFt-0.jpg', 'bgColor' => '#fff', 'color' => '#fff'], ['title' => '恭喜提车模板', 'cover' => $url . '/md-1.jpg', 'type' => 1, 'tpHeight' => 215, 'ftHeight' => 350, 'marginLR' => 20, 'posterBg' => $url . '/posterBg-1.jpg', 'posterFt' => $url . '/posterFt-1.jpg', 'bgColor' => '#dd3535', 'color' => '#dd3535'], ['title' => '新车到店模板', 'cover' => $url . '/md-2.jpg', 'type' => 1, 'tpHeight' => 175, 'ftHeight' => 350, 'marginLR' => 30, 'posterBg' => $url . '/posterBg-2.jpg', 'posterFt' => $url . '/posterFt-2.jpg', 'bgColor' => '#2a9267', 'color' => '#3f392d'], ['title' => '恭喜成单啦', 'cover' => $url . '/md-3.jpg', 'type' => 1, 'tpHeight' => 215, 'ftHeight' => 350, 'marginLR' => 20, 'posterBg' => $url . '/posterBg-3.jpg', 'posterFt' => $url . '/posterFt-3.jpg', 'bgColor' => '#db3333', 'color' => '#fff'], ]; $this->data['title'] = '选择模版'; $this->data['lists'] = $lists; return $this->data; } /** * Notes:保存海报 * Created on: 2021/11/9 14:46 * Created by: dengbw * @throws Hd_exception */ protected function put_posters() { $posters = $this->input_param('posters'); if (!$posters || !$this->biz_id) { throw new Hd_exception('参数错误', API_CODE_FAIL); } $re_b = $this->mdBiz->get(array('id' => $this->biz_id, 'status' => 1)); if (!$re_b) { throw new Hd_exception('门店不存在!', API_CODE_FAIL); } $jsondata = $re_b['jsondata'] ? json_decode($re_b['jsondata'], true) : []; $jsondata['posters'] = $posters; $ret = $this->mdBiz->update(['jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)], array('id' => $this->biz_id)); if ($ret) { throw new Exception('保存成功', API_CODE_SUCCESS); } else { throw new Exception('保存失败', API_CODE_FAIL); } } /** * Notes:获取二维码 * Created on: 2021/8/27 16:34 * Created by: dengbw * @return array * @throws Hd_Exception */ protected function get_qrcode() { $scene = $this->input_param('scene'); $page = $this->input_param('page'); $width = $this->input_param('width'); if (0 == strlen($scene)) { throw new Hd_Exception('二维码参数必填', API_CODE_INVILD_PARAM); } return $this->qrcode($scene, $page, $width); } /** * Notes:获取图片二维码 * Created on: 2021/8/27 16:33 * Created by: dengbw * @param $scene * @param string $page * @param int $width * @param string $fig * @return array * @throws Hd_Exception */ private function qrcode($scene, $page = '', $width = 0, $fig = 'liche') { $path = "{$page}?{$scene}"; $width && $path .= "{$width}"; if ($fig) { $this->config->load('app', true, true); $configs = $this->config->item('app'); $config = $configs[$fig]; if (!$config) { debug_log("[error] " . __FUNCTION__ . ": config not exist;fig={$fig}", $this->log_file); throw new Hd_Exception('请求的小程序不存在', API_CODE_INVILD_PARAM); } $wxconfig = $config['wx']; } else { $wxconfig = $this->wx_config; $fig = $this->app_key; } $filename = "{$fig}/" . substr(md5($path), 8, 16); $this->load->library('Hdwechat'); $hdwechat = new Hdwechat($wxconfig); $ret = $hdwechat->qrcode($filename, $scene, $page, $width); if (!$ret) { throw new Hd_Exception('生成失败,稍后重试', API_CODE_FAIL); } $data = array('url' => $ret['url']); return $data; } }