request->header('platform'); // 转换 //如果非服务端中转模式需要修改为中转 if ($upload['storage'] != 'local' && isset($upload['uploadmode']) && $upload['uploadmode'] != 'server') { //临时修改上传模式为服务端中转 set_addon_config($upload['storage'], ["uploadmode" => "server"], false); $upload = \app\common\model\Config::upload(); // 上传信息配置后 Hook::listen("upload_config_init", $upload); $upload = Config::set('upload', array_merge(Config::get('upload'), $upload)); } $upload['cdnurl'] = $upload['cdnurl'] ? $upload['cdnurl'] : cdnurl('', true); //上传地址强制切换为使用本地上传,云存储插件会自动处理 $upload['uploadurl'] = url('/api/common/upload', '', false, true); $arrConfig = ShopConfigService::getConfigs('shop.basic',false); $arrGoodsConfig = ShopConfigService::getConfigs('shop.goods',false); $orderTimeout = ShopConfigService::getConfigs('shop.order.order_timeout',false); $data = [ 'upload' => $upload, ]; $data['order_timeout'] = $orderTimeout; $data['sitename'] = $arrConfig['site_name']?? ""; // 手机号 $data['phone'] = $arrConfig['phone']??""; // 工作时间 $data['workinghours'] = $arrConfig['working_hours']??""; // 客服邮箱 $data['email'] =$arrConfig['email']??""; // 公司名称 $data['company'] = $arrConfig['company']??""; // 站点logo $data['sitelogo'] = $arrConfig['site_logo']? cdnurl($arrConfig['site_logo'], true) : ''; // 公安备案 $data['gwabeian'] = $arrConfig['public_network_filing']??""; // icp备案 $data['icpbeian'] = $arrConfig['icp']??""; // 默认商品图片 $defaultGoodsImg = $arrGoodsConfig['default_goods_img']??""; $data['default_goods_img'] = !empty($defaultGoodsImg ) ? cdnurl( $defaultGoodsImg, true) : ''; // 默认分类图片 $defaultCategoryImg = $arrGoodsConfig['default_category_img']??""; $data['default_category_img'] = !empty($defaultCategoryImg)? cdnurl($defaultCategoryImg, true) :''; $platformKey = $this->convertPlatformName($platform); $arrPlatformConfigs = ShopConfigService::getConfigs('shop.platform.' . $platformKey, false); // app 处理 if ($platform == ChannelEnum::CHANNEL_IOS_APP){ // 微信appid $data['wx_universal_link'] =$arrPlatformConfigs['wx_universal_link'] ?? ""; $data['app_wx_appid'] = $arrPlatformConfigs['app_id'] ?? ""; $data['wechat_mini_program_original'] = $arrPlatformConfigs['wechat_mini_program_original'] ?? ""; $data['wechat_mini_program_url'] = $arrPlatformConfigs['wechat_mini_program_url'] ?? ""; $data['wechat_mini_program_type'] = $arrPlatformConfigs['wechat_mini_program_type'] ?? ""; } if ($platform == ChannelEnum::CHANNEL_ANDROID_APP){ $data['wechat_mini_program_original'] = $arrPlatformConfigs['wechat_mini_program_original'] ?? ""; $data['wechat_mini_program_url'] = $arrPlatformConfigs['wechat_mini_program_url'] ?? ""; $data['app_wx_appid'] = $arrPlatformConfigs['app_id'] ?? ""; $data['wechat_mini_program_type'] = $arrPlatformConfigs['wechat_mini_program_type'] ?? ""; } // 微信小程序处理 if ($platform == ChannelEnum::CHANNEL_WECHAT_MINI_PROGRAM){ // 微信appid $data['wx_appid'] = $arrPlatformConfigs['app_id'] ?? ""; $data['app_url'] = !empty($arrPlatformConfigs['app_url']) ? cdnurl($arrPlatformConfigs['app_url'], true) : ''; } // 反馈类型 $data['feedback_type'] = FeedbackEnum::getFeedbackTypeMap(); // 性别 $data['gender'] = UserEnum::getGenderMap(); $this->success('', $data); } /** * 读取省市区数据,联动列表 */ public function area() { $province = $this->request->param('province', ''); $city = $this->request->param('city', ''); $where = ['pid' => 0, 'level' => 1]; $provincelist = null; if ($province !== '') { $where['pid'] = $province; $where['level'] = 2; } if ($city !== '') { $where['pid'] = $city; $where['level'] = 3; } $provincelist = Area::where($where)->field('id as value,name as label')->where('status', 'normal')->select(); $this->success('', $provincelist); } public function getBannerList() { $type = $this->request->param('type'); // 验证参数 if (!$type) { $this->error('参数错误'); } $list = Block::getBlockList(['type' => $type]); $this->success('', $list); } public function getDataByIndex() { // 固定 $type = ['首页BANNER', '首页LOTTERY','首页ARTICE','首页MEASURE']; $field = 'id,type,name,image,url,page_name,status,begintime,endtime,title,page_type'; $list = Block::getBlockList(['type' => $type, 'field' => $field]); // 根据type 区分新的数组 $newList = [ 'banner' => [], 'lottery' => [], 'article' => [], 'measure' => [], ]; foreach ($list as $item) { if ($item['type'] == '首页BANNER') { $bannerList[] = $item; } if ($item['type'] == '首页LOTTERY') { $lotteryList[] = $item; } if ($item['type'] == '首页ARTICE') { $articleList[] = $item; } if ($item['type'] == '首页MEASURE') { $measureList[] = $item; } } $newList['banner'] = $bannerList; $newList['lottery'] = $lotteryList; $newList['article'] = $articleList; $newList['measure'] = $measureList; // todo 查询活动商品 // 首页推荐的分类 $indexCategoryList = Category::where('status', StatusEnum::ENABLED) ->field('id,name,image') ->where('is_recommend',StatusEnum::YES) ->order('weigh desc') ->limit(8) ->select(); //热门分类 $indexHotCategoryList = Category::where('status', StatusEnum::ENABLED) ->field('id,name,image') ->where('is_hot',StatusEnum::YES) ->order('weigh desc') ->limit(4) ->select(); //查询 活动商品 $newList['indexCategoryList'] = $indexCategoryList; $newList['indexHotCategoryList'] = $indexHotCategoryList; $this->success('', $newList); } /** * 上传文件 * @ApiMethod (POST) * @ApiParams (name="file", type="file", required=true, description="文件流") */ public function upload() { Config::set('default_return_type', 'json'); //必须设定cdnurl为空,否则cdnurl函数计算错误 Config::set('upload.cdnurl', ''); $chunkid = $this->request->post("chunkid"); if ($chunkid) { if (!Config::get('upload.chunking')) { $this->error(__('Chunk file disabled')); } $action = $this->request->post("action"); $chunkindex = $this->request->post("chunkindex/d"); $chunkcount = $this->request->post("chunkcount/d"); $filename = $this->request->post("filename"); $method = $this->request->method(true); if ($action == 'merge') { $attachment = null; //合并分片文件 try { $upload = new Upload(); $attachment = $upload->merge($chunkid, $chunkcount, $filename); } catch (UploadException $e) { $this->error($e->getMessage()); } $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]); } elseif ($method == 'clean') { //删除冗余的分片文件 try { $upload = new Upload(); $upload->clean($chunkid); } catch (UploadException $e) { $this->error($e->getMessage()); } $this->success(); } else { //上传分片文件 //默认普通上传文件 $file = $this->request->file('file'); try { $upload = new Upload($file); $upload->chunk($chunkid, $chunkindex, $chunkcount); } catch (UploadException $e) { $this->error($e->getMessage()); } $this->success(); } } else { $attachment = null; //默认普通上传文件 $file = $this->request->file('file'); try { $upload = new Upload($file); $attachment = $upload->upload(); } catch (UploadException $e) { $this->error($e->getMessage()); } catch (\Exception $e) { $this->error($e->getMessage()); } $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]); } } /** * 验证码 * @ApiParams (name="id", type="string", required=true, description="要生成验证码的标识") * @return \think\Response */ public function captcha($id = "") { \think\Config::set([ 'captcha' => array_merge(config('captcha'), [ 'fontSize' => 44, 'imageH' => 150, 'imageW' => 350, ]) ]); $captcha = new Captcha((array)Config::get('captcha')); return $captcha->entry($id); } }