Community.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\CooperationConfiguration;
  5. use app\common\model\Document;
  6. use app\common\model\Cooperation;
  7. use app\common\model\DownloadLink;
  8. use app\common\model\Faq;
  9. use app\common\model\TeachingVideo;
  10. use app\common\model\VersionComparison;
  11. use app\common\model\VersionUpdating;
  12. use app\common\model\VersionUpdatingText;
  13. use app\common\model\Visit;
  14. use app\common\model\VisitConfiguration;
  15. /**
  16. * 社区接口
  17. */
  18. class Community extends Api
  19. {
  20. // protected $noNeedLogin = ['document,teaching_video'];
  21. protected $noNeedLogin = ['*'];
  22. /**
  23. * 教学视频列表
  24. */
  25. public function teaching_video(){
  26. $list = [];
  27. $classify = ['好柿购','多享柿','门柿购','海柿购','柿知识'];
  28. foreach ($classify as $v){
  29. $data = TeachingVideo::all(function ($query) use ($v){
  30. $query->where('type',$v)->limit(3);
  31. });
  32. array_push($list,$data);
  33. }
  34. $this->success('成功',$list);
  35. }
  36. /**
  37. * 教学视频详情
  38. * @ApiParams (name="type",description="好柿购','多享柿','门柿购','海柿购','柿知识")
  39. */
  40. public function teaching_video_x(){
  41. $data = TeachingVideo::all(function ($query){
  42. $query->where('type',input('type'))->field('*,TIME_TO_SEC(duration) as total');
  43. });
  44. $total = 0;
  45. foreach ($data as $v){
  46. $total += $v['total'];
  47. unset($v['total']);
  48. }
  49. $total=$this->changeTimeType($total);
  50. $list = ['list'=>$data,'total'=>$total];
  51. $this->success('成功',$list);
  52. }
  53. /**
  54. * 计算视频总时长
  55. */
  56. public function changeTimeType($seconds){
  57. if ($seconds >3600){
  58. $hours =intval($seconds/3600);
  59. $minutes = $seconds % 3600;
  60. $time = $hours.":".gmstrftime('%M:%S',$minutes);
  61. }else{
  62. $time = gmstrftime('%H:%M:%S',$seconds);
  63. }
  64. return$time;
  65. }
  66. /**
  67. * 文档列表
  68. */
  69. public function document_list(){
  70. $data = Document::all(function ($query){
  71. $query->where(['pid'=>0,'ismenu'=>1])->order('belong sec');
  72. });
  73. $this->success('成功',$data);
  74. }
  75. /**
  76. * 文档详情
  77. * @ApiParams (name="type",description="0好柿购,1多享柿,2门柿购,3海柿购,4柿知识")
  78. */
  79. public function document(){
  80. switch (input('type')){
  81. case 0:
  82. $where = ['belong'=>0];
  83. break;
  84. case 1:
  85. $where = ['belong'=>1];
  86. break;
  87. case 2:
  88. $where = ['belong'=>2];
  89. break;
  90. case 3:
  91. $where = ['belong'=>3];
  92. break;
  93. case 4:
  94. $where = ['belong'=>4];
  95. }
  96. $data = Document::where($where)->select();
  97. $res = [];
  98. foreach ($data as $k=>$v){
  99. array_push($res,$v->toarray());
  100. }
  101. $list = $this->getTree($res,'id','pid','children');
  102. $this->success('返回成功', $list);
  103. }
  104. /**
  105. * 树形化
  106. * @param $arr
  107. * @param $id
  108. * @param $fid
  109. * @param $child_name
  110. * @return array
  111. */
  112. function getTree($arr, $id = 'id', $fid = 'fid', $child_name = 'children'){
  113. $refer = array();
  114. $tree = array();
  115. foreach ($arr as $k => $v) {
  116. $refer[$v[$id]] = &$arr[$k]; //创建主键的数组引用
  117. }
  118. foreach ($arr as $k => $v) {
  119. $pid = $v[$fid]; //获取当前分类的父级id
  120. if ($pid == 0) {
  121. $tree[] = &$arr[$k]; //顶级栏目
  122. } else {
  123. if (isset($refer[$pid])) {
  124. $refer[$pid][$child_name][] = &$arr[$k]; //如果存在父级栏目,则添加进父级栏目的子栏目数组中
  125. }
  126. }
  127. }
  128. return $tree;
  129. }
  130. //
  131. /**
  132. * 成为合作伙伴
  133. * @ApiParams (name="token")
  134. * @ApiParams (name="name",description="姓名")
  135. * @ApiParams (name="phone",description="联系方式")
  136. * @ApiParams (name="company",description="公司名称")
  137. */
  138. public function become_cooperation(){
  139. $rule = [
  140. 'name|姓名'=>'require',
  141. 'phone|联系方式'=>'require',
  142. 'company|公司名称'=>'require',
  143. ];
  144. $data = $this->_validate($rule);
  145. $data['uid'] = $this->auth->id;
  146. Cooperation::create($data)?$this->success('提交成功'):$this->error('提交失败');
  147. }
  148. /**
  149. * 预约参观公司
  150. * @ApiParams (name="token")
  151. * @ApiParams (name="name",description="称呼")
  152. * @ApiParams (name="phone",description="手机号")
  153. * @ApiParams (name="visit_time",description="参观时间")
  154. */
  155. public function visit(){
  156. $rule = [
  157. 'name|称呼'=>'require',
  158. 'phone|手机号'=>'require',
  159. 'visit_time|参观时间'=>'require',
  160. ];
  161. $data = $this->_validate($rule);
  162. $data['uid'] = $this->auth->id;
  163. Visit::create($data)?$this->success('提交成功'):$this->error('提交失败');
  164. }
  165. /**
  166. * 下载地址
  167. */
  168. public function download_link(){
  169. $link = DownloadLink::all();
  170. foreach ($link as &$value){
  171. $value['image'] = explode(',',$value['image']);
  172. }
  173. $this->success('请求成功',$link);
  174. }
  175. /**
  176. * 版本对比
  177. */
  178. public function version_comparison(){
  179. $link = VersionComparison::all();
  180. foreach ($link as &$value){
  181. $value['image'] = explode(',',$value['image']);
  182. }
  183. $this->success('请求成功',$link);
  184. }
  185. /**
  186. * 版本更新列表
  187. */
  188. public function version_updating(){
  189. $data = VersionUpdating::all();
  190. $res = [];
  191. foreach ($data as $k=>$v){
  192. array_push($res,$v->toarray());
  193. }
  194. $list = $this->getTree($res,'id','pid','children');
  195. $this->success('请求成功',$list);
  196. }
  197. /**
  198. * 版本更新内容
  199. * @ApiParams(name='id')
  200. */
  201. public function version_updating_content(){
  202. $data = VersionUpdatingText::all(['classify_id'=>input('id')]);
  203. $this->success('请求成功',$data);
  204. }
  205. /**
  206. * 版本更新分类(3级)
  207. * @ApiParams (name="id")
  208. */
  209. public function version_updating_three(){
  210. $data = VersionUpdating::all(['pid'=>input('id'),'ismenu'=>0]);
  211. $this->success('请求成功',$data);
  212. }
  213. /**
  214. * 论坛
  215. */
  216. public function luntan(){
  217. }
  218. /**
  219. * 成为合作伙伴
  220. */
  221. public function cooperation_configuration(){
  222. $res = CooperationConfiguration::all();
  223. foreach ($res as $k=>&$v){
  224. $v['image'] = explode(',',$v['image']);
  225. }
  226. $this->success('请求成功',$res);
  227. }
  228. /**
  229. * 参观公司
  230. */
  231. public function visit_configuration(){
  232. $res = VisitConfiguration::all();
  233. foreach ($res as $k=>&$v){
  234. $v['image'] = explode(',',$v['image']);
  235. }
  236. $this->success('请求成功',$res);
  237. }
  238. /**
  239. * 常见问题
  240. */
  241. public function faq(){
  242. $res = Faq::all();
  243. $this->success('请求成功',$res);
  244. }
  245. /**
  246. * 常见问题浏览
  247. */
  248. public function browse_faq(){
  249. $res = Faq::all();
  250. foreach ($res as $v){
  251. $v->getQuery()->where('id',$v['id'])->inc('browse')->update();
  252. }
  253. $this->success('请求成功');
  254. }
  255. }