|
|
@@ -4,7 +4,9 @@
|
|
4
|
4
|
namespace app\controller\api\cron;
|
|
5
|
5
|
|
|
6
|
6
|
|
|
|
7
|
+use AdaPaySdk\Drawcash;
|
|
7
|
8
|
use AdaPaySdk\PaymentConfirm;
|
|
|
9
|
+use AdaPaySdk\SettleAccount;
|
|
8
|
10
|
use app\common\dao\store\order\StoreOrderDao;
|
|
9
|
11
|
use app\common\repositories\merchant\order\OrderGzcRepository;
|
|
10
|
12
|
use app\common\repositories\merchant\order\OrderMerchantRepository;
|
|
|
@@ -14,8 +16,10 @@ use app\common\repositories\user\UserRepository;
|
|
14
|
16
|
use app\controller\api\Common;
|
|
15
|
17
|
use app\controller\merchant\finance\Reconciliation;
|
|
16
|
18
|
use app\traits\GongApiRequest;
|
|
|
19
|
+use app\traits\ShouxinyiApiRequest;
|
|
17
|
20
|
use Carbon\Carbon;
|
|
18
|
21
|
use Exception;
|
|
|
22
|
+use PHPMailer\PHPMailer\PHPMailer;
|
|
19
|
23
|
use think\db\exception\DataNotFoundException;
|
|
20
|
24
|
use think\db\exception\DbException;
|
|
21
|
25
|
use think\db\exception\ModelNotFoundException;
|
|
|
@@ -1034,4 +1038,269 @@ where o.paid=1 and o.is_settlement=1 and settlement_time between '$this->startMo
|
|
1034
|
1038
|
$merber->isError();
|
|
1035
|
1039
|
return $merber->result;
|
|
1036
|
1040
|
}
|
|
|
1041
|
+
|
|
|
1042
|
+
|
|
|
1043
|
+
|
|
|
1044
|
+
|
|
|
1045
|
+ //服务器配置,一般是默认配置
|
|
|
1046
|
+ private $CharSet = "UTF-8"; //设定邮件编码
|
|
|
1047
|
+ private $SMTPDebug = 0; // 调试模式输出
|
|
|
1048
|
+ private $isSMTP = true; // 使用SMTP
|
|
|
1049
|
+ private $Host = 'smtp.163.com'; // SMTP服务器
|
|
|
1050
|
+ private $SMTPAuth = true; // 允许 SMTP 认证
|
|
|
1051
|
+ private $Username = 'username'; // SMTP 用户名 即邮箱的用户名
|
|
|
1052
|
+ private $Password = 'MHIKZOXVPTGNVOMU'; // SMTP 密码 部分邮箱是授权码(例如163邮箱)
|
|
|
1053
|
+ private $SMTPSecure = 'ssl'; // 允许 TLS 或者ssl协议
|
|
|
1054
|
+ private $Port = 465; // 服务器端口 25 或者465 具体要看邮箱服务器支持
|
|
|
1055
|
+ //修改成自己的邮箱
|
|
|
1056
|
+ private $From = 'formalverification@163.com'; //发件人邮箱
|
|
|
1057
|
+ private $FromName = 'makalo'; //发件人的用户昵称
|
|
|
1058
|
+
|
|
|
1059
|
+
|
|
|
1060
|
+ //邮件对象
|
|
|
1061
|
+ private $mail;
|
|
|
1062
|
+
|
|
|
1063
|
+ //一般只有用户名和密码还有端口会变动, 所以这三个参数可以创建对象动态指定,也可以直接写死
|
|
|
1064
|
+ public function mallInit($Username = '', $Password = '', $Port = '')
|
|
|
1065
|
+ {
|
|
|
1066
|
+ if (!empty($Username)) {
|
|
|
1067
|
+ $this->Username = $Username;
|
|
|
1068
|
+ }
|
|
|
1069
|
+ if (!empty($Password)) {
|
|
|
1070
|
+ $this->Password = $Password;
|
|
|
1071
|
+ }
|
|
|
1072
|
+ if (!empty($Port)) {
|
|
|
1073
|
+ $this->Port = $Port;
|
|
|
1074
|
+ }
|
|
|
1075
|
+
|
|
|
1076
|
+ //为true表示启用异常
|
|
|
1077
|
+ $mail = new PHPMailer(true);
|
|
|
1078
|
+ //服务器配置
|
|
|
1079
|
+ $mail->CharSet = $this->CharSet; //设定邮件编码
|
|
|
1080
|
+ $mail->SMTPDebug = $this->SMTPDebug; // 调试模121212 1式输出
|
|
|
1081
|
+
|
|
|
1082
|
+ if ($this->isSMTP === true) {
|
|
|
1083
|
+ $mail->isSMTP(); // 使用SMTP
|
|
|
1084
|
+ }
|
|
|
1085
|
+ $mail->Host = $this->Host; // SMTP服务器
|
|
|
1086
|
+ $mail->SMTPAuth = $this->SMTPAuth; // 允许 SMTP 认证
|
|
|
1087
|
+ $mail->Username = $this->Username; // SMTP 用户名 即邮箱的用户名
|
|
|
1088
|
+ $mail->Password = $this->Password; // SMTP 密码 部分邮箱是授权码(例如163邮箱)
|
|
|
1089
|
+ $mail->SMTPSecure = $this->SMTPSecure; // 允许 TLS 或者ssl协议
|
|
|
1090
|
+ $mail->Port = $this->Port; // 服务器端口 25 或者465 具体要看邮箱服务器支持
|
|
|
1091
|
+ $mail->setFrom($this->From, $this->FromName); //发件人
|
|
|
1092
|
+
|
|
|
1093
|
+ $this->mail = $mail;
|
|
|
1094
|
+ }
|
|
|
1095
|
+
|
|
|
1096
|
+ /**
|
|
|
1097
|
+ * 发送邮件
|
|
|
1098
|
+ * @param array $sendAddress 收件人地址数组, 如果为单值数组则只写入收件地址,如果为键值数组则还写入收件人名称
|
|
|
1099
|
+ * @param array $Attachment 附件数组,如果为单值数组则为添加附件,如果为键值数组则添加附件并且重命名
|
|
|
1100
|
+ * @param bool $isHtml 是否以html文档格式发送
|
|
|
1101
|
+ * @param string $Subject 邮件主题
|
|
|
1102
|
+ * @param string $Body 邮件内容,如果以html格式可以写入html
|
|
|
1103
|
+ * @param string $AltBody 如果为单值数组则只写入收件地址,如果为键值数组则还写入收件人名称
|
|
|
1104
|
+ * @param array $CC 抄送地址数组, 如果为单值数组则只写入收件地址,如果为键值数组则还写入收件人名称
|
|
|
1105
|
+ * @param array $BCC 密送地址数组,如果为单值数组则只写入收件地址,如果为键值数组则还写入收件人名称
|
|
|
1106
|
+ * @return bool 是否发送成功
|
|
|
1107
|
+ */
|
|
|
1108
|
+ public function sendEMail($sendAddress = [], $Subject = '', $Body = '', $AltBody = '', $Attachment = [], $isHtml = true, $CC = [], $BCC = [])
|
|
|
1109
|
+ {
|
|
|
1110
|
+ try {
|
|
|
1111
|
+ //必填参数校验
|
|
|
1112
|
+ if (empty($sendAddress) || empty($Subject) || empty($Body)) {
|
|
|
1113
|
+ return false;
|
|
|
1114
|
+ }
|
|
|
1115
|
+ //收件人
|
|
|
1116
|
+ foreach ($sendAddress as $key => $value) {
|
|
|
1117
|
+ if (is_int($key)) {
|
|
|
1118
|
+ // 处理单值
|
|
|
1119
|
+ $this->mail->addAddress($value);
|
|
|
1120
|
+ } else {
|
|
|
1121
|
+ // 处理键值
|
|
|
1122
|
+ $this->mail->addAddress($value, $key);
|
|
|
1123
|
+ }
|
|
|
1124
|
+ }
|
|
|
1125
|
+ //附件
|
|
|
1126
|
+ if (!empty($Attachment)) {
|
|
|
1127
|
+ foreach ($Attachment as $key => $value) {
|
|
|
1128
|
+ if (is_int($key)) {
|
|
|
1129
|
+ // 处理单值
|
|
|
1130
|
+ $this->mail->addAttachment($value);
|
|
|
1131
|
+ } else {
|
|
|
1132
|
+ // 处理键值
|
|
|
1133
|
+ $this->mail->addAttachment($value, $key);
|
|
|
1134
|
+ }
|
|
|
1135
|
+ }
|
|
|
1136
|
+ }
|
|
|
1137
|
+ //抄送
|
|
|
1138
|
+ if (!empty($CC)) {
|
|
|
1139
|
+ //抄送不为空
|
|
|
1140
|
+ foreach ($CC as $key => $value) {
|
|
|
1141
|
+ if (is_int($key)) {
|
|
|
1142
|
+ // 处理单值
|
|
|
1143
|
+ $this->mail->addCC($value);
|
|
|
1144
|
+ } else {
|
|
|
1145
|
+ // 处理键值
|
|
|
1146
|
+ $this->mail->addCC($value, $key);
|
|
|
1147
|
+ }
|
|
|
1148
|
+ }
|
|
|
1149
|
+ }
|
|
|
1150
|
+ //密送
|
|
|
1151
|
+ if (!empty($BCC)) {
|
|
|
1152
|
+ //密送不为空
|
|
|
1153
|
+ foreach ($BCC as $key => $value) {
|
|
|
1154
|
+ if (is_int($key)) {
|
|
|
1155
|
+ // 处理单值
|
|
|
1156
|
+ $this->mail->addBCC($value);
|
|
|
1157
|
+ } else {
|
|
|
1158
|
+ // 处理键值
|
|
|
1159
|
+ $this->mail->addBCC($value, $key);
|
|
|
1160
|
+ }
|
|
|
1161
|
+ }
|
|
|
1162
|
+ }
|
|
|
1163
|
+
|
|
|
1164
|
+ //回复的时候回复给哪个邮箱 建议和发件人一致
|
|
|
1165
|
+ $this->mail->addReplyTo($this->From, $this->FromName);
|
|
|
1166
|
+
|
|
|
1167
|
+ //Content
|
|
|
1168
|
+ // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
|
|
|
1169
|
+ $this->mail->isHTML($isHtml);
|
|
|
1170
|
+ //邮件主题
|
|
|
1171
|
+ $this->mail->Subject = $Subject;
|
|
|
1172
|
+ //邮件内容
|
|
|
1173
|
+ $this->mail->Body = $Body;
|
|
|
1174
|
+ //如果邮件客户端不支持HTML则显示此内容
|
|
|
1175
|
+ $this->mail->AltBody = $AltBody;
|
|
|
1176
|
+
|
|
|
1177
|
+ //发送
|
|
|
1178
|
+ $this->mail->send();
|
|
|
1179
|
+ return [
|
|
|
1180
|
+ 'code' => 200,
|
|
|
1181
|
+ ];
|
|
|
1182
|
+ } catch (\Exception $e) {
|
|
|
1183
|
+ return [
|
|
|
1184
|
+ 'code' => 400,
|
|
|
1185
|
+ 'message' => $this->mail->ErrorInfo
|
|
|
1186
|
+ ];
|
|
|
1187
|
+ }
|
|
|
1188
|
+ }
|
|
|
1189
|
+
|
|
|
1190
|
+ public function take()
|
|
|
1191
|
+ {
|
|
|
1192
|
+ set_time_limit(0);
|
|
|
1193
|
+ $this->mallInit('formalverification@163.com', 'SYECAWFLLTUPMDRP');
|
|
|
1194
|
+ $this->sendEMail(['389123492@qq.com', '420132441@qq.com'], '结算定时', "开始执行" . date('Y-m-d H:i:s'), '如果邮件客户端不支持HTML则显示此内容');
|
|
|
1195
|
+ $mallStr = '';
|
|
|
1196
|
+
|
|
|
1197
|
+// Log::info('执行一次1 '.date('H:i') );
|
|
|
1198
|
+// return ;
|
|
|
1199
|
+// $storeOrderRepository = app()->make(StoreOrderRepository::class);
|
|
|
1200
|
+ $key_list = [
|
|
|
1201
|
+ 1 => 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9',
|
|
|
1202
|
+ 2 => 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f',
|
|
|
1203
|
+ 3 => 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871'
|
|
|
1204
|
+ ];
|
|
|
1205
|
+ $appid_list = [
|
|
|
1206
|
+ 1 => 'app_44108546-d27a-48ee-88c1-84b45b75114f',
|
|
|
1207
|
+ 2 => 'app_0827b960-b932-45ec-b800-4e850091b419',
|
|
|
1208
|
+ 3 => 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0'
|
|
|
1209
|
+ ];
|
|
|
1210
|
+//
|
|
|
1211
|
+// $payment_id = ShouxinyiApiRequest::getOrderNumber('split');
|
|
|
1212
|
+// $insertData = [
|
|
|
1213
|
+// [
|
|
|
1214
|
+// 'mid' => 0,
|
|
|
1215
|
+// 'requestId' => $payment_id,
|
|
|
1216
|
+// 'group_order_id' => 'WX171955791230553863',
|
|
|
1217
|
+// 'splitAmount' => 0.25,
|
|
|
1218
|
+// 'status' => 0
|
|
|
1219
|
+// ],
|
|
|
1220
|
+// ];
|
|
|
1221
|
+// $div_members[] = [
|
|
|
1222
|
+// 'member_id' => 'member_personal_16704641278422',
|
|
|
1223
|
+// 'amount' => '1.00',
|
|
|
1224
|
+// 'fee_flag' => 'Y'
|
|
|
1225
|
+// ];
|
|
|
1226
|
+// //////分账表
|
|
|
1227
|
+// Db::name("store_split_order")->insertAll($insertData);
|
|
|
1228
|
+// /// 分账表end
|
|
|
1229
|
+//
|
|
|
1230
|
+// $params = [
|
|
|
1231
|
+// 'payment_id' => '002212024062814583210652657343702200320',
|
|
|
1232
|
+// 'order_no' => $payment_id,
|
|
|
1233
|
+// 'confirm_amt' => '1.00',
|
|
|
1234
|
+// 'div_members' => $div_members
|
|
|
1235
|
+// ];
|
|
|
1236
|
+//
|
|
|
1237
|
+// $params['api_key'] = $key_list[3];
|
|
|
1238
|
+//
|
|
|
1239
|
+// var_dump($params);
|
|
|
1240
|
+// Db::name("log")->insert(array('data' => '汇付延时分账参数-----' . json_encode($params)));//日志记录
|
|
|
1241
|
+// $res = $storeOrderRepository->payment_confirm_create_traits($params);
|
|
|
1242
|
+// Db::name("log")->insert(array('data' => '汇付延时分账-----' . json_encode($res)));//日志记录
|
|
|
1243
|
+// var_dump($res);
|
|
|
1244
|
+// // 分账
|
|
|
1245
|
+// return;
|
|
|
1246
|
+
|
|
|
1247
|
+ $merchant_member_list = Db::name('merchant_member')
|
|
|
1248
|
+// ->where('member_id', 'member_personal_16704641278422')
|
|
|
1249
|
+ ->column('mer_id,type,member_id,settle_account_id');
|
|
|
1250
|
+
|
|
|
1251
|
+ foreach ($merchant_member_list as $merchant_member) {
|
|
|
1252
|
+ $mer_id = $merchant_member['mer_id'];
|
|
|
1253
|
+ if (empty($mer_id))
|
|
|
1254
|
+ continue;
|
|
|
1255
|
+ if (empty($merchant_member['settle_account_id']))
|
|
|
1256
|
+ continue;
|
|
|
1257
|
+ $params = [
|
|
|
1258
|
+ 'app_id' => $appid_list[$merchant_member['type']],
|
|
|
1259
|
+ 'member_id' => $merchant_member['member_id'],
|
|
|
1260
|
+ 'settle_account_id' => $merchant_member['settle_account_id'],
|
|
|
1261
|
+ 'api_key' => $key_list[$merchant_member['type']]
|
|
|
1262
|
+ ];
|
|
|
1263
|
+ $merber = new SettleAccount();
|
|
|
1264
|
+ $merber->balance($params);
|
|
|
1265
|
+ $merber->result;
|
|
|
1266
|
+// var_dump($merber->result);
|
|
|
1267
|
+ if (isset($merber->result[1])) {
|
|
|
1268
|
+ $result = json_decode($merber->result[1], true);
|
|
|
1269
|
+ $result = json_decode($result['data'], true);
|
|
|
1270
|
+ $result['avl_balance'] = $result['avl_balance'] ?? 0;
|
|
|
1271
|
+ if ($result['avl_balance'] > 0) {
|
|
|
1272
|
+ $payment_id = ShouxinyiApiRequest::getOrderNumber('split');
|
|
|
1273
|
+ $params = [
|
|
|
1274
|
+ 'order_no' => $payment_id,
|
|
|
1275
|
+ 'app_id' => $appid_list[$merchant_member['type']],
|
|
|
1276
|
+ 'cash_type' => 'T1',
|
|
|
1277
|
+ 'cash_amt' => sprintf("%01.2f", $result['avl_balance']),
|
|
|
1278
|
+ 'member_id' => $merchant_member['member_id'],
|
|
|
1279
|
+ 'api_key' => $key_list[$merchant_member['type']]
|
|
|
1280
|
+ ];
|
|
|
1281
|
+
|
|
|
1282
|
+ $yanglao_member_ids = ['jsdk_member_wx21710232183139', 'jsdk_member_ali1710232187326'];
|
|
|
1283
|
+ if (in_array($merchant_member['member_id'], $yanglao_member_ids)) {
|
|
|
1284
|
+ $params['remark'] = '天地博爱科技~养老金';
|
|
|
1285
|
+ }
|
|
|
1286
|
+
|
|
|
1287
|
+ Db::name("log")->insert(array('data' => '汇付取现参数-----' . json_encode($params)));//日志记录
|
|
|
1288
|
+ $merber = new Drawcash();
|
|
|
1289
|
+ $merber->create($params);
|
|
|
1290
|
+ # 返回查询结果
|
|
|
1291
|
+ $merber->isError();
|
|
|
1292
|
+ $res = $merber->result;
|
|
|
1293
|
+ Db::name("log")->insert(array('data' => '汇付延时分账-----' . json_encode($res))); //日志记录
|
|
|
1294
|
+ Db::name("log")->insert(array('data' => "mer_id {$mer_id} 请求分账{$result['avl_balance']}元-----"));//日志记录
|
|
|
1295
|
+ var_dump("mer_id {$mer_id} 请求分账{$result['avl_balance']}元-----");
|
|
|
1296
|
+ $mallStr = $mallStr . "-----mer_id {$mer_id} 请求分账{$result['avl_balance']}元-----<br/>";
|
|
|
1297
|
+ }
|
|
|
1298
|
+ }
|
|
|
1299
|
+ }
|
|
|
1300
|
+ echo date('Y-m-d H:i:s') . '执行结束' . "\r\n";
|
|
|
1301
|
+
|
|
|
1302
|
+
|
|
|
1303
|
+ $this->sendEMail(['389123492@qq.com', '420132441@qq.com'], '结算定时', "执行结束<br/>" . $mallStr . date('Y-m-d H:i:s'), '如果邮件客户端不支持HTML则显示此内容');
|
|
|
1304
|
+ }
|
|
|
1305
|
+
|
|
1037
|
1306
|
}
|