mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-29 05:50:50 +00:00
173 lines
4.9 KiB
PHP
173 lines
4.9 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||
// +----------------------------------------------------------------------
|
||
// | Author: CRMEB Team <admin@crmeb.com>
|
||
// +----------------------------------------------------------------------
|
||
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');
|
||
if (!preg_match('/.*(\.png|\.jpg|\.jpeg|\.gif)$/', $goods['image']) && strpos(strtolower($goods['image']), "phar://") !== false) {
|
||
$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('删除成功');
|
||
}
|
||
|
||
}
|