Commit 083630ce authored by zhuwei's avatar zhuwei

小程序客户查看商铺记录

parent e42195de
<?php
namespace app\api\controller;
use app\api\extend\Basic;
use app\api\service\UserLookShopService;
use app\model\UWxInfo;
use think\Exception;
class UserLookShop extends Basic
{
private $wxInfoModel;
public function __construct($request = null)
{
parent::__construct($request);
$this->wxInfoModel = new UWxInfo();
}
/**
* 小程序客户查看商铺记录
* @return \think\Response
*/
public function addUserLookShop()
{
$params = $this->params;
/* $params = array(
"wx_union_id" => "123132123123123",
"house_id" => "18",
);*/
$checkResult = $this->validate($params, "UserLookShopValidate.addUserLookShop");
if (true !== $checkResult) {
return $this->response("101", $checkResult);
}
$s_user_look_shop = new UserLookShopService();
$res = $s_user_look_shop->addUserLookShop($params['wx_union_id'],$params['house_id']);
if($res){
return $this->response("200", "request success", $res);
}else{
return $this->response("101", '失败');
}
}
}
......@@ -215,7 +215,6 @@ class WxSdk extends Basic
}
if ($id > 0 ) {
$this->addUserLookShopV2($id,$params['house_id'],$params['source'],1);
return $this->response("200", "request success");
} else{
return $this->response("101", "request exception");
......@@ -224,39 +223,4 @@ class WxSdk extends Basic
}
/**
* 保存看铺数据
* @param $user_id
* @param $house_id
* @param $type
* @param $source
* @return bool
*/
public function addUserLookShopV2($user_id,$house_id,$type,$source)
{
$day = date("Y-m-d", time());
$tModel = new TLookShopUser();
$params["user_id"] = $user_id;
$params["type"] = $type;
$params["house_id"] = $house_id;
$params["look_day"] = $day;
$params["source"] = $day;
$result = $tModel->getList($params, "a.id", 1, 1);
if (count($result) > 0) {
return false;
}
$arr = array(
"user_id" => $user_id,
"type" => $type,
"house_id" => $house_id,
"look_day" => $day,
"source" => $day,
"create_time" => date("Y-m-d H:i:s", time()),
"update_time" => date("Y-m-d H:i:s", time()),
);
$tModel->addLookShop($arr);
return true;
}
}
......@@ -80,6 +80,7 @@ class Basic extends Controller
"office_api/getOfficeBuildingInfoShare",
"api/getOpenidByCode",
"api/saveWXInfoByPortableProgram",
"api/addUserLookShop",
);
......
<?php
namespace app\api\service;
use app\api_broker\service\LookShopService;
use app\api_broker\service\VerifyService;
use app\index\service\HouseService;
use app\model\AttentionModel;
use app\model\GHouses;
use app\model\GHousesImgs;
use app\model\GImageDepot;
use app\model\GLabels;
use app\model\OBargainModel;
use app\model\OfficeGLabels;
use app\model\TLookShopUser;
use app\model\UWxInfo;
class UserLookShopService
{
private $wxInfoModel;
function __construct()
{
$this->wxInfoModel = new UWxInfo();
}
/**
* 小程序客户查看商铺记录
* @param $wx_union_id
* @param $house_id
* @return bool
*/
public function addUserLookShop($wx_union_id,$house_id)
{
// 验证open_id是否已经存在,存在则更新
$wxInfoObj = $this->wxInfoModel->getWxInfoByOpenId($wx_union_id);
if ($wxInfoObj && count($wxInfoObj) > 0) {
$user_id = $wxInfoObj[0]["id"];
$res = $this->saveUserLookShop($user_id,$house_id,2,1);
if ($res) {
return true;
} else{
return false;
}
} else {
return false;
}
}
/**
* 保存看铺数据
* @param $user_id
* @param $house_id
* @param $type
* @param $source
* @return bool
*/
public function saveUserLookShop($user_id,$house_id,$type,$source)
{
$day = date("Y-m-d", time());
$tModel = new TLookShopUser();
$params["a.user_id"] = $user_id;
$params["a.type"] = $type;
$params["a.house_id"] = $house_id;
$params["a.look_day"] = $day;
$params["a.source"] = $source;
$result = $tModel->getList($params, "a.id", 1, 1);
if (count($result) > 0) {
return false;
}
$arr = array(
"user_id" => $user_id,
"type" => $type,
"house_id" => $house_id,
"look_day" => $day,
"source" => $source,
"create_time" => date("Y-m-d H:i:s", time()),
"update_time" => date("Y-m-d H:i:s", time()),
);
$tModel->addLookShop($arr);
return true;
}
}
\ No newline at end of file
......@@ -15,16 +15,8 @@ class WxSdkService{
public function __construct()
{
// $this->appId = "wxbbeb8cd2f4b72aea";
// $this->appSecret = "9ac6d1680553f4b554f3b46d263fbfb3";
if (strpos($this->http_host(), 'api') !== false) {
$this->appId = "wxbbeb8cd2f4b72aea";
$this->appSecret = "9ac6d1680553f4b554f3b46d263fbfb3";
} else {
$this->appId = "wxd30d74d1126d3278";//测试
$this->appSecret = "f29c8c502549020d2193a464be9632dc";//测试
}
$this->appId = "wx1d1bc80d3d973199";//测试
$this->appSecret = "8062e6629ebd7ad70174a382263c9e25";//测试
}
/**
......@@ -35,9 +27,12 @@ class WxSdkService{
public function getOpenidByCode($code)
{
$curl = new CurlUtil();
big_log($this->appId);
big_log($this->appSecret);
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->appId}&secret={$this->appSecret}&js_code={$code}&grant_type=authorization_code";
$result = $curl->get($url);
$result = json_decode($result, "true");
big_log($result);
return $result;
}
......
<?php
namespace app\api\validate;
use think\Validate;
class UserLookShopValidate extends Validate
{
protected $rule = [
'wx_union_id' => 'require|length:10,50',
'house_id' => 'require|number|gt:0',
];
protected $message = [
'wx_union_id.require' => '微信union_id不能为空',
'wx_union_id.length:10,50' => '微信union_id错误',
'house_id.require' => 'house_id为必须字段',
'house_id.number' => 'house_id必须是数字',
'house_id.gt' => 'house_id必须大于0',
];
protected $scene = [
'addUserLookShop' => [ 'wx_union_id','house_id' ],
];
}
\ No newline at end of file
......@@ -653,10 +653,12 @@ Route::group('api', [
'getVersionNo' => ['api/Version/getVersionNo', ['method' => 'post|get']],
'getVersionNoV2' => ['api/version/getVersionNoV2', ['method' => 'post|get']],
'saveWxInfo' => ['api/WxSdk/saveWxInfo', ['method' => 'POST']], //wx
'bindUserId' => ['api/WxSdk/bindUserId', ['method' => 'POST|GET']], //wx
'getOpenidByCode' => ['api/WxSdk/getOpenidByCode', ['method' => 'POST']], //wx
'saveWXInfoByPortableProgram' => ['api/WxSdk/saveWXInfoByPortableProgram', ['method' => 'POST']],
'saveWxInfo' => [ 'api/WxSdk/saveWxInfo', [ 'method' => 'POST' ] ], //wx
'bindUserId' => [ 'api/WxSdk/bindUserId', [ 'method' => 'POST|GET' ] ], //wx
'getOpenidByCode' => [ 'api/WxSdk/getOpenidByCode', [ 'method' => 'post|get' ] ], //wx
'saveWXInfoByPortableProgram' => [ 'api/WxSdk/saveWXInfoByPortableProgram', [ 'method' => 'post|get' ] ],
'addUserLookShop' => [ 'api/UserLookShop/addUserLookShop', [ 'method' => 'post|get' ] ],
'sendCode' => ['api/Register/registerSendCode', ['method' => 'POST']],
......
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