作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

测试

... ... @@ -194,7 +194,7 @@ class Cart extends Api
$cart = $this->model->get($cart_id);
empty($cart) && $this->error(__('购物车信息不存在'));
$goods_num < 1 && $this->error(__('商品数量不能小于1'));
halt(json($cart['spec']->toArray()));
halt($cart['spec']->toArray());
if($cart['goods']['ismake'] == '0' && $cart['spec']['stock_num'] < $goods_num){
$this->error(__('商品库存不足'.$goods_num.'件'));
}
... ...
... ... @@ -71,22 +71,22 @@ class User extends Api
$code = $this->request->post('code');
$user_info = $this->request->post('user_info');
$testopenid = $this->request->post('testopenid');
$session = Wechat::miniProgram()->auth->session($code);
// 自动注册用户
$userInfo = json_decode(htmlspecialchars_decode($user_info), true);
if (!$user = $this->model->get(['openid' => $session['openid']])) {
$user = $this->model;
$userInfo['openid'] = $session['openid'];
}
$userInfo['nickname'] = preg_replace('/[\xf0-\xf7].{3}/', '', $userInfo['nickName']);
$userInfo['avatar'] = $userInfo['avatarUrl'];
if (!$user->allowField(true)->save($userInfo)) {
$this->error('用户登录失败');
}
// $session = [
// 'openid' => $testopenid ?: 'test',
// ];
// $user = $this->model->get(['openid' => $session['openid']]);
// $session = Wechat::miniProgram()->auth->session($code);
// // 自动注册用户
// $userInfo = json_decode(htmlspecialchars_decode($user_info), true);
// if (!$user = $this->model->get(['openid' => $session['openid']])) {
// $user = $this->model;
// $userInfo['openid'] = $session['openid'];
// }
// $userInfo['nickname'] = preg_replace('/[\xf0-\xf7].{3}/', '', $userInfo['nickName']);
// $userInfo['avatar'] = $userInfo['avatarUrl'];
// if (!$user->allowField(true)->save($userInfo)) {
// $this->error('用户登录失败');
// }
$session = [
'openid' => $testopenid ?: 'test',
];
$user = $this->model->get(['openid' => $session['openid']]);
// 生成token (session3rd)
$guid = guidv4();// 生成一个不会重复的随机字符串
$timeStamp = microtime(true);// 当前时间戳 (精确到毫秒)
... ...