1], [['limit'], 'default', 'value' => 20], ]; } public function search() { if (!$this->validate()) { return $this->getModelError(); } $query = DevList::find()->alias('dev') ->join('left join', ['store' => Store::tableName()], 'dev.store_id = store.id') ->where([ 'dev.is_delete' => 0 ])->andFilterWhere([ 'dev.store_id' => $this->store_id ]); $query->select('dev.*,store.name as store_name'); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['created_at' => SORT_DESC])->asArray()->all(); foreach ($list as $index => $item) { $item['address'] = $item['province'] . $item['city'] . $item['district'] . $item['address']; $item['online_status_cn'] = $item['online_status'] == 1 ? '在线' : '离线'; $body_arr = [ 'path' => "pages/index/scanPage?type=yp&sn={$item['dev_id']}", ]; $md5 = md5(json_encode($body_arr)); if(!file_exists(\Yii::$app->basePath.'/web/upload/devcode')){ // 创建目录 @mkdir(\Yii::$app->basePath.'/web/upload/devcode'); } if(!is_file(\Yii::$app->basePath.'/web/upload/devcode/'.$md5.'.png')){ // 生成二维码 $qr_res = $this->wxmpQrcode($body_arr); $res = file_put_contents(\Yii::$app->basePath.'/web/upload/devcode/'.$md5.'.png',$qr_res); } $file_name = \Yii::$app->basePath.'/web/upload/'; $item['qr_img'] = "/upload/devcode/{$md5}.png"; $list[$index] = $item; } $data = []; $data['code'] = 0; $data['msg'] = 'ok'; $data['data'] = $list; $data['count'] = $count; return $data; } //获取小程序二维码 public function wxmpQrcode($body) { $plugin = new \app\models\common\PluginService(); $wxmpService = $plugin->getWxmpService(0); $accessToken = $wxmpService->getAccessToken(); if (empty($accessToken)) { $accessToken = $wxmpService->getAccessToken(true); } $body = json_encode($body); return $wxmpService->Qrcode->getWxappQrcodeLong($accessToken, $body); } }