Common.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\Agreement;
  4. use app\common\controller\Api;
  5. use app\common\exception\UploadException;
  6. use app\common\library\Upload;
  7. use app\common\model\Ad;
  8. use app\common\model\Area;
  9. use app\common\model\Feedback;
  10. use app\common\model\FeedbackBusiness;
  11. use app\common\model\MobileOrder;
  12. use app\common\service\SmsSend;
  13. use think\Cache;
  14. use think\Config;
  15. use think\File;
  16. /**
  17. * 公共接口
  18. */
  19. class Common extends Api
  20. {
  21. protected $noNeedLogin = ['agreement','ads','area','area_sort','area_tree','config','get_area','upload','feedback','business_form'];
  22. protected $noNeedRight="*";
  23. /**
  24. * 获取各种协议
  25. * @param int id 1入网许可协议2个人信息收集证明3查询订单说明4商务合作说明5隐私权政策6法律责任风险提示告知书
  26. * @ApiReturnParams(name=title,type=string,description=标题)
  27. * @ApiReturnParams(name=content,type=string,description=内容)
  28. */
  29. public function agreement(){
  30. $data=input();
  31. $this->validate($data,[
  32. 'id'=>['require'],
  33. ]);
  34. $agreement=Agreement::where('id',$data['id'])->value('content','');
  35. $agreement=$this->_($agreement);
  36. $this->success('',$agreement);
  37. }
  38. /**
  39. * 获取轮播图
  40. * @param string pos 位置index首页
  41. * @ApiReturnParams (name=img,description=图片地址)
  42. * @ApiReturnParams (name=link,description=链接)
  43. */
  44. public function ads(){
  45. $data=input();
  46. $this->validate($data,[
  47. 'pos'=>'require',
  48. ]);
  49. $chanId=getChanId();
  50. $ads=Ad::getAd($data['pos'],$chanId);
  51. $this->success('',$ads);
  52. }
  53. /**
  54. * 上传文件
  55. * @ApiMethod (POST)
  56. * @param File $file 文件流
  57. */
  58. public function upload()
  59. {
  60. Config::set('default_return_type', 'json');
  61. //必须设定cdnurl为空,否则cdnurl函数计算错误
  62. Config::set('upload.cdnurl', '');
  63. $chunkid = $this->request->post("chunkid");
  64. if ($chunkid) {
  65. if (!Config::get('upload.chunking')) {
  66. $this->error(__('Chunk file disabled'));
  67. }
  68. $action = $this->request->post("action");
  69. $chunkindex = $this->request->post("chunkindex/d");
  70. $chunkcount = $this->request->post("chunkcount/d");
  71. $filename = $this->request->post("filename");
  72. $method = $this->request->method(true);
  73. if ($action == 'merge') {
  74. $attachment = null;
  75. //合并分片文件
  76. try {
  77. $upload = new Upload();
  78. $attachment = $upload->merge($chunkid, $chunkcount, $filename);
  79. } catch (UploadException $e) {
  80. $this->error($e->getMessage());
  81. }
  82. $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
  83. } elseif ($method == 'clean') {
  84. //删除冗余的分片文件
  85. try {
  86. $upload = new Upload();
  87. $upload->clean($chunkid);
  88. } catch (UploadException $e) {
  89. $this->error($e->getMessage());
  90. }
  91. $this->success();
  92. } else {
  93. //上传分片文件
  94. //默认普通上传文件
  95. $file = $this->request->file('file');
  96. try {
  97. $upload = new Upload($file);
  98. $upload->chunk($chunkid, $chunkindex, $chunkcount);
  99. } catch (UploadException $e) {
  100. $this->error($e->getMessage());
  101. }
  102. $this->success();
  103. }
  104. } else {
  105. $attachment = null;
  106. //默认普通上传文件
  107. $file = $this->request->file('file');
  108. try {
  109. $upload = new Upload($file);
  110. $attachment = $upload->upload();
  111. } catch (UploadException $e) {
  112. $this->error($e->getMessage());
  113. }
  114. $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
  115. }
  116. }
  117. /**
  118. * 意见反馈
  119. * @ApiParams (name=name,description="称呼")
  120. * @ApiParams (name=phone,description=电话)
  121. * @ApiParams (name=sms_code,description=验证码)
  122. * @ApiParams (name=title,description=标题)
  123. * @ApiParams (name=content,description=内容)
  124. * @ApiParams (name=images,description=图片数组)
  125. */
  126. public function feedback(){
  127. $data=input();
  128. $this->validate($data,[
  129. 'name|姓名'=>['require','max:10'],
  130. 'phone|手机号'=>['require','integer','length:11'],
  131. 'title|标题'=>['require','max:10'],
  132. 'content|内容'=>['require','max:120'],
  133. 'images|图片'=>['require','array','max:3','min:1'],
  134. 'images.0'=>['require','url'],
  135. ]);
  136. SmsSend::setMobile($data['phone'])->setCode($data['sms_code']??'')->check();
  137. $feedback=new Feedback();
  138. $feedback->allowField(true)->save($data);
  139. $this->success('',$feedback);
  140. }
  141. /**
  142. * 商务合作
  143. * @ApiParams (name=type,description="1个人2公司")
  144. * @ApiParams (name=name,description="名称")
  145. * @ApiParams (name=for,description="方向1直播合作2学习直播3卡商合作")
  146. * @ApiParams (name=has_exp,description="1有0无经验")
  147. * @ApiParams (name=phone,description="手机号")
  148. * @ApiParams (name=sms_code,description="验证码")
  149. *
  150. */
  151. public function business_form(){
  152. $data=$this->_validate([
  153. 'type|类型'=>['require','in:1,2'],
  154. 'name|名称'=>['require','max:50'],
  155. 'for|方向'=>['require','in:1,2,3'],
  156. 'has_exp'=>['require','in:1,0'],
  157. 'phone|手机号'=>['require','integer','length:11'],
  158. ]);
  159. SmsSend::setMobile($data['phone'])->setCode($data['sms_code']??'')->check();
  160. $feedback=new FeedbackBusiness;
  161. $feedback->allowField(true)->save($data);
  162. $this->success('',$feedback);
  163. }
  164. /**
  165. * 获取地区信息
  166. * @ApiParams (name=level,description=1省2市3区)
  167. * @ApiParams (name=pid,description=上级区域ID)
  168. */
  169. public function area(){
  170. $data=$this->_validate([
  171. 'level'=>['require'],
  172. 'pid'=>['require'],
  173. ]);
  174. $this->success(
  175. '',
  176. Area::where('level',$data['level'])
  177. ->where('pid',$data['pid'])
  178. ->order('pinyin')
  179. ->select()
  180. );
  181. }
  182. /**
  183. * 获取地区信息(按字母排序)
  184. */
  185. public function area_sort(){
  186. $citys=Area::area()->field(['id','name','first'])->select();
  187. $a=[];
  188. for ($i=65;$i<91;$i++) {
  189. $one=[
  190. 'index'=>chr($i),
  191. 'child'=>[]
  192. ];
  193. foreach ($citys as $key=>&$city) {
  194. if($city['first']==$one['index']){
  195. $one['child'][]=[
  196. 'title'=>$city['name'],
  197. 'weight'=>$city['id'],
  198. 'id' =>$city['id'],
  199. ];
  200. unset($citys[$key]);
  201. }
  202. }
  203. $a[]=$one;
  204. }
  205. $this->success('',$a);
  206. }
  207. /**
  208. * 地区递归三级联动
  209. */
  210. public function area_tree(){
  211. function area(&$data,$areas,$first=false){
  212. foreach ($areas as $k=>$area){
  213. if($first){
  214. if($area['pid']==0) {
  215. area($area, $areas);
  216. unset($area['pid']);
  217. $data[] = $area;
  218. unset($areas[$k]);
  219. }
  220. }else{
  221. if($data['value']==$area['pid']){
  222. area($area, $areas);
  223. unset($area['pid']);
  224. $data['children'][]=$area;
  225. unset($areas[$k]);
  226. }
  227. }
  228. }
  229. }
  230. $fromCache=Cache::get('app_area');
  231. if(!$fromCache){
  232. $fina=[];
  233. $areas=Area::where('level','<=',3)->field('id as value,name as label,pid')->select()->toArray();
  234. area($fina,$areas,true);
  235. $fromCache=$fina;
  236. Cache::remember('app_area',$fina,0);
  237. }
  238. $this->success('',$fromCache);
  239. }
  240. /**
  241. * 根据名称获取信息
  242. * @ApiParams (name="name",description="城市名")
  243. * @ApiReturnParams (name="id",description="城市ID")
  244. */
  245. public function get_area(){
  246. $rs=null;
  247. if($name=input('name')){
  248. $cacheName="area_name_".$name;
  249. $rs=Cache::get($cacheName,null);
  250. if(!$rs){
  251. $rs=Area::where('name|shortname',$name)->find();
  252. Cache::set($cacheName,$rs);
  253. }
  254. }
  255. $this->success('',$rs);
  256. }
  257. /**
  258. * 获取系统配置
  259. * @ApiReturnParams (name="site_name",description="站点名称")
  260. * @ApiReturnParams (name="com_name",description="公司名称")
  261. * @ApiReturnParams (name="wxp_name",description="微信公众号名称")
  262. * @ApiReturnParams (name="wxp_qrcode",description="微信公众号二维码")
  263. * @ApiReturnParams (name="service_mobile",description="客服手机号")
  264. * @ApiReturnParams (name="system_service_mobile_show",description="是否展示客服手机号")
  265. * @ApiReturnParams (name="service_work_time",description="客服工作时间")
  266. * @ApiReturnParams (name="system_sms_open",description="短信验证码开关")
  267. * @ApiReturnParams (name="disable_send_province",description="禁止发货地区")
  268. * @ApiReturnParams (name="system_index_tr",description="首页右上角展示1投诉2商务合作")
  269. * @ApiReturnParams (name="system_index_m1",description="首页特价号1流量卡2号码定制3特价号")
  270. * @ApiReturnParams (name="system_id_form_open",description="身份证开关")
  271. * @ApiReturnParams (name="flow_main_logo",description="流量卡上方图片")
  272. * @ApiReturnParams (name="flow_main_link",description="流量卡上方图片链接")
  273. * @ApiReturnParams (name="flow_order_bg",description="流量卡订单查询背景图")
  274. * @ApiReturnParams (name="bussiness_contact_mobile",description="商务合作电话")
  275. * @ApiReturnParams (name="beauti_no_detail_bg",description="详情页背景图")
  276. * @ApiReturnParams (name="beauti_no_detail_text",description="详情页详情文本")
  277. * @ApiReturnParams (name="index_no_type",description="首页进入展示列表all全部local本地")
  278. * @ApiReturnParams (name="copy_btn_title",description="靓号详情复制按钮显示字符")
  279. * @ApiReturnParams (name="click_pop_content",description="复制按钮点击后弹窗内容")
  280. * @ApiReturnParams (name="flow_service_h5",description="平台h5客服类型1电话,2链接,3二维码")
  281. * @ApiReturnParams (name="flow_service_dy",description="平台抖音客服类型1电话,2链接,3二维码")
  282. * @ApiReturnParams (name="flow_service_ks",description="平台快手客服类型1电话,2链接,3二维码")
  283. * @ApiReturnParams (name="flow_service_tel",description="电话号")
  284. * @ApiReturnParams (name="flow_service_link",description="跳转链接")
  285. * @ApiReturnParams (name="flow_service_qrcode",description="二维码")
  286. * @ApiReturnParams (name="flow_service_qrcode_name",description="二维码名称")
  287. */
  288. public function config(){
  289. $chanId=getChanId();
  290. $data=[
  291. 'site_name'=>\config('site.name'),
  292. 'com_name'=>\config('site.base_company_name'),
  293. 'wxp_name'=>\config('site.system_wxp_name'),
  294. 'wxp_qrcode'=>\config('site.system_wxp_qrcode'),
  295. 'service_mobile'=>\config('site.system_service_mobile'),
  296. 'system_service_mobile_show'=>\config('site.system_service_mobile_show')?true:false,
  297. 'service_work_time'=>\config('site.service_work_time'),
  298. 'system_sms_open'=>\config('site.system_sms_open')?true:false,
  299. 'disable_send_province'=>Area::whereIn('id',\config('site.disable_send_province')?:0)->field('id,name')->select(),
  300. 'system_index_tr'=>config('site.system_index_tr')?:1,
  301. 'system_index_m1'=>config('site.system_index_m1')?:1,
  302. 'system_id_form_open'=>config('site.system_id_form_open')?1:0,
  303. 'flow_main_logo'=>config('site.flow_main_logo'),
  304. 'flow_main_link'=>config('site.flow_main_link'),
  305. 'flow_order_bg'=>config('site.flow_order_bg'),
  306. 'bussiness_contact_mobile'=>config('site.bussiness_contact_mobile'),
  307. 'beauti_no_detail_bg'=>config('site.beauti_no_detail_bg'),
  308. 'beauti_no_detail_text'=>\config('site.beauti_no_detail_text'),
  309. 'index_no_type'=>config('site.index_no_type')?:'all',
  310. 'copy_btn_title'=>config('site.copy_btn_title')?:'申请优惠',
  311. 'click_pop_content'=>config('site.click_pop_content'),
  312. 'flow_service_h5' => config('site.flow_service_h5'),
  313. 'flow_service_dy' => config('site.flow_service_dy'),
  314. 'flow_service_ks' => config('site.flow_service_ks'),
  315. 'flow_service_tel' => config('site.flow_service_tel'),
  316. 'flow_service_link' => config('site.flow_service_link'),
  317. 'flow_service_qrcode_name' => config('site.flow_service_qrcode_name'),
  318. 'flow_service_qrcode' => config('site.flow_service_qrcode'),
  319. ];
  320. if($chanId){
  321. if(getSub()->getAdmin('wx_qr')){
  322. $data['wxp_qrcode']=getSub()->getAdmin('wx_qr');
  323. }
  324. if(getSub()->getAdmin('wxp_name')){
  325. $data['wxp_name']=getSub()->getAdmin('wxp_name');
  326. }
  327. if($service = getSub()->getAdmin('flow_service')){
  328. $platform = \app\admin\model\AuthGroup::$servicePlatform;
  329. $tmpService = json_decode($service, true);
  330. foreach($platform as $key=>$val){
  331. $tmpKey = 'flow_service_'.$key;
  332. if(isset($tmpService[$tmpKey]) && $tmpService[$tmpKey]) $data[$tmpKey] = $tmpService[$tmpKey];
  333. }
  334. $tmp_flow_service_tel = getSub()->getAdmin('flow_service_tel');
  335. $tmp_flow_service_link = getSub()->getAdmin('flow_service_link');
  336. $tmp_flow_service_qrcode = getSub()->getAdmin('flow_service_qrcode');
  337. $tmp_flow_service_qrcode_name = getSub()->getAdmin('flow_service_qrcode_name');
  338. if($tmp_flow_service_tel) $data['flow_service_tel'] = $tmp_flow_service_tel;
  339. if($tmp_flow_service_link) $data['flow_service_link'] = $tmp_flow_service_link;
  340. if($tmp_flow_service_qrcode) $data['flow_service_qrcode'] = $tmp_flow_service_qrcode;
  341. if($tmp_flow_service_qrcode_name) $data['flow_service_qrcode_name'] = $tmp_flow_service_qrcode_name;
  342. }
  343. }
  344. $data['beauti_no_detail_text']=$this->_($data['beauti_no_detail_text']);
  345. $this->success('',$data);
  346. }
  347. protected function _($agreement){
  348. $agreement=str_replace('<p','<div',$agreement);
  349. $agreement=str_replace('</p','</div',$agreement);
  350. $agreement=str_replace("\r",'',$agreement);
  351. $agreement=str_replace("\n",'',$agreement);
  352. return $agreement;
  353. }
  354. //签收订单自动已完成
  355. public function order_completed(){
  356. MobileOrder::makeOver();
  357. }
  358. }