正在显示
1 个修改的文件
包含
202 行增加
和
7 行删除
@@ -15,6 +15,122 @@ use think\Db; | @@ -15,6 +15,122 @@ use think\Db; | ||
15 | 15 | ||
16 | class TestController extends HomeBaseController | 16 | class TestController extends HomeBaseController |
17 | { | 17 | { |
18 | + | ||
19 | + public function prob() | ||
20 | + { | ||
21 | + $uid = 451; | ||
22 | + $user = Db::name('user')->where('id',$uid)->find(); | ||
23 | + $indent = Db::name('indent')->where('salesman_uid',$uid)->order('create_time','desc')->select(); | ||
24 | + $arr = collection($indent)->toArray(); | ||
25 | + $data = []; | ||
26 | + $state_arr = [ | ||
27 | + 4 => '待付款', | ||
28 | + 2 => '待发货', | ||
29 | + 3 => '已完成', | ||
30 | + 5 => '已发货', | ||
31 | + 6 => '待取货' | ||
32 | + ]; | ||
33 | + foreach ($arr as &$v) { | ||
34 | + $money = Db::name('money_income')->where('uid',$uid)->where('indent_id',$v['id'])->value('money'); | ||
35 | + $fact_money = Db::name('money_income')->where('uid',$uid)->where('indent_id',$v['id'])->sum('money'); | ||
36 | +// $income = Db::name('money_income')->where('uid',$uid)->where('indent_id',$v['id'])->select(); | ||
37 | +// $v['income'] = collection($income)->toArray(); | ||
38 | + | ||
39 | +// $data[] = [ | ||
40 | +// 'id' => $v['id'], | ||
41 | +// 'money' => $money, | ||
42 | +// 'number' => $v['book_num'], | ||
43 | +// 'name' => $v['name'], | ||
44 | +// 'phone' => $v['phone'], | ||
45 | +// 'school' => $v['school'].'-'.$v['grade'].$v['class'], | ||
46 | +// 'state' => $state_arr[$v['state']], | ||
47 | +// 'create_time' => date('Y-m-d H:i:s',$v['create_time']), | ||
48 | +// 'pay_time' => date('Y-m-d H:i:s',$v['pay_time']), | ||
49 | +// 'region' => $v['region'], | ||
50 | +// 'beiyong_address' => $v['beiyong_address'], | ||
51 | +// 'award' => $money, | ||
52 | +// 'fact_award' => $fact_money, | ||
53 | +// 'is_error' => $fact_money != $money ? '是' : '否' | ||
54 | +// ]; | ||
55 | + $data[] = [ | ||
56 | + $v['id'], | ||
57 | + $money, | ||
58 | + $v['book_num'], | ||
59 | + $v['name'], | ||
60 | + $v['phone'], | ||
61 | + $v['school'].'-'.$v['grade'].$v['class'], | ||
62 | + $state_arr[$v['state']], | ||
63 | + date('Y-m-d H:i:s',$v['create_time']), | ||
64 | + date('Y-m-d H:i:s',$v['pay_time']), | ||
65 | + $v['region'], | ||
66 | + $v['beiyong_address'], | ||
67 | + $money, | ||
68 | + $fact_money, | ||
69 | + $fact_money != $money ? '是' : '否' | ||
70 | + ]; | ||
71 | + } | ||
72 | + $this->excel($user,$data); | ||
73 | + print_r($arr);exit; | ||
74 | + } | ||
75 | + | ||
76 | + | ||
77 | + /** | ||
78 | + * | ||
79 | + * 导出Excel | ||
80 | + */ | ||
81 | + public function excel($user,$data2) | ||
82 | + { | ||
83 | + //引入PHPExcel库文件 | ||
84 | +// Vendor('phpexcel2.PHPExcel'); | ||
85 | + //创建对象 | ||
86 | + $excel = new \PHPExcel(); | ||
87 | + //Excel表格式,这里简略写了8列 | ||
88 | + $letter = array('A', 'B', 'C', 'D', 'E', 'F', 'F', 'G','H','I','J','k','L','M','N'); | ||
89 | + $excel->getActiveSheet()->setCellValue("A1", "业务员名称"); | ||
90 | + $excel->getActiveSheet()->setCellValue("B1", $user['user_nickname']); | ||
91 | + //表头数组 | ||
92 | + $tableheader = array('订单号', '价钱', '数量', '姓名', '电话', '学校-班级', '订单状态', '创建时间', '支付时间', '配送时间', '地区', '备用地址', | ||
93 | + '应得收益', '实际收益', '是否异常'); | ||
94 | + //填充表头信息 | ||
95 | + for ($i = 1; $i < count($tableheader) + 1; $i++) { | ||
96 | + $excel->getActiveSheet()->setCellValue("$letter[$i]2", "$tableheader[$i]"); | ||
97 | + } | ||
98 | + //表格数组 | ||
99 | + $data = array( | ||
100 | + array('1', 'B', 'C', 'D', 'E', 'F', 'G'), | ||
101 | + array('2', 'B', 'C', 'D', 'E', 'F', 'G'), | ||
102 | + array('3', 'B', 'C', 'D', 'E', 'F', 'G'), | ||
103 | + array('4', 'B', 'C', 'D', 'E', 'F', 'G'), | ||
104 | + array('5', 'B', 'C', 'D', 'E', 'F', 'G'), | ||
105 | + array('6', 'B', 'C', 'D', 'E', 'F', 'G'), | ||
106 | + array('7', 'B', 'C', 'D', 'E', 'F', 'G'), | ||
107 | + ); | ||
108 | +// $tz = Db::name('taizhang'); | ||
109 | +// $data2 = $tz->field('type',true)->select(); | ||
110 | + //print_r($data2);exit(); | ||
111 | + //填充表格信息 | ||
112 | + for ($i = 3; $i <= count($data2) + 1; $i++) { | ||
113 | + $j = 0; | ||
114 | + foreach ($data2[$i - 2] as $key => $value) { | ||
115 | + $excel->getActiveSheet()->setCellValue("$letter[$j]$i", "$value"); | ||
116 | + $j++; | ||
117 | + } | ||
118 | + } | ||
119 | + //创建Excel输入对象 | ||
120 | + $write = new \PHPExcel_Writer_Excel2007($excel); | ||
121 | + header("Pragma: public"); | ||
122 | + header("Expires: 0"); | ||
123 | + header("Cache-Control:must-revalidate, post-check=0, pre-check=0"); | ||
124 | + header("Content-Type:application/force-download"); | ||
125 | + header("Content-Type:application/vnd.ms-execl"); | ||
126 | + header("Content-Type:application/octet-stream"); | ||
127 | + header("Content-Type:application/download");; | ||
128 | + header('Content-Disposition:attachment;filename="信息系统表.xlsx"'); | ||
129 | + header("Content-Transfer-Encoding:binary"); | ||
130 | + $write->save('php://output'); | ||
131 | + } | ||
132 | + | ||
133 | + | ||
18 | /** | 134 | /** |
19 | * 恢复父级id | 135 | * 恢复父级id |
20 | * @throws \think\Exception | 136 | * @throws \think\Exception |
@@ -24,14 +140,93 @@ class TestController extends HomeBaseController | @@ -24,14 +140,93 @@ class TestController extends HomeBaseController | ||
24 | * @throws \think\exception\PDOException | 140 | * @throws \think\exception\PDOException |
25 | */ | 141 | */ |
26 | public function test(){ | 142 | public function test(){ |
27 | - $uids = Db::name('indent_over')->group('uid')->column('uid'); | ||
28 | - $indent = Db::name('indent')->whereIn('salesman_uid',$uids)->select(); | ||
29 | - $insert = []; | ||
30 | - foreach ($indent as $v) { | ||
31 | - unset($v['id']); | ||
32 | - $insert[] = $v; | 143 | + ini_set('max_execution_time', 3600);//秒为单位,自己根据需要定义 |
144 | + ini_set('memory_limit','-1'); | ||
145 | +// $b = Db::name('indent_pro')->where('salesman_uid',309)->update(['is_out'=>0]); | ||
146 | + $page = $this->request->param('page',1); | ||
147 | + $uid = Db::name('indent_pro')->where('is_out',0)->group('salesman_uid')->order('salesman_uid','desc')->value('salesman_uid'); | ||
148 | + if(!$uid) { | ||
149 | + echo 123;exit; | ||
33 | } | 150 | } |
34 | - Db::name('indent_pro')->insertAll($insert); | 151 | +// print_r($uid);exit; |
152 | + $list = Db::name('indent_pro')->where('salesman_uid',$uid)->paginate(50,true,['page'=>$page]); | ||
153 | + $list = $list->items(); | ||
154 | + $state_arr = ['2'=>'待发货','3'=>'已完成','5'=>'已发货','6'=>'待收货']; | ||
155 | + $i = []; | ||
156 | + foreach ($list as $v) { | ||
157 | + $order = Db::name('indent')->where('salesman_uid',$v['salesman_uid'])->where('order_number',$v['order_number']) | ||
158 | + ->whereIn('state',['2','3','5','6'])->find(); | ||
159 | + if(!$order) continue; | ||
160 | + $school_class = $v['school'].'-'.$v['grade'].$v['class']; | ||
161 | + $salesman_name = Db::name('user')->where('id',$v['salesman_uid'])->value('user_nickname'); | ||
162 | + $award = Db::name('money_income')->where('indent_id',$order['id'])->where('uid',$order['salesman_uid'])->value('money'); | ||
163 | + if($award) { | ||
164 | + $award_fac = Db::name('money_income')->where('indent_id',$order['id'])->where('uid',$order['salesman_uid'])->sum('money'); | ||
165 | + $i[] = [ | ||
166 | + 'state_text' => $state_arr[$order['state']], | ||
167 | + 'order_number' => $order['order_number'], | ||
168 | + 'money' => $order['money'], | ||
169 | + 'create_time' => date('Y-m-d H:i:s',$order['create_time']), | ||
170 | + 'book_num' => $order['book_num'], | ||
171 | + 'leave_word' => $order['leave_word'], | ||
172 | + 'name' => $order['name'], | ||
173 | + 'phone' => $order['phone'], | ||
174 | + 'school_class' => $school_class, | ||
175 | + 'salesman_name' => $salesman_name, | ||
176 | + 'pay_time' => date('Y-m-d H:i:s',$order['pay_time']), | ||
177 | + 'start_time' => $order['start_time'], | ||
178 | + 'end_time' => $order['end_time'], | ||
179 | + 'region' => $order['region'], | ||
180 | + 'beiyong_address' => $order['beiyong_address'], | ||
181 | + 'award' => $award, | ||
182 | + 'award_fac' => $award_fac, | ||
183 | + 'is_pro' => $award_fac > $award ? '是' : '否' | ||
184 | + ]; | ||
185 | + } | ||
186 | + } | ||
187 | + $b = true; | ||
188 | + Db::startTrans(); | ||
189 | + if(count($i) == 0) { | ||
190 | + Db::name('indent_pro')->where('salesman_uid',$uid)->update(['is_out'=>1]); | ||
191 | + $page = 0; | ||
192 | + } else { | ||
193 | + $a = Db::name('indent_orders')->insertAll($i); | ||
194 | + if(count($i) < 50) { | ||
195 | + $b = Db::name('indent_pro')->where('salesman_uid',$uid)->update(['is_out'=>1]); | ||
196 | + $page = 0; | ||
197 | + } | ||
198 | + if(!$a || !$b) Db::rollback(); | ||
199 | + } | ||
200 | + Db::commit(); | ||
201 | + $page = $page + 1; | ||
202 | + sleep(1); | ||
203 | + $this->redirect(url('portal/test/test',['page'=>$page],true,true)); | ||
204 | +// $sql = Db::name('indent_pro')->getLastSql(); | ||
205 | +// print_r($sql); | ||
206 | +// print_r($uid);exit; | ||
207 | +// $page = $this->request->param('page',1,'intval'); | ||
208 | +// $num = 2000; | ||
209 | +//// $arr = [267,295,309]; | ||
210 | +// $uid = Db::name('indent_over')->where('status',0) | ||
211 | +//// ->whereNotIn('uid',$arr) | ||
212 | +// ->group('uid')->value('uid'); | ||
213 | +//// print_r($uid);exit; | ||
214 | +// $list = Db::name('indent')->whereIn('salesman_uid',$uid)->paginate($num,true,['page'=>$page]); | ||
215 | +// $indent = $list->items(); | ||
216 | +// $insert = []; | ||
217 | +// foreach ($indent as $v) { | ||
218 | +// unset($v['id']); | ||
219 | +// $insert[] = $v; | ||
220 | +// } | ||
221 | +// $res = $res2 = true; | ||
222 | +// Db::startTrans(); | ||
223 | +// if(count($indent) == 0) { | ||
224 | +// $res2 = Db::name('indent_over')->where('uid',$uid)->update(['status'=>1]); | ||
225 | +// } else { | ||
226 | +// $res = Db::name('indent_pro')->insertAll($insert); | ||
227 | +// } | ||
228 | +// if(!$res || !$res2) Db::rollback(); | ||
229 | +// Db::commit(); | ||
35 | // $all = Db::name('indent_over')->select(); | 230 | // $all = Db::name('indent_over')->select(); |
36 | // foreach ($all as $v) { | 231 | // foreach ($all as $v) { |
37 | // $indent = Db::name('indent')->where('id',$v['indent_id'])->where('book_num',2)->count(); | 232 | // $indent = Db::name('indent')->where('id',$v['indent_id'])->where('book_num',2)->count(); |
-
请 注册 或 登录 后发表评论