You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/api/controller/Square.php

170 lines
5.7 KiB

<?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;
7 months ago
use app\api\model\User as UserModel;
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;
6 months ago
use app\api\model\Goods as GoodsModel;
/**
* 广场动态
* Class Store
* @package app\store\controller
*/
class Square extends Controller
{
/**
* @notes:新增文章
* @return Json
* @throws BaseException
* @author: wanghousheng
*/
public function add(): Json
{
7 months ago
$useInfo = UserService::getCurrentLoginUser(true)->toArray();
$content = $this->request->post('content');
if (!$content) {
return $this->renderError('内容不能为空');
}
7 months ago
$cate = $this->request->post('cate');
if (!$cate) {
return $this->renderError('分类不能为空');
}
7 months ago
$data = $this->postData();
$data['merchant_id'] = $this->merchantId;
7 months ago
$data['user_name'] = $useInfo['user_id'];
$data['real_name'] = $useInfo['nick_name'];
if ((new squareModel)->add($data)) {
return $this->renderSuccess('添加成功');
}
return $this->renderError('添加失败');
}
6 months ago
/**
* 删除门店
* @param int $shopId
* @return Json
*/
public function delete(int $squareId): Json
{
// 门店详情
$model = squareModel::detail($squareId, $this->storeId);
if (!$model->setDelete()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
/**
* 列表
*/
public function list(): Json {
7 months ago
$pageSize = $this->request->param('pageSize');
$pageSize = empty($pageSize) ? 15 : $pageSize;
7 months ago
$useInfo = UserService::getCurrentLoginUser(true)->toArray();
$model = new squareModel;
7 months ago
$list = $model->getList($this->request->param(), intval($pageSize))->toArray();
foreach ($list['data'] as $kr => $r) {
7 months ago
$model = new UserModel();
7 months ago
$user = $model->where(['user_id' => $r['user_name']])->find()->toArray();
7 months ago
$modelLike = new squarelikeModel();
7 months ago
$like = $modelLike->where(['user_name' => $useInfo['user_id'],'square_id' => $r['square_id']])->find();
7 months ago
$res[$kr]['imgs'] = [];
6 months ago
$res[$kr]['goodsInfo'] = [];
7 months ago
$list['data'][$kr]['isLike'] = !empty($like) ? true : false;
7 months ago
$res[$kr]['avatar_url'] = [];
if ($r['imgs']) {
$img_ids = explode(",", $r['imgs']);
$files = UploadFile::getFileList($img_ids);
$list['data'][$kr]['imgs'] = $files ?: null;
}
6 months ago
if ($r['files']) {
$img_ids = explode(",", $r['files']);
$files = UploadFile::getFileList($img_ids);
$list['data'][$kr]['files'] = $files ?: null;
}
7 months ago
if ($r['user_name']) {
7 months ago
$files = UploadFile::getFileList([$user['avatar_id']]);
7 months ago
$list['data'][$kr]['avatar_url'] = $files ?: null;
}
6 months ago
if ($r['goods_id']) {
5 months ago
try {
$modelgoods = new GoodsModel;
$goods = $modelgoods->getBasic($r['goods_id'])->toArray();
//print_r($goods);die;
$list['data'][$kr]['goodsInfo'] = $goods;
} catch (\Exception $e) {
//print_r($goods);die;
$list['data'][$kr]['goodsInfo'] = [];
}
6 months ago
}
}
return $this->renderSuccess($list);
}
public function dynamicLike(int $id): Json
{
7 months ago
$useInfo = UserService::getCurrentLoginUser(true)->toArray();
$model = new squarelikeModel;
7 months ago
$detail = squarelikeModel::detail($id, (String)$useInfo['user_id']);
7 months ago
7 months ago
$data1 = [];
$data1['merchant_id'] = $this->merchantId;
$data1['user_name'] = $useInfo['user_id'];
$data1['square_id'] = $id;
$data1['real_name'] = $useInfo['nick_name'];
if (empty($detail)) {
7 months ago
if ($model->add($data1)) {
7 months ago
$this->dynamicLikeNum($id);
return $this->renderSuccess('操作成功');
}
} else {
$data['squarelike_id'] = $detail['squarelike_id'];
7 months ago
if ($model::whereIn('squarelike_id', $detail['squarelike_id'])->delete()) {
7 months ago
$this->dynamicLikeNum($id);
return $this->renderSuccess('操作成功');
}
}
}
7 months ago
public function dynamicLikeNum(int $id) : Json
{
$detail = squareModel::detail($id);
$count = squarelikeModel::getCount($id);
$arr = [
'likeNum' => $count,
7 months ago
//'square_id' => $id
7 months ago
];
$detail->edit($arr);
7 months ago
return $this->renderSuccess('操作成功');
7 months ago
}
}