Commit 55c388ec authored by clone's avatar clone

获取我关注的商品列表

parent 7a8bf575
<?php
namespace app\api\controller;
use app\api\extend\Basic;
use app\model\AttentionModel;
use think\Request;
/**
* Created by PhpStorm.
* User : zw
* Date : 2017/12/13
* Time : 10:20
* Intro: 我的关注楼盘列表
*/
class AttentionShop extends Basic
{
protected $attentionModel;
public function __construct($request = null)
{
parent::__construct($request);
$this->attentionModel = new AttentionModel();
}
/**
* 新增或者取消我的关注
* @return \think\Response
*/
public function addOrUpdateAttention()
{
$params = array(
"id" => 2,
"user_id" => 1,
"house_id" => 2,
"is_del" => 0
);
$msg = isset($params['id']) ? "修改" : "新增";
$result = $this->attentionModel->addOrUpdateAttentionShop($params);
if ($result['code'] == 200) {
return $this->response("200", $msg . "成功", $result["msg"]);
} else {
return $this->response("101", $msg . $result["msg"]);
}
}
/**
* 我的关注商铺列表
* @return \think\Response
*/
public function attentionList()
{
$params = array(
"user_id" => 1,
"pageNo" => 1,
"pageSize" => 15,
);
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
$order_ = 'a.create_time desc';
$field = "a.id,b.title,b.area,b.room_area2,b.price,b.shangpu_tags";
if (!isset($params["user_id"])) {
return $this->response("101", "用户id不能为空");
}
$params["is_del"] = 0; //关注中的商铺
$result = $this->attentionModel->myAttentionList($pageNo, $pageSize, $order_, $field, $params);
if (count($result) <= 0) {
return $this->response("200", "请求数据为空");
}
foreach ($result as $key => $val) {
$result[$key]["api_path"] = IMG_PATH;
$imgParam["house_id"] = $val["house_id"];
$imgParam["imgtype"] = 1; //默认主图
$result[$key]["images"] = $this->dbImg->getHouseImages($imgParam, 1);
}
return $this->response("200", "request success", $result);
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
namespace app\api\controller;
use app\api\extend\Basic;
use app\model\Evaluate;
use app\model\HouseImgs;
use app\model\JournalAccounts;
......@@ -11,25 +12,28 @@ use app\model\JournalAccounts;
* User : zw
* Date : 2017/12/12
* Time : 17:24
* Intro:
* Intro: 我的交易记录
*/
class TradeLog extends Basic
{
protected $journalAccountsMode;
protected $dbImg;
protected $evaluateMode;
public function __construct($request = null)
{
parent::__construct($request);
$this->journalAccountsMode = new JournalAccounts();
$this->dbImg = new HouseImgs();
$this->evaluateMode = new Evaluate();
}
public function getTradeList()
{
$params = $this->params;
$param = array(
"user_id" => "1",
"phone" => "158****6165",
"pageNo" => 1,
"pageSize" => 15,
......@@ -44,14 +48,19 @@ class TradeLog extends Basic
$result = $this->journalAccountsMode->getJournalAccountsList($pageNo, $pageSize, $order_, $field, $param);
if (count($result) <= 0) {
return $this->response("200", "请求数据为空");
}
foreach ($result as $key => $val) {
$result[$key]["api_path"] = IMG_PATH;
$param["house_id"] = $val["id"];
$param["imgtype"] = 1; //默认主图
$result[$key]["images"] = $this->dbImg->getHouseImages($param, 1);
$imgParam["house_id"] = $val["house_id"];
$imgParam["imgtype"] = 1; //默认主图
$result[$key]["images"] = $this->dbImg->getHouseImages($imgParam, 1);
$evaluateResult = $this->evaluateMode->getIsEvaluate(20, $val["house_id"], $param["user_id"]);
$result["is_evaluate"] = count($evaluateResult) > 0 ? 1 : 0;
}
return $this->response("200", "request", $result);
}
......
<?php
namespace app\model;
use think\Model;
class Attention extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'u_attention';
}
<?php
namespace app\model;
use think\Model;
class AttentionModel extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'u_attention';
public function __construct()
{
}
/**
* 新增或取消我关注的店铺
* @param $params
* @return array
*/
public function addOrUpdateAttentionShop($params){
$arr = array();
if (isset($params['user_id'])) {
$arr["user_id"] = $params['user_id'];
}
if (isset($params['house_id'])) {
$arr["house_id"] = $params['house_id'];
}
if (isset($params['is_del'])) {
$arr["is_del"] = $params['is_del'];
}
if (isset($params['id'])) {
$result = $this
->where("id=" . $params['id'])
->select();
if (count($result) > 0) {
$arr["id"] = $params["id"];
} else {
return [ "code" => "101", "msg" => "数据不存在" ];
}
} else {
$arr["create_time"] = time();
}
Db::startTrans();
try {
$id = $this->save($arr);
Db::commit();
return [ "code" => "200", "msg" => $id ];
} catch (\Exception $e) {
Db::rollback();
return [ "code" => "101", "msg" => "失败,数据异常" ];
}
}
/**
* 获取我关注的商品列表
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param $field
* @param $param
* @return false|\PDOStatement|string|\think\Collection
*/
public function myAttentionList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field, $param){
$params["a.user_id"] = $param["user_id"];
$params["b.room_num_left"] = array("<>",0); //剩余数为0 的商品不显示
return $this->field($field)
->alias("a")
->join('houseinfos b','a.house_id = b.id','LEFT')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
}
}
......@@ -54,4 +54,21 @@ class Evaluate extends Model
return $data;
}
/**
* 获取商铺是否评价
* @param int $source
* @param $recordId
* @param $userId
* @return false|\PDOStatement|string|\think\Collection
*/
public function getIsEvaluate($source =20 ,$recordId , $userId){
$params["source"] = $source ;
$params["record_id"] = $recordId;
$params["user_id"] = $userId;
return $this->field("id")
->where($params)
->select();
}
}
......@@ -30,10 +30,10 @@ class JournalAccounts extends Model
->where($where_)
->count("id");
}
/**
* 成交记录列表
*
*
* @param type $pageNo
* @param type $pageSize
* @param type $order_
......@@ -65,8 +65,8 @@ class JournalAccounts extends Model
->page($pageNo)
->select();
}
$fields_houinfo = 'id,title,rent_type,price,room_area,room_area2,shangpu_type';
$fields_houinfo = 'id,title,rent_type,price,room_area,room_area2,shangpu_type';
//查找商铺或街铺的名字和图片
foreach ($result as $key => $value) {
$data[$key] = Db::table('houseinfos')->field($fields_houinfo)->where('id',$value['house_id'])->find();
......@@ -74,7 +74,28 @@ class JournalAccounts extends Model
->where('house_id', $value['house_id'])->where('imgtype',1)->find();
$data[$key]['img'] = $img['imagename'];
}
return $data;
}
/**
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param $field
* @param $param
* @return mixed
*/
public function getJournalAccountsList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field, $param)
{
$params["b.phpone"] = $param["phone"];
return $this->db
->field($field)
->alias("a")
->join('applies b','a.apply_id = b.id' ,'LEFT')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
}
}
......@@ -83,6 +83,10 @@ Route::group('api',[
//tradeLog
'getTradeList' => ['api/TradeLog/getTradeList',['method' => 'get']],
//AttentionShop
'addOrUpdateAttention' => ['api/AttentionShop/addOrUpdateAttention',['method' => 'post']],
'attentionList' => ['api/AttentionShop/attentionList',['method' => 'post | get']],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment