| xqd
@@ -11,6 +11,8 @@ namespace App\Http\Controllers\Api\V1;
|
|
|
use App\Http\Controllers\Controller;
|
|
|
use App\Models\Area;
|
|
|
use App\Models\HelpInfo;
|
|
|
+use App\Models\Order;
|
|
|
+use App\Models\OrderPatient;
|
|
|
use App\Models\User;
|
|
|
use EasyWeChat\Factory;
|
|
|
use Cache;
|
| xqd
@@ -56,13 +58,14 @@ class CommonController extends Controller
|
|
|
if (empty($user)){
|
|
|
$add = [
|
|
|
'openid' => $data['openid'],
|
|
|
- 'unionid' => $data['unionid']?? '',
|
|
|
+ 'unionid' => $data['unionid'] ?? '',
|
|
|
'latitude' => $req['latitude'] ?? 0,
|
|
|
'longitude' => $req['longitude'] ?? 0,
|
|
|
'phone' => $req['phone'] ?? '',
|
|
|
'session_key' => $session_key,
|
|
|
'last_login_time' => time(),
|
|
|
];
|
|
|
+
|
|
|
$add['nickname'] = $req['nickname'] ?? '';
|
|
|
$add['avatar'] = $req['avatar'] ?? request()->getScheme().'://'.request()->getHost().'/img/default-head.png';
|
|
|
$user = User::create($add);
|
| xqd
@@ -78,7 +81,7 @@ class CommonController extends Controller
|
|
|
|
|
|
$update = [
|
|
|
'nickname' => $req['nickname'] ?? '',
|
|
|
- 'unionid' => $data['unionid']?? '',
|
|
|
+ 'unionid' => $data['unionid'] ?? '',
|
|
|
'avatar' => $req['avatar'] ?? '',
|
|
|
'latitude' => $req['latitude'] ?? 0,
|
|
|
'longitude' => $req['longitude'] ?? 0,
|
| xqd
@@ -359,4 +362,76 @@ class CommonController extends Controller
|
|
|
|
|
|
return out();
|
|
|
}
|
|
|
+
|
|
|
+ public function subscribe()
|
|
|
+ {
|
|
|
+ $msgType = request('type',3); //1公众号 2医生端小程序 3 用户端小程序
|
|
|
+ $orderId = request('order_id'); //订单id
|
|
|
+ if(empty($orderId)){
|
|
|
+ return apiReturn(601,'请输入参数');
|
|
|
+ }
|
|
|
+ $config = [
|
|
|
+ 1=>[
|
|
|
+ 'app_id' => env('OFFICE_APPID', 'wx92066f7587c34617'),
|
|
|
+ 'secret' => env('OFFICE_APPSECRET', 'bd7849c5259b79c41ec158173c5fb1d6'),
|
|
|
+ 'response_type' => 'array'
|
|
|
+ ],
|
|
|
+ 2=>[
|
|
|
+ 'app_id' => env('DOCTRER_WECHAT_APPID', 'wx92066f7587c34617'),
|
|
|
+ 'secret' => env('DOCTRER_WECHAT_APPSECRET', 'bd7849c5259b79c41ec158173c5fb1d6'),
|
|
|
+ 'response_type' => 'array'
|
|
|
+ ],
|
|
|
+ 3=>[
|
|
|
+ 'app_id' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
|
|
|
+ 'secret' => env('WECHAT_APPSECRET', 'b703596ab6cbcad5b74eb51fec2aeb0b'),
|
|
|
+ 'response_type' => 'array'
|
|
|
+ ],
|
|
|
+ ] ;
|
|
|
+
|
|
|
+ //测试环境配置
|
|
|
+// $config = [
|
|
|
+// 'app_id' => 'wx1c2357232cd25f65',
|
|
|
+// 'secret' => 'c8cab53e4e52234ed1bc2abbdeaba57d',
|
|
|
+// 'app_id' => 'wx13bedfcc62e9bab0',
|
|
|
+// 'secret' => '175e5518b6426dd12d3096f24ca68fb8',
|
|
|
+// 'response_type' => 'array'
|
|
|
+// oVxTzvgYlGktIDZXwfLMLQ01Tr5s
|
|
|
+// ];
|
|
|
+ $order = Order::where(['id'=>$orderId])->first();
|
|
|
+ if(empty($order)) return apiReturn(602,'无效订单');
|
|
|
+ if(empty($order->user_id)) return apiReturn(602,'此订单用户不存在');
|
|
|
+ $user = \App\User::where('id',$order->user_id)->first();
|
|
|
+ $uid = $user->unionid;
|
|
|
+ if(empty($user->unionid)) $uid = $user->openid;
|
|
|
+
|
|
|
+
|
|
|
+ if($msgType ==1){
|
|
|
+ $app = Factory::officialAccount($config[1]);
|
|
|
+// $app->user->get($uid);
|
|
|
+ apiReturn('200','发送功能在优化中');
|
|
|
+ } else {
|
|
|
+ $app = Factory::miniProgram($config[$msgType]);
|
|
|
+ $name = OrderPatient::where(['order_id'=>$orderId])->value('name');
|
|
|
+ $type_arr = [1=>'电话咨询',2=>'图文咨询',3=>'门诊预约',4=>'疫苗接种预约',5=>'儿保预约',6=>'服务包',7=>'充值'];
|
|
|
+ $order = Order::where(['id'=>$orderId])->first();
|
|
|
+ $orderType = $type_arr[$order->product_type];
|
|
|
+
|
|
|
+ $res = $app->subscribe_message->send([
|
|
|
+ 'touser' =>'oYmUA5A1OIqtpA1XSrw35tbjtv1w',
|
|
|
+ 'template_id' => 'M9b6PPKtD7PEqLsSnQ453iTIHtIZZpixOBjUjax8YXU',
|
|
|
+ 'page' => '/pages/common_tools/my_consulting/consultingInfo?order_id='.$orderId,
|
|
|
+ 'data' => [
|
|
|
+ 'phrase1' => $orderType,
|
|
|
+ 'name3' => $name,
|
|
|
+ 'date4' => date('Y-m-d H:i:s'),
|
|
|
+ 'thing8' => '你有一笔电话'.$orderType.'订单已成功下单请耐心等待',
|
|
|
+ 'amount10' => ($order->total_amount/100).'元',
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($res['errcode'] == 0) return apiReturn(200,'发送成功');
|
|
|
+ return apiReturn($res['errcode'],$res['errmsg']);
|
|
|
+ }
|
|
|
+
|
|
|
}
|