Commit 24b51f56 by 汪睦雄

修改接口

parent 7ce83c00
......@@ -188,42 +188,35 @@ class Order extends Base
}
$data['order_id'] = intval($order->id);
$data['total_fee'] = doubleval($order->total_fee);
//生成订单
//TODO::关闭支付接口
// 生成订单
// TODO::关闭支付接口
// // 更新订单号-防止签名失败
// $order->out_trade_no = (new \WxPayConfig())->GetMerchantId() . time() . $order->id;
//
// $input = new \WxPayUnifiedOrder();
// $input->SetBody($order->title);
// $input->SetAttach($order->id);
// $input->SetOut_trade_no($order->out_trade_no);
// $input->SetTotal_fee(floatval($order->total_fee) * 100); // 单位为分
// $input->SetTime_start(date("YmdHis"));
// $input->SetTime_expire(date("YmdHis", time() + 600));
// // $input->SetGoods_tag("wx-xcx");
// $input->SetNotify_url(config('wx_pay.notify_url'));
// $input->SetTrade_type("JSAPI");
// $input->SetOpenid($this->userinfo[1]);
// $unifiedOrder = \WxPayApi::unifiedOrder($input);
// if ($unifiedOrder["return_code"] == 'FAIL') {
// return ['code' => 1, 'msg' => $unifiedOrder['return_msg']];
// }
// // 保存 prepay_id 用于发送模版消息
// $order->prepay_id = $unifiedOrder['prepay_id'];
// $order->save();
// $jsApiParameters = $this->GetJsApiParameters($unifiedOrder);
// if ($jsApiParameters) {
// return ['code' => 0, 'msg' => '支付参数', 'data' => $data, 'result' => json_decode($jsApiParameters)];
// } else {
// throw new \Exception('订单签名失败');
// }
//TODO::删除测试代码 --------------------开始
$user = UserModel::get($this->userinfo[0]);
$user->is_vip = 1;
$user->vip_endtime = $vip_endtime;
$user->save();
//----------------------------------------结束
$order->out_trade_no = (new \WxPayConfig())->GetMerchantId() . time() . $order->id;
$input = new \WxPayUnifiedOrder();
$input->SetBody($order->title);
$input->SetAttach($order->id);
$input->SetOut_trade_no($order->out_trade_no);
$input->SetTotal_fee(floatval($order->total_fee) * 100); // 单位为分
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
// $input->SetGoods_tag("wx-xcx");
$input->SetNotify_url(config('wx_pay.notify_url'));
$input->SetTrade_type("JSAPI");
$input->SetOpenid($this->userinfo[1]);
$unifiedOrder = \WxPayApi::unifiedOrder($input);
if ($unifiedOrder["return_code"] == 'FAIL') {
return ['code' => 1, 'msg' => $unifiedOrder['return_msg']];
}
// 保存 prepay_id 用于发送模版消息
$order->prepay_id = $unifiedOrder['prepay_id'];
$order->save();
$jsApiParameters = $this->GetJsApiParameters($unifiedOrder);
if ($jsApiParameters) {
return ['code' => 0, 'msg' => '支付参数', 'data' => $data, 'result' => json_decode($jsApiParameters)];
} else {
throw new \Exception('订单签名失败');
}
Db::commit();
} catch (\Exception $e) {
......
......@@ -154,7 +154,7 @@ class Project extends Base
});
}
$newProjects = $newProjects ? collection($newProjects)->visible(['id', 'title', 'poster', 'night_num', 'price'])->toArray() : [];
$newProjects = $newProjects ? collection($newProjects)->visible(['id', 'title', 'poster', 'sign_limits', 'night_num', 'tags', 'price', 'vip_price', 'type', 'location', 'latitude', 'longitude'])->append(['sign_endtime_str'])->toArray() : [];
if (!$newProjects) return ['code' => 1, 'msg' => '没有更多'];
return ['code' => 0, 'msg' => 'success', 'data' => $newProjects];
......@@ -236,7 +236,7 @@ class Project extends Base
if ($data->delete()) {
$project->collect_num--;
$project->save();
return ['code' => 0, 'msg' => '取消收藏成功!'];
return ['code' => 0, 'msg' => '取消收藏成功!', 'collect'=>'remove'];
} else {
return ['code' => 1, 'msg' => '取消收藏失败,请重试!'];
}
......@@ -249,7 +249,7 @@ class Project extends Base
if ($result) {
$project->collect_num++;
$project->save();
return ['code' => 0, 'msg' => '收藏成功!'];
return ['code' => 0, 'msg' => '收藏成功!', 'collect'=>'add'];
} else {
return ['code' => 1, 'msg' => '收藏失败,请重试!'];
}
......@@ -291,6 +291,24 @@ class Project extends Base
if (!$project) {
return ['code' => 1, 'msg' => '该活动或商家不存在!'];
}
// 是否过期
$endTime = strtotime($project['sign_endtime']);
// 正常
$project['status'] = 0;
$project['status_text'] = '立即报名';
if (strtotime($project['sign_endtime']) > time()) {
// 已过期
$project['status'] = 1;
$project['status_text'] = '预约下次';
}else{
if (intval($project['sign_limits']) <= intval($project['sign_num'])) {
// 已售罄
$project['status'] = 2;
$project['status_text'] = '已售罄';
}
}
// 是否收藏了本活动
$project['is_collect'] = UserCollectionModel::get(['uid' => $this->userinfo[0], 'pid' => input('post.id')]) ? true : false;
return ['code' => 0, 'msg' => 'success', 'data' => $project];
}
......
......@@ -152,7 +152,6 @@ class User extends Base
}
}
public function index()
{
//用户UID
......@@ -196,12 +195,13 @@ class User extends Base
$uid = $this->userinfo[0];
$p = input('post.p/d', 1);
$page = input('post.page/d', 8);
$list = collection(UserModel::get($uid)->project()->page($p, $page)->select());
if ($list->isEmpty()) {
return ['code' => 1, 'msg' => '没有更多'];
}
$list = $list->visible(['title', 'night_num', 'price', 'vip_price', 'poster',])->append(['sign_endtime_str']);
$list = $list->visible(['id', 'title', 'poster', 'sign_limits', 'night_num', 'tags', 'price', 'vip_price', 'type', 'location', 'latitude', 'longitude'])->append(['sign_endtime_str']);
return ['code'=>0,'msg'=>'success','data'=>$list];
}
......
......@@ -42,7 +42,7 @@ class Project extends BaseModel
//未结束
return '剩余'.ceil(($endTime-time())/86400).'天';
} else {
return '结束,预约下一次';
return '预约下次';
}
} elseif ($data['type'] == 2) {
//商家
......
......@@ -30,11 +30,10 @@ class User extends BaseModel
}
}
//用户收藏多对多
// 用户收藏多对多
public function project()
{
return $this->belongsToMany('Project','user_collections','pid','uid');
return $this->belongsToMany('Project', 'user_collections', 'pid', 'uid');
}
}
\ No newline at end of file
......@@ -36,6 +36,7 @@
美行者 商家入驻H5网页<br/>
美行者 商家入驻H5网页<br/>
美行者 商家入驻H5网页<br/>
<img style="height:200px;width:200px;" src="http://jq.hthymedia.com/upload/201809/1537433486.jpeg"/>
</div>
</section>
......
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