// +---------------------------------------------------------------------- namespace app\controller\cashier; use app\Request; use app\services\product\branch\StoreBranchProductServices; use app\services\product\category\StoreProductCategoryServices; use app\services\activity\seckill\StoreSeckillServices; use app\services\product\sku\StoreProductAttrServices; use app\services\system\form\SystemFormServices; use app\services\activity\discounts\StoreDiscountsServices; /** * 收银台商品控制器 */ class Product extends AuthController { /** * 获取商品一级分类 * @param StoreProductCategoryServices $services * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getOneCategory(StoreProductCategoryServices $services) { return $this->success($services->getOneCategory()); } /** * 收银台商品列表 * @param Request $request * @param StoreBranchProductServices $services * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getProductList(Request $request, StoreBranchProductServices $services) { $where = $request->getMore([ ['store_name', ''], ['cate_id', 0, '', 'cid'], ['field_key', ''], ['staff_id', ''], ['uid', 0], ['tourist_uid', ''],//虚拟用户uid ['show_type', ''], ['cunqu', 0] ]); $cunqu = $where['cunqu']; unset($where['cunqu']); $store_id = (int)$this->storeId; $where['field_key'] = $where['field_key'] == 'all' ? '' : $where['field_key']; $where['field_key'] = $where['field_key'] == 'id' ? 'product_id' : $where['field_key']; $where['show_type'] = [0, 2]; $staff_id = (int)$where['staff_id']; $tourist_uid = (int)$where['tourist_uid']; $uid = (int)$where['uid']; unset($where['staff_id'], $where['uid'], $where['tourist_uid']); if($cunqu){ if(empty($where['store_name'])) return app('json')->status(0,'请扫描或者输入商品名称/ID/唯一码'); $list = $services->getCashierProductListV2($where, $store_id, $uid, $staff_id, $tourist_uid); if(empty($list['list'])) return app('json')->status(0,'系统未找到商品,请手动添加名称'); return $this->success(['product_name'=>$list['list'][0]['store_name']]); } return $this->success($services->getCashierProductListV2($where, $store_id, $uid, $staff_id, $tourist_uid)); } /** * 获取收银台商品详情 * @param Request $request * @param StoreBranchProductServices $services * @param int $id * @param int $uid * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getProductInfo(Request $request, StoreBranchProductServices $services, $id = 0, $uid = 0) { if (!$id) { return $this->fail('缺少商品id'); } $touristUid = $request->get('tourist_uid'); return $this->success($services->getProductDetail($this->storeId, (int)$id, (int)$uid, (int)$touristUid)); } /** * 获取商品属性 * @param Request $request * @return mixed */ public function getProductAttr(Request $request) { [$id, $cartNum, $uid] = $request->getMore([ ['id', 0], ['type', 0], ['uid', 0] ], true); if (!$id) return app('json')->fail('参数错误'); /** @var StoreSeckillServices $seckillServices */ $seckillServices = app()->make(StoreSeckillServices::class); /** @var StoreProductAttrServices $storeProductAttrServices */ $storeProductAttrServices = app()->make(StoreProductAttrServices::class); $storeInfo = $seckillServices->getOne(['id' => $id]); if (!$storeInfo) { return app('json')->fail('商品不存在'); } $storeInfo = $storeInfo ? $storeInfo->toArray() : []; //系统表单 $storeInfo['custom_form'] = []; if ($storeInfo['system_form_id']) { /** @var SystemFormServices $systemFormServices */ $systemFormServices = app()->make(SystemFormServices::class); $systemForm = $systemFormServices->value(['id' => $storeInfo['system_form_id']], 'value'); if ($systemForm) { $storeInfo['custom_form'] = is_string($systemForm) ? json_decode($systemForm, true) : $systemForm; } } //有自定义表单或预售或虚拟不展示加入购物车按钮 $storeInfo['cart_button'] = $storeInfo['custom_form'] || $storeInfo['is_presale_product'] || $storeInfo['product_type'] > 0 ? 0 : 1; $data['storeInfo'] = $storeInfo; $data['storeInfo']['store_name'] = $data['storeInfo']['title'] ?? ''; [$data['productAttr'], $data['productValue']] = $storeProductAttrServices->getProductAttrDetail((int)$id, (int)$uid, (int)$cartNum, 1, (int)$storeInfo['product_id']); return app('json')->successful($data); } public function getList(Request $request){ [$vip_type] = $request->postMore([ ['vip_type', 0] ], true); if (!$vip_type) return app('json')->fail('参数错误'); /** @var StoreDiscountsServices $systemFormServices */ $StoreDiscountsServices = app()->make(StoreDiscountsServices::class); $list = $StoreDiscountsServices->getList(['vip_type'=>$vip_type]); foreach($list['list'] as $key => &$v){ $v['attr_value'] = $StoreDiscountsServices->getInfo($v['id']); } return $list ? app('json')->successful($list) : app('json')->fail('无商品礼包'); } }