StoreProduct.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\openapi\store;
  12. use app\common\repositories\openapi\OpenAuthRepository;
  13. use app\common\repositories\system\merchant\MerchantRepository;
  14. use crmeb\exceptions\AuthException;
  15. use think\App;
  16. use crmeb\basic\BaseController;
  17. use app\common\repositories\store\product\ProductRepository as repository;
  18. class StoreProduct extends BaseController
  19. {
  20. /**
  21. * @var repository
  22. */
  23. protected $repository;
  24. /**
  25. * StoreProduct constructor.
  26. * @param App $app
  27. * @param repository $repository
  28. */
  29. public function __construct(App $app, repository $repository)
  30. {
  31. parent::__construct($app);
  32. $this->repository = $repository;
  33. $this->merId = $this->request->openMerId();
  34. if (!in_array(OpenAuthRepository::AUTH_TYPE_PRODUCT,$this->request->openRoule())) throw new AuthException('无此权限');
  35. }
  36. /**
  37. * 商品列表
  38. * @Author:Qinii
  39. * @Date: 2020/5/18
  40. * @return mixed
  41. */
  42. public function lst()
  43. {
  44. /**
  45. * type 商品状态 1 出售中 2 仓库中 3 已售罄 4 警戒库存 5 回收站 6 待审核 7 审核未通过
  46. * temp_id 运费模板ID
  47. * cate_id 平台商品分类ID
  48. * mer_cate_id 商户商品分类
  49. * product_id 商品ID
  50. * status 审核状态 0 待审核 1 审核通过 -1 审核未通过/强制下架
  51. * us_status 上架状态 1 上架 0 下架 -1 平台关闭/未审核通过
  52. * is_ficti 是否未虚拟商品 0 实体 1 虚拟 2 卡密
  53. * svip_price_type 付费会员价类型 0不参加,1默认比例,2自定义
  54. */
  55. [$page, $limit] = $this->getPage();
  56. $type = $this->request->param('type',1);
  57. $where = $this->request->params(['temp_id','cate_id','keyword','mer_cate_id','is_gift_bag','status','us_status','product_id','mer_labels',['order','sort'],'is_ficti','svip_price_type','filters_type','is_action']);
  58. $where = array_merge($where,$this->repository->switchType($type,$this->merId,0));
  59. return app('json')->success($this->repository->getList($this->merId,$where, $page, $limit));
  60. }
  61. /**
  62. * 商品详情
  63. * @Author:Qinii
  64. * @Date: 2020/5/18
  65. * @param $id
  66. * @return mixed
  67. */
  68. public function detail($id)
  69. {
  70. if(!$this->repository->merExists($this->merId,$id))
  71. return app('json')->fail('数据不存在');
  72. return app('json')->success($this->repository->getAdminOneProduct($id,null));
  73. }
  74. /**
  75. * 添加商品
  76. * @return \think\response\Json
  77. * @author Qinii
  78. * @day 2023/8/14
  79. * @attr: 规格参数[];
  80. * @attrValue: SkU数据[];
  81. * @brand_id?: number 品牌的ID;
  82. * @cate_id: number 平台商品分类,平台的商品分类ID,单选 ;
  83. * @content: string 详情;
  84. * @delivery_free: number 是否包邮,0.否,1.是;
  85. * @delivery_way: string[] 商品支持的配送类型,1.仅到店自提2快递计价配送;
  86. * @extension_type?: string 佣金比例 0.系统,1.自定义,佣金比例 :0.系统,即根据商户统一设置的比例计算; 1.自定义,手动在每个sku价格后面填写佣金金额;
  87. * @image: string 封面图,列表展示图;
  88. * @keyword: string 商品关键字,在分享海报或者微信分享好友等,会使用到;
  89. * @mer_cate_id?: string[] 商户商品分类,商户商品分类ID,多选;
  90. * @once_max_count?: number 订单单次购买数量最大限制,例如 5,单次购买不得超过5件/ 或者此商品每个商户只能购买5件,根据 pay_limit 类型决定;
  91. * @once_min_count?: number 单次购买最低限购,例如 5,则是5件起购;
  92. * @pay_limit?: number 是否限购,购买总数限制 0:不限购,1单次限购 2 长期限购;
  93. * @refund_switch?: number 商品是否支持退款,1.支持 0.不支持;
  94. * @slider_image: string[] 轮播图,详情页展示;
  95. * @spec_type: number 规格类型,0单规格 ,1 多规格;
  96. * @store_info: string 商品简介;
  97. * @store_name: string 商品名称;
  98. * @svip_price_type?: number 会员价类型,0不参加,1默认比例,2自定义;
  99. * @unit_name: string 单位,计量单位,例如:个、kg等;
  100. * @video_link?: string 视频链接地址;
  101. * @attr.value: string 规格名,例如尺码;
  102. * @attr.detail: string[] 规格值,["S (适合36-37)", "M (适合38-39)", "L (适合40-41)"];
  103. * @attrValue.cost: number 成本价;
  104. * @attrValue.detail: { [key: string]: any } 当前SKU信息,当前sku组合的信息,例如:"detail": {"颜色": "粉红色","尺码": "S (适合36-37)"},则表示当前的规格是颜色为粉红色,尺码为S的组合;
  105. * @attrValue.extension_one?: number 一级佣金,如果 extension_type 值为1 ,此项必填,但金额不得超过单价,即:price参数;
  106. * @attrValue.extension_two?: number 二级佣金,如果 extension_type 值为1 ,此项必填,但金额不得超过单价,即:price参数;
  107. * @attrValue.image: string sku封面图,选中当前规格会在移动端详情中显示的图片;
  108. * @attrValue.ot_price: number 原价;
  109. * @attrValue.price: number 售价;
  110. * @attrValue.stock: number 库存;
  111. * @attrValue.svip_price: string会员价,如果 svip_price_type 值为 1 此项必填;当svip_price_type值为1此项值为0时;即:付费会员免费获取;
  112. * @attrValue.volume: number 体积;
  113. * @attrValue.weight: number 重量;
  114. */
  115. public function create()
  116. {
  117. $params = $this->request->params($this->repository::CREATE_PARAMS);
  118. $data = $this->repository->checkParams($params,$this->merId);
  119. $data['mer_id'] = $this->merId;
  120. $data['is_gift_bag'] = 0;
  121. $merchant = app()->make(MerchantRepository::class)->get($this->merId);
  122. $data['status'] = $merchant->is_audit ? 0 : 1;
  123. $data['mer_status'] = (!$merchant->mer_state || !$merchant->status) ? 0 : 1;
  124. $data['rate'] = 3;
  125. $this->repository->create($data,0);
  126. return app('json')->success('添加成功');
  127. }
  128. }