price = get_params('price'); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $form->search(); } public function actionGetStore() { $store_id = get_store_id(); $store_info = []; if ($store_id > 0) { // TODO: store $store_info = [ 'id' => $store_id, 'name' => Option::get('name', $store_id, 'store')['value'], 'img' => Option::get('web_log', $store_id, 'web')['value'] ]; } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'store_info' => $store_info, ] ]; } /** * 获取收款码 */ public function actionGetQrcode() { $price = get_params('price', 0); $store_id = get_store_id(); // TODO: store_info $store_info = [ 'id' => $store_id, 'name' => Option::get('name', $store_id, 'store')['value'], 'img' => Option::get('web_log', $store_id, 'web')['value'] ]; $store_id = get_store_id(); $filename = md5('scan_' . $store_id); $ag = AggregateQrcode::findOne(['store_id' => $store_id]); $store = Store::findOne($store_id); $self_mini = Option::get('self_mini', $store_id, 'store', 0)['value']; if (!empty($store) && ((int)$store->business_model !== 1 || (\Yii::$app->prod_is_dandianpu()) && !$self_mini)) { $asg = AggregateSaasQrcode::findOne(['store_id' => $store_id]); //先查询聚合表 if(isset($asg->qrcode_url) && file_exists(str_replace(\Yii::$app->request->hostInfo,\Yii::$app->basePath,$asg->qrcode_url))){ return [ 'code' => 0, 'data' => [ 'url' => $asg->qrcode_url, 'store' => $store_info, ] ]; } if(empty($asg->qrcode_url) || !file_exists(str_replace(\Yii::$app->request->hostInfo,\Yii::$app->basePath,$asg->qrcode_url))){ if(!empty($asg->param_url)){ $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg'; $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg'); $text = $asg->param_url; QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path); $asg->qrcode_url = $pic_url; $asg->save(); return [ 'code' => 0, 'data' => [ 'url' => $pic_url, 'store' => $store_info, ] ]; } } $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg'; $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg'); if (file_exists($path)) { return [ 'code' => 0, 'data' => [ 'url' => $pic_url, 'store' => $store_info, ] ]; } $text = 'store_id:'. $store_id; $app = ShareQrcode::setBussinessWechat(); $response = $app->getUnlimit($text, [ 'width' => 500, 'page' => "face-pay/face-pay/payOut" ]); if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) { $filename = $response->save(\Yii::$app->runtimePath . '/image/', $filename); } else { return [ 'code' => 1, 'data' => [ 'response' => $response, 'store' => $store_info, ] ]; } return [ 'code' => 0, 'data' => [ 'url' => $pic_url, 'store' => $store_info, ] ]; } else if (empty($ag->param_url)) { $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg'; $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg'); if (file_exists($path)) { return [ 'code' => 0, 'data' => [ 'url' => $pic_url, 'store' => $store_info, ] ]; } //$text = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/scan/' . $store_id); $text = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/web/face/pay/' . $store_id); QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path); } else { //同步后端的聚合码 $filename = md5(date('YmdHis') . $ag->id); $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg'; $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg'); $ag = AggregateQrcode::find()->where(['id' => $ag->id])->select('param_url,id,qrcode_url')->one(); if(empty($ag->qrcode_url) || !file_exists(str_replace(\Yii::$app->request->hostInfo,\Yii::$app->basePath,$ag->qrcode_url))) { if (!empty($ag->param_url)) { $text = $ag->param_url; QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path); } } } // Todo 待添加背景 // $goods_qrcode = new \claviska\SimpleImage($path); // $bgPath = \Yii::$app->basePath . '/web/v1/statics/images/alipay-bg.png'; // $bg = new \claviska\SimpleImage($bgPath); // $bg->overlay($goods_qrcode, 'top left', 1, 200, 350); // $bg->toFile($path, 'image/jpeg', 85); return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'url' => $pic_url, 'store' => $store_info, ] ]; } /** * 获取当面付收款记录 */ public function actionGetMoneyRecord() { // TODO: 目前需要获取store下的收款记录 $store_id = get_store_id(); $list = AccountLog::find()->where(['store_id' => $store_id, 'order_type' => AccountLog::TYPE_SCAN_CODE_PAY, 'type' => AccountLog::TYPE_WECHAT])->asArray()->all(); if (empty($list)) { return [ 'code' => 0, 'msg' => 'success', 'data' => [] ]; } $res_arr = []; foreach ($list as $key => &$value) { $value['nickname'] = User::findOne($value['user_id'])->nickname; $list[$key]['date'] = date('Y-m-d', $value['created_at']); $list[$key]['time'] = date('H:i:s', $value['created_at']); $res_arr[$list[$key]['date']][] = $value; } $result = []; foreach ($res_arr as $k => $v) { $tmp = []; $tmp['date'] = $k; foreach ($v as $p) { $tmp['data'][] = $p; } $result[] = $tmp; } $date_arr = array_column($result, 'date'); array_multisort($date_arr, SORT_DESC, $result); return [ 'code' => 0, 'msg' => 'success', 'data' => $result ]; } }