123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- <?php
- namespace app\api\controller;
- use app\admin\model\Agreement;
- use app\common\controller\Api;
- use app\common\exception\UploadException;
- use app\common\library\Upload;
- use app\common\model\Ad;
- use app\common\model\Area;
- use app\common\model\Feedback;
- use app\common\model\FeedbackBusiness;
- use app\common\model\MobileOrder;
- use app\common\service\SmsSend;
- use think\Cache;
- use think\Config;
- use think\File;
- /**
- * 公共接口
- */
- class Common extends Api
- {
- protected $noNeedLogin = ['agreement','ads','area','area_sort','area_tree','config','get_area','upload','feedback','business_form'];
- protected $noNeedRight="*";
- /**
- * 获取各种协议
- * @param int id 1入网许可协议2个人信息收集证明3查询订单说明4商务合作说明5隐私权政策6法律责任风险提示告知书
- * @ApiReturnParams(name=title,type=string,description=标题)
- * @ApiReturnParams(name=content,type=string,description=内容)
- */
- public function agreement(){
- $data=input();
- $this->validate($data,[
- 'id'=>['require'],
- ]);
- $agreement=Agreement::where('id',$data['id'])->value('content','');
- $agreement=$this->_($agreement);
- $this->success('',$agreement);
- }
- /**
- * 获取轮播图
- * @param string pos 位置index首页
- * @ApiReturnParams (name=img,description=图片地址)
- * @ApiReturnParams (name=link,description=链接)
- */
- public function ads(){
- $data=input();
- $this->validate($data,[
- 'pos'=>'require',
- ]);
- $chanId=getChanId();
- $ads=Ad::getAd($data['pos'],$chanId);
- $this->success('',$ads);
- }
- /**
- * 上传文件
- * @ApiMethod (POST)
- * @param File $file 文件流
- */
- 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());
- }
- $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
- }
- }
- /**
- * 意见反馈
- * @ApiParams (name=name,description="称呼")
- * @ApiParams (name=phone,description=电话)
- * @ApiParams (name=sms_code,description=验证码)
- * @ApiParams (name=title,description=标题)
- * @ApiParams (name=content,description=内容)
- * @ApiParams (name=images,description=图片数组)
- */
- public function feedback(){
- $data=input();
- $this->validate($data,[
- 'name|姓名'=>['require','max:10'],
- 'phone|手机号'=>['require','integer','length:11'],
- 'title|标题'=>['require','max:10'],
- 'content|内容'=>['require','max:120'],
- 'images|图片'=>['require','array','max:3','min:1'],
- 'images.0'=>['require','url'],
- ]);
- SmsSend::setMobile($data['phone'])->setCode($data['sms_code']??'')->check();
- $feedback=new Feedback();
- $feedback->allowField(true)->save($data);
- $this->success('',$feedback);
- }
- /**
- * 商务合作
- * @ApiParams (name=type,description="1个人2公司")
- * @ApiParams (name=name,description="名称")
- * @ApiParams (name=for,description="方向1直播合作2学习直播3卡商合作")
- * @ApiParams (name=has_exp,description="1有0无经验")
- * @ApiParams (name=phone,description="手机号")
- * @ApiParams (name=sms_code,description="验证码")
- *
- */
- public function business_form(){
- $data=$this->_validate([
- 'type|类型'=>['require','in:1,2'],
- 'name|名称'=>['require','max:50'],
- 'for|方向'=>['require','in:1,2,3'],
- 'has_exp'=>['require','in:1,0'],
- 'phone|手机号'=>['require','integer','length:11'],
- ]);
- SmsSend::setMobile($data['phone'])->setCode($data['sms_code']??'')->check();
- $feedback=new FeedbackBusiness;
- $feedback->allowField(true)->save($data);
- $this->success('',$feedback);
- }
- /**
- * 获取地区信息
- * @ApiParams (name=level,description=1省2市3区)
- * @ApiParams (name=pid,description=上级区域ID)
- */
- public function area(){
- $data=$this->_validate([
- 'level'=>['require'],
- 'pid'=>['require'],
- ]);
- $this->success(
- '',
- Area::where('level',$data['level'])
- ->where('pid',$data['pid'])
- ->order('pinyin')
- ->select()
- );
- }
- /**
- * 获取地区信息(按字母排序)
- */
- public function area_sort(){
- $citys=Area::area()->field(['id','name','first'])->select();
- $a=[];
- for ($i=65;$i<91;$i++) {
- $one=[
- 'index'=>chr($i),
- 'child'=>[]
- ];
- foreach ($citys as $key=>&$city) {
- if($city['first']==$one['index']){
- $one['child'][]=[
- 'title'=>$city['name'],
- 'weight'=>$city['id'],
- 'id' =>$city['id'],
- ];
- unset($citys[$key]);
- }
- }
- $a[]=$one;
- }
- $this->success('',$a);
- }
- /**
- * 地区递归三级联动
- */
- public function area_tree(){
- function area(&$data,$areas,$first=false){
- foreach ($areas as $k=>$area){
- if($first){
- if($area['pid']==0) {
- area($area, $areas);
- unset($area['pid']);
- $data[] = $area;
- unset($areas[$k]);
- }
- }else{
- if($data['value']==$area['pid']){
- area($area, $areas);
- unset($area['pid']);
- $data['children'][]=$area;
- unset($areas[$k]);
- }
- }
- }
- }
- $fromCache=Cache::get('app_area');
- if(!$fromCache){
- $fina=[];
- $areas=Area::where('level','<=',3)->field('id as value,name as label,pid')->select()->toArray();
- area($fina,$areas,true);
- $fromCache=$fina;
- Cache::remember('app_area',$fina,0);
- }
- $this->success('',$fromCache);
- }
- /**
- * 根据名称获取信息
- * @ApiParams (name="name",description="城市名")
- * @ApiReturnParams (name="id",description="城市ID")
- */
- public function get_area(){
- $rs=null;
- if($name=input('name')){
- $cacheName="area_name_".$name;
- $rs=Cache::get($cacheName,null);
- if(!$rs){
- $rs=Area::where('name|shortname',$name)->find();
- Cache::set($cacheName,$rs);
- }
- }
- $this->success('',$rs);
- }
- /**
- * 获取系统配置
- * @ApiReturnParams (name="site_name",description="站点名称")
- * @ApiReturnParams (name="com_name",description="公司名称")
- * @ApiReturnParams (name="wxp_name",description="微信公众号名称")
- * @ApiReturnParams (name="wxp_qrcode",description="微信公众号二维码")
- * @ApiReturnParams (name="service_mobile",description="客服手机号")
- * @ApiReturnParams (name="system_service_mobile_show",description="是否展示客服手机号")
- * @ApiReturnParams (name="service_work_time",description="客服工作时间")
- * @ApiReturnParams (name="system_sms_open",description="短信验证码开关")
- * @ApiReturnParams (name="disable_send_province",description="禁止发货地区")
- * @ApiReturnParams (name="system_index_tr",description="首页右上角展示1投诉2商务合作")
- * @ApiReturnParams (name="system_index_m1",description="首页特价号1流量卡2号码定制3特价号")
- * @ApiReturnParams (name="system_id_form_open",description="身份证开关")
- * @ApiReturnParams (name="flow_main_logo",description="流量卡上方图片")
- * @ApiReturnParams (name="flow_main_link",description="流量卡上方图片链接")
- * @ApiReturnParams (name="flow_order_bg",description="流量卡订单查询背景图")
- * @ApiReturnParams (name="bussiness_contact_mobile",description="商务合作电话")
- * @ApiReturnParams (name="beauti_no_detail_bg",description="详情页背景图")
- * @ApiReturnParams (name="beauti_no_detail_text",description="详情页详情文本")
- * @ApiReturnParams (name="index_no_type",description="首页进入展示列表all全部local本地")
- * @ApiReturnParams (name="copy_btn_title",description="靓号详情复制按钮显示字符")
- * @ApiReturnParams (name="click_pop_content",description="复制按钮点击后弹窗内容")
- * @ApiReturnParams (name="flow_service_h5",description="平台h5客服类型1电话,2链接,3二维码")
- * @ApiReturnParams (name="flow_service_dy",description="平台抖音客服类型1电话,2链接,3二维码")
- * @ApiReturnParams (name="flow_service_ks",description="平台快手客服类型1电话,2链接,3二维码")
- * @ApiReturnParams (name="flow_service_tel",description="电话号")
- * @ApiReturnParams (name="flow_service_link",description="跳转链接")
- * @ApiReturnParams (name="flow_service_qrcode",description="二维码")
- * @ApiReturnParams (name="flow_service_qrcode_name",description="二维码名称")
- */
- public function config(){
- $chanId=getChanId();
- $data=[
- 'site_name'=>\config('site.name'),
- 'com_name'=>\config('site.base_company_name'),
- 'wxp_name'=>\config('site.system_wxp_name'),
- 'wxp_qrcode'=>\config('site.system_wxp_qrcode'),
- 'service_mobile'=>\config('site.system_service_mobile'),
- 'system_service_mobile_show'=>\config('site.system_service_mobile_show')?true:false,
- 'service_work_time'=>\config('site.service_work_time'),
- 'system_sms_open'=>\config('site.system_sms_open')?true:false,
- 'disable_send_province'=>Area::whereIn('id',\config('site.disable_send_province')?:0)->field('id,name')->select(),
- 'system_index_tr'=>config('site.system_index_tr')?:1,
- 'system_index_m1'=>config('site.system_index_m1')?:1,
- 'system_id_form_open'=>config('site.system_id_form_open')?1:0,
- 'flow_main_logo'=>config('site.flow_main_logo'),
- 'flow_main_link'=>config('site.flow_main_link'),
- 'flow_order_bg'=>config('site.flow_order_bg'),
- 'bussiness_contact_mobile'=>config('site.bussiness_contact_mobile'),
- 'beauti_no_detail_bg'=>config('site.beauti_no_detail_bg'),
- 'beauti_no_detail_text'=>\config('site.beauti_no_detail_text'),
- 'index_no_type'=>config('site.index_no_type')?:'all',
- 'copy_btn_title'=>config('site.copy_btn_title')?:'申请优惠',
- 'click_pop_content'=>config('site.click_pop_content'),
- 'flow_service_h5' => config('site.flow_service_h5'),
- 'flow_service_dy' => config('site.flow_service_dy'),
- 'flow_service_ks' => config('site.flow_service_ks'),
- 'flow_service_tel' => config('site.flow_service_tel'),
- 'flow_service_link' => config('site.flow_service_link'),
- 'flow_service_qrcode_name' => config('site.flow_service_qrcode_name'),
- 'flow_service_qrcode' => config('site.flow_service_qrcode'),
- ];
- if($chanId){
- if(getSub()->getAdmin('wx_qr')){
- $data['wxp_qrcode']=getSub()->getAdmin('wx_qr');
- }
- if(getSub()->getAdmin('wxp_name')){
- $data['wxp_name']=getSub()->getAdmin('wxp_name');
- }
- if($service = getSub()->getAdmin('flow_service')){
- $platform = \app\admin\model\AuthGroup::$servicePlatform;
- $tmpService = json_decode($service, true);
- foreach($platform as $key=>$val){
- $tmpKey = 'flow_service_'.$key;
- if(isset($tmpService[$tmpKey]) && $tmpService[$tmpKey]) $data[$tmpKey] = $tmpService[$tmpKey];
- }
-
- $tmp_flow_service_tel = getSub()->getAdmin('flow_service_tel');
- $tmp_flow_service_link = getSub()->getAdmin('flow_service_link');
- $tmp_flow_service_qrcode = getSub()->getAdmin('flow_service_qrcode');
- $tmp_flow_service_qrcode_name = getSub()->getAdmin('flow_service_qrcode_name');
-
- if($tmp_flow_service_tel) $data['flow_service_tel'] = $tmp_flow_service_tel;
- if($tmp_flow_service_link) $data['flow_service_link'] = $tmp_flow_service_link;
- if($tmp_flow_service_qrcode) $data['flow_service_qrcode'] = $tmp_flow_service_qrcode;
- if($tmp_flow_service_qrcode_name) $data['flow_service_qrcode_name'] = $tmp_flow_service_qrcode_name;
- }
- }
- $data['beauti_no_detail_text']=$this->_($data['beauti_no_detail_text']);
- $this->success('',$data);
- }
- protected function _($agreement){
- $agreement=str_replace('<p','<div',$agreement);
- $agreement=str_replace('</p','</div',$agreement);
- $agreement=str_replace("\r",'',$agreement);
- $agreement=str_replace("\n",'',$agreement);
- return $agreement;
- }
- //签收订单自动已完成
- public function order_completed(){
- MobileOrder::makeOver();
- }
- }
|