|
@@ -4,6 +4,10 @@ |
|
@@ -4,6 +4,10 @@ |
4
|
namespace app\api\controller;
|
4
|
namespace app\api\controller;
|
5
|
|
5
|
|
6
|
use dh2y\qrcode\QRcode;
|
6
|
use dh2y\qrcode\QRcode;
|
|
|
7
|
+use think\Db;
|
|
|
8
|
+use think\Exception;
|
|
|
9
|
+use think\exception\PDOException;
|
|
|
10
|
+use think\exception\ValidateException;
|
7
|
|
11
|
|
8
|
/**
|
12
|
/**
|
9
|
* 墨宝档案
|
13
|
* 墨宝档案
|
|
@@ -203,7 +207,17 @@ class Treasured extends BaseApi |
|
@@ -203,7 +207,17 @@ class Treasured extends BaseApi |
203
|
if ($treasured && $data['page'] == 1){
|
207
|
if ($treasured && $data['page'] == 1){
|
204
|
model('config')->where('name','mobao_num')->setInc('value');
|
208
|
model('config')->where('name','mobao_num')->setInc('value');
|
205
|
}
|
209
|
}
|
206
|
- //4.返回数据
|
210
|
+ //4.判断是不是点赞
|
|
|
211
|
+ if ($treasured){
|
|
|
212
|
+ foreach ($treasured as $key => $val){
|
|
|
213
|
+ $treasured[$key]['is_zan'] = 0;
|
|
|
214
|
+ $zan = model('treasured_zan')->where('user_id',$this->auth->id)->where('treasured_id',$val['id'])->find();
|
|
|
215
|
+ if ($zan){
|
|
|
216
|
+ $treasured[$key]['is_zan'] = 1;
|
|
|
217
|
+ }
|
|
|
218
|
+ }
|
|
|
219
|
+ }
|
|
|
220
|
+ //5.返回数据
|
207
|
$this->success('查询数据成功',$treasured);
|
221
|
$this->success('查询数据成功',$treasured);
|
208
|
}
|
222
|
}
|
209
|
|
223
|
|
|
@@ -255,6 +269,16 @@ class Treasured extends BaseApi |
|
@@ -255,6 +269,16 @@ class Treasured extends BaseApi |
255
|
}
|
269
|
}
|
256
|
$treasured = $treasured->page($data['page'],$data['num'])
|
270
|
$treasured = $treasured->page($data['page'],$data['num'])
|
257
|
->select();
|
271
|
->select();
|
|
|
272
|
+ //3.判断是不是点赞
|
|
|
273
|
+ if ($treasured){
|
|
|
274
|
+ foreach ($treasured as $key => $val){
|
|
|
275
|
+ $treasured[$key]['is_zan'] = 0;
|
|
|
276
|
+ $zan = model('treasured_zan')->where('user_id',$this->auth->id)->where('treasured_id',$val['id'])->find();
|
|
|
277
|
+ if ($zan){
|
|
|
278
|
+ $treasured[$key]['is_zan'] = 1;
|
|
|
279
|
+ }
|
|
|
280
|
+ }
|
|
|
281
|
+ }
|
258
|
//4.返回数据
|
282
|
//4.返回数据
|
259
|
$this->success('查询数据成功',$treasured);
|
283
|
$this->success('查询数据成功',$treasured);
|
260
|
}
|
284
|
}
|
|
@@ -268,14 +292,49 @@ class Treasured extends BaseApi |
|
@@ -268,14 +292,49 @@ class Treasured extends BaseApi |
268
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
292
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
269
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
293
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
270
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
294
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
271
|
- * @ApiReturn ()
|
295
|
+ * @ApiReturn ({
|
|
|
296
|
+ "code": 1,
|
|
|
297
|
+ "msg": "查询数据成功",
|
|
|
298
|
+ "time": "1609742416",
|
|
|
299
|
+ "data": {
|
|
|
300
|
+ "id": 1,
|
|
|
301
|
+ "user_id": 2,
|
|
|
302
|
+ "avatar": "头像",
|
|
|
303
|
+ "nickname": "署名",
|
|
|
304
|
+ "title": "墨宝标题",
|
|
|
305
|
+ "number": "墨宝编号",
|
|
|
306
|
+ "author": "作者",
|
|
|
307
|
+ "images": "墨宝图片",
|
|
|
308
|
+ "content": "内容",
|
|
|
309
|
+ "production_typeface": "字体",
|
|
|
310
|
+ "production_typeface_id": "字体ID",
|
|
|
311
|
+ "production_format": "格式",
|
|
|
312
|
+ "production_format_id": "格式ID",
|
|
|
313
|
+ "treasured_size": "尺寸名称",
|
|
|
314
|
+ "treasured_size_id": "尺寸ID",
|
|
|
315
|
+ "status": "状态:0=待出售,1=已出售,2=非卖品",
|
|
|
316
|
+ "zan_num": "点赞数量",
|
|
|
317
|
+ "createtime": "2020-12-30 13:38:38",
|
|
|
318
|
+ "qr_code": "二维码",
|
|
|
319
|
+ "qr_code_d": "海报二维码",
|
|
|
320
|
+ "updatetime": "2020-12-30 13:38:38",
|
|
|
321
|
+ "deletetime": "删除时间",
|
|
|
322
|
+ "message": "删除提示",
|
|
|
323
|
+ "is_zan": "是否点赞 0=未点赞,1=已点赞"
|
|
|
324
|
+ }
|
|
|
325
|
+ })
|
272
|
*/
|
326
|
*/
|
273
|
public function getTreasuredContent(){
|
327
|
public function getTreasuredContent(){
|
274
|
//1.获取动态id
|
328
|
//1.获取动态id
|
275
|
$id = $this->get_data('id','墨宝档案ID不能为空');
|
329
|
$id = $this->get_data('id','墨宝档案ID不能为空');
|
276
|
//2.查询数据
|
330
|
//2.查询数据
|
277
|
$treasured = model('treasured')->where('id',$id)->find();
|
331
|
$treasured = model('treasured')->where('id',$id)->find();
|
278
|
- //
|
332
|
+ //3.查询有没有点赞
|
|
|
333
|
+ $treasured['is_zan'] = 0;
|
|
|
334
|
+ $zan = model('treasured_zan')->where('user_id',$this->auth->id)->where('treasured_id',$id)->find();
|
|
|
335
|
+ if ($zan){
|
|
|
336
|
+ $treasured['is_zan'] = 1;
|
|
|
337
|
+ }
|
279
|
//4.返回数据
|
338
|
//4.返回数据
|
280
|
$this->success('查询数据成功',$treasured);
|
339
|
$this->success('查询数据成功',$treasured);
|
281
|
}
|
340
|
}
|
|
@@ -310,11 +369,14 @@ class Treasured extends BaseApi |
|
@@ -310,11 +369,14 @@ class Treasured extends BaseApi |
310
|
->find();
|
369
|
->find();
|
311
|
if ($treasured_zan){
|
370
|
if ($treasured_zan){
|
312
|
$treasured_zan->delete();
|
371
|
$treasured_zan->delete();
|
|
|
372
|
+ model('treasured')->where('id',$treasured_id)->setDec('zan_num');
|
313
|
$this->success('查询成功',['code'=>0,'msg'=>'取消点赞成功']);
|
373
|
$this->success('查询成功',['code'=>0,'msg'=>'取消点赞成功']);
|
314
|
}
|
374
|
}
|
315
|
- //3.增加点赞
|
375
|
+ //4.增加点赞
|
316
|
model('treasured_zan')->create(['user_id'=>$this->auth->id,'treasured_id'=>$treasured_id]);
|
376
|
model('treasured_zan')->create(['user_id'=>$this->auth->id,'treasured_id'=>$treasured_id]);
|
317
|
- //4.返回结果
|
377
|
+ //5.增加点赞数量
|
|
|
378
|
+ model('treasured')->where('id',$treasured_id)->setInc('zan_num');
|
|
|
379
|
+ //6.返回结果
|
318
|
$this->success('查询成功',['code'=>1,'msg'=>'点赞成功']);
|
380
|
$this->success('查询成功',['code'=>1,'msg'=>'点赞成功']);
|
319
|
}
|
381
|
}
|
320
|
|
382
|
|