Commit e67e7d01 authored by clone's avatar clone

work

parent 2bb1488f
<?php <?php
namespace app\api\controller; namespace app\api\controller;
/** /**
* 微信jsSdk * 微信jsSdk
* Created by zw. * Created by zw.
...@@ -10,21 +12,46 @@ namespace app\api\controller; ...@@ -10,21 +12,46 @@ namespace app\api\controller;
*/ */
use app\api\extend\Basic; use app\api\extend\Basic;
use think\Request; use app\model\UWxInfo;
use think\Exception;
class WxSdk extends Basic class WxSdk extends Basic
{ {
private $wxInfoModel;
public function __construct($request = null) public function __construct($request = null)
{ {
parent::__construct($request); parent::__construct($request);
$this->wxInfoModel = new UWxInfo();
} }
public function saveWxInfo(){ public function saveWxInfo()
$params = $this->params; {
$params = array( $params = $this->params;
"wang" /* $params = array(
); "wx_open_id" => "123132123123123",
"buyer_nick" => "123123123",
"buyer_img" => "123123123",
"sex" => 1,
"province" => "123123123",
"city" => "123123123",
"source" => 1,// 0:h5邀请 1安卓 2苹果',
);*/
$checkResult = $this->validate($params, "UWxInfoValidate.add");
if (true !== $checkResult) {
return $this->response("101", $checkResult);
}
try{
$id = $this->wxInfoModel->addWxInfo($params);
if($id > 0){
return $this->response("200","request success",["id"=>$id]);
}
}catch (Exception $exception){
return $this->response("101","request error:".$exception);
}
} }
} }
...@@ -14,18 +14,22 @@ use think\Validate; ...@@ -14,18 +14,22 @@ use think\Validate;
class UWxInfoValidate extends Validate class UWxInfoValidate extends Validate
{ {
protected $rule = [ protected $rule = [
'wx_open_id' => 'require', 'wx_open_id' => 'require|length:10,50',
'sex' => 'require|number', 'sex' => 'require|number',
'source' => 'require|number',
]; ];
protected $message = [ protected $message = [
'wx_open_id.require' => '微信open_id不能为空', 'wx_open_id.require' => '微信open_id不能为空',
'sex.require' => '性别为必须字段', 'wx_open_id.length:10,50' => '微信open_id错误',
'sex.number' => '性别必须是数字', 'sex.require' => '性别为必须字段',
'sex.number' => '性别必须是数字',
'source.require' => '来源为必须字段',
'source.number' => '来源必须是数字',
]; ];
protected $scene = [ protected $scene = [
'add' => [ 'wx_open_id', 'sex' ], 'add' => [ 'wx_open_id', 'sex','source' ],
'select' => [ 'wx_open_id' ], 'select' => [ 'wx_open_id' ],
]; ];
} }
\ No newline at end of file
<?php <?php
namespace app\model; namespace app\model;
use app\api\validate\UWxInfoValidate;
/** /**
* Created by PhpStorm. * Created by PhpStorm.
...@@ -9,17 +9,55 @@ use app\api\validate\UWxInfoValidate; ...@@ -9,17 +9,55 @@ use app\api\validate\UWxInfoValidate;
* Time : 17:14 * Time : 17:14
* Intro: * Intro:
*/ */
class UWxInfo extends Model{ use think\Db;
use think\Exception;
use think\Model;
class UWxInfo extends Model
{
// 设置当前模型对应的完整数据表名称 // 设置当前模型对应的完整数据表名称
protected $table = 'u_wx_info'; protected $table = 'u_wx_info';
private $validate_ ;
public function __construct() public function __construct()
{ {
$this->validate_ = new UWxInfoValidate();
} }
public function addWxInfo($params){ /**
$this->validate_->validate * 新增微信拉取用户信息
* @param $params
* @return int|string
* @throws Exception
*/
public function addWxInfo($params)
{
$wxBin = $this->wxInfoBin($params);
Db::startTrans();
try{
$id = $this->insertGetId($wxBin);
Db::commit();
return $id;
}catch (Exception $exception){
Db::rollback();
throw $exception;
}
}
private function wxInfoBin($params)
{
$arr = [];
if (isset($params["id"])) {
$arr["wx_open_id"] = $params["id"];
}
$arr["wx_open_id"] = $params["wx_open_id"];
$arr["buyer_nick"] = $params["buyer_nick"];
$arr["buyer_img"] = $params["buyer_img"];
$arr["sex"] = $params["sex"];
$arr["province"] = $params["province"];
$arr["city"] = $params["city"];
$arr["source"] = $params["source"];
$arr["create_time"] = date("Y-m-d H:i:s", time());
$arr["update_time"] = date("Y-m-d H:i:s", time());
return $arr;
} }
} }
...@@ -241,6 +241,7 @@ Route::group('index', [ ...@@ -241,6 +241,7 @@ Route::group('index', [
'test' => ['index/WxTest/test', [ 'method' => 'POST|GET' ] ], //wx 'test' => ['index/WxTest/test', [ 'method' => 'POST|GET' ] ], //wx
]); ]);
...@@ -316,6 +317,9 @@ Route::group('api', [ ...@@ -316,6 +317,9 @@ Route::group('api', [
'houseTable' => [ 'api/TransferHouseInfo/table', [ 'method' => 'post|get' ] ], //转商铺表 'houseTable' => [ 'api/TransferHouseInfo/table', [ 'method' => 'post|get' ] ], //转商铺表
'houseImgTable' => [ 'api/TransferHouseInfo/houseImg', [ 'method' => 'post|get' ] ], //转楼盘表 'houseImgTable' => [ 'api/TransferHouseInfo/houseImg', [ 'method' => 'post|get' ] ], //转楼盘表
'agentHouse' => [ 'api/TransferHouseInfo/agentHouse', [ 'method' => 'post|get' ] ], //转楼盘表 'agentHouse' => [ 'api/TransferHouseInfo/agentHouse', [ 'method' => 'post|get' ] ], //转楼盘表
'saveWxInfo' => ['api/WxSdk/saveWxInfo', [ 'method' => 'POST|GET' ] ], //wx
]); ]);
Route::group('chat', [ Route::group('chat', [
......
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