1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace app\api\controller;
- use app\api\model\Goods as GoodsModel;
- use app\api\model\Cart as CartModel;
- use app\common\service\qrcode\Goods as GoodsPoster;
- /**
- * 商品控制器
- * Class Goods
- * @package app\api\controller
- */
- class Goods extends Controller
- {
- /**
- * 商品列表
- * @return array
- * @throws \app\common\exception\BaseException
- * @throws \think\exception\DbException
- */
- public function lists()
- {
- // 整理请求的参数
- $param = array_merge($this->request->param(), [
- 'status' => 10
- ]);
- // 获取列表数据
- $model = new GoodsModel;
- $list = $model->getList($param, $this->getUser(false));
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 获取商品详情
- * @param $goods_id
- * @return array
- * @throws \app\common\exception\BaseException
- * @throws \think\exception\DbException
- */
- public function detail($goods_id)
- {
- // 用户信息
- $user = $this->getUser(false);
- // 商品详情
- $model = new GoodsModel;
- $goods = $model->getDetails($goods_id, $this->getUser(false));
- if ($goods === false) {
- return $this->renderError($model->getError() ?: '商品信息不存在');
- }
- return $this->renderSuccess([
- // 商品详情
- 'detail' => $goods,
- // 购物车商品总数量
- 'cart_total_num' => $user ? (new CartModel($user))->getTotalNum() : 0,
- ]);
- }
- /**
- * 生成商品海报
- * @param $goods_id
- * @return array
- * @throws \app\common\exception\BaseException
- * @throws \think\exception\DbException
- * @throws \Exception
- */
- public function poster($goods_id)
- {
- // 商品详情
- $detail = GoodsModel::detail($goods_id);
- $Qrcode = new GoodsPoster($detail, $this->getUser(false));
- return $this->renderSuccess([
- 'qrcode' => $Qrcode->getImage(),
- ]);
- }
- }
|