|
|
|
<?php
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Author: 萤火科技 <admin@yiovo.com>
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
declare (strict_types=1);
|
|
|
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
|
|
use app\common\model\store\StoreSettle;
|
|
|
|
use app\api\service\User as UserService;
|
|
|
|
use think\response\Json;
|
|
|
|
use app\api\model\Square as squareModel;
|
|
|
|
use app\api\model\Squarelike as squarelikeModel;
|
|
|
|
use app\common\model\UploadFile;
|
|
|
|
use app\common\model\Channel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 广场动态
|
|
|
|
* Class Store
|
|
|
|
* @package app\store\controller
|
|
|
|
*/
|
|
|
|
class Square extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @notes:新增文章
|
|
|
|
* @return Json
|
|
|
|
* @throws BaseException
|
|
|
|
* @author: wanghousheng
|
|
|
|
*/
|
|
|
|
public function add(): Json
|
|
|
|
{
|
|
|
|
$useInfo = UserService::getCurrentLoginUser(true)->toArray();
|
|
|
|
|
|
|
|
$content = $this->request->post('content');
|
|
|
|
if (!$content) {
|
|
|
|
return $this->renderError('内容不能为空');
|
|
|
|
}
|
|
|
|
$cate = $this->request->post('cate');
|
|
|
|
if (!$cate) {
|
|
|
|
return $this->renderError('分类不能为空');
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = $this->postForm();
|
|
|
|
$data['merchant_id'] = $this->merchantId;
|
|
|
|
$data['user_name'] = $useInfo['user_id'];
|
|
|
|
$data['real_name'] = $useInfo['nick_name'];
|
|
|
|
if ((new squareModel)->add($data)) {
|
|
|
|
return $this->renderSuccess('添加成功');
|
|
|
|
}
|
|
|
|
return $this->renderError('添加失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 列表
|
|
|
|
*/
|
|
|
|
public function list(): Json {
|
|
|
|
$model = new squareModel;
|
|
|
|
$list = $model->getList($this->request->param())->toArray();
|
|
|
|
|
|
|
|
foreach ($list['data'] as $kr => $r) {
|
|
|
|
$res[$kr]['imgs'] = [];
|
|
|
|
if ($r['imgs']) {
|
|
|
|
$img_ids = explode(",", $r['imgs']);
|
|
|
|
$files = UploadFile::getFileList($img_ids);
|
|
|
|
$list['data'][$kr]['imgs'] = $files ?: null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->renderSuccess($list);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dynamicLike(int $id): Json
|
|
|
|
{
|
|
|
|
$useInfo = UserService::getCurrentLoginUser(true)->toArray();
|
|
|
|
|
|
|
|
$model = new squarelikeModel;
|
|
|
|
$detail = squarelikeModel::detail($id, $useInfo['user_name']);
|
|
|
|
$data = $this->postForm();
|
|
|
|
if (empty($detail)) {
|
|
|
|
if ($model->add($data)) {
|
|
|
|
return $this->renderSuccess('操作成功');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$data['squarelike_id'] = $detail['squarelike_id'];
|
|
|
|
if ($detail->delete($data)) {
|
|
|
|
return $this->renderSuccess('操作成功');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|