Goods.php 2.1 KB

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