PortalController.php
9.7 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
namespace api\portal\controller;
use think\Controller;
use think\Db;
use PHPExcel;
use PHPExcel_IOFactory;
/**
* @title 前台补充
* @description 前台补充接口
*/
class PortalController extends Controller
{
/**
* @title 营销下单
* @description
* @author panhaowen
* @url /portal/portal/marketOrderAdd
* @param name:id type:int require:1 desc:营销id
* @param name:file type:varchar require:1 desc:上传文件
* @param name:money type:int require:1 desc:订单金额
* @method POST
*/
public function marketOrderAdd()
{
$param=$this->request->param();
$user=$this->getUser();
if ($user['money']<$param['money']){
$this->error('账号余额不足');
}
foreach ($param['id'] as $v){
$money=Db::name('market_business')->where('id',$v);
Db::name('market_order')->insert(['market_business_id'=>$v,'create_time'=>time(),'order_sn'=>cmf_get_order_sn(),'more'=>$param['file'],'money'=>$money,'user_id'=>$user['id']]);
}
Db::name('user')->where('id',$user['id'])->setDec('money',$param['money']);
Db::name('money_log')->insert(['type'=>3,'create_time'=>time(),'user_id'=>$user['id'],'money'=>$param['money'],'now_money'=>($user['money']-$param['money'])]);
$this->success('操作成功');
}
/**
* @title 新媒体下单
* @description
* @author panhaowen
* @url /portal/portal/businessOrderAdd
* @param name:business_id type:int require:1 desc:新媒体id
* @param name:count type:varchar require:1 desc:购买数量
* @param name:money type:int require:1 desc:订单金额
* @param name:post_url type:varchar require:0 desc:文章地址
* @param name:more type:varchar require:0 desc:文件上传
* @param name:content type:varchar require:0 desc:备注
* @param name:liuyan type:varchar require:0 desc:留言
* @method POST
*/
public function businessOrderAdd()
{
$param=$this->request->param();
$user=$this->getUser();
if ($user['money']<$param['money']){
$this->error('账号余额不足');
}
$param['create_time']=time();
$param['create_time']=cmf_get_order_sn();
$param['user_id']=$user['id'];
Db::name('business_order')->insert($param);
Db::name('user')->where('id',$user['id'])->setDec('money',$param['money']);
Db::name('money_log')->insert(['type'=>2,'create_time'=>time(),'user_id'=>$user['id'],'money'=>$param['money'],'now_money'=>($user['money']-$param['money'])]);
$this->success('操作成功');
}
/**
* @title 订单列表种类
* @description
* @author panhaowen
* @url /portal/portal/Order
* @method POST
*/
public function Order()
{
$data=Db::name('category')->select();
$this->success('获取信息成功',$data);
}
/**
* @title 营销订单查看(审核中),营销订单修改
* @description
* @author panhaowen
* @url /portal/portal/MarketOrder1
* @method POST
* @param name:id type:int require:1 desc:营销订单id
*/
public function MarketOrder1()
{
$param=$this->request->param();
$data=cmf_get_file_download_url(Db::name('market_order')->where('id',$param['id'])->find()['more']);
$this->success('获取信息成功',$data);
}
/**
* @title 营销订单查看(已发布)
* @description
* @author panhaowen
* @url /portal/portal/MarketOrder2
* @method POST
* @param name:id type:int require:1 desc:营销订单id
*/
public function MarketOrder2()
{
$param=$this->request->param();
$data=Db::name('market_order')->where('id',$param['id'])->find();
if ($data['url']!=null) {
$this->success('获取信息成功', $data['url']);
}
$this->success('获取信息成功', cmf_get_file_download_url($data['remark']));
}
/**
* @title 营销订单重投
* @description
* @author panhaowen
* @url /portal/portal/MarketOrderRe
* @method POST
* @param name:id type:int require:1 desc:营销订单id
* @param name:file type:varchar require:1 desc:文件上传
*/
public function MarketOrderRe()
{
$param=$this->request->param();
$user=$this->getUser();
$order=Db::name('market_order')->where('id',$param['id'])->find();
if ($user['money']<$order['money']){
$this->error('账户余额不足');
}
Db::name('market_order')->insert(['market_business_id'=>$order['market_business_id'],'create_time'=>time(),'order_sn'=>cmf_get_order_sn(),'more'=>$param['file'],'money'=>$order['money'],'user_id'=>$user['id']]);
Db::name('user')->where('id',$user['id'])->setDec('money',$order['money']);
Db::name('money_log')->insert(['type'=>3,'create_time'=>time(),'user_id'=>$user['id'],'money'=>$order['money'],'now_money'=>($user['money']-$order['money'])]);
$this->success('操作成功');
}
/**
* @title 新媒体订单查看内容
* @description
* @author panhaowen
* @url /portal/portal/BusinessOrder
* @method POST
* @param name:id type:int require:1 desc:新媒体订单id
*/
public function BusinessOrder()
{
$param=$this->request->param();
$data=Db::name('business_order')->where('id',$param['id'])->find();
if ($data['post_url']!=null) {
$this->success('获取信息成功', $data['post_url']);
}
$this->success('获取信息成功', cmf_get_file_download_url($data['remark']));
}
/**
* @title 新媒体订单退款
* @description
* @author panhaowen
* @url /portal/portal/BusinessOrderReturn
* @method POST
* @param name:id type:int require:1 desc:新媒体订单id
*/
public function BusinessOrderReturn()
{
$param=$this->request->param();
$user=$this->getUser();
$order=Db::name('business_order')->where('id',$param['id'])->find();
Db::name('business_order')->where('id',$param['id'])->update(['status'=>3]);
Db::name('user')->where('id',$user)->setInc('money',$order['money']);
Db::name('money_log')->insert(['create_time'=>time(),'user_id'=>$user['id'],'money'=>$order['money'],'now_money'=>$user['money']+$order['money'],'type'=>5]);
$this->success('操作成功');
}
/**
* @title excel表格导出
* @description
* @author panhaowen
* @url /portal/portal/excel
* @method POST
* @param name:market_id type:int require:1 desc:营销分类id
* @param name:param type:varchar require:1 desc:筛选参数
* @param name:plant type:varchar require:1 desc:筛选参数
* @param name:media type:varchar require:1 desc:筛选参数
*/
//导出数据
public function excel()
{
$param=$this->request->param();
$market=Db::name('market')->where('id',$param['market_id'])->find();
$selected=Db::name('classify')->where('id','in',explode(',',$market['selected']))->select()->toArray();
$where=[];
$where['market_id']=$param['market_id'];
foreach ($selected as $v){
if (!empty($param[$v['field']])){
$where[$v['field']]=$param[$v['field']];
}
}
// $this->success('1',$where);
$list=Db::name('market_business')->where($where)->select()->toArray();
$path = ROOT_PATH . '/public/upload/'; //找到当前脚本所在路径
$PHPExcel = new PHPExcel(); //实例化PHPExcel类,类似于在桌面上新建一个Excel表格
$PHPSheet = $PHPExcel->getActiveSheet(); //获得当前活动sheet的操作对象
$PHPSheet->setTitle('报价表'); //给当前活动sheet设置名称
$type=Db::name('type')->where('id',$market['type'])->find();
$classify=Db::name('classify')->where('id','in',explode(',',$type['classify']))->select()->toArray();
$arr=['B','C','D','E','F','G','H','I','J','K','L','M','N'];
$PHPSheet->setCellValue('A1', 'ID');
foreach ($classify as $k=>$v){
$PHPSheet->setCellValue($arr[$k].'1', $v['name']);
}
// $PHPSheet->setCellValue('A1', 'ID')
// ->setCellValue('B1', '微信名')
// ->setCellValue('C1', '手机号')
// ->setCellValue('D1', '餐谱');
foreach ($list as $k => $v) {
$n = $k + 2;
$PHPSheet->setCellValue("A$n", $v['id']);
foreach ($classify as $k2=>$v2){
$PHPSheet->setCellValue($arr[$k2]."$n", $v[$v2['field']]);
}
// ->setCellValue("B$n", "$v[user_nickname]")
// ->setCellValue("C$n", "$v[mobile]")
// ->setCellValue("D$n", "$v[cook]");
}
$PHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(20);//设置默认宽度
$PHPWriter = PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007');//按照指定格式生成Excel文件,‘Excel2007'表示生成2007版本的xlsx,
$file_name='/'.date('Y-m-d',time()).'表单信息.xlsx';
$PHPWriter->save($path.$file_name); //表示在$path路径下面生成demo.xlsx文件
$filename ='./upload'.$file_name;
ob_end_clean();
$file=cmf_get_file_download_url(date('Y-m-d',time()).'表单信息.xlsx');
header("Location: $file");
//下载文件需要用到的头
// header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// header('Content-Description: File Transfer');
// header('Content-Type: application/octet-stream');
// header('Content-Length: ' . filesize($filename));
// header('Content-Disposition: attachment; filename=' . basename($filename));
// readfile($filename);
exit;
}
}