Goods.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\api\controller\sharp;
  3. use app\api\controller\Controller;
  4. use app\api\service\sharp\Active as ActiveService;
  5. use app\common\service\qrcode\sharp\Goods as GoodsPoster;
  6. /**
  7. * 整点秒杀-商品管理
  8. * Class Goods
  9. * @package app\api\controller\sharp
  10. */
  11. class Goods extends Controller
  12. {
  13. /**
  14. * 秒杀活动商品列表
  15. * @param $active_time_id
  16. * @return array
  17. */
  18. public function lists($active_time_id)
  19. {
  20. // 获取秒杀活动会场首页数据
  21. $service = new ActiveService;
  22. $list = $service->getGoodsListByActiveTimeId($active_time_id);
  23. return $this->renderSuccess(compact('list'));
  24. }
  25. /**
  26. * 获取活动商品详情
  27. * @param $active_time_id
  28. * @param $sharp_goods_id
  29. * @return array
  30. * @throws \think\exception\DbException
  31. */
  32. public function detail($active_time_id, $sharp_goods_id)
  33. {
  34. // 获取秒杀活动商品详情
  35. $service = new ActiveService;
  36. $data = $service->getActiveGoodsDetail($active_time_id, $sharp_goods_id);
  37. if ($data === false) {
  38. return $this->renderError($service->getError());
  39. }
  40. return $this->renderSuccess($data);
  41. }
  42. /**
  43. * 生成商品海报
  44. * @param $active_time_id
  45. * @param $sharp_goods_id
  46. * @return array
  47. * @throws \app\common\exception\BaseException
  48. * @throws \think\exception\DbException
  49. */
  50. public function poster($active_time_id, $sharp_goods_id)
  51. {
  52. // 获取秒杀活动商品详情
  53. $service = new ActiveService;
  54. $data = $service->getActiveGoodsDetail($active_time_id, $sharp_goods_id);
  55. if ($data === false) {
  56. return $this->renderError($service->getError());
  57. }
  58. // 生成商品海报图
  59. $Qrcode = new GoodsPoster($data['active'], $data['goods'], $this->getUser(false));
  60. return $this->renderSuccess([
  61. 'qrcode' => $Qrcode->getImage(),
  62. ]);
  63. }
  64. }