| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\scancodepay\controllers\client;
- use app\models\AccountLog;
- use app\models\AggregateQrcode;
- use app\models\AggregateSaasQrcode;
- use app\models\Option;
- use app\models\Store;
- use app\models\User;
- use app\plugins\scanCodePay\controllers\BaseController;
- use app\plugins\scanCodePay\models\client\IndexForm;
- use app\utils\GenerateShareQrcode;
- use app\utils\QrCode;
- use app\utils\ShareQrcode;
- class IndexController extends BaseController
- {
- public function actionGetCoupon()
- {
- $form = new IndexForm();
- $form->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
- ];
- }
- }
|