作者 Cool

商圈列表接口调试,周边热点列表数据处理,新增点赞接口

... ... @@ -215,6 +215,65 @@ class Hot extends Api
}
/**
* 点赞
* @ApiWeigh (61)
*
* @ApiTitle (点赞)
* @ApiSummary (点赞)
* @ApiMethod (POST)
* @ApiRoute (/api/hot/good)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="object_id", type="int", required=true, description="点赞id")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {}
})
*/
public function good()
{
if($this->request->isPost()) {
$param = (new HotValidate())->goCheck('good');
// 判断是否点赞
$this->good_model = new StoreInformGood();
$where = [
'where' => [
'user_id' => $this->auth->id,
'object_id' => $param['object_id'],
]
];
$cancel = '';
$user_good = $this->good_model->findOrFail($where,false);
// 执行点赞/取消点赞操作
Db::startTrans();
if($user_good) {
$cancel = '取消';
$result = $this->good_model->where('id',$user_good['id'])->delete();
} else {
// 判断要点赞的数据是否存在
$data = $this->store_inform_model->where('id',$param['object_id'])->find();
if(!$data) {
Db::rollback();
$this->error('点赞的商圈信息不存在');
}
$insert = [
'user_id' => $this->auth->id,
'object_id' => $param['object_id'],
];
$result = $this->good_model->save($insert);
}
if(!$result) {
Db::rollback();
$this->error($cancel.'点赞失败');
}
Db::commit();
$this->success($cancel.'点赞成功');
}
}
/**
* 领取红包
* @ApiWeigh (60)
*
... ...
... ... @@ -835,7 +835,8 @@ class Store extends Api
$status = $this->request->param('status',0,'intval');
$store = $this->get_store();
$where_s = [
'store_id' => $store['id']
'store_id' => $store['id'],
'status' => ['neq',9]
];
if($status) {
$where_s['status'] = $status;
... ...
... ... @@ -7,4 +7,5 @@ namespace app\api\model;
class StoreInformView extends Base
{
protected $updateTime = false;
}
\ No newline at end of file
... ...
... ... @@ -9,38 +9,19 @@ class HotValidate extends BaseValidate
protected $rule = [
'page' => 'require|integer',
'store_id' => 'require',
'store_name' => 'require',
'mobile' => 'require|regex:^1\d{10}$',
'province' => 'require',
'city' => 'require',
'region' => 'require',
'images' => 'require',
'house_id' => 'require',
'house_user_id' => 'require',
'content' => 'require',
'house_ids' => 'require',
'type' => 'require|in:1,2',
'red_package' => 'require',
'number' => 'require',
'deposit_id' => 'require'
'object_id' => 'require',
'store_inform_id' => 'require'
];
protected $message = [
'page.integer' =>'页数必须是整数',
'mobile.regex' =>'手机号格式错误'
];
protected $scene = [
'common' => ['page'], // 公共分页验证
'comment_add' => ['store_id'], // 留言提交
'house_comment_add' => ['house_id','house_user_id'], // 社区留言提交
'store_apply' => ['store_name','province','city','region','name','mobile'], // 开通社区提交
'store_report' => ['content'], // 举报建议提交
'store_edit' => ['store_icon','store_name','mobile','province','city','region','images'], // 店铺信息修改
'store_inform_add' => ['content','images','house_ids','type'], // 发布信息
'red' => ['red_package','number'], // 发布信息红包
'house_new' => ['house_ids'], // 绑定社区
'deposit_order' => ['deposit_id'], // 板币充值提交
'comment_list' => ['store_id','page'], // 留言列表
'good' => ['object_id'], // 点赞
'get_red_package' => ['store_inform_id'], // 商家信息id
];
}
\ No newline at end of file
... ...