diff --git a/controllers/WechatController.php b/controllers/WechatController.php index 35d66b4..2ac4d75 100644 --- a/controllers/WechatController.php +++ b/controllers/WechatController.php @@ -61,7 +61,7 @@ class WechatController extends Controller $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; - $token = "3dxh"; + $token = "3u57ghc5dwh4pc6vsch4xqnqw5egg7cu"; $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr, SORT_STRING); $tmpStr = implode( $tmpArr ); @@ -98,6 +98,25 @@ class WechatController extends Controller if ($event=='subscribe') { // 关注事件 // $this->_doSubscribe($request_xml); }elseif ($event=='CLICK') {//菜单点击事件 + $id = $request_xml->EventKey; + if($id == 'diamond_cards'){ + $wechat_mp = $this->getWechat(); + // 推送客服消息 + $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$wechat_mp->getAccessToken(); + try{ + $to_user = reset($request_xml->FromUserName); + }catch (\Exception $e){ + $to_user = $request_xml->FromUserName; + } + $arr = [ + 'touser' => $to_user, + 'msgtype' => 'wxcard', + 'wxcard' => [ + 'card_id' => 'pVD1TwKeveIHet_0h-SnfL2VYGjU', + ], + ]; + $res = $wechat_mp->curl->post($url,json_encode($arr,JSON_UNESCAPED_UNICODE)); + } // $this->_doClick($request_xml); }elseif ($event=='VIEW') {//连接跳转事件 // $this->_doView($request_xml); @@ -115,63 +134,35 @@ class WechatController extends Controller 'id' => $find->store_id, ]); $wechat_mp = ""; - $wechat_app = WechatApp::findOne([ - 'cx_mch_id' => 0, - 'is_delete' => 0 - ]); - if($wechat_app){ - if (!is_dir(\Yii::$app->runtimePath . '/pem')) { - mkdir(\Yii::$app->runtimePath . '/pem'); - file_put_contents(\Yii::$app->runtimePath . '/pem/index.html', ''); - } - $cert_pem_file = null; - if ($wechat_app->cert_pem) { - $cert_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($wechat_app->cert_pem); - if (!file_exists($cert_pem_file)) - file_put_contents($cert_pem_file, $wechat_app->cert_pem); - } - $key_pem_file = null; - if ($wechat_app->key_pem) { - $key_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($wechat_app->key_pem); - if (!file_exists($key_pem_file)) - file_put_contents($key_pem_file, $wechat_app->key_pem); - } - $wechat_mp = new Wechat([ - 'appId' => $wechat_app->app_id, - 'appSecret' => $wechat_app->app_secret, - 'mchId' => $wechat_app->mch_id, - 'apiKey' => $wechat_app->key, - 'certPem' => $cert_pem_file, - 'keyPem' => $key_pem_file, - ]); - // 推送客服消息 - $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$wechat_mp->getAccessToken(); - $to_url = urlencode(SiteHelper::getCustomiseOptionByKey("siteDomain", "hump")."/site"); - $state = $find->id."_".$find->store_id."_".time(); - $res_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$wechat_app->app_id}&redirect_uri={$to_url}&response_type=code&scope=snsapi_userinfo&state={$state}#wechat_redirect"; - try{ - $to_user = reset($request_xml->FromUserName); - }catch (\Exception $e){ - $to_user = $request_xml->FromUserName; - } - $arr = [ - 'touser' => $to_user, - 'msgtype' => 'news', - 'news' => [ - 'articles' => [ - [ - 'title' => '欢迎访问'.SiteHelper::getCustomiseOptionByKey("siteName", "hump"), - 'description' => "请点击访问链接,配合工作人员完成步骤 - ".$find_store->name, - 'url' => $res_url, - 'picurl' => SiteHelper::getCustomiseOptionByKey("siteDomain", "hump").'/upload/0/1/upload/image/2023/1026/1698312821606159.jpg', - ] - ], - ], - ]; - $res = $wechat_mp->curl->post($url,json_encode($arr,JSON_UNESCAPED_UNICODE)); - \Yii::info(json_encode($res),'wxpay'); - \Yii::info(json_encode($arr).$request_xml->FromUserName,'wxpay'); + $wechat_mp = $this->getWechat(); + // 推送客服消息 + $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$wechat_mp->getAccessToken(); + $to_url = urlencode(SiteHelper::getCustomiseOptionByKey("siteDomain", "hump")."/site"); + $state = $find->id."_".$find->store_id."_".time(); + $res_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$wechat_mp->appId}&redirect_uri={$to_url}&response_type=code&scope=snsapi_userinfo&state={$state}#wechat_redirect"; + try{ + $to_user = reset($request_xml->FromUserName); + }catch (\Exception $e){ + $to_user = $request_xml->FromUserName; } + $site_name = SiteHelper::getCustomiseOptionByKey("siteName", "hump"); + $arr = [ + 'touser' => $to_user, + 'msgtype' => 'news', + 'news' => [ + 'articles' => [ + [ + 'title' => "欢迎您使用{$site_name}足部检测仪!", + 'description' => "当前门店:".$find_store->name."\n当前设备编号:{$find->dev_number}", + 'url' => $res_url, + 'picurl' => SiteHelper::getCustomiseOptionByKey("siteDomain", "hump").'/upload/0/1/upload/image/2023/1026/1698312821606159.jpg', + ] + ], + ], + ]; + $res = $wechat_mp->curl->post($url,json_encode($arr,JSON_UNESCAPED_UNICODE)); + \Yii::info(json_encode($res),'wxpay'); + \Yii::info(json_encode($arr).$request_xml->FromUserName,'wxpay'); $text = "欢迎来到英舒迪公众号"; $msg = sprintf($this->_msg_template['text'], $request_xml->FromUserName, $request_xml->ToUserName, time(),$text); $msg = ""; @@ -205,6 +196,42 @@ class WechatController extends Controller return $msg; } + public function getWechat(){ + $wechat_app = WechatApp::findOne([ + 'cx_mch_id' => 0, + 'is_delete' => 0 + ]); + if($wechat_app){ + if (!is_dir(\Yii::$app->runtimePath . '/pem')) { + mkdir(\Yii::$app->runtimePath . '/pem'); + file_put_contents(\Yii::$app->runtimePath . '/pem/index.html', ''); + } + $cert_pem_file = null; + if ($wechat_app->cert_pem) { + $cert_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($wechat_app->cert_pem); + if (!file_exists($cert_pem_file)) + file_put_contents($cert_pem_file, $wechat_app->cert_pem); + } + $key_pem_file = null; + if ($wechat_app->key_pem) { + $key_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($wechat_app->key_pem); + if (!file_exists($key_pem_file)) + file_put_contents($key_pem_file, $wechat_app->key_pem); + } + $wechat_mp = new Wechat([ + 'appId' => $wechat_app->app_id, + 'appSecret' => $wechat_app->app_secret, + 'mchId' => $wechat_app->mch_id, + 'apiKey' => $wechat_app->key, + 'certPem' => $cert_pem_file, + 'keyPem' => $key_pem_file, + ]); + return $wechat_mp; + + } + return false; + } + /** * @ 更新菜单 */ @@ -246,8 +273,35 @@ class WechatController extends Controller 'button' => [ [ 'type' => 'view', - 'name' => '查看报告', - 'url' => $res_url, + 'name' => '官网', + 'url' => "https://benson688.com/", + ], + [ + 'type' => 'miniprogram', + 'name' => '官网', + 'url' => "https://benson688.com/", + "appid"=>"wx7d887db4a4701186", + "pagepath"=>"pages/index/index", + ], + [ + "name" => "菜单", + "sub_button" => [ + [ + 'type' => 'view', + 'name' => '英舒迪AI聊天工具', + 'url' => "https://ai.benson688.com/h5/?i5hy", + ], + [ + 'type' => 'view', + 'name' => '携厦大研发保健鞋', + 'url' => "https://i.benson688.com/h5/1.html#/activity/luntan/index", + ], + [ + 'type' => 'click', + 'name' => '英舒迪钻石尊享卡', + "key" => "diamond_cards", + ], + ], ] ], ]; diff --git a/cxfoot.zip b/cxfoot.zip deleted file mode 100644 index a9087ac..0000000 Binary files a/cxfoot.zip and /dev/null differ diff --git a/modules/admin/models/Menu.php b/modules/admin/models/Menu.php index 6eb3899..6cd7f08 100644 --- a/modules/admin/models/Menu.php +++ b/modules/admin/models/Menu.php @@ -536,7 +536,7 @@ class Menu 'route' => 'admin/page/about-us', ], [ - 'name' => '微信小程序', + 'name' => '微信配置', 'is_menu' => true, 'is_show' => true, 'route' => null, diff --git a/modules/admin/models/report/ReportListForm.php b/modules/admin/models/report/ReportListForm.php index 4305da6..976acfc 100644 --- a/modules/admin/models/report/ReportListForm.php +++ b/modules/admin/models/report/ReportListForm.php @@ -51,7 +51,7 @@ class ReportListForm extends AdminModel return $this->getModelError(); } - $where = []; + $where = ['o.store_id' => $this->store_id]; if (!empty($this->times)) { $explode = explode(' - ', $this->times); $where = [ @@ -62,13 +62,12 @@ class ReportListForm extends AdminModel } $query = Report::find()->alias('o') - ->select('o.id,o.model_number,o.initial_path,o.final_path,o.pdf_path,o.step,u.real_name,u.mobile_phone,s.name as store_name,o.created_at') + ->select('o.id,o.model_number,o.initial_path,o.final_path,o.pdf_path,o.step,u.real_name,u.mobile_phone,s.name as store_name,o.created_at,o.json') ->leftJoin(['u' => User::tableName()], 'o.user_id=u.id') ->leftJoin(['s' => Store::tableName()], 'o.store_id=s.id') ->where([ ])->andWhere($where) - ->andFilterWhere(['o.store_id' => $this->store_id]) ->andFilterWhere([ 'OR', ['like', 'u.mobile_phone', $this->keywords], @@ -80,13 +79,39 @@ class ReportListForm extends AdminModel $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['o.created_at' => SORT_DESC])->asArray()->all(); + + $storeUser = StoreUser::findOne(['user_id' => $this->user_id]); + + $gender_str = [ + 0 => '未知', + 1 => '男', + 2 => '女', + ]; + $status = [ + 0 => '待上传', + 2 => '待生成报告', + 3 => '报告已生成', + ]; foreach ($list as $index => $item) { + if(!empty($item['json'])){ + $item['json'] = json_decode($item['json'],true); + } + if(empty($item['json'])){ + $item['json'] = json_decode('{"nickname":"","gender":0,"age":null,"height":null,"weight":null}',true); + } + + $item['json']['gender_str'] = $gender_str[$item['json']['gender']]??'未知'; + $item['user_type'] = $storeUser->user_type; + foreach ($item['json'] as $k=>$v){ + $item["json_".$k] = $v; + } + $item['created_at_cn'] = date("Y-m-d H:i", $item['created_at']); $item['initial_path_ext'] = ""; $item['initial_name'] = ''; if (!empty($item['initial_path'])) { - $item['initial_name'] = $item['model_number'] . '初始报告'; + $item['initial_name'] = $item['model_number'] . '初始模型'; $explode = explode('.', $item['initial_path']); $item['initial_path_ext'] = end($explode); } @@ -94,7 +119,7 @@ class ReportListForm extends AdminModel $item['final_path_ext'] = ''; $item['final_name'] = ''; if (!empty($item['final_path'])) { - $item['final_name'] = $item['model_number'] . '最终报告'; + $item['final_name'] = $item['model_number'] . '最终模型'; $explode = explode('.', $item['final_path']); $item['final_path_ext'] = end($explode); } @@ -108,6 +133,8 @@ class ReportListForm extends AdminModel $item['pdf_path_ext'] = end($explode); } + $item['status'] = $status[$item['step']]??''; + $list[$index] = $item; } diff --git a/modules/admin/models/wechat/WechatAppForm.php b/modules/admin/models/wechat/WechatAppForm.php index 3ec31dd..43f7b84 100644 --- a/modules/admin/models/wechat/WechatAppForm.php +++ b/modules/admin/models/wechat/WechatAppForm.php @@ -39,7 +39,7 @@ class WechatAppForm extends AdminModel { return [ [['name','app_id', 'app_secret', 'mch_id', 'key', 'cert_pem', 'key_pem','key_three'], 'trim'], - [['name','app_id', 'app_secret', 'mch_id', 'key', 'model', 'cx_mch_id','key_three'], 'required'], +// [['name','app_id', 'app_secret', 'mch_id', 'key', 'model', 'cx_mch_id','key_three'], 'required'], [['cx_mch_id'], 'integer'], ]; } diff --git a/modules/admin/views/report/index.php b/modules/admin/views/report/index.php index eb96fa4..33b4d32 100644 --- a/modules/admin/views/report/index.php +++ b/modules/admin/views/report/index.php @@ -29,7 +29,7 @@ $this->params['breadcrumbs'][] = $this->title;
- +
@@ -73,12 +73,27 @@ $this->params['breadcrumbs'][] = $this->title; - +
+ @@ -143,7 +158,7 @@ $this->params['breadcrumbs'][] = $this->title; //重新加载表格数据 function reload_table_data(conf) { table.reload('dtable', { - url: 'urlManager->createUrl(['admin/report/index'])?>' + url: 'urlManager->createUrl(['store/report/index'])?>' , page: true , where: conf }); @@ -163,17 +178,22 @@ $this->params['breadcrumbs'][] = $this->title; , {field: 'id', title: 'ID', width: 80} , {field: 'real_name', title: '姓名', width: 100} , {field: 'mobile_phone', title: '电话', width: 120} + , {field: "json_gender_str", title: '性别', width: 80} + , {field: "json_age", title: '年龄', width: 80} + , {field: "json_height", title: '身高', width: 80} + , {field: "json_weight", title: '体重', width: 80} , {field: 'store_name', title: '门店名称'} - , {field: 'model_number', title: '报告编号'} - , {field: 'initial_name', title: '初始模型'} - , {field: 'final_name', title: '最终模型'} - , {field: 'pdf_name', title: 'PDF报告'} + , {field: 'model_number', title: '设备编号'} + , {field: 'status', title: '状态'} + // , {field: 'initial_name', title: '初始模型'} + // , {field: 'final_name', title: '最终模型'} + // , {field: 'pdf_name', title: 'PDF报告'} // , {field: 'status', title: '状态', templet: '#statusTpl', width: 80} , {field: 'created_at_cn', title: '创建时间', width: 150} , {title: '操作', fixed: 'right', toolbar: '#rowBarTpl', width: 400} ] ] - , url: 'urlManager->createUrl(['admin/report/index'])?>' + , url: 'urlManager->createUrl(['store/report/index'])?>' , page: true //指向自定义工具栏模板选择器 , toolbar: '#toolBarTpl' @@ -211,23 +231,23 @@ $this->params['breadcrumbs'][] = $this->title; ids.push(id); if (lay_event == "delete") { - confirm_url = "urlManager->createUrl(['admin/store/delete'])?>"; + confirm_url = "urlManager->createUrl(['store/store/delete'])?>"; confirm_tip = "确定删除此门店吗"; } if (lay_event == "status_yes") { - confirm_url = "urlManager->createUrl(['admin/store/status-yes'])?>"; + confirm_url = "urlManager->createUrl(['store/store/status-yes'])?>"; confirm_tip = "确定此门店变更为营业吗?"; } if (lay_event == "status_no") { - confirm_url = "urlManager->createUrl(['admin/store/status-no'])?>"; + confirm_url = "urlManager->createUrl(['store/store/status-no'])?>"; confirm_tip = "确定此门店变更为停业吗?"; } - if (lay_event == "find_qrcode") { - confirm_url = "urlManager->createUrl(['admin/store/find-qrcode'])?>"; - confirm_tip = "确定查看此门店二维码吗?"; - } + //if (lay_event == "find_qrcode") { + // confirm_url = "urlManager->createUrl(['store/report/edit'])?>//"; + // confirm_tip = "确定上传报告吗?"; + //} if (lay_event == 'edit') { - confirm_url = "urlManager->createUrl(['admin/store/edit'])?>" + "?id=" + id; + confirm_url = "urlManager->createUrl(['store/report/edit'])?>" + "?id=" + id; location.href = confirm_url; return; } @@ -301,7 +321,7 @@ $this->params['breadcrumbs'][] = $this->title; ids.push(check_status.data[index]['id']); }); if (lay_event == 'batch_qrcode') { - confirm_url = "urlManager->createUrl(['admin/store/batch-qrcode'])?>"; + confirm_url = "urlManager->createUrl(['store/store/batch-qrcode'])?>"; location.href = confirm_url; return; } @@ -312,16 +332,16 @@ $this->params['breadcrumbs'][] = $this->title; var confirm_url = null; var confirm_tip = null; if (lay_event == 'batch_delete') { - confirm_url = "urlManager->createUrl(['admin/store/delete'])?>"; + confirm_url = "urlManager->createUrl(['store/store/delete'])?>"; confirm_tip = "确定将选中门店删除吗"; } if (lay_event == 'batch_status_yes') { - confirm_url = "urlManager->createUrl(['admin/store/status-yes'])?>"; + confirm_url = "urlManager->createUrl(['store/store/status-yes'])?>"; confirm_tip = "确定将选中门店变更为营业吗"; } if (lay_event == 'batch_status_no') { - confirm_url = "urlManager->createUrl(['admin/store/status-no'])?>"; + confirm_url = "urlManager->createUrl(['store/store/status-no'])?>"; confirm_tip = "确定将选中门店变更为停业吗"; } diff --git a/modules/admin/views/wechat/mp.php b/modules/admin/views/wechat/mp.php index 960bd78..a5ffe19 100644 --- a/modules/admin/views/wechat/mp.php +++ b/modules/admin/views/wechat/mp.php @@ -18,30 +18,30 @@ $this->params['breadcrumbs'][] = $this->title;
- +
- +
- +
- +
- +
- +
-
+
diff --git a/modules/store/views/dev/index.php b/modules/store/views/dev/index.php index a6977f0..9514600 100644 --- a/modules/store/views/dev/index.php +++ b/modules/store/views/dev/index.php @@ -80,7 +80,7 @@ $this->params['breadcrumbs'][] = $this->title;