Product.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\bestbao\controller\api\v1;
  9. use app\bestbao\controller\api\Base;
  10. use app\bestbao\model\BestbaoProduct;
  11. class Product extends Base{
  12. /**
  13. * 获取分类
  14. **/
  15. public function index(){
  16. $param['cate_id'] = $this->request->param('cate_id');
  17. $param['keyword'] = $this->request->param('keyword');
  18. $param['page'] = $this->request->param('page/d',1);
  19. $param['sign'] = $this->request->param('sign');
  20. $rel = $this->apiSign($param);
  21. if($rel['code'] != 200){
  22. return enjson($rel['code'],'签名验证失败');
  23. }
  24. $condition['member_miniapp_id'] = $this->miniapp_id;
  25. if($param['cate_id']){
  26. $condition['category_id'] = $param['cate_id'];
  27. }
  28. $rel = BestbaoProduct::where($condition)->withSearch(['title'],['title' => $param['keyword']])->order('sort desc,id desc')->paginate(10)->toArray();
  29. if($rel){
  30. return enjson(200,'成功',$rel['data']);
  31. }else{
  32. return enjson(204);
  33. }
  34. }
  35. /**
  36. * 获取某个产品
  37. */
  38. public function getView(){
  39. $this->isUserAuth();
  40. $data['product_id'] = $this->request->param('product_id/d',0);
  41. $data['product_code'] = $this->request->param('product_code');
  42. $data['sign'] = $this->request->param('sign');
  43. $rel = $this->apiSign($data);
  44. if($rel['code'] != 200){
  45. return enjson($rel['code'],'签名验证失败');
  46. }
  47. $condition['member_miniapp_id'] = $this->miniapp_id;
  48. if(empty($data['product_id']) && empty($data['product_code'])){
  49. return enjson(204);
  50. }
  51. if(!empty($data['product_id'])){
  52. $condition['id'] = $data['product_id'];
  53. }
  54. if(!empty($data['product_code'])){
  55. $condition['code'] = $data['product_code'];
  56. }
  57. $rel = BestbaoProduct::where($condition)->field('id,code,images,note,title')->find();
  58. if($rel){
  59. return enjson(200,'成功',$rel);
  60. }else{
  61. return enjson(204);
  62. }
  63. }
  64. }