Goods.php 2.4 KB

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