PublicApi.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/12/12
  6. */
  7. namespace app\wap\controller;
  8. use app\wap\model\store\StoreCombination;
  9. use app\admin\model\system\SystemGroup;
  10. use app\admin\model\system\SystemGroupData;
  11. use app\wap\model\store\StoreCategory;
  12. use app\wap\model\store\StoreCouponIssue;
  13. use app\wap\model\store\StoreProduct;
  14. use app\wap\model\wap\ArticleCategory;
  15. use service\FileService;
  16. use service\JsonService;
  17. use service\UtilService;
  18. use think\Cache;
  19. class PublicApi
  20. {
  21. public function get_cid_article($cid = 0,$first = 0,$limit = 8)
  22. {
  23. $list = ArticleCategory::cidByArticleList($cid,$first,$limit,'id,title,image_input,visit,add_time,synopsis,url')?:[];
  24. foreach ($list as &$article){
  25. $article['add_time'] = date('Y-m-d H:i',$article['add_time']);
  26. }
  27. return JsonService::successful('ok',$list);
  28. }
  29. public function get_video_list($key = '', $first = 0,$limit = 8)
  30. {
  31. $gid = SystemGroup::where('config_name',$key)->value('id');
  32. if(!$gid){
  33. $list = [];
  34. }else{
  35. $video = SystemGroupData::where('gid',$gid)->where('status',1)->order('sort DESC,add_time DESC')->limit($first,$limit)->select();
  36. $list = SystemGroupData::tidyList($video);
  37. }
  38. return JsonService::successful('ok',$list);
  39. }
  40. public function get_issue_coupon_list($limit = 2)
  41. {
  42. $list = StoreCouponIssue::validWhere('A')->join('__STORE_COUPON__ B','A.cid = B.id')
  43. ->field('A.*,B.coupon_price,B.use_min_price')->order('id DESC')->limit($limit)->select()->toArray();
  44. return JsonService::successful($list);
  45. }
  46. public function get_category_product_list($limit = 4)
  47. {
  48. $cateInfo = StoreCategory::where('is_show',1)->where('pid',0)->field('id,cate_name,pic')
  49. ->order('sort DESC')->select()->toArray();
  50. $result = [];
  51. $StoreProductModel = new StoreProduct;
  52. foreach ($cateInfo as $k=>$cate){
  53. $cate['product'] = $StoreProductModel::alias('A')->where('A.is_del',0)->where('A.is_show',1)
  54. ->where('A.mer_id',0)->where('B.pid',$cate['id'])
  55. ->join('__STORE_CATEGORY__ B','B.id = A.cate_id')
  56. ->order('A.is_benefit DESC,A.sort DESC,A.add_time DESC')
  57. ->limit($limit)->field('A.id,A.image,A.store_name,A.sales,A.price,A.unit_name')->select()->toArray();
  58. if(count($cate['product']))
  59. $result[] = $cate;
  60. }
  61. return JsonService::successful($result);
  62. }
  63. /** 首页获取推荐产品
  64. * @param int $first
  65. * @param int $limit
  66. */
  67. public function get_product_list($first = 0,$limit = 8)
  68. {
  69. $StoreProductmodel = StoreProduct::validWhere();
  70. if(input('type')=='is_best')
  71. $StoreProductmodel = $StoreProductmodel->where('is_best',1);
  72. if(input('type')=='is_hot')
  73. $StoreProductmodel = $StoreProductmodel->where('is_hot',1);
  74. if(input('type')=='is_benefit')
  75. $StoreProductmodel = $StoreProductmodel->where('is_benefit',1);
  76. if(input('type')=='is_new')
  77. $StoreProductmodel = $StoreProductmodel->where('is_new',1);
  78. if(input('type')=='is_postage')
  79. $StoreProductmodel = $StoreProductmodel->where('is_postage',1);
  80. $list = $StoreProductmodel->where('mer_id',0)->order('is_best DESC,sort DESC,add_time DESC')
  81. ->limit($first,$limit)->field('id,image,store_name,sales,price,unit_name')->select()->toArray();
  82. return JsonService::successful($list);
  83. }
  84. public function get_best_product_list($first = 0,$limit = 8)
  85. {
  86. $list = StoreProduct::validWhere()->where('mer_id',0)->order('is_best DESC,sort DESC,add_time DESC')
  87. ->limit($first,$limit)->field('id,image,store_name,sales,price,unit_name')->select()->toArray();
  88. return JsonService::successful($list);
  89. }
  90. public function wechat_media_id_by_image($mediaIds = '')
  91. {
  92. if(!$mediaIds) return JsonService::fail('参数错误');
  93. $mediaIds = explode(',',$mediaIds);
  94. $temporary = \app\core\util\WechatService::materialTemporaryService();
  95. $pathList = [];
  96. $dir='public'.DS.'uploads'.DS.'wechat'.DS.'media';
  97. foreach ($mediaIds as $mediaId){
  98. if(!$mediaId) continue;
  99. try{
  100. $content = $temporary->getStream($mediaId);
  101. }catch (\Exception $e){
  102. continue;
  103. }
  104. $name = substr(md5($mediaId),12,20).'.jpg';
  105. $path = '.'.DS.$dir.DS.$name;
  106. $file=new FileService();
  107. $res=$file->create_dir($dir);
  108. if(!$res) return JsonService::fail('生成文件保存目录失败!请检查权限!');
  109. $res = file_put_contents($path,$content);
  110. if($res) $pathList[] = UtilService::pathToUrl($path);
  111. }
  112. return JsonService::successful($pathList);
  113. }
  114. public function get_pink_host($limit = 0){
  115. $list = StoreCombination::getCombinationHost($limit);
  116. if($list) return JsonService::successful($list);
  117. else return JsonService::successful([]);
  118. }
  119. }