Coupon.php
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
/**
* 首页接口
*/
class Coupon extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
protected $postParam;
protected $store_id;
protected $store;
public function _initialize()
{
$postParam = $this->request->param();
$this->postParam = $postParam;
parent::_initialize();
$this->auth->id = 1;//测试用
$postParam = $this->request->param();
$this->postParam = $postParam;
if (empty($postParam['code'])) {
$this->error("门店code异常");
}
$this->store_id = $postParam['code'];
$store = Db::name("verification_store")->where("id", $this->store_id)->find();
if (empty($store)) {
$this->error("门店不存在,请退出登录后重试!");
}
$this->store = $store;
}
/**
* 首页
*
*/
public function index()
{
$this->success('请求成功');
}
/**
* 1、获取活动
*/
public function getactivity(){
//根据门店查询活动
$time=time();
$where["closetime"] = [">", $time];
$where["verification_store_id"] = ["=", $this->store_id];
$activity=Db::name('verification_activity')->where($where)->find();
$this->success('活动获取成功', $activity);
}
/**
* 2、创建订单
*/
public function crateorder(){
$time=time();
$verification_activity_id=$this->postParam['verification_activity_id'];
//查询到活动
$where["id"] = ["=", $verification_activity_id];
$activity=Db::name('verification_activity')->where($where)->find();
//判断活动是否到期
if(!empty($activity)){
if($activity['closetime']<=$time){
$this->error("活动已过期!");
}
}else{
$this->error("活动不存在!");
}
$phone=$this->postParam['phone'];
$name=$this->postParam['name'];
$verification_coupon_ids=$activity['verification_coupon_ids'];
$order_no=$time.rand(10000,99999);
$verification_store_id=$this->store_id;
$user_id=$this->auth->id;
$createtime=$time;
$type=0;
//整理数组
$data=[
'order_no'=>$order_no,
'verification_store_id'=>$verification_store_id,
'user_id'=>$user_id,
'createtime'=>$createtime,
'type'=>$type,
'verification_coupon_ids'=>$verification_coupon_ids,
'verification_activity_id'=>$verification_activity_id,
'name'=>$name,
'phone'=>$phone
];
//插入订单表
$res=Db::name('verification_order')->insertGetId($data);
if($res){
$this->success('添加订单成功');
}else{
$this->error("添加订单失败!");
}
}
/**
*3、获取订单
*/
public function getorder(){
$type=$this->postParam['type'];
}
}