Active.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\api\controller\bargain;
  3. use app\api\controller\Controller;
  4. use app\api\model\Goods as GoodsModel;
  5. use app\api\model\bargain\Active as ActiveModel;
  6. use app\api\model\bargain\Setting as SettingModel;
  7. use app\common\service\qrcode\bargain\Goods as GoodsPoster;
  8. /**
  9. * 砍价活动管理
  10. * Class Active
  11. * @package app\api\controller\bargain
  12. */
  13. class Active extends Controller
  14. {
  15. /**
  16. * 砍价活动会场列表
  17. * @return array
  18. * @throws \think\Exception
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. * @throws \think\exception\DbException
  22. */
  23. public function lists()
  24. {
  25. // 获取砍价活动会场列表
  26. $model = new ActiveModel;
  27. $activeList = $model->getHallList();
  28. return $this->renderSuccess(compact('activeList'));
  29. }
  30. /**
  31. * 砍价活动详情
  32. * @param $active_id
  33. * @return array
  34. * @throws \app\common\exception\BaseException
  35. * @throws \think\exception\DbException
  36. */
  37. public function detail($active_id)
  38. {
  39. // 获取砍价活动详情
  40. $model = new ActiveModel;
  41. $active = $model->getDetail($active_id);
  42. if ($active === false) {
  43. return $this->renderError($model->getError());
  44. }
  45. // 标记当前用户是否正在参与
  46. $task_id = $model->getWhetherPartake($active_id, $this->getUser(false));
  47. $is_partake = $task_id > 0;
  48. // 获取商品详情
  49. $goods = GoodsModel::detail($active['goods_id']);
  50. // 砍价规则
  51. $setting = SettingModel::getBasic();
  52. return $this->renderSuccess(compact('active', 'goods', 'setting', 'is_partake', 'task_id'));
  53. }
  54. /**
  55. * 生成商品海报
  56. * @param $active_id
  57. * @return array
  58. * @throws \app\common\exception\BaseException
  59. * @throws \think\exception\DbException
  60. * @throws \Exception
  61. */
  62. public function poster($active_id)
  63. {
  64. // 获取砍价活动详情
  65. $model = new ActiveModel;
  66. $active = $model->getDetail($active_id);
  67. if ($active === false) {
  68. return $this->renderError($model->getError());
  69. }
  70. // 获取商品详情
  71. $goods = GoodsModel::detail($active['goods_id']);
  72. // 生成商品海报图
  73. $Qrcode = new GoodsPoster($active, $goods, $this->getUser(false));
  74. return $this->renderSuccess([
  75. 'qrcode' => $Qrcode->getImage(),
  76. ]);
  77. }
  78. }