This commit is contained in:
2024-10-29 14:04:59 +08:00
commit 48bf3e6f33
2839 changed files with 762707 additions and 0 deletions

View File

@@ -0,0 +1,225 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2019-01-05
* Time: 13:58
*/
namespace app\admin\controller;
use app\admin\model\Tbpl;
use tbpls\Tbpls;
use think\Db;
use think\Jdtbpl;
use think\Loader;
use think\Model;
class Shopselle extends BaseController
{
private function init_search(&$search)
{
$search['product_id'] = '';
$search['item_id'] = '';
}
public function index() {
$param = $this->request->param();
$search = [];
$this->init_search($search);
$where = ['stat' => 0];
if (isset($param['product_id']) && $param['product_id'] != '')
{
$where['product_id'] = $param['product_id'];
$search['product_id'] = $param['product_id'];
}
if (isset($param['item_id']) && $param['item_id'] != '')
{
$where['item_id'] = $param['item_id'];
$search['item_id'] = $param['item_id'];
}
$order = ['id' => 'desc'];
$dataObject = db('tbpl')->where($where)->order($order)->paginate(20);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search
];
$this->assign($value);
return $this->fetch();
}
public function add(){
return $this->fetch();
}
public function creatpl(){
$item_id = $this->request->post('item_id');
$seller_id = $this->request->post('seller_id');
$current_page = $this->request->post('current_page');
$product_id = $this->request->post('pid');
$shopselle_list = model('shopselle')->where(['product_id' => $product_id, 'stat' => 0])->select();
$shopselle_list = json_decode(json_encode($shopselle_list), true);
$count = count($shopselle_list);
if ($count >= 50)
{
return $this->error('当前产品评论数量超过50,请先删除部分评论');
}
$tbpl = new Tbpl();
$findpl = Db('tbpl')->where(['product_id' => $product_id, 'item_id' => $item_id, 'stat' => 0])->find();
if (!empty($findpl))
{
$tbpl_id = $findpl['id'];
}
else
{
$insert_data = [
'product_id' => $product_id,
'item_id' => $item_id,
'create_time' => date('Y-m-d H:i:s'),
'stat' => 0
];
$tbpl_id = $tbpl->insertGetId($insert_data);
if (!$tbpl_id)
{
return $this->error('添加评论失败');
}
}
$pl = new Jdtbpl($item_id,$seller_id,$current_page);
$plBack = $pl->getPl();
$pl_list = json_decode(json_decode(json_decode($plBack, true), true)['result']['ret_body'], true)['rateList'];
if (empty($pl_list))
{
return $this->error('当前页没有评论');
}
$plid_list = array_column($shopselle_list, 'plid');
foreach ($pl_list as $key => $value) {
if (in_array($value['id'], $plid_list))
continue;
$count++;
if ($count > 50)
break;
$insert_data = [];
$insert_data['pics'] = json_encode($value['pics']);
$insert_data['auctionSku'] = $value['auctionSku'];
$insert_data['headPic'] = $value['headPic'];
$insert_data['cmsSource'] = $value['cmsSource'];
$insert_data['displayUserNick'] = $value['displayUserNick'];
$insert_data['plid'] = $value['id'];
$insert_data['rateContent'] = $value['rateContent'];
$insert_data['rateDate'] = $value['rateDate'];
$insert_data['reply'] = $value['reply'];
$insert_data['memberIcon'] = $value['memberIcon'];
$insert_data['tamllSweetLevel'] = $value['tamllSweetLevel'];
$insert_data['useful'] = $value['useful'] == 'true' ? 0 : 1; // 0可用1不可用
$insert_data['stat'] = 0;
$insert_data['product_id'] = $product_id;
$insert_data['tbpl_id'] = $tbpl_id;
model('shopselle')->insert($insert_data);
}
return $this->success('添加成功');
}
public function pllist($id,$page=''){
$id = intval($id);
$where = ['tbpl_id' => $id, 'stat' => 0];
$count = Db('shopselle')->where($where)->count();
$list = Db('shopselle')->where($where)->paginate(10,$count);
$page = $list->render();
$this->assign('page',$page);
$this->assign('list',$list);
return $this->fetch();
}
# 清空评论
public function clear_by_tbpl_id()
{
$tbpl_id = $this->request->param('tbpl_id');
if ($tbpl_id == '')
{
return $this->json(-1, '评论id错误');
}
model('shopselle')->where(['stat' => 0, 'tbpl_id' => $tbpl_id])->update(['stat' => 1]);
return $this->json(200, '清空成功');
}
public function delete_by_tbpl_id()
{
$tbpl_id = $this->request->param('tbpl_id');
if ($tbpl_id == '')
{
return $this->json(-1, '评论id错误');
}
model('shopselle')->where(['stat' => 0, 'tbpl_id' => $tbpl_id])->update(['stat' => 1]);
model('tbpl')->where(['id' => $tbpl_id])->update(['stat' => 1]);
return $this->json(200, '删除成功');
}
public function edit($id,$pid){
$id = intval($id);
$pid = intval($pid);
$where = ['id'=>$pid];//dump($where);die;
$tbpl = new Tbpl();
$find = $tbpl->where($where)->field('reply')->select();
//$find = $tbpl->getPageList($where);
$find=collection($find)->toArray();//把对象转成数组
//dump($find);die;
$reply = $find[0]['reply'];
$value = json_decode($reply);
$value = collection($value)->toArray();
$value = $value['result'];
$value = collection($value)->toArray();
$value = $value['ret_body'];
$value = json_decode($value);
$value = collection($value)->toArray();
$value = $value['rateList'];
foreach ($value as $k => $v){
$value = collection($v)->toArray();
}
dump($value);die;
}
public function delete() {
$id = $this->request->post('id');
$result = model('shopselle')->where('id', $id)->update(['stat' => 1]);
if ($result) {
return $this->json(1, '操作成功');
} else {
return $this->json(-2, '操作失败');
}
}
public function batchDelete() {
if ($this->administrator != 1) {
return $this->json(-1, '无权限');
}
$ids = rtrim($this->request->post('ids'), ',');
$ids = explode(",", $ids);
$data = [];
foreach ($ids as $key => $value) {
$result = model('shopselle')->where('id', $value)->update(['stat' => 1]);
if (!$result) {
return $this->json(-2, $value . '操作失败');
}
}
return $this->json(1, '操作成功');
}
}