IndexController.php
3.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
<?php
namespace app\index\controller;
use app\goods\model\GoodsModel;
use cmf\controller\HomeBaseController;
use think\Db;
class IndexController extends HomeBaseController
{
function _initialize()
{
// parent::_initialize(); // TODO: Change the autogenerated stub
// if (cmf_is_wechat()) {
// if (empty(session('user.id'))) {
// require_once EXTEND_PATH . '/WeChatCommon.php';
// $wx = new \WeChatCommon();
// if (request()->param('code') == NULL) {
// $wx->code();
// } else {
// $code = request()->param('code');
// $info = $wx->getOpenid($code);
// if(Db::name('user')->where(['openid'=>$info['openid']])->count() == 0) {
// //注册新用户
// //拉去用户信息
// $return = $wx->getUserInfo($info);
// $data = [
// 'user_type' => 2,
// 'create_time' => time(),
// 'user_nickname' => $return['nickname'],
// 'sex' => $return['sex'],
// 'avatar' => $return['headimgurl'],
// 'openid' => $info['openid']
// ];
// if(Db::name('user')->insert($data)) {
// $userId = Db::name('user')->getLastInsID();
// session('user.id', $userId);
// session('user.openid', $info['openid']);
// }
// }else {
// $userId = Db::name('user')->where(['openid'=>$info['openid']])->value('id');
// session('user.id', $userId);
// session('user.openid', $info['openid']);
// }
// }
// }
// }else {
// $this->error('请从微信浏览器打开');
// }
}
public function index()
{
$goods = new GoodsModel;
$goodsList = $goods->getGoods(2);
$id=[];
foreach ($goodsList as $k=>$v){
$id[$k]=$v['id'];
}
$num=Db::name('zj_evaluate')->where(['delete_time'=>'0','is_sta'=>'2','gid'=>['in',$id]])->group('gid')
->field("count('gid') as num,gid")->select()->toArray();
foreach ($goodsList as $k=>$v){
if(!empty($num)) {
foreach ($num as $val) {
if ($v['id'] == $val['gid']) {
$goodsList[$k]['eva'] = $val['num'];
break;
} else {
$goodsList[$k]['eva'] = 0;
}
}
}else {
$goodsList[$k]['eva'] = 0;
}
}
$notice=Db::name('zj_news')->where(['delete_time'=>0,'is_sta'=>1])->find();
$return = [
'notice' => $notice,
'banner' => getBanner(),
'goodsList' => $goodsList
];
return $this->fetch('', [
'data' => $return
]);
}
/**
* 易连云打印机demo
*/
public function demo()
{
//调用打印机
//1.配置信息
$config = [
'partner' => '27606',
'machine_code' => '4004564414',
'apiKey' => '1580c3fc2adca994e18b0982b42af850518011d0',
'msign' => '6kdjyzsr4sf3'
];
//2.打印内容(以一行三列的表格为例,内容不允许出现回车换行,切记!)
$content = '<table><tr><td>银河百荣科技</td><td>demo</td><td>By Soul of Cinder</td></tr></table>';
printer($config, $content);
}
}