作者 jinglong
1 个管道 的构建 失败 耗费 3 秒

增加我的收藏接口

# ���� stages
stages:
- pull
# ���� job
job1:
stage: pull
script:
- cd /alidata/www/fast/hotel111
- git pull
\ No newline at end of file
... ...
<?php
namespace app\admin\model;
use think\Model;
class Collection extends Model
{
// 表名
protected $name = 'collection';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
];
}
... ...
... ... @@ -140,6 +140,10 @@ class Brand extends Api
"隐秘乡奢",
"家庭情侣"
],
"style": [//商品规格
"主餐匙,茶匙各1件",
"古堡灰"
],
"new_price": 2199,//新人价格(未登录,未购买记录(个人中心返是否有购买记录),显示该字段,另加“新人价”标签)
"sale_price": 2299//销售价格
"expense_price": //运费(0:显示包运费标签)
... ...
... ... @@ -95,6 +95,7 @@ class Cars extends Api
"id": 1,//购物车id
"image": "http://jinglong.springchunjia.cn/uploads/20191127/287ca016a4d41a239ec77c91d982309d.png",//商品图片
"price": 100,//商品价格
"style": "",//商品款式
"goods_id": 1,//商品id
"goods_number": 2,//商品数量
"name": "MONENT 动感系列动感系列动感系列",//商品名称
... ... @@ -119,7 +120,7 @@ class Cars extends Api
->alias('c')
->join('goods g','c.g_id = g.id','LEFT')
->where(['c.uid'=>$this->uid])
->field('c.id,c.g_id goods_id,c.price,c.goods_number,g.name,g.image,g.introduce')
->field('c.id,c.g_id goods_id,c.price,c.goods_number,c.style,g.name,g.image,g.introduce')
->useSoftDelete('g.deletetime')
->select();
$total_price = 0;
... ... @@ -176,6 +177,70 @@ class Cars extends Api
}
/**
* @ApiTitle (猜你喜欢商品列表)
* @ApiSummary (猜你喜欢商品列表)
* @ApiMethod (GET)
* @ApiRoute (/api/cars/likeGodsList)
*
* @ApiParams (name="page", type="inter", required=true, description="分页页码")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1574941706",
"data": {
"data": [
{
"id": 7,//商品id
"image": "http://jinglong.springchunjia.cn/uploads/20191128/8a677f5a0418059bf1b974c50026af13.png",//图片路径
"name": "MONENT 动感系列",//商品名称
"tag": [//商品标签
"日式简约",
"隐秘乡奢",
"家庭情侣"
],
"style": [//商品规格
"主餐匙,茶匙各1件",
"古堡灰"
],
"new_price": 2199,//新人价格(未登录,未购买记录(个人中心返是否有购买记录),显示该字段,另加“新人价”标签)
"sale_price": 2299//销售价格
"expense_price": //运费(0:显示包运费标签)
},
{
"id": 4,
"image": "http://jinglong.springchunjia.cn/uploads/20191128/93971e55b83d1a09c1831f8197514305.png",
"name": "MONENT 动感系列",
"tag": [
"AB级",
"ABX级",
"ABN级"
],
"new_price": 2499,
"sale_price": 2599
},
],
"total_page": 1
}
})
*/
public function likeGodsList(){
if($this->request->isGet()){
$page = $this->request->get('page');
$rule = config('verify.page');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page])) {
$this->error($validate->getError());
}
$arr = Common::goodsList('',$page,'','hots desc,id desc');
$this->success('成功',$arr);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (商品结算)
* @ApiSummary (商品结算)
* @ApiMethod (POST)
... ... @@ -185,6 +250,7 @@ class Cars extends Api
* @ApiParams (name="goods_id", type="string", required=true, description="商品id(多个以逗号隔开,如:1,3,4)")
* @ApiParams (name="price", type="string", required=true, description="商品价格(多个以逗号隔开,如:100,10,200)")
* @ApiParams (name="goods_number", type="string", required=true, description="商品数量(多个以逗号隔开,如:10,10,10)")
* @ApiParams (name="style", type="string", required=true, description="商品款式(多个以逗号隔开,如:‘款式1,款式2,款式3’)")
*
* @ApiReturn({
"code": 1,
... ... @@ -199,6 +265,7 @@ class Cars extends Api
"introduce": "轻波款,为客厅缀上霞光淡雾",//商品简介
"price": "250",//商品价格
"goods_number": "5"//商品数量
"style": "款式1"//商品款式
},
{
"id": 1,
... ... @@ -220,18 +287,20 @@ class Cars extends Api
$goods_id = $this->request->post('goods_id');
$price = $this->request->post('price');
$goods_number = $this->request->post('goods_number');
$style = $this->request->post('style');
$rule = config('verify.settle_goods');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['goods_id'=>$goods_id,'price'=>$price,'goods_number'=>$goods_number])) {
if (!$validate->check(['goods_id'=>$goods_id,'price'=>$price,'goods_number'=>$goods_number,'style'=>$style])) {
$this->error($validate->getError());
}
$goods_id_s = explode(',',$goods_id);
$price_s = explode(',',$price);
$goods_number_s = explode(',',$goods_number);
$style_s = explode(',',$style);
//合并数组
$key = ['goods_id','price','goods_number'];
$res_goods = Common::array_merge_more($key,$goods_id_s,$price_s,$goods_number_s);
$key = ['goods_id','price','goods_number','style'];
$res_goods = Common::array_merge_more($key,$goods_id_s,$price_s,$goods_number_s,$style_s);
//查询商品
$res = Common::selectSoftWhereData('goods',['id'=>['in',$goods_id_s]],'id,name,image,expense_price,introduce');
$total_price = 0;//总商品费用(不含运费)
... ... @@ -242,6 +311,7 @@ class Cars extends Api
if($value['id'] == $g_value['goods_id']){
$value['price'] = $g_value['price'];//商品价格
$value['goods_number'] = $g_value['goods_number'];//商品数量
$value['style'] = $g_value['style'];//商品款式
$total_price += $g_value['price'] * $g_value['goods_number'];
break;
}
... ...
... ... @@ -56,6 +56,19 @@ class Common
}
/**
* 查找多条数据
* @ApiInternal
*/
public static function selectWhereData($table,$where,$field,$order='id desc'){
$res = Db::name($table)
->where($where)
->field($field)
->order($order)
->select();
return $res;
}
/**
* 查找多条数据(软删除)
* @ApiInternal
*/
... ... @@ -101,6 +114,23 @@ class Common
}
/**
* 查找多条数据(软删除,分页)
* @ApiInternal
*/
public static function selectSoftPageData($table,$field,$page,$limit='',$order='id desc'){
if($limit == ''){
$limit = config('verify.limit');
}
$res = Db::name($table)
->field($field)
->page($page,$limit)
->order($order)
->useSoftDelete('deletetime')
->select();
return $res;
}
/**
* 查找多条数据(软删除,限制条数)
* @ApiInternal
*/
... ... @@ -160,11 +190,17 @@ class Common
* 商品列表
* @ApiInternal
*/
public static function goodsList($where,$page,$limit='',$order='id desc'){
public static function goodsList($where='',$page,$limit='',$order='id desc'){
$arr = [];
$res = Common::selectSoftWherePageData('goods',$where,'id,image,name,tag,new_price,sale_price,expense_price',$page,$limit,$order);
if(empty($where)){
$res = Common::selectSoftPageData('goods','id,image,name,tag,style,new_price,sale_price,expense_price',$page,$limit,$order);
}else{
$res = Common::selectSoftWherePageData('goods',$where,'id,image,name,tag,style,new_price,sale_price,expense_price',$page,$limit,$order);
}
foreach ($res as &$value){
$value['image'] = self::absolutionUrlOne($value['image']);
$value['style'] = explode('|',$value['style']);
$value['tag'] = explode('|',$value['tag']);
}
$arr['data'] = $res;
... ... @@ -243,7 +279,25 @@ class Common
return $result;
}
//支付订单号
/**
* 订单号
* @ApiInternal
*/
public static function genOrderSn() {
$res = Db::name('oattach')->field('id,order_sn')->order('id desc')->find();
if($res){
$order_sn = $res['order_sn'];
$order_sn++;
}else{
$order_sn = '1000001';
}
return $order_sn;
}
/**
* 支付订单号
* @ApiInternal
*/
public static function genPayOrderSn($letter = '') {
$time = explode (" ", microtime ());
$timeArr = explode('.',$time [0]);
... ... @@ -252,42 +306,39 @@ class Common
return $fulltime;
}
//写入订单数据
public static function createOrder($data){
/**
* 写入订单数据
* @ApiInternal
*/
public static function createOrder($data,$pay_order_sn,$uid){
//写入订单主表
$data1['order_sn'] = self::genOrderSn();
$data1['pay_order_sn'] = $pay_order_sn;
$data1['uid'] = $uid;
$data1['receive_name'] = $data['receive_name'];
$data1['receive_mobile'] = $data['receive_mobile'];
$data1['receive_address'] = $data['receive_address'];
if(isset($data['leave_message']) && !empty($data['leave_message'])){
$data1['leave_message'] = $data['leave_message'];//留言
}
if(isset($data['coupon_id']) && !empty($data['coupon_id'])){
$data1['coupon_id'] = $data['coupon_id'];//优惠券id
}
$data1['total_goods_price'] = $data['total_goods_price'];//商品金额
$data1['discount_price'] = $data['discount_price'];//优惠金额
$data1['total_expense_price'] = $data['total_expense_price'];//运费总金额
$data1['total_price'] = $data['total_goods_price'] + $data['total_expense_price'] - $data['discount_price'];//商+运-优惠
//写入订单表
$goods_id_s = explode(',',$data['goods_id']);
$price_s = explode(',',$data['price']);
$goods_number_s = explode(',',$data['goods_number']);
$style_s = explode(',',$data['style']);
//合并数组
$key = ['goods_id','price','goods_number'];
$res_goods = self::array_merge_more($key,$goods_id_s,$price_s,$goods_number_s);
//查询商品
$res = Common::selectSoftWhereData('goods',['id'=>['in',$goods_id_s]],'id,introduce');
$total_price = 0;//总商品费用(不含运费)
$total_expense_price = 0;//总运费
foreach ($res as &$value){
foreach($res_goods as $g_value){
if($value['id'] == $g_value['goods_id']){
$value['price'] = $g_value['price'];//商品价格
$value['goods_number'] = $g_value['goods_number'];//商品数量
$total_price += $g_value['price'] * $g_value['goods_number'];
break;
}
}
$total_expense_price += $value['expense_price'];
unset($value['expense_price']);
}
if($res){
array_pop($res1);
$data['total_time'] = count($res1);//总晚数
$orderModel = new Order();
$res2 = $orderModel->create($data);
if($res2){
$arr['order_id'] = $res2->id;
return $arr;
}
return false;
}
return false;
$key = ['g_id','price','goods_number','style'];
$res_goods = self::array_merge_more($key,$goods_id_s,$price_s,$goods_number_s,$style_s);
return true;
}
}
... ...
... ... @@ -79,7 +79,7 @@ class Goods extends Api
$this->error($validate->getError());
}
$res = Common::findSoftWhereData('goods',['id'=>$goods_id],'type_name,is_design,is_recommend,sort,image,createtime,updatetime,deletetime',true);
$res = Common::findSoftWhereData('goods',['id'=>$goods_id],'type_name,is_design,is_recommend,sort,image,createtime,updatetime,deletetime,flag,hots,sales',true);
if($res){
if($res['file']){
//图片取视频帧
... ... @@ -105,6 +105,10 @@ class Goods extends Api
}else{
$res['b_type'] = '';
}
//浏览商品增加次数
$goodsModel = new \app\admin\model\Goods();
$goodsModel->where(['id'=>$goods_id])->setInc('hots',1);
}
$this->success('成功',$res);
}else{
... ... @@ -212,6 +216,10 @@ class Goods extends Api
"隐秘乡奢",
"家庭情侣"
],
"style": [//商品规格
"主餐匙,茶匙各1件",
"古堡灰"
],
"new_price": 2199,//新人价格(未登录,未购买记录(个人中心返是否有购买记录),显示该字段,另加“新人价”标签)
"sale_price": 2299//销售价格
"expense_price": //运费(0:显示包运费标签)
... ... @@ -250,13 +258,13 @@ class Goods extends Api
$order = 'id desc';
if($hots){
if($hots == 1){
$order = 'hots desc';
$order = 'hots desc,id desc';
}else if($hots == 2){
$order = 'hots asc';
}
}else if($sales){
if($sales == 1){
$order = 'sales desc';
$order = 'sales desc,id desc';
}else if($sales == 2){
$order = 'sales asc';
}
... ...
... ... @@ -189,6 +189,10 @@ class Index extends Api
"隐秘乡奢",
"家庭情侣"
],
"style": [//商品规格
"主餐匙,茶匙各1件",
"古堡灰"
],
"new_price": 2199,//新人价格(未登录,未购买记录(个人中心返是否有购买记录),显示该字段,另加“新人价”标签)
"sale_price": 2299//销售价格
"expense_price": //运费(0:显示包运费标签)
... ...
... ... @@ -42,6 +42,10 @@ class News extends Api
"隐秘乡奢",
"家庭情侣"
],
"style": [//商品规格
"主餐匙,茶匙各1件",
"古堡灰"
],
"new_price": 2199,//新人价格(未登录,未购买记录(个人中心返是否有购买记录),显示该字段,另加“新人价”标签)
"sale_price": 2299//销售价格
"expense_price": //运费(0:显示包运费标签)
... ...
... ... @@ -4,20 +4,14 @@ namespace app\api\controller;
use app\common\controller\Api;
use EasyWeChat\Factory;
use function GuzzleHttp\Promise\inspect;
use think\Db;
use app\admin\model\User;
use think\Log;
use fast\Http;
use think\Validate;
use Exception;
use function EasyWeChat\Kernel\Support\generate_sign;
/**
* 支付接口
*/
class Pay extends Api
{
protected $noNeedLogin = ['payMemberNotify','paySecurityNotify','payOrderNotify'];
protected $noNeedLogin = ['payOrderNotify','purchaseNotify'];
protected $noNeedRight = ['*'];
protected $uid = '';//token存贮uid
protected $order_status = [];//订单状态
... ... @@ -25,6 +19,7 @@ class Pay extends Api
{
parent::_initialize();
$this->uid = $this->auth->getUserId();
$this->order_status = config('verify.status');
}
/**
... ... @@ -32,64 +27,39 @@ class Pay extends Api
* @ApiSummary (支付订单)
* @ApiMethod (POST)
* @ApiRoute (/api/pay/pay)
* @ApiInternal
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="openid", type="string", required=true, description="小程序openid")
* @ApiParams (name="order_sn", type="inter", required=false, description="支付订单号")
* @ApiParams (name="pay_order_sn", type="inter", required=true, description="支付订单号")
*
*/
public function pay(){
if($this->request->isPost()){
$openid = $this->request->post('openid');
$order_sn = $this->request->post('order_sn');
$pay_order_sn = $this->request->post('pay_order_sn');
$rule = config('verify.pay_member');
$rule = config('verify.pay');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['openid'=>$openid])) {
if (!$validate->check(['openid'=>$openid,'pay_order_sn'=>$pay_order_sn])) {
$this->error($validate->getError());
}
$hotel_url = config('verify.hotel_url');
if($order_sn){
//支付订单
$res = Db::name('order')->where(['order_sn'=>$order_sn,'uid'=>$this->uid])->find();
if($res){
if($res['status'] == 0){
//判断该房间是否已被预订
$res2 = $this->auth->getHouseDetailId(['house_id'=>$res['house_id']]);
$full_time = [];
foreach($res2 as $r_value){
if($res['book_count'] <= $r_value['book_count']){
//满房时间
array_push($full_time,$r_value['book_time']);
}
}
if(in_array($res['start_time'],$full_time)){
$this->error('该房屋已被预订');
}
$pay_order = $order_sn;
$notify_url = $hotel_url.'/api/pay/payOrderNotify';
$total_fee = $res['security_price'];
}else{
$this->error('该订单已支付过了');
}
}else{
$this->error('无效的订单');
}
}else{
//购买会员
$pay_order = $this->auth->genPayOrderSn('pay');//支付订单号
$notify_url = $hotel_url.'/api/pay/payMemberNotify';
$total_fee = 0.01;//会员价格暂为0.01元
$ffg_host = config('verify.ffg_host');
$status = $this->order_status;
//支付订单
$res = Common::findSoftWhereData('order',['uid'=>$this->uid,'pay_order_sn'=>$pay_order_sn,'status'=>$status[0]],'id,total_price');
if(!$res){
$this->error('无效的订单');
}
//创建支付对象
$config = config('verify.wx_pay');
$app = Factory::payment($config);
$result = $app->order->unify([
'body' => '佛山市理想中网络科技有限公司',
'out_trade_no' => $pay_order,//支付订单号
'total_fee' => $total_fee*100,//单位分
'notify_url' => $notify_url, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'out_trade_no' => $pay_order_sn,//支付订单号
'total_fee' => $res['total_price']*100,//单位分
'notify_url' => $ffg_host.'/api/pay/payOrderNotify', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
'openid' => $openid,
]);
... ... @@ -111,29 +81,10 @@ class Pay extends Api
}
}
//购买会员回调通知(无需调用)
public function payMemberNotify(){
$config = config('verify.wx_pay');
$app = Factory::payment($config);
$response = $app->handlePaidNotify(function($message, $fail){
//return_code 表示通信状态
Log::info($message);
if ($message['return_code'] === 'SUCCESS') {
if ($message['result_code'] === 'SUCCESS') {
}elseif($message['result_code'] === 'FAIL') {
//支付失败
}
} else {
return $fail('通信失败,请稍后再通知我');
}
return true; // 返回处理完成
});
$response->send();
}
//支付订单(无需调用)
/**
* 支付订单回调
* @ApiInternal
*/
public function payOrderNotify(){
$config = config('verify.wx_pay');
$app = Factory::payment($config);
... ... @@ -160,15 +111,22 @@ class Pay extends Api
* @ApiSummary (立即购买)
* @ApiMethod (POST)
* @ApiRoute (/api/pay/purchase)
* @ApiInternal
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="receive_name", type="string", required=true, description="收货人")
* @ApiParams (name="receive_mobile", type="string", required=true, description="联系方式")
* @ApiParams (name="receive_address", type="string", required=true, description="收货地址")
* @ApiParams (name="openid", type="string", required=true, description="小程序openid")
* @ApiParams (name="goods_id", type="string", required=true, description="商品id(多个以逗号隔开,如:1,3,4)")
* @ApiParams (name="price", type="string", required=true, description="商品价格(多个以逗号隔开,如:100,10,200)")
* @ApiParams (name="goods_number", type="string", required=true, description="商品数量(多个以逗号隔开,如:10,10,10)")
* @ApiParams (name="style", type="string", required=true, description="商品款式(多个以逗号隔开,如:‘款式1,款式2,款式3’)")
* @ApiParams (name="leave_message", type="string", required=false, description="留言")
*
* @ApiParams (name="total_goods_price", type="inter", required=true, description="商品总金额")
* @ApiParams (name="discount_price", type="inter", required=true, description="优惠金额")
* @ApiParams (name="total_price", type="inter", required=true, description="总金额")
* @ApiParams (name="total_expense_price", type="inter", required=true, description="运费总金额")
*/
public function purchase(){
if($this->request->isPost()){
... ... @@ -183,13 +141,13 @@ class Pay extends Api
//创建支付对象
$config = config('verify.wx_pay');
$app = Factory::payment($config);
$pay_order = Common::genPayOrderSn('pay');//支付订单号
$hotel_url = config('verify.hotel_url');
$pay_order_sn = Common::genPayOrderSn('pay');//支付订单号
$ffg_host = config('verify.ffg_host');
$result = $app->order->unify([
'body' => '佛山市理想中网络科技有限公司',
'out_trade_no' => $pay_order,//支付订单号
'out_trade_no' => $pay_order_sn,//支付订单号
'total_fee' => $data['security_price']*100,//单位分
'notify_url' => $hotel_url.'/api/pay/purchaseNotify', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'notify_url' => $ffg_host.'/api/pay/purchaseNotify', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
'openid' => $data['openid'],
]);
... ... @@ -205,9 +163,9 @@ class Pay extends Api
// 注意这里用的是商户平台的Key进行二次签名
$params['paySign'] = generate_sign($params, $config['key']);
//写入订单
$res = Common::createOrder($data);
$res = Common::createOrder($data,$pay_order_sn,$this->uid);
if($res){
$this->success('成功',['data'=>$params,'order_sn'=>$pay_order,'order_id'=>$res['order_id']]);
$this->success('成功',['data'=>$params,'pay_order_sn'=>$pay_order_sn,'order_id'=>$res['order_id']]);
}
$this->error('创建订单失败');
}
... ... @@ -217,7 +175,10 @@ class Pay extends Api
}
}
//立即购买回调(无需调用)
/**
* 立即购买回调
* @ApiInternal
*/
public function purchaseNotify(){
$config = config('verify.wx_pay');
$app = Factory::payment($config);
... ... @@ -243,6 +204,8 @@ class Pay extends Api
* @ApiSummary (更新订单号(支付订单失败后调用))
* @ApiMethod (POST)
* @ApiRoute (/api/pay/updateOrder)
* @ApiInternal
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="order_sn", type="inter", required=false, description="支付订单号")
... ... @@ -265,7 +228,7 @@ class Pay extends Api
}
$orderModel = new \app\admin\model\Order();
$pay_order = $this->auth->genPayOrderSn('pay');//支付订单号
$pay_order = Common::genPayOrderSn('pay');//支付订单号
$res = $orderModel->where(['order_sn'=>$order_sn,'uid'=>$this->uid])->update(['order_sn'=>$pay_order]);
if($res){
$this->success('成功');
... ...
... ... @@ -44,6 +44,10 @@ class Search extends Api
"隐秘乡奢",
"家庭情侣"
],
"style": [//商品规格
"主餐匙,茶匙各1件",
"古堡灰"
],
"new_price": 2199,//新人价格(未登录,未购买记录(个人中心返是否有购买记录),显示该字段,另加“新人价”标签)
"sale_price": 2299//销售价格
"expense_price": //运费(0:显示包运费标签)
... ...
... ... @@ -2,6 +2,7 @@
namespace app\api\controller;
use app\admin\model\Collection;
use app\common\controller\Api;
use fast\Http;
use think\Validate;
... ... @@ -86,4 +87,236 @@ class User extends Api
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (获取个人信息(新人/旧人))
* @ApiSummary (获取个人信息(新人/旧人))
* @ApiMethod (GET)
* @ApiRoute (/api/user/info)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1575188985",
"data": {
"id": 2,//用户id
"openid": "orhy25PeYJsTeN70aoTL_Hvfvz20",//openid
"nickname": "风起时",//昵称
"mobile": "",
"avatar": "",//头像
"token": "2794e6d4-14d5-4725-ba79-8b863d3ef8c6",//token
"user_id": 2,
"createtime": 1574927973,
"expiretime": 1577519973,
"expires_in": 2330988,
"is_news": 0//是否为新人(0:是,1:否)
}
})
*/
public function info(){
if($this->request->isGet()){
$data = $this->auth->getUserinfo();
if($data){
$res = Common::findSoftWhereData('order',['uid'=>$data['id'],'status'=>config('verify.status')[3]],'id');
if($res){
$data['is_news'] = 1;//旧人
}else{
$data['is_news'] = 0;//新人
}
}
$this->success('成功', $data);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (获取二维码)
* @ApiSummary (获取二维码)
* @ApiMethod (GET)
* @ApiRoute (/api/user/getWxCode)
*
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1572602867",
"data": {
"code_url": "http://hotel.w.brotop.cnwx_code_img/code_6.jpg"//二维码路径
}
})
*/
public function getWxCode(){
if($this->request->isGet()){
//获取access_token
$config = config('verify.raw');
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$config['app_id'].'&secret='.$config['secret'];
$res = $this->auth->http_get($url);
$json_arr = json_decode($res,true);
if(!isset($json_arr['access_token'])&&empty($json_arr['access_token'])){
//用户登录
$this->error('失败');
}
$access_token = $json_arr['access_token'];
//获取二维码链接
$get_code_url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$access_token;
$data = [
'scene' => 'share_uid='.$this->uid,
'width' => 280,
// 'page' => 'pages/lixiangzhong/lixiangzhong',
];
$data = json_encode($data);
$code_res = $this->auth->http_post($get_code_url,$data);
file_put_contents('wx_code_img/code_'.$this->uid.'.jpg',$code_res);
$code_url = config('verify.hotel_url').'/wx_code_img/code_'.$this->uid.'.jpg';
$this->success('成功', ['code_url'=>$code_url]);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (收藏)
* @ApiSummary (收藏)
* @ApiMethod (POST)
* @ApiRoute (/api/user/collection)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="goods_id", type="inter", required=true, description="商品id")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571037179",
"data": null
})
*/
public function collection(){
if($this->request->isPost()){
$goods_id = $this->request->post('goods_id');
$rule = config('verify.goods_detail');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['goods_id'=>$goods_id])) {
$this->error($validate->getError());
}
$collectionModel = new Collection();
$res1 = Common::findWhereData('collection',['uid'=>$this->uid,'g_id'=>$goods_id],'id');
if($res1){
$this->error('已经收藏过了');
}else{
$res = $collectionModel->create(['g_id'=>$goods_id,'uid'=>$this->uid]);
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (取消收藏)
* @ApiSummary (取消收藏)
* @ApiMethod (POST)
* @ApiRoute (/api/user/cancelCollection)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="goods_id", type="inter", required=true, description="商品id")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571037179",
"data": null
})
*/
public function cancelCollection(){
if($this->request->isPost()){
$goods_id = $this->request->post('goods_id');
$rule = config('verify.goods_detail');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['goods_id'=>$goods_id])) {
$this->error($validate->getError());
}
$collectionModel = new Collection();
$res = $collectionModel->where(['uid'=>$this->uid,'g_id'=>$goods_id])->delete();
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (我的收藏)
* @ApiSummary (我的收藏)
* @ApiMethod (GET)
* @ApiRoute (/api/user/myCollectionList)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="page", type="inter", required=true, description="分页页码")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1574941706",
"data": {
"data": [
{
"id": 7,//商品id
"image": "http://jinglong.springchunjia.cn/uploads/20191128/8a677f5a0418059bf1b974c50026af13.png",//图片路径
"name": "MONENT 动感系列",//商品名称
"tag": [//商品标签
"日式简约",
"隐秘乡奢",
"家庭情侣"
],
"style": [//商品规格
"主餐匙,茶匙各1件",
"古堡灰"
],
"new_price": 2199,//新人价格(未登录,未购买记录(个人中心返是否有购买记录),显示该字段,另加“新人价”标签)
"sale_price": 2299//销售价格
"expense_price": //运费(0:显示包运费标签)
},
{
"id": 4,
"image": "http://jinglong.springchunjia.cn/uploads/20191128/93971e55b83d1a09c1831f8197514305.png",
"name": "MONENT 动感系列",
"tag": [
"AB级",
"ABX级",
"ABN级"
],
"new_price": 2499,
"sale_price": 2599
},
],
"total_page": 1
}
})
*/
public function myCollectionList(){
if($this->request->isGet()){
$page = $this->request->get('page');
$rule = config('verify.page');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page])) {
$this->error($validate->getError());
}
$res = Common::selectWhereData('collection',['uid'=>$this->uid],'id,g_id');
$goods_ids = array_column($res,'g_id');
$res1 = Common::goodsList(['id'=>['in',$goods_ids]],$page);
$this->success('成功',$res1);
}else{
$this->error('请求方式错误');
}
}
}
... ...
... ... @@ -619,4 +619,35 @@ class Auth
return $url;
}
//curl get请求
public function http_get($url){
$curl = curl_init();//启动一个CURL会话
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, false);//不开启header
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
$result = curl_exec($curl); //执行操作
curl_close($curl);
return $result;
}
//curl post请求
public function http_post($url,$data){
$curl = curl_init();//启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, false); // 开启header
// curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);//请求头部
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
$result = curl_exec($curl); //执行操作
curl_close($curl);
return $result;
}
}
... ...
... ... @@ -19,8 +19,12 @@ return [
],
//七牛云域名
'host' => 'http://jinglong.springchunjia.cn',
//非凡谷域名
'ffg_host' => 'http://feifangu.w.brotop.cn',
//商品标识
'flag' => [0,1,2,3],//0:普通,1:推荐,2:设计师作品,3:新人特惠
//订单状态
'status' => [0,1,2,3],//0:待付款,1:待发货,2:待收货,3:已完成
//分页数
'limit' => 10,
//商品分页
... ... @@ -150,29 +154,56 @@ return [
'goods_id' => 'require',
'price' => 'require',
'goods_number' => 'require',
'style' => 'require',
],
'msg' => [
'goods_id.require' => '商品id不能为空',
'price.require' => '商品价格不能为空',
'goods_number.require' => '商品数量不能为空',
'style.require' => '商品款式不能为空',
]
],
//立即购买
'purchase' => [
'rule' => [
'receive_name' => 'require',
'receive_mobile' => 'require',
'receive_address' => 'require',
'openid' => 'require',
'goods_id' => 'require',
'price' => 'require',
'goods_number' => 'require',
'style' => 'require',
'total_goods_price' => 'require|number',
'discount_price' => 'require|number',
'total_expense_price'=> 'require|number',
],
'msg' => [
'openid.require' => 'openid不能为空',
'goods_id.require' => '商品id不能为空',
'price.require' => '商品价格不能为空',
'goods_number.require' => '商品数量不能为空',
'discount_price.require' => '优惠金额不能为空',
'discount_price.number' => '优惠金额必须为数字',
'receive_name.require' => '收货人不能为空',
'receive_mobile.require' => '联系方式不能为空',
'receive_address.require' => '收货地址不能为空',
'openid.require' => 'openid不能为空',
'goods_id.require' => '商品id不能为空',
'price.require' => '商品价格不能为空',
'goods_number.require' => '商品数量不能为空',
'style.require' => '商品款式不能为空',
'total_goods_price.require' => '商品总金额不能为空',
'total_goods_price.number' => '商品总金额必须为数字',
'discount_price.require' => '优惠金额不能为空',
'discount_price.number' => '优惠金额必须为数字',
'total_expense_price.require' => '运费总金额不能为空',
'total_expense_price.number' => '运费总金额必须为数字',
]
],
//支付订单
'pay' => [
'rule' => [
'openid' => 'require',
'pay_order_sn' => 'require',
],
'msg' => [
'openid.require' => 'openid不能为空',
'pay_order_sn.require' => '支付订单号不能为空',
]
],
];
\ No newline at end of file
... ...
此 diff 太大无法显示。