Active.php 2.7 KB

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