attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->index()); } //立即抽奖 public function actionLottery() { $form = new PondForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); $data = $form->lottery(); return $this->asJson($data); } //中奖记录 public function actionPrize() { $form = new PondLogForm(); $form->page = get_params('page'); $form->limit = 10; $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->search()); } public function actionDel() { $form = new PondLogForm(); $form->id = get_params('id'); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->del()); } //海报 public function actionQrcode() { $saas_user_id = get_saas_user_id(); $scene = "{$saas_user_id}"; if (is_wechat_platform()) { $res = ShareQrcode::wxQrcode('md_admin/md-center/self-mention', $scene); if (isset($res['code']) && $res['code'] == 1) { return $this->asJson([ 'code' => 1, 'msg' => $res['response']['errmsg'], ]); } } elseif (is_alipay_platform()) { $res = ShareQrcode::getAlipayQrcode('md_admin/md-center/self-mention', $scene); if (empty($res['code']) || $res['code'] != 10000) { return $this->asJson($res); } $res['url_path'] = $res['qr_code_url_circle_blue']; } else { $file_name = md5('md_admin/md-center/self-mention' . $scene.get_store_id()); // 保存小程序码到文件 $dir = \Yii::$app->runtimePath . '/image/wx_qrcode'; if (! is_dir($dir)) { mkdir($dir, 0777, true); } $url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/wx_qrcode/' . $file_name); QrCode::image(\Yii::$app->request->hostInfo . '/h5/#/md_admin/md-center/self-mention', 600, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $dir. '/' .$file_name . '.jpg'); $res = [ 'code' => 0, 'root_path' => $dir . '/' . $file_name . '.jpg', 'url_path' => $url . '.jpg', ]; } $level = User::findOne(get_user_id())->level; $level_name = Level::findOne(['level' => $level])->name; $id = sprintf("%011d", get_user_id()); $generator = new BarcodeGeneratorJPG(); $barcode = $generator->getBarcode($id, $generator::TYPE_CODE_128, 2, 30); $filename = md5('user_clerk_' . $id); $code_path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg'; $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg'); file_put_contents($code_path, $barcode); // $barcode = base64_encode($barcode); return $this->asJson([ 'code' => 0, 'data' => [ 'qr_url' => $res['url_path'], 'name' => get_saas_user()->name, 'avatar' => get_saas_user()->avatar, 'level_name' => $level_name ?: '普通用户', 'code_path' => $pic_url ] ]); } }