// +---------------------------------------------------------------------- namespace modules\channel\wechat_mini\controller\admin; use app\adminapi\controller\AuthController; use modules\channel\wechat_mini\service\LiveGoodsServices; use think\facade\App; /** * 直播间商品 * Class LiveGoods * @package app\controller\admin\store */ class LiveGoodsController extends AuthController { /** * @var LiveGoodsServices */ protected $services; /** * LiveGoods constructor. * @param App $app * @param LiveGoodsServices $services */ public function __construct(App $app, LiveGoodsServices $services) { parent::__construct($app); $this->services = $services; } /** * 直播间商品列表 * @return mixed */ public function list() { $where = $this->request->postMore([ ['kerword', ''], ['status', ''], ['is_show', ''], ['live_id', 0] ]); return app('json')->success($this->services->getList($where)); } /** * 生成直播商品 * @return mixed */ public function create() { [$product_ids] = $this->request->postMore([ ['product_id', []] ], true); return app('json')->success($this->services->create($product_ids)); } /** * 上传直播商品 * @return mixed * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function add() { [$goods_info] = $this->request->postMore([ ['goods_info', []] ], true); $error = false; foreach ($goods_info as $goods) { $this->validate($goods, \modules\channel\wechat_mini\validate\LiveGoodsValidate::class, 'save'); // 正向校验(安全审计 D6):拒绝危险 stream wrapper(phar/zip/data/file 等), // 后缀白名单放行;相对路径与 http/https 均兼容 $image = (string)($goods['image'] ?? ''); $scheme = strtolower((string)parse_url($image, PHP_URL_SCHEME)); if (in_array($scheme, ['phar', 'zip', 'data', 'file', 'ftp', 'php'], true) || !preg_match('/\.(png|jpg|jpeg|gif)$/i', $image)) { $error = true; } } if ($error) return app('json')->fail(40137); $this->services->add($goods_info); return app('json')->success('保存成功'); } /** * 商品详情 * @param $id * @return mixed */ public function detail($id) { if (!$id) return app('json')->fail('参数错误'); $goods = $this->services->get($id, ['*'], ['product']); return app('json')->success($goods ? $goods->toArray() : []); } /** * 同步直播商品 * @return mixed */ public function syncGoods() { $this->services->syncGoodStatus(); return app('json')->success('同步成功'); } /** * 重新提交审核 * @param $id * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function audit($id) { if (!$id) return app('json')->fail('参数错误'); $this->services->audit((int)$id); return app('json')->success('设置成功'); } /** * 撤回审核 * @param $id * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function resetAudit($id) { if (!$id) return app('json')->fail('参数错误'); $this->services->resetAudit((int)$id); return app('json')->success('设置成功'); } /** * 设置状态 * @param int $id * @param $is_show * @return mixed */ public function setShow(int $id, $is_show) { if (!$id) return app('json')->fail('参数错误'); return app('json')->success($this->services->isShow($id, $is_show)); } /** * 删除商品 * @param $id * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function delete($id) { if (!$id) return app('json')->fail('参数错误'); $this->services->delete($id); return app('json')->success('删除成功'); } }