Friendship.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <?php
  2. /**
  3. *
  4. * User: anyluck
  5. * Date: 2020/5/28
  6. * Time: 12:13
  7. */
  8. namespace app\admin\controller;
  9. use app\common\controller\Aliyunoss;
  10. use think\facade\Db;
  11. use app\common\controller\Backend;
  12. use think\facade\Request;
  13. use think\facade\View;
  14. class Friendship extends Backend
  15. {
  16. // 上传图片
  17. public function upimage()
  18. {
  19. // $file = request()->file('image');
  20. $file = $_FILES["file"];
  21. // $file = $_FILES;
  22. // dump($file);
  23. // die();
  24. if (!$file) json_result(400, '请上传图片', '');
  25. $Aliyun = new Aliyunoss();
  26. $aa = $Aliyun->uploadFile($file);
  27. json_result(200, '发送成功', $aa);
  28. }
  29. // 主页
  30. public function index()
  31. {
  32. // 查询友情链接数量
  33. $links=Db::name("links")->count();
  34. $banner=Db::name("banner")->count();
  35. $user_count=Db::name("admin")->count();
  36. // 查询浏览量
  37. $liull=Db::name("browse")->where(["type"=>0])->count();
  38. $liull_zt=Db::name("browse")->where(["type"=>0])->whereDay("add_time")->count();
  39. $user=0;// 独立用户
  40. $zhixing=0;// 最终咨询
  41. $view = [
  42. 'info' => [
  43. "liull"=>$liull,
  44. "liull_zt"=>$liull_zt/($liull-$liull_zt)*100,
  45. "user"=>$user,
  46. "zhixing"=>$zhixing,
  47. "links"=>$links,
  48. "banner"=>$banner,
  49. "admin"=>$user_count,
  50. ],
  51. 'title' => lang('add'),
  52. // 'userLevel'=>$userLevel,
  53. ];
  54. View::assign($view);
  55. return View::fetch();
  56. }
  57. // 友情链接列表
  58. public function links()
  59. {
  60. if (Request::isPost()) {
  61. $page = input("page") ?: 1;
  62. $limit = input("limit") ?: 10;
  63. $name = input("name");
  64. $where = [];
  65. if ($name) {
  66. $where["name"] = ["like", "%" . $name . "%"];
  67. }
  68. $list = Db::name("links")->where($where)->order("pai desc")->paginate(["list_rows" => $limit, "page" => $page])->toArray();
  69. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']];
  70. } else {
  71. return View::fetch();
  72. }
  73. }
  74. //添加或修改友情链接
  75. public function add_links()
  76. {
  77. if (Request::isPost()) {
  78. $id = input("id");
  79. $name = input("name");
  80. $url = input("url");
  81. $add["name"] = $name;
  82. $add["url"] = $url;
  83. if ($id) {
  84. Db::name("links")->where(["id" => $id])->update($add);
  85. } else {
  86. Db::name("links")->insert($add);
  87. }
  88. $this->success(lang('add success'), url('links'));
  89. return;
  90. // json_result(200,"操作成功");
  91. }
  92. $id = input("id");
  93. $info = "";
  94. if ($id) {
  95. $info = Db::name("links")->where(["id" => $id])->find();
  96. }
  97. $view = [
  98. 'info' => $info,
  99. 'title' => lang('add'),
  100. // 'userLevel'=>$userLevel,
  101. ];
  102. View::assign($view);
  103. return View::fetch();
  104. }
  105. // 修改状态
  106. public function update_links()
  107. {
  108. $id = input("id");
  109. $status = input("status") ?: 0;
  110. Db::name("links")->where(["id" => $id])->update(["status" => $status]);
  111. json_result(1, "设置成功");
  112. }
  113. // 修改排序
  114. public function update_pai_links()
  115. {
  116. $id = input("id");
  117. $value = input("value");
  118. $field = input("field");
  119. Db::name("links")->where(["id" => $id])->update([$field => $value]);
  120. json_result(1, "设置成功");
  121. }
  122. //删除友情链接
  123. public function del_links()
  124. {
  125. $id = input("id");
  126. Db::name("links")->where(["id" => $id])->delete();
  127. json_result(1, "删除成功");
  128. }
  129. // 导航管理列表
  130. public function dh_list()
  131. {
  132. if (Request::isPost()) {
  133. $page = input("page") ?: 1;
  134. $limit = input("limit") ?: 10;
  135. $name = input("name");
  136. $type = input("type");
  137. $where = [];
  138. if ($name) {
  139. $where["name"] = ["like", "%" . $name . "%"];
  140. }
  141. if ($type) {
  142. $where["type"] = $type;
  143. }
  144. $list = Db::name("dh")->where($where)->order("pai desc")->paginate(["list_rows" => $limit, "page" => $page])->each(function ($item){
  145. if ($item["type"]==1){
  146. $item["type"]="商城系统";
  147. }elseif ($item["type"]==2){
  148. $item["type"]="解决方案";
  149. }else{
  150. $item["type"]="";
  151. }
  152. return $item;
  153. })->toArray();
  154. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']];
  155. } else {
  156. return View::fetch();
  157. }
  158. }
  159. // 修改数据
  160. public function update_pai_dh()
  161. {
  162. $id = input("id");
  163. $value = input("value");
  164. $field = input("field");
  165. Db::name("dh")->where(["id" => $id])->update([$field => $value]);
  166. json_result(1, "设置成功");
  167. }
  168. // 修改导航栏状态
  169. public function update_dh_status()
  170. {
  171. $id = input("id");
  172. $status = input("status") ?: 0;
  173. Db::name("dh")->where(["id" => $id])->update(["status" => $status]);
  174. json_result(1, "设置成功");
  175. }
  176. // 删除导航
  177. public function del_dh()
  178. {
  179. $id = input("id");
  180. Db::name("dh")->where(["id" => $id])->delete();
  181. json_result(1, "删除成功");
  182. }
  183. // 添加导航
  184. public function add_dh()
  185. {
  186. if (Request::isPost()) {
  187. $id = input("id");
  188. $name = input("name");
  189. $type = input("type");
  190. $status = input("status");
  191. $add["name"] = $name;
  192. $add["type"] = $type;
  193. $add["status"] = $status;
  194. if ($id) {
  195. Db::name("dh")->where(["id" => $id])->update($add);
  196. } else {
  197. Db::name("dh")->insert($add);
  198. }
  199. $this->success(lang('add success'), url('dh_list'));
  200. return;
  201. // json_result(200,"操作成功");
  202. }
  203. $id = input("id");
  204. $info = "";
  205. if ($id) {
  206. $info = Db::name("dh")->where(["id" => $id])->find();
  207. }
  208. $view = [
  209. 'info' => $info,
  210. 'title' => lang('add'),
  211. // 'userLevel'=>$userLevel,
  212. ];
  213. View::assign($view);
  214. return View::fetch();
  215. }
  216. // 轮播图列表
  217. public function banner()
  218. {
  219. if (Request::isPost()) {
  220. $page = input("page") ?: 1;
  221. $limit = input("limit") ?: 10;
  222. $name = input("name");
  223. $type = input("type");
  224. $where = [];
  225. if ($name) {
  226. $where["name"] = ["like", "%" . $name . "%"];
  227. }
  228. if ($type) {
  229. $where["type"] = $type;
  230. }
  231. $list = Db::name("banner")->where($where)->order("pai desc")->paginate(["list_rows" => $limit, "page" => $page])->each(function ($item){
  232. return $item;
  233. })->toArray();
  234. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']];
  235. } else {
  236. return View::fetch();
  237. }
  238. }
  239. // 修改数据轮播图
  240. public function update_pai_banner()
  241. {
  242. $id = input("id");
  243. $value = input("value");
  244. $field = input("field");
  245. Db::name("banner")->where(["id" => $id])->update([$field => $value]);
  246. json_result(1, "设置成功");
  247. }
  248. // 修改轮播图栏状态
  249. public function update_banner_status()
  250. {
  251. $id = input("id");
  252. $status = input("status") ?: 0;
  253. Db::name("banner")->where(["id" => $id])->update(["status" => $status]);
  254. json_result(1, "设置成功");
  255. }
  256. //添加或修改轮播图
  257. public function add_banner()
  258. {
  259. if (Request::isPost()) {
  260. $id = input("id");
  261. $name = input("name");
  262. $image = input("image");
  263. $url = input("url");
  264. $status = input("status");
  265. $add["name"] = $name;
  266. $add["image"] =$image;
  267. $add["url"] =$url;
  268. $add["status"] = $status;
  269. if ($id) {
  270. Db::name("banner")->where(["id" => $id])->update($add);
  271. } else {
  272. Db::name("banner")->insert($add);
  273. }
  274. $this->success(lang('add success'), url('banner'));
  275. return;
  276. // json_result(200,"操作成功");
  277. }
  278. $id = input("id");
  279. $info = "";
  280. if ($id) {
  281. $info = Db::name("banner")->where(["id" => $id])->find();
  282. }
  283. $view = [
  284. 'info' => $info,
  285. 'title' => lang('add'),
  286. // 'userLevel'=>$userLevel,
  287. ];
  288. View::assign($view);
  289. return View::fetch();
  290. }
  291. // 删除轮播图
  292. public function del_banner()
  293. {
  294. $id = input("id");
  295. Db::name("banner")->where(["id" => $id])->delete();
  296. json_result(1, "删除成功");
  297. }
  298. // 统计数据
  299. public function statistics()
  300. {
  301. if (Request::isPost()) {
  302. $type=input("type")?:0;//0 日指标 1 浏览量 2 独立用户 3 最终咨询
  303. $day=input("day");// 选中天数
  304. $start_time=input("start_time");// 开始时间
  305. $end_time=input("end_time");// 结束时间
  306. $where=[];
  307. $where[]=["type","=",$type];
  308. if ($type==0){// 日指标
  309. $list=Db::name("browse")->where($where)->whereDay('add_time')->field("add_time,FROM_UNIXTIME(add_time,'%H') as posttime,sum(num) as zong")->group('posttime')->select();
  310. // 处理数据
  311. $data=[];
  312. foreach ($list as $k=>$v){
  313. $data["day"][$k]=$v["posttime"]."点";
  314. $data["data"][$k]=$v["zong"];
  315. }
  316. json_result(200,"日指标",$data);
  317. }elseif ($type==1){// 浏览量
  318. if ($day){
  319. $start_time=date("Y-m-d",time()).' 23:59:59';
  320. $end_time=date('Y-m-d',strtotime('-'.($day).' days')).' 23:59:59';;
  321. }
  322. $start_time=strtotime($start_time);
  323. $end_time=strtotime($end_time);
  324. $list=Db::name("browse")->where(["type"=>0])->where("add_time",">",$end_time)->where("add_time","<",$start_time)->where(["type"=>0])->field("add_time,FROM_UNIXTIME(add_time,'%Y-%m-%d') as posttime,sum(num) as zong")->group('posttime')->select();
  325. // json_result($start_time,$end_time,$list);
  326. $data=[];
  327. foreach ($list as $k=>$v){
  328. $data["day"][$k]=date("m.d",strtotime($v["posttime"]));
  329. $data["data"][$k]=$v["zong"];
  330. }
  331. json_result(200,"浏览量",$data);
  332. }
  333. $data["data"]=[];
  334. $data["day"]=[];
  335. json_result(200,"浏览量22",$data);
  336. }
  337. // 查询浏览量
  338. $liull=Db::name("browse")->where(["type"=>0])->count();
  339. $liull_zt=Db::name("browse")->where(["type"=>0])->whereDay("add_time")->count();
  340. $user=0;// 独立用户
  341. $zhixing=0;// 最终咨询
  342. $view = [
  343. 'info' => [
  344. "liull"=>$liull,
  345. "liull_zt"=>$liull_zt/($liull-$liull_zt)*100,
  346. "user"=>$user,
  347. "zhixing"=>$zhixing,
  348. ],
  349. 'title' => lang('add'),
  350. // 'userLevel'=>$userLevel,
  351. ];
  352. View::assign($view);
  353. return View::fetch();
  354. }
  355. }