Adwords.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 小程序公共API服务
  7. */
  8. namespace app\popupshop\controller\api\v1;
  9. use app\popupshop\controller\api\Base;
  10. use app\popupshop\model\Adwords as Ads;
  11. use think\facade\Request;
  12. use think\facade\Validate;
  13. use filter\Filter;
  14. class Adwords extends Base{
  15. /**
  16. * 读取微信API
  17. * @param integer 读取ID
  18. * @return json
  19. */
  20. public function index($group = 1){
  21. $lists = Ads::field('title,picture,open_type,link')->where(['group_id'=> $group,'member_miniapp_id' => $this->miniapp_id])->order('sort desc,id desc')->select();
  22. $data = [];
  23. switch ($group) {
  24. case 1:
  25. $style = "?x-oss-process=style/640";
  26. break;
  27. case 2:
  28. $style = "?x-oss-process=style/640";
  29. break;
  30. case 3:
  31. $style = "?x-oss-process=style/80";
  32. break;
  33. default:
  34. $style = "";
  35. break;
  36. }
  37. foreach($lists as $key => $rs){
  38. $data[$key]['title'] = $rs['title'];
  39. $data[$key]['images'] = $rs['picture'].$style;
  40. $data[$key]['link'] = dehtml($rs['link']);
  41. $data[$key]['open_type'] = $rs['open_type'];
  42. }
  43. return json(['code'=>200,'msg'=>'成功','data' => $data]);
  44. }
  45. /**
  46. * 获取内容
  47. * @param [type] $apis
  48. * @param integer $num
  49. * @return void
  50. */
  51. public function all(){
  52. $ids = ids(explode('/',Request::param('apis','0')),true);
  53. $where = [];
  54. $where['member_miniapp_id'] = $this->miniapp_id;
  55. $where['group_id'] = $ids;
  56. $rel = Ads::where($where)->field('title,picture,link,open_type,group_id')->order('sort desc,id desc')->select();
  57. $cate = [];
  58. foreach ($ids as $value) {
  59. $cate[$value] = [];
  60. }
  61. foreach ($rel as $rs) {
  62. $cate[$rs['group_id']][] = $rs;
  63. }
  64. return json(['code'=>200,'msg'=>'成功','data' => $cate]);
  65. }
  66. }