Goods.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\api\controller\sharing;
  10. use app\api\controller\Controller;
  11. use app\api\model\sharing\Goods as GoodsModel;
  12. use app\common\service\qrcode\Goods as GoodsPoster;
  13. use app\api\model\sharing\Active as ActiveModel;
  14. /**
  15. * 商品控制器
  16. * Class Goods
  17. * @package app\api\controller
  18. */
  19. class Goods extends Controller
  20. {
  21. /**
  22. * 商品列表
  23. * @return array
  24. * @throws \app\common\exception\BaseException
  25. * @throws \think\exception\DbException
  26. */
  27. public function lists()
  28. {
  29. // 整理请求的参数
  30. $param = array_merge($this->request->param(), [
  31. 'status' => 10
  32. ]);
  33. // 获取列表数据
  34. $model = new GoodsModel;
  35. $list = $model->getList($param, $this->getUser(false));
  36. return $this->renderSuccess(compact('list'));
  37. }
  38. /**
  39. * 获取商品详情
  40. * @param $goods_id
  41. * @return array
  42. * @throws \app\common\exception\BaseException
  43. * @throws \think\exception\DbException
  44. */
  45. public function detail($goods_id)
  46. {
  47. // 商品详情
  48. $model = new GoodsModel;
  49. $goods = $model->getDetails($goods_id, $this->getUser(false));
  50. if ($goods === false) {
  51. return $this->renderError($model->getError() ?: '商品信息不存在');
  52. }
  53. // 多规格商品sku信息, todo: 已废弃 v1.1.25
  54. $specData = $goods['spec_type'] == 20 ? $model->getManySpecData($goods['spec_rel'], $goods['sku']) : null;
  55. // 当前进行中的拼单
  56. $activeList = ActiveModel::getActivityListByGoods($goods_id, 2);
  57. return $this->renderSuccess([
  58. // 商品详情
  59. 'detail' => $goods,
  60. // 当前进行中的拼单
  61. 'activeList' => $activeList,
  62. // 多规格商品sku信息
  63. 'specData' => $specData,
  64. ]);
  65. }
  66. /**
  67. * 生成商品海报
  68. * @param $goods_id
  69. * @return array
  70. * @throws \app\common\exception\BaseException
  71. * @throws \think\exception\DbException
  72. * @throws \Exception
  73. */
  74. public function poster($goods_id)
  75. {
  76. // 商品详情
  77. $detail = GoodsModel::detail($goods_id);
  78. // 生成推广二维码
  79. $Qrcode = new GoodsPoster($detail, $this->getUser(false), 20);
  80. return $this->renderSuccess([
  81. 'qrcode' => $Qrcode->getImage(),
  82. ]);
  83. }
  84. }