setRequest(); $logs = []; $count = 0; foreach ($this->admin_open_list as $item) { //发送数据 $args = [ 'touser' => $item['open_id'], 'template_id' => $this->templateId, 'data' => $this->data, ]; $log = [ 'open_id' => $args['touser'], 'mall_id' => $this->mall->id, 'status' => 1, 'data' => \Yii::$app->serializer->encode($args), 'error' => '', 'created_at' => mysql_timestamp(), 'token' => $this->token, ]; try { $res = (new MpTplMessage())->senderMsg($args, [ 'app_id' => $this->app_id, 'app_secret' => $this->app_secret, 'mall_id' => $this->mall->id, ]); } catch (\Exception $e) { \Yii::error($e); $log['error'] = $e->getMessage(); $log['status'] = 0; } $count++; $logs[] = $log; } if ($count > 0) { \Yii::$app->db->createCommand()->batchInsert( MpTemplateRecord::tableName(), ['open_id', 'mall_id', 'status', 'data', 'error', 'created_at', 'token'], $logs )->execute(); } } catch (\Exception $e) { \Yii::warning($e); throw $e; } } }