123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- <?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\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','about'];
- protected $noNeedRight="*";
- /**
- * 获取各种协议
- * @param int id 1用户协议2隐私政策
- * @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','');
- $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',
- ]);
- $ads=Ad::getAd($data['pos']);
- $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=answer[exp],description="购物体验")
- * @ApiParams (name=answer[speed],description="响应速度")
- * @ApiParams (name=answer[design],description="设计符合购物习惯吗")
- * @ApiParams (name=answer[kf],description="服务态度满意吗")
- * @ApiParams (name=feed,description="其他意见")
- */
- public function feedback(){
- $data=input();
- $this->validate($data,[
- 'answer|意见'=>['require','array'],
- 'answer.exp|购物体验'=>['require'],
- 'answer.speed|响应速度'=>['require'],
- 'answer.design|设计符合购物习惯吗'=>['require'],
- 'answer.kf|服务态度满意吗'=>['require'],
- 'feed|其他意见'=>['require'],
- ]);
- $feedback=new Feedback();
- $feedback['user_id']=$this->auth->id;
- $feedback['content']=[
- 'answer'=>$data['answer'],
- 'feed'=>$data['feed'],
- ];
- $feedback->save();
- $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="beian",description="备案号")
- * @ApiReturnParams (name="telephone",description="座机号")
- * @ApiReturnParams (name="company_address",description="公司地址")
- * @ApiReturnParams (name="service_time",description="服务时间")
- * @ApiReturnParams (name="mobile_kp",description="手机屏酷码")
- * @ApiReturnParams (name="footer_left_logo",description="左下角logo")
- * @ApiReturnParams (name="cloud_link",description="云平台链接")
- */
- public function config(){
- $data=[
- 'site_name'=>\config('site.name'),
- 'com_name'=>\config('site.base_company_name'),
- 'beian'=>\config('site.beian'),
- 'telephone'=>\config('site.telephone'),
- 'company_address'=>\config('site.company_address'),
- 'service_time'=>\config('site.service_time'),
- 'mobile_kp'=>\config('site.mobile_kp'),
- 'footer_left_logo'=>\config('site.footer_left_logo'),
- 'cloud_link'=>\config('site.cloud_link'),
- ];
- $this->success('',$data);
- }
- /**
- * 关于酷屏
- * @ApiReturnParams(name=content,type=string,description=内容)
- */
- public function about(){
- $content=Db('AboutScreen')->where('id',1)->value('content','');
- $this->success('',$content);
- }
- }
|